diff --git a/import/XbSymbolDatabase b/import/XbSymbolDatabase index 75ce58fa8..313ed04a7 160000 --- a/import/XbSymbolDatabase +++ b/import/XbSymbolDatabase @@ -1 +1 @@ -Subproject commit 75ce58fa8d135ef0a75bee729cde9542eda393b6 +Subproject commit 313ed04a76e1079178652fa0deaf78c96c061e37 diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index fe0877296..79f6bb446 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -320,15 +320,17 @@ g_EmuCDPD; /*XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_LoadVertexShader_4, (xbox::dword_xt) );*/\ XB_MACRO(xbox::hresult_xt, WINAPI, D3DDevice_PersistDisplay, (xbox::void_xt) ); \ XB_MACRO(xbox::hresult_xt, WINAPI, D3DDevice_Reset, (xbox::X_D3DPRESENT_PARAMETERS*) ); \ + XB_MACRO(xbox::hresult_xt, WINAPI, D3DDevice_Reset_0__LTCG_edi1, () ); \ + XB_MACRO(xbox::hresult_xt, WINAPI, D3DDevice_Reset_0__LTCG_ebx1, () ); \ /*XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SelectVertexShader, (xbox::dword_xt, xbox::dword_xt) );*/\ - /*XB_MACRO(xbox::void_xt, __stdcall, D3DDevice_SelectVertexShader_0, () );*/\ - /*XB_MACRO(xbox::void_xt, __stdcall, D3DDevice_SelectVertexShader_4, (xbox::dword_xt) );*/\ + /*XB_MACRO(xbox::void_xt, __stdcall, D3DDevice_SelectVertexShader_0__LTCG_eax1_ebx2, () );*/\ + /*XB_MACRO(xbox::void_xt, __stdcall, D3DDevice_SelectVertexShader_4__LTCG_eax1, (xbox::dword_xt) );*/\ /*XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetGammaRamp, (xbox::dword_xt, CONST X_D3DGAMMARAMP*) );*/\ XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetIndices, (xbox::X_D3DIndexBuffer*, xbox::uint_xt) ); \ XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetIndices_4, (xbox::uint_xt) ); \ XB_MACRO(xbox::hresult_xt, WINAPI, D3DDevice_SetLight, (xbox::dword_xt, CONST xbox::X_D3DLIGHT8*) ); \ XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetPixelShader, (xbox::dword_xt) ); \ - XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetPixelShader_0, () ); \ + XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetPixelShader_0__LTCG_eax_handle, () ); \ XB_MACRO(xbox::void_xt, __fastcall, D3DDevice_SetRenderState_Simple, (xbox::dword_xt, xbox::dword_xt) ); \ XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetRenderTarget, (xbox::X_D3DSurface*, xbox::X_D3DSurface*) ); \ XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetRenderTarget_0, () ); \ @@ -339,7 +341,7 @@ g_EmuCDPD; XB_MACRO(xbox::void_xt, __fastcall, D3DDevice_SetStreamSource_8__LTCG_edx_StreamNumber, (void*, xbox::uint_xt, xbox::X_D3DVertexBuffer*, xbox::uint_xt) ); \ XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetTexture, (xbox::dword_xt, xbox::X_D3DBaseTexture*) ); \ XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetTexture_4__LTCG_eax_pTexture, (xbox::dword_xt) ); \ - XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetTexture_4, (xbox::X_D3DBaseTexture*) ); \ + XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetTexture_4__LTCG_eax_Stage, (xbox::X_D3DBaseTexture*) ); \ XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetPalette, (xbox::dword_xt, xbox::X_D3DPalette*) ); \ XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetPalette_4, (xbox::X_D3DPalette*) ); \ XB_MACRO(xbox::void_xt, WINAPI, D3DDevice_SetVertexShader, (xbox::dword_xt) ); \ @@ -2813,10 +2815,13 @@ void Direct3D_CreateDevice_End { #if 0 // Unused : // Set g_Xbox_D3DDevice to point to the Xbox D3D Device - auto it = g_SymbolAddresses.find("D3DDEVICE"); + auto it = g_SymbolAddresses.find("D3D_g_pDevice"); if (it != g_SymbolAddresses.end()) { g_Xbox_D3DDevice = (DWORD*)it->second; } + else { + EmuLog(LOG_LEVEL::ERROR2, "D3D_g_pDevice was not found!"); + } #endif UpdateHostBackBufferDesc(); @@ -3164,30 +3169,41 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(Direct3D_CreateDevice) // ****************************************************************** // * patch: D3DDevice_Reset // ****************************************************************** -xbox::hresult_xt WINAPI xbox::EMUPATCH(D3DDevice_Reset) -( - X_D3DPRESENT_PARAMETERS* pPresentationParameters -) -{ - LOG_FUNC_ONE_ARG(pPresentationParameters) +static void CxbxImpl_Reset(xbox::X_D3DPRESENT_PARAMETERS* pPresentationParameters) +{ // Unlike the host version of Reset, The Xbox version does not actually reset the entire device // Instead, it simply re-creates the backbuffer with a new configuration // Store the new multisampling configuration SetXboxMultiSampleType(pPresentationParameters->MultiSampleType); - // Update scaling aspect ratio - SetAspectRatioScale(pPresentationParameters); + // Update scaling aspect ratio + SetAspectRatioScale(pPresentationParameters); // Since Reset will call create a new backbuffer surface, we can clear our current association // NOTE: We don't actually free the Xbox data, the Xbox side will do this for us when we call the trampoline below. // We must not reset the values to nullptr, since the XDK will re-use the same addresses for the data headers // (they are members of the Direct3DDevice object). if we overwrite then, the reference to the xbox backbuffer will be lost - // and we'll get a black screen. + // and we'll get a black screen. FreeHostResource(GetHostResourceKey(g_pXbox_BackBufferSurface)); FreeHostResource(GetHostResourceKey(g_pXbox_DefaultDepthStencilSurface)); - + + // Below requirement for patched function(s) in order to function properly. + // Perform xbox's D3DDevice_Reset call. + + // Perform CxbxImpl_SetRenderTarget call. +} + +xbox::hresult_xt WINAPI xbox::EMUPATCH(D3DDevice_Reset) +( + X_D3DPRESENT_PARAMETERS* pPresentationParameters +) +{ + LOG_FUNC_ONE_ARG(pPresentationParameters); + + CxbxImpl_Reset(pPresentationParameters); + // Call the Xbox Reset function to do the rest of the work for us hresult_xt hRet = XB_TRMP(D3DDevice_Reset)(pPresentationParameters); @@ -3198,6 +3214,70 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(D3DDevice_Reset) return hRet; } +static void D3DDevice_Reset_0__LTCG_edi1(xbox::X_D3DPRESENT_PARAMETERS* pPresentationParameters) +{ + LOG_FUNC_ONE_ARG(pPresentationParameters); +} + +__declspec(naked) xbox::hresult_xt WINAPI xbox::EMUPATCH(D3DDevice_Reset_0__LTCG_edi1)() +{ + X_D3DPRESENT_PARAMETERS* pPresentationParameters; + __asm { + LTCG_PROLOGUE + mov pPresentationParameters, edi + } + + // Log + D3DDevice_Reset_0__LTCG_edi1(pPresentationParameters); + + CxbxImpl_Reset(pPresentationParameters); + + // Call the Xbox version of DestroyResource + __asm { + mov edi, pPresentationParameters + call XB_TRMP(D3DDevice_Reset_0__LTCG_edi1) + } + + CxbxImpl_SetRenderTarget(g_pXbox_RenderTarget, g_pXbox_DepthStencil); + + __asm { + LTCG_EPILOGUE + ret + } +} + +static void D3DDevice_Reset_0__LTCG_ebx1(xbox::X_D3DPRESENT_PARAMETERS* pPresentationParameters) +{ + LOG_FUNC_ONE_ARG(pPresentationParameters); +} + +__declspec(naked) xbox::hresult_xt WINAPI xbox::EMUPATCH(D3DDevice_Reset_0__LTCG_ebx1)() +{ + X_D3DPRESENT_PARAMETERS* pPresentationParameters; + __asm { + LTCG_PROLOGUE + mov pPresentationParameters, ebx + } + + // Log + D3DDevice_Reset_0__LTCG_ebx1(pPresentationParameters); + + CxbxImpl_Reset(pPresentationParameters); + + // Call the Xbox version of DestroyResource + __asm { + mov ebx, pPresentationParameters + call XB_TRMP(D3DDevice_Reset_0__LTCG_ebx1) + } + + CxbxImpl_SetRenderTarget(g_pXbox_RenderTarget, g_pXbox_DepthStencil); + + __asm { + LTCG_EPILOGUE + ret + } +} + // ****************************************************************** // * patch: D3DDevice_GetDisplayFieldStatus @@ -3587,7 +3667,7 @@ xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_LoadVertexShader) } // Overload for logging -static void D3DDevice_SelectVertexShader_0 +static void D3DDevice_SelectVertexShader_0__LTCG_eax1_ebx2 ( xbox::dword_xt Handle, xbox::dword_xt Address @@ -3602,7 +3682,7 @@ static void D3DDevice_SelectVertexShader_0 // LTCG specific D3DDevice_SelectVertexShader function... // This uses a custom calling convention where parameter is passed in EAX, EBX // Test-case: Star Wars - Battlefront -__declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SelectVertexShader_0) +__declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SelectVertexShader_0__LTCG_eax1_ebx2) ( ) { @@ -3615,7 +3695,7 @@ __declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SelectVertexShad } // Log - D3DDevice_SelectVertexShader_0(Handle, Address); + D3DDevice_SelectVertexShader_0__LTCG_eax1_ebx2(Handle, Address); CxbxImpl_SelectVertexShader(Handle, Address); @@ -3626,7 +3706,7 @@ __declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SelectVertexShad } // Overload for logging -static void D3DDevice_SelectVertexShader_4 +static void D3DDevice_SelectVertexShader_4__LTCG_eax1 ( xbox::dword_xt Handle, xbox::dword_xt Address @@ -3641,7 +3721,7 @@ static void D3DDevice_SelectVertexShader_4 // LTCG specific D3DDevice_SelectVertexShader function... // This uses a custom calling convention where parameter is passed in EAX // Test-case: Aggressive Inline -__declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SelectVertexShader_4) +__declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SelectVertexShader_4__LTCG_eax1) ( dword_xt Address ) @@ -3653,7 +3733,7 @@ __declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SelectVertexShad } // Log - D3DDevice_SelectVertexShader_4(Handle, Address); + D3DDevice_SelectVertexShader_4__LTCG_eax1(Handle, Address); CxbxImpl_SelectVertexShader(Handle, Address); @@ -4371,7 +4451,7 @@ __declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SetTexture_4__LT } // Overload for logging -static void D3DDevice_SetTexture_4 +static void D3DDevice_SetTexture_4__LTCG_eax_Stage ( xbox::dword_xt Stage, xbox::X_D3DBaseTexture *pTexture @@ -4386,7 +4466,7 @@ static void D3DDevice_SetTexture_4 // LTCG specific D3DDevice_SetTexture function... // This uses a custom calling convention where Stage is passed in EAX // Test-case: Metal Wolf Chaos -__declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SetTexture_4) +__declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SetTexture_4__LTCG_eax_Stage) ( X_D3DBaseTexture *pTexture ) @@ -4398,13 +4478,13 @@ __declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SetTexture_4) } // Log - D3DDevice_SetTexture_4(Stage, pTexture); + D3DDevice_SetTexture_4__LTCG_eax_Stage(Stage, pTexture); // Call the Xbox implementation of this function, to properly handle reference counting for us __asm { mov eax, Stage push pTexture - call XB_TRMP(D3DDevice_SetTexture_4) + call XB_TRMP(D3DDevice_SetTexture_4__LTCG_eax_Stage) } g_pXbox_SetTexture[Stage] = pTexture; @@ -7712,7 +7792,7 @@ xbox::void_xt CxbxImpl_SetPixelShader(xbox::dword_xt Handle) } // Overload for logging -static void D3DDevice_SetPixelShader_0 +static void D3DDevice_SetPixelShader_0__LTCG_eax_handle ( xbox::dword_xt Handle ) @@ -7725,7 +7805,7 @@ static void D3DDevice_SetPixelShader_0 // Test-case: Metal Wolf Chaos // Test-case: Lord of the Rings: The Third Age // Test-case: Midtown Madness 3 -__declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SetPixelShader_0)() +__declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SetPixelShader_0__LTCG_eax_handle)() { dword_xt Handle; __asm { @@ -7734,11 +7814,11 @@ __declspec(naked) xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_SetPixelShader_0 } // Log - D3DDevice_SetPixelShader_0(Handle); + D3DDevice_SetPixelShader_0__LTCG_eax_handle(Handle); __asm { mov eax, Handle - call XB_TRMP(D3DDevice_SetPixelShader_0) + call XB_TRMP(D3DDevice_SetPixelShader_0__LTCG_eax_handle) } CxbxImpl_SetPixelShader(Handle); @@ -7815,7 +7895,7 @@ xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_DrawVertices) return; } - // TODO : Call unpatched CDevice_SetStateVB(0); + // TODO : Call unpatched CDevice_SetStateVB[_8](0); CxbxUpdateNativeD3DResources(); @@ -7999,7 +8079,7 @@ xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_DrawIndexedVertices) return; } - // TODO : Call unpatched CDevice_SetStateVB(g_Xbox_BaseVertexIndex); + // TODO : Call unpatched CDevice_SetStateVB[_8](g_Xbox_BaseVertexIndex); CxbxUpdateNativeD3DResources(); @@ -9008,14 +9088,33 @@ xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_GetProjectionViewportMatrix) // ****************************************************************** // * patch: CDevice_SetStateVB (D3D::CDevice::SetStateVB) // ****************************************************************** -xbox::void_xt WINAPI xbox::EMUPATCH(CDevice_SetStateVB)(ulong_xt Unknown1 ) +xbox::void_xt WINAPI xbox::EMUPATCH(CDevice_SetStateVB)(ulong_xt Unknown1) { - LOG_FUNC_ONE_ARG(Unknown1); + addr_xt _this; + __asm mov _this, ecx; + + LOG_FUNC_BEGIN + LOG_FUNC_ARG(_this) + LOG_FUNC_ARG(Unknown1) + LOG_FUNC_END; // TODO: Anything? // __asm int 3; - LOG_UNIMPLEMENTED(); + LOG_UNIMPLEMENTED(); +} + +xbox::void_xt WINAPI xbox::EMUPATCH(CDevice_SetStateVB_8)(addr_xt _this, ulong_xt Unknown1) +{ + LOG_FUNC_BEGIN + LOG_FUNC_ARG(_this) + LOG_FUNC_ARG(Unknown1) + LOG_FUNC_END; + + // TODO: Anything? +// __asm int 3; + + LOG_UNIMPLEMENTED(); } // ****************************************************************** diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.h b/src/core/hle/D3D8/Direct3D9/Direct3D9.h index 36ed559d2..14ce0000e 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.h +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.h @@ -213,8 +213,8 @@ xbox::void_xt WINAPI EMUPATCH(D3DDevice_SelectVertexShader) dword_xt Address ); -xbox::void_xt WINAPI EMUPATCH(D3DDevice_SelectVertexShader_0)(); -xbox::void_xt WINAPI EMUPATCH(D3DDevice_SelectVertexShader_4) +xbox::void_xt WINAPI EMUPATCH(D3DDevice_SelectVertexShader_0__LTCG_eax1_ebx2)(); +xbox::void_xt WINAPI EMUPATCH(D3DDevice_SelectVertexShader_4__LTCG_eax1) ( dword_xt Address ); @@ -359,6 +359,10 @@ xbox::hresult_xt WINAPI EMUPATCH(D3DDevice_Reset) X_D3DPRESENT_PARAMETERS *pPresentationParameters ); +xbox::hresult_xt WINAPI EMUPATCH(D3DDevice_Reset_0__LTCG_edi1)(); + +xbox::hresult_xt WINAPI EMUPATCH(D3DDevice_Reset_0__LTCG_ebx1)(); + // ****************************************************************** // * patch: D3DDevice_GetRenderTarget // ****************************************************************** @@ -505,7 +509,7 @@ xbox::void_xt WINAPI EMUPATCH(D3DDevice_SetPixelShader) dword_xt Handle ); -xbox::void_xt WINAPI EMUPATCH(D3DDevice_SetPixelShader_0)(); +xbox::void_xt WINAPI EMUPATCH(D3DDevice_SetPixelShader_0__LTCG_eax_handle)(); // ****************************************************************** // * patch: D3DDevice_CreateTexture2 @@ -611,7 +615,7 @@ xbox::void_xt WINAPI EMUPATCH(D3DDevice_SetTexture_4__LTCG_eax_pTexture) dword_xt Stage ); -xbox::void_xt WINAPI EMUPATCH(D3DDevice_SetTexture_4) +xbox::void_xt WINAPI EMUPATCH(D3DDevice_SetTexture_4__LTCG_eax_Stage) ( X_D3DBaseTexture *pTexture ); @@ -1897,7 +1901,8 @@ xbox::void_xt WINAPI EMUPATCH(D3DDevice_GetTexture) // ****************************************************************** // * patch: CDevice_SetStateVB (D3D::CDevice::SetStateVB) // ****************************************************************** -xbox::void_xt WINAPI EMUPATCH(CDevice_SetStateVB)( xbox::ulong_xt Unknown1 ); +xbox::void_xt WINAPI EMUPATCH(CDevice_SetStateVB)(xbox::ulong_xt Unknown1); +xbox::void_xt WINAPI EMUPATCH(CDevice_SetStateVB_8)(xbox::addr_xt _this, xbox::ulong_xt Unknown1); // ****************************************************************** // * patch: CDevice_SetStateUP (D3D::CDevice::SetStateUP) diff --git a/src/core/hle/D3D8/Direct3D9/RenderStates.cpp b/src/core/hle/D3D8/Direct3D9/RenderStates.cpp index e617eb30b..6b57ded62 100644 --- a/src/core/hle/D3D8/Direct3D9/RenderStates.cpp +++ b/src/core/hle/D3D8/Direct3D9/RenderStates.cpp @@ -36,20 +36,14 @@ void SetXboxMultiSampleType(xbox::X_D3DMULTISAMPLE_TYPE value); bool XboxRenderStateConverter::Init() { - if (g_SymbolAddresses.find("D3DDeferredRenderState") != g_SymbolAddresses.end()) { - D3D__RenderState = (uint32_t*)g_SymbolAddresses["D3DDeferredRenderState"]; + // Get render state + if (g_SymbolAddresses.find("D3D_g_RenderState") != g_SymbolAddresses.end()) { + D3D__RenderState = (uint32_t*)g_SymbolAddresses["D3D_g_RenderState"]; } else { + EmuLog(LOG_LEVEL::ERROR2, "D3D_g_RenderState was not found!"); return false; } - // At this point, D3D__RenderState points to the first Deferred render state - // Do a little magic to verify that it's correct, then count back to determine the - // start offset of the entire structure - VerifyAndFixDeferredRenderStateOffset(); - - // Now use the verified Deferred offset to derive the D3D__RenderState offset - DeriveRenderStateOffsetFromDeferredRenderStateOffset(); - // Build a mapping of Cxbx Render State indexes to indexes within the current XDK BuildRenderStateMappingTable(); @@ -70,54 +64,6 @@ bool IsRenderStateAvailableInCurrentXboxD3D8Lib(RenderStateInfo& aRenderStateInf return bIsRenderStateAvailable; } -void XboxRenderStateConverter::VerifyAndFixDeferredRenderStateOffset() -{ - DWORD CullModeOffset = g_SymbolAddresses["D3DRS_CULLMODE"]; - // If we found a valid CullMode offset, verify the symbol location - if (CullModeOffset == 0) { - EmuLog(LOG_LEVEL::WARNING, "D3DRS_CULLMODE could not be found. Please update the XbSymbolDatabase submodule"); - return; - } - - // Calculate index of D3DRS_CULLMODE for this XDK. We start counting from the first deferred state (D3DRS_FOGENABLE) - DWORD CullModeIndex = 0; - for (int i = xbox::X_D3DRS_DEFERRED_FIRST; i < xbox::X_D3DRS_CULLMODE; i++) { - auto RenderStateInfo = GetDxbxRenderStateInfo(i); - if (IsRenderStateAvailableInCurrentXboxD3D8Lib(RenderStateInfo)) { - CullModeIndex++; - } - } - - // If the offset was incorrect, calculate the correct offset, log it, and fix it - if ((DWORD)(&D3D__RenderState[CullModeIndex]) != CullModeOffset) { - DWORD CorrectOffset = CullModeOffset - (CullModeIndex * sizeof(DWORD)); - EmuLog(LOG_LEVEL::WARNING, "EmuD3DDeferredRenderState returned by XboxSymbolDatabase (0x%08X) was incorrect. Correcting to be 0x%08X.\nPlease file an issue with the XbSymbolDatabase project", D3D__RenderState, CorrectOffset); - D3D__RenderState = (uint32_t*)CorrectOffset; - } -} - -void XboxRenderStateConverter::DeriveRenderStateOffsetFromDeferredRenderStateOffset() -{ - // When this function is called. D3D__RenderState actually points to the first deferred render state - // (this is X_D3DRS_FOGENABLE). We can count back from this using our RenderStateInfo table to find - // the start of D3D__RenderStates. - - // Count the number of render states (for this XDK) between 0 and the first deferred render state (D3DRS_FOGENABLE) - int FirstDeferredRenderStateOffset = 0; - for (unsigned int RenderState = xbox::X_D3DRS_FIRST; RenderState < xbox::X_D3DRS_DEFERRED_FIRST; RenderState++) { - // if the current renderstate exists in this XDK version, count it - auto RenderStateInfo = GetDxbxRenderStateInfo(RenderState); - if (IsRenderStateAvailableInCurrentXboxD3D8Lib(RenderStateInfo)) { - FirstDeferredRenderStateOffset++; - } - } - - // At this point, FirstDeferredRenderStateOffset should point to the index of D3DRS_FOGENABLE for the given XDK - // This will be correct as long as our table DxbxRenderStateInfo is correct - // We can get the correct 0 offset by using a negative index - D3D__RenderState = &D3D__RenderState[-FirstDeferredRenderStateOffset]; -} - void XboxRenderStateConverter::BuildRenderStateMappingTable() { EmuLog(LOG_LEVEL::INFO, "Building Cxbx to XDK Render State Mapping Table"); diff --git a/src/core/hle/D3D8/Direct3D9/TextureStates.cpp b/src/core/hle/D3D8/Direct3D9/TextureStates.cpp index cd761472a..96a5426d7 100644 --- a/src/core/hle/D3D8/Direct3D9/TextureStates.cpp +++ b/src/core/hle/D3D8/Direct3D9/TextureStates.cpp @@ -79,11 +79,12 @@ TextureStateInfo CxbxTextureStateInfo[] = { bool XboxTextureStateConverter::Init(XboxRenderStateConverter* pState) { - // Deferred states start at 0, this means that D3DDeferredTextureState IS D3D__TextureState + // Deferred states start at 0, this means that D3D_g_DeferredTextureState IS D3D__TextureState // No further works is required to derive the offset - if (g_SymbolAddresses.find("D3DDeferredTextureState") != g_SymbolAddresses.end()) { - D3D__TextureState = (uint32_t*)g_SymbolAddresses["D3DDeferredTextureState"]; + if (g_SymbolAddresses.find("D3D_g_DeferredTextureState") != g_SymbolAddresses.end()) { + D3D__TextureState = (uint32_t*)g_SymbolAddresses["D3D_g_DeferredTextureState"]; } else { + EmuLog(LOG_LEVEL::ERROR2, "D3D_g_DeferredTextureState was not found!"); return false; } diff --git a/src/core/hle/Intercept.cpp b/src/core/hle/Intercept.cpp index aff13632f..f0e0e9c14 100644 --- a/src/core/hle/Intercept.cpp +++ b/src/core/hle/Intercept.cpp @@ -205,6 +205,7 @@ void CDECL EmuOutputMessage(xb_output_message mFlag, void CDECL EmuRegisterSymbol(const char* library_str, uint32_t library_flag, + uint32_t xref_index, const char* symbol_str, uint32_t func_addr, uint32_t revision) @@ -438,22 +439,6 @@ void EmuHLEIntercept(Xbe::Header *pXbeHeader) << " -> " << functionName << "\n"; std::printf(output.str().c_str()); } - - // Fix up Render state and Texture States - if (g_SymbolAddresses.find("D3DDeferredRenderState") == g_SymbolAddresses.end() - || g_SymbolAddresses["D3DDeferredRenderState"] == 0) { - EmuLog(LOG_LEVEL::WARNING, "EmuD3DDeferredRenderState was not found!"); - } - - if (g_SymbolAddresses.find("D3DDeferredTextureState") == g_SymbolAddresses.end() - || g_SymbolAddresses["D3DDeferredTextureState"] == 0) { - EmuLog(LOG_LEVEL::WARNING, "EmuD3DDeferredTextureState was not found!"); - } - - if (g_SymbolAddresses.find("D3DDEVICE") == g_SymbolAddresses.end() - || g_SymbolAddresses["D3DDEVICE"] == 0) { - EmuLog(LOG_LEVEL::WARNING, "D3DDEVICE was not found!"); - } } } diff --git a/src/core/hle/Patches.cpp b/src/core/hle/Patches.cpp index 74e0b3d2d..7c115ef02 100644 --- a/src/core/hle/Patches.cpp +++ b/src/core/hle/Patches.cpp @@ -58,6 +58,7 @@ std::map g_PatchTable = { // Direct3D PATCH_ENTRY("CDevice_SetStateUP", xbox::EMUPATCH(CDevice_SetStateUP), PATCH_HLE_D3D), PATCH_ENTRY("CDevice_SetStateVB", xbox::EMUPATCH(CDevice_SetStateVB), PATCH_HLE_D3D), + PATCH_ENTRY("CDevice_SetStateVB_8", xbox::EMUPATCH(CDevice_SetStateVB_8), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_Begin", xbox::EMUPATCH(D3DDevice_Begin), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_BeginPush", xbox::EMUPATCH(D3DDevice_BeginPush), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_BeginPush2", xbox::EMUPATCH(D3DDevice_BeginPush2), PATCH_HLE_D3D), @@ -118,12 +119,14 @@ std::map g_PatchTable = { PATCH_ENTRY("D3DDevice_Present", xbox::EMUPATCH(D3DDevice_Present), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_PrimeVertexCache", xbox::EMUPATCH(D3DDevice_PrimeVertexCache), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_Reset", xbox::EMUPATCH(D3DDevice_Reset), PATCH_HLE_D3D), + PATCH_ENTRY("D3DDevice_Reset_0__LTCG_edi1", xbox::EMUPATCH(D3DDevice_Reset_0__LTCG_edi1), PATCH_HLE_D3D), + PATCH_ENTRY("D3DDevice_Reset_0__LTCG_ebx1", xbox::EMUPATCH(D3DDevice_Reset_0__LTCG_ebx1), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_RunPushBuffer", xbox::EMUPATCH(D3DDevice_RunPushBuffer), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_RunVertexStateShader", xbox::EMUPATCH(D3DDevice_RunVertexStateShader), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SelectVertexShader", xbox::EMUPATCH(D3DDevice_SelectVertexShader), PATCH_HLE_D3D), //PATCH_ENTRY("D3DDevice_SelectVertexShaderDirect", xbox::EMUPATCH(D3DDevice_SelectVertexShaderDirect), PATCH_HLE_D3D), - PATCH_ENTRY("D3DDevice_SelectVertexShader_0", xbox::EMUPATCH(D3DDevice_SelectVertexShader_0), PATCH_HLE_D3D), - PATCH_ENTRY("D3DDevice_SelectVertexShader_4", xbox::EMUPATCH(D3DDevice_SelectVertexShader_4), PATCH_HLE_D3D), + PATCH_ENTRY("D3DDevice_SelectVertexShader_0__LTCG_eax1_ebx2", xbox::EMUPATCH(D3DDevice_SelectVertexShader_0__LTCG_eax1_ebx2), PATCH_HLE_D3D), + PATCH_ENTRY("D3DDevice_SelectVertexShader_4__LTCG_eax1", xbox::EMUPATCH(D3DDevice_SelectVertexShader_4__LTCG_eax1), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetBackBufferScale", xbox::EMUPATCH(D3DDevice_SetBackBufferScale), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetDepthClipPlanes", xbox::EMUPATCH(D3DDevice_SetDepthClipPlanes), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetFlickerFilter", xbox::EMUPATCH(D3DDevice_SetFlickerFilter), PATCH_HLE_D3D), @@ -138,7 +141,7 @@ std::map g_PatchTable = { PATCH_ENTRY("D3DDevice_SetPalette_4", xbox::EMUPATCH(D3DDevice_SetPalette_4), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetPixelShader", xbox::EMUPATCH(D3DDevice_SetPixelShader), PATCH_HLE_D3D), //PATCH_ENTRY("D3DDevice_SetPixelShaderConstant_4", xbox::EMUPATCH(D3DDevice_SetPixelShaderConstant_4), PATCH_HLE_D3D), - PATCH_ENTRY("D3DDevice_SetPixelShader_0", xbox::EMUPATCH(D3DDevice_SetPixelShader_0), PATCH_HLE_D3D), + PATCH_ENTRY("D3DDevice_SetPixelShader_0__LTCG_eax_handle", xbox::EMUPATCH(D3DDevice_SetPixelShader_0__LTCG_eax_handle), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetRenderState_Simple", xbox::EMUPATCH(D3DDevice_SetRenderState_Simple), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetRenderTarget", xbox::EMUPATCH(D3DDevice_SetRenderTarget), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetRenderTargetFast", xbox::EMUPATCH(D3DDevice_SetRenderTargetFast), PATCH_HLE_D3D), @@ -156,7 +159,7 @@ std::map g_PatchTable = { PATCH_ENTRY("D3DDevice_SetSwapCallback", xbox::EMUPATCH(D3DDevice_SetSwapCallback), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetTexture", xbox::EMUPATCH(D3DDevice_SetTexture), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetTexture_4__LTCG_eax_pTexture", xbox::EMUPATCH(D3DDevice_SetTexture_4__LTCG_eax_pTexture), PATCH_HLE_D3D), - PATCH_ENTRY("D3DDevice_SetTexture_4", xbox::EMUPATCH(D3DDevice_SetTexture_4), PATCH_HLE_D3D), + PATCH_ENTRY("D3DDevice_SetTexture_4__LTCG_eax_Stage", xbox::EMUPATCH(D3DDevice_SetTexture_4__LTCG_eax_Stage), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetTransform", xbox::EMUPATCH(D3DDevice_SetTransform), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetTransform_0__LTCG_eax1_edx2", xbox::EMUPATCH(D3DDevice_SetTransform_0__LTCG_eax1_edx2), PATCH_HLE_D3D), PATCH_ENTRY("D3DDevice_SetVertexData2f", xbox::EMUPATCH(D3DDevice_SetVertexData2f), PATCH_HLE_D3D), diff --git a/src/core/hle/XAPI/Xapi.cpp b/src/core/hle/XAPI/Xapi.cpp index ee381df8b..a17c1682f 100644 --- a/src/core/hle/XAPI/Xapi.cpp +++ b/src/core/hle/XAPI/Xapi.cpp @@ -399,91 +399,34 @@ void DestructHleInputDevice(DeviceState *dev) void SetupXboxDeviceTypes() { - // If we don't yet have the offset to gDeviceType_Gamepad, work it out! - if (g_DeviceType_Gamepad == nullptr) { - // First, attempt to find GetTypeInformation - auto typeInformation = g_SymbolAddresses.find("GetTypeInformation"); - if (typeInformation != g_SymbolAddresses.end() && typeInformation->second != xbox::zero) { - EmuLog(LOG_LEVEL::INFO, "Deriving XDEVICE_TYPE_GAMEPAD from DeviceTable (via GetTypeInformation)"); - // Read the offset values of the device table structure from GetTypeInformation - xbox::addr_xt deviceTableStartOffset = *(uint32_t*)((uint32_t)typeInformation->second + 0x01); - xbox::addr_xt deviceTableEndOffset = *(uint32_t*)((uint32_t)typeInformation->second + 0x09); - - // Calculate the number of device entires in the table - size_t deviceTableEntryCount = (deviceTableEndOffset - deviceTableStartOffset) / sizeof(uint32_t); - - EmuLog(LOG_LEVEL::INFO, "DeviceTableStart: 0x%08X", deviceTableStartOffset); - EmuLog(LOG_LEVEL::INFO, "DeviceTableEnd: 0x%08X", deviceTableEndOffset); - EmuLog(LOG_LEVEL::INFO, "DeviceTable Entires: %u", deviceTableEntryCount); - - // Sanity check: Where all these device offsets within Xbox memory - if ((deviceTableStartOffset >= g_SystemMaxMemory) || (deviceTableEndOffset >= g_SystemMaxMemory)) { - CxbxrAbort("DeviceTable Location is outside of Xbox Memory range"); - } - - // Iterate through the table until we find gamepad - xbox::PXID_TYPE_INFORMATION* deviceTable = (xbox::PXID_TYPE_INFORMATION*)(deviceTableStartOffset); - for (unsigned int i = 0; i < deviceTableEntryCount; i++) { - // Skip empty table entries - if (deviceTable[i] == nullptr) { - continue; - } - - EmuLog(LOG_LEVEL::INFO, "----------------------------------------"); - EmuLog(LOG_LEVEL::INFO, "DeviceTable[%u]->ucType = %d", i, deviceTable[i]->ucType); - - switch (deviceTable[i]->ucType) { - case XINPUT_DEVTYPE_GAMEPAD: - g_DeviceType_Gamepad = deviceTable[i]->XppType; - EmuLog(LOG_LEVEL::INFO, "DeviceTable[%u]->XppType = 0x%08X (XDEVICE_TYPE_GAMEPAD)", i, (uintptr_t)g_DeviceType_Gamepad); - break; - - case XINPUT_DEVTYPE_STEELBATTALION: - g_DeviceType_SBC = deviceTable[i]->XppType; - EmuLog(LOG_LEVEL::INFO, "DeviceTable[%u]->XppType = 0x%08X (XDEVICE_TYPE_STEELBATTALION)", i, (uintptr_t)g_DeviceType_SBC); - break; - - default: - EmuLog(LOG_LEVEL::WARNING, "DeviceTable[%u]->XppType = 0x%08X (Unknown device type)", i, (uintptr_t)deviceTable[i]->XppType); - continue; - } - } - } else { - // XDKs without GetTypeInformation have the GamePad address hardcoded in XInputOpen - // Only the earliest XDKs use this code path, and the offset never changed between them - // so this works well for us. - void* XInputOpenAddr = (void*)g_SymbolAddresses["XInputOpen"]; - if (XInputOpenAddr != nullptr) { - EmuLog(LOG_LEVEL::INFO, "Deriving XDEVICE_TYPE_GAMEPAD from XInputOpen (0x%08X)", (uintptr_t)XInputOpenAddr); - g_DeviceType_Gamepad = *(xbox::PXPP_DEVICE_TYPE*)((uint32_t)XInputOpenAddr + 0x0B); - } - } - - if (g_DeviceType_Gamepad == nullptr) { - EmuLog(LOG_LEVEL::WARNING, "XDEVICE_TYPE_GAMEPAD was not found"); - return; - } - - EmuLog(LOG_LEVEL::INFO, "XDEVICE_TYPE_GAMEPAD found at 0x%08X", (uintptr_t)g_DeviceType_Gamepad); + // Get address to xpp type's devices + if (xbox::addr_xt gamepad_xpp_type = g_SymbolAddresses["g_DeviceType_Gamepad"]) { + g_DeviceType_Gamepad = reinterpret_cast(gamepad_xpp_type); + } +#if 0 // Not implemented + if (xbox::addr_xt ir_dongle_xpp_type = g_SymbolAddresses["g_DeviceType_IRDongle"]) { + g_DeviceType_IRDongle = reinterpret_cast(ir_dongle_xpp_type); + } + if (xbox::addr_xt keyboard_xpp_type = g_SymbolAddresses["g_DeviceType_Keyboard"]) { + g_DeviceType_Keyboard = reinterpret_cast(keyboard_xpp_type); + } + if (xbox::addr_xt mouse_xpp_type = g_SymbolAddresses["g_DeviceType_Mouse"]) { + g_DeviceType_Mouse = reinterpret_cast(mouse_xpp_type); + } +#endif + if (xbox::addr_xt sbc_xpp_type = g_SymbolAddresses["g_DeviceType_SBC"]) { + g_DeviceType_SBC = reinterpret_cast(sbc_xpp_type); } - if (xbox::addr_xt mu_xpp_type = g_SymbolAddresses["g_DeviceType_MU"]) { g_DeviceType_MU = reinterpret_cast(mu_xpp_type); - EmuLog(LOG_LEVEL::INFO, "XDEVICE_TYPE_MEMORY_UNIT found at 0x%08X", reinterpret_cast(g_DeviceType_MU)); - } - else { - EmuLog(LOG_LEVEL::INFO, "XDEVICE_TYPE_MEMORY_UNIT was not found by XbSymbolDatabase"); } + // Get additional variables relative to Memory Unit if (xbox::addr_xt xapi_mounted_mu = g_SymbolAddresses["g_XapiMountedMUs"]) { - g_XapiMountedMUs = reinterpret_cast(xapi_mounted_mu); - EmuLog(LOG_LEVEL::INFO, "XapiMountedMUs found at 0x%08X", reinterpret_cast(g_XapiMountedMUs)); - - g_XapiAltLett_MU = reinterpret_cast(g_XapiMountedMUs - 1); - EmuLog(LOG_LEVEL::INFO, "XapiAltLett_MU found at 0x%08X", reinterpret_cast(g_XapiAltLett_MU)); + g_XapiMountedMUs = reinterpret_cast(xapi_mounted_mu); } - else { - EmuLog(LOG_LEVEL::INFO, "XapiMountedMUs was not found by XbSymbolDatabase"); + if (xbox::addr_xt xapi_alt_lett_mu = g_SymbolAddresses["g_XapiAltLett_MU"]) { + g_XapiAltLett_MU = reinterpret_cast(xapi_alt_lett_mu); } }