This commit is contained in:
UnitedAirforce
2025-02-09 21:01:28 +08:00
parent d5bc4841f4
commit 9633c3acf4
3 changed files with 64 additions and 0 deletions
+25
View File
@@ -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')
+3
View File
@@ -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.
+36
View File
@@ -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')