Skip to content

Commit

Permalink
Fix command limit checking for PluginSDK called commands. (#250)
Browse files Browse the repository at this point in the history
* Fix command limit checking for PluginSDK called commands.

Added support of -1 argument for limits config.

* fixup! Fix command limit checking for PluginSDK called commands.

* fixup! Fix command limit checking for PluginSDK called commands.
  • Loading branch information
MiranDMC authored Dec 20, 2024
1 parent 97da09a commit 4a4b314
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
9 changes: 5 additions & 4 deletions cleo_plugins/DebugUtils/DebugUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DebugUtils
}

auto config = GetConfigFilename();
configLimitCommand = GetPrivateProfileInt("Limits", "Command", 100000, config.c_str());
configLimitCommand = GetPrivateProfileInt("Limits", "Command", 200000, config.c_str());

// register opcodes
CLEO_RegisterOpcode(0x00C3, Opcode_DebugOn);
Expand Down Expand Up @@ -183,7 +183,7 @@ class DebugUtils

static bool WINAPI OnScriptProcess(CScriptThread* thread)
{
currScript.Reset();
currScript.Begin(thread);

for (size_t i = 0; i < pausedScripts.size(); i++)
{
Expand All @@ -198,8 +198,9 @@ class DebugUtils

static OpcodeResult WINAPI OnScriptOpcodeProcess(CRunningScript* thread, DWORD opcode)
{
currScript.commandCounter++;
if (currScript.commandCounter > configLimitCommand && !IsLegacyScript(thread))
currScript.ProcessCommand(thread);

if (configLimitCommand > 0 && currScript.commandCounter > configLimitCommand && !IsLegacyScript(thread))
{
SHOW_ERROR("Over %d,%03d commands executed in a single frame by script %s \nTo prevent the game from freezing, CLEO suspended this script.\n\nTo ignore this error, increase 'command' property in %s.ini file and restart the game.", configLimitCommand / 1000, configLimitCommand % 1000, ScriptInfoStr(thread).c_str(), TARGET_NAME);
return thread->Suspend();
Expand Down
5 changes: 3 additions & 2 deletions cleo_plugins/DebugUtils/SA.DebugUtils.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
; Opcodes 0662, 0663, 0664: 0 - off, 1 - enabled
LegacyDebugOpcodes = 0


[ScreenLog]
; Level: 0 - off, 1 - errors and warnings, 2 - debug messages, 3 - all
Level = 2
Expand All @@ -23,6 +24,6 @@ ColorError = "FF30EEFF"
ColorDebug = "FFEE30FF"
ColorSystem = "DDDDDDFF"

; limits between 'wait' commands in script after which it is considered hanging

[Limits]
command = 100000
Command = 200000 ; maximum instructions per script per frame. Set to 0 to disable the limit
11 changes: 10 additions & 1 deletion cleo_plugins/DebugUtils/ScriptLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@

struct ScriptLog
{
CRunningScript* thread = nullptr;
size_t commandCounter = 0;

void Reset()
void Begin(CRunningScript* thread)
{
this->thread = thread;
commandCounter = 0;
}

void ProcessCommand(CRunningScript* thread)
{
if (this->thread != thread) Begin(thread);

commandCounter++;
}
};

0 comments on commit 4a4b314

Please sign in to comment.