Code edits to ExtraSaveSlots.cpp

* the page numbering is now 0-indexed, to better align with the macros.

Re-numbered save slot control metarules.
This commit is contained in:
NovaRain
2021-08-13 10:58:55 +08:00
parent cc29d548fe
commit 6b34303268
4 changed files with 50 additions and 42 deletions
+6 -5
View File
@@ -118,7 +118,7 @@ OverrideMusicDir=1
;Set to 1 to automatically search for new SFX sound files at game startup
;Note: With this option enabled, you will no longer need to use the utility regsnd.exe to register new SFX sounds
;This will slightly increase the startup time of the game
;This will slightly increase the startup time of the game on older computers
AutoSearchSFX=1
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
@@ -225,7 +225,7 @@ DebugEditorKey=0
Fallout1Behavior=0
;Time limit in years. Must be between -3 and 13
;Set to 0 if you want to die the instant you leave arroyo
;Set to 0 if you want to die the instant you leave Arroyo
;Set to -1 to remove the time limit, and automatically reset the date back to 2241 each time you would have reached it
;Set to -2 or -3 to remove the time limit, automatically reset the date, but override Fallout's GetDate function to return the correct year
TimeLimit=13
@@ -494,11 +494,12 @@ UseScrollingQuestsList=1
ExtraSaveSlots=0
;To use more than one save slot for quick saving (F6 key) without picking a slot beforehand, set the next two lines
;Quick save will cyclically overwrite saves from the first slot on the specified page to the last slot on the n-th page
;AutoQuickSave sets how many pages you want to use for quick saving (valid range: 1..10)
;AutoQuickSavePage is the page number to start at (valid range: 1..1000, if ExtraSaveSlots is enabled)
;The quick saves will be rotated from the first slot on the page to the last slot on the n-th page
;Set to 0 to disable. AutoQuickSave will use the current selected page if AutoQuickSavePage is disabled
;Set to 0 to disable
AutoQuickSave=0
;AutoQuickSavePage is the page number to start at if ExtraSaveSlots is enabled (valid range: 0..999)
;Set to -1 to use the current selected page (not recommended)
AutoQuickSavePage=1
;Set to 1 to speed up the HP/AC counter animations
+6 -6
View File
@@ -367,11 +367,11 @@
#define clear_keyboard_buffer metarule3(201, 0, 0, 0)
// functions to control the save slot
// Note: page and slot here are 0-indexed instead of 1-indexed displayed in game
#define get_current_save_slot metarule3(1000, 0, 0, 0) // returns the amount: page + slot
#define set_current_save_slot(page, slot) metarule3(1001, page, slot, 0)
#define get_current_quick_save_page metarule3(1002, 0, 0, 0)
#define get_current_quick_save_slot metarule3(1003, 0, 0, 0)
#define set_current_quick_save_slot(page, slot, check) metarule3(1004, page, slot, check) // check: 1 - don't check slot when saving
// Note: slot value here is 0-indexed instead of 1-indexed displayed in game and used for folder names
#define get_current_save_slot metarule3(210, 0, 0, 0) // returns the amount: page + slot
#define set_current_save_slot(page, slot) metarule3(211, page, slot, 0)
#define get_current_quick_save_page metarule3(212, 0, 0, 0)
#define get_current_quick_save_slot metarule3(213, 0, 0, 0)
#define set_current_quick_save_slot(page, slot, check) metarule3(214, page, slot, check) // check: 1 - don't check slot when saving
#endif
+32 -24
View File
@@ -34,7 +34,7 @@ long ExtraSaveSlots_GetSaveSlot() {
}
void ExtraSaveSlots_SetSaveSlot(long page, long slot) {
if (ExtraSaveSlots_GetQuickSavePage() >= 0 && page >= 0 && page <= 9990) LSPageOffset = page - (page % 10);;
if (page >= 0 && page <= 9990) LSPageOffset = page - (page % 10);
if (slot >= 0 && slot < 10) *ptr_slot_cursor = slot;
}
@@ -53,6 +53,7 @@ static long save_page_offsets() {
return *ptr_lsgwin; // restore original code
}
// load last slot position values from file
static void LoadPageOffsets() {
char LoadPath[MAX_PATH];
@@ -70,7 +71,6 @@ static void LoadPageOffsets() {
static void __declspec(naked) load_page_offsets(void) {
__asm {
// load last slot position values from file
call LoadPageOffsets;
mov edx, 0x50A480; // ASCII "SAV" (restore original code)
retn;
@@ -107,13 +107,13 @@ static void SetPageNum() {
BYTE ConsoleGold = *ptr_YellowColor; // palette offset stored in mem - text colour
char tempText[32];
unsigned int TxtMaxWidth = GetMaxCharWidth() * 8; // GetTextWidth(tempText);
unsigned int TxtMaxWidth = GetMaxCharWidth() * 6; // GetTextWidth(tempText);
unsigned int HalfMaxWidth = TxtMaxWidth / 2;
unsigned int TxtWidth = 0;
DWORD NewTick = 0, OldTick = 0;
int button = 0, exitFlag = 0, numpos = 0;
char Number[5], blip = '_';
char Number[4], blip = '_';
DWORD tempPageOffset = -1;
@@ -133,14 +133,14 @@ static void SetPageNum() {
if (tempPageOffset == -1) {
sprintf_s(tempText, 32, "[ %c ]", '_');
} else {
sprintf_s(tempText, 32, "[ %d%c ]", tempPageOffset / 10 + 1, '_');
sprintf_s(tempText, 32, "[ %d%c ]", tempPageOffset / 10, '_');
}
TxtWidth = GetTextWidth(tempText);
if (tempPageOffset == -1) {
sprintf_s(tempText, 32, "[ %c", blip);
} else {
sprintf_s(tempText, 32, "[ %d%c", tempPageOffset / 10 + 1, blip);
sprintf_s(tempText, 32, "[ %d%c", tempPageOffset / 10, blip);
}
int z = 0;
@@ -158,15 +158,15 @@ static void SetPageNum() {
button = fo_get_input();
if (button >= '0' && button <= '9') {
if (numpos < 4) {
if (numpos < 3) {
Number[numpos] = button;
Number[numpos + 1] = '\0';
numpos++;
if (Number[0] == '0') {
numpos = 0;
tempPageOffset = -1;
tempPageOffset = 0;
} else {
tempPageOffset = (atoi(Number) - 1) * 10;
tempPageOffset = (atoi(Number)) * 10;
}
}
//else exitFlag=-1;
@@ -176,7 +176,7 @@ static void SetPageNum() {
if (!numpos) {
tempPageOffset = -1;
} else {
tempPageOffset = (atoi(Number) - 1) * 10;
tempPageOffset = (atoi(Number)) * 10;
}
} else if (button == 0x0D || button == 0x20 || button == 'p' || button == 'P') {
exitFlag = -1; // Enter, Space or P Keys
@@ -273,7 +273,7 @@ static void DrawPageText() {
BYTE Colour = ConsoleGreen;
char tempText[32];
sprintf_s(tempText, 32, "[ %d ]", LSPageOffset / 10 + 1);
sprintf_s(tempText, 32, "[ %d ]", LSPageOffset / 10);
unsigned int TxtWidth = GetTextWidth(tempText);
PrintText(tempText, Colour, 170 - TxtWidth / 2, 64, TxtWidth, SaveLoadWin->width, SaveLoadWin->surface);
@@ -432,7 +432,7 @@ static bool qFirst = true;
static FILETIME ftPrevSlot;
static DWORD __stdcall QuickSaveGame(DbFile* file, char* filename) {
long currSlot = *ptr_slot_cursor;
long currSlot = quickSaveSlot;
if (dontCheckSlot) {
if (file) fo_db_fclose(file);
@@ -456,9 +456,9 @@ static DWORD __stdcall QuickSaveGame(DbFile* file, char* filename) {
return 0x47B929; // check next slot
}
currSlot = 0; // set if currSlot >= 9
}
}
qFirst = false;
}
}
// next save slot
if (++quickSaveSlot >= 10) {
quickSaveSlot = 0;
@@ -497,10 +497,17 @@ static void __declspec(naked) SaveGame_hack0() {
static void __declspec(naked) SaveGame_hack1() {
__asm {
mov eax, quickSavePage;
test eax, eax;
js skip;
mov LSPageOffset, eax;
mov eax, quickSaveSlot;
mov ds:[FO_VAR_slot_cursor], eax;
mov eax, quickSavePage;
mov LSPageOffset, eax;
retn;
skip: // if AutoQuickSavePage is disabled (set to less than 0)
xor eax, eax;
mov quickSaveSlot, eax;
mov ds:[FO_VAR_slot_cursor], eax;
retn;
}
}
@@ -514,7 +521,11 @@ long ExtraSaveSlots_GetQuickSaveSlot() {
}
void ExtraSaveSlots_SetQuickSaveSlot(long page, long slot, long check) {
if (quickSavePage >= 0 && page >= 0 && page <= 9990) quickSavePage = page - (page % 10);
if (page < 0) {
quickSavePage = -1;
} else if (page <= 9990) {
quickSavePage = page - (page % 10);
}
if (slot >= 0 && slot < 10) quickSaveSlot = slot;
dontCheckSlot = check;
}
@@ -533,17 +544,14 @@ void ExtraSaveSlots_Init() {
if (quickSavePageCount > 10) quickSavePageCount = 10;
quickSavePage = GetConfigInt("Misc", "AutoQuickSavePage", 1);
if (quickSavePage > 1000) quickSavePage = 1000;
if (quickSavePage > 999) quickSavePage = 999;
if (extraSaveSlots && quickSavePage > 0) {
quickSavePage = (quickSavePage - 1) * 10;
if (extraSaveSlots && quickSavePage >= 0) {
quickSavePage *= 10;
quickSavePageInit = quickSavePage;
MakeCall(0x47B923, SaveGame_hack1, 1);
} else { // for quickSavePage == 0
SafeWrite8(0x47B923, 0x89);
SafeWrite32(0x47B924, 0x5193B83D); // mov [slot_cursor], edi = 0
}
MakeJump(0x47B984, SaveGame_hack0);
MakeCall(0x47B923, SaveGame_hack1, 1);
dlogr(" Done", DL_INIT);
}
}
+5 -6
View File
@@ -31,12 +31,11 @@ enum MetaruleFunction : long {
SET_HORRIGAN_ENCOUNTER = 200, // sets the number of days for the Frank Horrigan encounter or disable encounter
CLEAR_KEYBOARD_BUFFER = 201, // clears the keyboard input buffer, should be used in the HOOK_KEYPRESS hook to clear keyboard events in some cases
// for save slots
GET_CURRENT_SAVE_SLOT = 1000,
SET_CURRENT_SAVE_SLOT = 1001,
GET_CURRENT_QSAVE_PAGE = 1002,
GET_CURRENT_QSAVE_SLOT = 1003,
SET_CURRENT_QSAVE_SLOT = 1004,
GET_CURRENT_SAVE_SLOT = 210,
SET_CURRENT_SAVE_SLOT = 211,
GET_CURRENT_QSAVE_PAGE = 212,
GET_CURRENT_QSAVE_SLOT = 213,
SET_CURRENT_QSAVE_SLOT = 214,
};
/*