From c79b11109f5404c3501c59a805bcbf6070b3f71a Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Tue, 8 Oct 2019 16:24:47 +0100 Subject: [PATCH] Fix crash in pixel shaders caused undefined behavior in LTCG handler --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index bec7ed67a..6afc5c8da 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -6806,25 +6806,30 @@ VOID __declspec(noinline) D3DDevice_SetPixelShaderCommon(DWORD Handle) // This uses a custom calling convention where parameter is passed in EAX // Test-case: Metal Wolf Chaos // Test-case: Lord of the Rings: The Third Age -VOID WINAPI XTL::EMUPATCH(D3DDevice_SetPixelShader_0) +VOID WINAPI D3DDevice_SetPixelShader_0_IMPL ( + DWORD Handle ) { - DWORD Handle; - __asm mov Handle, eax; + LOG_FUNC_ONE_ARG(Handle); - //LOG_FUNC_ONE_ARG(Handle); - - EmuLog(LOG_LEVEL::DEBUG, "D3DDevice_SetPixelShader_0(Handle : %d);", Handle); - - // Call the Xbox function to make sure D3D structures get set - XB_trampoline(VOID, WINAPI, D3DDevice_SetPixelShader_0, ()); + // Call the Xbox function to make sure D3D structures get set + XB_trampoline(VOID, WINAPI, D3DDevice_SetPixelShader_0, ()); __asm { mov eax, Handle call XB_D3DDevice_SetPixelShader_0 } - D3DDevice_SetPixelShaderCommon(Handle); + D3DDevice_SetPixelShaderCommon(Handle); +} + +VOID WINAPI XTL::EMUPATCH(D3DDevice_SetPixelShader_0)() +{ + __asm { + push eax + call D3DDevice_SetPixelShader_0_IMPL + ret + } } // ******************************************************************