diff --git a/D2Patch.h b/D2Patch.h index 4b29f29..86bc74f 100644 --- a/D2Patch.h +++ b/D2Patch.h @@ -13,12 +13,57 @@ #include #include #include +#include +#include + // Function to read settings from D2Mod.ini file -int ReadSettingFromIni(const char* section, const char* key, BYTE defaultValue) { - return GetPrivateProfileInt(section, key, defaultValue, "D2Mod.ini"); +#include + +// Function to read setting from the INI file and provide detailed information +int ReadSettingFromIni(const char* section, const char* key, int defaultValue) { + // Get the file path + const char* filePath = "./D2Mod.ini"; + + // Check if the file exists and can be found + DWORD fileAttributes = GetFileAttributesA(filePath); + if (fileAttributes == INVALID_FILE_ATTRIBUTES) { + MessageBoxA(NULL, "INI file not found or inaccessible.", "INI File Error", MB_OK | MB_ICONERROR); + return defaultValue; + } + + // Try to read the setting from the INI file + int value = GetPrivateProfileIntA(section, key, defaultValue, filePath); + //DWORD lastError = GetLastError(); + //if (value == 0 && lastError != 0) { + // // Error occurred while reading from INI file + // char errorMessage[512]; + // sprintf(errorMessage, "Error reading setting from INI file:\n\n" + // "INI File Path: %s\n" + // "Section: %s\n" + // "Key: %s\n" + // "Default Value: %d\n" + // "Error Code: %d\n\n" + // "Ensure that the section and key exist in the INI file and the file is accessible.", + // filePath, section, key, defaultValue, lastError); + // MessageBoxA(NULL, errorMessage, "INI File Error", MB_OK | MB_ICONERROR); + //} + //else { + // // Successfully read the setting + // char successMessage[256]; + // sprintf(successMessage, "Setting read from INI file:\n\n" + // "INI File Path: %s\n" + // "Section: %s\n" + // "Key: %s\n" + // "Value: %d", filePath, section, key, value); + // MessageBoxA(NULL, successMessage, "INI File Success", MB_OK | MB_ICONINFORMATION); + //} + + return value; } + + // Function to calculate relative offset (D2COMMON base address is 0x6F600000) DWORD calculateRelativeOffsetD2Common(DWORD offset) { return offset - 0x6F600000; @@ -30,10 +75,10 @@ DWORD calculateRelativeOffsetD2Client(DWORD offset) { } // Define settings from D2Mod.ini -BYTE leftBorder = ReadSettingFromIni("CharmZone", "leftBorder", 0x00); -BYTE rightBorder = ReadSettingFromIni("CharmZone", "rightBorder", 0x10); -BYTE topBorder = ReadSettingFromIni("CharmZone", "topBorder", 0x0C); -BYTE bottomBorder = ReadSettingFromIni("CharmZone", "bottomBorder", 0x10); +BYTE leftBorder = ReadSettingFromIni("CharmZone", "leftBorder", 0x04); +BYTE rightBorder = ReadSettingFromIni("CharmZone", "rightBorder", 0x08); +BYTE topBorder = ReadSettingFromIni("CharmZone", "topBorder", 0x00); +BYTE bottomBorder = ReadSettingFromIni("CharmZone", "bottomBorder", 0x04); // Function to reverse the bytes of a hexadecimal number uint32_t reverseHexBytes(uint32_t hexNumber) { @@ -113,20 +158,20 @@ static const DLLPatchStrc gptTemplatePatches[] = {D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FAE118F), (DWORD)PATCH_JMP, FALSE, 0x00}, {D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FAE1190), (DWORD)reverseHexBytes(0x6CB30800), FALSE, 0x00}, {D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FAE1194), (DWORD)0x90, FALSE, 0x03}, - + // Patching TEST EAX,EAX at address 0x6FB6C500 {D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FB6C500), (DWORD)(0xC085), FALSE, 0x00}, // Patching JE 6FAE1283 at address 0x6FB6C502 {D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FB6C502), (DWORD)(0x840F), FALSE, 0x00}, {D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FB6C504), (DWORD)reverseHexBytes(0x7B4DF7FF), FALSE, 0x00}, - + // Patching PUSH 0D at address 0x6FB6C508 {D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FB6C508), (DWORD)(0x0D6A), FALSE, 0x00}, - + // Patching PUSH ESI at address 0x6FB6C50A {D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FB6C50A), (DWORD)(0x56), FALSE, 0x00}, - + // Patching CALL at address 0x6FB6C50B {D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FB6C50B), (DWORD)(0xE8), FALSE, 0x01}, {D2DLL_D2CLIENT, calculateRelativeOffsetD2Client(0x6FB6C50C), (DWORD)reverseHexBytes(0x10E7FFFF), FALSE, 0x00},