Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_dynamic_GXT_entry opcode bug fix #73

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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