Skip to content

Commit

Permalink
Merge pull request #199 from jackchentwkh/add_kickoff_ltcg
Browse files Browse the repository at this point in the history
Add LTCG symbols: CDevice_KickOff variants, D3DDevice_MakeSpace, and XGSetSurfaceHeader
  • Loading branch information
ergo720 authored Oct 28, 2023
2 parents 3896aab + b070478 commit 0884e10
Show file tree
Hide file tree
Showing 20 changed files with 340 additions and 92 deletions.
1 change: 1 addition & 0 deletions include/xref/xgraphic.def
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ XREF_SYMBOL(XFONT_OpenBitmapFontFromMemory)
XREF_SYMBOL(XGCompressRect)
XREF_SYMBOL(XGIsSwizzledFormat)
XREF_SYMBOL(XGSetIndexBufferHeader)
XREF_SYMBOL(XGSetSurfaceHeader)
XREF_SYMBOL(XGSetTextureHeader)
XREF_SYMBOL(XGSetVertexBufferHeader)
XREF_SYMBOL(XGSwizzleBox)
Expand Down
27 changes: 15 additions & 12 deletions src/OOVPADatabase/D3D8/3911.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1464,23 +1464,26 @@ OOVPA_SIG_MATCH(
// ******************************************************************
// * D3D::CDevice::KickOff
// ******************************************************************
OOVPA_SIG_HEADER_NO_XREF(CDevice_KickOff,
3911)
OOVPA_SIG_HEADER_XREF(CDevice_KickOff,
3911,
XRefOne)
OOVPA_SIG_MATCH(
// mov eax, [D3D_g_pDevice]
XREF_ENTRY(0x1F, XREF_D3D_g_pDevice),

{ 0x01, 0xA1 },
// push ecx
// mov eax, [addr]
OV_MATCH(0x00, 0x51, 0xA1),

{ 0x32, 0x81 },
{ 0x33, 0xCA },
{ 0x36, 0x01 },
// test byte ptr [ecx + 0xC], 0x04
// jz eip + 8
OV_MATCH(0x0E, 0xF6, 0x41, 0x0C, 0x04, 0x74, 0x08),

{ 0x5E, 0x89 },
{ 0x5F, 0x50 },
{ 0x60, 0x40 },
// mov eax, [D3D_g_pDevice]
OV_MATCH(0x1E, 0xA1),

{ 0x90, 0x83 },
{ 0x91, 0xEA },
{ 0x92, 0x02 },
// ret
OV_MATCH(0x69, 0xC3),
//
);

Expand Down
48 changes: 19 additions & 29 deletions src/OOVPADatabase/D3D8/4034.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1568,23 +1568,19 @@ OOVPA_SIG_MATCH(
OOVPA_SIG_HEADER_NO_XREF(CDevice_KickOff,
4034)
OOVPA_SIG_MATCH(
// push ecx
OV_MATCH(0x00, 0x51),

{ 0x00, 0x51 },
{ 0x0E, 0x04 },
{ 0x0F, 0x74 },
{ 0x10, 0x08 },
{ 0x11, 0x8B },
{ 0x12, 0x89 },
{ 0x1B, 0xA1 },

{ 0x80, 0x08 },
{ 0x81, 0x00 },
{ 0x82, 0x20 },
{ 0x83, 0x00 },
{ 0x84, 0x00 },
{ 0x85, 0x59 },
{ 0x86, 0xC3 },
{ 0x87, 0xB8 },
// mov eax, [ecx + 8]
OV_MATCH(0x05, 0x8B, 0x41, 0x08),
// test ah, 20h
OV_MATCH(0x08, 0xF6, 0xC4, 0x20),

// or [eax + 0x08], 0x2000
OV_MATCH(0x7E, 0x81, 0x48, 0x08, 0x00, 0x20, 0x00, 0x00), // unique

// ret
OV_MATCH(0x86, 0xC3),
//
);

Expand Down Expand Up @@ -1794,22 +1790,16 @@ OOVPA_SIG_HEADER_XREF(D3DDevice_MakeSpace,
4034,
XRefOne)
OOVPA_SIG_MATCH(

// D3DDevice_MakeSpace+0x06 : call D3D::MakeRequestedSpace
// call D3D::MakeRequestedSpace
XREF_ENTRY(0x07, XREF_D3D_MakeRequestedSpace),

// D3DDevice_MakeSpace+0x00 : mov eax,[addr]
// mov eax, [addr]
OV_MATCH(0x00, 0xA1),

// D3DDevice_MakeSpace+0x05 : push eax
OV_MATCH(0x05, 0x50),

// D3DDevice_MakeSpace+0x06 : call D3D::MakeRequestedSpace
OV_MATCH(0x06, 0xE8),

// D3DDevice_MakeSpace+0x0B : ret
OV_MATCH(0x0B, 0xC3),

// push eax
// call D3D::MakeRequestedSpace
OV_MATCH(0x05, 0x50, 0xE8),
// ret
OV_MATCH(0x0B, 0xC3), // required to separate this detection from inlined function
//
);

Expand Down
15 changes: 6 additions & 9 deletions src/OOVPADatabase/D3D8/4134.inl
Original file line number Diff line number Diff line change
Expand Up @@ -614,21 +614,18 @@ OOVPA_SIG_HEADER_XREF(D3DDevice_MakeSpace,
4134,
XRefOne)
OOVPA_SIG_MATCH(

// D3DDevice_MakeSpace+0x09 : call D3D::MakeRequestedSpace
// call D3D::MakeRequestedSpace
XREF_ENTRY(0x0A, XREF_D3D_MakeRequestedSpace),

// D3DDevice_MakeSpace+0x00 : mov eax,[addr]
// mov eax, [addr]
OV_MATCH(0x00, 0xA1),

// D3DDevice_MakeSpace+0x05 : push eax
// push eax
OV_MATCH(0x05, 0x50),

// D3DDevice_MakeSpace+0x09 : call D3D::MakeRequestedSpace
// call D3D::MakeRequestedSpace
OV_MATCH(0x09, 0xE8),

// D3DDevice_MakeSpace+0x0E : ret
OV_MATCH(0x0E, 0xC3),
// ret
OV_MATCH(0x0E, 0xC3), // required to separate this detection from inlined function
//
);

Expand Down
31 changes: 11 additions & 20 deletions src/OOVPADatabase/D3D8/4531.inl
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,18 @@ OOVPA_SIG_MATCH(
OOVPA_SIG_HEADER_NO_XREF(CDevice_KickOff,
4531)
OOVPA_SIG_MATCH(
// push ecx
OV_MATCH(0x00, 0x51),

// D3D::CDevice::KickOff+0x0B : mov edx, [ecx+0x35C]
{ 0x0B, 0x8B },
{ 0x0C, 0x91 },
{ 0x0D, 0x5C },
{ 0x0E, 0x03 },
{ 0x0F, 0x00 },
{ 0x10, 0x00 },

// D3D::CDevice::KickOff+0x1F : test ch, 0x20
{ 0x1F, 0xF6 },
{ 0x20, 0xC5 },
{ 0x21, 0x20 },

// D3D::CDevice::KickOff+0x2F : sfence
{ 0x2F, 0x0F },
{ 0x30, 0xAE },
{ 0x31, 0xF8 },

// D3D::CDevice::KickOff+0xE2 : retn
{ 0xE2, 0xC3 },
// test byte ptr [ecx + 0x8], 0x04
// jz eip + 8
OV_MATCH(0x05, 0xF6, 0x41, 0x08, 0x04, 0x74, 0x08),

// or [eax + 0x08], 0x2000
OV_MATCH(0x7D, 0x81, 0x48, 0x08, 0x00, 0x20, 0x00, 0x00), // unique

// ret
OV_MATCH(0x85, 0xC3),
//
);

Expand Down
21 changes: 13 additions & 8 deletions src/OOVPADatabase/D3D8/5028.inl
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,20 @@ OOVPA_SIG_MATCH(
OOVPA_SIG_HEADER_NO_XREF(CDevice_KickOff,
5028)
OOVPA_SIG_MATCH(
// push ecx
OV_MATCH(0x00, 0x51),

{ 0x07, 0x08 },
{ 0x17, 0xC4 },
{ 0x18, 0x20 },
{ 0x19, 0x75 },
{ 0x1A, 0x63 },
{ 0x1B, 0xA1 },
{ 0x6D, 0x85 },
{ 0x7E, 0xBA },
// mov eax, [ecx + 8]
OV_MATCH(0x05, 0x8B, 0x41, 0x08),
// test al, 0x04
// jz eip + 8
OV_MATCH(0x08, 0xA8, 0x04, 0x74, 0x08),

// or [eax + 0x08], 0x2000
OV_MATCH(0x75, 0x81, 0x48, 0x08, 0x00, 0x20, 0x00, 0x00), // unique

// ret
OV_MATCH(0x7D, 0xC3), // required due to another function matches except this offset
//
);

Expand Down
18 changes: 7 additions & 11 deletions src/OOVPADatabase/D3D8/5455.inl
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,22 @@ OOVPA_SIG_MATCH(
// ******************************************************************
// * D3D::CDevice::KickOff
// ******************************************************************
OOVPA_SIG_HEADER_XREF(CDevice_KickOff,
5455,
XRefOne)
// Generic as of OOVPA 5455 and newer.
OOVPA_SIG_HEADER_NO_XREF(CDevice_KickOff,
5455)
OOVPA_SIG_MATCH(
// mov eax, XREF_D3D_g_pDevice
XREF_ENTRY(0x1A, XREF_D3D_g_pDevice), // Derived

// push esi
// mov esi, ecx
OV_MATCH(0x00, 0x56, 0x8B, 0xF1),
// mov eax, [esi + 8]
// test al, 0x04
OV_MATCH(0x03, 0x8B, 0x46, 0x08, 0xA8, 0x04),

// test ah, 0x20
OV_MATCH(0x14, 0xF6, 0xC4, 0x20),

// mov eax, XREF_D3D_g_pDevice
OV_MATCH(0x19, 0xA1),
// or [esi + 0x08], 0x2000
OV_MATCH(0x6D, 0x81, 0x4E, 0x08, 0x00, 0x20, 0x00, 0x00), // unique

// ret
OV_MATCH(0x75, 0xC3),
//
);

Expand Down
22 changes: 22 additions & 0 deletions src/OOVPADatabase/D3D8LTCG/3911.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1414,3 +1414,25 @@ OOVPA_SIG_MATCH(
OV_MATCH(0x1F, 0x0D, 0x80, 0x00, 0x00),
//
);

// ******************************************************************
// * D3D::CDevice::KickOff
// ******************************************************************
OOVPA_SIG_HEADER_NO_XREF(CDevice_KickOff_0__LTCG_edx1,
3911)
OOVPA_SIG_MATCH(
// mov eax, [addr]
OV_MATCH(0x00, 0xA1),
// test eax, eax
// jnz eip + 0x2B
OV_MATCH(0x05, 0x85, 0xC0, 0x75, 0x2B),
// test byte ptr [edx + 0Ch], 4
OV_MATCH(0x09, 0xF6, 0x42, 0x0C, 0x04),
// push esi
// jz eip + 0x08
OV_MATCH(0x0D, 0x56, 0x74, 0x08),

// ret
OV_MATCH(0x33, 0xC3),
//
);
22 changes: 22 additions & 0 deletions src/OOVPADatabase/D3D8LTCG/4039.inl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,28 @@ OOVPA_SIG_MATCH(
// Do not use any offsets after 0x1B
);

// ******************************************************************
// * D3D::CDevice::KickOff
// ******************************************************************
OOVPA_SIG_HEADER_NO_XREF(CDevice_KickOff_0__LTCG_edx1,
4039)
OOVPA_SIG_MATCH(
// mov eax, [edx + 0x08]
OV_MATCH(0x00, 0x8B, 0x42, 0x08),

// "test ?h, 0x20" and "test ?l, 0x4" instructions tend to swap or at different offsets.
// To reduce signatures, we check for "or eax, 0x2000" unique instruction and its return.

// pop edi
// or eax, 0x2000
// pop ebp
OV_MATCH(0x82, 0x5F, 0x0D, 0x00, 0x20, 0x00, 0x00, 0x5D), // unique

// ret
OV_MATCH(0x8D, 0xC3),
//
);

// ******************************************************************
// * D3DDevice_SetViewport
// ******************************************************************
Expand Down
46 changes: 46 additions & 0 deletions src/OOVPADatabase/D3D8LTCG/4134.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ******************************************************************
// *
// * OOVPADatabase->D3D8LTCG->4134.inl
// *
// * XbSymbolDatabase is free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 of the license, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// *
// * All rights reserved
// *
// ******************************************************************

// ******************************************************************
// * D3DDevice::MakeSpace
// ******************************************************************
// Almost identical to generic 4134 signature.
// Earliest found is in titles with 5659 build.
OOVPA_SIG_HEADER_XREF(D3DDevice_MakeSpace,
1036,
XRefOne)
OOVPA_SIG_MATCH(
// call D3D::MakeRequestedSpace
XREF_ENTRY(0x0B, XREF_D3D_MakeRequestedSpace),

// mov eax, [addr]
OV_MATCH(0x00, 0xA1),

// push ecx
OV_MATCH(0x09, 0x51),
// call D3D::MakeRequestedSpace
OV_MATCH(0x0A, 0xE8),
// ret
OV_MATCH(0x0F, 0xC3), // required to separate this detection from inlined function
//
);
21 changes: 21 additions & 0 deletions src/OOVPADatabase/D3D8LTCG/4432.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1122,3 +1122,24 @@ OOVPA_SIG_MATCH(
OV_MATCH(0x26, 0xC2, 0x18),
//
);

// ******************************************************************
// * D3D::CDevice::KickOff
// ******************************************************************
// stdcall (LTCG)
OOVPA_SIG_HEADER_NO_XREF(CDevice_KickOff_4,
4432)
OOVPA_SIG_MATCH(
// mov eax, [esp + param_1]
OV_MATCH(0x00, 0x8B, 0x44, 0x24, 0x04),

// test ch, 0x20
OV_MATCH(0x07, 0xF6, 0xC5, 0x20),

// or ecx, 0x2000
OV_MATCH(0xB6, 0x81, 0xC9, 0x00, 0x20, 0x00, 0x00), // unique

// ret 0x04
OV_MATCH(0xC1, 0xC2, 0x04),
//
);
26 changes: 26 additions & 0 deletions src/OOVPADatabase/D3D8LTCG/4531.inl
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,29 @@ OOVPA_SIG_MATCH(
OV_MATCH(0x2A, 0xC3),
//
);

// ******************************************************************
// * D3D::CDevice::KickOff
// ******************************************************************
// stdcall (LTCG)
// NOTE: Detected with 4627 build, except moved to 4531 since it is
// almost identical to non-ltcg 4531 signature.
OOVPA_SIG_HEADER_NO_XREF(CDevice_KickOff_4,
4531)
OOVPA_SIG_MATCH(
// mov eax, [esp + param_1]
OV_MATCH(0x00, 0x8B, 0x44, 0x24, 0x04),

// test byte ptr [eax + 0x08], 0x04
OV_MATCH(0x04, 0xF6, 0x40, 0x08, 0x04),

// jz eip + 0x08
OV_MATCH(0x09, 0x74, 0x08),

// or ecx, 0x2000
OV_MATCH(0xB8, 0x81, 0xC9, 0x00, 0x20, 0x00, 0x00), // unique

// ret 0x04
OV_MATCH(0xC3, 0xC2, 0x04),
//
);
Loading

0 comments on commit 0884e10

Please # to comment.