diff --git a/configure.py b/configure.py index d9ce213eb..b91fbea8e 100755 --- a/configure.py +++ b/configure.py @@ -360,7 +360,7 @@ config.libs = [ "host": True, "objects": [ Object(NonMatching, "c/c_damagereaction.cpp"), - Object(MatchingFor("GZLJ01", "GZLE01", "GZLP01"), "c/c_dylink.cpp"), + Object(Matching, "c/c_dylink.cpp"), ], }, { diff --git a/include/DynamicLink.h b/include/DynamicLink.h index 0433926ed..db9df4235 100644 --- a/include/DynamicLink.h +++ b/include/DynamicLink.h @@ -18,12 +18,16 @@ struct DynamicModuleControlBase { virtual const char* getModuleName() const { return NULL; } virtual int getModuleSize() const { return 0; } virtual const char* getModuleTypeString() const { return "Base"; } +#if VERSION == VERSION_DEMO + static void dump(); +#else #if __MWERKS__ && __MWERKS__ < 0x4200 // This is illegal function overloading, but MWCC for GC allows it. MWCC for Wii does not. virtual void dump(); #endif static void dump(); virtual void dump2() {} +#endif virtual bool do_load() { return true; } virtual BOOL do_load_async() { return TRUE; } virtual bool do_unload() { return true; } @@ -48,7 +52,9 @@ struct DynamicModuleControl : DynamicModuleControlBase { virtual const char* getModuleName() const { return mName; } virtual int getModuleSize() const; virtual const char* getModuleTypeString() const; +#if VERSION != VERSION_DEMO virtual void dump2(); +#endif virtual bool do_load(); virtual BOOL do_load_async(); virtual bool do_unload(); @@ -56,6 +62,7 @@ struct DynamicModuleControl : DynamicModuleControlBase { virtual bool do_unlink(); DynamicModuleControl(char const*); static JKRArchive* mountCallback(void*); + static void mountCreate(); static bool initialize(); static bool callback(void*); @@ -66,12 +73,14 @@ struct DynamicModuleControl : DynamicModuleControlBase { /* 0x20 */ u8 mResourceType; /* 0x21 */ u8 unk_33; /* 0x22 */ u16 mChecksum; +#if VERSION != VERSION_DEMO /* 0x24 */ s32 mSize; +#endif /* 0x28 */ mDoDvdThd_callback_c* mAsyncLoadCallback; static u32 sAllocBytes; static JKRArchive* sArchive; static JKRFileCache* sFileCache; -}; +}; // Size: 0x2C #endif /* DYNAMICLINK_H */ diff --git a/include/JSystem/JKernel/JKRFileCache.h b/include/JSystem/JKernel/JKRFileCache.h index 892f1670b..c9c34f08d 100644 --- a/include/JSystem/JKernel/JKRFileCache.h +++ b/include/JSystem/JKernel/JKRFileCache.h @@ -63,4 +63,8 @@ inline JKRFileCache* JKRMountDvdDrive(const char* path, JKRHeap* heap, const cha return JKRFileCache::mount(path, heap, param_2); } +inline void JKRUnmountDvdDrive(JKRFileCache* cache) { + cache->unmount(); +} + #endif /* JKRFILECACHE_H */ diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index 17ef7b21a..e16f788b6 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -50,32 +50,46 @@ DynamicModuleControlBase::DynamicModuleControlBase() { } BOOL DynamicModuleControlBase::link() { +#if VERSION != VERSION_DEMO OSThread* thread = OSGetCurrentThread(); if (thread != &mainThread) { OSReport_Error("DynamicModuleControlBase::link not mainthread %08x\n", thread); } +#endif if (mLinkCount == 0) { do_load(); if (do_link() == false) { return false; } +#if VERSION == VERSION_DEMO + mDoLinkCount++; +#else if (mDoLinkCount < 0xFFFF) { mDoLinkCount++; } +#endif } +#if VERSION != VERSION_DEMO JUT_ASSERT(100, mLinkCount < 65535); +#endif +#if VERSION == VERSION_DEMO + mLinkCount++; +#else if (mLinkCount < 0xFFFF) { mLinkCount++; } +#endif return true; } BOOL DynamicModuleControlBase::unlink() { +#if VERSION != VERSION_DEMO OSThread* thread = OSGetCurrentThread(); if (thread != &mainThread) { OSReport_Error("DynamicModuleControlBase::unlink not mainthread %08x\n", thread); } +#endif if (mLinkCount != 0) { mLinkCount--; @@ -106,16 +120,19 @@ bool DynamicModuleControlBase::force_unlink() { } void DynamicModuleControlBase::dump() { - u16 doLinkCount; - u16 linkCount; DynamicModuleControlBase* current = getFirstClass(); size_t totalSize = 0; JUTReportConsole_f("\nDynamicModuleControlBase::dump()\n"); JUTReportConsole_f("Do Ln Size Name\n"); while (current != NULL) { - doLinkCount = current->mDoLinkCount; - linkCount = current->mLinkCount; - if (doLinkCount != 0 || linkCount != 0) { +#if VERSION == VERSION_DEMO + u32 doLinkCount = current->mDoLinkCount; + u32 linkCount = current->mLinkCount; +#else + u16 doLinkCount = current->mDoLinkCount; + u16 linkCount = current->mLinkCount; +#endif + if (current->mDoLinkCount != 0 || current->mLinkCount != 0) { u32 size = current->getModuleSize(); const char* name = current->getModuleName(); if (size < 0xFFFFFFFF) { @@ -130,7 +147,9 @@ void DynamicModuleControlBase::dump() { JUTReportConsole_f("%3d%3d ???? ????? %-4s %s\n", doLinkCount, linkCount, type, name); } +#if VERSION != VERSION_DEMO current->dump2(); +#endif } current = current->getNextClass(); } @@ -143,9 +162,11 @@ DynamicModuleControl::DynamicModuleControl(char const* name) { unk_24 = 0; mName = name; mResourceType = 0; +#if VERSION != VERSION_DEMO unk_33 = 0; mChecksum = 0; mSize = 0; +#endif mAsyncLoadCallback = NULL; } @@ -171,6 +192,10 @@ JKRArchive* DynamicModuleControl::mountCallback(void* param_0) { return sArchive; } +void DynamicModuleControl::mountCreate() { + mDoDvdThd_callback_c::create((mDoDvdThd_callback_func)DynamicModuleControl::callback, NULL); +} + bool DynamicModuleControl::initialize() { sFileCache = NULL; sAllocBytes = 0; @@ -194,6 +219,48 @@ static u32 calcSum2(u16 const* data, u32 size) { return sum; } +#if VERSION == VERSION_DEMO +bool DynamicModuleControl::do_load() { + /* Nonmatching - sArchive load order */ + if (mModule != NULL) { + return true; + } + char buffer[64]; + snprintf(buffer, 64, "%s.rel", mName); + if (mModule == NULL && sArchive != NULL) { + if (mModule == NULL) { + mModule = (OSModuleHeader*)JKRGetResource('MMEM', buffer, sArchive); + if (mModule != NULL) { + mResourceType = 1; + } + } + if (mModule == NULL) { + mModule = (OSModuleHeader*)JKRGetResource('AMEM', buffer, sArchive); + if (mModule != NULL) { + mResourceType = 2; + } + } + if (mModule == NULL) { + mModule = (OSModuleHeader*)JKRGetResource('DMEM', buffer, sArchive); + if (mModule != NULL) { + mResourceType = 3; + } + } + } + if (mModule == NULL) { + mModule = (OSModuleHeader*)sFileCache->getResource('rels', buffer); + if (mModule != NULL) { + mResourceType = 3; + } + } + if (mModule == NULL) { + // "DynamicModuleControl::do_load() Resource load failure [%s]\n" + OSReport_Error("DynamicModuleControl::do_load() リソース読み込み失敗 [%s]\n", mName); + return false; + } + return true; +} +#else bool DynamicModuleControl::do_load() { if (mModule != NULL) { return true; @@ -287,6 +354,7 @@ bool DynamicModuleControl::do_load() { } return true; } +#endif BOOL DynamicModuleControl::do_load_async() { if (mAsyncLoadCallback == NULL) { @@ -312,12 +380,17 @@ BOOL DynamicModuleControl::do_load_async() { bool DynamicModuleControl::do_unload() { if (mModule != NULL) { +#if VERSION == VERSION_DEMO + JKRFileLoader::removeResource(mModule, NULL); +#else JKRFree(mModule); +#endif mModule = NULL; } return true; } +#if VERSION != VERSION_DEMO void DynamicModuleControl::dump2() { if (mModule != NULL) { OSSectionInfo* section = (OSSectionInfo*)mModule->info.sectionInfoOffset; @@ -326,6 +399,7 @@ void DynamicModuleControl::dump2() { mModule->impSize); } } +#endif BOOL DynamicModuleControl::do_link() { OSGetTime(); @@ -333,8 +407,10 @@ BOOL DynamicModuleControl::do_link() { do_load(); } if (mModule != NULL) { - JUT_ASSERT(613, mModule->info.sectionInfoOffset < 0x80000000); + JUT_ASSERT(VERSION_SELECT(501, 613, 613, 613), mModule->info.sectionInfoOffset < 0x80000000); +#if VERSION != VERSION_DEMO JUT_ASSERT(615, (u32)mModule + mModule->fixSize < 0x82000000); +#endif OSGetTime(); OSGetTime(); if (mModule->info.version >= 3) { @@ -402,7 +478,7 @@ BOOL DynamicModuleControl::do_link() { } } } else { - JUT_ASSERT(724, FALSE); + JUT_ASSERT(VERSION_SELECT(610, 724, 724, 724), FALSE); } OSGetTime(); sAllocBytes = sAllocBytes + getModuleSize(); @@ -413,13 +489,19 @@ BOOL DynamicModuleControl::do_link() { } error: +#if VERSION != VERSION_DEMO unk_33 = 0; +#endif if (mBss != NULL) { - JKRHeap::free(mBss, NULL); + JKRFree(mBss); mBss = NULL; } if (mModule != NULL) { +#if VERSION == VERSION_DEMO + JKRFileLoader::removeResource(mModule, NULL); +#else JKRHeap::free(mModule, NULL); +#endif mModule = NULL; } return FALSE; @@ -484,7 +566,7 @@ extern "C" void ModuleUnresolved() { } extern "C" void ModuleConstructorsX(void (**_ctors)()) { - JUT_ASSERT(850, _ctors); + JUT_ASSERT(VERSION_SELECT(726, 850, 850, 850), _ctors); while (*_ctors != 0) { (**_ctors)(); _ctors++; @@ -492,7 +574,7 @@ extern "C" void ModuleConstructorsX(void (**_ctors)()) { } extern "C" void ModuleDestructorsX(void (**_dtors)()) { - JUT_ASSERT(864, _dtors); + JUT_ASSERT(VERSION_SELECT(740, 864, 864, 864), _dtors); while (*_dtors != 0) { (**_dtors)(); _dtors++; diff --git a/src/c/c_dylink.cpp b/src/c/c_dylink.cpp index 0c0f62d84..e66f0b249 100644 --- a/src/c/c_dylink.cpp +++ b/src/c/c_dylink.cpp @@ -17,9 +17,12 @@ #include "string.h" DynamicModuleControlBase * DMC[PROC_COUNT_e]; +#if VERSION != VERSION_DEMO bool DMC_initialized = false; -BOOL cDyl_Initialized = false; +#endif +volatile BOOL cDyl_Initialized = false; mDoDvdThd_callback_c * cDyl_DVD = NULL; +JKRSolidHeap* cCc_solidHeap = NULL; const DynamicNameTableEntry DynamicNameTable[] = { {PROC_ALLDIE, "d_a_alldie"}, @@ -186,6 +189,9 @@ const DynamicNameTableEntry DynamicNameTable[] = { {PROC_MANT, "d_a_mant"}, {PROC_KANTERA, "d_a_kantera"}, {PROC_KAMOME, "d_a_kamome"}, +#if VERSION == VERSION_DEMO + {PROC_KAMOME2, "d_a_kamome2"}, +#endif {PROC_NPC_KAM, "d_a_npc_kamome"}, {PROC_WBIRD, "d_a_wbird"}, {PROC_DEMO_KMM, "d_a_demo_kmm"}, @@ -457,10 +463,17 @@ const DynamicNameTableEntry DynamicNameTable[] = { /* 800227A0-800229E0 .text cCc_Init__Fv */ BOOL cCc_Init() { +#if VERSION != VERSION_DEMO JUT_ASSERT(0x2a, !DMC_initialized); +#endif +#if VERSION == VERSION_DEMO + JKRExpHeap * pHeap = mDoExt_getArchiveHeap(); + cCc_solidHeap = mDoExt_createSolidHeapToCurrent(0, NULL, 0); +#else JKRSolidHeap * pHeap = JKRSolidHeap::create(0x5648, mDoExt_getArchiveHeap(), false); JKRHeap * pOldHeap = pHeap->becomeCurrentHeap(); +#endif memset(DMC, 0, sizeof(DMC)); for (int i = 0; i < ARRAY_SIZE(DynamicNameTable); i++) { @@ -468,8 +481,8 @@ BOOL cCc_Init() { if (d.name == NULL) continue; - JUT_ASSERT(0x39, d.mKey < ARRAY_SIZE(DMC)); - JUT_ASSERT(0x3a, DMC[d.mKey] == NULL); + JUT_ASSERT(VERSION_SELECT(47, 57, 57, 57), d.mKey < ARRAY_SIZE(DMC)); + JUT_ASSERT(VERSION_SELECT(48, 58, 58, 58), DMC[d.mKey] == NULL); for (int j = 0; j < ARRAY_SIZE(DMC); j++) { if (DMC[j] != NULL) { @@ -481,18 +494,28 @@ BOOL cCc_Init() { } if (DMC[d.mKey] == NULL) +#if VERSION == VERSION_DEMO + DMC[d.mKey] = new (pHeap, 0) DynamicModuleControl(d.name); +#else DMC[d.mKey] = new DynamicModuleControl(d.name); +#endif } +#if VERSION == VERSION_DEMO + mDoExt_restoreCurrentHeap(); + mDoExt_adjustSolidHeap(cCc_solidHeap); +#else pHeap->adjustSize(); pOldHeap->becomeCurrentHeap(); DMC_initialized = TRUE; +#endif + return TRUE; } /* 800229E0-80022A80 .text cDyl_IsLinked__Fs */ BOOL cDyl_IsLinked(s16 i_ProfName) { - JUT_ASSERT(0xae, cDyl_Initialized); + JUT_ASSERT(VERSION_SELECT(134, 174, 174, 174), cDyl_Initialized); if (DMC[i_ProfName] != NULL) return DMC[i_ProfName]->isLinked(); @@ -502,8 +525,8 @@ BOOL cDyl_IsLinked(s16 i_ProfName) { /* 80022A80-80022B58 .text cDyl_Unlink__Fs */ BOOL cDyl_Unlink(s16 i_ProfName) { - JUT_ASSERT(0xc5, cDyl_Initialized); - JUT_ASSERT(0xc6, i_ProfName < ARRAY_SIZE(DMC)); + JUT_ASSERT(VERSION_SELECT(154, 197, 197, 197), cDyl_Initialized); + JUT_ASSERT(VERSION_SELECT(155, 198, 198, 198), i_ProfName < ARRAY_SIZE(DMC)); if (DMC[i_ProfName] != NULL) return DMC[i_ProfName]->unlink(); @@ -511,32 +534,65 @@ BOOL cDyl_Unlink(s16 i_ProfName) { return FALSE; } -static void dummy(s16 i_ProfName) { - OSReport_Error("cDyl_Link i_ProfName=%d\n", i_ProfName); +cPhs_State cDyl_Link(s16 i_ProfName) { + JUT_ASSERT(180, cDyl_Initialized); + if (i_ProfName >= ARRAY_SIZE(DMC)) { + OSReport_Error("cDyl_Link i_ProfName=%d\n", i_ProfName); + return cPhs_ERROR_e; + } + JUT_ASSERT(185, i_ProfName < ARRAY_SIZE(DMC)); + if (DMC[i_ProfName]) { + if (DMC[i_ProfName]->link()) { + return cPhs_COMPLEATE_e; + } else { + return cPhs_ERROR_e; + } + } else { + return cPhs_COMPLEATE_e; + } +} + +#if VERSION != VERSION_DEMO +static void dummy() { OSReport_Error("cDyl_LinkASync: リンクに失敗しました。諦めます\n"); } +#endif /* 80022B58-80022CEC .text cDyl_LinkASync__Fs */ cPhs_State cDyl_LinkASync(s16 i_ProfName) { - JUT_ASSERT(0x101, DMC_initialized); +#if VERSION == VERSION_DEMO + if (!cDyl_Initialized) { + OSReport_Error("初期化が終わってないのに呼んでもらっても困ります %d\n", i_ProfName); + return cPhs_INIT_e; + } +#endif +#if VERSION == VERSION_DEMO + JUT_ASSERT(203, cDyl_Initialized); +#else + JUT_ASSERT(257, DMC_initialized); if (!cDyl_Initialized) return cPhs_INIT_e; +#endif if (i_ProfName >= ARRAY_SIZE(DMC)) { OSReport_Error("cDyl_Link i_ProfName=%d\n", i_ProfName); return cPhs_ERROR_e; } - JUT_ASSERT(0x111, i_ProfName < ARRAY_SIZE(DMC)); + JUT_ASSERT(VERSION_SELECT(208, 273, 273, 273), i_ProfName < ARRAY_SIZE(DMC)); DynamicModuleControlBase * d = DMC[i_ProfName]; if (d != NULL) { +#if VERSION != VERSION_DEMO JUT_ASSERT(0x115, cDyl_Initialized); +#endif if (d->load_async()) { if (d->link()) { return cPhs_COMPLEATE_e; } else { +#if VERSION != VERSION_DEMO OSReport_Error("cDyl_LinkASync: リンクに失敗しました。諦めます\n"); +#endif return cPhs_ERROR_e; } } @@ -549,25 +605,31 @@ cPhs_State cDyl_LinkASync(s16 i_ProfName) { /* 80022CEC-80022DF8 .text cDyl_InitCallback__FPv */ BOOL cDyl_InitCallback(void*) { - JUT_ASSERT(0x12f, !cDyl_Initialized); - JKRFileLoader * pFileLoader = JKRFileCache::mount("/", mDoExt_getArchiveHeap(), NULL); + JUT_ASSERT(VERSION_SELECT(230, 303, 303, 303), !cDyl_Initialized); + JKRFileCache* loader = JKRMountDvdDrive("/", mDoExt_getArchiveHeap(), NULL); DynamicModuleControl::initialize(); - void * pData = JKRFileLoader::getGlbResource("/dvd/framework.str"); - JKRFileLoader::detachResource(pData, pFileLoader); - pFileLoader->unmount(); - OSSetStringTable(pData); + + void* strTbl = (void*)JKRGetResource("/dvd/framework.str"); + JKRDetachResource(strTbl, loader); + JKRUnmountDvdDrive(loader); + OSSetStringTable(strTbl); DynamicModuleControl dmc("f_pc_profile_lst"); dmc.link(); +#if VERSION == VERSION_DEMO + cCc_Init(); +#endif cDyl_Initialized = TRUE; return TRUE; } /* 80022DF8-80022E70 .text cDyl_InitAsync__Fv */ void cDyl_InitAsync() { +#if VERSION != VERSION_DEMO cCc_Init(); +#endif - JUT_ASSERT(0x145, cDyl_DVD == NULL); + JUT_ASSERT(VERSION_SELECT(252, 325, 325, 325), cDyl_DVD == NULL); cDyl_DVD = mDoDvdThd_callback_c::create((mDoDvdThd_callback_func) cDyl_InitCallback, NULL); } @@ -617,7 +679,7 @@ cPhs_State cDylPhs::Link(request_of_phase_process_class* i_phase, s16 profName) /* 80022F68-80023004 .text Unlink__7cDylPhsFP30request_of_phase_process_classs */ BOOL cDylPhs::Unlink(request_of_phase_process_class* i_phase, s16 profName) { - JUT_ASSERT(0x1a6, i_phase->id != 1); + JUT_ASSERT(VERSION_SELECT(357, 422, 422, 422), i_phase->id != 1); BOOL ret; if (i_phase->id == 2) {