mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Fixed inconsistent behavior of escaped percent sign in sprintf/string_format
Minor code edits to LoadGameHook.cpp.
This commit is contained in:
@@ -122,7 +122,8 @@ void ClearLoopFlag(LoopFlag flag) {
|
||||
inLoop &= ~flag;
|
||||
}
|
||||
|
||||
static void __stdcall GameModeChange(DWORD state) { // OnGameModeChange
|
||||
static void __stdcall GameModeChange(DWORD state) {
|
||||
// OnGameModeChange
|
||||
Worldmap::OnGameModeChange();
|
||||
HookCommon::GameModeChangeHook(state);
|
||||
}
|
||||
@@ -330,13 +331,12 @@ static bool __stdcall GameReset(DWORD isGameLoad) {
|
||||
Console::OnGameReset();
|
||||
MetaruleExtender::OnGameReset();
|
||||
ScriptExtender::OnGameReset();
|
||||
inLoop = 0;
|
||||
gameLoaded = false;
|
||||
|
||||
if (isDebug) {
|
||||
char* str = (isGameLoad) ? "on Load" : "on Exit";
|
||||
fo::func::debug_printf("\nSFALL: [State reset %s]\n", str);
|
||||
}
|
||||
inLoop = 0;
|
||||
gameLoaded = false;
|
||||
|
||||
return (isGameLoad) ? LoadGame_Before() : false;
|
||||
}
|
||||
@@ -401,22 +401,25 @@ static __declspec(naked) void main_load_new_hook() {
|
||||
}
|
||||
}
|
||||
|
||||
static void __stdcall GameInitialization() { // OnBeforeGameInit
|
||||
static void __stdcall GameInitialization() {
|
||||
// OnBeforeGameInit
|
||||
BugFixes::OnBeforeGameInit();
|
||||
}
|
||||
|
||||
static void __stdcall game_init_hook() { // OnGameInit
|
||||
static void __stdcall game_init_hook() {
|
||||
// OnGameInit
|
||||
FallbackEnglishLoadMsgFiles();
|
||||
FallbackEnglishCredits();
|
||||
}
|
||||
|
||||
static void __stdcall GameInitialized(int initResult) { // OnAfterGameInit
|
||||
static void __stdcall GameInitialized(int initResult) {
|
||||
#ifdef NDEBUG
|
||||
if (!initResult) {
|
||||
MessageBoxA(0, "Game initialization failed!", 0, MB_TASKMODAL | MB_ICONERROR);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// OnAfterGameInit
|
||||
BugFixes::OnAfterGameInit();
|
||||
LoadOrder::OnAfterGameInit();
|
||||
BarBoxes::OnAfterGameInit();
|
||||
@@ -427,18 +430,21 @@ static void __stdcall GameInitialized(int initResult) { // OnAfterGameInit
|
||||
DebugEditor::OnAfterGameInit();
|
||||
}
|
||||
|
||||
static void __stdcall GameExit() { // OnGameExit
|
||||
static void __stdcall GameExit() {
|
||||
// OnGameExit
|
||||
if (femaleMsgs > 1) PlayerGenderCutsRestore();
|
||||
}
|
||||
|
||||
static void __stdcall GameClose() { // OnBeforeGameClose
|
||||
static void __stdcall GameClose() {
|
||||
// OnBeforeGameClose
|
||||
ConsoleWindow::OnBeforeGameClose();
|
||||
Graphics::OnBeforeGameClose();
|
||||
ClearReadExtraGameMsgFiles();
|
||||
Sound::OnBeforeGameClose();
|
||||
}
|
||||
|
||||
static void __stdcall MapLoadHook() { // OnBeforeMapLoad
|
||||
static void __stdcall MapLoadHook() {
|
||||
// OnBeforeMapLoad
|
||||
ObjectName::OnBeforeMapLoad();
|
||||
}
|
||||
|
||||
|
||||
@@ -248,10 +248,14 @@ static const char* sprintf_lite(OpcodeContext& ctx, const char* opcodeName) {
|
||||
if (!conversion) {
|
||||
// Start conversion.
|
||||
if (c == '%') conversion = true;
|
||||
} else {
|
||||
} else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '%') {
|
||||
int partLen;
|
||||
if (c == '%') {
|
||||
conversion = false; // escaped % sign, just skip
|
||||
} else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
|
||||
// escaped % sign, just copy newFmt up to (and including) the leading % sign
|
||||
newFmt[j] = '\0';
|
||||
strncpy_s(outBuf, bufCount, newFmt, j);
|
||||
partLen = j;
|
||||
} else {
|
||||
// ignore size prefixes
|
||||
if (c == 'h' || c == 'l' || c == 'j' || c == 'z' || c == 't' || c == 'w' || c == 'L' || c == 'I') continue;
|
||||
// Type specifier, perform conversion.
|
||||
@@ -269,18 +273,18 @@ static const char* sprintf_lite(OpcodeContext& ctx, const char* opcodeName) {
|
||||
}
|
||||
newFmt[j++] = c;
|
||||
newFmt[j] = '\0';
|
||||
int partLen = arg.isFloat()
|
||||
? _snprintf(outBuf, bufCount, newFmt, arg.floatValue())
|
||||
: _snprintf(outBuf, bufCount, newFmt, arg.rawValue());
|
||||
outBuf += partLen;
|
||||
bufCount -= partLen;
|
||||
conversion = false;
|
||||
j = 0;
|
||||
if (bufCount <= 0) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
partLen = arg.isFloat()
|
||||
? _snprintf(outBuf, bufCount, newFmt, arg.floatValue())
|
||||
: _snprintf(outBuf, bufCount, newFmt, arg.rawValue());
|
||||
}
|
||||
outBuf += partLen;
|
||||
bufCount -= partLen;
|
||||
conversion = false;
|
||||
j = 0;
|
||||
if (bufCount <= 0) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
newFmt[j++] = c;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user