Skip to content

Commit 8d7d36e

Browse files
committed
Move goldp code to common directory + implement dll loading function
1 parent b34dd58 commit 8d7d36e

10 files changed

Lines changed: 113 additions & 30 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,20 @@ set(COMMON_SOURCES
6868
common/src/golstream.cpp
6969
common/src/golfilesource.cpp
7070
common/src/goldirentry.cpp
71+
common/src/golinterface.cpp
7172
)
7273

7374
# --- GolDP.dll target ---
7475
add_library(goldp SHARED
7576
GolDP/src/goldrawdpstate.cpp
76-
GolDP/src/adapter.cpp
7777
GolDP/src/goldpexport.cpp
7878
GolDP/src/goldrawstate.cpp
7979
GolDP/src/golcommondrawstate.cpp
8080
GolDP/src/main.cpp
8181
util/decomp.cpp
8282
${COMMON_SOURCES}
8383
)
84+
target_compile_definitions(goldp PRIVATE BUILDING_GOL)
8485
reccmp_add_target(goldp ID GOLDP)
8586

8687
if (MSVC)
@@ -126,6 +127,7 @@ add_executable(legoracers WIN32
126127
util/decomp.cpp
127128
${COMMON_SOURCES}
128129
)
130+
target_compile_definitions(legoracers PRIVATE BUILDING_LEGORACERS)
129131
reccmp_add_target(legoracers ID LEGORACERS)
130132

131133
target_include_directories(legoracers PRIVATE
@@ -140,13 +142,14 @@ target_link_libraries(legoracers PRIVATE
140142
ole32
141143
winmm
142144
)
143-
add_dependencies(legoracers goldp)
144145

145146
set_property(TARGET legoracers PROPERTY OUTPUT_NAME "LEGORacers")
146147
set_property(TARGET legoracers PROPERTY SUFFIX ".exe")
147148

148149
set_property(SOURCE LEGORacers/racers.rc APPEND PROPERTY OBJECT_DEPENDS "${PROJECT_SOURCE_DIR}/LEGORacers/resources/racers.ico")
149150

151+
add_custom_target(game DEPENDS legoracers goldp)
152+
150153
# --- Modern compiler compatibility ---
151154
if (MSVC)
152155
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "15")

GolDP/include/gol.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77

88
#include <windows.h>
99

10-
typedef void FatalErrorCBFN(const char* p_message);
10+
typedef void FatalErrorMessageCBFN(const char* p_message, const char* p_file, int p_line);
1111
typedef void GolExitCBFN();
1212

1313
struct GolImport {
14-
undefined4* m_unk0x0; // 0x00
15-
undefined4* m_unk0x4; // 0x04
16-
undefined4* m_unk0x8[4]; // 0x08
17-
LegoU32 m_unk0x18; // 0x18
18-
undefined4* m_unk0x1c; // 0x1c
19-
HANDLE m_mutex; // 0x20
20-
undefined m_unk0x24[0x28 - 0x24]; // 0x24
21-
FatalErrorCBFN* m_fatalError; // 0x28
14+
undefined4* m_unk0x0; // 0x00
15+
undefined4* m_unk0x4; // 0x04
16+
undefined4* m_unk0x8[4]; // 0x08
17+
LegoU32 m_unk0x18; // 0x18
18+
undefined4* m_unk0x1c; // 0x1c
19+
HANDLE m_mutex; // 0x20
20+
undefined m_unk0x24[0x28 - 0x24]; // 0x24
21+
FatalErrorMessageCBFN* m_fatalErrorMessage; // 0x28
2222
};
2323

2424
// VTABLE: GOLDP 0x100564b0

GolDP/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
GolDPExport* g_golDPExport;
1010

1111
// GLOBAL: GOLDP 0x1006314c
12-
FatalErrorCBFN* g_fatalError;
12+
FatalErrorMessageCBFN* g_fatalErrorMessage;
1313

1414
// FUNCTION: GOLDP 0x10006ff0
1515
GolExport* GolEntry(GolImport* p_import)
1616
{
1717
SetGolImport(p_import);
18-
g_fatalError = p_import->m_fatalError;
18+
g_fatalErrorMessage = p_import->m_fatalErrorMessage;
1919
g_golDPExport = new GolDPExport;
2020
return g_golDPExport;
2121
}

