1
0
Fork 0

DBG: add plugin menu api

This commit is contained in:
Mr. eXoDia 2014-04-22 19:25:37 +02:00
parent 8e0e02bc2e
commit 98b0d7d858
6 changed files with 169 additions and 7 deletions

View File

@ -53,3 +53,23 @@ PLUG_IMPEXP void _plugin_debugskipexceptions(bool skip)
{
dbgsetskipexceptions(skip);
}
PLUG_IMPEXP int _plugin_menuadd(int hMenu, const char* title)
{
return pluginmenuadd(hMenu, title);
}
PLUG_IMPEXP bool _plugin_menuaddentry(int hMenu, int hEntry, const char* title)
{
return pluginmenuaddentry(hMenu, hEntry, title);
}
PLUG_IMPEXP bool _plugin_menuaddseparator(int hMenu)
{
return pluginmenuaddseparator(hMenu);
}
PLUG_IMPEXP bool _plugin_menuclear(int hMenu)
{
return pluginmenuclear(hMenu);
}

View File

@ -23,6 +23,8 @@ struct PLUG_INITSTRUCT
int sdkVersion;
int pluginVersion;
char pluginName[256];
//provided by the debugger
int hMenu; //plugin menu handle
};
//callback structures
@ -137,7 +139,8 @@ enum CBTYPE
CB_RESUMEDEBUG, //PLUG_CB_RESUMEDEBUG
CB_STEPPED, //PLUG_CB_STEPPED
CB_ATTACH, //PLUG_CB_ATTACHED (before attaching, after CB_INITDEBUG)
CB_DETACH //PLUG_CB_DETACH (before detaching, before CB_STOPDEBUG)
CB_DETACH, //PLUG_CB_DETACH (before detaching, before CB_STOPDEBUG)
CB_DEBUGEVENT, //PLUG_CB_DEBUGEVENT (called on any debug event)
};
//typedefs
@ -158,6 +161,10 @@ PLUG_IMPEXP void _plugin_logprintf(const char* format, ...);
PLUG_IMPEXP void _plugin_logputs(const char* text);
PLUG_IMPEXP void _plugin_debugpause();
PLUG_IMPEXP void _plugin_debugskipexceptions(bool skip);
PLUG_IMPEXP int _plugin_menuadd(int hMenu, const char* title);
PLUG_IMPEXP bool _plugin_menuaddentry(int hMenu, int hEntry, const char* title);
PLUG_IMPEXP bool _plugin_menuaddseparator(int hMenu);
PLUG_IMPEXP bool _plugin_menuclear(int hMenu);
#ifdef __cplusplus
}

View File

