Skip to content

Commit ad31165

Browse files
committed
Working game.exe replacement!!
1 parent 87e6573 commit ad31165

File tree

3 files changed

+95
-29
lines changed

3 files changed

+95
-29
lines changed

Game/diablo2.cpp

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ static D2CmdArgStrc OpenD2CommandArguments[] = {
102102
{"FILEIO", "MODPATH", "modpath", CMD_STRING, co(szModPath), 0x00},
103103
};
104104

105+
/////////////////////////////////////////////////////////////////////////////////////////////////////
106+
105107
/*
106108
* Processes a single commandline argument
107109
*/
@@ -160,7 +162,7 @@ void ProcessOpenD2Argument(char* arg, OpenD2ConfigStrc* config)
160162
}
161163

162164
pArg = OpenD2CommandArguments;
163-
165+
// TODO
164166
}
165167

166168
/*
@@ -203,16 +205,11 @@ D2InterfaceModules PumpModuleFrame(D2InterfaceModules dwInterface, D2GameConfigS
203205
}
204206

205207
/*
206-
* Initialize the game (from main entrypoint)
208+
* Parse commandline arguments
207209
*/
208-
int InitGame(int argc, char** argv, DWORD pid)
210+
void ParseCommandline(int argc, char** argv, D2GameConfigStrc* pConfig, OpenD2ConfigStrc* pOpenConfig)
209211
{
210212
char* arg;
211-
D2GameConfigStrc config{ 0 };
212-
OpenD2ConfigStrc openD2Config{ 0 };
213-
bool bSuccess;
214-
DWORD dwRenderingMode;
215-
D2InterfaceModules dwCurrentModule;
216213

217214
// Process the commandline arguments
218215
for (int i = 1; i < argc; i++)
@@ -224,19 +221,84 @@ int InitGame(int argc, char** argv, DWORD pid)
224221
}
225222
else if (arg[0] == '-')
226223
{ // Diablo II game setting
227-
ProcessDiablo2Argument(arg + 1, &config);
224+
ProcessDiablo2Argument(arg + 1, pConfig);
228225
}
229226
else if (arg[0] == '+')
230227
{ // OpenD2 game setting
231-
ProcessOpenD2Argument(arg + 1, &openD2Config);
228+
ProcessOpenD2Argument(arg + 1, pOpenConfig);
232229
}
233230
}
231+
}
232+
233+
/*
234+
* Pull default values from a D2CmdArgStrc array
235+
*/
236+
static void PopulateDefaultValues(D2CmdArgStrc* paCommandArguments, void* pvInput)
237+
{
238+
D2CmdArgStrc* pArg = paCommandArguments;
239+
while (pArg != nullptr && pArg->szKeyName[0] != '\0')
240+
{
241+
switch (pArg->dwType)
242+
{
243+
case CMD_BOOLEAN:
244+
case CMD_BYTE:
245+
*((BYTE*)pvInput + pArg->nOffset) = (BYTE)pArg->dwDefault;
246+
break;
247+
case CMD_WORD:
248+
*((WORD*)pvInput + pArg->nOffset) = (WORD)pArg->dwDefault;
249+
break;
250+
case CMD_DWORD:
251+
*((DWORD*)pvInput + pArg->nOffset) = pArg->dwDefault;
252+
break;
253+
}
254+
++pArg;
255+
}
256+
}
257+
258+
/*
259+
* A (tiny) callback that is needed by the game for some reason
260+
*/
261+
int __stdcall LoadExpansionMPQ()
262+
{
263+
return 1;
264+
}
234265

