Skip to content

Commit 0d3f479

Browse files
committed
Implement ddraw and d3d enumeration/initialization
1 parent fe2fc2a commit 0d3f479

10 files changed

Lines changed: 863 additions & 9 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ jobs:
254254
--clang-lib ${{ env.LLVM_PATH }}/lib/libclang.so \
255255
--recurse \
256256
--style tools/ncc/ncc.style \
257-
--definition WINAPI FAR BOOL CALLBACK HWND__=HWND \
257+
--definition PASCAL WINAPI FAR BOOL CALLBACK HWND__=HWND \
258258
--include \
259259
util \
260260
LEGORacers/include \

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ set(COMMON_SOURCES
9090
add_library(goldp SHARED
9191
GolDP/src/goldrawdpstate.cpp
9292
GolDP/src/goldpexport.cpp
93+
GolDP/src/goldevicelist.cpp
9394
GolDP/src/goldrawstate.cpp
9495
GolDP/src/golcommondrawstate.cpp
9596
GolDP/src/main.cpp
@@ -111,6 +112,7 @@ target_include_directories(goldp PRIVATE
111112
)
112113
target_link_libraries(goldp PRIVATE
113114
ddraw
115+
dxguid
114116
)
115117

116118
set_property(TARGET goldp PROPERTY OUTPUT_NAME "GolDP")

GolDP/include/goldevicelist.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#ifndef GOL_DEVICELIST_H
2+
#define GOL_DEVICELIST_H
3+
4+
#include "types.h"
5+
6+
#include <d3d.h>
7+
#include <windows.h>
8+
9+
template <typename T>
10+
class GolVector {
11+
GolVector()
12+
{
13+
m_size = 0;
14+
m_data = NULL;
15+
}
16+
~GolVector() { Clear(); }
17+
void Clear()
18+
{
19+
LegoU32 i;
20+
21+
for (i = 0; i < m_size; i++) {
22+
m_data[i].Clear();
23+
}
24+
}
25+
LegoU32 m_size;
26+
T* m_data;
27+
};
28+
29+
// SIZE 0x10
30+
class GolDeviceList {
31+
public:
32+
struct GolD3DDeviceInfo;
33+
struct GolD3DDriverInfo;
34+
35+
struct GolD3DDeviceInfo {
36+
GolD3DDriverInfo* m_driver; // 0x00
37+
BOOL m_validGuid; // 0x04
38+
BOOL m_hwAccelerated; // 0x08
39+
GUID m_guid; // 0x0c
40+
char* m_name; // 0x1c
41+
char* m_description; // 0x20
42+
D3DDEVICEDESC m_deviceDesc; // 0x24
43+
};
44+
45+
struct GolD3DDriverInfo {
46+
LegoBool32 m_unk0x00; // 0x00
47+
LegoBool32 m_accelerated; // 0x04
48+
LegoBool32 m_unk0x08; // 0x08
49+
GUID m_guid; // 0x0c
50+
LegoChar* m_description; // 0x1c
51+
LegoChar* m_name; // 0x20
52+
LegoU32 m_countDevices; // 0x24
53+
GolD3DDeviceInfo* m_devices; // 0x28
54+
};
55+
56+
GolDeviceList();
57+
58+
void Clear();
59+
GolD3DDeviceInfo* SelectDevice(
60+
HWND p_hWnd,
61+
LegoU32 p_flags,
62+
const LegoChar* p_driverDescription,
63+
const LegoChar* p_deviceName
64+
);
65+
void DetectDevices();
66+
void UpdateDialog(HWND p_hWnd);
67+
GolD3DDeviceInfo* FindMatchingDevice(
68+
LegoU32 p_flags,
69+
const LegoChar* p_driverDescription,
70+
const LegoChar* p_deviceName
71+
);
72+
73+
private:
74+
static BOOL CALLBACK
75+
CountDirectDrawDriversCallback(GUID* p_guid, LPSTR p_name, LPSTR p_description, LPVOID Context);
76+
static BOOL CALLBACK
77+
EnumerateDirectDrawDriversCallback(GUID* p_guid, LPSTR p_name, LPSTR p_description, LPVOID Context);
78+
static HRESULT CALLBACK CountDirect3DDevicesCallback(
79+
GUID* p_guid,
80+
LPSTR p_description,
81+
LPSTR p_name,
82+
LPD3DDEVICEDESC p_halDesc,
83+
LPD3DDEVICEDESC p_helDesc,
84+
LPVOID p_context
85+
);
86+
static HRESULT CALLBACK EnumerateDirect3DDevicesCallback(
87+
GUID* p_guid,
88+
LPSTR p_description,
89+
LPSTR p_name,
90+
LPD3DDEVICEDESC p_halDesc,
91+
LPD3DDEVICEDESC p_helDesc,
92+
LPVOID p_context
93+
);
94+
static void StoreDialogWord(LegoU8** p_ptrStorage, LegoU16 p_word);
95+
static void StoreDialogItemText(LegoU8** p_ptrStorage, const char* p_text);
96+
static void StoreDialogItem(
97+
LegoU8** p_ptrStorage,
98+
LegoU32 p_style,
99+
LegoS16 p_x,
100+
LegoS16 p_y,
101+
LegoS16 p_cx,
102+
LegoS16 p_cy,
103+
LegoU16 p_id,
104+
const char* p_type,
105+
const char* p_text
106+
);
107+
static int CALLBACK SelectDeviceDlgProc(HWND p_hWnd, UINT p_uMsg, WPARAM p_wParam, LPARAM p_lParam);
108+
109+
// GolVector<GolD3DDriverInfo> m_drivers;
110+
LegoU32 m_countDrivers;
111+
GolD3DDriverInfo* m_drivers;
112+
LegoU32 m_driverIndex;
113+
LegoU32 m_deviceIndex;
114+
115+
static GolDeviceList* s_DialogDeviceList;
116+
};
117+
118+
#endif // GOL_DEVICELIST_H

GolDP/include/goldrawdpstate.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#define GOLDP_GOLDPSTATE_H
33

44
#include "golcommondrawstate.h"
5+
#include "goldevicelist.h"
6+
7+
#include <ddraw.h>
58

69
// VTABLE: GOLDP 0x10056140
710
// SIZE 0xc8ac4
@@ -52,13 +55,30 @@ class GolDrawDPState : public GolCommonDrawState {
5255
undefined4 VTable0xb0() override; // vtable+0xb0
5356
undefined4 VTable0xb4() override; // vtable+0xb4
5457

58+
const LegoChar* GetDriverName() const { return m_driverName; }
59+
const LegoChar* GetDeviceName() const { return m_deviceName; }
60+
5561
// SYNTHETIC: GOLDP 0x100010e0
5662
// GolDrawDPState::`scalar deleting destructor'
5763

5864
private:
59-
undefined m_unk0x20[0x2c - 0x20]; // 0x20
60-
HWND m_hWnd; // 0x2c
61-
undefined m_unk0x30[0xc8ac4 - 0x30]; // 0x30
65+
void ReleaseDDraw();
66+
67+
LPDIRECTDRAW m_ddraw; // 0x20
68+
LPDIRECTDRAW4 m_ddraw4; // 0x24
69+
LPDIRECT3D3 m_d3d3; // 0x28
70+
HWND m_hWnd; // 0x2c
71+
DDCAPS m_ddrawCaps; // 0x30
72+
D3DDEVICEDESC m_deviceDesc; // 0x1ac
73+
GolDeviceList::GolD3DDeviceInfo* m_device; // 0x2a8
74+
GUID m_deviceGuid; // 0x2ac
75+
LegoBool32 m_validGuid; // 0x2bc
76+
undefined4 m_unk0x2c0; // 0x2c0
77+
undefined m_unk0x2c4[0x2e4 - 0x2c4]; // 0x2c4
78+
GolDeviceList m_deviceList; // 0x2e4
79+
LegoChar* m_driverName; // 0x2f4
80+
LegoChar* m_deviceName; // 0x2f8
81+
undefined m_unk0x2fc[0xc8ac4 - 0x2fc]; // 0x30
6282
};
6383

6484
#endif // GOLDP_GOLDPSTATE_H

GolDP/include/goldrawstate.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,33 @@ class GolDrawState {
4545
// SYNTHETIC: GOLDP 0x1001d590
4646
// GolDrawState::`scalar deleting destructor'
4747

48+
enum {
49+
c_flagBit9 = 1 << 9,
50+
c_flagBit10 = 1 << 10,
51+
c_flagBit11 = 1 << 11,
52+
c_flagBit13 = 1 << 13,
53+
c_flagBit14 = 1 << 14,
54+
c_flagBit15 = 1 << 15,
55+
c_flagBit16 = 1 << 16,
56+
c_flagBit17 = 1 << 17,
57+
c_flagBit18 = 1 << 18,
58+
c_flagBit19 = 1 << 19,
59+
};
60+
61+
protected:
62+
LegoU32 GetFlags() const { return m_flags; }
63+
void SetFlags(LegoU32 p_flags) { m_flags = p_flags; }
64+
void SetBitsPerPixel(LegoU32 p_bpp) { m_bpp = p_bpp; }
65+
LegoU32 GetBitsPerPixel() const { return m_bpp; }
66+
67+
undefined4 GetWidth() const { return m_width; }
68+
undefined4 GetHeight() const { return m_height; }
69+
4870
private:
4971
undefined4 m_width; // 0x04
5072
undefined4 m_height; // 0x08
5173
undefined4 m_bpp; // 0x0c
52-
undefined4 m_flags; // 0x10
74+
LegoU32 m_flags; // 0x10
5375
undefined4 m_unk0x14; // 0x14
5476
};
5577

GolDP/library_msvc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// LIBRARY: GOLDP 0x1004b356
66
// ??3@YAXPAX@Z
77

8+
// LIBRARY: GOLDP 0x1004b361
9+
// sprintf
10+
811
// aka `operator new`
912
// LIBRARY: GOLDP 0x1004b3b3
1013
// ??2@YAPAXI@Z
@@ -18,6 +21,15 @@
1821
// LIBRARY: GOLDP 0x1004c6a0
1922
// __DllMainCRTStartup@12
2023

24+
// GLOBAL: GOLDP 0x10058098
25+
// IID_IDirectDraw4
26+
27+
// GLOBAL: GOLDP 0x100580a8
28+
// IID_IDirectDrawSurface
29+
30+
// GLOBAL: GOLDP 0x100583b8
31+
// IID_IDirect3D3
32+
2133
// GLOBAL: GOLDP 0x10067620
2234
// __pRawDllMain
2335

0 commit comments

Comments
 (0)