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

Standardized warning messages of terminate_this_script and terminate_… #174

Merged
merged 3 commits into from
Aug 2, 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
8 changes: 4 additions & 4 deletions source/CCustomOpcodeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,11 +863,11 @@ namespace CLEO
CCustomScript *cs = reinterpret_cast<CCustomScript *>(thread);
if (thread->IsMission() || !cs->IsCustom())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why custom missions are forced to use 004E?

{
LOG_WARNING(0, "Incorrect usage of opcode [0A93] in script %s", ((CCustomScript*)thread)->GetInfoStr().c_str());

return OR_CONTINUE;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep it as is. Nobody asked for this change

Copy link
Collaborator Author

@MiranDMC MiranDMC Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to fix bugs only if somebody else spot and report them?
Why terminate_this_custom_script would be ignored in custom script mission?
Why this opcode just prints warning then proceed the execution (potentially random bytes) of the script? Misuse of 004E was printing error AND stopping the script.
Is there any possible scenario where user called terminate_this_custom_script but wanted the script to keep ruining?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0a93 never worked in custom missions and nobody used it here. Its been like this from day 1. No need to change the behavior

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, added old behavior back.

LOG_WARNING(0, "Incorrect usage of opcode [0A93] in script %s. Use [004E] instead.", ((CCustomScript*)thread)->GetInfoStr().c_str());
return OR_CONTINUE; // legacy behavior
}
GetInstance().ScriptEngine.RemoveCustomScript(cs);

GetInstance().ScriptEngine.RemoveScript(thread);
return OR_INTERRUPT;
}

Expand Down
25 changes: 8 additions & 17 deletions source/CScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,6 @@ namespace CLEO

extern "C" void __stdcall opcode_004E(CCustomScript *pScript) // terminate_this_script
{
if (pScript->IsCustom())
{
if (pScript->IsMission())
*MissionLoaded = false;
else
{
TRACE("Incorrect usage of opcode [004E] in script %s.", pScript->GetName().c_str());
}
}

GetInstance().ScriptEngine.RemoveScript(pScript);
}

Expand Down Expand Up @@ -1369,17 +1359,18 @@ namespace CLEO

void CScriptEngine::RemoveScript(CRunningScript* thread)
{
if (!thread->IsCustom())
if (thread->IsMission()) *MissionLoaded = false;

if (thread->IsCustom())
{
RemoveCustomScript((CCustomScript*)thread);
}
else // native script
{
if (thread->IsMission()) *MissionLoaded = false;
RemoveScriptFromQueue(thread, activeThreadQueue);
AddScriptToQueue(thread, inactiveThreadQueue);
StopScript(thread);
}
else
{
RemoveCustomScript((CCustomScript*)thread);
}
}

void CScriptEngine::RemoveCustomScript(CCustomScript *cs)
Expand All @@ -1397,7 +1388,7 @@ namespace CLEO
}
for (auto childThread : cs->childThreads)
{
CScriptEngine::RemoveCustomScript(childThread);
CScriptEngine::RemoveScript(childThread);
}
if (cs == CustomMission)
{
Expand Down
4 changes: 3 additions & 1 deletion source/CScriptEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ namespace CLEO
bool IsValidScriptPtr(const CRunningScript*) const; // leads to any script? (regular or custom)
void AddCustomScript(CCustomScript*);
void RemoveScript(CRunningScript*); // native or custom
void RemoveCustomScript(CCustomScript*);
void RemoveAllCustomScripts();
void UnregisterAllScripts();
void ReregisterAllScripts();
Expand All @@ -151,6 +150,9 @@ namespace CLEO

inline CCustomScript* GetCustomMission() { return CustomMission; }
inline size_t WorkingScriptsCount() { return CustomScripts.size(); }

private:
void RemoveCustomScript(CCustomScript*);
};

extern void(__thiscall * AddScriptToQueue)(CRunningScript *, CRunningScript **queue);
Expand Down