235-
// Fix some other settings
266+
/*
267+
* Populate the config with default values
268+
*/
269+
static void PopulateConfiguration(D2GameConfigStrc* pConfig, OpenD2ConfigStrc* pOpenConfig)
270+
{
236271
#ifdef EXPANSION
237-
config.dwExpansion = 1;
272+
pConfig->dwExpansion = 1;
238273
#endif
239274

275+
// Push the default values from the commandline settings for both OpenD2 and the retail game
276+
//PopulateDefaultValues(CommandArguments, pConfig);
277+
//PopulateDefaultValues(OpenD2CommandArguments, pOpenConfig);
278+
279+
// Set the default MPQ callback
280+
#if GAME_MINOR_VERSION >= 13 // In 1.13 we apply a +1 offset to keep it kosher
281+
*(void**)((BYTE*)&pConfig->pfMPQFunc + 1) = LoadExpansionMPQ;
282+
#else
283+
pConfig->pfMPQFunc = LoadExpansionMPQ;
284+
#endif
285+
}
286+
287+
/*
288+
* Initialize the game (from main entrypoint)
289+
*/
290+
int InitGame(int argc, char** argv, DWORD pid)
291+
{
292+
char* arg;
293+
D2GameConfigStrc config{ 0 };
294+
OpenD2ConfigStrc openD2Config{ 0 };
295+
bool bSuccess;
296+
DWORD dwRenderingMode;
297+
D2InterfaceModules dwCurrentModule;
298+
299+
PopulateConfiguration(&config, &openD2Config);
300+
ParseCommandline(argc, argv, &config, &openD2Config);
301+
240302
dwRenderingMode = GetRenderingMode(&config);
241303

242304
/*

Shared/D2Shared.hpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,24 @@ typedef unsigned char BYTE;
3939
* The structure which contains data about commandline arguments (ie, the precise values of them)
4040
* @author Necrolis
4141
*/
42+
#pragma pack(push,enter_include)
43+
#pragma pack(1)
4244
struct D2GameConfigStrc // size 0x3C7
4345
{
44-
DWORD dwExpansion;
45-
BYTE bWindowed; // {"VIDEO","WINDOW" ,"w" , 0x00, 0x04, 0x00},
46-
BYTE b3DFX; // {"VIDEO","3DFX" ,"3dfx" , 0x00, 0x05, 0x00},
47-
BYTE bOpenGL; // {"VIDEO","OPENGL" ,"opengl", 0x00, 0x06, 0x00},
48-
BYTE bRave; // {"VIDEO","RAVE" ,"rave" , 0x00, 0x07, 0x00},
49-
BYTE bD3D; // {"VIDEO","D3D" ,"d3d" , 0x00, 0x08, 0x00},
50-
BYTE bPerspective; // {"VIDEO","PERSPECTIVE" ,"per" , 0x00, 0x09, 0x00},
51-
BYTE bQuality; // {"VIDEO","QUALITY" ,"lq" , 0x00, 0x0A, 0x00},
52-
DWORD dwGamma; // {"VIDEO","GAMMA" ,"gamma" , 0x00, 0x0B, 0x00},
53-
BYTE bVSync; // {"VIDEO","VSYNC" ,"vsync" , 0x00, 0x0F, 0x00},
54-
DWORD dwFramerate; // {"VIDEO","FRAMERATE" ,"fr" , 0x01, 0x10, 0x00},
55-
DWORD dwGameType; // {"NETWORK" ,"GAMETYPE" ,"gametype" , 0x01, 0x0014, 0x00},
56-
WORD wJoinID; // {"NETWORK" ,"JOINID" ,"joinid" , 0x01, 0x0018, 0x00}, ??? dword overlapps next addy !
57-
char szGameName[24]; // {"NETWORK" ,"GAMENAME" ,"gamename" , 0x02, 0x001A, 0x00},
46+
DWORD dwExpansion; // +00
47+
BYTE bWindowed; // +04 ("w" option)
48+
BYTE b3DFX; // +05 ("3dfx" option)
49+
BYTE bOpenGL; // +06 ("opengl" option)
50+
BYTE bRave; // +07 ("rave" option)
51+
BYTE bD3D; // +08 ("d3d" option)
52+
BYTE bPerspective; // +09 ("per" option)
53+
BYTE bQuality; // +0A ("lq" option)
54+
DWORD dwGamma; // +0B ("gamma" option)
55+
BYTE bVSync; // +0F ("vsync" option)
56+
DWORD dwFramerate; // +10 ("fr" option)
57+
DWORD dwGameType; // +14 ("gametype" option)
58+
WORD wJoinID; // +18 ("joinid" option) ??? dword overlapps next addy !
59+
char szGameName[24]; // +1A ("gamename" option),
5860
char szServerIP[24]; // {"NETWORK" ,"SERVERIP" ,"s" , 0x02, 0x0032, 0x00},
5961
char szBNetIP[24]; // {"NETWORK" ,"BATTLENETIP" ,"bn" , 0x02, 0x004A, 0x00},
6062
char szMCPIP[24]; // {"NETWORK" ,"MCPIP" ,"mcpip" , 0x02, 0x0062, 0x00},
@@ -95,8 +97,8 @@ struct D2GameConfigStrc // size 0x3C7
9597
BYTE bUnk208;
9698
BYTE bUnk209;
9799
BYTE bUnk20A;
98-
BYTE nDifficulty;
99-
void* pfMPQFunc; // function ptr; returns 1
100+
BYTE nDifficulty; // +20B
101+
void* pfMPQFunc; // +20C function ptr; returns 1
100102
BYTE bTXT; // {"TXT" ,"TXT" ,"txt" , 0x00, 0x0210, 0x00},
101103
BYTE bLog; // {"DEBUG" ,"LOG" ,"log" , 0x00, 0x0211, 0x00},
102104
BYTE bMsgLog; // {"DEBUG" ,"MSGLOG" ,"msglog" , 0x00, 0x0212, 0x00},
@@ -110,14 +112,15 @@ struct D2GameConfigStrc // size 0x3C7
110112
BYTE bSkipInterface; // skips loading the BNClient QueryInterface
111113
BYTE bBuild; // {"BUILD" ,"BUILD" ,"build" , 0x00, 0x021E, 0x00},
112114
void* pInterface; // {"NETWORK" ,"COMINT" ,"comint" , 0x01, 0x021F, 0x00},
113-
BYTE bUnk223[0x134]; // ?
115+
BYTE bUnk223[0x134]; // +223 ?
114116
BYTE bSkipToBNet; // {"NETWORK" ,"SKIPTOBNET" ,"W" , 0x00, 0x0357, 0x00}, //check at d2launch.6FA1D660 CMP BYTE PTR DS:[EAX+357],BL
115117
BYTE nScreenSize; // {"VIDEO" ,"SCREENSIZE" ,"sz" , 0x00, 0x358, 0x00},
116118
BYTE bShowLogo; // {"VIDEO" ,"SHOWLOGO" ,"sl" , 0x00, 0x359, 0x00},
117119
BYTE nUnk[0x6E]; // ?
118120

119121
BYTE nPadding; // account for the extra option in 1.13c+
120122
};
123+
#pragma pack(pop,enter_include)
121124

122125
/*
123126
* The structure which contains OpenD2-specific data

Shared/Fog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ D2_API void __fastcall FOG_10053(void);
1010
D2_API void __fastcall FOG_10089(DWORD, DWORD);
1111
D2_API void __fastcall FOG_10090(void);
1212
D2_API void __fastcall FOG_10101(DWORD, DWORD);
13+
//D2_API int __cdecl FOG_10117() <-- gets value of -direct
1314
D2_API void __cdecl FOG_10143(void*);
1415
D2_API void __fastcall FOG_10198(DWORD, void*, double, int, int, int);
1516
D2_API void __fastcall FOG_10218(void);

0 commit comments

Comments
 (0)