From 3d9febecb9af6ce694f7c1e223c0470a6896240e Mon Sep 17 00:00:00 2001 From: NovaRain Date: Wed, 16 Oct 2019 12:24:54 +0800 Subject: [PATCH] Replaced GetPrivateProfileInt/String with wrapper functions Fixed crash when a name in PremadePaths exceeds 11 characters. --- artifacts/ddraw.ini | 1 + sfall/CRC.cpp | 4 ++-- sfall/Logging.cpp | 8 ++++---- sfall/Modules/BarBoxes.cpp | 2 +- sfall/Modules/Books.cpp | 10 +++++----- sfall/Modules/BugFixes.cpp | 2 +- sfall/Modules/Criticals.cpp | 20 +++++++++++++------- sfall/Modules/DebugEditor.cpp | 6 +++--- sfall/Modules/Drugs.cpp | 16 ++++++++-------- sfall/Modules/Elevators.cpp | 16 +++++++--------- sfall/Modules/ExtraSaveSlots.cpp | 4 ++-- sfall/Modules/HookScripts.cpp | 2 +- sfall/Modules/Karma.cpp | 12 +++++++----- sfall/Modules/Premade.cpp | 10 ++++++++-- sfall/Modules/Reputations.cpp | 4 ++-- sfall/Modules/ScriptExtender.cpp | 2 +- sfall/Modules/Scripting/Handlers/Misc.cpp | 4 ++-- sfall/Modules/Scripting/Opcodes.cpp | 2 +- sfall/Modules/Skills.cpp | 21 +++++++++++++-------- sfall/Modules/Skills.h | 1 + sfall/Modules/Sound.cpp | 2 +- sfall/SafeWrite.cpp | 2 +- sfall/main.cpp | 8 ++++---- 23 files changed, 89 insertions(+), 70 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index a3e51579..fa1a1089 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -449,6 +449,7 @@ UseScrollingQuestsList=1 ;Uncomment these lines to control the premade characters offered when starting a new game ;Multiple options should be separated by commas, and there must be the same number of entries in both lines +;Each name in PremadePaths is limited to 11 characters ;PremadePaths=combat,diplomat,stealth ;PremadeFIDs=201,203,202 diff --git a/sfall/CRC.cpp b/sfall/CRC.cpp index dab870e7..4a6b7fcf 100644 --- a/sfall/CRC.cpp +++ b/sfall/CRC.cpp @@ -83,7 +83,7 @@ void CRC(const char* filepath) { DWORD size = GetFileSize(h, 0), crc; bool sizeMatch = (size == ExpectedSize); - if (!sizeMatch && GetPrivateProfileIntA("Debugging", "SkipSizeCheck", 0, ::sfall::ddrawIni)) { + if (!sizeMatch && iniGetInt("Debugging", "SkipSizeCheck", 0, ::sfall::ddrawIni)) { sizeMatch = true; } @@ -100,7 +100,7 @@ void CRC(const char* filepath) { bool matchedCRC = false; auto extraCrcList = GetIniList("Debugging", "ExtraCRC", "", 512, ',', ::sfall::ddrawIni); - if (extraCrcList.size() > 0) { + if (!extraCrcList.empty()) { matchedCRC = std::any_of(extraCrcList.begin(), extraCrcList.end(), [crc](const std::string& testCrcStr) { auto testedCrc = strtoul(testCrcStr.c_str(), 0, 16); return testedCrc && crc == testedCrc; diff --git a/sfall/Logging.cpp b/sfall/Logging.cpp index 565c839f..4ea2dbc6 100644 --- a/sfall/Logging.cpp +++ b/sfall/Logging.cpp @@ -58,16 +58,16 @@ void dlog_f(const char *fmt, int type, ...) { void LoggingInit() { Log.open("sfall-log.txt", ios_base::out | ios_base::trunc); - if (GetPrivateProfileIntA("Debugging", "Init", 0, ::sfall::ddrawIni)) { + if (iniGetInt("Debugging", "Init", 0, ::sfall::ddrawIni)) { DebugTypes |= DL_INIT; } - if (GetPrivateProfileIntA("Debugging", "Hook", 0, ::sfall::ddrawIni)) { + if (iniGetInt("Debugging", "Hook", 0, ::sfall::ddrawIni)) { DebugTypes |= DL_HOOK; } - if (GetPrivateProfileIntA("Debugging", "Script", 0, ::sfall::ddrawIni)) { + if (iniGetInt("Debugging", "Script", 0, ::sfall::ddrawIni)) { DebugTypes |= DL_SCRIPT; } - if (GetPrivateProfileIntA("Debugging", "Criticals", 0, ::sfall::ddrawIni)) { + if (iniGetInt("Debugging", "Criticals", 0, ::sfall::ddrawIni)) { DebugTypes |= DL_CRITICALS; } } diff --git a/sfall/Modules/BarBoxes.cpp b/sfall/Modules/BarBoxes.cpp index 4a3385f6..c67e106e 100644 --- a/sfall/Modules/BarBoxes.cpp +++ b/sfall/Modules/BarBoxes.cpp @@ -300,7 +300,7 @@ void BarBoxes::init() { MakeCall(0x4615FA, refresh_box_bar_win_hack); SafeWriteBatch((DWORD)newBoxSlot, bboxSlotAddr); // _bboxslot - ifaceWidth = GetPrivateProfileIntA("IFACE", "IFACE_BAR_WIDTH", 640, ".\\f2_res.ini"); + ifaceWidth = iniGetInt("IFACE", "IFACE_BAR_WIDTH", 640, ".\\f2_res.ini"); if (ifaceWidth < 640) ifaceWidth = 640; LoadGameHook::OnAfterGameInit() += SetMaxSlots; diff --git a/sfall/Modules/Books.cpp b/sfall/Modules/Books.cpp index bc2982c5..d267d54d 100644 --- a/sfall/Modules/Books.cpp +++ b/sfall/Modules/Books.cpp @@ -89,10 +89,10 @@ void Books::init() { dlog("Applying books patch...", DL_INIT); const char* iniBooks = booksFile.insert(0, ".\\").c_str(); - bool includeVanilla = (GetPrivateProfileIntA("main", "overrideVanilla", 0, iniBooks) == 0); + bool includeVanilla = (iniGetInt("main", "overrideVanilla", 0, iniBooks) == 0); if (includeVanilla) BooksCount = 5; - int count = GetPrivateProfileIntA("main", "count", 0, iniBooks); + int count = iniGetInt("main", "count", 0, iniBooks); int n = 0; if (count > 0) { @@ -104,9 +104,9 @@ void Books::init() { char section[4]; for (int i = 1; i <= count; i++) { _itoa_s(i, section, 10); - if (books[BooksCount].bookPid = GetPrivateProfileIntA(section, "PID", 0, iniBooks)) { - books[BooksCount].msgID = GetPrivateProfileIntA(section, "TextID", 0, iniBooks); - books[BooksCount].skill = GetPrivateProfileIntA(section, "Skill", 0, iniBooks); + if (books[BooksCount].bookPid = iniGetInt(section, "PID", 0, iniBooks)) { + books[BooksCount].msgID = iniGetInt(section, "TextID", 0, iniBooks); + books[BooksCount].skill = iniGetInt(section, "Skill", 0, iniBooks); BooksCount++; n++; } diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 5daf22c8..55a925ff 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -2382,7 +2382,7 @@ void BugFixes::init() { #ifndef NDEBUG LoadGameHook::OnBeforeGameClose() += PrintAddrList; - if (isDebug && (GetPrivateProfileIntA("Debugging", "BugFixes", 1, ::sfall::ddrawIni) == 0)) return; + if (isDebug && (iniGetInt("Debugging", "BugFixes", 1, ::sfall::ddrawIni) == 0)) return; #endif // Missing game initialization diff --git a/sfall/Modules/Criticals.cpp b/sfall/Modules/Criticals.cpp index a11163dc..434e0b29 100644 --- a/sfall/Modules/Criticals.cpp +++ b/sfall/Modules/Criticals.cpp @@ -76,9 +76,10 @@ void Criticals::ResetCriticalTable(DWORD critter, DWORD bodypart, DWORD slot, DW critTable[critter][bodypart][slot].values[element] = baseCritTable[critter][bodypart][slot].values[element]; } -static void CritTableLoad() { +static int CritTableLoad() { if (mode == 1) { dlogr("Setting up critical hit table using CriticalOverrides.ini (old fmt)", DL_CRITICALS); + if (GetFileAttributes(critTableFile.c_str()) == INVALID_FILE_ATTRIBUTES) return 1; char section[16]; for (DWORD critter = 0; critter < 20; critter++) { for (DWORD part = 0; part < 9; part++) { @@ -88,7 +89,7 @@ static void CritTableLoad() { fo::CritInfo& newEffect = baseCritTable[newCritter][part][crit]; fo::CritInfo& defaultEffect = fo::var::crit_succ_eff[critter][part][crit]; for (int i = 0; i < 7; i++) { - newEffect.values[i] = GetPrivateProfileIntA(section, critNames[i], defaultEffect.values[i], critTableFile.c_str()); + newEffect.values[i] = iniGetInt(section, critNames[i], defaultEffect.values[i], critTableFile.c_str()); if (isDebug) { char logmsg[256]; if (newEffect.values[i] != defaultEffect.values[i]) { @@ -108,15 +109,16 @@ static void CritTableLoad() { if (mode == 3) { dlogr(" and CriticalOverrides.ini (new fmt)", DL_CRITICALS); + if (GetFileAttributes(critTableFile.c_str()) == INVALID_FILE_ATTRIBUTES) return 1; char buf[32], buf2[32], buf3[32]; for (int critter = 0; critter < Criticals::critTableCount; critter++) { sprintf_s(buf, "c_%02d", critter); int all; - if (!(all = GetPrivateProfileIntA(buf, "Enabled", 0, critTableFile.c_str()))) continue; + if (!(all = iniGetInt(buf, "Enabled", 0, critTableFile.c_str()))) continue; for (int part = 0; part < 9; part++) { if (all < 2) { sprintf_s(buf2, "Part_%d", part); - if (!GetPrivateProfileIntA(buf, buf2, 0, critTableFile.c_str())) continue; + if (!iniGetInt(buf, buf2, 0, critTableFile.c_str())) continue; } sprintf_s(buf2, "c_%02d_%d", critter, part); @@ -124,7 +126,7 @@ static void CritTableLoad() { fo::CritInfo& effect = baseCritTable[critter][part][crit]; for (int i = 0; i < 7; i++) { sprintf_s(buf3, "e%d_%s", crit, critNames[i]); - effect.values[i] = GetPrivateProfileIntA(buf2, buf3, effect.values[i], critTableFile.c_str()); + effect.values[i] = iniGetInt(buf2, buf3, effect.values[i], critTableFile.c_str()); } } } @@ -133,6 +135,7 @@ static void CritTableLoad() { dlog("\n", DL_CRITICALS); } } + return 0; } #define SetEntry(critter, bodypart, effect, param, value) fo::var::crit_succ_eff[critter][bodypart][effect].values[param] = value; @@ -240,8 +243,11 @@ static void CriticalTableOverride() { SetEntry(18, 7, 5, 5, 7101); } - CritTableLoad(); - dlogr("Completed applying critical hit table.", DL_INIT); + if (CritTableLoad()) { + dlogr("Failed to initialize critical hit table from file.", DL_INIT); + } else { + dlogr("Completed applying critical hit table.", DL_INIT); + } Inited = true; } #undef SetEntry diff --git a/sfall/Modules/DebugEditor.cpp b/sfall/Modules/DebugEditor.cpp index 02fa3d64..8b93b6e0 100644 --- a/sfall/Modules/DebugEditor.cpp +++ b/sfall/Modules/DebugEditor.cpp @@ -320,7 +320,7 @@ static void __declspec(naked) win_debug_hook() { } void DebugModePatch() { - DWORD dbgMode = GetPrivateProfileIntA("Debugging", "DebugMode", 0, ::sfall::ddrawIni); + DWORD dbgMode = iniGetInt("Debugging", "DebugMode", 0, ::sfall::ddrawIni); if (dbgMode) { dlog("Applying debugmode patch.", DL_INIT); // If the player is using an exe with the debug patch already applied, just skip this block without erroring @@ -342,7 +342,7 @@ void DebugModePatch() { } else { SafeWrite32(0x4C6D9C, (DWORD)debugGnw); } - if (GetPrivateProfileIntA("Debugging", "HideObjIsNullMsg", 0, ::sfall::ddrawIni)) { + if (iniGetInt("Debugging", "HideObjIsNullMsg", 0, ::sfall::ddrawIni)) { MakeJump(0x453FD2, dbg_error_hack); } dlogr(" Done", DL_INIT); @@ -350,7 +350,7 @@ void DebugModePatch() { } void DontDeleteProtosPatch() { - if (GetPrivateProfileIntA("Debugging", "DontDeleteProtos", 0, ::sfall::ddrawIni)) { + if (iniGetInt("Debugging", "DontDeleteProtos", 0, ::sfall::ddrawIni)) { dlog("Applying permanent protos patch.", DL_INIT); SafeWrite8(0x48007E, 0xEB); dlogr(" Done", DL_INIT); diff --git a/sfall/Modules/Drugs.cpp b/sfall/Modules/Drugs.cpp index 8813a703..6b697448 100644 --- a/sfall/Modules/Drugs.cpp +++ b/sfall/Modules/Drugs.cpp @@ -268,9 +268,9 @@ void Drugs::init() { dlog("Applying drugs patch...", DL_INIT); const char* iniDrugs = drugsFile.insert(0, ".\\").c_str(); - if (GetPrivateProfileIntA("main", "JetWithdrawal", 0, iniDrugs) == 1) SafeWrite8(0x47A3A8, 0); + if (iniGetInt("main", "JetWithdrawal", 0, iniDrugs) == 1) SafeWrite8(0x47A3A8, 0); - int count = GetPrivateProfileIntA("main", "Count", 0, iniDrugs); + int count = iniGetInt("main", "Count", 0, iniDrugs); if (count > 0) { if (count > drugsMax) count = drugsMax; drugs = new sDrugs[count](); @@ -279,12 +279,12 @@ void Drugs::init() { char section[4]; for (int i = 1; i <= count; i++) { _itoa_s(i, section, 10); - int pid = GetPrivateProfileIntA(section, "PID", 0, iniDrugs); + int pid = iniGetInt(section, "PID", 0, iniDrugs); if (pid > 0) { CheckEngineNumEffects(set, pid); drugs[drugsCount].drugPid = pid; - drugs[drugsCount].addictTimeOff = drugs[drugsCount].iniAddictTimeOff = GetPrivateProfileIntA(section, "AddictTime", 0, iniDrugs); - long ef = GetPrivateProfileIntA(section, "NumEffects", -1, iniDrugs); + drugs[drugsCount].addictTimeOff = drugs[drugsCount].iniAddictTimeOff = iniGetInt(section, "AddictTime", 0, iniDrugs); + long ef = iniGetInt(section, "NumEffects", -1, iniDrugs); if (set != -1) { if (ef < -1) { ef = -1; @@ -298,12 +298,12 @@ void Drugs::init() { drugs[drugsCount].numEffects = ef; // -1 to use the value from the engine } else { drugs[drugsCount].numEffects = drugs[drugsCount].iniNumEffects = max(0, ef); - int gvar = GetPrivateProfileIntA(section, "GvarID", 0, iniDrugs); + int gvar = iniGetInt(section, "GvarID", 0, iniDrugs); drugs[drugsCount].gvarID = max(0, gvar); // not allow negative values if (gvar) { - int msg = GetPrivateProfileIntA(section, "TextID", -1, iniDrugs); + int msg = iniGetInt(section, "TextID", -1, iniDrugs); drugs[drugsCount].msgID = (msg > 0) ? msg : -1; - drugs[drugsCount].frmID = GetPrivateProfileIntA(section, "FrmID", -1, iniDrugs); + drugs[drugsCount].frmID = iniGetInt(section, "FrmID", -1, iniDrugs); addictionGvarCount++; } } diff --git a/sfall/Modules/Elevators.cpp b/sfall/Modules/Elevators.cpp index 4d5b7f7d..842ce99c 100644 --- a/sfall/Modules/Elevators.cpp +++ b/sfall/Modules/Elevators.cpp @@ -28,8 +28,6 @@ static const int exitsPerElevator = 4; static const int vanillaElevatorCount = 24; static const int elevatorCount = 50; -//static char elevFile[MAX_PATH] = ".\\"; - static DWORD elevatorType[elevatorCount] = {0}; static fo::ElevatorExit elevatorExits[elevatorCount][exitsPerElevator] = {0}; // _retvals static fo::ElevatorFrms elevatorsFrms[elevatorCount] = {0}; // _intotal @@ -118,23 +116,23 @@ static void LoadElevators(const char* elevFile) { if (elevFile) { for (int i = 0; i < elevatorCount; i++) { _itoa_s(i, section, 10); - int type = GetPrivateProfileIntA(section, "Image", elevatorType[i], elevFile); + int type = iniGetInt(section, "Image", elevatorType[i], elevFile); elevatorType[i] = min(type, elevatorCount - 1); if (i >= vanillaElevatorCount) { - int cBtn = GetPrivateProfileIntA(section, "ButtonCount", 2, elevFile); + int cBtn = iniGetInt(section, "ButtonCount", 2, elevFile); if (cBtn > exitsPerElevator) cBtn = exitsPerElevator; elevatorsBtnCount[i] = max(2, cBtn); } - elevatorsFrms[i].main = GetPrivateProfileIntA(section, "MainFrm", elevatorsFrms[i].main, elevFile); - elevatorsFrms[i].buttons = GetPrivateProfileIntA(section, "ButtonsFrm", elevatorsFrms[i].buttons, elevFile); + elevatorsFrms[i].main = iniGetInt(section, "MainFrm", elevatorsFrms[i].main, elevFile); + elevatorsFrms[i].buttons = iniGetInt(section, "ButtonsFrm", elevatorsFrms[i].buttons, elevFile); char setting[32]; for (int j = 0; j < exitsPerElevator; j++) { sprintf_s(setting, "ID%d", j + 1); - elevatorExits[i][j].id = GetPrivateProfileIntA(section, setting, elevatorExits[i][j].id, elevFile); + elevatorExits[i][j].id = iniGetInt(section, setting, elevatorExits[i][j].id, elevFile); sprintf_s(setting, "Elevation%d", j + 1); - elevatorExits[i][j].elevation = GetPrivateProfileIntA(section, setting, elevatorExits[i][j].elevation, elevFile); + elevatorExits[i][j].elevation = iniGetInt(section, setting, elevatorExits[i][j].elevation, elevFile); sprintf_s(setting, "Tile%d", j + 1); - elevatorExits[i][j].tile = GetPrivateProfileIntA(section, setting, elevatorExits[i][j].tile, elevFile); + elevatorExits[i][j].tile = iniGetInt(section, setting, elevatorExits[i][j].tile, elevFile); } } } diff --git a/sfall/Modules/ExtraSaveSlots.cpp b/sfall/Modules/ExtraSaveSlots.cpp index 068738fa..9c042e95 100644 --- a/sfall/Modules/ExtraSaveSlots.cpp +++ b/sfall/Modules/ExtraSaveSlots.cpp @@ -62,11 +62,11 @@ void LoadPageOffsets() { sprintf_s(LoadPath, MAX_PATH, filename, fo::var::patches); - fo::var::slot_cursor = GetPrivateProfileInt("POSITION", "ListNum", 0, LoadPath); + fo::var::slot_cursor = iniGetInt("POSITION", "ListNum", 0, LoadPath); if (fo::var::slot_cursor > 9) { fo::var::slot_cursor = 0; } - LSPageOffset = GetPrivateProfileInt("POSITION", "PageOffset", 0, LoadPath); + LSPageOffset = iniGetInt("POSITION", "PageOffset", 0, LoadPath); if (LSPageOffset > 9990) { LSPageOffset = 0; } diff --git a/sfall/Modules/HookScripts.cpp b/sfall/Modules/HookScripts.cpp index ccafafd9..9397ddf0 100644 --- a/sfall/Modules/HookScripts.cpp +++ b/sfall/Modules/HookScripts.cpp @@ -262,7 +262,7 @@ void HookScripts::init() { LoadGameHook::OnGameModeChange() += GameModeChangeHook; LoadGameHook::OnAfterGameStarted() += SourceUseSkillOnInit; - HookScripts::injectAllHooks = isDebug && (GetPrivateProfileIntA("Debugging", "InjectAllGameHooks", 0, ::sfall::ddrawIni) != 0); + HookScripts::injectAllHooks = isDebug && (iniGetInt("Debugging", "InjectAllGameHooks", 0, ::sfall::ddrawIni) != 0); if (HookScripts::injectAllHooks) dlogr("Injecting all game hooks", DL_HOOK); } diff --git a/sfall/Modules/Karma.cpp b/sfall/Modules/Karma.cpp index 183cf3e7..0b678d17 100644 --- a/sfall/Modules/Karma.cpp +++ b/sfall/Modules/Karma.cpp @@ -90,14 +90,16 @@ void ApplyDisplayKarmaChangesPatch() { void ApplyKarmaFRMsPatch() { auto karmaFrmList = GetConfigList("Misc", "KarmaFRMs", "", 512); - if (!karmaFrmList.empty()) { + size_t countFrm = karmaFrmList.size(); + if (countFrm) { dlog("Applying karma FRM patch.", DL_INIT); - auto karmaPointsList = GetConfigList("Misc", "KarmaPoints", "", 512); - karmaFrms.resize(karmaFrmList.size()); - for (size_t i = 0; i < karmaFrmList.size(); i++) { + + karmaFrms.resize(countFrm); + size_t countPoints = karmaPointsList.size(); + for (size_t i = 0; i < countFrm; i++) { karmaFrms[i].frm = atoi(karmaFrmList[i].c_str()); - karmaFrms[i].points = (karmaPointsList.size() > i) + karmaFrms[i].points = (countPoints > i) ? atoi(karmaPointsList[i].c_str()) : INT_MAX; } diff --git a/sfall/Modules/Premade.cpp b/sfall/Modules/Premade.cpp index 2cd3df1d..5f438c42 100644 --- a/sfall/Modules/Premade.cpp +++ b/sfall/Modules/Premade.cpp @@ -30,11 +30,16 @@ void Premade::init() { auto premadePaths = GetConfigList("misc", "PremadePaths", "", 512); auto premadeFids = GetConfigList("misc", "PremadeFIDs", "", 512); if (!premadePaths.empty() && !premadeFids.empty()) { + dlog("Applying premade characters patch.", DL_INIT); int count = min(premadePaths.size(), premadeFids.size()); premade = new fo::PremadeChar[count]; for (int i = 0; i < count; i++) { auto path = "premade\\" + premadePaths[i]; - strcpy_s(premade[i].path, 20, path.c_str()); + if (path.size() > 19) { + dlogr(" Failed: name exceeds 11 characters", DL_INIT); + return; + } + strcpy(premade[i].path, path.c_str()); premade[i].fid = atoi(premadeFids[i].c_str()); } @@ -42,7 +47,8 @@ void Premade::init() { SafeWrite32(0x4A7D76, (DWORD)premade); SafeWrite32(0x4A8B1E, (DWORD)premade); SafeWrite32(0x4A7E2C, (DWORD)premade + 20); - strcpy_s((char*)0x50AF68, 20, premade[0].path); + strcpy((char*)0x50AF68, premade[0].path); + dlogr(" Done", DL_INIT); } } diff --git a/sfall/Modules/Reputations.cpp b/sfall/Modules/Reputations.cpp index 05e02fdb..48292a40 100644 --- a/sfall/Modules/Reputations.cpp +++ b/sfall/Modules/Reputations.cpp @@ -37,17 +37,17 @@ static CityRep* repList = nullptr; void Reputations::init() { auto cityRepList = GetConfigList("Misc", "CityRepsList", "", 512); size_t count = cityRepList.size(); - if (count > 0) { + if (count) { repList = new CityRep[count]; std::vector pair; pair.reserve(2); for (size_t i = 0; i < count; i++) { - pair.clear(); split(cityRepList[i], ':', std::back_inserter(pair), 2); repList[i].cityID = atoi(pair[0].c_str()); if (pair.size() >= 2) { repList[i].globalID = atoi(pair[1].c_str()); } + pair.clear(); } SafeWrite32(0x43BEA5, (DWORD)&repList[0].cityID); diff --git a/sfall/Modules/ScriptExtender.cpp b/sfall/Modules/ScriptExtender.cpp index 76138fc7..d6f3d5ff 100644 --- a/sfall/Modules/ScriptExtender.cpp +++ b/sfall/Modules/ScriptExtender.cpp @@ -751,7 +751,7 @@ void ScriptExtender::init() { } } - alwaysFindScripts = isDebug && (GetPrivateProfileIntA("Debugging", "AlwaysFindScripts", 0, ::sfall::ddrawIni) != 0); + alwaysFindScripts = isDebug && (iniGetInt("Debugging", "AlwaysFindScripts", 0, ::sfall::ddrawIni) != 0); if (alwaysFindScripts) dlogr("Always searching for global scripts behavior enabled.", DL_SCRIPT); MakeJump(0x4A390C, FindSidHack); diff --git a/sfall/Modules/Scripting/Handlers/Misc.cpp b/sfall/Modules/Scripting/Handlers/Misc.cpp index af73e0e0..f75aa176 100644 --- a/sfall/Modules/Scripting/Handlers/Misc.cpp +++ b/sfall/Modules/Scripting/Handlers/Misc.cpp @@ -562,10 +562,10 @@ static DWORD GetIniSetting(const char* str, bool isString) { } if (isString) { IniStrBuffer[0] = 0; - GetPrivateProfileStringA(section, key, "", IniStrBuffer, 256, file); + iniGetString(section, key, "", IniStrBuffer, 256, file); return (DWORD)&IniStrBuffer[0]; } else { - return GetPrivateProfileIntA(section, key, -1, file); + return iniGetInt(section, key, -1, file); } } diff --git a/sfall/Modules/Scripting/Opcodes.cpp b/sfall/Modules/Scripting/Opcodes.cpp index e4bf2fa4..fb0f18cd 100644 --- a/sfall/Modules/Scripting/Opcodes.cpp +++ b/sfall/Modules/Scripting/Opcodes.cpp @@ -263,7 +263,7 @@ void InitNewOpcodes() { SafeWrite32(0x46CE6C, (DWORD)opcodes); // call that actually jumps to the opcode SafeWrite32(0x46E390, (DWORD)opcodes); // mov that writes to the opcode - if (GetPrivateProfileIntA("Debugging", "AllowUnsafeScripting", 0, ::sfall::ddrawIni)) { + if (iniGetInt("Debugging", "AllowUnsafeScripting", 0, ::sfall::ddrawIni)) { dlogr(" Unsafe opcodes enabled.", DL_SCRIPT); opcodes[0x1cf] = op_write_byte; opcodes[0x1d0] = op_write_short; diff --git a/sfall/Modules/Skills.cpp b/sfall/Modules/Skills.cpp index 45bbb4da..f9d9bb2f 100644 --- a/sfall/Modules/Skills.cpp +++ b/sfall/Modules/Skills.cpp @@ -331,17 +331,21 @@ void Skills::init() { // 0x00000400 - Energy Weapon (forces weapon to use Energy Weapons skill) HookCall(0x47831E, item_w_skill_hook); + LoadGameHook::OnGameReset() += Skills_OnGameLoad; + char buf[512], key[16]; auto skillsFile = GetConfigString("Misc", "SkillsFile", "", MAX_PATH); if (!skillsFile.empty()) { fo::SkillInfo *skills = fo::var::skill_data; const char* file = skillsFile.insert(0, ".\\").c_str(); + if (GetFileAttributes(file) == INVALID_FILE_ATTRIBUTES) return; + multipliers = new double[7 * fo::SKILL_count](); for (int i = 0; i < fo::SKILL_count; i++) { sprintf(key, "Skill%d", i); - if (GetPrivateProfileStringA("Skills", key, "", buf, 64, file)) { + if (iniGetString("Skills", key, "", buf, 64, file)) { char* tok = strtok(buf, "|"); while (tok) { if (strlen(tok) >= 2) { @@ -365,7 +369,7 @@ void Skills::init() { if (skills[i].statB >= 0) multipliers[i * 7 + skills[i].statB] = skills[i].statMulti; } sprintf(key, "SkillCost%d", i); - if (GetPrivateProfileStringA("Skills", key, "", buf, 512, file)) { + if (iniGetString("Skills", key, "", buf, 512, file)) { char* tok = strtok(buf, "|"); DWORD upto = 0; BYTE price = 1; @@ -387,15 +391,15 @@ void Skills::init() { for (int j = 201; j <= 512; j++) skillCosts[i * 512 + j] = 6; } sprintf(key, "SkillBase%d", i); - skills[i].base = GetPrivateProfileIntA("Skills", key, skills[i].base, file); + skills[i].base = iniGetInt("Skills", key, skills[i].base, file); sprintf(key, "SkillMulti%d", i); - int multi = GetPrivateProfileIntA("Skills", key, skills[i].skillPointMulti, file); + int multi = iniGetInt("Skills", key, skills[i].skillPointMulti, file); if (multi < 1) multi = 1; else if (multi > 10) multi = 10; skills[i].skillPointMulti = multi; sprintf(key, "SkillImage%d", i); - skills[i].image = GetPrivateProfileIntA("Skills", key, skills[i].image, file); + skills[i].image = iniGetInt("Skills", key, skills[i].image, file); } MakeJump(0x4AA59D, skill_level_hack_bonus, 1); @@ -403,11 +407,12 @@ void Skills::init() { MakeJump(0x4AA940, skill_dec_point_hack_cost, 1); HookCalls(skill_dec_point_hook_cost, {0x4AA9E1, 0x4AA9F1}); - basedOnPoints = GetPrivateProfileIntA("Skills", "BasedOnPoints", 0, file); + basedOnPoints = iniGetInt("Skills", "BasedOnPoints", 0, file); if (basedOnPoints) HookCall(0x4AA9EC, (void*)fo::funcoffs::skill_points_); // skill_dec_point_ } - - LoadGameHook::OnGameReset() += Skills_OnGameLoad; } +void Skills::exit() { + delete[] multipliers; +} } diff --git a/sfall/Modules/Skills.h b/sfall/Modules/Skills.h index a8d83f88..9a3333a2 100644 --- a/sfall/Modules/Skills.h +++ b/sfall/Modules/Skills.h @@ -27,6 +27,7 @@ class Skills : public Module { public: const char* name() { return "Skills"; } void init(); + void exit() override; }; void _stdcall SetSkillMax(fo::GameObject* critter, int maximum); diff --git a/sfall/Modules/Sound.cpp b/sfall/Modules/Sound.cpp index fe7f57a7..646d4d24 100644 --- a/sfall/Modules/Sound.cpp +++ b/sfall/Modules/Sound.cpp @@ -64,7 +64,7 @@ void Sound::init() { HookCall(0x42B849, ai_print_msg_hook); //Yes, I did leave this in on purpose. Will be of use to anyone trying to add in the sound effects - if (isDebug && GetPrivateProfileIntA("Debugging", "Test_ForceFloats", 0, ::sfall::ddrawIni)) { + if (isDebug && iniGetInt("Debugging", "Test_ForceFloats", 0, ::sfall::ddrawIni)) { SafeWrite8(0x42B6F5, 0xEB); // bypass chance } } diff --git a/sfall/SafeWrite.cpp b/sfall/SafeWrite.cpp index ab5d8052..10d7adb5 100644 --- a/sfall/SafeWrite.cpp +++ b/sfall/SafeWrite.cpp @@ -14,7 +14,7 @@ std::multimap writeAddress; /* Checking for conflicts requires all options in ddraw.ini to be enabled */ void PrintAddrList() { - bool level = (GetPrivateProfileIntA("Debugging", "Enable", 0, ::sfall::ddrawIni) > 1); + bool level = (iniGetInt("Debugging", "Enable", 0, ::sfall::ddrawIni) > 1); unsigned long pa = 0, pl = 0; for (const auto &wa : writeAddress) { unsigned long diff = (pa) ? (wa.first - pa) : -1; // length between two addresses diff --git a/sfall/main.cpp b/sfall/main.cpp index bc83a441..b65b44c9 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -251,7 +251,7 @@ static void CompatModeCheck(HKEY root, const char* filepath, int extra) { inline void SfallInit() { // enabling debugging features - isDebug = (GetPrivateProfileIntA("Debugging", "Enable", 0, ::sfall::ddrawIni) != 0); + isDebug = (iniGetInt("Debugging", "Enable", 0, ::sfall::ddrawIni) != 0); if (isDebug) { LoggingInit(); if (!ddraw.dll) dlog("Error: Cannot load the original ddraw.dll library.\n", DL_MAIN); @@ -262,7 +262,7 @@ inline void SfallInit() { CRC(filepath); - if (!isDebug || !GetPrivateProfileIntA("Debugging", "SkipCompatModeCheck", 0, ::sfall::ddrawIni)) { + if (!isDebug || !iniGetInt("Debugging", "SkipCompatModeCheck", 0, ::sfall::ddrawIni)) { int is64bit; typedef int (_stdcall *chk64bitproc)(HANDLE, int*); HMODULE h = LoadLibrary("Kernel32.dll"); @@ -280,7 +280,7 @@ inline void SfallInit() { // ini file override bool cmdlineexists = false; char* cmdline = GetCommandLineA(); - if (GetPrivateProfileIntA("Main", "UseCommandLine", 0, ::sfall::ddrawIni)) { + if (iniGetInt("Main", "UseCommandLine", 0, ::sfall::ddrawIni)) { while (cmdline[0] == ' ') cmdline++; bool InQuote = false; int count = -1; @@ -314,7 +314,7 @@ inline void SfallInit() { } } else { defaultIni: - strcpy_s(ini, ::sfall::ddrawIni); + strcpy(&ini[2], &::sfall::ddrawIni[2]); } GetConfigString("Main", "TranslationsINI", ".\\Translations.ini", translationIni, 65);