lib: sync XbSymbolDatabase

This commit is contained in:
RadWolfie 2023-01-12 13:34:45 -06:00
parent 111728f170
commit b2f05b8b0b
8 changed files with 181 additions and 199 deletions

@ -1 +1 @@
Subproject commit 75ce58fa8d135ef0a75bee729cde9542eda393b6
Subproject commit 313ed04a76e1079178652fa0deaf78c96c061e37

View File

@ -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,13 +3169,9 @@ 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
@ -3188,6 +3189,21 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(D3DDevice_Reset)
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();
@ -9010,7 +9090,26 @@ xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_GetProjectionViewportMatrix)
// ******************************************************************
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();
}
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;

View File

@ -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
);
@ -1898,6 +1902,7 @@ 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_8)(xbox::addr_xt _this, xbox::ulong_xt Unknown1);
// ******************************************************************
// * patch: CDevice_SetStateUP (D3D::CDevice::SetStateUP)

View File

@ -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");

View File

@ -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;
}

View File

@ -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!");
}
}
}

View File

@ -58,6 +58,7 @@ std::map<const std::string, const xbox_patch_t> 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<const std::string, const xbox_patch_t> 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<const std::string, const xbox_patch_t> 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<const std::string, const xbox_patch_t> 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),

View File

@ -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");
// Get address to xpp type's devices
if (xbox::addr_xt gamepad_xpp_type = g_SymbolAddresses["g_DeviceType_Gamepad"]) {
g_DeviceType_Gamepad = reinterpret_cast<xbox::PXPP_DEVICE_TYPE>(gamepad_xpp_type);
}
// 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;
#if 0 // Not implemented
if (xbox::addr_xt ir_dongle_xpp_type = g_SymbolAddresses["g_DeviceType_IRDongle"]) {
g_DeviceType_IRDongle = reinterpret_cast<xbox::PXPP_DEVICE_TYPE>(ir_dongle_xpp_type);
}
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;
if (xbox::addr_xt keyboard_xpp_type = g_SymbolAddresses["g_DeviceType_Keyboard"]) {
g_DeviceType_Keyboard = reinterpret_cast<xbox::PXPP_DEVICE_TYPE>(keyboard_xpp_type);
}
if (xbox::addr_xt mouse_xpp_type = g_SymbolAddresses["g_DeviceType_Mouse"]) {
g_DeviceType_Mouse = reinterpret_cast<xbox::PXPP_DEVICE_TYPE>(mouse_xpp_type);
}
} 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);
#endif
if (xbox::addr_xt sbc_xpp_type = g_SymbolAddresses["g_DeviceType_SBC"]) {
g_DeviceType_SBC = reinterpret_cast<xbox::PXPP_DEVICE_TYPE>(sbc_xpp_type);
}
}
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);
}
if (xbox::addr_xt mu_xpp_type = g_SymbolAddresses["g_DeviceType_MU"]) {
g_DeviceType_MU = reinterpret_cast<xbox::PXPP_DEVICE_TYPE>(mu_xpp_type);
EmuLog(LOG_LEVEL::INFO, "XDEVICE_TYPE_MEMORY_UNIT found at 0x%08X", reinterpret_cast<uintptr_t>(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<xbox::ulong_xt*>(xapi_mounted_mu);
EmuLog(LOG_LEVEL::INFO, "XapiMountedMUs found at 0x%08X", reinterpret_cast<uintptr_t>(g_XapiMountedMUs));
g_XapiAltLett_MU = reinterpret_cast<xbox::char_xt *>(g_XapiMountedMUs - 1);
EmuLog(LOG_LEVEL::INFO, "XapiAltLett_MU found at 0x%08X", reinterpret_cast<uintptr_t>(g_XapiAltLett_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<xbox::char_xt *>(xapi_alt_lett_mu);
}
}