Skip to content

Commit

Permalink
add_dynamic_GXT_entry opcode bug fix (#73)
Browse files Browse the repository at this point in the history
* add_dynamic_GXT_entry opcode bug fix

* fixup! add_dynamic_GXT_entry opcode bug fix
  • Loading branch information
MiranDMC authored Feb 27, 2024
1 parent a8d1f62 commit 3fc4b36
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cleo_sdk/CLEO.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ SCRIPT_VAR* WINAPI CLEO_GetPointerToScriptVariable(CRunningScript* thread); // g
void WINAPI CLEO_RetrieveOpcodeParams(CRunningScript* thread, int count); // read multiple params. Stored in opcodeParams array
DWORD WINAPI CLEO_GetIntOpcodeParam(CRunningScript* thread);
float WINAPI CLEO_GetFloatOpcodeParam(CRunningScript* thread);
LPSTR WINAPI CLEO_ReadStringOpcodeParam(CRunningScript* thread, char* buf = nullptr, int bufSize = 0); // returns nullptr on fail
LPSTR WINAPI CLEO_ReadStringOpcodeParam(CRunningScript* thread, char* buf = nullptr, int bufSize = 0); // returns null terminated string, nullptr on fail
LPSTR WINAPI CLEO_ReadStringPointerOpcodeParam(CRunningScript* thread, char* buf = nullptr, int bufSize = 0); // exactly same as CLEO_ReadStringOpcodeParam
void WINAPI CLEO_ReadStringParamWriteBuffer(CRunningScript* thread, char** outBuf, int* outBufSize, DWORD* outNeedsTerminator); // get info about the string opcode param, so it can be written latter. If outNeedsTerminator is not 0 then whole bufSize can be used as text characters. Advances script to next param
char* WINAPI CLEO_ReadParamsFormatted(CRunningScript* thread, const char* format, char* buf = nullptr, int bufSize = 0); // consumes all var-arg params and terminator
Expand Down
2 changes: 1 addition & 1 deletion cleo_sdk/CLEO_Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace CLEO
OPCODE_READ_PARAM_UINT()
OPCODE_READ_PARAM_FLOAT()
OPCODE_READ_PARAM_STRING() // returns char* to internal buffer. It might be overwritten by another string read!
OPCODE_READ_PARAM_STRING_BUFF(_buffer, _bufferSize)
OPCODE_READ_PARAM_STRING_BUFF(_buffer, _bufferSize) // always null terminated
OPCODE_READ_PARAM_FILEPATH() // returns char* to internal buffer. It might be overwritten by another string read!
OPCODE_READ_PARAM_PTR() // read and validate memory address argument
OPCODE_READ_PARAM_OBJECT_HANDLE()
Expand Down
6 changes: 3 additions & 3 deletions source/CCustomOpcodeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ namespace CLEO
return thread;
}

// read string parameter according to convention on strings
// read string parameter according to convention on strings. Always null terminated
char* ReadStringParam(CRunningScript *thread, char* buf, DWORD bufSize)
{
static char internal_buf[MAX_STR_LEN];
Expand Down Expand Up @@ -1551,8 +1551,8 @@ namespace CLEO
//0ADF=2,add_dynamic_GXT_entry %1d% text %2d%
OpcodeResult __stdcall opcode_0ADF(CRunningScript *thread)
{
char gxtLabel[8] = { 0 }; // 7 + terminator character
auto gxt = OPCODE_READ_PARAM_STRING_BUFF(gxtLabel, 7);
char gxtBuff[8]; // 7 + terminator character
auto gxt = OPCODE_READ_PARAM_STRING_BUFF(gxtBuff, sizeof(gxtBuff));
auto txt = OPCODE_READ_PARAM_STRING();

GetInstance().TextManager.AddFxt(gxt, txt);
Expand Down
2 changes: 1 addition & 1 deletion source/CCustomOpcodeSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace CLEO
bool needTerminator = false;
};

char* ReadStringParam(CRunningScript* thread, char* buf = nullptr, DWORD bufSize = 0);
char* ReadStringParam(CRunningScript* thread, char* buf = nullptr, DWORD bufSize = 0); // null terminated
StringParamBufferInfo GetStringParamWriteBuffer(CRunningScript* thread); // consumes the param
int ReadFormattedString(CRunningScript* thread, char* buf, DWORD bufSize, const char* format);

Expand Down
3 changes: 2 additions & 1 deletion source/CScriptEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ namespace CLEO
extern SCRIPT_VAR * (__thiscall * GetScriptParamPointer1)(CRunningScript *);
extern SCRIPT_VAR * (__thiscall * GetScriptParamPointer2)(CRunningScript *, int __unused__);

char* __fastcall GetScriptStringParam(CRunningScript* thread, int dummy, char* buff, int buffLen);
// reimplemented hook of original game's procedure. Null terminator ommited if not enought space in the buffer!
char* __fastcall GetScriptStringParam(CRunningScript* thread, int dummy, char* buff, int buffLen);

inline SCRIPT_VAR * GetScriptParamPointer(CRunningScript *thread)
{
Expand Down

0 comments on commit 3fc4b36

Please sign in to comment.