2015-01-30 21:01:21 +00:00
|
|
|
#include "stdafx.h"
|
2016-01-18 11:26:15 +00:00
|
|
|
#include <Project64-core/Plugins/PluginBase.h>
|
2016-02-01 06:33:19 +00:00
|
|
|
#include <Common/path.h>
|
2015-01-30 21:01:21 +00:00
|
|
|
|
|
|
|
CPlugin::CPlugin() :
|
2016-02-01 06:33:19 +00:00
|
|
|
DllAbout(NULL),
|
|
|
|
DllConfig(NULL),
|
|
|
|
CloseDLL(NULL),
|
|
|
|
RomOpen(NULL),
|
|
|
|
RomClosed(NULL),
|
|
|
|
PluginOpened(NULL),
|
|
|
|
SetSettingInfo(NULL),
|
|
|
|
SetSettingInfo2(NULL),
|
|
|
|
SetSettingInfo3(NULL),
|
|
|
|
m_LibHandle(NULL),
|
|
|
|
m_Initialized(false),
|
|
|
|
m_RomOpen(false)
|
2015-01-30 21:01:21 +00:00
|
|
|
{
|
2015-11-08 06:08:15 +00:00
|
|
|
memset(&m_PluginInfo, 0, sizeof(m_PluginInfo));
|
2015-01-30 21:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CPlugin::~CPlugin()
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Start");
|
2015-11-08 06:08:15 +00:00
|
|
|
UnloadPlugin();
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Done");
|
2015-01-30 21:01:21 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 18:23:00 +00:00
|
|
|
bool CPlugin::Load(const char * FileName)
|
2015-01-30 21:01:21 +00:00
|
|
|
{
|
2016-08-07 08:27:14 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Loading: %s", FileName);
|
2016-04-18 09:38:20 +00:00
|
|
|
|
2015-11-08 06:08:15 +00:00
|
|
|
// Already loaded, so unload first.
|
2016-01-17 18:48:19 +00:00
|
|
|
if (m_LibHandle != NULL)
|
2015-11-08 06:08:15 +00:00
|
|
|
{
|
|
|
|
UnloadPlugin();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to load the plugin DLL
|
|
|
|
//Try to load the DLL library
|
2018-01-15 21:23:21 +00:00
|
|
|
m_LibHandle = pjutil::DynLibOpen(FileName, HaveDebugger());
|
2016-08-07 08:27:14 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Loaded: %s LibHandle: %X", FileName, m_LibHandle);
|
|
|
|
|
2016-01-17 18:48:19 +00:00
|
|
|
if (m_LibHandle == NULL)
|
2015-11-08 06:08:15 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get DLL information
|
2016-01-17 18:48:19 +00:00
|
|
|
void(CALL *GetDllInfo) (PLUGIN_INFO * PluginInfo);
|
2015-11-08 06:08:15 +00:00
|
|
|
LoadFunction(GetDllInfo);
|
|
|
|
if (GetDllInfo == NULL) { return false; }
|
|
|
|
|
|
|
|
GetDllInfo(&m_PluginInfo);
|
|
|
|
if (!ValidPluginVersion(m_PluginInfo)) { return false; }
|
|
|
|
if (m_PluginInfo.Type != type()) { return false; }
|
|
|
|
|
2016-01-17 18:48:19 +00:00
|
|
|
LoadFunction(CloseDLL);
|
|
|
|
LoadFunction(RomOpen);
|
|
|
|
LoadFunction(RomClosed);
|
|
|
|
_LoadFunction("PluginLoaded", PluginOpened);
|
|
|
|
LoadFunction(DllConfig);
|
|
|
|
LoadFunction(DllAbout);
|
2015-11-08 06:08:15 +00:00
|
|
|
|
2017-04-18 11:32:43 +00:00
|
|
|
LoadFunction(SetPluginNotification);
|
|
|
|
if (SetPluginNotification)
|
|
|
|
{
|
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Found SetPluginNotification");
|
|
|
|
PLUGIN_NOTIFICATION info;
|
|
|
|
info.DisplayError = DisplayError;
|
|
|
|
info.FatalError = FatalError;
|
|
|
|
info.DisplayMessage = DisplayMessage;
|
|
|
|
info.DisplayMessage2 = DisplayMessage2;
|
|
|
|
info.BreakPoint = BreakPoint;
|
|
|
|
SetPluginNotification(&info);
|
|
|
|
}
|
|
|
|
|
2016-08-07 08:27:14 +00:00
|
|
|
LoadFunction(SetSettingNotificationInfo);
|
|
|
|
if (SetSettingNotificationInfo)
|
|
|
|
{
|
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Found SetSettingNotificationInfo");
|
|
|
|
PLUGIN_SETTINGS_NOTIFICATION info;
|
|
|
|
info.RegisterChangeCB = (void(*)(void *, int ID, void * Data, PLUGIN_SETTINGS_NOTIFICATION::SettingChangedFunc Func))CSettings::sRegisterChangeCB;
|
|
|
|
info.UnregisterChangeCB = (void(*)(void *, int ID, void * Data, PLUGIN_SETTINGS_NOTIFICATION::SettingChangedFunc Func))CSettings::sUnregisterChangeCB;
|
|
|
|
SetSettingNotificationInfo(&info);
|
|
|
|
}
|
|
|
|
|
2016-01-17 18:48:19 +00:00
|
|
|
LoadFunction(SetSettingInfo3);
|
2015-11-08 06:08:15 +00:00
|
|
|
if (SetSettingInfo3)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Found SetSettingInfo3");
|
2015-11-08 06:08:15 +00:00
|
|
|
PLUGIN_SETTINGS3 info;
|
2015-12-10 18:23:00 +00:00
|
|
|
info.FlushSettings = (void(*)(void * handle))CSettings::FlushSettings;
|
2015-11-08 06:08:15 +00:00
|
|
|
SetSettingInfo3(&info);
|
|
|
|
}
|
|
|
|
|
2016-01-17 18:48:19 +00:00
|
|
|
LoadFunction(SetSettingInfo2);
|
2015-11-08 06:08:15 +00:00
|
|
|
if (SetSettingInfo2)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Found SetSettingInfo2");
|
2015-11-08 06:08:15 +00:00
|
|
|
PLUGIN_SETTINGS2 info;
|
2015-12-10 18:23:00 +00:00
|
|
|
info.FindSystemSettingId = (uint32_t(*)(void * handle, const char *))CSettings::FindSetting;
|
2015-11-08 06:08:15 +00:00
|
|
|
SetSettingInfo2(&info);
|
|
|
|
}
|
|
|
|
|
2016-01-17 18:48:19 +00:00
|
|
|
LoadFunction(SetSettingInfo);
|
2015-11-08 06:08:15 +00:00
|
|
|
if (SetSettingInfo)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Found SetSettingInfo");
|
2015-11-08 06:08:15 +00:00
|
|
|
PLUGIN_SETTINGS info;
|
|
|
|
info.dwSize = sizeof(PLUGIN_SETTINGS);
|
|
|
|
info.DefaultStartRange = GetDefaultSettingStartRange();
|
|
|
|
info.SettingStartRange = GetSettingStartRange();
|
|
|
|
info.MaximumSettings = MaxPluginSetting;
|
|
|
|
info.NoDefault = Default_None;
|
|
|
|
info.DefaultLocation = g_Settings->LoadDword(Setting_UseFromRegistry) ? SettingType_Registry : SettingType_CfgFile;
|
|
|
|
info.handle = g_Settings;
|
|
|
|
info.RegisterSetting = (void(*)(void *, int, int, SettingDataType, SettingType, const char *, const char *, uint32_t))&CSettings::RegisterSetting;
|
|
|
|
info.GetSetting = (uint32_t(*)(void *, int))&CSettings::GetSetting;
|
|
|
|
info.GetSettingSz = (const char * (*)(void *, int, char *, int))&CSettings::GetSettingSz;
|
|
|
|
info.SetSetting = (void(*)(void *, int, uint32_t))&CSettings::SetSetting;
|
|
|
|
info.SetSettingSz = (void(*)(void *, int, const char *))&CSettings::SetSettingSz;
|
|
|
|
info.UseUnregisteredSetting = NULL;
|
|
|
|
|
|
|
|
SetSettingInfo(&info);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RomClosed == NULL)
|
2016-01-17 18:48:19 +00:00
|
|
|
{
|
2015-11-08 06:08:15 +00:00
|
|
|
return false;
|
2016-01-17 18:48:19 +00:00
|
|
|
}
|
2015-11-08 06:08:15 +00:00
|
|
|
|
|
|
|
if (!LoadFunctions())
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceWarning, "Failed to load functions");
|
2015-11-08 06:08:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Functions loaded");
|
2015-11-08 06:08:15 +00:00
|
|
|
|
|
|
|
if (PluginOpened)
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Before Plugin Opened");
|
2015-11-08 06:08:15 +00:00
|
|
|
PluginOpened();
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "After Plugin Opened");
|
2015-11-08 06:08:15 +00:00
|
|
|
}
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Loaded");
|
2015-11-08 06:08:15 +00:00
|
|
|
return true;
|
2015-01-30 21:01:21 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 09:38:20 +00:00
|
|
|
void CPlugin::RomOpened(RenderWindow * Render)
|
2015-01-30 21:01:21 +00:00
|
|
|
{
|
2015-11-08 06:08:15 +00:00
|
|
|
if (m_RomOpen)
|
2015-12-14 10:51:33 +00:00
|
|
|
{
|
2015-11-08 06:08:15 +00:00
|
|
|
return;
|
2015-12-14 10:51:33 +00:00
|
|
|
}
|
2015-11-08 06:08:15 +00:00
|
|
|
|
2016-04-18 09:38:20 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
if (m_PluginInfo.Type == PLUGIN_TYPE_GFX)
|
|
|
|
{
|
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Render = %p", Render);
|
|
|
|
if (Render != NULL)
|
|
|
|
{
|
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Calling GfxThreadInit");
|
|
|
|
Render->GfxThreadInit();
|
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "GfxThreadInit Done");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
Render = Render; // used just for andoid
|
|
|
|
#endif
|
|
|
|
|
2015-12-10 18:23:00 +00:00
|
|
|
if (RomOpen != NULL)
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Before Rom Open");
|
2015-11-08 06:08:15 +00:00
|
|
|
RomOpen();
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "After Rom Open");
|
2015-11-08 06:08:15 +00:00
|
|
|
}
|
2016-04-18 09:38:20 +00:00
|
|
|
|
2015-11-08 06:08:15 +00:00
|
|
|
m_RomOpen = true;
|
2015-01-30 21:01:21 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 09:38:20 +00:00
|
|
|
void CPlugin::RomClose(RenderWindow * Render)
|
2015-01-30 21:01:21 +00:00
|
|
|
{
|
2015-11-08 06:08:15 +00:00
|
|
|
if (!m_RomOpen)
|
2016-01-17 18:48:19 +00:00
|
|
|
{
|
2015-11-08 06:08:15 +00:00
|
|
|
return;
|
2016-01-17 18:48:19 +00:00
|
|
|
}
|
2015-01-30 21:01:21 +00:00
|
|
|
|
2016-04-18 09:38:20 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
if (m_PluginInfo.Type == PLUGIN_TYPE_GFX)
|
|
|
|
{
|
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Render = %p", Render);
|
|
|
|
if (Render != NULL)
|
|
|
|
{
|
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Calling GfxThreadDone");
|
|
|
|
Render->GfxThreadDone();
|
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "GfxThreadDone Done");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
Render = Render; // used just for andoid
|
|
|
|
#endif
|
|
|
|
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Before Rom Close");
|
2015-11-08 06:08:15 +00:00
|
|
|
RomClosed();
|
|
|
|
m_RomOpen = false;
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "After Rom Close");
|
2015-01-30 21:01:21 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 09:38:20 +00:00
|
|
|
void CPlugin::GameReset(RenderWindow * Render)
|
2015-01-30 21:01:21 +00:00
|
|
|
{
|
2015-11-08 06:08:15 +00:00
|
|
|
if (m_RomOpen)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
RomClose(Render);
|
|
|
|
RomOpened(Render);
|
2015-11-08 06:08:15 +00:00
|
|
|
}
|
2015-01-30 21:01:21 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 09:38:20 +00:00
|
|
|
void CPlugin::Close(RenderWindow * Render)
|
2015-01-30 21:01:21 +00:00
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "(%s): Start", PluginType());
|
2016-04-18 09:38:20 +00:00
|
|
|
RomClose(Render);
|
2018-11-24 02:52:35 +00:00
|
|
|
m_Initialized = false;
|
2018-11-26 00:53:39 +00:00
|
|
|
if (CloseDLL != NULL)
|
|
|
|
{
|
|
|
|
CloseDLL();
|
|
|
|
}
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "(%s): Done", PluginType());
|
2015-01-30 21:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugin::UnloadPlugin()
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "(%s): Start", PluginType());
|
2015-11-08 06:08:15 +00:00
|
|
|
memset(&m_PluginInfo, 0, sizeof(m_PluginInfo));
|
2016-01-17 18:48:19 +00:00
|
|
|
if (m_LibHandle != NULL)
|
2015-11-08 06:08:15 +00:00
|
|
|
{
|
|
|
|
UnloadPluginDetails();
|
2016-04-18 09:38:20 +00:00
|
|
|
}
|
|
|
|
if (m_LibHandle != NULL)
|
|
|
|
{
|
2016-01-17 18:48:19 +00:00
|
|
|
pjutil::DynLibClose(m_LibHandle);
|
|
|
|
m_LibHandle = NULL;
|
2015-11-08 06:08:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DllAbout = NULL;
|
|
|
|
CloseDLL = NULL;
|
|
|
|
RomOpen = NULL;
|
|
|
|
RomClosed = NULL;
|
|
|
|
PluginOpened = NULL;
|
|
|
|
DllConfig = NULL;
|
|
|
|
SetSettingInfo = NULL;
|
|
|
|
SetSettingInfo2 = NULL;
|
|
|
|
SetSettingInfo3 = NULL;
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "(%s): Done", PluginType());
|
2015-01-30 21:01:21 +00:00
|
|
|
}
|
2015-02-12 10:58:28 +00:00
|
|
|
|
2015-12-10 18:23:00 +00:00
|
|
|
const char * CPlugin::PluginType() const
|
2015-02-12 10:58:28 +00:00
|
|
|
{
|
2015-11-08 06:08:15 +00:00
|
|
|
switch (m_PluginInfo.Type)
|
|
|
|
{
|
|
|
|
case PLUGIN_TYPE_RSP: return "RSP";
|
|
|
|
case PLUGIN_TYPE_GFX: return "GFX";
|
|
|
|
case PLUGIN_TYPE_AUDIO: return "Audio";
|
|
|
|
case PLUGIN_TYPE_CONTROLLER: return "Control";
|
|
|
|
}
|
|
|
|
return "Unknown";
|
2015-02-12 10:58:28 +00:00
|
|
|
}
|
|
|
|
|
2015-12-14 10:51:33 +00:00
|
|
|
TraceModuleProject64 CPlugin::PluginTraceType() const
|
2015-02-12 10:58:28 +00:00
|
|
|
{
|
2015-11-08 06:08:15 +00:00
|
|
|
switch (m_PluginInfo.Type)
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
case PLUGIN_TYPE_RSP: return TraceRSPPlugin;
|
|
|
|
case PLUGIN_TYPE_GFX: return TraceGFXPlugin;
|
|
|
|
case PLUGIN_TYPE_AUDIO: return TraceAudioPlugin;
|
|
|
|
case PLUGIN_TYPE_CONTROLLER: return TraceControllerPlugin;
|
2015-11-08 06:08:15 +00:00
|
|
|
}
|
2016-08-07 08:27:14 +00:00
|
|
|
return TracePlugins;
|
2015-11-08 06:08:15 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 18:23:00 +00:00
|
|
|
bool CPlugin::ValidPluginVersion(PLUGIN_INFO & PluginInfo)
|
2015-11-08 06:08:15 +00:00
|
|
|
{
|
|
|
|
switch (PluginInfo.Type)
|
|
|
|
{
|
|
|
|
case PLUGIN_TYPE_RSP:
|
|
|
|
if (!PluginInfo.MemoryBswaped) { return false; }
|
2015-12-10 18:23:00 +00:00
|
|
|
if (PluginInfo.Version == 0x0001) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0100) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0101) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0102) { return true; }
|
2016-10-02 23:57:07 +00:00
|
|
|
if (PluginInfo.Version == 0x0103) { return true; }
|
2015-11-08 06:08:15 +00:00
|
|
|
break;
|
|
|
|
case PLUGIN_TYPE_GFX:
|
|
|
|
if (!PluginInfo.MemoryBswaped) { return false; }
|
2015-12-10 18:23:00 +00:00
|
|
|
if (PluginInfo.Version == 0x0102) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0103) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0104) { return true; }
|
2015-11-08 06:08:15 +00:00
|
|
|
break;
|
|
|
|
case PLUGIN_TYPE_AUDIO:
|
|
|
|
if (!PluginInfo.MemoryBswaped) { return false; }
|
2015-12-10 18:23:00 +00:00
|
|
|
if (PluginInfo.Version == 0x0101) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0102) { return true; }
|
2015-11-08 06:08:15 +00:00
|
|
|
break;
|
|
|
|
case PLUGIN_TYPE_CONTROLLER:
|
|
|
|
if (PluginInfo.Version == 0x0100) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0101) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0102) { return true; }
|
|
|
|
break;
|
|
|
|
}
|
2016-01-17 18:48:19 +00:00
|
|
|
return false;
|
2017-04-18 11:32:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugin::DisplayError(const char * Message)
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugin::FatalError(const char * Message)
|
|
|
|
{
|
|
|
|
g_Notify->FatalError(Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugin::DisplayMessage(int DisplayTime, const char * Message)
|
|
|
|
{
|
|
|
|
g_Notify->DisplayMessage(DisplayTime, Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugin::DisplayMessage2(const char * Message)
|
|
|
|
{
|
|
|
|
g_Notify->DisplayMessage2(Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugin::BreakPoint(const char * FileName, int32_t LineNumber)
|
|
|
|
{
|
|
|
|
g_Notify->BreakPoint(FileName, LineNumber);
|
|
|
|
}
|