diff --git a/include/JSystem/JKernel/JKRArchive.h b/include/JSystem/JKernel/JKRArchive.h index 9c413274ec4..31991837d20 100644 --- a/include/JSystem/JKernel/JKRArchive.h +++ b/include/JSystem/JKernel/JKRArchive.h @@ -222,4 +222,8 @@ inline void* JKRGetTypeResource(u32 tag, const char* name, JKRArchive* arc) { return JKRArchive::getGlbResource(tag, name, arc); } +inline void* JKRGetResource(u32 tag, const char* name, JKRArchive* arc) { + return JKRArchive::getGlbResource(tag, name, arc); +} + #endif \ No newline at end of file diff --git a/include/JSystem/JKernel/JKRDvdRipper.h b/include/JSystem/JKernel/JKRDvdRipper.h index b333a87de03..8248d167a2c 100644 --- a/include/JSystem/JKernel/JKRDvdRipper.h +++ b/include/JSystem/JKernel/JKRDvdRipper.h @@ -43,4 +43,12 @@ inline void* JKRDvdToMainRam(s32 entryNum, u8* dst, JKRExpandSwitch expandSwitch offset, compression, returnSize); } +inline void* JKRDvdToMainRam(char const* param_0, u8* dst, JKRExpandSwitch expandSwitch, + u32 dstLength, JKRHeap* heap, + JKRDvdRipper::EAllocDirection allocDirection, u32 offset, + JKRCompression* compression, u32* returnSize) { + return JKRDvdRipper::loadToMainRAM(param_0, dst, expandSwitch, dstLength, heap, allocDirection, + offset, compression, returnSize); +} + #endif /* JKRDVDRIPPER_H */ diff --git a/include/JSystem/JKernel/JKRHeap.h b/include/JSystem/JKernel/JKRHeap.h index 74fd1e2840a..f2194cb7a88 100644 --- a/include/JSystem/JKernel/JKRHeap.h +++ b/include/JSystem/JKernel/JKRHeap.h @@ -225,4 +225,12 @@ inline u32 JKRGetMemBlockSize(JKRHeap* heap, void* block) { return JKRHeap::getSize(block, heap); } +inline void* JKRAlloc(u32 size, int alignment) { + return JKRHeap::alloc(size, alignment, NULL); +} + +inline s32 JKRResizeMemBlock(JKRHeap* heap, void* ptr, u32 size) { + return JKRHeap::resize(ptr, size, heap); +} + #endif /* JKRHEAP_H */ diff --git a/include/d/com/d_com_inf_game.h b/include/d/com/d_com_inf_game.h index 3caf9c43974..e27e8be59fc 100644 --- a/include/d/com/d_com_inf_game.h +++ b/include/d/com/d_com_inf_game.h @@ -578,7 +578,7 @@ void dComIfGs_setWarpMarkFlag(u8); void dComIfGs_setSelectEquipSword(u8); void dComIfGs_setSelectEquipShield(u8); void* dComIfG_getStageRes(char const*); -void dComLbG_PhaseHandler(request_of_phase_process_class*, request_of_phase_process_fn, void*); +int dComLbG_PhaseHandler(request_of_phase_process_class*, request_of_phase_process_fn, void*); void dComIfGp_addSelectItemNum(int, s16); BOOL dComIfGs_isOneZoneSwitch(int, int); u8 dComIfGp_getSelectItem(int); diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index 7dcaac9cc01..534d990e074 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -186,80 +186,40 @@ bool DynamicModuleControlBase::force_unlink() { return true; } -#ifdef NONMATCHING +/* 80262470-80262660 25CDB0 01F0+00 2/0 2/2 0/0 .text dump__24DynamicModuleControlBaseFv + */ void DynamicModuleControlBase::dump() { + u16 doLinkCount; + u16 linkCount; DynamicModuleControlBase* current = getFirstClass(); - int totalSize = 0; + size_t totalSize = 0; JUTReportConsole_f("\nDynamicModuleControlBase::dump()\n"); JUTReportConsole_f("Do Lnk Size Name\n"); - // lbl_80262608 while (current != NULL) { - // lbl_802624B8 - u16 doLinkCount = current->mDoLinkCount; - u16 linkCount = current->mLinkCount; + doLinkCount = current->mDoLinkCount; + linkCount = current->mLinkCount; if (doLinkCount != 0 || linkCount != 0) { - // lbl_802624D0 u32 size = current->getModuleSize(); const char* name = current->getModuleName(); if (size < 0xFFFFFFFF) { name = (name != NULL) ? name : "(Null)"; - // lbl_80262524 const char* type = current->getModuleTypeString(); JUTReportConsole_f("%3d%3d%5.1f %05x %-4s %-24s ", doLinkCount, linkCount, - size * (1.0f / 1024.0f), size, type, name); + size / 1024.0f, size, type, name); totalSize = totalSize + size; } else { - // lbl_80262588 name = (name != NULL) ? name : "(Null)"; - // lbl_802625A4 const char* type = current->getModuleTypeString(); JUTReportConsole_f("%3d%3d ???? ????? %-4s %-24s ", doLinkCount, linkCount, type, name); } - // lbl_802625DC current->dump2(); JUTReportConsole_f("\n"); } - // lbl_80262604 - current = getNextClass(); + current = current->getNextClass(); } - // lbl_80262608 - JUTReportConsole_f("TotalSize %6.2f %06x\n\n", (1.0f / 1024.0f) * totalSize, totalSize); + JUTReportConsole_f("TotalSize %6.2f %06x\n\n", totalSize / 1024.0f, totalSize); } -#else -/* ############################################################################################## */ -/* 80455008-80455010 003608 0004+04 1/1 0/0 0/0 .sdata2 @3772 */ -SECTION_SDATA2 static f32 lit_3772[1 + 1 /* padding */] = { - 0.0009765625f, // 1/1024 - /* padding */ - 0.0f, -}; - -#pragma push -#pragma force_active on -SECTION_DEAD static char const* const stringBase_8039A4E5 = "\nDynamicModuleControlBase::dump()\n"; -SECTION_DEAD static char const* const stringBase_8039A508 = "Do Lnk Size Name\n"; -SECTION_DEAD static char const* const stringBase_8039A520 = "(Null)"; -SECTION_DEAD static char const* const stringBase_8039A527 = "%3d%3d%5.1f %05x %-4s %-24s "; -SECTION_DEAD static char const* const stringBase_8039A544 = "%3d%3d ???? ????? %-4s %-24s "; -SECTION_DEAD static char const* const stringBase_8039A562 = "\n"; -SECTION_DEAD static char const* const stringBase_8039A564 = "TotalSize %6.2f %06x\n\n"; -#pragma pop - -/* 80455010-80455018 003610 0008+00 1/1 0/0 0/0 .sdata2 @3774 */ -SECTION_SDATA2 static f64 lit_3774 = 4503599627370496.0 /* cast u32 to float */; - -/* 80262470-80262660 25CDB0 01F0+00 2/0 2/2 0/0 .text dump__24DynamicModuleControlBaseFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControlBase::dump() { - nofralloc -#include "asm/DynamicLink/dump__24DynamicModuleControlBaseFv.s" -} -#pragma pop -#endif /* 80262660-802626D0 25CFA0 0070+00 0/0 2/2 0/0 .text __ct__20DynamicModuleControlFPCc */ DynamicModuleControl::DynamicModuleControl(char const* name) { @@ -332,7 +292,8 @@ static u32 calcSum2(u16 const* data, u32 size) { return sum; } -#ifdef NONMATCHING +/* 802627E8-80262AFC 25D128 0314+00 1/0 0/0 0/0 .text do_load__20DynamicModuleControlFv + */ bool DynamicModuleControl::do_load() { if (mModule != NULL) { return true; @@ -341,26 +302,26 @@ bool DynamicModuleControl::do_load() { s32 i = 0; while (true) { if (mModule != NULL) { - JKRHeap::free(mModule, NULL); + JKRFree(mModule); mModule = NULL; } char buffer[64]; snprintf(buffer, 64, "%s.rel", mName); if (mModule == NULL && sArchive != NULL) { if (mModule == NULL) { - mModule = (OSModuleInfo*)JKRArchive::getGlbResource('MMEM', buffer, sArchive); + mModule = (OSModuleInfo*)JKRGetResource('MMEM', buffer, sArchive); if (mModule != NULL) { mResourceType = 1; } } if (mModule == NULL) { - mModule = (OSModuleInfo*)JKRArchive::getGlbResource('AMEM', buffer, sArchive); + mModule = (OSModuleInfo*)JKRGetResource('AMEM', buffer, sArchive); if (mModule != NULL) { mResourceType = 2; } } if (mModule == NULL) { - mModule = (OSModuleInfo*)JKRArchive::getGlbResource('DMEM', buffer, sArchive); + mModule = (OSModuleInfo*)JKRGetResource('DMEM', buffer, sArchive); if (mModule != NULL) { mResourceType = 3; } @@ -368,23 +329,25 @@ bool DynamicModuleControl::do_load() { } if (mModule != NULL) { mSize = sArchive->getExpandedResSize(mModule); - JKRFileLoader::detachResource(mModule, NULL); - } else if (mModule == NULL) { - snprintf(buffer, 64, "/rel/Final/Release/%s.rel", mName); - mModule = (OSModuleInfo*)JKRDvdRipper::loadToMainRAM( - buffer, NULL, EXPAND_SWITCH_UNKNOWN1, 0, heap, - JKRDvdRipper::ALLOC_DIRECTION_FORWARD, 0, NULL, NULL); - if (mModule != NULL) { - mSize = 0; - mResourceType = 7; + JKRDetachResource(mModule, NULL); + } else { + if (mModule == NULL) { + snprintf(buffer, 64, "/rel/Final/Release/%s.rel", mName); + mModule = (OSModuleInfo*)JKRDvdToMainRam( + buffer, NULL, EXPAND_SWITCH_UNKNOWN1, NULL, heap, + JKRDvdRipper::ALLOC_DIRECTION_FORWARD, 0, NULL, NULL); + if (mModule != NULL) { + mSize = 0; + mResourceType = 7; + } } - } - if (mModule == NULL && sFileCache != NULL) { - mModule = (OSModuleInfo*)sFileCache->getResource('rels', buffer); - if (mModule != NULL) { - mSize = 0; - mResourceType = 11; - JKRFileLoader::detachResource(mModule, NULL); + if (mModule == NULL && sFileCache != NULL) { + mModule = (OSModuleInfo*)sFileCache->getResource('rels', buffer); + if (mModule != NULL) { + mSize = 0; + mResourceType = 11; + JKRDetachResource(mModule, NULL); + } } } if (mModule == NULL) { @@ -413,49 +376,22 @@ bool DynamicModuleControl::do_load() { if (i >= 3) { return false; } + } else { + if (unk_33 < 0xFF) { + unk_33++; + } + break; } } + } else { if (unk_33 < 0xFF) { unk_33++; - return true; } - } - if (unk_33 < 0xFF) { - unk_33++; - return true; + break; } } + return true; } -#else -/* ############################################################################################## */ -/* 8039A4A0-8039A4A0 026B00 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */ -#pragma push -#pragma force_active on -SECTION_DEAD static char const* const stringBase_8039A5E1 = "%s.rel"; -SECTION_DEAD static char const* const stringBase_8039A5E8 = "/rel/Final/Release/%s.rel"; -// MWCC ignores mapping of some japanese characters using the -// byte 0x5C (ASCII '\'). This is why this string is hex-encoded. -SECTION_DEAD static char const* const stringBase_8039A602 = - "\x44\x79\x6E\x61\x6D\x69\x63\x4D\x6F\x64\x75\x6C\x65\x43\x6F\x6E\x74\x72\x6F\x6C\x3A\x3A\x64" - "\x6F\x5F\x6C\x6F\x61\x64\x28\x29\x20\x83\x8A\x83\x5C\x81\x5B\x83\x58\x93\xC7\x82\xDD\x8D\x9E" - "\x82\xDD" - "\x8E\xB8\x94\x73\x20\x5B\x25\x73\x5D\x0A"; -SECTION_DEAD static char const* const stringBase_8039A63D = - "DynamicModuleControl::do_load() チェックサムエラー %04x %" - "04x[%s]\n"; -#pragma pop - -/* 802627E8-80262AFC 25D128 0314+00 1/0 0/0 0/0 .text do_load__20DynamicModuleControlFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm bool DynamicModuleControl::do_load() { - nofralloc -#include "asm/DynamicLink/do_load__20DynamicModuleControlFv.s" -} -#pragma pop -#endif /* 80262AFC-80262BC4 25D43C 00C8+00 1/0 0/0 0/0 .text do_load_async__20DynamicModuleControlFv */ BOOL DynamicModuleControl::do_load_async() { @@ -500,96 +436,92 @@ void DynamicModuleControl::dump2() { } } -#ifdef NONMATCHING +/* 80262C5C-80262F28 25D59C 02CC+00 1/0 0/0 0/0 .text do_link__20DynamicModuleControlFv + */ BOOL DynamicModuleControl::do_link() { OSGetTime(); if (mModule == NULL) { do_load(); } - if (mModule != NULL) { ASSERT(mModule->info.sectionInfoOffset < 0x80000000); ASSERT((u32)mModule + mModule->fixSize < 0x82000000); OSGetTime(); OSGetTime(); if (mModule->mModuleVersion >= 3) { - u32 unk = mModule->fixSize; - u32 unk3 = (unk + 0x1f) & ~0x1f; - u32 unk2 = (u32)mModule + unk3; - s32 size = JKRHeap::getSize(mModule, NULL); + u32 fixSizePtr; + u32 fixSize = mModule->fixSize; + u32 fixSize2 = (fixSize + 0x1f) & ~0x1f; + fixSizePtr = (u32)mModule + fixSize2; + s32 size = JKRGetMemBlockSize(NULL, mModule); if (size < 0) { - void* bss = JKRHeap::alloc(mModule->mBssSize, 0x20, NULL); + void* bss = JKRAlloc(mModule->mBssSize, 0x20); if (bss == NULL) { // "BSS Memory allocation failed\n" - OSReport_Error("BSSメモリ確保失敗\n"); - goto end; - } else { - mBss = bss; - BOOL linkResult = OSLink(mModule); - if (linkResult == FALSE) { - // "link failed\n" - OSReport_Error("リンク失敗\n"); - goto end; - } + OSReport_Error("BSSメモリ確保失敗\n", bss); + goto error; + } + mBss = bss; + BOOL linkResult = OSLink(mModule); + if (linkResult == FALSE) { + // "link failed\n" + OSReport_Error("リンク失敗\n"); + goto error; } } else { - if (mModule->mBssSize + unk < size) { - BOOL linkResult = OSLinkFixed(mModule, unk2); + if (fixSize2 + mModule->mBssSize < size) { + BOOL linkResult = OSLinkFixed(mModule, fixSizePtr); if (linkResult == FALSE) { // "link failed\n" OSReport_Error("リンク失敗\n"); - goto end; + goto error; + } + s32 result = JKRResizeMemBlock(NULL, mModule, fixSize2 + mModule->mBssSize); + if (result < 0) { + // "Module size (resize) failed\n" + OSReport_Error("モジュールリサイズ(縮小)失敗\n"); + } + } else { + s32 result = JKRResizeMemBlock(NULL, mModule, fixSize2 + mModule->mBssSize); + if (result > 0) { + BOOL linkResult = OSLinkFixed(mModule, fixSizePtr); + if (linkResult == FALSE) { + // "link failed\n" + OSReport_Error("リンク失敗\n"); + goto error; + } } else { - s32 result = JKRHeap::resize(mModule, mModule->mBssSize + unk, NULL); + void* bss = JKRAlloc(mModule->mBssSize, 0x20); + if (bss == NULL) { + // "BSS Memory allocation failure [%x]\n" + OSReport_Error("BSSメモリ確保失敗 [%x]\n", mModule->mBssSize); + goto error; + } + mBss = bss; + BOOL linkResult = OSLinkFixed(mModule, (u32)bss); + if (linkResult == FALSE) { + // "link failed\n" + OSReport_Error("リンク失敗\n"); + goto error; + } + s32 result = JKRResizeMemBlock(NULL, mModule, fixSize); if (result < 0) { // "Module size (resize) failed\n" OSReport_Error("モジュールリサイズ(縮小)失敗\n"); } } - } else { // lbl_80262DB0 - s32 result = JKRHeap::resize(mModule, mModule->mBssSize + unk, NULL); - if (result > 0) { - BOOL linkResult = OSLinkFixed(mModule, unk2); - if (linkResult == FALSE) { - // "link failed\n" - OSReport_Error("リンク失敗\n"); - goto end; - } - } else { // lbl_80262DF0 - void* bss = JKRHeap::alloc(mModule->mBssSize, 0x20, NULL); - if (bss == NULL) { - // "BSS Memory allocation failure [%x]\n" - OSReport_Error("BSSメモリ確保失敗 [%x]\n", mModule->mBssSize); - goto end; - } else { // lbl_80262E2C - mBss = bss; - BOOL linkResult = OSLinkFixed(mModule, (u32)bss); - if (linkResult == FALSE) { - // "link failed\n" - OSReport_Error("リンク失敗\n"); - goto end; - } - // lbl_80262E58 - s32 result = JKRHeap::resize(mModule, unk3, NULL); - if (result < 0) { - // "Module size (resize) failed\n" - OSReport_Error("モジュールリサイズ(縮小)失敗\n"); - } - } - } } } } - // lbl_80262E84 OSGetTime(); sAllocBytes = sAllocBytes + getModuleSize(); OSGetTime(); - unk_24 = mModule->prolog(); + unk_24 = ((u32(*)())mModule->prolog)(); OSGetTime(); return TRUE; } -end: // lbl_80262ECC +error: unk_33 = 0; if (mBss != NULL) { JKRHeap::free(mBss, NULL); @@ -601,26 +533,6 @@ end: // lbl_80262ECC } return FALSE; } -#else -#pragma push -#pragma force_active on -SECTION_DEAD static char const* const stringBase_8039A6E2 = "BSSメモリ確保失敗\n"; -SECTION_DEAD static char const* const stringBase_8039A6F5 = "リンク失敗\n"; -SECTION_DEAD static char const* const stringBase_8039A701 = "モジュールリサイズ(縮小)失敗\n"; -SECTION_DEAD static char const* const stringBase_8039A71F = "BSSメモリ確保失敗 [%x]\n"; -#pragma pop - -/* 80262C5C-80262F28 25D59C 02CC+00 1/0 0/0 0/0 .text do_link__20DynamicModuleControlFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm BOOL DynamicModuleControl::do_link() { - nofralloc -#include "asm/DynamicLink/do_link__20DynamicModuleControlFv.s" -} -#pragma pop -#endif /* 80262F28-80263000 25D868 00D8+00 1/0 0/0 0/0 .text do_unlink__20DynamicModuleControlFv */ diff --git a/src/c/c_dylink.cpp b/src/c/c_dylink.cpp index e1600538103..7866eab5a0e 100644 --- a/src/c/c_dylink.cpp +++ b/src/c/c_dylink.cpp @@ -961,61 +961,32 @@ int cDylPhs::phase_01(void* param_0) { } /* 8001880C-80018844 01314C 0038+00 1/0 0/0 0/0 .text phase_02__7cDylPhsFPs */ -// instructions switched -#ifdef NONMATCHING int cDylPhs::phase_02(s16* p_profName) { - s32 temp_r3 = cDyl_LinkASync(*p_profName); - s32 phi_r0 = 2; + int ret = cDyl_LinkASync(*p_profName); - if (temp_r3 != 4) { - phi_r0 = temp_r3; + if (ret != 4) { + return ret; } - return phi_r0; + return 2; } -#else -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm int cDylPhs::phase_02(s16* param_0) { - nofralloc -#include "asm/c/c_dylink/phase_02__7cDylPhsFPs.s" -} -#pragma pop -#endif /* 80018844-8001884C 013184 0008+00 1/0 0/0 0/0 .text phase_03__7cDylPhsFPv */ int cDylPhs::phase_03(void* param_0) { return 0; } -/* ############################################################################################## */ -/* 803A3590-803A35A0 -00001 000C+04 1/1 0/0 0/0 .data l_method$3807 */ -SECTION_DATA static request_of_phase_process_fn l_method[3] = { - (request_of_phase_process_fn)cDylPhs::phase_01, - (request_of_phase_process_fn)cDylPhs::phase_02, - (request_of_phase_process_fn)cDylPhs::phase_03, -}; - /* 8001884C-80018890 01318C 0044+00 0/0 2/2 0/0 .text * Link__7cDylPhsFP30request_of_phase_process_classs */ -#ifdef NONMATCHING int cDylPhs::Link(request_of_phase_process_class* i_phase, s16 param_1) { + static int (*l_method[3])(void*) = {cDylPhs::phase_01, (int (*)(void*))cDylPhs::phase_02, + cDylPhs::phase_03}; + if (i_phase->mPhaseStep == 2) { return 4; } - dComLbG_PhaseHandler(i_phase, l_method[0], ¶m_1); + return dComLbG_PhaseHandler(i_phase, l_method, ¶m_1); } -#else -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm int cDylPhs::Link(request_of_phase_process_class* param_0, s16 param_1) { - nofralloc -#include "asm/c/c_dylink/Link__7cDylPhsFP30request_of_phase_process_classs.s" -} -#pragma pop -#endif /* 80018890-800188DC 0131D0 004C+00 0/0 1/1 0/0 .text * Unlink__7cDylPhsFP30request_of_phase_process_classs */ diff --git a/src/d/com/d_com_inf_game.cpp b/src/d/com/d_com_inf_game.cpp index 1b37d72d0b8..f1b59bb10b0 100644 --- a/src/d/com/d_com_inf_game.cpp +++ b/src/d/com/d_com_inf_game.cpp @@ -2526,8 +2526,8 @@ BOOL dComIfGp_TransportWarp_check() { #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void dComLbG_PhaseHandler(request_of_phase_process_class* param_0, int (**param_1)(void*), - void* param_2) { +asm int dComLbG_PhaseHandler(request_of_phase_process_class* param_0, int (**param_1)(void*), + void* param_2) { nofralloc #include "asm/d/com/d_com_inf_game/dComLbG_PhaseHandler__FP30request_of_phase_process_classPPFPv_iPv.s" } diff --git a/tools/package_game_assets.py b/tools/package_game_assets.py index a8ea2e0675d..960ca1cc99b 100644 --- a/tools/package_game_assets.py +++ b/tools/package_game_assets.py @@ -9,12 +9,6 @@ import ctypes import oead -def sha1_from_data(data): - sha1 = hashlib.sha1() - sha1.update(data) - - return sha1.hexdigest().upper() - def copy(path,destPath): for root,dirs,files in os.walk(str(path)): for file in files: @@ -28,11 +22,7 @@ def copy(path,destPath): print(str(inFile)+" -> "+str(outputFile)) shutil.copyfile(inFile,outputFile) else: - inf = open(inFile,"rb") - inSum = sha1_from_data(bytearray(inf.read())) - outf = open(outputFile,"rb") - outSum = sha1_from_data(bytearray(outf.read())) - if inSum!=outSum: + if os.path.getmtime(inFile)>os.path.getmtime(outputFile): print(str(inFile)+" -> "+str(outputFile)) shutil.copyfile(inFile,outputFile)