Skip to content

Commit

Permalink
New opcode display_text_formatted (#115)
Browse files Browse the repository at this point in the history
* New opcode display_text_formated

* Changelog updated.

* Solution fixes.
  • Loading branch information
MiranDMC authored Mar 29, 2024
1 parent 398871a commit 66f90f8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
- new opcode **2602 ([is_text_in_text](https://library.sannybuilder.com/#/sa/text/2602))**
- new opcode **2603 ([is_text_prefix](https://library.sannybuilder.com/#/sa/text/2603))**
- new opcode **2604 ([is_text_suffix](https://library.sannybuilder.com/#/sa/text/2604))**
- new opcode **2605 ([display_text_formatted](https://library.sannybuilder.com/#/sa/text/2605))**
- 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))**
Expand Down
66 changes: 46 additions & 20 deletions cleo_plugins/Text/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "CModelInfo.h"
#include "CText.h"
#include "CTextManager.h"
#include "CTheScripts.h"
#include <shlwapi.h>

using namespace CLEO;
Expand Down Expand Up @@ -57,6 +58,7 @@ class Text
CLEO_RegisterOpcode(0x2602, opcode_2602); // is_text_in_text
CLEO_RegisterOpcode(0x2603, opcode_2603); // is_text_prefix
CLEO_RegisterOpcode(0x2604, opcode_2604); // is_text_sufix
CLEO_RegisterOpcode(0x2605, opcode_2605); // display_text_formatted

// register event callbacks
CLEO_RegisterCallback(eCallbackId::GameBegin, OnGameBegin);
Expand Down Expand Up @@ -98,7 +100,7 @@ class Text
}

//0ACA=1,show_text_box %1d%
static OpcodeResult __stdcall opcode_0ACA(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0ACA(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(text);

Expand All @@ -107,7 +109,7 @@ class Text
}

//0ACB=3,show_styled_text %1d% time %2d% style %3d%
static OpcodeResult __stdcall opcode_0ACB(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0ACB(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(text);
auto time = OPCODE_READ_PARAM_INT();
Expand All @@ -120,7 +122,7 @@ class Text
}

//0ACC=2,show_text_lowpriority %1d% time %2d%
static OpcodeResult __stdcall opcode_0ACC(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0ACC(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(text);
auto time = OPCODE_READ_PARAM_INT();
Expand All @@ -131,7 +133,7 @@ class Text
}

//0ACD=2,show_text_highpriority %1d% time %2d%
static OpcodeResult __stdcall opcode_0ACD(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0ACD(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(text);
auto time = OPCODE_READ_PARAM_INT();
Expand All @@ -142,7 +144,7 @@ class Text
}

//0ACE=-1,show_formatted_text_box %1d%
static OpcodeResult __stdcall opcode_0ACE(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0ACE(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING_FORMATTED(text);

Expand All @@ -151,7 +153,7 @@ class Text
}

//0ACF=-1,show_formatted_styled_text %1d% time %2d% style %3d%
static OpcodeResult __stdcall opcode_0ACF(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0ACF(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(format);
auto time = OPCODE_READ_PARAM_INT();
Expand All @@ -165,7 +167,7 @@ class Text
}

//0AD0=-1,show_formatted_text_lowpriority %1d% time %2d%
static OpcodeResult __stdcall opcode_0AD0(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0AD0(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(format);
auto time = OPCODE_READ_PARAM_INT();
Expand All @@ -177,7 +179,7 @@ class Text
}

//0AD1=-1,show_formatted_text_highpriority %1d% time %2d%
static OpcodeResult __stdcall opcode_0AD1(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0AD1(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(format);
auto time = OPCODE_READ_PARAM_INT();
Expand All @@ -189,7 +191,7 @@ class Text
}

//0AD3=-1,string %1d% format %2d% ...
static OpcodeResult __stdcall opcode_0AD3(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0AD3(CLEO::CRunningScript* thread)
{
auto result = OPCODE_READ_PARAM_OUTPUT_VAR_STRING();
OPCODE_READ_PARAM_STRING_FORMATTED(text);
Expand All @@ -199,7 +201,7 @@ class Text
}

//0AD4=-1,%3d% = scan_string %1d% format %2d% //IF and SET
static OpcodeResult __stdcall opcode_0AD4(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0AD4(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(src);
OPCODE_READ_PARAM_STRING(format);
Expand Down Expand Up @@ -271,7 +273,7 @@ class Text
}

//0ADB=2,%2d% = car_model %1d% name
static OpcodeResult __stdcall opcode_0ADB(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0ADB(CLEO::CRunningScript* thread)
{
auto modelIndex = OPCODE_READ_PARAM_UINT();

Expand All @@ -289,7 +291,7 @@ class Text
}

//0ADE=2,%2d% = text_by_GXT_entry %1d%
static OpcodeResult __stdcall opcode_0ADE(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0ADE(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING_LEN(gxt, 7); // GXT labels can be max 7 character long

Expand All @@ -307,7 +309,7 @@ class Text
}

//0ADF=2,add_dynamic_GXT_entry %1d% text %2d%
static OpcodeResult __stdcall opcode_0ADF(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0ADF(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING_LEN(gxt, 7); // GXT labels can be max 7 character long
OPCODE_READ_PARAM_STRING(txt);
Expand All @@ -317,7 +319,7 @@ class Text
}

//0AE0=1,remove_dynamic_GXT_entry %1d%
static OpcodeResult __stdcall opcode_0AE0(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0AE0(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING_LEN(gxt, 7); // GXT labels can be max 7 character long

Expand All @@ -326,7 +328,7 @@ class Text
}

//0AED=3,%3d% = float %1d% to_string_format %2d%
static OpcodeResult __stdcall opcode_0AED(CRunningScript* thread)
static OpcodeResult __stdcall opcode_0AED(CLEO::CRunningScript* thread)
{
// this opcode is useless now
auto val = OPCODE_READ_PARAM_FLOAT();
Expand All @@ -340,7 +342,7 @@ class Text
}

//2600=1, is_text_empty %1s%
static OpcodeResult __stdcall opcode_2600(CRunningScript* thread)
static OpcodeResult __stdcall opcode_2600(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(str);

Expand All @@ -349,7 +351,7 @@ class Text
}

//2601=3, is_text_equal %1s% another %2s% ignore_case %3d%
static OpcodeResult __stdcall opcode_2601(CRunningScript* thread)
static OpcodeResult __stdcall opcode_2601(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(a);
OPCODE_READ_PARAM_STRING(b);
Expand All @@ -362,7 +364,7 @@ class Text
}

//2602=3, is_text_in_text %1s% sub_text %2s% ignore_case %3d%
static OpcodeResult __stdcall opcode_2602(CRunningScript* thread)
static OpcodeResult __stdcall opcode_2602(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(str);
OPCODE_READ_PARAM_STRING(substr);
Expand All @@ -381,7 +383,7 @@ class Text
}

//2603=3, is_text_prefix %1s% prefix %2s% ignore_case %3d%
static OpcodeResult __stdcall opcode_2603(CRunningScript* thread)
static OpcodeResult __stdcall opcode_2603(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(str);
OPCODE_READ_PARAM_STRING(prefix);
Expand All @@ -395,7 +397,7 @@ class Text
}

//2604=3, is_text_sufix %1s% sufix %2s% ignore_case %3d%
static OpcodeResult __stdcall opcode_2604(CRunningScript* thread)
static OpcodeResult __stdcall opcode_2604(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING(str);
OPCODE_READ_PARAM_STRING(sufix);
Expand All @@ -416,6 +418,30 @@ class Text
OPCODE_CONDITION_RESULT(result == 0);
return OR_CONTINUE;
}

//2605=-1,display_text_formatted offset_left %1d% offset_top %2d% format %3d% args
static OpcodeResult __stdcall opcode_2605(CLEO::CRunningScript* thread)
{
auto posX = OPCODE_READ_PARAM_FLOAT();
auto posY = OPCODE_READ_PARAM_FLOAT();
OPCODE_READ_PARAM_STRING_FORMATTED(text);

// new GXT label
// includes unprintable character, to ensure there will be no collision with user GXT lables
char gxt[8] = { 0x01, 'C', 'L', 'E', 'O', '_', 0x01, 0x00 };
gxt[6] += CTheScripts::NumberOfIntroTextLinesThisFrame; // unique label for each possible entry

textManager.AddFxt(gxt, text);

auto& draw = CTheScripts::IntroTextLines[CTheScripts::NumberOfIntroTextLinesThisFrame];
memcpy(&draw.xPosition, &posX, sizeof(draw.xPosition)); // invalid type in Plugin SDK. Just copy memory
memcpy(&draw.yPosition, &posY, sizeof(draw.yPosition));
strcpy(draw.gxtEntry, gxt);

CTheScripts::NumberOfIntroTextLinesThisFrame++;

return OR_CONTINUE;
}
} textInstance;

CTextManager Text::textManager;
Expand Down
2 changes: 2 additions & 0 deletions cleo_plugins/Text/Text.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ xcopy /Y "$(OutDir)$(TargetName).*" "$(GTA_SA_DIR)\cleo\cleo_plugins\"
<ClCompile Include="$(PLUGIN_SDK_DIR)\shared\GameVersion.cpp" />
<ClCompile Include="$(PLUGIN_SDK_DIR)\shared\Patch.cpp" />
<ClCompile Include="$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\CFileMgr.cpp" />
<ClCompile Include="$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\CTheScripts.cpp" />
<ClCompile Include="$(PLUGIN_SDK_DIR)\shared\game\CRGBA.cpp" />
<ClCompile Include="crc32.cpp" />
<ClCompile Include="CTextManager.cpp" />
<ClCompile Include="Text.cpp" />
Expand Down
8 changes: 7 additions & 1 deletion cleo_plugins/Text/Text.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
<ClCompile Include="$(PLUGIN_SDK_DIR)\shared\Patch.cpp">
<Filter>plugin_sdk</Filter>
</ClCompile>
<ClCompile Include="$(PLUGIN_SDK_DIR)\third-party\plugin-sdk\plugin_sa\game_sa\CFileMgr.cpp">
<ClCompile Include="$(PLUGIN_SDK_DIR)\shared\game\CRGBA.cpp">
<Filter>plugin_sdk</Filter>
</ClCompile>
<ClCompile Include="$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\CFileMgr.cpp">
<Filter>plugin_sdk</Filter>
</ClCompile>
<ClCompile Include="$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\CTheScripts.cpp">
<Filter>plugin_sdk</Filter>
</ClCompile>
</ItemGroup>
Expand Down

0 comments on commit 66f90f8

Please sign in to comment.