Skip to content

Commit e6d1bef

Browse files
authored
custom implementation for terminate_all_scripts_with_this_name (#285)
1 parent 1811b2d commit e6d1bef

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

cleo_plugins/MemoryOperations/MemoryOperations.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class MemoryOperations
2525
}
2626

2727
//register opcodes
28+
CLEO_RegisterOpcode(0x0459, opcode_0459); // terminate_all_scripts_with_this_name
29+
2830
CLEO_RegisterOpcode(0x0A8C, opcode_0A8C); // write_memory
2931
CLEO_RegisterOpcode(0x0A8D, opcode_0A8D); // read_memory
3032

@@ -218,6 +220,24 @@ class MemoryOperations
218220
return OR_CONTINUE;
219221
}
220222

223+
//0459=1,terminate_all_scripts_with_this_name %1s%
224+
static OpcodeResult __stdcall opcode_0459(CLEO::CRunningScript* thread)
225+
{
226+
OPCODE_READ_PARAM_STRING(threadName);
227+
228+
while (true)
229+
{
230+
// we only want to terminate game scripts, not custom ones
231+
auto found = CLEO_GetScriptByName(threadName, true, false, 0);
232+
if (found == nullptr)
233+
break;
234+
235+
CLEO_TerminateScript(found);
236+
}
237+
238+
return OR_CONTINUE;
239+
}
240+
221241
//0A8C=4,write_memory %1d% size %2d% value %3d% virtual_protect %4d%
222242
static OpcodeResult __stdcall opcode_0A8C(CLEO::CRunningScript* thread)
223243
{

source/CScriptEngine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,11 @@ namespace CLEO
12001200
{
12011201
for (auto script = *activeThreadQueue; script; script = script->GetNext())
12021202
{
1203+
if (script->IsCustom())
1204+
{
1205+
// skip custom scripts in the queue, they are handled separately
1206+
continue;
1207+
}
12031208
if (_strnicmp(threadName, script->Name, sizeof(script->Name)) == 0)
12041209
{
12051210
if (resultIndex == 0) return script;

0 commit comments

Comments
 (0)