2017-08-18 05:08:22 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdafx.h>
|
|
|
|
#include <3rdParty/duktape/duktape.h>
|
|
|
|
|
|
|
|
#include "ScriptInstance.h"
|
|
|
|
|
|
|
|
class CScriptHook;
|
|
|
|
|
|
|
|
class CScriptSystem
|
|
|
|
{
|
|
|
|
public:
|
2017-09-13 10:36:03 +00:00
|
|
|
CScriptSystem(CDebuggerUI* debugger);
|
|
|
|
~CScriptSystem();
|
|
|
|
// Run a script in its own context/thread
|
2021-01-19 05:58:59 +00:00
|
|
|
void RunScript(const char * path);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:36:03 +00:00
|
|
|
// Kill a script context/thread by its path
|
2021-01-19 05:58:59 +00:00
|
|
|
void StopScript(const char * path);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:36:03 +00:00
|
|
|
const char* APIScript();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
|
|
|
private:
|
2017-09-13 10:36:03 +00:00
|
|
|
typedef struct {
|
|
|
|
const char* hookId;
|
|
|
|
CScriptHook* cbList;
|
|
|
|
} HOOKENTRY;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:36:03 +00:00
|
|
|
typedef struct {
|
|
|
|
char* path;
|
|
|
|
CScriptInstance* scriptInstance;
|
|
|
|
} INSTANCE_ENTRY;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:36:03 +00:00
|
|
|
CDebuggerUI* m_Debugger;
|
2019-12-01 10:10:36 +00:00
|
|
|
int m_NumCallbacks;
|
2017-09-13 10:36:03 +00:00
|
|
|
char* m_APIScript;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:36:03 +00:00
|
|
|
vector<HOOKENTRY> m_Hooks;
|
|
|
|
vector<INSTANCE_ENTRY> m_RunningInstances;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:36:03 +00:00
|
|
|
vector<char*> m_LogData;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:36:03 +00:00
|
|
|
CScriptHook* m_HookCPUExec;
|
|
|
|
CScriptHook* m_HookCPURead;
|
|
|
|
CScriptHook* m_HookCPUWrite;
|
2018-12-07 04:19:28 +00:00
|
|
|
CScriptHook* m_HookCPUExecOpcode;
|
2019-12-25 00:41:20 +00:00
|
|
|
CScriptHook* m_HookCPUGPRValue;
|
2017-09-13 10:36:03 +00:00
|
|
|
CScriptHook* m_HookFrameDrawn;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
CriticalSection m_CS;
|
2019-04-29 06:28:12 +00:00
|
|
|
|
2021-03-18 03:39:02 +00:00
|
|
|
void RegisterHook(const char* hookId, CScriptHook* cbList); // Associate string ID with callback list
|
2017-09-13 10:36:03 +00:00
|
|
|
void UnregisterHooks();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:36:03 +00:00
|
|
|
HDC m_ScreenDC;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:36:03 +00:00
|
|
|
int m_NextCallbackId;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
|
|
|
public:
|
2017-09-13 10:36:03 +00:00
|
|
|
// Returns true if any of the script hooks have callbacks for scriptInstance
|
|
|
|
|
|
|
|
void SetScreenDC(HDC hdc)
|
|
|
|
{
|
|
|
|
m_ScreenDC = hdc;
|
|
|
|
}
|
|
|
|
|
|
|
|
HDC GetScreenDC()
|
|
|
|
{
|
|
|
|
return m_ScreenDC;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline vector<char*>* LogData()
|
|
|
|
{
|
|
|
|
return &m_LogData;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void LogText(const char* text)
|
|
|
|
{
|
|
|
|
char* newStr = (char*)malloc(strlen(text));
|
|
|
|
strcpy(newStr, text);
|
|
|
|
m_LogData.push_back(newStr);
|
|
|
|
m_Debugger->Debug_RefreshScriptsWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasCallbacksForInstance(CScriptInstance* scriptInstance);
|
|
|
|
|
|
|
|
// Remove all hooked callbacks for an instance
|
|
|
|
void ClearCallbacksForInstance(CScriptInstance* scriptInstance);
|
|
|
|
|
|
|
|
void RemoveCallbackById(int callbackId);
|
|
|
|
|
|
|
|
CScriptHook* GetHook(const char* hookId);
|
|
|
|
|
|
|
|
int GetNextCallbackId();
|
2019-12-01 10:10:36 +00:00
|
|
|
void CallbackAdded();
|
|
|
|
void CallbackRemoved();
|
|
|
|
|
|
|
|
inline int HaveCallbacks()
|
|
|
|
{
|
|
|
|
return m_NumCallbacks != 0;
|
|
|
|
}
|
2017-09-13 10:36:03 +00:00
|
|
|
|
|
|
|
void DeleteStoppedInstances();
|
2020-05-12 12:19:05 +00:00
|
|
|
INSTANCE_STATE GetInstanceState(const char* scriptName);
|
|
|
|
CScriptInstance* GetInstance(const char* scriptName);
|
2017-09-13 10:36:03 +00:00
|
|
|
|
|
|
|
CScriptHook* HookCPUExec()
|
|
|
|
{
|
|
|
|
return m_HookCPUExec;
|
|
|
|
}
|
|
|
|
|
|
|
|
CScriptHook* HookCPURead()
|
|
|
|
{
|
|
|
|
return m_HookCPURead;
|
|
|
|
}
|
|
|
|
|
|
|
|
CScriptHook* HookCPUWrite()
|
|
|
|
{
|
|
|
|
return m_HookCPUWrite;
|
|
|
|
}
|
|
|
|
|
2018-12-07 04:19:28 +00:00
|
|
|
CScriptHook* HookCPUExecOpcode()
|
2018-11-21 08:57:50 +00:00
|
|
|
{
|
2018-12-07 04:19:28 +00:00
|
|
|
return m_HookCPUExecOpcode;
|
2018-11-21 08:57:50 +00:00
|
|
|
}
|
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
CScriptHook* HookCPUGPRValue()
|
|
|
|
{
|
|
|
|
return m_HookCPUGPRValue;
|
|
|
|
}
|
2018-12-09 21:24:11 +00:00
|
|
|
|
2017-09-13 10:36:03 +00:00
|
|
|
CScriptHook* HookFrameDrawn()
|
|
|
|
{
|
|
|
|
return m_HookFrameDrawn;
|
|
|
|
}
|
2021-03-18 03:39:02 +00:00
|
|
|
};
|