LEGORacers/include/ironflame0x944.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
#include "compat.h"
55
#include "crimsonforge0x800.h"
66
#include "decomp.h"
7+
#include "gol.h"
78
#include "opalvault0xf0.h"
89
#include "types.h"
910

11+
#include <windows.h>
12+
1013
// VTABLE: LEGORACERS 0x4af9f4
1114
// SIZE 0x944
1215
class IronFlame0x944 : public CrimsonForge0x800 {
@@ -33,9 +36,10 @@ class IronFlame0x944 : public CrimsonForge0x800 {
3336
void SetUnk0x928(undefined4 p_unk0x928) { m_unk0x928 = p_unk0x928; }
3437

3538
private:
36-
undefined4 m_unk0x800; // 0x800
37-
undefined m_unk0x804[0x830 - 0x804]; // 0x804
38-
undefined4 m_unk0x830; // 0x830
39+
GolExport* m_golExport; // 0x800
40+
GolDrawState* m_golDrawState; // 0x804
41+
undefined m_unk0x808[0x830 - 0x808]; // 0x808
42+
HMODULE m_golLibrary; // 0x830
3943
OpalVault0xf0 m_unk0x834; // 0x834
4044
undefined4 m_unk0x924; // 0x924
4145
undefined4 m_unk0x928; // 0x928

LEGORacers/src/ironflame0x944.cpp

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
#include "ironflame0x944.h"
22

3+
#include "../../GolDP/include/gol.h"
4+
#include "gol.h"
5+
#include "golerror.h"
6+
#include "golinterface.h"
7+
8+
#include <stdio.h>
9+
310
DECOMP_SIZE_ASSERT(IronFlame0x944, 0x944)
411

512
// FUNCTION: LEGORACERS 0x4164d0
613
IronFlame0x944::IronFlame0x944()
714
{
8-
m_unk0x830 = 0;
9-
m_unk0x800 = 0;
15+
m_golLibrary = NULL;
16+
m_golExport = NULL;
1017
m_unk0x924 = 0;
1118
m_unk0x928 = 0;
1219
m_unk0x92c = 0;
@@ -44,11 +51,39 @@ void IronFlame0x944::VTable0x10()
4451
STUB(0x4167e0);
4552
}
4653

47-
// STUB: LEGORACERS 0x416960
54+
// FUNCTION: LEGORACERS 0x416960
4855
void IronFlame0x944::VTable0x14()
4956
{
50-
// TODO
51-
STUB(0x416960);
57+
char buffer[100];
58+
// const char *dllname;
59+
GolImport gol_import;
60+
61+
if (m_unk0x928 & 0x2) {
62+
m_golLibrary = LoadLibraryA("GolGlide.DLL");
63+
}
64+
else if (m_unk0x928 & 0x1) {
65+
m_golLibrary = LoadLibraryA("GolSoft.DLL");
66+
}
67+
else if (m_unk0x928 & 0x4) {
68+
m_golLibrary = LoadLibraryA("GolD3D.DLL");
69+
// dllname = "GolD3D.DLL";
70+
}
71+
else {
72+
m_golLibrary = LoadLibraryA("GolDP.DLL");
73+
// dllname = "GolDP.DLL";
74+
}
75+
if (m_golLibrary == NULL) {
76+
sprintf(buffer, "Unable to find a valid Gol DLL\nError Code = %d", GetLastError());
77+
GOL_FATALERROR_MESSAGE(buffer);
78+
}
79+
GolEntryCBFN* golEntry = (GolEntryCBFN*) GetProcAddress(m_golLibrary, "GolEntry");
80+
if (golEntry == NULL) {
81+
GOL_FATALERROR_MESSAGE("Invalid Gol DLL - cannot call entry procedure");
82+
}
83+
CreateGolImport(&gol_import);
84+
gol_import.m_fatalErrorMessage = GolFatalErrorMessage;
85+
m_golExport = golEntry(&gol_import);
86+
m_golDrawState = m_golExport->VTable0x04();
5287
}
5388

5489
// STUB: LEGORACERS 0x416a30

LEGORacers/src/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "main.h"
77

88
#include "decomp.h"
9+
#include "golerror.h"
910
#include "neoncactus0x1d6c.h"
1011
#include "types.h"
1112

@@ -42,6 +43,15 @@ LegoS32 GameMain(LegoS32 p_argc, LegoChar** p_argv)
4243
return 0;
4344
}
4445

46+
// FUNCTION: LEGORACERS 0x0042f8b0
47+
void GolFatalErrorMessage(const char* p_message, const char* p_file, int p_line)
48+
{
49+
g_unk0x4c4a38.FUN_0042be90();
50+
MessageBox(NULL, p_message, "Fatal Error", MB_TOPMOST | MB_SETFOREGROUND | MB_ICONWARNING);
51+
g_unk0x4c4a38.FUN_0042bc20();
52+
exit(1);
53+
}
54+
4555
// FUNCTION: LEGORACERS 0x449ce0
4656
void SplitCommand()
4757
{

common/include/golerror.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "types.h"
55

6+
#define GOL_FATALERROR_MESSAGE(MESSAGE) GolFatalErrorMessage(MESSAGE, NULL, 0)
7+
68
enum GolErrorCode {
79
c_golErrorAssertion = -7,
810
c_golErrorCriticalResource = -5,
@@ -13,6 +15,8 @@ enum GolErrorCode {
1315
c_golErrorInvalidCondition = 0
1416
};
1517

16-
void GolFatalError(LegoS32, LegoS32, LegoS32);
18+
extern void GolFatalErrorMessage(const char* p_message, const char* p_file, int p_line);
19+
20+
extern void GolFatalError(GolErrorCode p_code, const char* p_file, int p_line);
1721

1822
#endif // GOLERROR_H

common/include/golinterface.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef GOLINTERFACE_H
2+
#define GOLINTERFACE_H
3+
4+
#include "gol.h"
5+
6+
#ifdef BUILDING_LEGORACERS
7+
extern void CreateGolImport(GolImport* p_import);
8+
#endif
9+
10+
#ifdef BUILDING_GOL
11+
extern void SetGolImport(GolImport* p_import);
12+
#endif
13+
14+
extern void LockGlobalMutex();
15+
16+
extern void ReleaseGlobalMutex();
17+
18+
#endif // GOLERROR_H

common/src/golerror.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
#include "decomp.h"
44

5+
// STUB: GOLDP 0x100070f0
56
// STUB: LEGORACERS 0x42f8f0
6-
void GolFatalError(LegoS32, LegoS32, LegoS32)
7+
void GolFatalError(GolErrorCode p_code, const char* p_file, int p_line)
78
{
89
// TODO
910
STUB(0x42f8f0);
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
#include "gol.h"
1+
#include "golinterface.h"
22

33
#include <windows.h>
44

55
#if (defined(_MSC_VER) && defined(_M_X64)) || (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64)))
66
#include <cpuid.h>
77
#endif
88

9-
// #ifdef _MSC_VER
10-
// #if _MSC_VER < 1300
11-
// #define cpuid __emit 0x0f __emit 0xa2
12-
// #endif
13-
// #endif
14-
159
// GLOBAL: GOLDP 0x10065ed4
10+
// GLOBAL: LEGORACE 0x004c73f0
1611
HANDLE g_globalMutex;
1712

1813
// GLOBAL: GOLDP 0x10065ed8
@@ -27,14 +22,26 @@ BOOL g_CPU_supports_MMX;
2722
// GLOBAL: GOLDP 0x10065ee4
2823
char g_cpuManufacturer[16];
2924

25+
#ifdef BUILDING_LEGORACERS
26+
void CreateGolImport(GolImport* p_import)
27+
{
28+
// TODO
29+
// result.m_unk0x1c = ;
30+
p_import->m_mutex = g_globalMutex;
31+
}
32+
#endif
33+
34+
#ifdef BUILDING_GOL
3035
// STUB: GOLDP 0x10032b80
3136
void SetGolImport(GolImport* p_import)
3237
{
3338
// TODO
3439
STUB(0x10032b80);
3540
}
41+
#endif
3642

3743
// FUNCTION: GOLDP 0x10032bf0
44+
// FUNCTION: LEGORACE 0x00450df0
3845
void LockGlobalMutex()
3946
{
4047
if (g_globalMutex != NULL) {
@@ -43,6 +50,7 @@ void LockGlobalMutex()
4350
}
4451

4552
// FUNCTION: GOLDP 0x10032c10
53+
// FUNCTION: LEGORACE 0x00450e10
4654
void ReleaseGlobalMutex()
4755
{
4856
if (g_globalMutex != NULL) {

0 commit comments

Comments
 (0)