Skip to content

Commit

Permalink
d3d8(ltcg): add/update CDevice_KickOff and D3DDevice_MakeSpace signat…
Browse files Browse the repository at this point in the history
…ures

Updated:
- CDevice_KickOff (3911, 4034, 4531, 5028, 5455)
- D3DDevice_MakeSpace (4034, 4134)

Added:
- CDevice_KickOff_4  (4432, 4531, 5028)
- CDevice_KickOff_0__LTCG_eax1 (5455)
  • Loading branch information
RadWolfie committed Oct 27, 2023
1 parent 833d81c commit 56594dd
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 91 deletions.
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 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 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
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),
//
);
24 changes: 24 additions & 0 deletions src/OOVPADatabase/D3D8LTCG/5028.inl
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,27 @@ OOVPA_SIG_MATCH(
OV_MATCH(0x66, 0x5E, 0xC3),
//
);

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

// test cl, 0x04
// jz eip + 0x08
OV_MATCH(0x07, 0xF6, 0xC1, 0x04, 0x74, 0x08),

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

// ret 0x04
OV_MATCH(0xAD, 0xC2, 0x04),
//
);
21 changes: 21 additions & 0 deletions src/OOVPADatabase/D3D8LTCG/5455.inl
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,24 @@ OOVPA_SIG_MATCH(
OV_MATCH(0x8F, 0x81, 0x49, 0x08, 0x00, 0x20, 0x00, 0x00), // unique
//
);

// ******************************************************************
// * D3D::CDevice::KickOff
// ******************************************************************
OOVPA_SIG_HEADER_NO_XREF(CDevice_KickOff_0__LTCG_eax1,
5455)
OOVPA_SIG_MATCH(
// mov ecx, [eax + 0x08]
// test cl, 0x04
OV_MATCH(0x00, 0x8B, 0x48, 0x08, 0xF6, 0xC1, 0x04),

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

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

// ret
OV_MATCH(0x98, 0xC3),
//
);
2 changes: 2 additions & 0 deletions src/OOVPADatabase/D3D8LTCG_OOVPA.inl
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ OOVPATable D3D8LTCG_OOVPA[] = {
REGISTER_OOVPAS_BIND_XREF(D3D_CommonSetMultiSampleModeAndScale_4__LTCG_eax1, D3D_CommonSetMultiSampleModeAndScale, 5344),
REGISTER_OOVPAS(D3D_KickOffAndWaitForIdle2, 1024, 1036, 1048),
REGISTER_OOVPAS_D3D(CDevice_KickOff, 1048), // thiscall
REGISTER_OOVPAS_BIND_XREF(CDevice_KickOff_4, D3D_CDevice_KickOff, 4432, 4531, 5028), // stdcall (LTCG)
REGISTER_OOVPAS_BIND_XREF(CDevice_KickOff_0__LTCG_edx1, D3D_CDevice_KickOff, 3911, 4039, 5028), // Final generic OOVPA: 5028; Removed: 0
REGISTER_OOVPAS_BIND_XREF(CDevice_KickOff_0__LTCG_eax1, D3D_CDevice_KickOff, 5455),
REGISTER_OOVPAS(D3DDevice_MakeSpace, 1036), // Almost identical to generic 4134 signature.
REGISTER_OOVPAS(Direct3D_CreateDevice, 1024, 1036),
REGISTER_OOVPAS_BIND_XREF(Direct3D_CreateDevice_16__LTCG_eax_BehaviorFlags_ebx_ppReturnedDeviceInterface, Direct3D_CreateDevice, 2024),
Expand Down
2 changes: 1 addition & 1 deletion src/OOVPADatabase/D3D8_OOVPA.inl
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ OOVPATable D3D8_OOVPA[] = {
REGISTER_OOVPAS(D3DDevice_InsertFence, 3911),
REGISTER_OOVPAS(D3DDevice_IsBusy, 3911, 5028),
REGISTER_OOVPAS(D3DDevice_IsFencePending, 3911, 4039, 5028),
REGISTER_OOVPAS_D3D(CDevice_KickOff, 3911, 4034, 4531, 5028, 5455), // thiscall
REGISTER_OOVPAS_D3D(CDevice_KickOff, 3911, 4034, 4531, 5028, 5455), // Final generic OOVPA: 5455; Removed: 0 // thiscall
REGISTER_OOVPAS(D3DDevice_KickPushBuffer, 3911),
REGISTER_OOVPAS(D3DDevice_LightEnable, 3911, 5344), // Was 5233 (from 5344's comment)
REGISTER_OOVPAS(D3DDevice_LoadVertexShader, 3911, 4034, 4627, 5028),
Expand Down
4 changes: 3 additions & 1 deletion src/test/libverify/D3D8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ static const library_list database_full = {
REGISTER_SYMBOL_INLINE(D3DDevice_IsFencePending, VER_RANGE(3911)),
REGISTER_SYMBOLS(D3D_CDevice_KickOff, // thiscall
REGISTER_SYMBOL(CDevice_KickOff, VER_RANGE(3911)),
REGISTER_SYMBOL(CDevice_KickOff_0__LTCG_edx1, VER_RANGE(3911))),
REGISTER_SYMBOL(CDevice_KickOff_4, VER_RANGE(4432)), // stdcall (LTCG)
REGISTER_SYMBOL(CDevice_KickOff_0__LTCG_edx1, VER_RANGE(3911)),
REGISTER_SYMBOL(CDevice_KickOff_0__LTCG_eax1, VER_RANGE(5455))),
REGISTER_SYMBOL_INLINE(D3DDevice_KickPushBuffer, VER_RANGE(3911)),
REGISTER_SYMBOLS(D3DDevice_LightEnable,
REGISTER_SYMBOL(D3DDevice_LightEnable, VER_RANGE(3911)),
Expand Down

0 comments on commit 56594dd

Please sign in to comment.