Correction to the previous commit

* shouldn't modify the string in-place.
This commit is contained in:
NovaRain
2025-04-13 16:39:09 +08:00
parent 3b9348dd69
commit d16f1bc60c
2 changed files with 32 additions and 31 deletions
-31
View File
@@ -185,35 +185,6 @@ static __declspec(naked) void display_print_line_break_extHRP() {
}
}
static void __fastcall ObjDescStripNewlines(char* desc) {
size_t i = 0, j = 0;
while (desc[i]) {
if (desc[i] == '\\' && desc[i + 1] == 'n') {
desc[j++] = ' ';
i += 2;
} else {
desc[j++] = desc[i++];
}
}
desc[j] = '\0'; // null-terminate the modified string
}
static __declspec(naked) void obj_examine_func_hack() {
__asm {
cmp dword ptr [esp + 0x1AC - 0x14 + 4], 0x445448; // gdialogDisplayMsg_
jne skip;
push eax;
push ecx;
mov ecx, eax;
call ObjDescStripNewlines;
pop ecx;
pop eax;
skip:
mov edx, ds:[FO_VAR_proto_none_str]; // overwritten engine code
retn;
}
}
void Text::init() {
void* printFunc = display_print_line_break; // for vanilla and HRP 4.1.8
@@ -228,8 +199,6 @@ void Text::init() {
// Support for the newline control character '\n' in the object description in pro_*.msg files
sf::SafeWriteBatch<DWORD>((DWORD)printFunc, {0x46ED87, 0x49AD7A}); // setup_inventory_, obj_examine_
sf::SafeWrite32(0x472F9A, (DWORD)&inven_display_msg_line_break); // inven_obj_examine_func_
// Remove visible newline control characters when examining items in the barter screen
sf::MakeCall(0x49AE33, obj_examine_func_hack, 1);
}
}
+32
View File
@@ -1825,6 +1825,35 @@ skip:
}
}
static void __fastcall StripNewlines(char* desc) {
size_t i = 0, j = 0;
while (desc[i] && j < sizeof(messageBuffer) - 1) {
if (desc[i] == '\\' && desc[i + 1] == 'n') {
messageBuffer[j++] = ' ';
i += 2;
} else {
messageBuffer[j++] = desc[i++];
}
}
messageBuffer[j] = '\0'; // null-terminate the modified string
}
static __declspec(naked) void obj_examine_func_hack_objdesc() {
__asm {
cmp dword ptr [esp + 0x1AC - 0x14 + 4], 0x445448; // gdialogDisplayMsg_
jne skip;
push ecx;
mov ecx, eax;
call StripNewlines;
pop ecx;
lea eax, messageBuffer;
mov esi, eax;
skip:
mov edx, ds:[FO_VAR_proto_none_str]; // overwritten engine code
retn;
}
}
static DWORD expSwiftLearner; // experience points for print
static __declspec(naked) void statPCAddExperienceCheckPMs_hack() {
@@ -3928,6 +3957,9 @@ void BugFixes::init() {
dlogr("Applying full item description in barter patch.", DL_FIX);
HookCall(0x49B452, obj_examine_func_hack_weapon); // it's jump
}
// Remove visible newline control characters when examining items in the barter screen
// Supplementary fix for hacks in Game\GUI\Text.cpp
MakeCall(0x49AE33, obj_examine_func_hack_objdesc, 1);
// Display experience points with the bonus from Swift Learner perk when gained from non-scripted situations
//if (IniReader::GetConfigInt("Misc", "DisplaySwiftLearnerExp", 1)) {