diff --git a/UnleashedRecomp/exports.cpp b/UnleashedRecomp/exports.cpp index c09c29cb..c792646f 100644 --- a/UnleashedRecomp/exports.cpp +++ b/UnleashedRecomp/exports.cpp @@ -6,7 +6,7 @@ SWA_API void Game_PlaySound(const char* pName) { void* soundPlayerSharedPtr = g_userHeap.Alloc(8); - GuestToHostFunction(0x82B4DF50, soundPlayerSharedPtr, ((be*)g_memory.Translate(0x83367900))->get(), 7, 0, 0); + GuestToHostFunction(sub_82B4DF50, soundPlayerSharedPtr, ((be*)g_memory.Translate(0x83367900))->get(), 7, 0, 0); auto soundPlayer = (be*)g_memory.Translate(*(be*)soundPlayerSharedPtr); auto soundPlayerVtable = (be*)g_memory.Translate(*soundPlayer); @@ -18,7 +18,7 @@ SWA_API void Game_PlaySound(const char* pName) GuestToHostFunction(virtualFunction, soundPlayer, strAllocation, 0); g_userHeap.Free(strAllocation); - GuestToHostFunction(0x822C0890, *((be*)soundPlayerSharedPtr + 1)); + GuestToHostFunction(sub_822C0890, *((be*)soundPlayerSharedPtr + 1)); g_userHeap.Free(soundPlayerSharedPtr); } diff --git a/UnleashedRecomp/kernel/function.h b/UnleashedRecomp/kernel/function.h index ee41a742..7c110fcc 100644 --- a/UnleashedRecomp/kernel/function.h +++ b/UnleashedRecomp/kernel/function.h @@ -301,8 +301,8 @@ FORCEINLINE PPC_FUNC(HostToGuestFunction) } } -template -FORCEINLINE T GuestToHostFunction(uint32_t addr, TArgs... argv) +template +FORCEINLINE T GuestToHostFunction(const TFunction& func, TArgs... argv) { auto args = std::make_tuple(argv...); auto& currentCtx = *GetPPCContext(); @@ -313,10 +313,15 @@ FORCEINLINE T GuestToHostFunction(uint32_t addr, TArgs... argv) newCtx.r13 = currentCtx.r13; newCtx.fpscr = currentCtx.fpscr; - _translate_args_to_guest>(newCtx, (uint8_t*)g_memory.base, args); + _translate_args_to_guest>(newCtx, (uint8_t*)g_memory.base, args); SetPPCContext(newCtx); - (*(PPCFunc**)(newCtx.fn + uint64_t(addr) * 2))(newCtx, (uint8_t*)g_memory.base); + + if constexpr (std::is_function_v) + func(newCtx, (uint8_t*)g_memory.base); + else + (*(PPCFunc**)(newCtx.fn + uint64_t(func) * 2))(newCtx, (uint8_t*)g_memory.base); + currentCtx.fpscr = newCtx.fpscr; SetPPCContext(currentCtx); diff --git a/UnleashedRecomp/kernel/memory.h b/UnleashedRecomp/kernel/memory.h index 8cea4c4f..8ff4504c 100644 --- a/UnleashedRecomp/kernel/memory.h +++ b/UnleashedRecomp/kernel/memory.h @@ -16,11 +16,13 @@ public: void* Translate(size_t offset) const noexcept { + assert(offset < 0x100000000ull); return base + offset; } uint32_t MapVirtual(void* host) const noexcept { + assert(host >= base && host < (base + size)); return static_cast(static_cast(host) - base); } }; diff --git a/thirdparty/PowerRecomp b/thirdparty/PowerRecomp index 62e3188a..7dd4f91a 160000 --- a/thirdparty/PowerRecomp +++ b/thirdparty/PowerRecomp @@ -1 +1 @@ -Subproject commit 62e3188a811aef25e84f63bd2957432e081a6dad +Subproject commit 7dd4f91ac635b001a56cc7a27af48f0436bbad3f