diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 03c59865..e6d216e7 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -437,7 +437,6 @@ UseScrollingQuestsList=1 ;Use this line to modify the list of cities and their associated global variables used for city reputations ;Syntax is 'city id:global id', with each city/global pair separated by a comma. -;CityRepsCount=19 ;CityRepsList=0:47,2:48,1:49,4:50,5:51,3:52,8:53,6:54,7:55,13:56,10:57,11:59,14:61,17:63,19:64,18:65,25:66,9:294,20:308 ;Set this to a valid path to save a copy of the console contents @@ -453,7 +452,6 @@ SpeedInterfaceCounterAnims=0 ;These lines allow you to control the karma FRMs displayed on the character screen ;Number of KarmaPoints should be 1 less than number of KarmaFRMs -;KarmaFRMsCount=3 ;KarmaFRMs=47,48,49 ;KarmaPoints=-100,100 diff --git a/sfall/Books.cpp b/sfall/Books.cpp index f537c3f0..29da4c47 100644 --- a/sfall/Books.cpp +++ b/sfall/Books.cpp @@ -24,7 +24,6 @@ static int BooksCount = 0; static const int BooksMax = 50; -static char iniBooks[MAX_PATH]; struct sBook { DWORD bookPid; @@ -82,11 +81,10 @@ static void LoadVanillaBooks() { } void BooksInit() { - char buf[MAX_PATH - 3]; - GetPrivateProfileString("Misc", "BooksFile", "", buf, MAX_PATH - 3, ini); - if (strlen(buf) > 0) { + std::string booksFile = GetConfigString("Misc", "BooksFile", "", MAX_PATH); + if (!booksFile.empty()) { dlog("Applying books patch...", DL_INIT); - sprintf(iniBooks, ".\\%s", buf); + const char* iniBooks = booksFile.insert(0, ".\\").c_str(); bool includeVanilla = (GetPrivateProfileIntA("main", "overrideVanilla", 0, iniBooks) == 0); if (includeVanilla) BooksCount = 5; diff --git a/sfall/Elevators.cpp b/sfall/Elevators.cpp index 32166020..fe1b1119 100644 --- a/sfall/Elevators.cpp +++ b/sfall/Elevators.cpp @@ -17,15 +17,15 @@ */ #include "main.h" +#include "FalloutEngine.h" #include "Elevators.h" -#include "FalloutEngine.h" static const int exitsPerElevator = 4; static const int vanillaElevatorCount = 24; static const int elevatorCount = 50; -static char elevFile[MAX_PATH] = ".\\"; +//static char elevFile[MAX_PATH] = ".\\"; struct sElevator { DWORD ID1; @@ -122,7 +122,7 @@ void ResetElevators() { //for (int i = vanillaElevatorCount; i < elevatorCount; i++) elevatorType[i] = 0; } -static void LoadElevators() { +void LoadElevators(const char* elevFile) { //ResetElevators(); memcpy(elevators, (void*)_retvals, sizeof(sElevator) * vanillaElevatorCount); @@ -161,9 +161,7 @@ static void LoadElevators() { } } -void ElevatorsInit(char* file) { - strcat_s(elevFile, file); - +void ElevatorsInit() { HookCall(0x43EF83, GetMenuHook); HookCall(0x43F141, CheckHotKeysHook); //HookCall(0x43F2D2, UnknownHook2); // unused @@ -185,6 +183,4 @@ void ElevatorsInit(char* file) { MakeCall(0x43F05D, GetNumButtonsHook1, 2); MakeCall(0x43F184, GetNumButtonsHook2, 2); MakeCall(0x43F1E4, GetNumButtonsHook3, 2); - - LoadElevators(); } diff --git a/sfall/Elevators.h b/sfall/Elevators.h index 7f0bfc91..c6057bed 100644 --- a/sfall/Elevators.h +++ b/sfall/Elevators.h @@ -18,4 +18,5 @@ #pragma once -void ElevatorsInit(char* file); \ No newline at end of file +void ElevatorsInit(); +void LoadElevators(const char* elevFile); diff --git a/sfall/LoadGameHook.cpp b/sfall/LoadGameHook.cpp index bef2c39a..1d9622b0 100644 --- a/sfall/LoadGameHook.cpp +++ b/sfall/LoadGameHook.cpp @@ -87,7 +87,7 @@ static void _stdcall ResetState(DWORD onLoad) { if (!onLoad) FileSystemReset(); ClearGlobalScripts(); ClearGlobals(); - ForceGraphicsRefresh(0); + ForceGraphicsRefresh(0); // disable refresh WipeSounds(); if (GraphicsMode > 3) GraphicsResetOnGameLoad(); Combat_OnGameLoad(); diff --git a/sfall/Premade.cpp b/sfall/Premade.cpp index 9cba0dcf..ce16eb19 100644 --- a/sfall/Premade.cpp +++ b/sfall/Premade.cpp @@ -27,30 +27,15 @@ struct PremadeChar { PremadeChar* premade; void PremadeInit() { - char buf[512]; - GetPrivateProfileString("misc", "PremadePaths", "", buf, 512, ini); - if(buf[0]) { - char buf2[512]; - GetPrivateProfileString("misc", "PremadeFIDs", "", buf2, 512, ini); - - int count=1; - char* tmp=buf; - while(tmp=strchr(tmp, ',')) { tmp++; count++; } - premade=new PremadeChar[count]; - - tmp=buf; - char* tmp2=buf2; - for(int i=0;i premadePaths = GetConfigList("misc", "PremadePaths", "", 512); + std::vector premadeFids = GetConfigList("misc", "PremadeFIDs", "", 512); + if (!premadePaths.empty() && !premadeFids.empty()) { + int count = min(premadePaths.size(), premadeFids.size()); + premade = new PremadeChar[count]; + for (int i = 0; i < count; i++) { + std::string path = "premade\\" + premadePaths[i]; + strcpy_s(premade[i].path, 20, path.c_str()); + premade[i].fid = atoi(premadeFids[i].c_str()); } SafeWrite32(0x51C8D4, count); diff --git a/sfall/Reputations.cpp b/sfall/Reputations.cpp index da58ba21..1ee16f49 100644 --- a/sfall/Reputations.cpp +++ b/sfall/Reputations.cpp @@ -16,35 +16,32 @@ * along with this program. If not, see . */ +#include + #include "main.h" +#include "Utils.h" struct CityRep { DWORD globalID; DWORD cityID; }; +// C-array is neccessary, because it is used by game engine static CityRep* repList = nullptr; void ReputationsInit() { - int count; - if (count = GetPrivateProfileIntA("Misc", "CityRepsCount", 0, ini)) { + std::vector cityRepList = GetConfigList("Misc", "CityRepsList", "", 512); + size_t count = cityRepList.size(); + if (count > 0) { repList = new CityRep[count]; - char buf[512]; - GetPrivateProfileStringA("Misc", "CityRepsList", "", buf, 512, ini); - char* end; - char* start = buf; - for(int i = 0; i < count; i++) { - end = strchr(start, ':'); - *end = '\0'; - repList[i].cityID = atoi(start); - start = end + 1; - if (i == count - 1) { - repList[i].globalID = atoi(start); - } else { - end = strchr(start, ','); - *end = '\0'; - repList[i].globalID = atoi(start); - start = end + 1; + 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()); } } diff --git a/sfall/Stats.cpp b/sfall/Stats.cpp index 45d12add..1cb44475 100644 --- a/sfall/Stats.cpp +++ b/sfall/Stats.cpp @@ -227,28 +227,21 @@ void StatsInit() { MakeCall(0x4AF54E, stat_set_base_hack_allow); MakeCall(0x455D65, op_set_critter_stat_hack); // STAT_unused for other critters - char table[2048]; - GetConfigString("Misc", "XPTable", "", table, 2048); - if (strlen(table) > 0) { - char *ptr = table, *ptr2; - DWORD level = 0; - + std::vector xpTableList = GetConfigList("Misc", "XPTable", "", 2048); + size_t numLevels = xpTableList.size(); + if (numLevels > 0) { HookCall(0x434AA7, GetNextLevelXPHook); HookCall(0x439642, GetNextLevelXPHook); HookCall(0x4AFB22, GetNextLevelXPHook); HookCall(0x496C8D, GetLevelXPHook); HookCall(0x4AFC53, GetLevelXPHook); - while ((ptr2 = strstr(ptr, ",")) && level < 99) { - ptr2[0] = '\0'; - xpTable[level++] = atoi(ptr); - ptr = ptr2 + 1; + for (size_t i = 0; i < 99; i++) { + xpTable[i] = (i < numLevels) + ? atoi(xpTableList[i].c_str()) + : -1; } - if (level < 99 && ptr[0] != '\0') { - xpTable[level++] = atoi(ptr); - } - for (int i = level; i < 99; i++) xpTable[i] = -1; - SafeWrite8(0x4AFB1B, static_cast(level + 1)); + SafeWrite8(0x4AFB1B, static_cast(numLevels + 1)); } std::string statsFile = GetConfigString("Misc", "DerivedStats", "", MAX_PATH); diff --git a/sfall/main.cpp b/sfall/main.cpp index 1c5a0a5f..ed71f23d 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -75,7 +75,7 @@ bool hrpIsEnabled = false; bool hrpVersionValid = false; // HRP 4.1.8 version validation const char ddrawIniDef[] = ".\\ddraw.ini"; -char ini[65] = ".\\"; +static char ini[65] = ".\\"; static char translationIni[65]; DWORD modifiedIni; @@ -136,6 +136,13 @@ size_t Translate(const char* section, const char* setting, const char* defaultVa static std::vector savPrototypes; +struct KarmaFrmSetting { + DWORD frm; + int points; +}; + +static std::vector karmaFrms; + static char mapName[65]; static char configName[65]; static char patchName[65]; @@ -410,7 +417,7 @@ static void _stdcall SetKarma(int value) { mov old, eax; } old = value - old; - char buf[64]; + char buf[128]; if (old == 0) return; if (old > 0) { sprintf_s(buf, KarmaGainMsg, old); @@ -422,12 +429,12 @@ static void _stdcall SetKarma(int value) { static void __declspec(naked) SetGlobalVarWrapper() { __asm { - test eax, eax; + test eax, eax; // GVar number jnz end; - pushad; + pushadc; push edx; call SetKarma; - popad; + popadc; end: jmp game_set_global_var_; } @@ -522,15 +529,14 @@ end: } } -static DWORD KarmaFrmCount; -static DWORD* KarmaFrms = nullptr; -static int* KarmaPoints = nullptr; static DWORD _stdcall DrawCard() { - int rep = **(int**)_game_global_vars; - for (DWORD i = 0; i < KarmaFrmCount - 1; i++) { - if (rep < KarmaPoints[i]) return KarmaFrms[i]; + int reputation = **(int**)_game_global_vars; + for (std::vector::const_iterator it = karmaFrms.begin(); it != karmaFrms.end(); ++it) { + if (reputation < it->points) { + return it->frm; + } } - return KarmaFrms[KarmaFrmCount - 1]; + return karmaFrms.end()->frm; } static void __declspec(naked) DrawInfoWin_hook() { @@ -664,14 +670,14 @@ static void DllMain2() { dlogr("Running TalkingHeadsInit().", DL_INIT); TalkingHeadsInit(); - //if (GetPrivateProfileIntA("Input", "Enable", 0, ini)) { + //if (GetConfigInt("Input", "Enable", 0)) { dlog("Applying input patch.", DL_INIT); SafeWriteStr(0x50FB70, "ddraw.dll"); AvailableGlobalScriptTypes |= 1; dlogr(" Done", DL_INIT); //} - if (GetPrivateProfileIntA("Misc", "DataLoadOrderPatch", 1, ini)) { + if (GetConfigInt("Misc", "DataLoadOrderPatch", 1)) { dlog("Applying data load order patch.", DL_INIT); MakeCall(0x444259, game_init_databases_hack1); MakeCall(0x4442F1, game_init_databases_hack2); @@ -703,21 +709,21 @@ static void DllMain2() { ObjectsInit(); mapName[64] = 0; - if (GetPrivateProfileString("Misc", "StartingMap", "", mapName, 64, ini)) { + if (GetConfigString("Misc", "StartingMap", "", mapName, 64)) { dlog("Applying starting map patch.", DL_INIT); SafeWrite32(0x480AAA, (DWORD)&mapName); dlogr(" Done", DL_INIT); } versionString[64] = 0; - if (GetPrivateProfileString("Misc", "VersionString", "", versionString, 64, ini)) { + if (GetConfigString("Misc", "VersionString", "", versionString, 64)) { dlog("Applying version string patch.", DL_INIT); SafeWrite32(0x4B4588, (DWORD)&versionString); dlogr(" Done", DL_INIT); } configName[64] = 0; - if (GetPrivateProfileString("Misc", "ConfigFile", "", configName, 64, ini)) { + if (GetConfigString("Misc", "ConfigFile", "", configName, 64)) { dlog("Applying config file patch.", DL_INIT); SafeWrite32(0x444BA5, (DWORD)&configName); SafeWrite32(0x444BCA, (DWORD)&configName); @@ -725,34 +731,34 @@ static void DllMain2() { } patchName[64] = 0; - if (GetPrivateProfileString("Misc", "PatchFile", "", patchName, 64, ini)) { + if (GetConfigString("Misc", "PatchFile", "", patchName, 64)) { dlog("Applying patch file patch.", DL_INIT); SafeWrite32(0x444323, (DWORD)&patchName); dlogr(" Done", DL_INIT); } startMaleModelName[64] = 0; - if (GetPrivateProfileString("Misc", "MaleStartModel", "", startMaleModelName, 64, ini)) { + if (GetConfigString("Misc", "MaleStartModel", "", startMaleModelName, 64)) { dlog("Applying male start model patch.", DL_INIT); SafeWrite32(0x418B88, (DWORD)&startMaleModelName); dlogr(" Done", DL_INIT); } startFemaleModelName[64] = 0; - if (GetPrivateProfileString("Misc", "FemaleStartModel", "", startFemaleModelName, 64, ini)) { + if (GetConfigString("Misc", "FemaleStartModel", "", startFemaleModelName, 64)) { dlog("Applying female start model patch.", DL_INIT); SafeWrite32(0x418BAB, (DWORD)&startFemaleModelName); dlogr(" Done", DL_INIT); } defaultMaleModelName[64] = 0; - GetPrivateProfileString("Misc", "MaleDefaultModel", "hmjmps", defaultMaleModelName, 64, ini); + GetConfigString("Misc", "MaleDefaultModel", "hmjmps", defaultMaleModelName, 64); dlog("Applying male model patch.", DL_INIT); SafeWrite32(0x418B50, (DWORD)&defaultMaleModelName); dlogr(" Done", DL_INIT); defaultFemaleModelName[64] = 0; - GetPrivateProfileString("Misc", "FemaleDefaultModel", "hfjmps", defaultFemaleModelName, 64, ini); + GetConfigString("Misc", "FemaleDefaultModel", "hfjmps", defaultFemaleModelName, 64); dlog("Applying female model patch.", DL_INIT); SafeWrite32(0x418B6D, (DWORD)&defaultFemaleModelName); dlogr(" Done", DL_INIT); @@ -760,7 +766,7 @@ static void DllMain2() { dlogr("Running WorldmapInit().", DL_INIT); WorldmapInit(); - if (GetPrivateProfileIntA("Misc", "DialogueFix", 1, ini)) { + if (GetConfigInt("Misc", "DialogueFix", 1)) { dlog("Applying dialogue patch.", DL_INIT); SafeWrite8(0x446848, 0x31); dlogr(" Done", DL_INIT); @@ -769,13 +775,13 @@ static void DllMain2() { dlogr("Running CriticalsInit().", DL_INIT); CriticalsInit(); - if (GetPrivateProfileIntA("Misc", "ExtraKillTypes", 0, ini)) { + if (GetConfigInt("Misc", "ExtraKillTypes", 0)) { dlog("Applying extra kill types patch.", DL_INIT); KillCounterInit(); dlogr(" Done", DL_INIT); } - //if (GetPrivateProfileIntA("Misc", "ScriptExtender", 0, ini)) { + //if (GetConfigInt("Misc", "ScriptExtender", 0)) { dlogr("Running StatsInit().", DL_INIT); StatsInit(); dlogr("Running ScriptExtenderSetup().", DL_INIT); @@ -796,7 +802,7 @@ static void DllMain2() { dlogr("Running DebugEditorInit().", DL_INIT); DebugEditorInit(); - if (GetPrivateProfileIntA("Misc", "SingleCore", 1, ini)) { + if (GetConfigInt("Misc", "SingleCore", 1)) { dlog("Applying single core patch.", DL_INIT); HANDLE process = GetCurrentProcess(); SetProcessAffinityMask(process, 1); @@ -804,22 +810,22 @@ static void DllMain2() { dlogr(" Done", DL_INIT); } - if (GetPrivateProfileIntA("Misc", "OverrideArtCacheSize", 0, ini)) { + if (GetConfigInt("Misc", "OverrideArtCacheSize", 0)) { dlog("Applying override art cache size patch.", DL_INIT); SafeWrite32(0x418867, 0x90909090); SafeWrite32(0x418872, 256); dlogr(" Done", DL_INIT); } - char elevPath[MAX_PATH - 3]; - GetPrivateProfileString("Misc", "ElevatorsFile", "", elevPath, MAX_PATH - 3, ini); - if (strlen(elevPath) > 0) { + std::string elevPath = GetConfigString("Misc", "ElevatorsFile", "", MAX_PATH); + if (!elevPath.empty()) { dlog("Applying elevator patch.", DL_INIT); - ElevatorsInit(elevPath); + ElevatorsInit(); + LoadElevators(elevPath.insert(0, ".\\").c_str()); dlogr(" Done", DL_INIT); } - if (GetPrivateProfileIntA("Misc", "AdditionalWeaponAnims", 0, ini)) { + if (GetConfigInt("Misc", "AdditionalWeaponAnims", 0)) { dlog("Applying additional weapon animations patch.", DL_INIT); SafeWrite8(0x419320, 0x12); HookCall(0x4194CC, WeaponAnimHook); @@ -828,34 +834,34 @@ static void DllMain2() { dlogr(" Done", DL_INIT); } - //if (GetPrivateProfileIntA("Misc", "MultiPatches", 0, ini)) { + //if (GetConfigInt("Misc", "MultiPatches", 0)) { dlog("Applying load multiple patches patch.", DL_INIT); SafeWrite8(0x444354, 0x90); // Change step from 2 to 1 SafeWrite8(0x44435C, 0xC4); // Disable check dlogr(" Done", DL_INIT); //} - if (GetPrivateProfileInt("Misc", "DisplayKarmaChanges", 0, ini)) { + if (GetConfigInt("Misc", "DisplayKarmaChanges", 0)) { dlog("Applying display karma changes patch.", DL_INIT); - GetPrivateProfileString("sfall", "KarmaGain", "You gained %d karma.", KarmaGainMsg, 128, translationIni); - GetPrivateProfileString("sfall", "KarmaLoss", "You lost %d karma.", KarmaLossMsg, 128, translationIni); + Translate("sfall", "KarmaGain", "You gained %d karma.", KarmaGainMsg); + Translate("sfall", "KarmaLoss", "You lost %d karma.", KarmaLossMsg); HookCall(0x455A6D, SetGlobalVarWrapper); dlogr(" Done", DL_INIT); } - if (GetPrivateProfileInt("Misc", "AlwaysReloadMsgs", 0, ini)) { + if (GetConfigInt("Misc", "AlwaysReloadMsgs", 0)) { dlog("Applying always reload messages patch.", DL_INIT); SafeWrite8(0x4A6B8D, 0x0); dlogr(" Done", DL_INIT); } - if (GetPrivateProfileInt("Misc", "PlayIdleAnimOnReload", 0, ini)) { + if (GetConfigInt("Misc", "PlayIdleAnimOnReload", 0)) { dlog("Applying idle anim on reload patch.", DL_INIT); HookCall(0x460B8C, ReloadHook); dlogr(" Done", DL_INIT); } - if (GetPrivateProfileInt("Misc", "CorpseLineOfFireFix", 1, ini)) { + if (GetConfigInt("Misc", "CorpseLineOfFireFix", 1)) { dlog("Applying corpse line of fire patch.", DL_INIT); MakeJump(0x48B994, CorpseHitFix2); MakeJump(0x48BA04, CorpseHitFix2b); @@ -863,19 +869,19 @@ static void DllMain2() { } dlog("Checking for changed skilldex images.", DL_INIT); - tmp = GetPrivateProfileIntA("Misc", "Lockpick", 293, ini); + tmp = GetConfigInt("Misc", "Lockpick", 293); if (tmp != 293) SafeWrite32(0x518D54, tmp); - tmp = GetPrivateProfileIntA("Misc", "Steal", 293, ini); + tmp = GetConfigInt("Misc", "Steal", 293); if (tmp != 293) SafeWrite32(0x518D58, tmp); - tmp = GetPrivateProfileIntA("Misc", "Traps", 293, ini); + tmp = GetConfigInt("Misc", "Traps", 293); if (tmp != 293) SafeWrite32(0x518D5C, tmp); - tmp = GetPrivateProfileIntA("Misc", "FirstAid", 293, ini); + tmp = GetConfigInt("Misc", "FirstAid", 293); if (tmp != 293) SafeWrite32(0x518D4C, tmp); - tmp = GetPrivateProfileIntA("Misc", "Doctor", 293, ini); + tmp = GetConfigInt("Misc", "Doctor", 293); if (tmp != 293) SafeWrite32(0x518D50, tmp); - tmp = GetPrivateProfileIntA("Misc", "Science", 293, ini); + tmp = GetConfigInt("Misc", "Science", 293); if (tmp != 293) SafeWrite32(0x518D60, tmp); - tmp = GetPrivateProfileIntA("Misc", "Repair", 293, ini); + tmp = GetConfigInt("Misc", "Repair", 293); if (tmp != 293) SafeWrite32(0x518D64, tmp); dlogr(" Done", DL_INIT); @@ -904,12 +910,12 @@ static void DllMain2() { dlogr("Running ConsoleInit().", DL_INIT); ConsoleInit(); - if (GetPrivateProfileIntA("Misc", "ExtraSaveSlots", 0, ini)) { + if (GetConfigInt("Misc", "ExtraSaveSlots", 0)) { dlogr("Running EnableSuperSaving().", DL_INIT); EnableSuperSaving(); } - switch (GetPrivateProfileIntA("Misc", "SpeedInterfaceCounterAnims", 0, ini)) { + switch (GetConfigInt("Misc", "SpeedInterfaceCounterAnims", 0)) { case 1: dlog("Applying SpeedInterfaceCounterAnims patch.", DL_INIT); MakeJump(0x460BA1, intface_rotate_numbers_hack); @@ -922,35 +928,24 @@ static void DllMain2() { break; } - KarmaFrmCount = GetPrivateProfileIntA("Misc", "KarmaFRMsCount", 0, ini); - if (KarmaFrmCount) { - KarmaFrms = new DWORD[KarmaFrmCount]; - KarmaPoints = new int[KarmaFrmCount - 1]; + std::vector karmaFrmList = GetConfigList("Misc", "KarmaFRMs", "", 512); + if (!karmaFrmList.empty()) { dlog("Applying karma FRM patch.", DL_INIT); - char buf[512]; - GetPrivateProfileStringA("Misc", "KarmaFRMs", "", buf, 512, ini); - char *ptr = buf, *ptr2; - for (DWORD i = 0; i < KarmaFrmCount - 1; i++) { - ptr2 = strchr(ptr, ','); - *ptr2 = '\0'; - KarmaFrms[i] = atoi(ptr); - ptr = ptr2 + 1; + + std::vector karmaPointsList = GetConfigList("Misc", "KarmaPoints", "", 512); + karmaFrms.resize(karmaFrmList.size()); + for (size_t i = 0; i < karmaFrmList.size(); i++) { + karmaFrms[i].frm = atoi(karmaFrmList[i].c_str()); + karmaFrms[i].points = (karmaPointsList.size() > i) + ? atoi(karmaPointsList[i].c_str()) + : INT_MAX; } - KarmaFrms[KarmaFrmCount - 1] = atoi(ptr); - GetPrivateProfileStringA("Misc", "KarmaPoints", "", buf, 512, ini); - ptr = buf; - for (DWORD i = 0; i < KarmaFrmCount - 2; i++) { - ptr2 = strchr(ptr, ','); - *ptr2 = '\0'; - KarmaPoints[i] = atoi(ptr); - ptr = ptr2 + 1; - } - KarmaPoints[KarmaFrmCount - 2] = atoi(ptr); HookCall(0x4367A9, DrawInfoWin_hook); + dlogr(" Done", DL_INIT); } - switch (GetPrivateProfileIntA("Misc", "ScienceOnCritters", 0, ini)) { + switch (GetConfigInt("Misc", "ScienceOnCritters", 0)) { case 1: HookCall(0x41276E, ScienceCritterCheckHook); break; @@ -959,7 +954,7 @@ static void DllMain2() { break; } - tmp = GetPrivateProfileIntA("Misc", "SpeedInventoryPCRotation", 166, ini); + tmp = GetConfigInt("Misc", "SpeedInventoryPCRotation", 166); if (tmp != 166 && tmp <= 1000) { dlog("Applying SpeedInventoryPCRotation patch.", DL_INIT); SafeWrite32(0x47066B, tmp); @@ -975,7 +970,7 @@ static void DllMain2() { dlogr("Running AnimationsAtOnceInit().", DL_INIT); AnimationsAtOnceInit(); - if (tmp = GetPrivateProfileIntA("Sound", "OverrideMusicDir", 0, ini)) { + if (tmp = GetConfigInt("Sound", "OverrideMusicDir", 0)) { SafeWrite32(0x4449C2, (DWORD)musicOverridePath); SafeWrite32(0x4449DB, (DWORD)musicOverridePath); if (tmp == 2) { @@ -984,7 +979,7 @@ static void DllMain2() { } } - if (GetPrivateProfileIntA("Misc", "BoostScriptDialogLimit", 0, ini)) { + if (GetConfigInt("Misc", "BoostScriptDialogLimit", 0)) { const int scriptDialogCount = 10000; dlog("Applying script dialog limit patch.", DL_INIT); scriptDialog = new int[scriptDialogCount * 2]; // Because the msg structure is 8 bytes, not 4. @@ -1000,7 +995,7 @@ static void DllMain2() { dlogr("Running InventoryInit().", DL_INIT); InventoryInit(); - if (tmp = GetPrivateProfileIntA("Misc", "MotionScannerFlags", 1, ini)) { + if (tmp = GetConfigInt("Misc", "MotionScannerFlags", 1)) { dlog("Applying MotionScannerFlags patch.", DL_INIT); if (tmp & 1) MakeJump(0x41BBE9, ScannerAutomapHook); if (tmp & 2) { @@ -1013,7 +1008,7 @@ static void DllMain2() { dlogr(" Done", DL_INIT); } - tmp = GetPrivateProfileIntA("Misc", "EncounterTableSize", 0, ini); + tmp = GetConfigInt("Misc", "EncounterTableSize", 0); if (tmp > 40 && tmp <= 127) { dlog("Applying EncounterTableSize patch.", DL_INIT); SafeWrite8(0x4BDB17, (BYTE)tmp); @@ -1024,7 +1019,7 @@ static void DllMain2() { dlogr(" Done", DL_INIT); } - if (GetPrivateProfileIntA("Misc", "DisablePipboyAlarm", 0, ini)) { + if (GetConfigInt("Misc", "DisablePipboyAlarm", 0)) { dlog("Applying Disable Pip-Boy alarm button patch.", DL_INIT); SafeWrite8(0x499518, 0xC3); SafeWrite8(0x443601, 0x0); @@ -1037,7 +1032,7 @@ static void DllMain2() { dlogr("Initializing party control.", DL_INIT); PartyControlInit(); - if (GetPrivateProfileIntA("Misc", "ObjCanSeeObj_ShootThru_Fix", 0, ini)) { + if (GetConfigInt("Misc", "ObjCanSeeObj_ShootThru_Fix", 0)) { dlog("Applying ObjCanSeeObj ShootThru Fix.", DL_INIT); HookCall(0x456BC6, op_obj_can_see_obj_hook); dlogr(" Done", DL_INIT); @@ -1057,21 +1052,21 @@ static void DllMain2() { addrs[0] = 0x499B99; addrs[1] = 0x499DA8; SimplePatch(addrs, 2, "Misc", "PipboyTimeAnimDelay", 50, 0, 127); - if (GetPrivateProfileIntA("Misc", "EnableMusicInDialogue", 0, ini)) { + if (GetConfigInt("Misc", "EnableMusicInDialogue", 0)) { dlog("Applying music in dialogue patch.", DL_INIT); SafeWrite8(0x44525B, 0x0); //BlockCall(0x450627); dlogr(" Done", DL_INIT); } - if (GetPrivateProfileIntA("Misc", "DontTurnOffSneakIfYouRun", 0, ini)) { + if (GetConfigInt("Misc", "DontTurnOffSneakIfYouRun", 0)) { dlog("Applying DontTurnOffSneakIfYouRun patch.", DL_INIT); SafeWrite8(0x418135, 0xEB); dlogr(" Done", DL_INIT); } - if (GetPrivateProfileIntA("Misc", "InstantWeaponEquip", 0, ini)) { - //Skip weapon equip/unequip animations + if (GetConfigInt("Misc", "InstantWeaponEquip", 0)) { + //Skip weapon equip/unequip animations dlog("Applying instant weapon equip patch.", DL_INIT); for (int i = 0; i < sizeof(PutAwayWeapon) / 4; i++) { SafeWrite8(PutAwayWeapon[i], 0xEB); // jmps @@ -1083,7 +1078,7 @@ static void DllMain2() { dlogr(" Done", DL_INIT); } - if (GetPrivateProfileIntA("Misc", "NumbersInDialogue", 0, ini)) { + if (GetConfigInt("Misc", "NumbersInDialogue", 0)) { dlog("Applying numbers in dialogue patch.", DL_INIT); SafeWrite32(0x502C32, 0x2000202E); SafeWrite8(0x446F3B, 0x35); @@ -1096,29 +1091,29 @@ static void DllMain2() { dlogr(" Done", DL_INIT); } - if (GetPrivateProfileIntA("Misc", "DisplaySecondWeaponRange", 1, ini)) { + if (GetConfigInt("Misc", "DisplaySecondWeaponRange", 1)) { dlog("Applying display second weapon range patch.", DL_INIT); HookCall(0x472201, display_stats_hook); dlogr(" Done", DL_INIT); } - if (GetPrivateProfileIntA("Misc", "InterfaceDontMoveOnTop", 0, ini)) { + if (GetConfigInt("Misc", "InterfaceDontMoveOnTop", 0)) { dlog("Applying InterfaceDontMoveOnTop patch.", DL_INIT); SafeWrite8(0x46ECE9, 0x10); // set only Exclusive flag for Player Inventory/Loot/UseOn SafeWrite8(0x41B966, 0x10); // set only Exclusive flag for Automap dlogr(" Done", DL_INIT); } - tmp = GetPrivateProfileIntA("Misc", "UseWalkDistance", 3, ini) + 2; - if (tmp > 1 && tmp < 5) { + int distance = GetConfigInt("Misc", "UseWalkDistance", 3) + 2; + if (distance > 1 && distance < 5) { dlog("Applying walk distance for using objects patch.", DL_INIT); for (int i = 0; i < sizeof(WalkDistanceAddr) / 4; i++) { - SafeWrite8(WalkDistanceAddr[i], (BYTE)tmp); // default is 5 + SafeWrite8(WalkDistanceAddr[i], static_cast(distance)); // default is 5 } dlogr(" Done", DL_INIT); } - int time = GetPrivateProfileIntA("Misc", "CorpseDeleteTime", 6, ini); // time in days + int time = GetConfigInt("Misc", "CorpseDeleteTime", 6); // time in days if (time != 6) { dlog("Applying corpse deletion time patch.", DL_INIT); if (time <= 0) { @@ -1135,7 +1130,7 @@ static void DllMain2() { SimplePatch(0x440C2A, "Misc", "SpecialDeathGVAR", 491); // GVAR_MODOC_SHITTY_DEATH // Remove hardcoding for maps with IDs 19 and 37 - if (GetPrivateProfileIntA("Misc", "DisableSpecialMapIDs", 0, ini)) { + if (GetConfigInt("Misc", "DisableSpecialMapIDs", 0)) { dlog("Applying disable special map IDs patch.", DL_INIT); SafeWrite8(0x4836D6, 0); SafeWrite8(0x4836DB, 0); @@ -1146,7 +1141,7 @@ static void DllMain2() { SafeWrite8(0x43ACD5, 144); // 136 SafeWrite8(0x43DD37, 144); // 133 - if (GetPrivateProfileIntA("Misc", "Fallout1Behavior", 0, ini)) { + if (GetConfigInt("Misc", "Fallout1Behavior", 0)) { dlog("Applying Fallout 1 engine behavior patch.", DL_INIT); BlockCall(0x4A4343); // disable playing the final movie/credits after the endgame slideshow SafeWrite8(0x477C71, 0xEB); // disable halving the weight for power armor items @@ -1160,10 +1155,6 @@ static void _stdcall OnExit() { if (scriptDialog != nullptr) { delete[] scriptDialog; } - if (KarmaFrmCount) { - delete[] KarmaFrms; - delete[] KarmaPoints; - } SpeedPatchExit(); ClearReadExtraGameMsgFiles(); ReputationsExit(); @@ -1328,8 +1319,8 @@ defaultIni: strcpy_s(ini, ddrawIniDef); } - GetPrivateProfileStringA("Main", "TranslationsINI", ".\\Translations.ini", translationIni, 65, ini); - modifiedIni = GetPrivateProfileIntA("Main", "ModifiedIni", 0, ini); + GetConfigString("Main", "TranslationsINI", ".\\Translations.ini", translationIni, 65); + modifiedIni = GetConfigInt("Main", "ModifiedIni", 0); hrpIsEnabled = (*(DWORD*)0x4E4480 != 0x278805C7); // check if HRP is enabled if (hrpIsEnabled) { diff --git a/sfall/main.h b/sfall/main.h index 39a20140..caf1ac96 100644 --- a/sfall/main.h +++ b/sfall/main.h @@ -103,7 +103,6 @@ size_t Translate(const char* section, const char* setting, const char* defaultVa DWORD HRPAddressOffset(DWORD offset); extern const char ddrawIniDef[]; -extern char ini[65]; extern DWORD modifiedIni; extern bool hrpIsEnabled; diff --git a/sfall/skills.cpp b/sfall/skills.cpp index 2c059dcb..a8fa0feb 100644 --- a/sfall/skills.cpp +++ b/sfall/skills.cpp @@ -346,11 +346,12 @@ void SkillsInit() { // 0x00000400 - Energy Weapon (forces weapon to use Energy Weapons skill) HookCall(0x47831E, item_w_skill_hook); - char buf[512], key[16], file[MAX_PATH]; - if (GetPrivateProfileStringA("Misc", "SkillsFile", "", buf, MAX_PATH - 3, ini) > 0) { + char buf[512], key[16]; + std::string skillsFile = GetConfigString("Misc", "SkillsFile", "", MAX_PATH); + if (!skillsFile.empty()) { SkillInfo *skills = (SkillInfo*)_skill_data; - sprintf(file, ".\\%s", buf); + const char* file = skillsFile.insert(0, ".\\").c_str(); multipliers = new double[7 * SKILL_count](); for (int i = 0; i < SKILL_count; i++) {