[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>
CPlugin::CPlugin() :
DllAbout(NULL),
DllConfig(NULL),
CloseDLL(NULL),
RomOpen(NULL),
RomClosed(NULL),
PluginOpened(NULL),
SetSettingInfo(NULL),
SetSettingInfo2(NULL),
SetSettingInfo3(NULL),
m_hDll(NULL),
m_Initialized(false),
m_RomOpen(false)
DllAbout(NULL),
DllConfig(NULL),
CloseDLL(NULL),
RomOpen(NULL),
RomClosed(NULL),
PluginOpened(NULL),
SetSettingInfo(NULL),
SetSettingInfo2(NULL),
SetSettingInfo3(NULL),
m_hDll(NULL),
m_Initialized(false),
m_RomOpen(false)
{
memset(&m_PluginInfo, 0, sizeof(m_PluginInfo));
}
@ -34,7 +34,7 @@ CPlugin::~CPlugin()
UnloadPlugin();
}
bool CPlugin::Load (const char * FileName)
bool CPlugin::Load(const char * FileName)
{
// Already loaded, so unload first.
if (m_hDll != NULL)
@ -69,30 +69,30 @@ bool CPlugin::Load (const char * FileName)
if (!ValidPluginVersion(m_PluginInfo)) { return false; }
if (m_PluginInfo.Type != type()) { return false; }
CloseDLL = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "CloseDLL" );
RomOpen = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "RomOpen" );
RomClosed = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "RomClosed" );
PluginOpened = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "PluginLoaded" );
DllConfig = (void (__cdecl *)(void *)) GetProcAddress( (HMODULE)m_hDll, "DllConfig" );
DllAbout = (void (__cdecl *)(void *)) GetProcAddress( (HMODULE)m_hDll, "DllAbout" );
CloseDLL = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "CloseDLL");
RomOpen = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "RomOpen");
RomClosed = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "RomClosed");
PluginOpened = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "PluginLoaded");
DllConfig = (void(__cdecl *)(void *)) GetProcAddress((HMODULE)m_hDll, "DllConfig");
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)
{
PLUGIN_SETTINGS3 info;
info.FlushSettings = (void (*)( void * handle))CSettings::FlushSettings;
info.FlushSettings = (void(*)(void * handle))CSettings::FlushSettings;
SetSettingInfo3(&info);
}
SetSettingInfo2 = (void (__cdecl *)(PLUGIN_SETTINGS2 *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo2" );
SetSettingInfo2 = (void(__cdecl *)(PLUGIN_SETTINGS2 *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo2");
if (SetSettingInfo2)
{
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);
}
SetSettingInfo = (void (__cdecl *)(PLUGIN_SETTINGS *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo" );
SetSettingInfo = (void(__cdecl *)(PLUGIN_SETTINGS *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo");
if (SetSettingInfo)
{
PLUGIN_SETTINGS info;
@ -120,13 +120,13 @@ bool CPlugin::Load (const char * FileName)
{
return false;
}
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Functions loaded",PluginType());
WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Functions loaded", PluginType());
if (PluginOpened)
{
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Plugin Opened",PluginType());
WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Before Plugin Opened", PluginType());
PluginOpened();
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Plugin Opened",PluginType());
WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): After Plugin Opened", PluginType());
}
return true;
}
@ -136,10 +136,11 @@ void CPlugin::RomOpened()
if (m_RomOpen)
return;
if(RomOpen != NULL){
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Rom Open",PluginType());
if (RomOpen != NULL)
{
WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Before Rom Open", PluginType());
RomOpen();
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Rom Open",PluginType());
WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): After Rom Open", PluginType());
}
m_RomOpen = true;
}
@ -149,10 +150,10 @@ void CPlugin::RomClose()
if (!m_RomOpen)
return;
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Rom Close",PluginType());
WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Before Rom Close", PluginType());
RomClosed();
m_RomOpen = false;
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Rom Close",PluginType());
WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): After Rom Close", PluginType());
}
void CPlugin::GameReset()
@ -169,19 +170,19 @@ void CPlugin::GameReset()
void CPlugin::Close()
{
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Start",PluginType());
WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Start", PluginType());
RomClose();
if (m_Initialized)
{
CloseDLL();
m_Initialized = false;
}
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Done",PluginType());
WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): Done", PluginType());
}
void CPlugin::UnloadPlugin()
{
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): unloading",PluginType());
WriteTraceF(PluginTraceType(), __FUNCTION__ "(%s): unloading", PluginType());
memset(&m_PluginInfo, 0, sizeof(m_PluginInfo));
if (m_hDll != NULL)
{
@ -201,7 +202,7 @@ void CPlugin::UnloadPlugin()
SetSettingInfo3 = NULL;
}
const char * CPlugin::PluginType () const
const char * CPlugin::PluginType() const
{
switch (m_PluginInfo.Type)
{
@ -213,7 +214,7 @@ const char * CPlugin::PluginType () const
return "Unknown";
}
TraceType CPlugin::PluginTraceType () const
TraceType CPlugin::PluginTraceType() const
{
switch (m_PluginInfo.Type)
{
@ -225,27 +226,27 @@ TraceType CPlugin::PluginTraceType () const
return TraceDebug;
}
bool CPlugin::ValidPluginVersion ( PLUGIN_INFO & PluginInfo )
bool CPlugin::ValidPluginVersion(PLUGIN_INFO & PluginInfo)
{
switch (PluginInfo.Type)
{
case PLUGIN_TYPE_RSP:
if (!PluginInfo.MemoryBswaped) { return false; }
if (PluginInfo.Version == 0x0001) { return true; }
if (PluginInfo.Version == 0x0100) { return true; }
if (PluginInfo.Version == 0x0101) { return true; }
if (PluginInfo.Version == 0x0102) { return true; }
if (PluginInfo.Version == 0x0001) { return true; }
if (PluginInfo.Version == 0x0100) { return true; }
if (PluginInfo.Version == 0x0101) { return true; }
if (PluginInfo.Version == 0x0102) { return true; }
break;
case PLUGIN_TYPE_GFX:
if (!PluginInfo.MemoryBswaped) { return false; }
if (PluginInfo.Version == 0x0102) { return true; }
if (PluginInfo.Version == 0x0103) { return true; }
if (PluginInfo.Version == 0x0104) { return true; }
if (PluginInfo.Version == 0x0102) { return true; }
if (PluginInfo.Version == 0x0103) { return true; }
if (PluginInfo.Version == 0x0104) { return true; }
break;
case PLUGIN_TYPE_AUDIO:
if (!PluginInfo.MemoryBswaped) { return false; }
if (PluginInfo.Version == 0x0101) { return true; }
if (PluginInfo.Version == 0x0102) { return true; }
if (PluginInfo.Version == 0x0101) { return true; }
if (PluginInfo.Version == 0x0102) { return true; }
break;
case PLUGIN_TYPE_CONTROLLER:
if (PluginInfo.Version == 0x0100) { return true; }
@ -254,4 +255,4 @@ bool CPlugin::ValidPluginVersion ( PLUGIN_INFO & PluginInfo )
break;
}
return FALSE;
}
}

View File

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