mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 12:51:42 +00:00
Accept functions directly in GuestToHostFunction & add memory range asserts.
This commit is contained in:
parent
031229166a
commit
588b5677eb
4 changed files with 14 additions and 7 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
SWA_API void Game_PlaySound(const char* pName)
|
SWA_API void Game_PlaySound(const char* pName)
|
||||||
{
|
{
|
||||||
void* soundPlayerSharedPtr = g_userHeap.Alloc(8);
|
void* soundPlayerSharedPtr = g_userHeap.Alloc(8);
|
||||||
GuestToHostFunction<void>(0x82B4DF50, soundPlayerSharedPtr, ((be<uint32_t>*)g_memory.Translate(0x83367900))->get(), 7, 0, 0);
|
GuestToHostFunction<void>(sub_82B4DF50, soundPlayerSharedPtr, ((be<uint32_t>*)g_memory.Translate(0x83367900))->get(), 7, 0, 0);
|
||||||
|
|
||||||
auto soundPlayer = (be<uint32_t>*)g_memory.Translate(*(be<uint32_t>*)soundPlayerSharedPtr);
|
auto soundPlayer = (be<uint32_t>*)g_memory.Translate(*(be<uint32_t>*)soundPlayerSharedPtr);
|
||||||
auto soundPlayerVtable = (be<uint32_t>*)g_memory.Translate(*soundPlayer);
|
auto soundPlayerVtable = (be<uint32_t>*)g_memory.Translate(*soundPlayer);
|
||||||
|
|
@ -18,7 +18,7 @@ SWA_API void Game_PlaySound(const char* pName)
|
||||||
GuestToHostFunction<void>(virtualFunction, soundPlayer, strAllocation, 0);
|
GuestToHostFunction<void>(virtualFunction, soundPlayer, strAllocation, 0);
|
||||||
g_userHeap.Free(strAllocation);
|
g_userHeap.Free(strAllocation);
|
||||||
|
|
||||||
GuestToHostFunction<void>(0x822C0890, *((be<uint32_t>*)soundPlayerSharedPtr + 1));
|
GuestToHostFunction<void>(sub_822C0890, *((be<uint32_t>*)soundPlayerSharedPtr + 1));
|
||||||
g_userHeap.Free(soundPlayerSharedPtr);
|
g_userHeap.Free(soundPlayerSharedPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -301,8 +301,8 @@ FORCEINLINE PPC_FUNC(HostToGuestFunction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... TArgs>
|
template<typename T, typename TFunction, typename... TArgs>
|
||||||
FORCEINLINE T GuestToHostFunction(uint32_t addr, TArgs... argv)
|
FORCEINLINE T GuestToHostFunction(const TFunction& func, TArgs... argv)
|
||||||
{
|
{
|
||||||
auto args = std::make_tuple(argv...);
|
auto args = std::make_tuple(argv...);
|
||||||
auto& currentCtx = *GetPPCContext();
|
auto& currentCtx = *GetPPCContext();
|
||||||
|
|
@ -313,10 +313,15 @@ FORCEINLINE T GuestToHostFunction(uint32_t addr, TArgs... argv)
|
||||||
newCtx.r13 = currentCtx.r13;
|
newCtx.r13 = currentCtx.r13;
|
||||||
newCtx.fpscr = currentCtx.fpscr;
|
newCtx.fpscr = currentCtx.fpscr;
|
||||||
|
|
||||||
_translate_args_to_guest<GuestToHostFunction<T, TArgs...>>(newCtx, (uint8_t*)g_memory.base, args);
|
_translate_args_to_guest<GuestToHostFunction<T, TFunction, TArgs...>>(newCtx, (uint8_t*)g_memory.base, args);
|
||||||
|
|
||||||
SetPPCContext(newCtx);
|
SetPPCContext(newCtx);
|
||||||
(*(PPCFunc**)(newCtx.fn + uint64_t(addr) * 2))(newCtx, (uint8_t*)g_memory.base);
|
|
||||||
|
if constexpr (std::is_function_v<TFunction>)
|
||||||
|
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;
|
currentCtx.fpscr = newCtx.fpscr;
|
||||||
SetPPCContext(currentCtx);
|
SetPPCContext(currentCtx);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,13 @@ public:
|
||||||
|
|
||||||
void* Translate(size_t offset) const noexcept
|
void* Translate(size_t offset) const noexcept
|
||||||
{
|
{
|
||||||
|
assert(offset < 0x100000000ull);
|
||||||
return base + offset;
|
return base + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t MapVirtual(void* host) const noexcept
|
uint32_t MapVirtual(void* host) const noexcept
|
||||||
{
|
{
|
||||||
|
assert(host >= base && host < (base + size));
|
||||||
return static_cast<uint32_t>(static_cast<char*>(host) - base);
|
return static_cast<uint32_t>(static_cast<char*>(host) - base);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
2
thirdparty/PowerRecomp
vendored
2
thirdparty/PowerRecomp
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 62e3188a811aef25e84f63bd2957432e081a6dad
|
Subproject commit 7dd4f91ac635b001a56cc7a27af48f0436bbad3f
|
||||||
Loading…
Add table
Reference in a new issue