Skip to content

Commit

Permalink
fix some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wooddoll committed Nov 9, 2024
1 parent dbbd564 commit 7ce6c26
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 174 deletions.
4 changes: 3 additions & 1 deletion fileStruct/merge_StringBIN.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,15 @@ def packData(self, output_path: str):
MENU2_1 = createStringBINNClass('MENU/MENU2.PRG', [12, 13, 14, 15, 16, 17], 0x2478)
MENU3 = createStringBINNClass('MENU/MENU3.PRG', [], 0x6bb4)
MENU7 = createStringBINNClass('MENU/MENU7.PRG', startPtr=0x7c54)
MENU8 = createStringBINNClass('MENU/MENU8.PRG', [62], 0x429c)

MENU12 = createStringBINNClass('MENU/MENU12.BIN')
#NAMEDIC = createStringBINNClass('MENU/NAMEDIC.BIN', [9, 10, 11, 12])
MENUB = createStringBINNClass('MENU/MENUB.PRG', startPtr=0x7a80)

MON = createStringBINNClass('SMALL/MON.BIN', [], 0x19C8)

FileLoadFuncNames = ['MENU0', 'MENU1', 'MENU2', 'MENU2_1', 'MENU3', 'MENU4', 'MENU7', 'MENU12', 'MCMAN', 'ITEMHELP',
FileLoadFuncNames = ['MENU0', 'MENU1', 'MENU2', 'MENU2_1', 'MENU3', 'MENU4', 'MENU7', 'MENU8', 'MENU12', 'MCMAN', 'ITEMHELP',
'MENUB', 'BATTLE_3', 'MON' ]

def getNNClass(className: str):
Expand Down
18 changes: 14 additions & 4 deletions fileStruct/readStrFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def unpackData(self, buffer: bytes):
def __len__(self):
return self.len_buffer if 0 < self.itemNums else 0

def packData(self):
def packData(self, aligb4b = True):
if 0 >= self.itemNums:
return None

Expand Down Expand Up @@ -100,10 +100,20 @@ def packData(self):
byte_stream.write(data)

currPos = byte_stream.tell()
if self.len_buffer < currPos:
logging.warning(f"check the length of strings, size overflowed; {self.len_buffer} < current({currPos})")
if aligb4b:
sumBytes_pad = ((currPos+3)//4)*4
padding = sumBytes_pad - currPos
if padding:
for _ in range(padding):
byte_stream.write(bytes1(0))
sumBytes = sumBytes_pad
else:
sumBytes = currPos

if self.len_buffer < sumBytes:
logging.warning(f"check the length of strings, size overflowed; {self.len_buffer} < current({sumBytes})")

self.len_buffer = currPos
self.len_buffer = sumBytes

return byte_stream.getvalue()

Expand Down
7 changes: 6 additions & 1 deletion fileStruct/read_EVT.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ def unpackData(self, input_path: str):
self.strings.unpackData(self.buffer[head[1]:head[2]])
self.Unknown1 = self.buffer[head[2]:head[3]]
self.Unknown2 = self.buffer[head[3]:head[0]]

self.strings_byte = self.strings._byte

#if not all([x==0 for x in self.Unknown1]):
# print()
#if not all([x==0 for x in self.Unknown2]):
# print()

def packData(self, output_path: str):
byte_stream = io.BytesIO(self.buffer)
Expand Down
4 changes: 2 additions & 2 deletions fileStruct/read_Nstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ def packData(self, output_path: str):


FileLoadFuncNames = ['MENU5', 'NAMEDIC',
'MENU8', 'MENU9', 'MENUD', 'MENUE',
'MENU9', 'MENUD', 'MENUE',
'BATTLE', 'MON', 'TITLE', 'INITBTL',
'ITEMNAME', 'SL_Main']

FileLoad1Strs = ['NAMEDIC',
'MENU8', 'MENUD', 'MENUE',
'MENUD', 'MENUE',
'TITLE', 'ITEMNAME']

def getNNClass(className: str) -> Tuple[Class_Nstrings, Class_Nstrings]:
Expand Down
60 changes: 31 additions & 29 deletions fileStruct/structMPD.py

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions rebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def calpos(row: int, col: int):

return jpnList

def makeKorFont():
def makeKorFontData():
jpnIndexes, jpnLetters = jpnTableslots(jpnTBL)
korTBL = deepcopy(jpnTBL)
korKeys = list(korTBL.fwd_tbl.keys())
Expand Down Expand Up @@ -244,6 +244,13 @@ def makeKorFont():

f.write(f"{h}={v}\n")


return korHisto

def applyKorFont():
krfontImage = 'font/font12kr.png'
imgJpKr = Image.open(krfontImage)

system_dat = cvtFontBin.SYSTEM_DAT(f'{PATH_JPN_VARGRANTSTORY}')
system_dat.fontData.setImage(imgJpKr)

Expand All @@ -253,7 +260,6 @@ def makeKorFont():
system_dat.packData(f'{PATH_KOR_VARGRANTSTORY}/BATTLE/SYSTEM.DAT')

insertTITLE_font(f'{PATH_JPN_VARGRANTSTORY}/TITLE/TITLE.PRG', 'font/font12kr.png', f'{PATH_KOR_VARGRANTSTORY}/TITLE/TITLE.PRG')
return korHisto

def posInTable18_ja(index: int):
row = index//18
Expand Down Expand Up @@ -320,6 +326,8 @@ def fixMPD(idx: int, mpd: MPDstruct):
def update_MPD(index: int, kor_strings: dict):
Name = f"MAP{index:03}"
filepath = f"{PATH_JPN_VARGRANTSTORY}/MAP/{Name}.MPD"
if Name == 'MAP038':
print()
mpd = MPDstruct(str(filepath), DoorPtrs_jp)
mpd.cvtByte2Str(jpnTBL)

Expand Down Expand Up @@ -371,7 +379,8 @@ def updateMAP_MDP(kor_strings: dict):
for key in kor_strings.keys():
if str(key)[:3] == 'MAP' and str(key) != 'MAP_ZND':
idx = int(str(key)[3:])
logging.info(f"=== MAP{idx:03}.MPD packing ===")
#logging.info(f"=== MAP{idx:03}.MPD packing ===")
print(f"=== MAP{idx:03}.MPD packing ===")
update_MPD(idx, kor_strings)

def update_ARM(Name: str, dictTexts: dict):
Expand Down Expand Up @@ -561,9 +570,10 @@ def update_EVT(kor_strings: dict):
string = v1.get('string')
if string is not None:
evts_jp.evtFiles[int_k0].strings_str[int_k1] = string

evts_jp.cvtStr2Byte(korTBL)
evts_jp.packData(PATH_KOR_VARGRANTSTORY)

evts_jp.evtFiles[int_k0].strings.cvtStr2Byte(korTBL)
evts_jp.evtFiles[int_k0].packData(f"{PATH_KOR_VARGRANTSTORY}/EVENT/{int_k0:04}.EVT")


def stringBIN_merge(kor_strings: dict):
print(f"update === stringBIN_merge === ")
Expand Down Expand Up @@ -693,10 +703,11 @@ def rebuildKor():
#exit()
#downlaod_localazy()

#korHisto = makeKorFont()
#korHisto = makeKorFontData()
#makeKorFont14(korHisto)
#update_Help()
#exit()
applyKorFont()
rebuildKor()

def test1():
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ def searchByte():
#word = bytearray([0x91, 0xE0, 0x90, 0xCD, 0x53, 0xA2, 0xD7, 0xE7])
#word = bytearray([0xE0, 0x9C, 0x90, 0xCD, 0xED, 0x23, 0xA2, 0xD7])
#word = bytearray([0xEF, 0x6B, 0xF0, 0x0C, 0x4A, 0x63])
word = bytearray([0x16 , 0x19 , 0xED , 0x2A , 0xEE , 0xAB , 0x56 , 0x4D , 0x5F])
word = bytearray([0xD1,0xC4 ,0xB5 ,0xB2])
len_word = len(word)
for filepath in tqdm(file_list, desc="Processing"):
relative_path = filepath.relative_to(folder_path)
Expand Down
Loading

0 comments on commit 7ce6c26

Please sign in to comment.