mirror of
https://github.com/CosmicStar98/bedrocktool.git
synced 2024-06-26 01:39:44 +00:00
broken regex, add geometry output
This commit is contained in:
parent
0996108fd4
commit
abb23b55e9
2
main.go
2
main.go
|
@ -92,7 +92,7 @@ func input_server() string {
|
||||||
fmt.Printf("Enter Server: ")
|
fmt.Printf("Enter Server: ")
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
target, _ := reader.ReadString('\n')
|
target, _ := reader.ReadString('\n')
|
||||||
r, _ := regexp.Compile(`[^\n\r]`)
|
r, _ := regexp.Compile(`[\n\r]`)
|
||||||
target = string(r.ReplaceAll([]byte(target), []byte("")))
|
target = string(r.ReplaceAll([]byte(target), []byte("")))
|
||||||
return target
|
return target
|
||||||
}
|
}
|
||||||
|
|
61
skins.go
61
skins.go
|
@ -1,15 +1,18 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -40,9 +43,19 @@ func cleanup_name(name string) string {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
// write skin as png without geometry
|
func write_skin_geometry(output_path string, skin protocol.Skin) {
|
||||||
func write_skin_simple(name string, skin protocol.Skin) {
|
os.Mkdir(output_path, 0755)
|
||||||
f, err := os.Create(fmt.Sprintf("%s/%s.png", out_path, name))
|
f, err := os.Create(path.Join(output_path, "geometry.json"))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Failed to write skin geom %s: %s\n", out_path, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
io.Copy(f, bytes.NewReader(skin.SkinGeometry))
|
||||||
|
}
|
||||||
|
|
||||||
|
func write_skin_texture(name string, skin protocol.Skin) {
|
||||||
|
f, err := os.Create(name + ".png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error writing skin: %s\n", err)
|
fmt.Fprintf(os.Stderr, "Error writing skin: %s\n", err)
|
||||||
return
|
return
|
||||||
|
@ -57,13 +70,49 @@ func write_skin_simple(name string, skin protocol.Skin) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func write_skin_cape(output_path string, skin protocol.Skin) {
|
||||||
|
os.Mkdir(output_path, 0755)
|
||||||
|
f, err := os.Create(path.Join(output_path, "cape.png"))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Failed to write skin cape %s: %s\n", out_path, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
cape_tex := image.NewRGBA(image.Rect(0, 0, int(skin.CapeImageWidth), int(skin.CapeImageHeight)))
|
||||||
|
cape_tex.Pix = skin.CapeData
|
||||||
|
|
||||||
|
if err := png.Encode(f, cape_tex); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error writing skin: %s\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func write_skin_animations(output_path string, skin protocol.Skin) {
|
||||||
|
os.Mkdir(output_path, 0755)
|
||||||
|
fmt.Printf("%s has animations (unimplemented)\n", output_path)
|
||||||
|
}
|
||||||
|
|
||||||
func write_skin(name string, skin protocol.Skin) {
|
func write_skin(name string, skin protocol.Skin) {
|
||||||
fmt.Printf("Writing skin for %s\n", name)
|
fmt.Printf("Writing skin for %s\n", name)
|
||||||
|
complex := false
|
||||||
|
skin_dir := path.Join(out_path, name)
|
||||||
if len(skin.SkinGeometry) > 0 {
|
if len(skin.SkinGeometry) > 0 {
|
||||||
fmt.Printf("%s has geometry\n", name)
|
write_skin_geometry(skin_dir, skin)
|
||||||
write_skin_simple(name, skin)
|
complex = true
|
||||||
|
}
|
||||||
|
if len(skin.CapeData) > 0 {
|
||||||
|
write_skin_cape(skin_dir, skin)
|
||||||
|
complex = true
|
||||||
|
}
|
||||||
|
if len(skin.Animations) > 0 {
|
||||||
|
write_skin_animations(skin_dir, skin)
|
||||||
|
complex = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if complex {
|
||||||
|
write_skin_texture(path.Join(skin_dir, "skin"), skin)
|
||||||
} else {
|
} else {
|
||||||
write_skin_simple(name, skin)
|
write_skin_texture(skin_dir, skin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user