diff --git a/Game/diablo2.cpp b/Game/diablo2.cpp index c620e7b..c111b7f 100644 --- a/Game/diablo2.cpp +++ b/Game/diablo2.cpp @@ -102,6 +102,8 @@ static D2CmdArgStrc OpenD2CommandArguments[] = { {"FILEIO", "MODPATH", "modpath", CMD_STRING, co(szModPath), 0x00}, }; +///////////////////////////////////////////////////////////////////////////////////////////////////// + /* * Processes a single commandline argument */ @@ -160,7 +162,7 @@ void ProcessOpenD2Argument(char* arg, OpenD2ConfigStrc* config) } pArg = OpenD2CommandArguments; - + // TODO } /* @@ -203,16 +205,11 @@ D2InterfaceModules PumpModuleFrame(D2InterfaceModules dwInterface, D2GameConfigS } /* - * Initialize the game (from main entrypoint) + * Parse commandline arguments */ -int InitGame(int argc, char** argv, DWORD pid) +void ParseCommandline(int argc, char** argv, D2GameConfigStrc* pConfig, OpenD2ConfigStrc* pOpenConfig) { char* arg; - D2GameConfigStrc config{ 0 }; - OpenD2ConfigStrc openD2Config{ 0 }; - bool bSuccess; - DWORD dwRenderingMode; - D2InterfaceModules dwCurrentModule; // Process the commandline arguments for (int i = 1; i < argc; i++) @@ -224,19 +221,84 @@ int InitGame(int argc, char** argv, DWORD pid) } else if (arg[0] == '-') { // Diablo II game setting - ProcessDiablo2Argument(arg + 1, &config); + ProcessDiablo2Argument(arg + 1, pConfig); } else if (arg[0] == '+') { // OpenD2 game setting - ProcessOpenD2Argument(arg + 1, &openD2Config); + ProcessOpenD2Argument(arg + 1, pOpenConfig); } } +} + +/* + * Pull default values from a D2CmdArgStrc array + */ +static void PopulateDefaultValues(D2CmdArgStrc* paCommandArguments, void* pvInput) +{ + D2CmdArgStrc* pArg = paCommandArguments; + while (pArg != nullptr && pArg->szKeyName[0] != '\0') + { + switch (pArg->dwType) + { + case CMD_BOOLEAN: + case CMD_BYTE: + *((BYTE*)pvInput + pArg->nOffset) = (BYTE)pArg->dwDefault; + break; + case CMD_WORD: + *((WORD*)pvInput + pArg->nOffset) = (WORD)pArg->dwDefault; + break; + case CMD_DWORD: + *((DWORD*)pvInput + pArg->nOffset) = pArg->dwDefault; + break; + } + ++pArg; + } +} + +/* + * A (tiny) callback that is needed by the game for some reason + */ +int __stdcall LoadExpansionMPQ() +{ + return 1; +} - // Fix some other settings +/* + * Populate the config with default values + */ +static void PopulateConfiguration(D2GameConfigStrc* pConfig, OpenD2ConfigStrc* pOpenConfig) +{ #ifdef EXPANSION - config.dwExpansion = 1; + pConfig->dwExpansion = 1; #endif + // Push the default values from the commandline settings for both OpenD2 and the retail game + //PopulateDefaultValues(CommandArguments, pConfig); + //PopulateDefaultValues(OpenD2CommandArguments, pOpenConfig); + + // Set the default MPQ callback +#if GAME_MINOR_VERSION >= 13 // In 1.13 we apply a +1 offset to keep it kosher + *(void**)((BYTE*)&pConfig->pfMPQFunc + 1) = LoadExpansionMPQ; +#else + pConfig->pfMPQFunc = LoadExpansionMPQ; +#endif +} + +/* + * Initialize the game (from main entrypoint) + */ +int InitGame(int argc, char** argv, DWORD pid) +{ + char* arg; + D2GameConfigStrc config{ 0 }; + OpenD2ConfigStrc openD2Config{ 0 }; + bool bSuccess; + DWORD dwRenderingMode; + D2InterfaceModules dwCurrentModule; + + PopulateConfiguration(&config, &openD2Config); + ParseCommandline(argc, argv, &config, &openD2Config); + dwRenderingMode = GetRenderingMode(&config); /* diff --git a/Shared/D2Shared.hpp b/Shared/D2Shared.hpp index c141939..1dd0a1f 100644 --- a/Shared/D2Shared.hpp +++ b/Shared/D2Shared.hpp @@ -39,22 +39,24 @@ typedef unsigned char BYTE; * The structure which contains data about commandline arguments (ie, the precise values of them) * @author Necrolis */ +#pragma pack(push,enter_include) +#pragma pack(1) struct D2GameConfigStrc // size 0x3C7 { - DWORD dwExpansion; - BYTE bWindowed; // {"VIDEO","WINDOW" ,"w" , 0x00, 0x04, 0x00}, - BYTE b3DFX; // {"VIDEO","3DFX" ,"3dfx" , 0x00, 0x05, 0x00}, - BYTE bOpenGL; // {"VIDEO","OPENGL" ,"opengl", 0x00, 0x06, 0x00}, - BYTE bRave; // {"VIDEO","RAVE" ,"rave" , 0x00, 0x07, 0x00}, - BYTE bD3D; // {"VIDEO","D3D" ,"d3d" , 0x00, 0x08, 0x00}, - BYTE bPerspective; // {"VIDEO","PERSPECTIVE" ,"per" , 0x00, 0x09, 0x00}, - BYTE bQuality; // {"VIDEO","QUALITY" ,"lq" , 0x00, 0x0A, 0x00}, - DWORD dwGamma; // {"VIDEO","GAMMA" ,"gamma" , 0x00, 0x0B, 0x00}, - BYTE bVSync; // {"VIDEO","VSYNC" ,"vsync" , 0x00, 0x0F, 0x00}, - DWORD dwFramerate; // {"VIDEO","FRAMERATE" ,"fr" , 0x01, 0x10, 0x00}, - DWORD dwGameType; // {"NETWORK" ,"GAMETYPE" ,"gametype" , 0x01, 0x0014, 0x00}, - WORD wJoinID; // {"NETWORK" ,"JOINID" ,"joinid" , 0x01, 0x0018, 0x00}, ??? dword overlapps next addy ! - char szGameName[24]; // {"NETWORK" ,"GAMENAME" ,"gamename" , 0x02, 0x001A, 0x00}, + DWORD dwExpansion; // +00 + BYTE bWindowed; // +04 ("w" option) + BYTE b3DFX; // +05 ("3dfx" option) + BYTE bOpenGL; // +06 ("opengl" option) + BYTE bRave; // +07 ("rave" option) + BYTE bD3D; // +08 ("d3d" option) + BYTE bPerspective; // +09 ("per" option) + BYTE bQuality; // +0A ("lq" option) + DWORD dwGamma; // +0B ("gamma" option) + BYTE bVSync; // +0F ("vsync" option) + DWORD dwFramerate; // +10 ("fr" option) + DWORD dwGameType; // +14 ("gametype" option) + WORD wJoinID; // +18 ("joinid" option) ??? dword overlapps next addy ! + char szGameName[24]; // +1A ("gamename" option), char szServerIP[24]; // {"NETWORK" ,"SERVERIP" ,"s" , 0x02, 0x0032, 0x00}, char szBNetIP[24]; // {"NETWORK" ,"BATTLENETIP" ,"bn" , 0x02, 0x004A, 0x00}, char szMCPIP[24]; // {"NETWORK" ,"MCPIP" ,"mcpip" , 0x02, 0x0062, 0x00}, @@ -95,8 +97,8 @@ struct D2GameConfigStrc // size 0x3C7 BYTE bUnk208; BYTE bUnk209; BYTE bUnk20A; - BYTE nDifficulty; - void* pfMPQFunc; // function ptr; returns 1 + BYTE nDifficulty; // +20B + void* pfMPQFunc; // +20C function ptr; returns 1 BYTE bTXT; // {"TXT" ,"TXT" ,"txt" , 0x00, 0x0210, 0x00}, BYTE bLog; // {"DEBUG" ,"LOG" ,"log" , 0x00, 0x0211, 0x00}, BYTE bMsgLog; // {"DEBUG" ,"MSGLOG" ,"msglog" , 0x00, 0x0212, 0x00}, @@ -110,7 +112,7 @@ struct D2GameConfigStrc // size 0x3C7 BYTE bSkipInterface; // skips loading the BNClient QueryInterface BYTE bBuild; // {"BUILD" ,"BUILD" ,"build" , 0x00, 0x021E, 0x00}, void* pInterface; // {"NETWORK" ,"COMINT" ,"comint" , 0x01, 0x021F, 0x00}, - BYTE bUnk223[0x134]; // ? + BYTE bUnk223[0x134]; // +223 ? BYTE bSkipToBNet; // {"NETWORK" ,"SKIPTOBNET" ,"W" , 0x00, 0x0357, 0x00}, //check at d2launch.6FA1D660 CMP BYTE PTR DS:[EAX+357],BL BYTE nScreenSize; // {"VIDEO" ,"SCREENSIZE" ,"sz" , 0x00, 0x358, 0x00}, BYTE bShowLogo; // {"VIDEO" ,"SHOWLOGO" ,"sl" , 0x00, 0x359, 0x00}, @@ -118,6 +120,7 @@ struct D2GameConfigStrc // size 0x3C7 BYTE nPadding; // account for the extra option in 1.13c+ }; +#pragma pack(pop,enter_include) /* * The structure which contains OpenD2-specific data diff --git a/Shared/Fog.h b/Shared/Fog.h index b93b2c6..a994f39 100644 --- a/Shared/Fog.h +++ b/Shared/Fog.h @@ -10,6 +10,7 @@ D2_API void __fastcall FOG_10053(void); D2_API void __fastcall FOG_10089(DWORD, DWORD); D2_API void __fastcall FOG_10090(void); D2_API void __fastcall FOG_10101(DWORD, DWORD); +//D2_API int __cdecl FOG_10117() <-- gets value of -direct D2_API void __cdecl FOG_10143(void*); D2_API void __fastcall FOG_10198(DWORD, void*, double, int, int, int); D2_API void __fastcall FOG_10218(void);