From 6d5b40b45fe0d284fb880a7c3b8cdc6322f41d23 Mon Sep 17 00:00:00 2001 From: UnitedAirforce <52387376+qwerfd2@users.noreply.github.com> Date: Mon, 10 Feb 2025 09:51:03 +0800 Subject: [PATCH] toolset --- various-tools/uvdata dat/decode.py | 18 ++++++++++++++++++ various-tools/uvdata dat/encode.py | 19 +++++++++++++++++++ various-tools/uvdata dat/readme.txt | 6 +++++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 various-tools/uvdata dat/decode.py create mode 100644 various-tools/uvdata dat/encode.py diff --git a/various-tools/uvdata dat/decode.py b/various-tools/uvdata dat/decode.py new file mode 100644 index 0000000..ed3f692 --- /dev/null +++ b/various-tools/uvdata dat/decode.py @@ -0,0 +1,18 @@ +def hex_to_json(hex_string): + hex_string = hex_string.replace(" ", "").replace("\n", "") + byte_data = bytes.fromhex(hex_string) + + if len(byte_data) % 4 != 0: + raise ValueError("Hex data must contain a multiple of 4 bytes.") + + coordinates = [] + for i in range(0, len(byte_data), 4): + x = int.from_bytes(byte_data[i:i+2], byteorder='big', signed=False) + y = int.from_bytes(byte_data[i+2:i+4], byteorder='big', signed=False) + coordinates.append({"x": x, "y": y}) + + return coordinates + +hex_data = input("Input the hex data (with header 8 bytes removed):") +json_output = hex_to_json(hex_data) +print(json_output) diff --git a/various-tools/uvdata dat/encode.py b/various-tools/uvdata dat/encode.py new file mode 100644 index 0000000..a50fa7d --- /dev/null +++ b/various-tools/uvdata dat/encode.py @@ -0,0 +1,19 @@ +import json + +def json_to_hex(json_filename): + with open(json_filename, 'r') as f: + coordinates = json.load(f) + + hex_data = bytearray() + + for coord in coordinates: + x_bytes = coord["x"].to_bytes(2, byteorder='big', signed=False) + y_bytes = coord["y"].to_bytes(2, byteorder='big', signed=False) + hex_data.extend(x_bytes + y_bytes) + + return hex_data.hex().upper() + +file_name = input("input the json file name: ") + +hex_output = json_to_hex(file_name) +print(hex_output) \ No newline at end of file diff --git a/various-tools/uvdata dat/readme.txt b/various-tools/uvdata dat/readme.txt index d7f25b3..8a5e786 100644 --- a/various-tools/uvdata dat/readme.txt +++ b/various-tools/uvdata dat/readme.txt @@ -1,3 +1,7 @@ uvdata is like the plist for the sprite sheets. To edit their dimensions, this tool can be used. -Parse uvdata.dat to uvdata.xlsx, and write it back to out_uvdata.dat. \ No newline at end of file +Parse uvdata.dat to uvdata.xlsx, and write it back to out_uvdata.dat. + +Each row of uvdata is the dimension of that image.bin. 8 byte of header is included (file index, number of elements) + +Use the encode/decode.py to convert the header-removed hex strings to/from json coordinates. \ No newline at end of file