From 3bfa70d384ba46f40d384515d26c8081e92d7e56 Mon Sep 17 00:00:00 2001 From: adman Date: Fri, 8 May 2026 19:17:09 +0200 Subject: [PATCH] replay testdata --- .gitattributes | 3 + cmd/strom/main.go | 4 +- cmd/strom/print_replay/main.go | 83 +++++++++++++++++++ .../testdata/2026_04_18_20_07_53.mcpr | 3 + cmd/strom/print_replay/testdata/markers.json | 1 + cmd/strom/print_replay/testdata/metaData.json | 1 + cmd/strom/print_replay/testdata/mods.json | 1 + .../print_replay/testdata/recording.tmcpr | 3 + .../testdata/recording.tmcpr.crc32 | 1 + .../testdata/small/2026_04_21_22_30_31.mcpr | 3 + .../print_replay/testdata/small/metaData.json | 1 + .../print_replay/testdata/small/mods.json | 1 + .../testdata/small/recording.tmcpr | 3 + .../testdata/small/recording.tmcpr.crc32 | 1 + 14 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 cmd/strom/print_replay/main.go create mode 100644 cmd/strom/print_replay/testdata/2026_04_18_20_07_53.mcpr create mode 100644 cmd/strom/print_replay/testdata/markers.json create mode 100644 cmd/strom/print_replay/testdata/metaData.json create mode 100644 cmd/strom/print_replay/testdata/mods.json create mode 100644 cmd/strom/print_replay/testdata/recording.tmcpr create mode 100644 cmd/strom/print_replay/testdata/recording.tmcpr.crc32 create mode 100644 cmd/strom/print_replay/testdata/small/2026_04_21_22_30_31.mcpr create mode 100644 cmd/strom/print_replay/testdata/small/metaData.json create mode 100644 cmd/strom/print_replay/testdata/small/mods.json create mode 100644 cmd/strom/print_replay/testdata/small/recording.tmcpr create mode 100644 cmd/strom/print_replay/testdata/small/recording.tmcpr.crc32 diff --git a/.gitattributes b/.gitattributes index e4b1d56..e5352cb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,5 @@ **/*_test.go export-ignore **/testdata export-ignore +*.zip filter=lfs diff=lfs merge=lfs -text +*.tmcpr filter=lfs diff=lfs merge=lfs -text +*.mcpr filter=lfs diff=lfs merge=lfs -text diff --git a/cmd/strom/main.go b/cmd/strom/main.go index bf447b8..ed8ee2f 100644 --- a/cmd/strom/main.go +++ b/cmd/strom/main.go @@ -15,6 +15,7 @@ import ( "github.com/admin-else/strom/cmd/strom/offline_uuid" "github.com/admin-else/strom/cmd/strom/packet_inspector" "github.com/admin-else/strom/cmd/strom/print_nbt" + "github.com/admin-else/strom/cmd/strom/print_replay" "github.com/admin-else/strom/cmd/strom/status" ) @@ -43,6 +44,7 @@ var subcommands = map[string]func(args []string) error{ "version": Version, "extract-mca": extract_mca.Run, "data": data.Run, + "print-replay": print_replay.Run, } func Help(args []string) (err error) { @@ -60,7 +62,7 @@ func mainE() (err error) { // Debug stuff slog.SetLogLoggerLevel(slog.LevelDebug) - //args = []string{"TEST", "version"} + args = []string{"TEST", "print-replay", "-protocol", "774", "-file", "./cmd/strom/print_replay/testdata/recording.tmcpr"} if len(args) < 2 { err = ExpectedASubcommandErr diff --git a/cmd/strom/print_replay/main.go b/cmd/strom/print_replay/main.go new file mode 100644 index 0000000..6eaf70c --- /dev/null +++ b/cmd/strom/print_replay/main.go @@ -0,0 +1,83 @@ +package print_replay + +import ( + "bytes" + "encoding/binary" + "flag" + "fmt" + "io" + "os" + "reflect" + + "github.com/admin-else/strom/proto" + "github.com/admin-else/strom/proto_base" +) + +var ( + cmd = flag.NewFlagSet("print-replay", flag.ContinueOnError) + FileFlag = cmd.String("file", "", "The tmcpr file to print") + ProtocolVersion = cmd.Int("protocol", -1, "The protocol version") +) + +func UnpackPacket(r io.Reader) (packet proto_base.EncodeDecodeAble, err error) { + var timestamp, length uint32 + err = binary.Read(r, binary.BigEndian, ×tamp) + if err != nil { + return + } + err = binary.Read(r, binary.BigEndian, &length) + if err != nil { + return + } + b := bytes.NewBuffer(nil) + _, err = io.CopyN(b, r, int64(length)) + if err != nil { + return + } + + packetId, err := proto_base.DecodeVarInt(b) + if err != nil { + return + } + + i, ok := proto.LookUpTypeByPacketInfo(proto_base.ToClient, proto_base.Login, packetId, int32(*ProtocolVersion)) + if !ok { + packet = &proto.UnCodablePacket{Err: proto.BadPacketIdErr, Data: b.Bytes(), Direction: proto_base.ToClient} + return + } + packet = reflect.New(reflect.TypeOf(i.Type).Elem()).Interface().(proto_base.EncodeDecodeAble) + err = packet.Decode(b) + if err != nil { + packet = &proto.UnCodablePacket{Err: err, Data: b.Bytes(), Direction: proto_base.ToClient} + err = nil + } + return +} + +func Run(args []string) (err error) { + err = cmd.Parse(args) + if err != nil { + return + } + if *ProtocolVersion == -1 { + return fmt.Errorf("no protocol version specified") + } + if *FileFlag == "" { + return fmt.Errorf("no file specified") + } + f, err := os.Open(*FileFlag) + if err != nil { + return + } + defer f.Close() + + for { + var packet proto_base.EncodeDecodeAble + packet, err = UnpackPacket(f) + if err != nil { + return + } + fmt.Printf("Packet: %#v\n", packet) + fmt.Printf("Packet lllll: %v\n", packet) + } +} diff --git a/cmd/strom/print_replay/testdata/2026_04_18_20_07_53.mcpr b/cmd/strom/print_replay/testdata/2026_04_18_20_07_53.mcpr new file mode 100644 index 0000000..8fe95e9 --- /dev/null +++ b/cmd/strom/print_replay/testdata/2026_04_18_20_07_53.mcpr @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2d90ee976987678593a6b1d09136bb9b4fd131390796ea6e413376a6ddc63226 +size 75035693 diff --git a/cmd/strom/print_replay/testdata/markers.json b/cmd/strom/print_replay/testdata/markers.json new file mode 100644 index 0000000..6b5d98c --- /dev/null +++ b/cmd/strom/print_replay/testdata/markers.json @@ -0,0 +1 @@ +[{"realTimestamp":9845034,"value":{"position":{"x":-31.946051078575692,"y":93.0,"z":29.523387113769626,"yaw":-627.44653,"pitch":37.573395,"roll":0.0}}},{"realTimestamp":9845138,"value":{"position":{"x":-31.946051078575692,"y":93.0,"z":29.523387113769626,"yaw":-627.44653,"pitch":37.573395,"roll":0.0}}},{"realTimestamp":9844902,"value":{"position":{"x":-31.946051078575692,"y":93.0,"z":29.523387113769626,"yaw":-627.44653,"pitch":37.573395,"roll":0.0}}},{"realTimestamp":9908896,"value":{"position":{"x":-1.6053634059630886,"y":91.672484820985,"z":-10.594536888795163,"yaw":-1151.6353,"pitch":16.142092,"roll":0.0}}},{"realTimestamp":9844750,"value":{"position":{"x":-31.946051078575692,"y":93.0,"z":29.523387113769626,"yaw":-627.44653,"pitch":37.573395,"roll":0.0}}},{"realTimestamp":9853735,"value":{"position":{"x":-31.05268144454021,"y":88.0,"z":-25.371850030366133,"yaw":-624.37897,"pitch":16.105839,"roll":0.0}}},{"realTimestamp":9845690,"value":{"position":{"x":-31.946051078575692,"y":93.0,"z":29.523387113769626,"yaw":-627.44653,"pitch":37.573395,"roll":0.0}}},{"realTimestamp":9938194,"value":{"position":{"x":39.88206777447001,"y":103.87657142499006,"z":58.09267383764874,"yaw":-1781.1023,"pitch":37.354122,"roll":0.0}}},{"realTimestamp":9846991,"value":{"position":{"x":-31.946051078575692,"y":93.0,"z":29.523387113769626,"yaw":-628.46875,"pitch":36.04,"roll":0.0}}},{"realTimestamp":9908638,"value":{"position":{"x":-1.5870303355717672,"y":91.672484820985,"z":-11.359450846926011,"yaw":-1142.6902,"pitch":20.997843,"roll":0.0}}},{"realTimestamp":9845490,"value":{"position":{"x":-31.946051078575692,"y":93.0,"z":29.523387113769626,"yaw":-627.44653,"pitch":37.573395,"roll":0.0}}},{"realTimestamp":9845990,"value":{"position":{"x":-31.946051078575692,"y":93.0,"z":29.523387113769626,"yaw":-627.44653,"pitch":37.573395,"roll":0.0}}}] \ No newline at end of file diff --git a/cmd/strom/print_replay/testdata/metaData.json b/cmd/strom/print_replay/testdata/metaData.json new file mode 100644 index 0000000..a9a572f --- /dev/null +++ b/cmd/strom/print_replay/testdata/metaData.json @@ -0,0 +1 @@ +{"singleplayer":false,"serverName":"protect-beta.anygate.cloud","customServerName":"protect-beta.anygate.cloud","duration":10198341,"date":1776535673280,"mcversion":"1.21.11","fileFormat":"MCPR","fileFormatVersion":14,"protocol":774,"generator":"ReplayMod v1.21.11-2.6.26","selfId":-1,"players":["fe2d6f64-7ab0-3373-a526-af097abbcb39"]} \ No newline at end of file diff --git a/cmd/strom/print_replay/testdata/mods.json b/cmd/strom/print_replay/testdata/mods.json new file mode 100644 index 0000000..99a2cad --- /dev/null +++ b/cmd/strom/print_replay/testdata/mods.json @@ -0,0 +1 @@ +{"requiredMods":[{"modID":"viafabricplus","modName":"ViaFabricPlus","modVersion":"4.4.4"}]} \ No newline at end of file diff --git a/cmd/strom/print_replay/testdata/recording.tmcpr b/cmd/strom/print_replay/testdata/recording.tmcpr new file mode 100644 index 0000000..e5aef8d --- /dev/null +++ b/cmd/strom/print_replay/testdata/recording.tmcpr @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be007aa681f7959708e89e39e05390e228753291823a18274068d310a50aa78b +size 526306397 diff --git a/cmd/strom/print_replay/testdata/recording.tmcpr.crc32 b/cmd/strom/print_replay/testdata/recording.tmcpr.crc32 new file mode 100644 index 0000000..f550308 --- /dev/null +++ b/cmd/strom/print_replay/testdata/recording.tmcpr.crc32 @@ -0,0 +1 @@ +270566013 \ No newline at end of file diff --git a/cmd/strom/print_replay/testdata/small/2026_04_21_22_30_31.mcpr b/cmd/strom/print_replay/testdata/small/2026_04_21_22_30_31.mcpr new file mode 100644 index 0000000..0247342 --- /dev/null +++ b/cmd/strom/print_replay/testdata/small/2026_04_21_22_30_31.mcpr @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0da58f5cdd65ef241df8c61f9e633af7317faa77034183d4fb648b039c1e14ed +size 842 diff --git a/cmd/strom/print_replay/testdata/small/metaData.json b/cmd/strom/print_replay/testdata/small/metaData.json new file mode 100644 index 0000000..9308260 --- /dev/null +++ b/cmd/strom/print_replay/testdata/small/metaData.json @@ -0,0 +1 @@ +{"singleplayer":false,"serverName":"protect-test-server.anygate.cloud","customServerName":"proxied test server","duration":476,"date":1776803431635,"mcversion":"1.21.11","fileFormat":"MCPR","fileFormatVersion":14,"protocol":774,"generator":"ReplayMod v1.21.11-2.6.26","selfId":-1,"players":[]} \ No newline at end of file diff --git a/cmd/strom/print_replay/testdata/small/mods.json b/cmd/strom/print_replay/testdata/small/mods.json new file mode 100644 index 0000000..99a2cad --- /dev/null +++ b/cmd/strom/print_replay/testdata/small/mods.json @@ -0,0 +1 @@ +{"requiredMods":[{"modID":"viafabricplus","modName":"ViaFabricPlus","modVersion":"4.4.4"}]} \ No newline at end of file diff --git a/cmd/strom/print_replay/testdata/small/recording.tmcpr b/cmd/strom/print_replay/testdata/small/recording.tmcpr new file mode 100644 index 0000000..58cadd7 --- /dev/null +++ b/cmd/strom/print_replay/testdata/small/recording.tmcpr @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52fa049f97918289e018fa4c3bf5ff789d4f99f44f590ad875ce1f65e5fa9563 +size 37 diff --git a/cmd/strom/print_replay/testdata/small/recording.tmcpr.crc32 b/cmd/strom/print_replay/testdata/small/recording.tmcpr.crc32 new file mode 100644 index 0000000..ac456ab --- /dev/null +++ b/cmd/strom/print_replay/testdata/small/recording.tmcpr.crc32 @@ -0,0 +1 @@ +1105715802 \ No newline at end of file