diff --git a/include/xref/d3d8.def b/include/xref/d3d8.def index 40cd863b..6ecd722d 100644 --- a/include/xref/d3d8.def +++ b/include/xref/d3d8.def @@ -12,6 +12,7 @@ XREF_SYMBOL(D3D_g_ComplexRenderState) XREF_SYMBOL(D3D_g_DeferredTextureState) XREF_SYMBOL(D3D_g_pDevice) XREF_SYMBOL(D3D_g_Stream) +XREF_SYMBOL(D3D_g_Stream_i_pVertexBuffer) XREF_SYMBOL(D3DRS_BackFillMode) XREF_SYMBOL(D3DRS_CullMode) XREF_SYMBOL(D3DRS_Dxt1NoiseEnable) diff --git a/projects/libXbSymbolDatabase/CMakeLists.txt b/projects/libXbSymbolDatabase/CMakeLists.txt index e081e3e9..755cd11b 100644 --- a/projects/libXbSymbolDatabase/CMakeLists.txt +++ b/projects/libXbSymbolDatabase/CMakeLists.txt @@ -41,12 +41,14 @@ file(GLOB HEADERS "${XBSDB_ROOT_DIR}/src/lib/manual_jvs.h" "${XBSDB_ROOT_DIR}/src/lib/manual_xapilib.h" "${XBSDB_ROOT_DIR}/src/OOVPADatabase/OOVPA.h" + "${XBSDB_ROOT_DIR}/src/OOVPADatabase/OOVPA_databases.h" ) source_group(TREE ${XBSDB_ROOT_DIR}/src PREFIX header FILES ${HEADERS}) file(GLOB_RECURSE SOURCES "${XBSDB_ROOT_DIR}/src/libXbSymbolDatabase.c" - "${XBSDB_ROOT_DIR}/src/OOVPADatabase/*.inl" + "${XBSDB_ROOT_DIR}/src/OOVPADatabase/*/*.inl" + "${XBSDB_ROOT_DIR}/src/OOVPADatabase/*.c" ) source_group(TREE ${XBSDB_ROOT_DIR} FILES ${SOURCES}) diff --git a/src/OOVPADatabase/D3D8/3911.inl b/src/OOVPADatabase/D3D8/3911.inl index 3775aa44..abe1ac6d 100644 --- a/src/OOVPADatabase/D3D8/3911.inl +++ b/src/OOVPADatabase/D3D8/3911.inl @@ -1742,10 +1742,11 @@ OOVPA_SIG_MATCH( // ****************************************************************** OOVPA_SIG_HEADER_XREF(D3DDevice_SetStreamSource, 3911, - XRefOne) + XRefTwo) OOVPA_SIG_MATCH( - XREF_ENTRY(0x23, XREF_D3D_g_Stream), // Derived + XREF_ENTRY(0x23, XREF_D3D_g_Stream_i_pVertexBuffer), // Derived + XREF_ENTRY(0x53, XREF_D3D_g_Stream), // Derived // D3DDevice_SetStreamSource+0x00 : push ebx { 0x00, 0x53 }, diff --git a/src/OOVPADatabase/D3D8/4034.inl b/src/OOVPADatabase/D3D8/4034.inl index 4ef4e9e5..31115659 100644 --- a/src/OOVPADatabase/D3D8/4034.inl +++ b/src/OOVPADatabase/D3D8/4034.inl @@ -303,10 +303,11 @@ OOVPA_SIG_MATCH( // * D3DDevice_SetStreamSource // ****************************************************************** OOVPA_XREF(D3DDevice_SetStreamSource, 4034, 1 + 14, // 1+28 - XRefOne) + XRefTwo) { - XREF_ENTRY(0x22, XREF_D3D_g_Stream), // Derived + XREF_ENTRY(0x22, XREF_D3D_g_Stream_i_pVertexBuffer), // Derived + XREF_ENTRY(0x52, XREF_D3D_g_Stream), // Derived #if 0 { 0x00, 0x8B }, diff --git a/src/OOVPADatabase/D3D8LTCG/3911.inl b/src/OOVPADatabase/D3D8LTCG/3911.inl index 45bb6f16..37c80686 100644 --- a/src/OOVPADatabase/D3D8LTCG/3911.inl +++ b/src/OOVPADatabase/D3D8LTCG/3911.inl @@ -1165,10 +1165,11 @@ OOVPA_SIG_MATCH( //7406810300000800 OOVPA_SIG_HEADER_XREF(D3DDevice_SetStreamSource_8__LTCG_edx1, 2039, - XRefOne) + XRefTwo) OOVPA_SIG_MATCH( - XREF_ENTRY(0x47, XREF_D3D_g_Stream), // Derived + XREF_ENTRY(0x47, XREF_D3D_g_Stream_i_pVertexBuffer), // Derived + XREF_ENTRY(0x77, XREF_D3D_g_Stream), // Derived { 0x00, 0x53 }, { 0x01, 0x8B }, diff --git a/src/OOVPADatabase/D3D8LTCG/4039.inl b/src/OOVPADatabase/D3D8LTCG/4039.inl index 64a8b502..542bd5eb 100644 --- a/src/OOVPADatabase/D3D8LTCG/4039.inl +++ b/src/OOVPADatabase/D3D8LTCG/4039.inl @@ -1119,10 +1119,11 @@ OOVPA_SIG_MATCH( //7406810300000800 ...C20800 OOVPA_SIG_HEADER_XREF(D3DDevice_SetStreamSource_8__LTCG_eax1, 2040, - XRefOne) + XRefTwo) OOVPA_SIG_MATCH( - XREF_ENTRY(0x23, XREF_D3D_g_Stream), // Derived + XREF_ENTRY(0x23, XREF_D3D_g_Stream_i_pVertexBuffer), // Derived + XREF_ENTRY(0x53, XREF_D3D_g_Stream), // Derived { 0x00, 0x8B }, { 0x01, 0x0D }, diff --git a/src/OOVPADatabase/D3D8LTCG/4432.inl b/src/OOVPADatabase/D3D8LTCG/4432.inl index 658e6ab0..da62a96c 100644 --- a/src/OOVPADatabase/D3D8LTCG/4432.inl +++ b/src/OOVPADatabase/D3D8LTCG/4432.inl @@ -45,10 +45,11 @@ OOVPA_SIG_MATCH( //7406810300000800 OOVPA_SIG_HEADER_XREF(D3DDevice_SetStreamSource, 1044, - XRefOne) + XRefTwo) OOVPA_SIG_MATCH( - XREF_ENTRY(0x22, XREF_D3D_g_Stream), // Derived + XREF_ENTRY(0x22, XREF_D3D_g_Stream_i_pVertexBuffer), // Derived + XREF_ENTRY(0x52, XREF_D3D_g_Stream), // Derived { 0x00, 0x8B }, { 0x01, 0x0D }, diff --git a/src/OOVPADatabase/D3D8LTCG/5233.inl b/src/OOVPADatabase/D3D8LTCG/5233.inl index b09ab137..605c3f25 100644 --- a/src/OOVPADatabase/D3D8LTCG/5233.inl +++ b/src/OOVPADatabase/D3D8LTCG/5233.inl @@ -67,6 +67,7 @@ OOVPA_SIG_MATCH( // * D3DDevice_SetTextureState_TexCoordIndex // ****************************************************************** //81E30000FFFFB901 ...C20400 +// verified for World Series Baseball 2K3 OOVPA_SIG_HEADER_XREF(D3DDevice_SetTextureState_TexCoordIndex_4__LTCG_esi1, 2052, XRefOne) diff --git a/src/OOVPADatabase/D3D8LTCG/5849.inl b/src/OOVPADatabase/D3D8LTCG/5849.inl index c296f90f..61dec208 100644 --- a/src/OOVPADatabase/D3D8LTCG/5849.inl +++ b/src/OOVPADatabase/D3D8LTCG/5849.inl @@ -214,6 +214,7 @@ OOVPA_SIG_MATCH( // * D3DDevice_SetTextureState_TexCoordIndex // ****************************************************************** //81E30000FFFFB901 ...C3 +// verified for Ski Racing 2006 OOVPA_SIG_HEADER_XREF(D3DDevice_SetTextureState_TexCoordIndex_0__LTCG_edi1_eax2, 2058, XRefOne) @@ -706,10 +707,11 @@ OOVPA_SIG_MATCH( // ****************************************************************** OOVPA_SIG_HEADER_XREF(D3DDevice_SetStreamSource_0__LTCG_eax1_edi2_ebx3, 2058, - XRefOne) + XRefTwo) OOVPA_SIG_MATCH( - XREF_ENTRY(0x19, XREF_D3D_g_Stream), // Derived + XREF_ENTRY(0x19, XREF_D3D_g_Stream_i_pVertexBuffer), // Derived + XREF_ENTRY(0x49, XREF_D3D_g_Stream), // Derived // test edi, edi; mov ecx, [...] OV_MATCH(0x00, 0x85, 0xFF, 0x8B, 0x0D), @@ -725,10 +727,11 @@ OOVPA_SIG_MATCH( //7406810300000800 ...C20400 OOVPA_SIG_HEADER_XREF(D3DDevice_SetStreamSource_4__LTCG_eax1_ebx2, 2058, - XRefOne) + XRefTwo) OOVPA_SIG_MATCH( - XREF_ENTRY(0x1E, XREF_D3D_g_Stream), // Derived + XREF_ENTRY(0x1E, XREF_D3D_g_Stream_i_pVertexBuffer), // Derived + XREF_ENTRY(0x4E, XREF_D3D_g_Stream), // Derived { 0x00, 0x85 }, { 0x01, 0xDB }, diff --git a/src/OOVPADatabase/D3D8LTCG_OOVPA.inl b/src/OOVPADatabase/D3D8LTCG_OOVPA.c similarity index 96% rename from src/OOVPADatabase/D3D8LTCG_OOVPA.inl rename to src/OOVPADatabase/D3D8LTCG_OOVPA.c index d1c587e9..9572df4f 100644 --- a/src/OOVPADatabase/D3D8LTCG_OOVPA.inl +++ b/src/OOVPADatabase/D3D8LTCG_OOVPA.c @@ -28,10 +28,7 @@ // * D3DDevice_Reset_0__LTCG_edi1 (4034 ... < 4039) // NOTE: Unknown if 4039 signature needs to be lower. // * D3DDevice_Reset_0__LTCG_ebx1 (... < 5344) // NOTE: Unknown if signature needs to be lower, and may have appeared at the same time when CDevice_InitializeFrameBuffers_4__LTCG_edi1 was introduced. -#ifndef D3D8LTCG_OOVPA_INL -#define D3D8LTCG_OOVPA_INL - -#include "OOVPA.h" +#include "OOVPA_databases.h" #include "D3D8LTCG/3911.inl" #include "D3D8LTCG/4034.inl" @@ -50,10 +47,13 @@ #include "D3D8LTCG/5788.inl" #include "D3D8LTCG/5849.inl" +#define REGISTER_OOVPAS_D3D(Symbol, ...) REGISTER_OOVPAS_PREFIX(D3D, Symbol, __VA_ARGS__) +#define REGISTER_OOVPAS_D3D8(Symbol, ...) REGISTER_OOVPAS_PREFIX(D3D8, Symbol, __VA_ARGS__) + // ****************************************************************** -// * D3D8LTCG_OOVPA +// * D3D8LTCG_OOVPA_Table // ****************************************************************** -OOVPATable D3D8LTCG_OOVPA[] = { +static OOVPATable D3D8LTCG_OOVPA_Table[] = { REGISTER_OOVPAS(SYM_FUN_LTCG(D3D_CreateTexture, CALL(unk), STACK(28), PARAMS(PARAM(psh, Width), PARAM(psh, Height), PARAM(psh, Depth), PARAM(psh, Levels), PARAM(psh, Usage), PARAM(psh, Format), PARAM(psh, isCube), PARAM(_dl, isVolume), PARAM(edi, ppTexture))), SYM_SIG(4039)), // Final generic OOVPA: 4039; Removed: 4627 // See note for details. @@ -303,16 +303,16 @@ OOVPATable D3D8LTCG_OOVPA[] = { SYM_SIG(4039, 4040)), REGISTER_OOVPAS_D3D(SYM_FUN(CDevice_SetStateVB, CALL(std), STACK(8), PARAMS(PARAM(psh, this), PARAM(psh, unknown2))), SYM_SIG(3911, 4039)), // TODO: Update unknown parameter name(s) if able. - REGISTER_OOVPAS(SYM_FUN(D3DDevice_SetStreamSource, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, StreamNumber), PARAM(psh, pStreamData), PARAM(psh, Stride))), - SYM_SIG(1044)), - REGISTER_OOVPAS(SYM_FUN_LTCG(D3DDevice_SetStreamSource, CALL(unk), STACK(0), PARAMS(PARAM(eax, StreamNumber), PARAM(edi, pStreamData), PARAM(ebx, Stride))), - SYM_SIG(2058)), - REGISTER_OOVPAS(SYM_FUN_LTCG(D3DDevice_SetStreamSource, CALL(unk), STACK(8), PARAMS(PARAM(edx, StreamNumber), PARAM(psh, pStreamData), PARAM(psh, Stride))), - SYM_SIG(2039)), - REGISTER_OOVPAS(SYM_FUN_LTCG(D3DDevice_SetStreamSource, CALL(unk), STACK(4), PARAMS(PARAM(eax, StreamNumber), PARAM(ebx, pStreamData), PARAM(psh, Stride))), - SYM_SIG(2058)), - REGISTER_OOVPAS(SYM_FUN_LTCG(D3DDevice_SetStreamSource, CALL(unk), STACK(8), PARAMS(PARAM(eax, StreamNumber), PARAM(psh, pStreamData), PARAM(psh, Stride))), - SYM_SIG(2040)), + REGISTER_OOVPAS_M(SYM_FUN(D3DDevice_SetStreamSource, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, StreamNumber), PARAM(psh, pStreamData), PARAM(psh, Stride))), + SYM_SIG(1044)), + REGISTER_OOVPAS_M(SYM_FUN_LTCG(D3DDevice_SetStreamSource, CALL(unk), STACK(0), PARAMS(PARAM(eax, StreamNumber), PARAM(edi, pStreamData), PARAM(ebx, Stride))), + SYM_SIG(2058)), + REGISTER_OOVPAS_M(SYM_FUN_LTCG(D3DDevice_SetStreamSource, CALL(unk), STACK(8), PARAMS(PARAM(edx, StreamNumber), PARAM(psh, pStreamData), PARAM(psh, Stride))), + SYM_SIG(2039)), + REGISTER_OOVPAS_M(SYM_FUN_LTCG(D3DDevice_SetStreamSource, CALL(unk), STACK(4), PARAMS(PARAM(eax, StreamNumber), PARAM(ebx, pStreamData), PARAM(psh, Stride))), + SYM_SIG(2058)), + REGISTER_OOVPAS_M(SYM_FUN_LTCG(D3DDevice_SetStreamSource, CALL(unk), STACK(8), PARAMS(PARAM(eax, StreamNumber), PARAM(psh, pStreamData), PARAM(psh, Stride))), + SYM_SIG(2040)), REGISTER_OOVPAS(SYM_FUN(D3DDevice_SetTexture, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, Stage), PARAM(psh, pTexture))), SYM_SIG(1024)), REGISTER_OOVPAS(SYM_FUN_LTCG(D3DDevice_SetTextureStageStateNotInline, CALL(unk), STACK(0), PARAMS(PARAM(ecx, Stage), PARAM(edx, Type), PARAM(eax, Value))), @@ -343,11 +343,11 @@ OOVPATable D3D8LTCG_OOVPA[] = { SYM_SIG(2024, 2036, 2048)), REGISTER_OOVPAS(SYM_FUN_LTCG(D3DDevice_SetTextureState_ColorKeyColor, CALL(unk), STACK(4), PARAMS(PARAM(eax, Stage), PARAM(psh, Value))), SYM_SIG(2048, 2060)), - REGISTER_OOVPAS_C(SYM_FUN(D3DDevice_SetTextureState_TexCoordIndex, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, Stage), PARAM(psh, Value))), + REGISTER_OOVPAS_M(SYM_FUN(D3DDevice_SetTextureState_TexCoordIndex, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, Stage), PARAM(psh, Value))), SYM_SIG(1944, 1958)), - REGISTER_OOVPAS_C(SYM_FUN_LTCG(D3DDevice_SetTextureState_TexCoordIndex, CALL(unk), STACK(0), PARAMS(PARAM(edi, Stage), PARAM(eax, Value))), + REGISTER_OOVPAS_M(SYM_FUN_LTCG(D3DDevice_SetTextureState_TexCoordIndex, CALL(unk), STACK(0), PARAMS(PARAM(edi, Stage), PARAM(eax, Value))), SYM_SIG(2039, 2058)), - REGISTER_OOVPAS_C(SYM_FUN_LTCG(D3DDevice_SetTextureState_TexCoordIndex, CALL(unk), STACK(4), PARAMS(PARAM(esi, Stage), PARAM(psh, Value))), + REGISTER_OOVPAS_M(SYM_FUN_LTCG(D3DDevice_SetTextureState_TexCoordIndex, CALL(unk), STACK(4), PARAMS(PARAM(esi, Stage), PARAM(psh, Value))), SYM_SIG(2040, 2045, 2052, 2058)), REGISTER_OOVPAS(SYM_FUN_LTCG(D3DDevice_SetTexture, CALL(unk), STACK(4), PARAMS(PARAM(psh, Stage), PARAM(eax, pTexture))), SYM_SIG(2024)), @@ -458,8 +458,6 @@ OOVPATable D3D8LTCG_OOVPA[] = { }; // ****************************************************************** -// * D3D8LTCG_OOVPA_COUNT +// * D3D8LTCG_OOVPA // ****************************************************************** -#define D3D8LTCG_OOVPA_COUNT XBSDB_ARRAY_SIZE(D3D8LTCG_OOVPA) - -#endif +OOVPATableList D3D8LTCG_OOVPA = { XBSDB_ARRAY_SIZE(D3D8LTCG_OOVPA_Table), D3D8LTCG_OOVPA_Table }; diff --git a/src/OOVPADatabase/D3D8_OOVPA.inl b/src/OOVPADatabase/D3D8_OOVPA.c similarity index 99% rename from src/OOVPADatabase/D3D8_OOVPA.inl rename to src/OOVPADatabase/D3D8_OOVPA.c index 551096b0..8bc689b7 100644 --- a/src/OOVPADatabase/D3D8_OOVPA.inl +++ b/src/OOVPADatabase/D3D8_OOVPA.c @@ -128,10 +128,7 @@ // * D3D_KickOffAndWaitForIdle2 (4627) // * D3D_CommonSetRenderTargetB (4627) -#ifndef D3D8_OOVPA_INL -#define D3D8_OOVPA_INL - -#include "OOVPA.h" +#include "OOVPA_databases.h" #include "D3D8/3911.inl" #include "D3D8/3925.inl" @@ -159,9 +156,9 @@ #define REGISTER_OOVPAS_D3D8(Symbol, ...) REGISTER_OOVPAS_PREFIX(D3D8, Symbol, __VA_ARGS__) // ****************************************************************** -// * D3D8_OOVPA +// * D3D8_OOVPA_Table // ****************************************************************** -OOVPATable D3D8_OOVPA[] = { +static OOVPATable D3D8_OOVPA_Table[] = { // Custom manual search by reverse engineering team (which will not be public to the user) REGISTER_OOVPAS_M(SYM_INT(D3DDevice__m_VerticalBlankEvent__GenericFragment), SYM_SIG(3911)), // This OOVPA signature is not a symbol. Read its note for more details. @@ -537,8 +534,8 @@ OOVPATable D3D8_OOVPA[] = { SYM_SIG(3911, 4034, 4134)), REGISTER_OOVPAS(SYM_FUN(D3DDevice_SetStipple, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, pPattern))), SYM_SIG(4627)), - REGISTER_OOVPAS(SYM_FUN(D3DDevice_SetStreamSource, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, StreamNumber), PARAM(psh, pStreamData), PARAM(psh, Stride))), - SYM_SIG(3911, 4034)), + REGISTER_OOVPAS_M(SYM_FUN(D3DDevice_SetStreamSource, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, StreamNumber), PARAM(psh, pStreamData), PARAM(psh, Stride))), + SYM_SIG(3911, 4034)), REGISTER_OOVPAS(SYM_FUN(D3DDevice_SetSwapCallback, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, pCallback))), SYM_SIG(4039)), // Final generic OOVPA: 4039; Removed: 0 REGISTER_OOVPAS(SYM_FUN(D3DDevice_SetTexture, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, Stage), PARAM(psh, pTexture))), @@ -551,7 +548,7 @@ OOVPATable D3D8_OOVPA[] = { SYM_SIG(3911, 4034)), REGISTER_OOVPAS(SYM_FUN(D3DDevice_SetTextureState_ColorKeyColor, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, Stage), PARAM(psh, Value))), SYM_SIG(3911, 4034)), - REGISTER_OOVPAS_C(SYM_FUN(D3DDevice_SetTextureState_TexCoordIndex, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, Stage), PARAM(psh, Value))), + REGISTER_OOVPAS_M(SYM_FUN(D3DDevice_SetTextureState_TexCoordIndex, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, Stage), PARAM(psh, Value))), SYM_SIG(3911, 4034, 4242, 4627)), REGISTER_OOVPAS(SYM_FUN(D3DDevice_SetTile, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, Index), PARAM(psh, pTile))), SYM_SIG(3911, 4034, 4627)), // Then it has changed calls ?SetTileNoWait@D3D@@YGXKPBU_D3DTILE@@@Z in XDK 4627 and higher. @@ -699,10 +696,7 @@ OOVPATable D3D8_OOVPA[] = { SYM_SIG(4627)), }; - // ****************************************************************** -// * D3D8_OOVPA_COUNT +// * D3D8_OOVPA // ****************************************************************** -#define D3D8_OOVPA_COUNT XBSDB_ARRAY_SIZE(D3D8_OOVPA) - -#endif +OOVPATableList D3D8_OOVPA = { XBSDB_ARRAY_SIZE(D3D8_OOVPA_Table), D3D8_OOVPA_Table }; diff --git a/src/OOVPADatabase/DSound_OOVPA.inl b/src/OOVPADatabase/DSound_OOVPA.c similarity index 99% rename from src/OOVPADatabase/DSound_OOVPA.inl rename to src/OOVPADatabase/DSound_OOVPA.c index 6ff959af..8e24d055 100644 --- a/src/OOVPADatabase/DSound_OOVPA.inl +++ b/src/OOVPADatabase/DSound_OOVPA.c @@ -121,7 +121,8 @@ #ifndef DSOUND_OOVPA_INL #define DSOUND_OOVPA_INL -#include "OOVPA.h" +#include "OOVPA_databases.h" +#include #include "DSound/3911.inl" #include "DSound/3936.inl" @@ -140,9 +141,9 @@ #include "DSound/5558.inl" // ****************************************************************** -// * DSOUND_OOVPA_manual +// * DSound_OOVPA_manual_Table // ****************************************************************** -OOVPATable DSound_OOVPA_manual[] = { +static OOVPATable DSound_OOVPA_manual_Table[] = { // Without xrefs dependency REGISTER_OOVPAS_M(SYM_FUN(CDirectSoundStream_AddRef, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, pThis))), @@ -162,12 +163,12 @@ OOVPATable DSound_OOVPA_manual[] = { REGISTER_OOVPAS_M(SYM_FUN(CDirectSoundStream_Constructor, CALL(thi), STACK(/*default*/), PARAMS(PARAM(ecx, this), PARAM(psh, pdssd))), SYM_SIG(3911)), // NOTE: Does not need to be register in db. Using manual work instead, like D3D8 did. }; -#define DSound_OOVPA_manual_COUNT XBSDB_ARRAY_SIZE(DSound_OOVPA_manual) +OOVPATableList DSound_OOVPA_manual = { XBSDB_ARRAY_SIZE(DSound_OOVPA_manual_Table), DSound_OOVPA_manual_Table }; // ****************************************************************** -// * DSOUND_OOVPA +// * DSound_OOVPA_Table // ****************************************************************** -OOVPATable DSound_OOVPA[] = { +static OOVPATable DSound_OOVPA_Table[] = { REGISTER_OOVPAS(SYM_FUN(XAudioCalculatePitch, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, dwFrequency))), SYM_SIG(3911, 4039, 5455)), // Final generic OOVPA: 5455; Removed: 0 @@ -884,8 +885,8 @@ OOVPATable DSound_OOVPA[] = { }; // ****************************************************************** -// * DSound_OOVPA_COUNT +// * DSound_OOVPA // ****************************************************************** -#define DSound_OOVPA_COUNT XBSDB_ARRAY_SIZE(DSound_OOVPA) +OOVPATableList DSound_OOVPA = { XBSDB_ARRAY_SIZE(DSound_OOVPA_Table), DSound_OOVPA_Table }; #endif diff --git a/src/OOVPADatabase/JVS_OOVPA.inl b/src/OOVPADatabase/JVS_OOVPA.c similarity index 98% rename from src/OOVPADatabase/JVS_OOVPA.inl rename to src/OOVPADatabase/JVS_OOVPA.c index 0d90086a..f5dffdce 100644 --- a/src/OOVPADatabase/JVS_OOVPA.inl +++ b/src/OOVPADatabase/JVS_OOVPA.c @@ -19,17 +19,14 @@ // is the same except the functions are quite different in layout, etc // and some offsets are different within them too. -#ifndef JVS_OOVPA_INL -#define JVS_OOVPA_INL - -#include "OOVPA.h" +#include "OOVPA_databases.h" #include "JVS/4831.inl" // ****************************************************************** -// * JVSLIB_OOVPA +// * JVSLIB_OOVPA_Table // ****************************************************************** -OOVPATable JVSLIB_OOVPA[] = { +static OOVPATable JVSLIB_OOVPA_Table[] = { // Variables REGISTER_OOVPAS_M(SYM_VAR(JVS_g_pPINSA), @@ -168,8 +165,6 @@ OOVPATable JVSLIB_OOVPA[] = { }; // ****************************************************************** -// * JVSLIB_OOVPA_COUNT +// * JVSLIB_OOVPA // ****************************************************************** -#define JVSLIB_OOVPA_COUNT XBSDB_ARRAY_SIZE(JVSLIB_OOVPA) - -#endif +OOVPATableList JVSLIB_OOVPA = { XBSDB_ARRAY_SIZE(JVSLIB_OOVPA_Table), JVSLIB_OOVPA_Table }; diff --git a/src/OOVPADatabase/OOVPA.h b/src/OOVPADatabase/OOVPA.h index f1185319..5447483f 100644 --- a/src/OOVPADatabase/OOVPA.h +++ b/src/OOVPADatabase/OOVPA.h @@ -3,8 +3,9 @@ // SPDX-FileCopyrightText: 2017 PatrickvL // SPDX-FileCopyrightText: 2017 RadWolfie -#ifndef OOVPA_H -#define OOVPA_H +#pragma once + +#include "libXbSymbolDatabase.h" // http://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly // MSVC_EXPAND works around a Visual C++ problem, expanding __VA_ARGS__ incorrectly: @@ -220,6 +221,11 @@ typedef struct _OOVPATable { const unsigned count; OOVPARevision* const revisions; } OOVPATable; + +typedef struct _OOVPATableList { + unsigned int Count; + OOVPATable* Table; +} OOVPATableList; #pragma pack(1) // http://en.cppreference.com/w/cpp/iterator/size @@ -440,5 +446,3 @@ typedef struct _OOVPATable { OV_BYTES_3, OV_BYTES_2, OV_BYTES_1, OV_BYTES_0)(Offset, __VA_ARGS__)) #pragma pack() - -#endif diff --git a/src/OOVPADatabase/OOVPA_databases.h b/src/OOVPADatabase/OOVPA_databases.h new file mode 100644 index 00000000..28aef9e0 --- /dev/null +++ b/src/OOVPADatabase/OOVPA_databases.h @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: ODbL-1.0 + +#pragma once + +#include "OOVPA.h" +#include + +extern OOVPATableList D3D8_OOVPA; + +extern OOVPATableList D3D8LTCG_OOVPA; + +extern OOVPATableList DSound_OOVPA_manual; +extern OOVPATableList DSound_OOVPA; + +extern OOVPATableList JVSLIB_OOVPA; + +extern OOVPATableList XACTENG_OOVPA; + +extern OOVPATableList XAPILIB_OOVPA; + +extern OOVPATableList XGRAPHC_OOVPA; + +extern OOVPATableList XNET_OOVPA; + +extern OOVPATableList XONLINE_OOVPA; diff --git a/src/OOVPADatabase/XActEng_OOVPA.inl b/src/OOVPADatabase/XActEng_OOVPA.c similarity index 97% rename from src/OOVPADatabase/XActEng_OOVPA.inl rename to src/OOVPADatabase/XActEng_OOVPA.c index 4f9a20e1..ff4574f7 100644 --- a/src/OOVPADatabase/XActEng_OOVPA.inl +++ b/src/OOVPADatabase/XActEng_OOVPA.c @@ -29,10 +29,7 @@ // * IXACTSoundBank_PlayEx (5455) // * IXACTSoundBank_Play (4928 to 5849) -#ifndef XACTENG_OOVPA_INL -#define XACTENG_OOVPA_INL - -#include "OOVPA.h" +#include "OOVPA_databases.h" #include "XActEng/4627.inl" #include "XActEng/4928.inl" @@ -43,9 +40,9 @@ // ****************************************************************** -// * XACTENG_OOVPA +// * XACTENG_OOVPA_Table // ****************************************************************** -OOVPATable XACTENG_OOVPA[] = { +static OOVPATable XACTENG_OOVPA_Table[] = { REGISTER_OOVPAS(SYM_FUN(XACTEngineCreate, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, pParams), PARAM(psh, ppEngine))), SYM_SIG(4627, 4928, 5120)), @@ -96,8 +93,6 @@ OOVPATable XACTENG_OOVPA[] = { }; // ****************************************************************** -// * XACTENG_OOVPA_COUNT +// * XACTENG_OOVPA // ****************************************************************** -#define XACTENG_OOVPA_COUNT XBSDB_ARRAY_SIZE(XACTENG_OOVPA) - -#endif +OOVPATableList XACTENG_OOVPA = { XBSDB_ARRAY_SIZE(XACTENG_OOVPA_Table), XACTENG_OOVPA_Table }; diff --git a/src/OOVPADatabase/XGraphic_OOVPA.inl b/src/OOVPADatabase/XGraphic_OOVPA.c similarity index 96% rename from src/OOVPADatabase/XGraphic_OOVPA.inl rename to src/OOVPADatabase/XGraphic_OOVPA.c index bd823dba..59f6bc1c 100644 --- a/src/OOVPADatabase/XGraphic_OOVPA.inl +++ b/src/OOVPADatabase/XGraphic_OOVPA.c @@ -40,19 +40,16 @@ // NOTE: Known Xgraphics OOVPA not included in initial revision. // * XFONT_OpenBitmapFontFromMemory (4361) -#ifndef XGRAPHC_OOVPA_INL -#define XGRAPHC_OOVPA_INL - -#include "OOVPA.h" +#include "OOVPA_databases.h" #include "XGraphic/3911.inl" #include "XGraphic/4134.inl" #include "XGraphic/4361.inl" // ****************************************************************** -// * XGRAPHC_OOVPA +// * XGRAPHC_OOVPA_Table // ****************************************************************** -OOVPATable XGRAPHC_OOVPA[] = { +static OOVPATable XGRAPHC_OOVPA_Table[] = { REGISTER_OOVPAS(SYM_FUN(XFONT_OpenBitmapFontFromMemory, CALL(std), STACK(/*default*/), PARAMS(PARAM(psh, pFontData), PARAM(psh, uFontDataSize), PARAM(psh, ppFont))), SYM_SIG(4361)), @@ -81,8 +78,6 @@ OOVPATable XGRAPHC_OOVPA[] = { }; // ****************************************************************** -// * XGRAPHC_OOVPA_COUNT +// * XGRAPHC_OOVPA // ****************************************************************** -#define XGRAPHC_OOVPA_COUNT XBSDB_ARRAY_SIZE(XGRAPHC_OOVPA) - -#endif +OOVPATableList XGRAPHC_OOVPA = { XBSDB_ARRAY_SIZE(XGRAPHC_OOVPA_Table), XGRAPHC_OOVPA_Table }; diff --git a/src/OOVPADatabase/XNet_OOVPA.inl b/src/OOVPADatabase/XNet_OOVPA.c similarity index 95% rename from src/OOVPADatabase/XNet_OOVPA.inl rename to src/OOVPADatabase/XNet_OOVPA.c index 16ef4e6c..9cf64392 100644 --- a/src/OOVPADatabase/XNet_OOVPA.inl +++ b/src/OOVPADatabase/XNet_OOVPA.c @@ -17,10 +17,7 @@ // * send (4721) // * XNetGetEthernetLinkStatus (5344) -#ifndef XNET_OOVPA_INL -#define XNET_OOVPA_INL - -#include "OOVPA.h" +#include "OOVPA_databases.h" #include "XNet/3911.inl" #include "XNet/4361.inl" @@ -29,9 +26,9 @@ #include "XNet/5455.inl" // ****************************************************************** -// * XNET_OOVPA +// * XNET_OOVPA_Table // ****************************************************************** -OOVPATable XNET_OOVPA[] = { +static OOVPATable XNET_OOVPA_Table[] = { REGISTER_OOVPAS(SYM_FUN(XnInit, CALL(std), STACK(8), PARAMS(PARAM(psh, pxnsp), PARAM(psh, bWSA))), SYM_SIG(3911)), // 3911 is only XNETS library, XNET library is different OOVPA. @@ -62,8 +59,6 @@ OOVPATable XNET_OOVPA[] = { }; // ****************************************************************** -// * XNET_OOVPA_COUNT +// * XNET_OOVPA // ****************************************************************** -#define XNET_OOVPA_COUNT XBSDB_ARRAY_SIZE(XNET_OOVPA) - -#endif +OOVPATableList XNET_OOVPA = { XBSDB_ARRAY_SIZE(XNET_OOVPA_Table), XNET_OOVPA_Table }; diff --git a/src/OOVPADatabase/XOnline_OOVPA.inl b/src/OOVPADatabase/XOnline_OOVPA.c similarity index 97% rename from src/OOVPADatabase/XOnline_OOVPA.inl rename to src/OOVPADatabase/XOnline_OOVPA.c index 3a67b2b6..859cc252 100644 --- a/src/OOVPADatabase/XOnline_OOVPA.inl +++ b/src/OOVPADatabase/XOnline_OOVPA.c @@ -28,10 +28,7 @@ // * recv (5120, 5233) // * send (5120, 5233) -#ifndef XONLINES_OOVPA_INL -#define XONLINES_OOVPA_INL - -#include "OOVPA.h" +#include "OOVPA_databases.h" #include "XOnline/4361.inl" #include "XOnline/4627.inl" @@ -44,9 +41,9 @@ #include "XOnline/5849.inl" // ****************************************************************** -// * XONLINE_OOVPA +// * XONLINE_OOVPA_Table // ****************************************************************** -OOVPATable XONLINE_OOVPA[] = { +static OOVPATable XONLINE_OOVPA_Table[] = { // XOnline section REGISTER_OOVPAS(SYM_FUN(CXo_XOnlineLogon, CALL(thi), STACK(/*default*/), PARAMS(PARAM(ecx, this), PARAM(psh, pUsers), PARAM(psh, pdwServiceIDs), PARAM(psh, dwServices), PARAM(psh, hEvent), PARAM(psh, pHandle))), @@ -80,8 +77,6 @@ OOVPATable XONLINE_OOVPA[] = { }; // ****************************************************************** -// * XONLINE_OOVPA_COUNT +// * XONLINE_OOVPA // ****************************************************************** -#define XONLINE_OOVPA_COUNT XBSDB_ARRAY_SIZE(XONLINE_OOVPA) - -#endif +OOVPATableList XONLINE_OOVPA = { XBSDB_ARRAY_SIZE(XONLINE_OOVPA_Table), XONLINE_OOVPA_Table }; diff --git a/src/OOVPADatabase/Xapi_OOVPA.inl b/src/OOVPADatabase/Xapi_OOVPA.c similarity index 99% rename from src/OOVPADatabase/Xapi_OOVPA.inl rename to src/OOVPADatabase/Xapi_OOVPA.c index ce6231ac..248585b2 100644 --- a/src/OOVPADatabase/Xapi_OOVPA.inl +++ b/src/OOVPADatabase/Xapi_OOVPA.c @@ -359,10 +359,7 @@ // * InterlockedExchangeAdd // * InterlockedIncrement -#ifndef XAPI_OOVPA_INL -#define XAPI_OOVPA_INL - -#include "OOVPA.h" +#include "OOVPA_databases.h" #include "Xapi/3911.inl" #include "Xapi/3950.inl" @@ -379,9 +376,9 @@ #include "Xapi/5455.inl" // ****************************************************************** -// * XAPILIB_OOVPA +// * XAPILIB_OOVPA_Table // ****************************************************************** -OOVPATable XAPILIB_OOVPA[] = { +static OOVPATable XAPILIB_OOVPA_Table[] = { // Variables REGISTER_OOVPAS_M(SYM_VAR(_tls_array), @@ -587,8 +584,6 @@ OOVPATable XAPILIB_OOVPA[] = { }; // ****************************************************************** -// * XAPILIB_OOVPA_COUNT +// * XAPILIB_OOVPA // ****************************************************************** -#define XAPILIB_OOVPA_COUNT XBSDB_ARRAY_SIZE(XAPILIB_OOVPA) - -#endif +OOVPATableList XAPILIB_OOVPA = { XBSDB_ARRAY_SIZE(XAPILIB_OOVPA_Table), XAPILIB_OOVPA_Table }; diff --git a/src/lib/internal_db_version.h b/src/lib/internal_db_version.h index 8c0e67c9..ef9cc4ad 100644 --- a/src/lib/internal_db_version.h +++ b/src/lib/internal_db_version.h @@ -53,8 +53,9 @@ void HashOOVPATable(unsigned int* Hash, const OOVPATable* pTable) void HashSymbolData(unsigned int* Hash, SymbolDatabaseList* pData) { - for (unsigned int i = 0; i < pData->SymbolsTableCount; ++i) { - HashOOVPATable(Hash, &pData->SymbolsTable[i]); + OOVPATableList* Symbols = pData->Symbols; + for (unsigned int i = 0; i < Symbols->Count; ++i) { + HashOOVPATable(Hash, &Symbols->Table[i]); } } diff --git a/src/lib/internal_functions.h b/src/lib/internal_functions.h index cb56e259..2ae5e848 100644 --- a/src/lib/internal_functions.h +++ b/src/lib/internal_functions.h @@ -430,15 +430,16 @@ static void internal_RegisterSymbol(iXbSymbolContext* pContext, static OOVPATable* internal_OOVPATable_FindBySymbolName(SymbolDatabaseList* LibraryDB, const char* szSymbolName, unsigned scan_type) { - for (unsigned i = 0; i < LibraryDB->SymbolsTableCount; i++) { + OOVPATableList* Symbols = LibraryDB->Symbols; + for (unsigned i = 0; i < Symbols->Count; i++) { // Intended for optimization purpose without need to search every single symbol's string. - if ((scan_type & LibraryDB->SymbolsTable[i].scan_type) == 0) { + if ((scan_type & LibraryDB->Symbols->Table[i].scan_type) == 0) { continue; } - if (strcmp(szSymbolName, LibraryDB->SymbolsTable[i].szSymbolName) == 0) { - return &LibraryDB->SymbolsTable[i]; + if (strcmp(szSymbolName, Symbols->Table[i].szSymbolName) == 0) { + return &Symbols->Table[i]; } } return NULL; @@ -446,15 +447,16 @@ static OOVPATable* internal_OOVPATable_FindBySymbolName(SymbolDatabaseList* Libr static OOVPATable* internal_OOVPATable_FindByReference(SymbolDatabaseList* LibraryDB, uint16_t xref_index, unsigned scan_type) { - for (unsigned i = 0; i < LibraryDB->SymbolsTableCount; i++) { + OOVPATableList* Symbols = LibraryDB->Symbols; + for (unsigned i = 0; i < Symbols->Count; i++) { // Intended for optimization purpose without need to search every single symbol's string. - if ((scan_type & LibraryDB->SymbolsTable[i].scan_type) == 0) { + if ((scan_type & Symbols->Table[i].scan_type) == 0) { continue; } - if (LibraryDB->SymbolsTable[i].xref == xref_index) { - return &LibraryDB->SymbolsTable[i]; + if (Symbols->Table[i].xref == xref_index) { + return &Symbols->Table[i]; } } return NULL; @@ -473,7 +475,7 @@ static OOVPATable* internal_OOVPATable_FindByReference(SymbolDatabaseList* Libra static void internal_OOVPATable_scan(iXbSymbolContext* pContext, const iXbSymbolLibrarySession* pLibrarySession, const XbSDBSection* pSection, - bool xref_first_pass, + const bool xref_first_pass, const OOVPATable* pSymbol, OOVPARevision** pRevisionReturn, void** pAddressReturn) @@ -517,6 +519,55 @@ static void internal_OOVPATable_scan(iXbSymbolContext* pContext, *pRevisionReturn = pLastKnownRevision; } +static void* internal_SymbolDatabaseList_ScanByReference(iXbSymbolContext* pContext, + const iXbSymbolLibrarySession* pLibrarySession, + SymbolDatabaseList* LibraryDB, + const XbSDBSection* pSection, + const uint16_t xref_index, + const unsigned scan_type, + const eFirstPass xref_first_pass, + const eRegisterSymbol register_symbol, + OOVPATable** pSymbolReturn, + OOVPARevision** pRevisionReturn) +{ + OOVPARevision* pRevision = NULL; + void* pSymbolAddr = NULL; + OOVPATableList* Symbols = LibraryDB->Symbols; + for (unsigned i = 0; i < Symbols->Count; i++) { + + // Intended for optimization purpose without need to search every single symbol reference index. + if ((scan_type & Symbols->Table[i].scan_type) == 0) { + continue; + } + + if (Symbols->Table[i].xref == xref_index) { + // If reference is found, then perform the scan process. + internal_OOVPATable_scan(pContext, + pLibrarySession, + pSection, + xref_first_pass, + Symbols->Table + i, + &pRevision, + &pSymbolAddr); + + // if symbol is found, then make the break to return the symbol entry. + if (pSymbolAddr) { + if (pSymbolReturn) { + *pSymbolReturn = Symbols->Table + i; + } + if (pRevisionReturn) { + *pRevisionReturn = pRevision; + } + if (register_symbol) { + internal_RegisterSymbol(pContext, pLibrarySession, Symbols->Table + i, pRevision->Version, (xbaddr)(uintptr_t)pSymbolAddr); + } + break; + } + } + } + return pSymbolAddr; +} + static void internal_OOVPA_register(iXbSymbolContext* pContext, const OOVPATable* Symbol, const OOVPARevision* OovpaRevision, @@ -524,24 +575,19 @@ static void internal_OOVPA_register(iXbSymbolContext* pContext, xbaddr address) { if (OovpaRevision != NULL) { - internal_RegisterSymbol(pContext, pLibrarySession, Symbol, OovpaRevision->Version, address); } } -static void internal_OOVPA_scan(iXbSymbolContext* pContext, - OOVPATable* SymbolsTable, - unsigned int SymbolsTableCount, - const iXbSymbolLibrarySession* pLibrarySession, - const XbSDBSection* pSection, - bool xref_first_pass) +static void internal_OOVPATableList_scan(iXbSymbolContext* pContext, + const iXbSymbolLibrarySession* pLibrarySession, + OOVPATableList* Symbols, + const XbSDBSection* pSection, + const bool xref_first_pass) { - const XbSDBLibrary* pLibrary = pLibrarySession->pLibrary; - const eLibraryType iLibraryType = pLibrarySession->iLibraryType; - // traverse the full OOVPA table - OOVPATable* pSymbolEnd = &SymbolsTable[SymbolsTableCount]; - OOVPATable* pSymbol = SymbolsTable; + OOVPATable* pSymbolEnd = &Symbols->Table[Symbols->Count]; + OOVPATable* pSymbol = Symbols->Table; for (; pSymbol < pSymbolEnd; pSymbol++) { @@ -569,40 +615,6 @@ static void internal_OOVPA_scan(iXbSymbolContext* pContext, } } -// Intended design for manual scan without register. Could be expand -static void* internal_LocateSymbolScan(iXbSymbolContext* pContext, - const iXbSymbolLibrarySession* pLibrarySession, - SymbolDatabaseList* pLibraryDB, - const char* szSymbolName, - const XbSDBSection* pSection, - bool xref_first_pass, - OOVPATable** pSymbol, - OOVPARevision** pOOVPARevision) -{ - void* symbol_addr = 0; - OOVPARevision* pRevisionLocal = NULL; - OOVPATable* pSymbolLocal = internal_OOVPATable_FindBySymbolName(pLibraryDB, szSymbolName, DB_ST_MANUAL); - - if (pSymbolLocal) { - internal_OOVPATable_scan(pContext, - pLibrarySession, - pSection, - xref_first_pass, - pSymbolLocal, - &pRevisionLocal, - &symbol_addr); - } - - if (pSymbol) { - *pSymbol = pSymbolLocal; - } - - if (pOOVPARevision) { - *pOOVPARevision = pRevisionLocal; - } - return symbol_addr; -} - static eLibraryType internal_GetLibraryType(uint32_t library) { switch (library) { diff --git a/src/lib/internal_tests.h b/src/lib/internal_tests.h index 9c527c7d..b9ac3c0d 100644 --- a/src/lib/internal_tests.h +++ b/src/lib/internal_tests.h @@ -27,7 +27,7 @@ static int OOVPAErrorString(char* bufferTemp, SymbolDatabaseList* data, OOVPATab // Convert active data pointer to an index base on starting point of SymbolDBList. unsigned int db_index = (unsigned int)(data - SymbolDBList); // Convert active symbol pointer to an index base on starting point of SymbolsTable. - unsigned int sym_index = (unsigned int)(symbol - data->SymbolsTable); + unsigned int sym_index = (unsigned int)(symbol - data->Symbols->Table); return sprintf(bufferTemp, "OOVPATable db=%2u, i=[%4u], b=%4hu s=%s[%4u]", db_index, sym_index, symbol->revisions[index].Version, symbol->szSymbolName, index); } @@ -40,14 +40,14 @@ static void SymbolDatabaseVerifyContext_OOVPAError(SymbolDatabaseVerifyContext* if (context->main.data != NULL) { - ret_str_count = OOVPAErrorString(bufferTemp, context->main.data, context->main.data->SymbolsTable + context->main.symbol_index, context->main.revision_index); + ret_str_count = OOVPAErrorString(bufferTemp, context->main.data, context->main.data->Symbols->Table + context->main.symbol_index, context->main.revision_index); (void)strncat(buffer, bufferTemp, ret_str_count); } if (context->against.oovpa != NULL && context->against.data != NULL) { (void)strcat(buffer, ", comparing against "); - ret_str_count = OOVPAErrorString(bufferTemp, context->against.data, context->against.data->SymbolsTable + context->against.symbol_index, context->against.revision_index); + ret_str_count = OOVPAErrorString(bufferTemp, context->against.data, context->against.data->Symbols->Table + context->against.symbol_index, context->against.revision_index); (void)strncat(buffer, bufferTemp, ret_str_count); } @@ -99,8 +99,8 @@ static unsigned int SymbolDatabaseVerifyContext_VerifyOOVPA(SymbolDatabaseVerify } // prevent checking an oovpa against itself - if ((&context->main.data->SymbolsTable[context->main.symbol_index].revisions + context->main.revision_index) == - (&context->against.data->SymbolsTable[context->against.symbol_index].revisions + context->against.revision_index)) { + if ((&context->main.data->Symbols->Table[context->main.symbol_index].revisions + context->main.revision_index) == + (&context->against.data->Symbols->Table[context->against.symbol_index].revisions + context->against.revision_index)) { return error_count; } @@ -251,19 +251,20 @@ static unsigned int SymbolDatabaseVerifyContext_VerifyDatabase(SymbolDatabaseVer } // Verify each entry in data's symbol table. - for (uint32_t s = 0; s < data->SymbolsTableCount; s++) { + OOVPATableList* Symbols = data->Symbols; + for (uint32_t s = 0; s < Symbols->Count; s++) { // We only need to check from main, not against. if (context->against.data == NULL) { // For safety check purpose - if (internal_IsXRefUnset(data->SymbolsTable[s].xref)) { - output_message_format(&context->output, XB_OUTPUT_MESSAGE_ERROR, "%s cannot have unset xref.", data->SymbolsTable[s].szSymbolName); + if (internal_IsXRefUnset(data->Symbols->Table[s].xref)) { + output_message_format(&context->output, XB_OUTPUT_MESSAGE_ERROR, "%s cannot have unset xref.", Symbols->Table[s].szSymbolName); error_count++; } } // Check each revision entry in a symbol. - for (uint32_t r = 0; r < data->SymbolsTable[s].count; r++) { - error_count += SymbolDatabaseVerifyContext_VerifyEntry(context, data->SymbolsTable, s, r); + for (uint32_t r = 0; r < data->Symbols->Table[s].count; r++) { + error_count += SymbolDatabaseVerifyContext_VerifyEntry(context, Symbols->Table, s, r); } } return error_count; diff --git a/src/lib/libXbSymbolDatabase.c b/src/lib/libXbSymbolDatabase.c index d8752bf0..d3b850c4 100644 --- a/src/lib/libXbSymbolDatabase.c +++ b/src/lib/libXbSymbolDatabase.c @@ -54,16 +54,7 @@ static inline uint32_t BitScanReverse(uint32_t value) // * Xbox Symbol OOVPA Database // ****************************************************************** -#include -#include "Xapi_OOVPA.inl" -#include "D3D8_OOVPA.inl" -#include "D3D8LTCG_OOVPA.inl" -#include "DSound_OOVPA.inl" -#include "JVS_OOVPA.inl" -#include "XGraphic_OOVPA.inl" -#include "XNet_OOVPA.inl" -#include "XOnline_OOVPA.inl" -#include "XActEng_OOVPA.inl" +#include "OOVPA_databases.h" #define PAIRSCANSEC_MAX 4 @@ -95,6 +86,16 @@ typedef enum _eScanStage { SS_2_SCAN_LIBS, } eScanStage; +typedef enum _eRegisterSymbol { + REGISTER_NO = 0, + REGISTER_YES, +} eRegisterSymbol; + +typedef enum _eFirstPass { + FIRSTPASS_NO = 0, + FIRSTPASS_YES, +} eFirstPass; + typedef struct _iXbSymbolLibraryContext { uint32_t xref_registered; bool is_active; @@ -127,8 +128,7 @@ typedef const struct _PairScanLibSec { typedef const struct _SymbolDatabaseList { PairScanLibSec LibSec; - OOVPATable* SymbolsTable; - unsigned int SymbolsTableCount; + OOVPATableList* Symbols; } SymbolDatabaseList; typedef bool (*custom_scan_func_t)(iXbSymbolContext* pContext, @@ -138,56 +138,56 @@ typedef bool (*custom_scan_func_t)(iXbSymbolContext* pContext, SymbolDatabaseList SymbolDBList[] = { // Support inline functions in .text section - { XbSymbolLib_D3D8 | XbSymbolLib_D3D8LTCG, { Sec_text, Sec_D3D, Sec_FLASHROM }, D3D8_OOVPA, D3D8_OOVPA_COUNT }, + { XbSymbolLib_D3D8 | XbSymbolLib_D3D8LTCG, { Sec_text, Sec_D3D, Sec_FLASHROM }, &D3D8_OOVPA }, // LTCG database have to be after standard library or otherwise the scan process will not work correctly. - { XbSymbolLib_D3D8LTCG, { Sec_text, Sec_D3D }, D3D8LTCG_OOVPA, D3D8LTCG_OOVPA_COUNT }, + { XbSymbolLib_D3D8LTCG, { Sec_text, Sec_D3D }, &D3D8LTCG_OOVPA }, // NOTE: Likely is a D3D Helper library. // Jarupxx mention this is not a requirement? - //{ Lib_D3DX8, { Sec_D3DX }, _OOVPA, _OOVPA_COUNT }, + //{ Lib_D3DX8, { Sec_D3DX }, &_OOVPA }, // Only used for manual scan purpose as a workaround since both FLASHROM // and text section will lead to false detection for non-manual signatures, see comment below. - { XbSymbolLib_DSOUND, { Sec_DSOUND, Sec_rdata, Sec_FLASHROM, Sec_text }, DSound_OOVPA_manual, DSound_OOVPA_manual_COUNT }, + { XbSymbolLib_DSOUND, { Sec_DSOUND, Sec_rdata, Sec_FLASHROM, Sec_text }, &DSound_OOVPA_manual }, // NOTE: By adding FLASHROM to scan section may will lead false detection. // Since some symbols has very short asm codes. - { XbSymbolLib_DSOUND, { Sec_DSOUND, Sec_rdata, Sec_FLASHROM }, DSound_OOVPA, DSound_OOVPA_COUNT }, + { XbSymbolLib_DSOUND, { Sec_DSOUND, Sec_rdata, Sec_FLASHROM }, &DSound_OOVPA }, // DSOUNDH is just meant to define hot fix, there is no separate section - //{ XbSymbolLib_DSOUNDH, { Sec_DSOUND }, &DSound_OOVPA, DSound_OOVPA_COUNT }, + //{ XbSymbolLib_DSOUNDH, { Sec_DSOUND }, &DSound_OOVPA }, // Only used in Chihiro applications - { XbSymbolLib_JVS, { Sec_text, Sec_XPP, Sec_FLASHROM }, JVSLIB_OOVPA, JVSLIB_OOVPA_COUNT }, + { XbSymbolLib_JVS, { Sec_text, Sec_XPP, Sec_FLASHROM }, &JVSLIB_OOVPA }, // - { XbSymbolLib_XACTENG, { Sec_XACTENG, Sec_FLASHROM }, XACTENG_OOVPA, XACTENG_OOVPA_COUNT }, + { XbSymbolLib_XACTENG, { Sec_XACTENG, Sec_FLASHROM }, &XACTENG_OOVPA }, // test case: Power Drome (Unluckily, it use LTCG version of the library.) // LTCG database have to be after standard library or otherwise the scan process will not work correctly. - //{ XbSymbolLib_XACTENLT, { Sec_XACTENG }, XACTENGLT_OOVPA, XACTENGLT_OOVPA_COUNT }, + //{ XbSymbolLib_XACTENLT, { Sec_XACTENG }, &XACTENGLT_OOVPA }, // - { XbSymbolLib_XAPILIB, { Sec_text, Sec_XPP, Sec_FLASHROM }, XAPILIB_OOVPA, XAPILIB_OOVPA_COUNT }, + { XbSymbolLib_XAPILIB, { Sec_text, Sec_XPP, Sec_FLASHROM }, &XAPILIB_OOVPA }, // Support inline functions in .text section - { XbSymbolLib_XGRAPHC, { Sec_text, Sec_XGRPH, Sec_FLASHROM }, XGRAPHC_OOVPA, XGRAPHC_OOVPA_COUNT }, + { XbSymbolLib_XGRAPHC, { Sec_text, Sec_XGRPH, Sec_FLASHROM }, &XGRAPHC_OOVPA }, // LTCG database have to be after standard library or otherwise the scan process will not work correctly. - //{ XbSymbolLib_XGRAPHCL, { Sec_XGRPH }, XGRAPHCL_OOVPA, XGRAPHCL_OOVPA_COUNT }, + //{ XbSymbolLib_XGRAPHCL, { Sec_XGRPH }, &XGRAPHCL_OOVPA }, // Added Sec_text and Sec_XNET just in case. // TODO: Do we need to keep Sec_XNET in here? // TODO: Need to find out which function is only part of XOnlines. // Fun fact, XONLINES are split into 2 header sections. - { XbSymbolLib_XONLINE | XbSymbolLib_XONLINES | XbSymbolLib_XONLINLS, { Sec_text, Sec_XONLINE, Sec_XNET, Sec_FLASHROM }, XONLINE_OOVPA, XONLINE_OOVPA_COUNT }, + { XbSymbolLib_XONLINE | XbSymbolLib_XONLINES | XbSymbolLib_XONLINLS, { Sec_text, Sec_XONLINE, Sec_XNET, Sec_FLASHROM }, &XONLINE_OOVPA }, // Added Sec_text just in case. // TODO: Need to find out which function is only part of XNets. // XNETS only has XNET, might be true. // XNETN's test case: Stake - { XbSymbolLib_XNET | XbSymbolLib_XNETS | XbSymbolLib_XNETN | XbSymbolLib_XONLINE | XbSymbolLib_XONLINES | XbSymbolLib_XONLINLS, { Sec_text, Sec_XNET, Sec_FLASHROM }, XNET_OOVPA, XNET_OOVPA_COUNT }, + { XbSymbolLib_XNET | XbSymbolLib_XNETS | XbSymbolLib_XNETN | XbSymbolLib_XONLINE | XbSymbolLib_XONLINES | XbSymbolLib_XONLINLS, { Sec_text, Sec_XNET, Sec_FLASHROM }, &XNET_OOVPA }, }; // ****************************************************************** @@ -873,6 +873,7 @@ bool XbSymbolDatabase_CreateXbSymbolContext(XbSymbolContextHandle* ppHandle, // D3D pContext->xref_database[XREF_D3DTSS_TEXCOORDINDEX] = XREF_ADDR_DERIVE; //In use pContext->xref_database[XREF_D3D_g_Stream] = XREF_ADDR_DERIVE; //In use + pContext->xref_database[XREF_D3D_g_Stream_i_pVertexBuffer] = XREF_ADDR_DERIVE; //In use pContext->xref_database[XREF_D3DDevice__m_PixelShader_OFFSET] = XREF_ADDR_DERIVE; // pContext->xref_database[XREF_D3DDevice__m_Textures_OFFSET] = XREF_ADDR_DERIVE; // pContext->xref_database[XREF_D3DDevice__m_Palettes_OFFSET] = XREF_ADDR_DERIVE; // @@ -1087,8 +1088,11 @@ unsigned int XbSymbolContext_ScanLibrary(XbSymbolContextHandle pHandle, output_message_format(&pContext->output, XB_OUTPUT_MESSAGE_DEBUG, "Scanning %.8s library in %.8s section", pLibrary->name, pSymbolDB->LibSec.section[d3]); - internal_OOVPA_scan(pContext, pSymbolDB->SymbolsTable, pSymbolDB->SymbolsTableCount, - &librarySession, pContext->section_input.filters + s, xref_first_pass); + internal_OOVPATableList_scan(pContext, + &librarySession, + pSymbolDB->Symbols, + pContext->section_input.filters + s, + xref_first_pass); break; } } @@ -1295,7 +1299,7 @@ unsigned XbSymbolDatabase_GetTotalSymbols(uint32_t library_filter) SymbolDatabaseList* pLibraryDB; while ((pLibraryDB = internal_FindLibraryDB(library_filter, &db_i))) { db_i++; - total += pLibraryDB->SymbolsTableCount; + total += pLibraryDB->Symbols->Count; } return total; } diff --git a/src/lib/manual_d3d8__ltcg.h b/src/lib/manual_d3d8__ltcg.h index c9b4cbda..98ca980a 100644 --- a/src/lib/manual_d3d8__ltcg.h +++ b/src/lib/manual_d3d8__ltcg.h @@ -362,25 +362,23 @@ static bool manual_scan_section_dx8_register_D3DRS(iXbSymbolContext* pContext, SymbolDatabaseList* pLibraryDB, const XbSDBSection* pSection) { - OOVPATable* pSymbol = NULL; - OOVPARevision* pRevision = NULL; // First, we need to find D3DDevice_SetRenderState_Simple symbol. xbaddr D3DDevice_SetRenderState_Simple = pContext->xref_database[XREF_D3DDevice_SetRenderState_Simple]; if (internal_IsXRefAddrUnset(D3DDevice_SetRenderState_Simple)) { - xbaddr xFuncAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "D3DDevice_SetRenderState_Simple", - pSection, - true, - &pSymbol, - &pRevision); + xbaddr xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_D3DDevice_SetRenderState_Simple, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_YES, + NULL, + NULL); // If not found, skip the rest of the scan. - if (xFuncAddr == 0) { + if (xSymbolAddr == 0) { return false; } - - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, pRevision->Version, xFuncAddr); } memptr_t pD3D_g_DeferredRenderStateOffset = 0; @@ -390,47 +388,50 @@ static bool manual_scan_section_dx8_register_D3DRS(iXbSymbolContext* pContext, if (internal_IsXRefAddrUnset(D3D_g_RenderState)) { // Below xref is used to obtain from D3DDevice_SetRenderState(Not)Inline signatures. pContext->xref_database[XREF_D3D_g_RenderState] = XREF_ADDR_DERIVE; - xbaddr xFuncAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "D3DDevice_SetRenderStateNotInline", - pSection, - true, - &pSymbol, - &pRevision); - if (xFuncAddr == 0) { + xbaddr xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_D3DDevice_SetRenderStateNotInline, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_YES, + NULL, + NULL); + if (xSymbolAddr == 0) { // If not found, then check if library is not LTCG. if (pLibrarySession->pLibrary->flag == XbSymbolLib_D3D8) { pContext->xref_database[XREF_D3D_g_RenderState] = XREF_ADDR_UNDETERMINED; return false; } // Otherwise, let's look up for D3DDevice_SetRenderStateInline__GenericFragment which is NOT a symbol. - xFuncAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "D3DDevice_SetRenderStateInline__GenericFragment", - pSection, - true, - &pSymbol, - &pRevision); + xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_D3DDevice_SetRenderStateInline__GenericFragment, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_NO, + NULL, + NULL); // If not found, skip the rest of the scan. - if (xFuncAddr == 0) { + if (xSymbolAddr == 0) { pContext->xref_database[XREF_D3D_g_RenderState] = XREF_ADDR_UNDETERMINED; return false; } // pointer to cmp opcode's value from D3DDevice_SetRenderStateInline__GenericFragment sig. - pD3D_g_DeferredRenderStateOffset = internal_section_VirtToHostAddress(pContext, xFuncAddr + 0x02); + pD3D_g_DeferredRenderStateOffset = internal_section_VirtToHostAddress(pContext, xSymbolAddr + 0x02); // If it is found, don't register it. } else { // pointer to cmp opcode's value from D3DDevice_SetRenderStateNotInline sig. - pD3D_g_DeferredRenderStateOffset = internal_section_VirtToHostAddress(pContext, xFuncAddr + 0x07); + pD3D_g_DeferredRenderStateOffset = internal_section_VirtToHostAddress(pContext, xSymbolAddr + 0x07); - // Register only D3DDevice_SetRenderStateNotInline symbol function. + // Self register only D3DDevice_SetRenderStateNotInline symbol function. // NOTE: D3DDevice_SetRenderStateInline__GenericFragment is NOT a symbol but a generic method to find D3D_g_RenderState. - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, pRevision->Version, xFuncAddr); } // D3D_g_RenderState variable is already set internal, will be register later. @@ -459,8 +460,6 @@ static bool manual_scan_section_dx8_register_D3DCRS(iXbSymbolContext* pContext, SymbolDatabaseList* pLibraryDB, const XbSDBSection* pSection) { - OOVPATable* pSymbol = NULL; - OOVPARevision* pRevision = NULL; // First, we need to find D3DRS_FillMode symbol. xbaddr D3DRS_FillMode = pContext->xref_database[XREF_D3DRS_FillMode]; if (internal_IsXRefAddrUnset(D3DRS_FillMode)) { @@ -468,23 +467,23 @@ static bool manual_scan_section_dx8_register_D3DCRS(iXbSymbolContext* pContext, pContext->xref_database[XREF_D3DRS_FillMode] = XREF_ADDR_DERIVE; pContext->xref_database[XREF_D3DRS_BackFillMode] = XREF_ADDR_DERIVE; pContext->xref_database[XREF_D3DRS_TwoSidedLighting] = XREF_ADDR_DERIVE; - xbaddr xFuncAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "D3DDevice_SetRenderState_FillMode", - pSection, - false, - &pSymbol, - &pRevision); + xbaddr xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_D3DDevice_SetRenderState_FillMode, + DB_ST_MANUAL, + FIRSTPASS_NO, + REGISTER_YES, + NULL, + NULL); // If not found, skip the rest of the scan. - if (xFuncAddr == 0) { + if (xSymbolAddr == 0) { pContext->xref_database[XREF_D3DRS_FillMode] = XREF_ADDR_UNDETERMINED; pContext->xref_database[XREF_D3DRS_BackFillMode] = XREF_ADDR_UNDETERMINED; pContext->xref_database[XREF_D3DRS_TwoSidedLighting] = XREF_ADDR_UNDETERMINED; return false; } - - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, pRevision->Version, xFuncAddr); } // Derived D3DRS_FillMode, D3DRS_BackFillMode, and D3DRS_TwoSidedLighting variables are already set. @@ -505,8 +504,6 @@ static bool manual_scan_section_dx8_register_D3DRS_end_of_list(iXbSymbolContext* SymbolDatabaseList* pLibraryDB, const XbSDBSection* pSection) { - OOVPATable* pSymbol = NULL; - OOVPARevision* pRevision = NULL; // First, we need to find D3DRS_DoNotCullUncompressed symbol. xbaddr D3DRS_DoNotCullUncompressed = pContext->xref_database[XREF_D3DRS_DoNotCullUncompressed]; if (internal_IsXRefAddrUnset(D3DRS_DoNotCullUncompressed)) { @@ -515,16 +512,18 @@ static bool manual_scan_section_dx8_register_D3DRS_end_of_list(iXbSymbolContext* pContext->xref_database[XREF_D3DRS_RopZCmpAlwaysRead] = XREF_ADDR_DERIVE; pContext->xref_database[XREF_D3DRS_RopZRead] = XREF_ADDR_DERIVE; pContext->xref_database[XREF_D3DRS_DoNotCullUncompressed] = XREF_ADDR_DERIVE; - xbaddr xFuncAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "D3D_CommonSetDebugRegisters", - pSection, - false, - &pSymbol, - &pRevision); + xbaddr xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_D3D_CommonSetDebugRegisters, + DB_ST_MANUAL, + FIRSTPASS_NO, + REGISTER_YES, + NULL, + NULL); // If not found, skip the rest of the scan. - if (xFuncAddr == 0) { + if (xSymbolAddr == 0) { pContext->xref_database[XREF_D3D_g_pDevice] = XREF_ADDR_UNDETERMINED; pContext->xref_database[XREF_D3DRS_RopZCmpAlwaysRead] = XREF_ADDR_UNDETERMINED; pContext->xref_database[XREF_D3DRS_RopZRead] = XREF_ADDR_UNDETERMINED; @@ -532,17 +531,16 @@ static bool manual_scan_section_dx8_register_D3DRS_end_of_list(iXbSymbolContext* return false; } - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, pRevision->Version, xFuncAddr); - - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, D3D_g_pDevice); - internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbol, 0); + OOVPATable* pSymbolEntry = NULL; + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, D3D_g_pDevice); + internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbolEntry, 0); #if 0 // TODO: Fix this after #208 pull request is merged. - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, D3DRS_RopZCmpAlwaysRead); - internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbol, 0); - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, D3DRS_RopZRead); - internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbol, 0); - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, D3DRS_DoNotCullUncompressed); - internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbol, 0); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, D3DRS_RopZCmpAlwaysRead); + internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbolEntry, 0); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, D3DRS_RopZRead); + internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbolEntry, 0); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, D3DRS_DoNotCullUncompressed); + internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbolEntry, 0); #endif } return true; @@ -554,8 +552,6 @@ static bool manual_scan_section_dx8_register_D3DRS_Stencils_and_Occlusion(iXbSym SymbolDatabaseList* pLibraryDB, const XbSDBSection* pSection) { - OOVPATable* pSymbol = NULL; - OOVPARevision* pRevision = NULL; // First, we need to find D3DRS_StencilEnable symbol. xbaddr D3DRS_StencilEnable = pContext->xref_database[XREF_D3DRS_StencilEnable]; if (internal_IsXRefAddrUnset(D3DRS_StencilEnable)) { @@ -564,16 +560,18 @@ static bool manual_scan_section_dx8_register_D3DRS_Stencils_and_Occlusion(iXbSym pContext->xref_database[XREF_D3DRS_StencilFail] = XREF_ADDR_DERIVE; pContext->xref_database[XREF_D3DRS_OcclusionCullEnable] = XREF_ADDR_DERIVE; pContext->xref_database[XREF_D3DRS_StencilCullEnable] = XREF_ADDR_DERIVE; - xbaddr xFuncAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "D3DRS_Stencils_and_Occlusion__GenericFragment", - pSection, - false, - &pSymbol, - &pRevision); + xbaddr xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_D3DRS_Stencils_and_Occlusion__GenericFragment, + DB_ST_MANUAL, + FIRSTPASS_NO, + REGISTER_NO, + NULL, + NULL); // If not found, skip the rest of the scan. - if (xFuncAddr == 0) { + if (xSymbolAddr == 0) { pContext->xref_database[XREF_D3DRS_StencilEnable] = XREF_ADDR_UNDETERMINED; pContext->xref_database[XREF_D3DRS_StencilFail] = XREF_ADDR_UNDETERMINED; pContext->xref_database[XREF_D3DRS_OcclusionCullEnable] = XREF_ADDR_UNDETERMINED; @@ -587,67 +585,24 @@ static bool manual_scan_section_dx8_register_D3DRS_Stencils_and_Occlusion(iXbSym } static void manual_scan_section_dx8_register_D3DTSS(iXbSymbolContext* pContext, - const iXbSymbolLibrarySession* pLibrarySession, - memptr_t pFunc, - uint32_t pXRefOffset) + const iXbSymbolLibrarySession* pLibrarySession) { - if (pFunc == NULL) { - return; - } const XbSDBLibrary* pLibrary = pLibrarySession->pLibrary; const eLibraryType iLibraryType = pLibrarySession->iLibraryType; - xbaddr DerivedAddr_D3DTSS_TEXCOORDINDEX = 0; + xbaddr DerivedAddr_D3DTSS_TEXCOORDINDEX = pContext->xref_database[XREF_D3DTSS_TEXCOORDINDEX]; int Decrement = 0x70; // TODO : Rename into something understandable - // TODO : Remove this when XREF_D3D_TextureState_TexCoordIndex derivation is deemed stable - { - DerivedAddr_D3DTSS_TEXCOORDINDEX = *(xbaddr*)(pFunc + pXRefOffset); - - // Temporary verification - is XREF_D3DTSS_TEXCOORDINDEX derived correctly? - if (pContext->xref_database[XREF_D3DTSS_TEXCOORDINDEX] != DerivedAddr_D3DTSS_TEXCOORDINDEX) { - - if (pContext->xref_database[XREF_D3DTSS_TEXCOORDINDEX] != XREF_ADDR_DERIVE) { - output_message(&pContext->output, XB_OUTPUT_MESSAGE_WARN, "Second derived XREF_D3DTSS_TEXCOORDINDEX differs from first!"); - } - - //SetXRefDataBase(pContext, iLibraryType, XREF_D3DTSS_BUMPENV, DerivedAddr_D3DTSS_TEXCOORDINDEX - 28*4); - internal_SetXRefDatabase(pContext, iLibraryType, XREF_D3DTSS_TEXCOORDINDEX, DerivedAddr_D3DTSS_TEXCOORDINDEX); - //SetXRefDataBase(pContext, iLibraryType, XREF_D3DTSS_BORDERCOLOR, DerivedAddr_D3DTSS_TEXCOORDINDEX + 1*4); - //SetXRefDataBase(pContext, iLibraryType, XREF_D3DTSS_COLORKEYCOLOR, DerivedAddr_D3DTSS_TEXCOORDINDEX + 2*4); - } - } + //internal_SetXRefDatabase(pContext, iLibraryType, XREF_D3DTSS_BUMPENV, DerivedAddr_D3DTSS_TEXCOORDINDEX - 28 * 4); + //internal_SetXRefDatabase(pContext, iLibraryType, XREF_D3DTSS_TEXCOORDINDEX, DerivedAddr_D3DTSS_TEXCOORDINDEX); // Already been set. + //internal_SetXRefDatabase(pContext, iLibraryType, XREF_D3DTSS_BORDERCOLOR, DerivedAddr_D3DTSS_TEXCOORDINDEX + 1 * 4); + //internal_SetXRefDatabase(pContext, iLibraryType, XREF_D3DTSS_COLORKEYCOLOR, DerivedAddr_D3DTSS_TEXCOORDINDEX + 2 * 4); uint32_t EmuD3DDeferredTextureState = DerivedAddr_D3DTSS_TEXCOORDINDEX - Decrement; internal_RegisterXRef(pContext, pLibrarySession, XREF_D3D_g_DeferredTextureState, 0, "D3D_g_DeferredTextureState", EmuD3DDeferredTextureState, symbol_variable, call_none, 0, NULL, true); } -static void manual_scan_section_dx8_register_stream(iXbSymbolContext* pContext, - const iXbSymbolLibrarySession* pLibrarySession, - memptr_t pFunc, - uint32_t iCodeOffsetFor_g_Stream) -{ - if (pFunc == NULL) { - return; - } - const XbSDBLibrary* pLibrary = pLibrarySession->pLibrary; - - // Read address of Xbox_g_Stream from D3DDevice_SetStreamSource - uint32_t Derived_g_Stream = *((uint32_t*)(pFunc + iCodeOffsetFor_g_Stream)); - - // Temporary verification - is XREF_D3D_g_Stream derived correctly? - // TODO : Remove this when XREF_D3D_g_Stream derivation is deemed stable -#if 0 // TODO: How can we enforce it for callback? - VerifySymbolAddressAgainstXRef("g_Stream", Derived_g_Stream, XREF_D3D_g_Stream); -#endif - - // Now that both Derived XREF and OOVPA-based function-contents match, - // correct base-address (because "g_Stream" is actually "g_Stream"+8") : - Derived_g_Stream -= 8; - pContext->register_func(pLibrary->name, pLibrary->flag, XREF_D3D_g_Stream, "D3D_g_Stream", Derived_g_Stream, 0, symbol_variable, call_none, 0, NULL); -} - // Has dependency on D3D_g_pDevice xref. static bool manual_scan_section_dx8_register_callbacks(iXbSymbolContext* pContext, const iXbSymbolLibrarySession* pLibrarySession, @@ -657,8 +612,6 @@ static bool manual_scan_section_dx8_register_callbacks(iXbSymbolContext* pContex // Generic usage memptr_t pFunc = 0; xbaddr xSymbolAddr = 0; - OOVPATable* pSymbol = NULL; - const eLibraryType iLibraryType = pLibrarySession->iLibraryType; // Manual check require for able to self-register these symbols: // * D3DDevice_SetSwapCallback // * D3DDevice_SetVerticalBlankCallback @@ -670,14 +623,16 @@ static bool manual_scan_section_dx8_register_callbacks(iXbSymbolContext* pContex // Scan if event handle variable is not yet derived. if (pContext->xref_database[XREF_D3DDevice__m_VerticalBlankEvent_OFFSET] == XREF_ADDR_DERIVE) { - xSymbolAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "D3DDevice__m_VerticalBlankEvent__GenericFragment", - pSection, - true, - NULL, - NULL); + xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_D3DDevice__m_VerticalBlankEvent__GenericFragment, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_NO, + NULL, + NULL); } // We are not registering D3DDevice__m_VerticalBlankEvent__GenericFragment itself, as it is NOT a symbol. @@ -689,13 +644,14 @@ static bool manual_scan_section_dx8_register_callbacks(iXbSymbolContext* pContex } // Finally, manual register the symbol variables. + OOVPATable* pSymbolEntry = NULL; xSymbolAddr = pContext->xref_database[XREF_D3DDevice__m_VerticalBlankEvent_OFFSET]; - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, D3DDevice__m_VerticalBlankEvent_OFFSET); - internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbol, 0); - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, D3DDevice__m_SwapCallback_OFFSET); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 0, xSymbolAddr - 8); - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, D3DDevice__m_VBlankCallback_OFFSET); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 0, xSymbolAddr - 4); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, D3DDevice__m_VerticalBlankEvent_OFFSET); + internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbolEntry, 0); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, D3DDevice__m_SwapCallback_OFFSET); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 0, xSymbolAddr - 8); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, D3DDevice__m_VBlankCallback_OFFSET); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 0, xSymbolAddr - 4); } // If D3D_g_pDevice is not found, the scan is not complete // and will continue scan to next given section. @@ -712,16 +668,9 @@ static bool manual_scan_section_dx8(iXbSymbolContext* pContext, const XbSDBSection* pSection) { // Generic usage - memptr_t pFunc = 0; - xbaddr xSymbolAddr = 0; - int OOVPA_version; - int iCodeOffsetFor_g_Stream; - int pXRefOffset = 0; // TODO : Rename into something understandable + memptr_t pSymbolAddr = 0; uintptr_t virt_start_relative = (uintptr_t)pSection->buffer_lower - pSection->xb_virt_addr; const XbSDBLibrary* pLibrary = pLibrarySession->pLibrary; - const eLibraryType iLibraryType = pLibrarySession->iLibraryType; - - OOVPARevision* pOOVPARevision = NULL; // We need to mask boolean from each function's scan process if any return false. // Needed for no dependency, scanning multiple sections, and library's databases. @@ -753,161 +702,58 @@ static bool manual_scan_section_dx8(iXbSymbolContext* pContext, return bComplete; } - // then locate D3DDeferredTextureState - if (pLibrary->flag == XbSymbolLib_D3D8) { - - if (pLibrary->build_version < 3911) { - // Not supported, currently ignored. - pFunc = 0; - } - else { - pFunc = internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "D3DDevice_SetTextureState_TexCoordIndex", - pSection, - true, - NULL, - NULL); - - // TODO: Can we integrate below into XRef? - if (pLibrary->build_version < 4034) { - pXRefOffset = 0x11; - } - else if (pLibrary->build_version < 4242) { - pXRefOffset = 0x18; - } - else { - pXRefOffset = 0x19; - } - } - } - else { // D3D8LTCG - - /* - // TODO: Need some reform work for this portion. Since there are mixture of suffix involved. - // Current listing are: - // - D3DDevice_SetTextureState_TexCoordIndex (1944, 1958) - // - D3DDevice_SetTextureState_TexCoordIndex_0 (2039, 2058) - // - D3DDevice_SetTextureState_TexCoordIndex_4 (2040, 2045, 2058, 2052) - pFunc = internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "", - pSection, - false, - pOOVPARevision); - //*/ - - // verified for 3925 - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetTextureState_TexCoordIndex_0__LTCG_edi1_eax2", 2039, - &D3DDevice_SetTextureState_TexCoordIndex_0__LTCG_edi1_eax2_2039, pSection); - pXRefOffset = 0x08; - - if (pFunc == 0) { // verified for 4039 - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetTextureState_TexCoordIndex_4__LTCG_esi1", 2040, - &D3DDevice_SetTextureState_TexCoordIndex_4__LTCG_esi1_2040, pSection); - pXRefOffset = 0x14; - } - - if (pFunc == 0) { // verified for 4432 - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetTextureState_TexCoordIndex", 1944, - &D3DDevice_SetTextureState_TexCoordIndex_1944, pSection); - pXRefOffset = 0x19; - } - - if (pFunc == 0) { // verified for 4531 - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetTextureState_TexCoordIndex_4__LTCG_esi1", 2045, - &D3DDevice_SetTextureState_TexCoordIndex_4__LTCG_esi1_2045, pSection); - pXRefOffset = 0x14; - } - - if (pFunc == 0) { // verified for 4627 and higher - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetTextureState_TexCoordIndex_4__LTCG_esi1", 2058, - &D3DDevice_SetTextureState_TexCoordIndex_4__LTCG_esi1_2058, pSection); - pXRefOffset = 0x14; - } - - if (pFunc == 0) { // verified for 4627 and higher - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetTextureState_TexCoordIndex", 1958, - &D3DDevice_SetTextureState_TexCoordIndex_1958, pSection); - pXRefOffset = 0x19; - } - - if (pFunc == 0) { // verified for World Series Baseball 2K3 - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetTextureState_TexCoordIndex_4__LTCG_esi1", 2052, - &D3DDevice_SetTextureState_TexCoordIndex_4__LTCG_esi1_2052, pSection); - pXRefOffset = 0x15; - } - - if (pFunc == 0) { // verified for Ski Racing 2006 - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetTextureState_TexCoordIndex_0__LTCG_edi1_eax2", 2058, - &D3DDevice_SetTextureState_TexCoordIndex_0__LTCG_edi1_eax2_2058, pSection); - pXRefOffset = 0x15; - } - } - - if (pFunc != 0) { - // NOTE: Is a requirement to align properly. - pFunc += virt_start_relative; - manual_scan_section_dx8_register_D3DTSS(pContext, pLibrarySession, pFunc, pXRefOffset); + if (pLibrary->build_version < 3911) { + // Not supported, currently ignored. + return true; } - // Locate Xbox symbol "g_Stream" and store it's address - pFunc = 0; - // verified for D3D8 with 4361, 4627, 5344, 5558, 5659, 5788, 5849, 5933 - // and verified for LTCG with 4432, 4627, 5344, 5558, 5849 - iCodeOffsetFor_g_Stream = 0x22; - - // TODO: Need investigate reason for going with higher number first then lower last. - if (pLibrary->flag == XbSymbolLib_D3D8) { - if (pLibrary->build_version >= 4034) { - OOVPA_version = 4034; - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetStreamSource", 4034, - &D3DDevice_SetStreamSource_4034, pSection); - } - else { - OOVPA_version = 3911; - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetStreamSource", 3911, - &D3DDevice_SetStreamSource_3911, pSection); - iCodeOffsetFor_g_Stream = 0x23; // verified for 3911 - } + // then locate D3DDeferredTextureState + OOVPATable* pSymbolEntry = NULL; + OOVPARevision* pSymbolEntryRevision = NULL; + pSymbolAddr = internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_D3DDevice_SetTextureState_TexCoordIndex, DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_YES, + &pSymbolEntry, + &pSymbolEntryRevision); + + if (pSymbolAddr != 0) { + // Self register D3DDevice_SetTextureState_TexCoordIndex + + manual_scan_section_dx8_register_D3DTSS(pContext, pLibrarySession); } - else { // D3D8LTCG - if (pLibrary->build_version > 4039) { - OOVPA_version = 4034; // TODO Verify - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetStreamSource", 1044, - &D3DDevice_SetStreamSource_1044, pSection); - } - - if (pFunc == 0) { // LTCG specific - - OOVPA_version = 4034; // TODO Verify - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetStreamSource_4__LTCG_eax1_ebx2", 2058, - &D3DDevice_SetStreamSource_4__LTCG_eax1_ebx2_2058, pSection); - iCodeOffsetFor_g_Stream = 0x1E; - } - if (pFunc == 0) { // verified for 4039 - OOVPA_version = 4034; - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetStreamSource_8__LTCG_eax1", 2040, - &D3DDevice_SetStreamSource_8__LTCG_eax1_2040, pSection); - iCodeOffsetFor_g_Stream = 0x23; + pSymbolEntry = NULL; + pSymbolEntryRevision = NULL; + pSymbolAddr = internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_D3DDevice_SetStreamSource, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_YES, + &pSymbolEntry, + &pSymbolEntryRevision); + + if (pSymbolAddr != 0) { + // Self register D3DDevice_SetStreamSource + + xbaddr D3D_g_Stream = pContext->xref_database[XREF_D3D_g_Stream]; + xbaddr D3D_g_Stream_i_pVertexBuffer = pContext->xref_database[XREF_D3D_g_Stream_i_pVertexBuffer]; + + // Verify both variables are offset correctly. + if (D3D_g_Stream_i_pVertexBuffer - D3D_g_Stream != 8) { + // If not correct, then do the correction in case of third-party rely on this. + output_message_format(&pContext->output, XB_OUTPUT_MESSAGE_ERROR, "D3D_g_Stream_i_pVertexBuffer (0x%08X) - D3D_g_Stream (0x%08X) != 0x8", D3D_g_Stream_i_pVertexBuffer, D3D_g_Stream); + pContext->xref_database[XREF_D3D_g_Stream] = D3D_g_Stream_i_pVertexBuffer - 8; } - if (pFunc == 0) { // verified for 3925 - OOVPA_version = 3911; - pFunc = LocateSymbolCast(pContext, iLibraryType, "D3DDevice_SetStreamSource_8__LTCG_edx1", 2039, - &D3DDevice_SetStreamSource_8__LTCG_edx1_2039, pSection); - iCodeOffsetFor_g_Stream = 0x47; - } - } - - if (pFunc != 0) { - // NOTE: Is a requirement to align properly. - pFunc += virt_start_relative; - - manual_scan_section_dx8_register_stream(pContext, pLibrarySession, pFunc, iCodeOffsetFor_g_Stream); + // TODO: Use internal_FindByReferenceHelper to get OOVPA revision. Or better yet, do self register. + internal_RegisterValidXRefAddr(pContext, pLibrary->name, pLibrary->flag, XREF_D3D_g_Stream, 0, "D3D_g_Stream", symbol_variable, call_none, 0, NULL); } bComplete = manual_scan_section_dx8_register_callbacks(pContext, pLibrarySession, pLibraryDB, pSection); diff --git a/src/lib/manual_dsound.h b/src/lib/manual_dsound.h index f4e68894..eb779c06 100644 --- a/src/lib/manual_dsound.h +++ b/src/lib/manual_dsound.h @@ -14,11 +14,8 @@ static bool manual_scan_section_dsound(iXbSymbolContext* pContext, xbaddr xblower = pSection->xb_virt_addr; xbaddr xbupper = pSection->xb_virt_addr + pSection->buffer_size; uintptr_t virt_start_relative = (uintptr_t)pSection->buffer_lower - pSection->xb_virt_addr; - xbaddr xFuncAddr = 0; - memptr_t pFuncAddr = 0; - const XbSDBLibrary* pLibrary = pLibrarySession->pLibrary; - const eLibraryType iLibraryType = pLibrarySession->iLibraryType; - OOVPATable* pSymbol = NULL; + xbaddr xSymbolAddr = 0; + memptr_t pSymbolAddr = 0; /* bool testRun = 1; @@ -27,28 +24,27 @@ static bool manual_scan_section_dsound(iXbSymbolContext* pContext, // Scan for DirectSoundStream's constructor function. if (pContext->xref_database[XREF_CDirectSoundStream_Constructor] == XREF_ADDR_UNDETERMINED) { - // TODO: Lookup xref index instead of symbol name. - xFuncAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "CDirectSoundStream_Constructor", - pSection, - true, - &pSymbol, - NULL); + xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_CDirectSoundStream_Constructor, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_YES, + NULL, + NULL); // If not found, skip the rest of the scan. - if (xFuncAddr == 0) { + if (xSymbolAddr == 0) { return false; } - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 3911, xFuncAddr); - // TODO: If possible, integrate into the OOVPA structure. internal_RegisterXRef(pContext, pLibrarySession, XREF_DSS_VOICE_VTABLE, 3911, - NULL, *(xbaddr*)(virt_start_relative + xFuncAddr + 0x14), symbol_variable, call_none, 0, NULL, false); + NULL, *(xbaddr*)(virt_start_relative + xSymbolAddr + 0x14), symbol_variable, call_none, 0, NULL, false); internal_RegisterXRef(pContext, pLibrarySession, XREF_DSS_STREAM_VTABLE, 3911, - NULL, *(xbaddr*)(virt_start_relative + xFuncAddr + 0x1B), symbol_variable, call_none, 0, NULL, false); + NULL, *(xbaddr*)(virt_start_relative + xSymbolAddr + 0x1B), symbol_variable, call_none, 0, NULL, false); } // Verify both variables are already set from the scan function above. @@ -64,35 +60,35 @@ static bool manual_scan_section_dsound(iXbSymbolContext* pContext, xbaddr vtable = pContext->xref_database[XREF_DSS_STREAM_VTABLE]; if (xblower <= vtable && vtable < xbupper) { - pFuncAddr = (memptr_t)virt_start_relative + vtable; - OOVPATable* pSymbol = NULL; - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, CDirectSoundStream_AddRef); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 3911, *(uint32_t*)(pFuncAddr + 0 * 4)); + pSymbolAddr = (memptr_t)virt_start_relative + vtable; + OOVPATable* pSymbolEntry = NULL; + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, CDirectSoundStream_AddRef); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 3911, *(uint32_t*)(pSymbolAddr + 0 * 4)); - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, CDirectSoundStream_Release); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 3911, *(uint32_t*)(pFuncAddr + 1 * 4)); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, CDirectSoundStream_Release); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 3911, *(uint32_t*)(pSymbolAddr + 1 * 4)); - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, CDirectSoundStream_GetInfo); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 3911, *(uint32_t*)(pFuncAddr + 2 * 4)); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, CDirectSoundStream_GetInfo); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 3911, *(uint32_t*)(pSymbolAddr + 2 * 4)); - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, CDirectSoundStream_GetStatus); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, CDirectSoundStream_GetStatus); // TODO: May need further investigation with Cxbx-Reloaded's source code for possible reasoning why this method is used. SYMBOL_COUNTER_VALUE; // Force increase by one symbol counter since we do not have both revisions difference in the OOVPA database. - if (pLibrary->build_version < 4134) { - internal_RegisterSymbolHelper(pContext, pLibrarySession, pSymbol, "CDirectSoundStream_GetStatus__r1", 3911, *(uint32_t*)(pFuncAddr + 3 * 4)); + if (pLibrarySession->pLibrary->build_version < 4134) { + internal_RegisterSymbolHelper(pContext, pLibrarySession, pSymbolEntry, "CDirectSoundStream_GetStatus__r1", 3911, *(uint32_t*)(pSymbolAddr + 3 * 4)); } else { - internal_RegisterSymbolHelper(pContext, pLibrarySession, pSymbol, "CDirectSoundStream_GetStatus__r2", 4134, *(uint32_t*)(pFuncAddr + 3 * 4)); + internal_RegisterSymbolHelper(pContext, pLibrarySession, pSymbolEntry, "CDirectSoundStream_GetStatus__r2", 4134, *(uint32_t*)(pSymbolAddr + 3 * 4)); } - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, CDirectSoundStream_Process); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 3911, *(uint32_t*)(pFuncAddr + 4 * 4)); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, CDirectSoundStream_Process); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 3911, *(uint32_t*)(pSymbolAddr + 4 * 4)); - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, CDirectSoundStream_Discontinuity); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 3911, *(uint32_t*)(pFuncAddr + 5 * 4)); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, CDirectSoundStream_Discontinuity); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 3911, *(uint32_t*)(pSymbolAddr + 5 * 4)); - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, CDirectSoundStream_Flush); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 3911, *(uint32_t*)(pFuncAddr + 6 * 4)); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, CDirectSoundStream_Flush); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 3911, *(uint32_t*)(pSymbolAddr + 6 * 4)); // NOTE: it is possible to manual add GetInfo, GetStatus, Process, Discontinuity, // and Flush functions. diff --git a/src/lib/manual_xapilib.h b/src/lib/manual_xapilib.h index 818e7579..d6630201 100644 --- a/src/lib/manual_xapilib.h +++ b/src/lib/manual_xapilib.h @@ -11,26 +11,26 @@ static bool internal_xapi_find_XGetSectionSize(iXbSymbolContext* pContext, const XbSDBSection* pSection, uintptr_t virt_start_relative) { - xbaddr xXbAddr = 0; - OOVPARevision* pOOVPARevision = NULL; - OOVPATable* pSymbol = NULL; + xbaddr xSymbolAddr = 0; + OOVPARevision* pSymbolRevision = NULL; + OOVPATable* pSymbolEntry = NULL; // Find XapiMapLetterToDirectory function if (!internal_IsXRefAddrValid(pContext->xref_database[XREF_XapiMapLetterToDirectory])) { - const char* sig_func_str = "XapiMapLetterToDirectory"; const char* xref_str = "XGetSectionSize"; - xXbAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - sig_func_str, - pSection, - true, - &pSymbol, - &pOOVPARevision); + xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_XapiMapLetterToDirectory, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_YES, + &pSymbolEntry, + &pSymbolRevision); - if (xXbAddr) { - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, pOOVPARevision->Version, xXbAddr); + if (xSymbolAddr) { // Register XGetSectionSize function. if (!internal_IsXRefAddrValid(pContext->xref_database[XREF_XGetSectionSize])) { @@ -38,20 +38,20 @@ static bool internal_xapi_find_XGetSectionSize(iXbSymbolContext* pContext, output_message_format(&pContext->output, XB_OUTPUT_MESSAGE_ERROR, "Please verify %s (%hu) signature do contain %s's xref entry.", - sig_func_str, pOOVPARevision->Version, xref_str); + pSymbolEntry->szSymbolName, pSymbolRevision->Version, xref_str); return false; } // Manually translate to virtual address from relative address. - xXbAddr = internal_OOVPARevision_ConvertXRefRelativeAddrtToVirtAddr(pContext, pSymbol, pOOVPARevision, xref_str, XREF_XGetSectionSize); - if (!xXbAddr) { + xSymbolAddr = internal_OOVPARevision_ConvertXRefRelativeAddrtToVirtAddr(pContext, pSymbolEntry, pSymbolRevision, xref_str, XREF_XGetSectionSize); + if (!xSymbolAddr) { // Error message is handled by above function. No extra message necessary here. return false; } // Update to use virtual address instead of relative address. - pContext->xref_database[XREF_XGetSectionSize] = xXbAddr; + pContext->xref_database[XREF_XGetSectionSize] = xSymbolAddr; - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, XGetSectionSize); - internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbol, pOOVPARevision->Version); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, XGetSectionSize); + internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbolEntry, pSymbolRevision->Version); } } @@ -64,26 +64,22 @@ static bool internal_xapi_find_DeviceType_MU(iXbSymbolContext* pContext, const XbSDBSection* pSection, uintptr_t virt_start_relative) { - xbaddr xXbAddr = 0; - OOVPARevision* pOOVPARevision = NULL; - OOVPATable* pSymbol = NULL; + xbaddr xSymbolAddr = 0; memptr_t buffer_upper = (memptr_t)pSection->buffer_lower + pSection->buffer_size; // Find MU_Init function if (!internal_IsXRefAddrValid(pContext->xref_database[XREF_MU_Init])) { - xXbAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "MU_Init", - pSection, - true, - &pSymbol, - &pOOVPARevision); - - if (xXbAddr) { - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, pOOVPARevision->Version, xXbAddr); - } + xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_MU_Init, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_YES, + NULL, + NULL); } if (!internal_IsXRefAddrValid(pContext->xref_database[XREF_MU_Init])) { @@ -94,24 +90,24 @@ static bool internal_xapi_find_DeviceType_MU(iXbSymbolContext* pContext, // Scan for IUsbInit::GetMaxDeviceTypeCount function. if (!internal_IsXRefAddrValid(pContext->xref_database[XREF_IUsbInit_GetMaxDeviceTypeCount])) { - xXbAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "IUsbInit_GetMaxDeviceTypeCount", - pSection, - true, - &pSymbol, - NULL); + xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_IUsbInit_GetMaxDeviceTypeCount, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_YES, + NULL, + NULL); // If not found, skip the rest of the scan. - if (xXbAddr == 0) { + if (xSymbolAddr == 0) { return false; } - - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 3911, xXbAddr); } - xXbAddr = 0; + xSymbolAddr = 0; // TODO: Move below into separate function. // search all of the buffer memory range for (memptr_t cur = (memptr_t)virt_start_relative + pContext->xref_database[XREF_MU_Init]; cur < buffer_upper; cur++) { @@ -128,7 +124,7 @@ static bool internal_xapi_find_DeviceType_MU(iXbSymbolContext* pContext, xbaddr ActualAddr = *(xbaddr*)(cur + 6); if (MatchXRefAddr(cur + 6, virt_start_relative, pContext->xref_database[XREF_IUsbInit_GetMaxDeviceTypeCount])) { // this is where g_DeviceType_MU hardcode address reside in. - xXbAddr = *(xbaddr*)(cur + 1); + xSymbolAddr = *(xbaddr*)(cur + 1); break; } } @@ -138,8 +134,9 @@ static bool internal_xapi_find_DeviceType_MU(iXbSymbolContext* pContext, if (!internal_IsXRefAddrValid(pContext->xref_database[XREF_g_DeviceType_MU])) { // Register g_DeviceType_MU - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, g_DeviceType_MU); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 3911, xXbAddr); + OOVPATable* pSymbolEntry = NULL; + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, g_DeviceType_MU); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, pSymbolEntry->revisions[0].Version, xSymbolAddr); } return true; @@ -151,42 +148,44 @@ static bool internal_xapi_find_device_types(iXbSymbolContext* pContext, const XbSDBSection* pSection, uintptr_t virt_start_relative) { - xbaddr xXbAddr = 0; - OOVPARevision* pOOVPARevision = NULL; - OOVPATable* pSymbol = NULL; + xbaddr xSymbolAddr = 0; // Find GetTypeInformation_4 function if (!internal_IsXRefAddrValid(pContext->xref_database[XREF_GetTypeInformation_4])) { - xXbAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "GetTypeInformation_4", - pSection, - true, - &pSymbol, - &pOOVPARevision); + xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_GetTypeInformation_4, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_YES, + NULL, + NULL); // If GetTypeInformation_4 is not found, then try find GetTypeInformation_8 - if (!xXbAddr) { - xXbAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "GetTypeInformation_8", - pSection, - true, - &pSymbol, - &pOOVPARevision); + if (!xSymbolAddr) { + xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_GetTypeInformation_8, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_YES, + NULL, + NULL); } // If either GetTypeInformation overload is found, start look up in DeviceTypeInfo table's entries. - if (xXbAddr) { - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, pOOVPARevision->Version, xXbAddr); + if (xSymbolAddr) { // TODO: Make below as self-register - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, g_DeviceTypeInfoTableBegin); - internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbol, 4242); - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, g_DeviceTypeInfoTableEnd); - internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbol, 4242); + OOVPATable* pSymbolEntry = NULL; + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, g_DeviceTypeInfoTableBegin); + internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbolEntry, 4242); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, g_DeviceTypeInfoTableEnd); + internal_RegisterSelfValidXRefAddr(pContext, pLibrarySession, pSymbolEntry, 4242); uint32_t* table_i = (uint32_t*)internal_section_VirtToHostAddress(pContext, pContext->xref_database[XREF_g_DeviceTypeInfoTableBegin]); uint32_t* table_end = (uint32_t*)internal_section_VirtToHostAddress(pContext, pContext->xref_database[XREF_g_DeviceTypeInfoTableEnd]); @@ -212,25 +211,25 @@ static bool internal_xapi_find_device_types(iXbSymbolContext* pContext, } switch (DeviceTypeInfo->ucType) { case 1: // Gamepad (Generic) - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, g_DeviceType_Gamepad); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 0, DeviceTypeInfo->XppType); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, g_DeviceType_Gamepad); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 0, DeviceTypeInfo->XppType); break; case 2: // Keyboard - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, g_DeviceType_Keyboard); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 0, DeviceTypeInfo->XppType); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, g_DeviceType_Keyboard); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 0, DeviceTypeInfo->XppType); break; case 3: // IR Dongle - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, g_DeviceType_IRDongle); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 0, DeviceTypeInfo->XppType); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, g_DeviceType_IRDongle); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 0, DeviceTypeInfo->XppType); break; case 4: // Mouse // NOTE: Possibly introduced when Phantasy Star Online (b4831) added keyboard support. - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, g_DeviceType_Mouse); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 0, DeviceTypeInfo->XppType); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, g_DeviceType_Mouse); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 0, DeviceTypeInfo->XppType); break; case 128: // Steel Battalion - internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbol, g_DeviceType_SBC); - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, 4242, DeviceTypeInfo->XppType); + internal_FindByReferenceHelper(pContext, pLibraryDB, pSymbolEntry, g_DeviceType_SBC); + internal_RegisterSymbol(pContext, pLibrarySession, pSymbolEntry, 4242, DeviceTypeInfo->XppType); break; default: // Unknown output_message_format(&pContext->output, XB_OUTPUT_MESSAGE_WARN, "Unknown device type, DeviceTypeInfoTable[%hhu]: ucType = %hhu, XppType = %08X", i, DeviceTypeInfo->ucType, DeviceTypeInfo->XppType); @@ -241,23 +240,22 @@ static bool internal_xapi_find_device_types(iXbSymbolContext* pContext, else { // Find XInputOpen function if (!internal_IsXRefAddrValid(pContext->xref_database[XREF_XInputOpen])) { - xXbAddr = (xbaddr)(uintptr_t)internal_LocateSymbolScan(pContext, - pLibrarySession, - pLibraryDB, - "XInputOpen", - pSection, - true, - &pSymbol, - &pOOVPARevision); - if (xXbAddr) { - internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, pOOVPARevision->Version, xXbAddr); - // No further manual action require. - } + xSymbolAddr = (xbaddr)(uintptr_t)internal_SymbolDatabaseList_ScanByReference(pContext, + pLibrarySession, + pLibraryDB, + pSection, + XREF_XInputOpen, + DB_ST_MANUAL, + FIRSTPASS_YES, + REGISTER_YES, + NULL, + NULL); + // No further manual action require. } } } - if (!xXbAddr) { + if (!xSymbolAddr) { return false; } diff --git a/src/test/libverify/D3D8.cpp b/src/test/libverify/D3D8.cpp index aeba3f86..14f6ac32 100644 --- a/src/test/libverify/D3D8.cpp +++ b/src/test/libverify/D3D8.cpp @@ -497,7 +497,7 @@ void getLibraryD3D8(library_db& lib_db) // TODO: database is incomplete + 3 internal reference need to be exclude. // Excluding: // - 3 internal manual scan reference - // - 1 variables + // - 2 variables // - 5 internal offsets - lib_db.xref_exclude = 9; + lib_db.xref_exclude = 10; }