[Project64] Clean up PluginBase.cpp

This commit is contained in:
zilmar 2015-12-11 05:23:00 +11:00
parent ac1211eb76
commit 709c34fcd1
2 changed files with 50 additions and 49 deletions

View File

@ -13,18 +13,18 @@
#include <Windows.h> #include <Windows.h>
CPlugin::CPlugin() : CPlugin::CPlugin() :
DllAbout(NULL), DllAbout(NULL),
DllConfig(NULL), DllConfig(NULL),
CloseDLL(NULL), CloseDLL(NULL),
RomOpen(NULL), RomOpen(NULL),
RomClosed(NULL), RomClosed(NULL),
PluginOpened(NULL), PluginOpened(NULL),
SetSettingInfo(NULL), SetSettingInfo(NULL),
SetSettingInfo2(NULL), SetSettingInfo2(NULL),
SetSettingInfo3(NULL), SetSettingInfo3(NULL),
m_hDll(NULL), m_hDll(NULL),
m_Initialized(false), m_Initialized(false),
m_RomOpen(false) m_RomOpen(false)
{ {
memset(&m_PluginInfo, 0, sizeof(m_PluginInfo)); memset(&m_PluginInfo, 0, sizeof(m_PluginInfo));
} }
@ -34,7 +34,7 @@ CPlugin::~CPlugin()
UnloadPlugin(); UnloadPlugin();
} }
bool CPlugin::Load (const char * FileName) bool CPlugin::Load(const char * FileName)
{ {
// Already loaded, so unload first. // Already loaded, so unload first.
if (m_hDll != NULL) if (m_hDll != NULL)
@ -69,30 +69,30 @@ bool CPlugin::Load (const char * FileName)
if (!ValidPluginVersion(m_PluginInfo)) { return false; } if (!ValidPluginVersion(m_PluginInfo)) { return false; }
if (m_PluginInfo.Type != type()) { return false; } if (m_PluginInfo.Type != type()) { return false; }
CloseDLL = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "CloseDLL" ); CloseDLL = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "CloseDLL");
RomOpen = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "RomOpen" ); RomOpen = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "RomOpen");
RomClosed = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "RomClosed" ); RomClosed = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "RomClosed");
PluginOpened = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "PluginLoaded" ); PluginOpened = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "PluginLoaded");
DllConfig = (void (__cdecl *)(void *)) GetProcAddress( (HMODULE)m_hDll, "DllConfig" ); DllConfig = (void(__cdecl *)(void *)) GetProcAddress((HMODULE)m_hDll, "DllConfig");
DllAbout = (void (__cdecl *)(void *)) GetProcAddress( (HMODULE)m_hDll, "DllAbout" ); DllAbout = (void(__cdecl *)(void *)) GetProcAddress((HMODULE)m_hDll, "DllAbout");
SetSettingInfo3 = (void (__cdecl *)(PLUGIN_SETTINGS3 *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo3" ); SetSettingInfo3 = (void(__cdecl *)(PLUGIN_SETTINGS3 *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo3");
if (SetSettingInfo3) if (SetSettingInfo3)
{ {
PLUGIN_SETTINGS3 info; PLUGIN_SETTINGS3 info;
info.FlushSettings = (void (*)( void * handle))CSettings::FlushSettings; info.FlushSettings = (void(*)(void * handle))CSettings::FlushSettings;
SetSettingInfo3(&info); SetSettingInfo3(&info);
} }
SetSettingInfo2 = (void (__cdecl *)(PLUGIN_SETTINGS2 *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo2" ); SetSettingInfo2 = (void(__cdecl *)(PLUGIN_SETTINGS2 *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo2");
if (SetSettingInfo2) if (SetSettingInfo2)
{ {
PLUGIN_SETTINGS2 info; PLUGIN_SETTINGS2 info;
info.FindSystemSettingId = (uint32_t (*)( void * handle, const char * ))CSettings::FindSetting; info.FindSystemSettingId = (uint32_t(*)(void * handle, const char *))CSettings::FindSetting;
SetSettingInfo2(&info); SetSettingInfo2(&info);
} }
SetSettingInfo = (void (__cdecl *)(PLUGIN_SETTINGS *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo" ); SetSettingInfo = (void(__cdecl *)(PLUGIN_SETTINGS *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo");
if (SetSettingInfo) if (SetSettingInfo)
{ {
PLUGIN_SETTINGS info; PLUGIN_SETTINGS info;
@ -120,13 +120,13 @@ bool CPlugin::Load (const char * FileName)
{ {
return false; return false;
} }
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Functions loaded",PluginType()); WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Functions loaded", PluginType());
if (PluginOpened) if (PluginOpened)
{ {
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Plugin Opened",PluginType()); WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Before Plugin Opened", PluginType());
PluginOpened(); PluginOpened();
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Plugin Opened",PluginType()); WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): After Plugin Opened", PluginType());
} }
return true; return true;
} }
@ -136,10 +136,11 @@ void CPlugin::RomOpened()
if (m_RomOpen) if (m_RomOpen)
return; return;
if(RomOpen != NULL){ if (RomOpen != NULL)
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Rom Open",PluginType()); {
WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Before Rom Open", PluginType());
RomOpen(); RomOpen();
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Rom Open",PluginType()); WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): After Rom Open", PluginType());
} }
m_RomOpen = true; m_RomOpen = true;
} }
@ -149,10 +150,10 @@ void CPlugin::RomClose()
if (!m_RomOpen) if (!m_RomOpen)
return; return;
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Rom Close",PluginType()); WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Before Rom Close", PluginType());
RomClosed(); RomClosed();
m_RomOpen = false; m_RomOpen = false;
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Rom Close",PluginType()); WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): After Rom Close", PluginType());
} }
void CPlugin::GameReset() void CPlugin::GameReset()
@ -169,19 +170,19 @@ void CPlugin::GameReset()
void CPlugin::Close() void CPlugin::Close()
{ {
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Start",PluginType()); WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Start", PluginType());
RomClose(); RomClose();
if (m_Initialized) if (m_Initialized)
{ {
CloseDLL(); CloseDLL();
m_Initialized = false; m_Initialized = false;
} }
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Done",PluginType()); WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Done", PluginType());
} }
void CPlugin::UnloadPlugin() void CPlugin::UnloadPlugin()
{ {
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): unloading",PluginType()); WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): unloading", PluginType());
memset(&m_PluginInfo, 0, sizeof(m_PluginInfo)); memset(&m_PluginInfo, 0, sizeof(m_PluginInfo));
if (m_hDll != NULL) if (m_hDll != NULL)
{ {
@ -201,7 +202,7 @@ void CPlugin::UnloadPlugin()
SetSettingInfo3 = NULL; SetSettingInfo3 = NULL;
} }
const char * CPlugin::PluginType () const const char * CPlugin::PluginType() const
{ {
switch (m_PluginInfo.Type) switch (m_PluginInfo.Type)
{ {
@ -213,7 +214,7 @@ const char * CPlugin::PluginType () const
return "Unknown"; return "Unknown";
} }
TraceType CPlugin::PluginTraceType () const TraceType CPlugin::PluginTraceType() const
{ {
switch (m_PluginInfo.Type) switch (m_PluginInfo.Type)
{ {
@ -225,7 +226,7 @@ TraceType CPlugin::PluginTraceType () const
return TraceDebug; return TraceDebug;
} }
bool CPlugin::ValidPluginVersion ( PLUGIN_INFO & PluginInfo ) bool CPlugin::ValidPluginVersion(PLUGIN_INFO & PluginInfo)
{ {
switch (PluginInfo.Type) switch (PluginInfo.Type)
{ {

View File

@ -35,7 +35,7 @@ public:
void(__cdecl *DllAbout) (void * hWnd); void(__cdecl *DllAbout) (void * hWnd);
void(__cdecl *DllConfig) (void * hParent); void(__cdecl *DllConfig) (void * hParent);
static bool ValidPluginVersion ( PLUGIN_INFO & PluginInfo ); static bool ValidPluginVersion(PLUGIN_INFO & PluginInfo);
protected: protected:
void UnloadPlugin(); void UnloadPlugin();