This commit is contained in:
Hash Borgir 2024-04-10 20:39:36 -06:00
parent f88ca7c2f2
commit 0ff4515b2b

View File

@ -13,12 +13,57 @@
#include <map>
#include <fstream>
#include <algorithm>
#include <unordered_map>
#include <Windows.h>
// 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 <Windows.h>
// 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) {