diff --git a/various-tools/uvdata dat/reader.py b/various-tools/uvdata dat/reader.py new file mode 100644 index 0000000..e54522a --- /dev/null +++ b/various-tools/uvdata dat/reader.py @@ -0,0 +1,25 @@ +import struct +import openpyxl + +def read_uvdata(file_path, output_excel): + with open(file_path, 'rb') as f: + data = f.read() + + num_sections = struct.unpack('>H', data[4:6])[0] + + offsets = [struct.unpack('>I', data[6 + i * 4:10 + i * 4])[0] for i in range(num_sections)] + offsets.append(len(data)) + + wb = openpyxl.Workbook() + ws = wb.active + + for i in range(num_sections): + start, end = offsets[i], offsets[i + 1] + section_data = data[start:end] + hex_string = ' '.join(f'{byte:02X}' for byte in section_data) + ws.append([hex_string]) + + wb.save(output_excel) + print(f"Extracted {num_sections} sections to {output_excel}") + +read_uvdata('uvdata.dat', 'uvdata.xlsx') \ No newline at end of file diff --git a/various-tools/uvdata dat/readme.txt b/various-tools/uvdata dat/readme.txt new file mode 100644 index 0000000..d7f25b3 --- /dev/null +++ b/various-tools/uvdata dat/readme.txt @@ -0,0 +1,3 @@ +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 diff --git a/various-tools/uvdata dat/writer.py b/various-tools/uvdata dat/writer.py new file mode 100644 index 0000000..45c2de5 --- /dev/null +++ b/various-tools/uvdata dat/writer.py @@ -0,0 +1,36 @@ +import struct +import openpyxl + +def write_uvdata(input_excel, output_file): + wb = openpyxl.load_workbook(input_excel) + ws = wb.active + + sections = [] + for row in ws.iter_rows(values_only=True): + if row[0]: + sections.append(bytes.fromhex(row[0])) + + num_sections = len(sections) + offsets = [] + current_offset = 6 + num_sections * 4 + 4 # Additional header repeat + + for section in sections: + offsets.append(current_offset) + current_offset += len(section) + + with open(output_file, 'wb') as f: + file_length = struct.pack('>I', current_offset) + num_sections_packed = struct.pack('>H', num_sections) + f.write(file_length + num_sections_packed) + + for offset in offsets: + f.write(struct.pack('>I', offset)) + + f.write(file_length) + + for section in sections: + f.write(section) + + print(f"Packed {num_sections} sections into {output_file}") + +write_uvdata('uvdata.xlsx', 'out_uvdata.dat') \ No newline at end of file