Skip to content

Commit

Permalink
More opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
RusJJ committed Apr 4, 2024
1 parent d74c2a7 commit 8a4cb9b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 11 deletions.
18 changes: 11 additions & 7 deletions cleo4opcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,14 +901,8 @@ CLEO_Fn(GET_TEXT_LABEL_STRING)
CLEO_WriteStringEx(handle, GXTCharToAscii(keyvalue, 0));
}

CLEO_Fn(ADD_TEXT_LABEL)
void AddGXTLabel(const char* gxtLabel, const char* text)
{
char gxtLabel[8], text[MAX_STR_LEN];
CLEO_ReadStringEx(handle, gxtLabel, sizeof(gxtLabel));
CLEO_ReadStringEx(handle, text, sizeof(text));

if(IsCLEORelatedGXTKey(gxtLabel)) return; // NUH-UH

CLEO_STD_String key, keytext;
CLEO_STD_PutStrToAlloced(&key, gxtLabel);
CLEO_STD_PutStrToAlloced(&keytext, text);
Expand All @@ -918,6 +912,16 @@ CLEO_Fn(ADD_TEXT_LABEL)
CLEO_STD_DeallocStorage(&key);
CLEO_STD_DeallocStorage(&keytext);
}
CLEO_Fn(ADD_TEXT_LABEL)
{
char gxtLabel[8], text[MAX_STR_LEN];
CLEO_ReadStringEx(handle, gxtLabel, sizeof(gxtLabel));
CLEO_ReadStringEx(handle, text, sizeof(text));

if(IsCLEORelatedGXTKey(gxtLabel)) return; // NUH-UH

AddGXTLabel(gxtLabel, text);
}

CLEO_Fn(REMOVE_TEXT_LABEL)
{
Expand Down
74 changes: 70 additions & 4 deletions cleo5opcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ void CleoReturnGeneric(void* handle, bool returnArgs, int returnArgCount);

// Game vars
bool *m_CodePause;
uint16_t *NumberOfIntroTextLinesThisFrame;
char *IntroTextLines;

// Debug plugin (need additional work)
CLEO_Fn(DEBUG_ON)
Expand Down Expand Up @@ -91,15 +93,48 @@ CLEO_Fn(READ_MEMORY_WITH_OFFSET)
uint32_t offset = cleo->ReadParam(handle)->u;
int size = cleo->ReadParam(handle)->i;

// Need additional work
if(IsParamString(handle))
{
std::string str(std::string_view((char*)source + offset, size)); // null terminated
CLEO_WriteStringEx(handle, str.c_str());
}
else
{
int result = 0;
if(size > 0 && size <= sizeof(result))
{
memcpy(&result, (void*)(source + offset), size);
}
cleo->GetPointerToScriptVar(handle)->i = result;
}
}
CLEO_Fn(WRITE_MEMORY_WITH_OFFSET)
{
uint32_t source = cleo->ReadParam(handle)->u;
uint32_t offset = cleo->ReadParam(handle)->u;
int size = cleo->ReadParam(handle)->i;

// Need additional work
if(size <= 0)
{
SkipOpcodeParameters(handle, 1);
return;
}

if(IsParamString(handle))
{
char buf[MAX_STR_LEN];
CLEO_ReadStringEx(handle, buf, sizeof(buf));
int len = strlen(buf);
memcpy((void*)(source + offset), buf, (size < len) ? size : len);
if (size > len) memset((void*)(source + offset + len), 0, size - len);
}
else
{
int value = cleo->ReadParam(handle)->i;
if(size > sizeof(value)) size = sizeof(value);

memcpy((void*)(source + offset), &value, size);
}
}
CLEO_Fn(FORGET_MEMORY)
{
Expand Down Expand Up @@ -190,7 +225,36 @@ CLEO_Fn(IS_TEXT_SUFFIX)
}
CLEO_Fn(DISPLAY_TEXT_FORMATTED)
{
// Need additional work
float posX = cleo->ReadParam(handle)->f;
float posY = cleo->ReadParam(handle)->f;

char fmt[MAX_STR_LEN], buf[MAX_STR_LEN];
CLEO_ReadStringEx(handle, fmt, sizeof(fmt));
CLEO_FormatString(handle, buf, sizeof(buf), fmt);

if(*nGameIdent == GTASA)
{
// 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] += *NumberOfIntroTextLinesThisFrame; // unique label for each possible entry

char* introTxtLine = IntroTextLines + *NumberOfIntroTextLinesThisFrame * ValueForGame(0xF4, 0xF4, 0x44);
AddGXTLabel(gxt, buf);

*(float*)(introTxtLine + 0x2C) = posX;
*(float*)(introTxtLine + 0x30) = posY;
strncpy(introTxtLine + 0x34, gxt, sizeof(gxt));
}
else
{
uint16_t gxt[256];
AsciiToGXTChar(buf, gxt);
memcpy(introTxtLine + 0x2C, &gxt[0], 200);
*(float*)(introTxtLine + 0x24) = posX;
*(float*)(introTxtLine + 0x28) = posY;
}
++(*NumberOfIntroTextLinesThisFrame);
}

// CLEO 5
Expand All @@ -210,7 +274,9 @@ CLEO_Fn(CLEO_RETURN_FAIL)

void Init5Opcodes()
{
SET_TO(m_CodePause, cleo->GetMainLibrarySymbol("_ZN6CTimer11m_CodePauseE"));
SET_TO(m_CodePause, cleo->GetMainLibrarySymbol("_ZN6CTimer11m_CodePauseE"));
SET_TO(NumberOfIntroTextLinesThisFrame, cleo->GetMainLibrarySymbol("_ZN11CTheScripts31NumberOfIntroTextLinesThisFrameE"));
SET_TO(IntroTextLines, cleo->GetMainLibrarySymbol("_ZN11CTheScripts14IntroTextLinesE"));

// Debug plugin
CLEO_RegisterOpcode(0x00C3, DEBUG_ON); // 00C3=0, debug_on
Expand Down
17 changes: 17 additions & 0 deletions cleohelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ union GXTChar
};

// Custom Funcs
void AddGXTLabel(const char* gxtLabel, const char* text);
inline void* AllocMem(size_t size)
{
void* mem = malloc(size);
Expand Down Expand Up @@ -892,6 +893,22 @@ inline bool IsValidScriptHandle(void* handle)
{
return IsInActiveScripts(handle) || IsInPausedScripts(handle) || IsInCLEOScripts(handle);
}
inline bool IsParamString(void* handle, bool checkIfPointer = false)
{
if(Read1Byte_NoSkip(handle) >= SCRIPT_PARAM_STATIC_SHORT_STRING)
{
return true;
}
else if(checkIfPointer)
{
uint8_t* backupPC = GetPC(handle);
void* probMem = (void*)cleo->ReadParam(handle)->i;
GetPC(handle) = backupPC;


}
return false;
}

// CLEO5
struct PausedScriptInfo
Expand Down

0 comments on commit 8a4cb9b

Please sign in to comment.