diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b0869cb..572d95cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ - new opcode **2606 ([load_fxt](https://library.sannybuilder.com/#/sa/text/2606))** - new opcode **2607 ([unload_fxt](https://library.sannybuilder.com/#/sa/text/2607))** - new opcode **2608 ([get_text_length](https://library.sannybuilder.com/#/sa/text/2608))** + - new opcode **2609 ([add_text_label_formatted](https://library.sannybuilder.com/#/sa/text/2609))** - new and updated opcodes - implemented support for **memory pointer string** arguments for all game's native opcodes - **0B1E ([sign_extend](https://library.sannybuilder.com/#/sa/bitwise/0B1E))** diff --git a/cleo_plugins/Text/Text.cpp b/cleo_plugins/Text/Text.cpp index bc006da0..13a3b289 100644 --- a/cleo_plugins/Text/Text.cpp +++ b/cleo_plugins/Text/Text.cpp @@ -66,6 +66,7 @@ class Text CLEO_RegisterOpcode(0x2606, opcode_2606); // load_fxt CLEO_RegisterOpcode(0x2607, opcode_2607); // unload_fxt CLEO_RegisterOpcode(0x2608, opcode_2608); // get_text_length + CLEO_RegisterOpcode(0x2609, opcode_2609); // add_text_label_formatted // register event callbacks CLEO_RegisterCallback(eCallbackId::GameBegin, OnGameBegin); @@ -522,6 +523,17 @@ class Text OPCODE_WRITE_PARAM_INT(result); return OR_CONTINUE; } + + //2609=-1,add_text_label_formatted %1d% args %2d% + static OpcodeResult __stdcall opcode_2609(CLEO::CRunningScript* thread) + { + OPCODE_READ_PARAM_STRING_LEN(gxt, 7); // GXT labels can be max 7 character long + OPCODE_READ_PARAM_STRING_FORMATTED(str); + + textManager.AddFxt(gxt, str); + + return OR_CONTINUE; + } } textInstance; CTextManager Text::textManager; diff --git a/tests/cleo_tests/Text/2609.txt b/tests/cleo_tests/Text/2609.txt new file mode 100644 index 00000000..ce8936ab --- /dev/null +++ b/tests/cleo_tests/Text/2609.txt @@ -0,0 +1,23 @@ +{$CLEO .s} +{$INCLUDE_ONCE ../cleo_tester.inc} + +script_name '2609' +test("2609 (add_text_label_formatted)", tests) +terminate_this_custom_script + +function tests + it("should add dynamic GXT", test1) + return + + function test1 + // gxt entry not present yet + 0@v = get_text_label_string {key} 'CLE2609' + assert_eqs(0@v, "") + + add_text_label_formatted {dynamicKey} 'CLE2609' {format} "cleo %s %d" {args} "test" 42 + 0@v = get_text_label_string {key} 'CLE2609' + assert_eqs(0@v, "cleo test 42") + + remove_text_label {key} 'CLE2609' // cleanup + end +end