@ -37,17 +37,23 @@ void msgfreestack(MESSAGE_STACK* msgstack)
//add a message to the stack
bool msgsend(MESSAGE_STACK* msgstack, int msg, uint param1, uint param2)
{
CRITICAL_SECTION* cr=&msgstack->cr;
EnterCriticalSection(cr);
int stackpos=msgstack->stackpos;
if(stackpos>=MAX_MESSAGES)
{
LeaveCriticalSection(cr);
return false;
}
MESSAGE* newmsg=msgalloc();
if(!newmsg)
{
LeaveCriticalSection(cr);
return false;
}
newmsg->msg=msg;
newmsg->param1=param1;
newmsg->param2=param2;
CRITICAL_SECTION* cr=&msgstack->cr;
EnterCriticalSection(cr);
msgstack->msg[stackpos]=newmsg;
msgstack->stackpos++; //increase stack pointer
LeaveCriticalSection(cr);

View File

@ -7,10 +7,12 @@ static std::vector<PLUG_DATA> pluginList;
static int curPluginHandle=0;
static std::vector<PLUG_CALLBACK> pluginCallbackList;
static std::vector<PLUG_COMMAND> pluginCommandList;
static std::vector<PLUG_MENU> pluginMenuList;
///internal plugin functions
void pluginload(const char* pluginDir)
{
//load new plugins
char currentDir[deflen]="";
GetCurrentDirectoryA(deflen, currentDir);
SetCurrentDirectoryA(pluginDir);
@ -30,7 +32,6 @@ void pluginload(const char* pluginDir)
PLUG_DATA pluginData;
do
{
memset(&pluginData, 0, sizeof(PLUG_DATA));
pluginData.initStruct.pluginHandle=curPluginHandle;
char szPluginPath[MAX_PATH]="";
sprintf(szPluginPath, "%s\\%s", pluginDir, foundData.cFileName);
@ -64,6 +65,19 @@ void pluginload(const char* pluginDir)
SetCurrentDirectoryA(currentDir);
}
static void plugincmdunregisterall(int pluginHandle)
{
int listsize=pluginCommandList.size();
for(int i=listsize-1; i>=0; i--)
{
if(pluginCommandList.at(i).pluginHandle==pluginHandle)
{
cmddel(dbggetcommandlist(), pluginCommandList.at(i).command);
pluginCommandList.erase(pluginCommandList.begin()+i);
}
}
}
void pluginunload()
{
int pluginCount=pluginList.size();
@ -72,8 +86,12 @@ void pluginunload()
PLUGSTOP stop=pluginList.at(i).plugstop;
if(stop)
stop();
plugincmdunregisterall(pluginList.at(i).initStruct.pluginHandle);
FreeLibrary(pluginList.at(i).hPlugin);
}
pluginCallbackList.clear(); //remove all callbacks
pluginMenuList.clear(); //clear menu list
GuiMenuClear(GUI_PLUGIN_MENU); //clear the plugin menu
}
///debugging plugin exports
@ -144,3 +162,90 @@ bool plugincmdunregister(int pluginHandle, const char* command)
}
return false;
}
int pluginmenuadd(int hMenu, const char* title)
{
if(!title or !strlen(title))
return -1;
int nFound=-1;
for(unsigned int i=0; i<pluginMenuList.size(); i++)
{
if(pluginMenuList.at(i).hEntryMenu==hMenu and pluginMenuList.at(i).hEntryPlugin==-1)
{
nFound=i;
break;
}
}
if(nFound==-1) //not a valid menu handle
return -1;
int hMenuNew=GuiMenuAdd(pluginMenuList.at(nFound).hEntryMenu, title);
PLUG_MENU newMenu;
newMenu.pluginHandle=pluginMenuList.at(nFound).pluginHandle;
newMenu.hEntryPlugin=-1;
newMenu.hEntryMenu=hMenuNew;
pluginMenuList.push_back(newMenu);
return hMenuNew;
}
bool pluginmenuaddentry(int hMenu, int hEntry, const char* title)
{
if(!title or !strlen(title) or hEntry==-1)
return false;
int pluginHandle=-1;
//find plugin handle
for(unsigned int i=0; i<pluginMenuList.size(); i++)
{
if(pluginMenuList.at(i).hEntryMenu==hMenu and pluginMenuList.at(i).hEntryPlugin==-1)
{
pluginHandle=pluginMenuList.at(i).pluginHandle;
break;
}
}
if(pluginHandle==-1) //not found
return false;
//search if hEntry was previously used
for(unsigned int i=0; i<pluginMenuList.size(); i++)
if(pluginMenuList.at(i).pluginHandle==pluginHandle && pluginMenuList.at(i).hEntryPlugin==hEntry)
return false;
int hNewEntry=GuiMenuAddEntry(hMenu, title);
PLUG_MENU newMenu;
newMenu.hEntryMenu=hNewEntry;
newMenu.hEntryPlugin=hEntry;
newMenu.pluginHandle=pluginHandle;
pluginMenuList.push_back(newMenu);
return true;
}
bool pluginmenuaddseparator(int hMenu)
{
bool bFound=false;
for(unsigned int i=0; i<pluginMenuList.size(); i++)
{
if(pluginMenuList.at(i).hEntryMenu==hMenu and pluginMenuList.at(i).hEntryPlugin==-1)
{
bFound=true;
break;
}
}
if(!bFound)
return false;
GuiMenuAddSeparator(hMenu);
return true;
}
bool pluginmenuclear(int hMenu)
{
bool bFound=false;
for(unsigned int i=0; i<pluginMenuList.size(); i++)
{
if(pluginMenuList.at(i).hEntryMenu==hMenu and pluginMenuList.at(i).hEntryPlugin==-1)
{
bFound=true;
break;
}
}
if(!bFound)
return false;
GuiMenuClear(hMenu);
return false;
}

View File

@ -9,6 +9,13 @@ typedef bool (*PLUGINIT)(PLUG_INITSTRUCT* initStruct);
typedef bool (*PLUGSTOP)();
//structures
struct PLUG_MENU
{
int pluginHandle; //plugin handle
int hEntryMenu; //GUI entry/menu handle (unique)
int hEntryPlugin; //plugin entry handle (unique per plugin)
};
struct PLUG_DATA
{
HINSTANCE hPlugin;
@ -38,5 +45,9 @@ bool pluginunregistercallback(int pluginHandle, CBTYPE cbType);
void plugincbcall(CBTYPE cbType, void* callbackInfo);
bool plugincmdregister(int pluginHandle, const char* command, CBPLUGINCOMMAND cbCommand, bool debugonly);
bool plugincmdunregister(int pluginHandle, const char* command);
int pluginmenuadd(int hMenu, const char* title);
bool pluginmenuaddentry(int hMenu, int hEntry, const char* title);
bool pluginmenuaddseparator(int hMenu);
bool pluginmenuclear(int hMenu);
#endif // _PLUGIN_LOADER_H

View File

@ -274,9 +274,22 @@ static bool scriptisruncommand(const char* cmdlist)
return false;
}
static bool scriptisinternalcommand(const char* text, const char* cmd)
{
int len=strlen(text);
int cmdlen=strlen(cmd);
if(cmdlen>len)
return false;
else if(cmdlen==len)
return scmp(text, cmd);
else if(text[cmdlen]==' ')
return (!_strnicmp(text, cmd, cmdlen));
return false;
}
static CMDRESULT scriptinternalcmdexec(const char* cmd)
{
if(scmp(cmd, "ret")) //script finished
if(scriptisinternalcommand(cmd, "ret")) //script finished
{
if(!scriptstack.size()) //nothing on the stack
{
@ -287,9 +300,9 @@ static CMDRESULT scriptinternalcmdexec(const char* cmd)
scriptstack.pop_back(); //remove last stack entry
return STATUS_CONTINUE;
}
else if(scmp(cmd, "invalid")) //invalid command for testing
else if(scriptisinternalcommand(cmd, "invalid")) //invalid command for testing
return STATUS_ERROR;
else if(scmp(cmd, "pause")) //pause the script
else if(scriptisinternalcommand(cmd, "pause")) //pause the script
return STATUS_PAUSE;
char command[deflen]="";
strcpy(command, cmd);