import mmap import struct from pathlib import Path import json def read_until_null(indx: int, data: tuple) -> int: end = indx while end + 1 < len(data): ## Read 2 bytes at a time until null found if data[end:end+2] == b"\x00\x00": break end += 2 return end def read_until_space(indx: int, data: tuple) -> int: end = indx while end + 1 < len(data): ## Read 2 bytes at a time until null found if data[end:end+2] == b"\x4F\x00": break end += 2 return end # 8 bytes at a time cd_db = {} def get_props(): test = 0 for r in range(0,len(offsets_data),8): test += 1 # offsets_data[4:8].hex() card_index_name_data = int.from_bytes( offsets_data[r:r+4], byteorder='little', signed=False ) if card_index_name_data == 0: continue #card_index_desc_data = int.from_bytes( offsets_data[r+4:r+8], byteorder='little' ) #card_id = card_id[::-1] #read until null found # end = card_index_name_data # while end + 1 < len(name_data): # ## Read 2 bytes at a time until null found # if name_data[end:end+2] == b"\x00\x00": # break # end += 2 # name = name_data[card_index_name_data:end].decode("utf-16le", errors="replace") end_index = read_until_null(card_index_name_data, name_data) name = name_data[card_index_name_data:end_index].decode("utf-16le", errors="replace") print(name) if name == '': continue #print(card_id.hex(' ')) # 2. Get last 14 bits using mask 0x3FFF (binary 11 1111 1111 1111) #print([bin(x) for x in card_first]) # if test > 3: # break; #print(prop_data[r:r+8]) if cd_db.get(test) is None: cd_db[test] = {} # { # f"name_{language_code}":name, # f"desc_{language_code}": 'foo', # f"name_addr_{language_code}": hex(card_index_name_data), # f"desc_addr_{language_code}": hex(card_index_desc_data) # } cd_db[test][f"name_{language_code}"] = name #cd_db[card_id][f"desc_{language_code}"] = desc cd_db[test][f"name_addr_{language_code}"] = hex(card_index_name_data) #cd_db[card_id][f"desc_addr_{language_code}"] = hex(card_index_desc_data) language_code = 'E' #offsets_data = Path(f"YGO_2020/bin/DLG_Indx_{language_code}.bin").read_bytes() # Get all the bytes e_name_data = Path(f"YGO_2020/main/howto_db/howtoplay_{language_code}.bin").read_bytes() # Get all the bytes #get_props() language_code = 'J' j_name_data = Path(f"YGO_2020/main/howto_db/howtoplay_{language_code}.bin").read_bytes() # Get all the bytes print("now what?") count_of_items = int.from_bytes(e_name_data[0:4], byteorder='big') # 202 ## 202 * 8 = 1616 (Thats about where this started) help_dump = {} i_e = 1624 i_j = 1624 c = 1 while (i_e < len(e_name_data) and i_j < len(j_name_data)): help_dump[c] = {} e = read_until_null(i_e,e_name_data) help_dump[c]['en'] = e_name_data[i_e:e].decode("utf-16be", errors="replace") print(help_dump[c]['en'] ) i_e = e + 2 e = read_until_null(i_j,j_name_data) help_dump[c]['ja'] = j_name_data[i_j:e].decode("utf-16be", errors="replace") print(help_dump[c]['ja']) i_j = e + 2 c+=1 print(c, " - strings extracted.") # c = 333 not sure how to index these anymore with open("helptext_dump.json", "w", encoding="utf-8") as outfile: json.dump(help_dump, outfile, ensure_ascii=False, indent=2) exit() ## Attempt to get ids or sense out of the beginning block, no luck so far for r in range(0,len(name_data),8): #id = int.from_bytes( name_data[r:r+4], byteorder='big', signed=False ) #id = int(name_data[r:r+4], 16) & 0xFFFFFFFF id = struct.unpack(' bytes; # file.read((char*)(bytes.data()),4); # value = bytes[0] | (bytes[1]<<8) | (bytes[2]<<16) | (bytes[3]<<24); # return value; # } # Long ReadLong(std::ifstream &file){ # Long value; # std::array bytes; # file.read((char*)(bytes.data()),8); # value = bytes[0] | (bytes[1]<<8) | (bytes[2]<<16) | (bytes[3]<<24) | (bytes[4]<<32) | (bytes[5]<<40) | (bytes[6]<<48) | (bytes[7]<<56); # return value; # } # if (scriptFile.is_open()){ # Long pointerToPointers=ReadLong(scriptFile); # Int titleCount=ReadInt(scriptFile); # Int scriptBlockCount=ReadInt(scriptFile); # std::vector titleStartPos; # std::vector titleEndPos; # std::vector titlePointer; # for (Int i=0; i titleNames; # for (Int i=0; i > script; # for (Int i=0; i< titleCount; i++){ # std::vector scriptBlocks; # Int blockCount=titleEndPos[i]-titleStartPos[i]+1; # int pointer; # for (Int j=0; j