diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index 7f205b29..5d521e3d 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -274,7 +274,6 @@ #define create_win(winName, x, y, w, h) sfall_func5("create_win", winName, x, y, w, h) #define create_win_flag(winName, x, y, w, h, flag) sfall_func6("create_win", winName, x, y, w, h, flag) #define critter_inven_obj2(obj, type) sfall_func2("critter_inven_obj2", obj, type) -#define dialog_box(text) sfall_func1("dialog_box", text) #define dialog_message(text) sfall_func1("dialog_message", text) #define dialog_obj sfall_func0("dialog_obj") #define display_stats sfall_func0("display_stats") @@ -312,6 +311,7 @@ #define item_weight(obj) sfall_func1("item_weight", obj) #define lock_is_jammed(obj) sfall_func1("lock_is_jammed", obj) #define loot_obj sfall_func0("loot_obj") +#define message_box(text) sfall_func1("message_box", text) #define metarule_exist(metaruleName) sfall_func1("metarule_exist", metaruleName) #define npc_engine_level_up(toggle) sfall_func1("npc_engine_level_up", toggle) #define obj_under_cursor(onlyCritter, includeDude) sfall_func2("obj_under_cursor", onlyCritter, includeDude) diff --git a/artifacts/scripting/sfall function notes.txt b/artifacts/scripting/sfall function notes.txt index ff1aa05d..04377ec6 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -717,12 +717,13 @@ optional argument: - sets a floating text for a town on the world map when hovering the cursor over the player's marker - areaID: the ID number of the town from city.txt -> int sfall_func1("dialog_box", string text1) -> int sfall_func2("dialog_box", string text1, string text2) -> int sfall_func3("dialog_box", string text1, string text2, string text3) -- creates a dialog box with text and returns the result of pressing the button: 0 - No, 1 - Yes -- text1/text2/text3: corresponding text in the dialog box for the first, second, and third lines +> int sfall_func4("message_box", string message, int flags, int color1, int color2) +- creates a dialog box with text and returns the result of pressing the button: 0 - No, 1 - Yes/Done - returns -1 if for some reason the dialog box cannot be created +- message: the text in the dialog box. Use the \n control character to move text to a new line (example: "Hello\nWorld!") +optional arguments: +- flags: mode flags (see DIALOGOUT_* constants in define_extra.h). Pass -1 to skip setting the flags (default flags are DIALOGOUT_NORMAL|DIALOGOUT_YESNO) +- color1/2: the color index in Fallout palette. color1 sets the text color for the first line, and color2 for all subsequent lines of text (default color is 145) ------------------------ ------ MORE INFO ------- diff --git a/sfall/FalloutEngine/Functions.cpp b/sfall/FalloutEngine/Functions.cpp index 401443f7..7cb510cc 100644 --- a/sfall/FalloutEngine/Functions.cpp +++ b/sfall/FalloutEngine/Functions.cpp @@ -402,35 +402,37 @@ long __stdcall win_register_button(DWORD winRef, long xPos, long yPos, long widt } } -void __stdcall DialogOut(const char* text) { +void __fastcall DialogOut(const char* text, const char** textEx, long lines) { __asm { push 1; // DIALOGOUT_NORMAL flag xor eax, eax; - push eax; // ColorMsg - push eax; // DisplayMsg (unknown) mov al, byte ptr ds:[0x6AB718]; + push eax; // ColorMsg + push 0; // DisplayMsg (unknown) push eax; // ColorIndex + mov eax, ecx; // DisplayText push 116; // y mov ecx, 192; // x - mov eax, text; // DisplayText - xor ebx, ebx; - xor edx, edx; + mov ebx, lines; // count text lines 0-5 call fo::funcoffs::dialog_out_; } } -long __fastcall DialogOutEx(const char* text, const char** textEx, long count, long flags) { +long __fastcall DialogOutEx(const char* text, const char** textEx, long lines, long flags, long colors) { __asm { - mov eax, 145; // Color index + xor eax, eax; + mov ebx, colors;// Color index + mov al, bh; push flags; // flag + and ebx, 0xFF push eax; // ColorMsg2 push 0; // DisplayMsg (unknown) - push eax; // ColorMsg1 mov eax, ecx; // DisplayText first line - push 116; // y + push ebx; // ColorMsg1 mov ecx, 192; // x - mov ebx, count; // count text lines 0-2 - call fo::funcoffs::dialog_out_; // edx - DisplayText second/third line + push 116; // y + mov ebx, lines; // count text lines 0-5 + call fo::funcoffs::dialog_out_; // edx - DisplayText second and later lines } } diff --git a/sfall/FalloutEngine/Functions.h b/sfall/FalloutEngine/Functions.h index 3b432f86..070dc15a 100644 --- a/sfall/FalloutEngine/Functions.h +++ b/sfall/FalloutEngine/Functions.h @@ -206,9 +206,9 @@ long __stdcall stat_level(GameObject* critter, long statId); // pictureUp/pictureDown - pointers to a surface long __stdcall win_register_button(DWORD winRef, long xPos, long yPos, long width, long height, long hoverOn, long hoverOff, long buttonDown, long buttonUp, BYTE* pictureUp, BYTE* pictureDown, long arg12, long buttonType); -void __stdcall DialogOut(const char* text); +void __fastcall DialogOut(const char* text, const char** textEx, long lines); -long __fastcall DialogOutEx(const char* text, const char** textEx, long count, long flags); +long __fastcall DialogOutEx(const char* text, const char** textEx, long lines, long flags, long colors); // draws an image to the buffer without scaling and with transparency display toggle void __fastcall windowDisplayBuf(long x, long width, long y, long height, void* data, long noTrans); diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 1e22e5a4..e5139cfe 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -2487,6 +2487,14 @@ endLoop: } } +static void __declspec(naked) main_death_scene_hook() { + __asm { + mov eax, 100; + call fo::funcoffs::block_for_tocks_; + jmp fo::funcoffs::get_time_; + } +} + void BugFixes::init() { #ifndef NDEBUG @@ -3134,6 +3142,9 @@ void BugFixes::init() // Fix for party member's equipped weapon being placed in the incorrect item slot after leveling up MakeCall(0x495FD9, partyMemberCopyLevelInfo_hack, 1); + + // Fix the playback of the speech sound file for the death screen + HookCall(0x481409, main_death_scene_hook); } } diff --git a/sfall/Modules/Scripting/Handlers/Interface.cpp b/sfall/Modules/Scripting/Handlers/Interface.cpp index 855a8f4d..1f41c868 100644 --- a/sfall/Modules/Scripting/Handlers/Interface.cpp +++ b/sfall/Modules/Scripting/Handlers/Interface.cpp @@ -127,6 +127,20 @@ void __declspec(naked) op_resume_game() { } } +// copy and split +static void SplitToBuffer(const char* str, const char** str_ptr, long &lines) { + size_t i = 0; + do { + if (str[i] == '\n' && lines < 4) { + ScriptExtender::gTextBuffer[i] = '\0'; + str_ptr[lines++] = &ScriptExtender::gTextBuffer[++i]; + } else { + ScriptExtender::gTextBuffer[i] = str[i++]; + } + } while (str[i]); + ScriptExtender::gTextBuffer[i] = '\0'; +} + void sf_create_message_window(OpcodeContext &ctx) { static bool dialogShow = false; if (dialogShow) return; @@ -134,28 +148,37 @@ void sf_create_message_window(OpcodeContext &ctx) { const char* str = ctx.arg(0).strValue(); if (!str || str[0] == 0) return; + long lines = 0; + const char* str_ptr[4]; + SplitToBuffer(str, str_ptr, lines); + dialogShow = true; - fo::func::DialogOut(str); + fo::func::DialogOut(ScriptExtender::gTextBuffer, str_ptr, lines); dialogShow = false; } -void sf_dialog_box(OpcodeContext &ctx) { - const char* str = ctx.arg(0).strValue(); - if (!str || str[0] == 0) return; +void sf_message_box(OpcodeContext &ctx) { + static u_short dialogShowCount = 0; - const char* str2[2]; long lines = 0; - if (ctx.numArgs() > 1) { - ++lines; - str2[0] = ctx.arg(1).strValue(); - } + const char* str_ptr[4]; + SplitToBuffer(ctx.arg(0).asString(), str_ptr, lines); + + long colors = 0x9191, flags = fo::DIALOGOUT_NORMAL | fo::DIALOGOUT_YESNO; + if (ctx.numArgs() > 1 && ctx.arg(1).rawValue() != -1) flags = ctx.arg(1).rawValue(); if (ctx.numArgs() > 2) { - ++lines; - str2[1] = ctx.arg(2).strValue(); + colors &= 0xFF00; + colors |= (ctx.arg(2).rawValue() & 0xFF); } + if (ctx.numArgs() > 3) { + colors &= 0xFF; + colors |= (ctx.arg(3).rawValue() & 0xFF) << 8; + } + dialogShowCount++; *(DWORD*)FO_VAR_script_engine_running = 0; - long result = fo::func::DialogOutEx(str, str2, lines, fo::DIALOGOUT_NORMAL | fo::DIALOGOUT_YESNO); - *(DWORD*)FO_VAR_script_engine_running = 1; + long result = fo::func::DialogOutEx(ScriptExtender::gTextBuffer, str_ptr, lines, flags, colors); + if (--dialogShowCount == 0) *(DWORD*)FO_VAR_script_engine_running = 1; + ctx.setReturn(result); } diff --git a/sfall/Modules/Scripting/Handlers/Interface.h b/sfall/Modules/Scripting/Handlers/Interface.h index c2f86798..cbca21c3 100644 --- a/sfall/Modules/Scripting/Handlers/Interface.h +++ b/sfall/Modules/Scripting/Handlers/Interface.h @@ -59,7 +59,7 @@ void __declspec() op_resume_game(); //Create a message window with given string void sf_create_message_window(OpcodeContext&); -void sf_dialog_box(OpcodeContext&); +void sf_message_box(OpcodeContext&); void __declspec() op_get_viewport_x(); diff --git a/sfall/Modules/Scripting/Handlers/Metarule.cpp b/sfall/Modules/Scripting/Handlers/Metarule.cpp index 0efc6851..983c6573 100644 --- a/sfall/Modules/Scripting/Handlers/Metarule.cpp +++ b/sfall/Modules/Scripting/Handlers/Metarule.cpp @@ -70,7 +70,6 @@ static const SfallMetarule metarules[] = { {"car_gas_amount", sf_car_gas_amount, 0, 0}, {"create_win", sf_create_win, 5, 6, -1, {ARG_STRING, ARG_INT, ARG_INT, ARG_INT, ARG_INT, ARG_INT}}, {"critter_inven_obj2", sf_critter_inven_obj2, 2, 2, 0, {ARG_OBJECT, ARG_INT}}, - {"dialog_box", sf_dialog_box, 1, 3, -1, {ARG_STRING, ARG_STRING, ARG_STRING}}, {"dialog_message", sf_dialog_message, 1, 1, -1, {ARG_STRING}}, {"dialog_obj", sf_get_dialog_object, 0, 0}, {"display_stats", sf_display_stats, 0, 0}, // refresh @@ -93,7 +92,7 @@ static const SfallMetarule metarules[] = { {"get_sfall_arg_at", sf_get_sfall_arg_at, 1, 1, 0, {ARG_INT}}, {"get_string_pointer", sf_get_string_pointer, 1, 1, 0, {ARG_STRING}}, {"get_text_width", sf_get_text_width, 1, 1, 0, {ARG_STRING}}, - {"get_window_attribute", sf_get_window_attribute, 1, 2, 0, {ARG_INT, ARG_INT}}, + {"get_window_attribute", sf_get_window_attribute, 1, 2, -1, {ARG_INT, ARG_INT}}, {"has_fake_perk_npc", sf_has_fake_perk_npc, 2, 2, 0, {ARG_OBJECT, ARG_STRING}}, {"has_fake_trait_npc", sf_has_fake_trait_npc, 2, 2, 0, {ARG_OBJECT, ARG_STRING}}, {"hide_window", sf_hide_window, 0, 1, -1, {ARG_STRING}}, @@ -106,6 +105,7 @@ static const SfallMetarule metarules[] = { {"item_weight", sf_item_weight, 1, 1, 0, {ARG_OBJECT}}, {"lock_is_jammed", sf_lock_is_jammed, 1, 1, 0, {ARG_OBJECT}}, {"loot_obj", sf_get_loot_object, 0, 0}, + {"message_box", sf_message_box, 1, 4, -1, {ARG_STRING, ARG_INT, ARG_INT, ARG_INT}}, {"metarule_exist", sf_metarule_exist, 1, 1}, // no arg check {"npc_engine_level_up", sf_npc_engine_level_up, 1, 1}, {"obj_under_cursor", sf_obj_under_cursor, 2, 2, 0, {ARG_INT, ARG_INT}},