2016-01-27 09:11:59 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include <Project64-core/N64System/SystemGlobals.h>
|
2021-04-14 05:34:15 +00:00
|
|
|
#include <Project64-core/N64System/N64System.h>
|
|
|
|
#include <Project64-core/Plugins/Plugin.h>
|
2016-01-27 09:11:59 +00:00
|
|
|
#include <Common/path.h>
|
|
|
|
|
2016-08-07 08:27:14 +00:00
|
|
|
CPlugins::CPlugins(SettingID PluginDirSetting, bool SyncPlugins) :
|
2021-04-14 05:34:15 +00:00
|
|
|
m_MainWindow(nullptr),
|
|
|
|
m_SyncWindow(nullptr),
|
|
|
|
m_PluginDirSetting(PluginDirSetting),
|
|
|
|
m_PluginDir(g_Settings->LoadStringVal(PluginDirSetting)),
|
|
|
|
m_Gfx(nullptr),
|
|
|
|
m_Audio(nullptr),
|
|
|
|
m_RSP(nullptr),
|
|
|
|
m_Control(nullptr),
|
|
|
|
m_initilized(false),
|
|
|
|
m_SyncPlugins(SyncPlugins)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
CreatePlugins();
|
|
|
|
g_Settings->RegisterChangeCB(Plugin_RSP_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Plugin_GFX_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Plugin_AUDIO_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Plugin_CONT_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Plugin_UseHleGfx, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Plugin_UseHleAudio, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Game_EditPlugin_Gfx, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Game_EditPlugin_Audio, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Game_EditPlugin_Contr, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Game_EditPlugin_RSP, this, (CSettings::SettingChangedFunc)PluginChanged);
|
2016-02-01 06:33:19 +00:00
|
|
|
g_Settings->RegisterChangeCB(m_PluginDirSetting, this, (CSettings::SettingChangedFunc)PluginChanged);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CPlugins::~CPlugins(void)
|
|
|
|
{
|
|
|
|
g_Settings->UnregisterChangeCB(Plugin_RSP_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Plugin_GFX_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Plugin_AUDIO_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Plugin_CONT_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Plugin_UseHleGfx, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Plugin_UseHleAudio, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Game_EditPlugin_Gfx, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Game_EditPlugin_Audio, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Game_EditPlugin_Contr, this, (CSettings::SettingChangedFunc)PluginChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Game_EditPlugin_RSP, this, (CSettings::SettingChangedFunc)PluginChanged);
|
2016-02-01 06:33:19 +00:00
|
|
|
g_Settings->UnregisterChangeCB(m_PluginDirSetting, this, (CSettings::SettingChangedFunc)PluginChanged);
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
DestroyGfxPlugin();
|
|
|
|
DestroyAudioPlugin();
|
|
|
|
DestroyRspPlugin();
|
|
|
|
DestroyControlPlugin();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugins::PluginChanged(CPlugins * _this)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Start");
|
2016-01-27 09:11:59 +00:00
|
|
|
if (g_Settings->LoadBool(Game_TempLoaded) == true)
|
|
|
|
{
|
2016-02-01 06:33:19 +00:00
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Game is temporary loaded, not changing plugins");
|
2016-01-27 09:11:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-02-01 06:33:19 +00:00
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
bool bGfxChange = _stricmp(_this->m_GfxFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str()) != 0;
|
|
|
|
bool bAudioChange = _stricmp(_this->m_AudioFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Audio).c_str()) != 0;
|
|
|
|
bool bRspChange = _stricmp(_this->m_RSPFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_RSP).c_str()) != 0;
|
|
|
|
bool bContChange = _stricmp(_this->m_ControlFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Controller).c_str()) != 0;
|
2016-04-18 09:38:20 +00:00
|
|
|
bool bDirChange = _stricmp(_this->m_PluginDir.c_str(), g_Settings->LoadStringVal(_this->m_PluginDirSetting).c_str()) != 0;
|
2016-08-07 08:27:14 +00:00
|
|
|
WriteTrace(TracePlugins, TraceVerbose, "m_GfxFile: \"%s\" Game_Plugin_Gfx: \"%s\" changed: %s", _this->m_GfxFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str(), bGfxChange ? "true" : "false");
|
2022-07-18 12:56:29 +00:00
|
|
|
WriteTrace(TracePlugins, TraceVerbose, "m_AudioFile: \"%s\" Game_Plugin_Audio: \"%s\" changed: %s", _this->m_AudioFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Audio).c_str(), bAudioChange ? "true" : "false");
|
|
|
|
WriteTrace(TracePlugins, TraceVerbose, "m_RSPFile: \"%s\" Game_Plugin_RSP: \"%s\" changed: %s", _this->m_RSPFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_RSP).c_str(), bRspChange ? "true" : "false");
|
|
|
|
WriteTrace(TracePlugins, TraceVerbose, "m_ControlFile: \"%s\" Game_Plugin_Controller: \"%s\" changed: %s", _this->m_ControlFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Controller).c_str(), bContChange ? "true" : "false");
|
2016-08-07 08:27:14 +00:00
|
|
|
WriteTrace(TracePlugins, TraceVerbose, "m_PluginDir: \"%s\" m_PluginDirSetting: \"%s\" changed: %s", _this->m_PluginDir.c_str(), g_Settings->LoadStringVal(_this->m_PluginDirSetting).c_str(), bDirChange ? "true" : "false");
|
2016-04-18 09:38:20 +00:00
|
|
|
if (bDirChange)
|
2016-02-01 06:33:19 +00:00
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Plugin directory changed");
|
2016-02-01 06:33:19 +00:00
|
|
|
bGfxChange = true;
|
|
|
|
bAudioChange = true;
|
|
|
|
bRspChange = true;
|
|
|
|
bContChange = true;
|
2016-04-18 09:38:20 +00:00
|
|
|
_this->m_PluginDir = g_Settings->LoadStringVal(_this->m_PluginDirSetting);
|
2016-02-01 06:33:19 +00:00
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
if (bGfxChange || bAudioChange || bRspChange || bContChange)
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
if (bGfxChange) { WriteTrace(TracePlugins, TraceDebug, "GFX plugin changed"); }
|
2016-02-01 06:33:19 +00:00
|
|
|
if (bAudioChange) { WriteTrace(TracePlugins, TraceDebug, "Audio plugin changed"); }
|
|
|
|
if (bRspChange) { WriteTrace(TracePlugins, TraceDebug, "RSP plugin changed"); }
|
|
|
|
if (bContChange) { WriteTrace(TracePlugins, TraceDebug, "Controller plugin changed"); }
|
2016-01-27 09:11:59 +00:00
|
|
|
if (g_Settings->LoadBool(GameRunning_CPU_Running))
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
// Ensure that base system actually exists before we go triggering the event
|
2016-01-27 09:11:59 +00:00
|
|
|
if (g_BaseSystem)
|
|
|
|
{
|
|
|
|
g_BaseSystem->ExternalEvent(SysEvent_ChangePlugins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
_this->Reset(nullptr);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-01 06:33:19 +00:00
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Done");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename plugin_type>
|
2016-08-07 08:27:14 +00:00
|
|
|
static void LoadPlugin(SettingID PluginSettingID, SettingID PluginVerSettingID, plugin_type * & plugin, const char * PluginDir, stdstr & FileName, TraceModuleProject64 TraceLevel, const char * type, bool IsCopy)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (plugin != nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FileName = g_Settings->LoadStringVal(PluginSettingID);
|
|
|
|
CPath PluginFileName(PluginDir, FileName.c_str());
|
2016-08-07 08:27:14 +00:00
|
|
|
if (IsCopy)
|
|
|
|
{
|
|
|
|
PluginFileName.SetName(stdstr_f("%s-copy", PluginFileName.GetName().c_str()).c_str());
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
plugin = new plugin_type();
|
|
|
|
if (plugin)
|
|
|
|
{
|
|
|
|
WriteTrace(TraceLevel, TraceDebug, "%s Loading (%s): Starting", type, (const char *)PluginFileName);
|
|
|
|
if (plugin->Load(PluginFileName))
|
|
|
|
{
|
|
|
|
WriteTrace(TraceLevel, TraceDebug, "%s Current Ver: %s", type, plugin->PluginName());
|
|
|
|
g_Settings->SaveString(PluginVerSettingID, plugin->PluginName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-01 06:33:19 +00:00
|
|
|
WriteTrace(TraceLevel, TraceError, "Failed to load %s", (const char *)PluginFileName);
|
2016-01-27 09:11:59 +00:00
|
|
|
delete plugin;
|
2021-04-12 11:35:39 +00:00
|
|
|
plugin = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceLevel, TraceDebug, "%s Loading done", type);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-01 06:33:19 +00:00
|
|
|
WriteTrace(TraceLevel, TraceError, "Failed to allocate %s plugin", type);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugins::CreatePlugins(void)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(TracePlugins, TraceInfo, "Start");
|
2016-08-07 08:27:14 +00:00
|
|
|
|
2022-06-27 10:02:38 +00:00
|
|
|
LoadPlugin(Game_Plugin_Gfx, Plugin_GFX_CurVer, m_Gfx, m_PluginDir.c_str(), m_GfxFile, TraceVideoPlugin, "GFX", m_SyncPlugins);
|
2016-08-07 08:27:14 +00:00
|
|
|
LoadPlugin(Game_Plugin_Audio, Plugin_AUDIO_CurVer, m_Audio, m_PluginDir.c_str(), m_AudioFile, TraceAudioPlugin, "Audio", m_SyncPlugins);
|
|
|
|
LoadPlugin(Game_Plugin_RSP, Plugin_RSP_CurVer, m_RSP, m_PluginDir.c_str(), m_RSPFile, TraceRSPPlugin, "RSP", m_SyncPlugins);
|
|
|
|
LoadPlugin(Game_Plugin_Controller, Plugin_CONT_CurVer, m_Control, m_PluginDir.c_str(), m_ControlFile, TraceControllerPlugin, "Control", m_SyncPlugins);
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Enable debugger
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_RSP != nullptr && m_RSP->EnableDebugging)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
WriteTrace(TraceRSPPlugin, TraceInfo, "EnableDebugging starting");
|
2018-01-15 21:23:21 +00:00
|
|
|
m_RSP->EnableDebugging(HaveDebugger());
|
2016-01-27 09:11:59 +00:00
|
|
|
WriteTrace(TraceRSPPlugin, TraceInfo, "EnableDebugging done");
|
|
|
|
}
|
2016-04-18 09:38:20 +00:00
|
|
|
WriteTrace(TracePlugins, TraceInfo, "Done");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugins::GameReset(void)
|
|
|
|
{
|
|
|
|
if (m_Gfx)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
m_Gfx->GameReset(m_MainWindow);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
if (m_Audio)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
m_Audio->GameReset(m_MainWindow);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
if (m_RSP)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
m_RSP->GameReset(m_MainWindow);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
if (m_Control)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
m_Control->GameReset(m_MainWindow);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugins::DestroyGfxPlugin(void)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_Gfx == nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "Before close");
|
2016-09-26 10:51:55 +00:00
|
|
|
m_Gfx->Close(m_MainWindow);
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceInfo, "Deleting");
|
2016-01-27 09:11:59 +00:00
|
|
|
delete m_Gfx;
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceInfo, "m_Gfx deleted");
|
2021-04-12 11:35:39 +00:00
|
|
|
m_Gfx = nullptr;
|
|
|
|
// g_Settings->UnknownSetting_GFX = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
DestroyRspPlugin();
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceInfo, "Done");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugins::DestroyAudioPlugin(void)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_Audio == nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAudioPlugin, TraceDebug, "Before close");
|
2016-04-18 09:38:20 +00:00
|
|
|
m_Audio->Close(m_MainWindow);
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAudioPlugin, TraceDebug, "Before delete");
|
2016-01-27 09:11:59 +00:00
|
|
|
delete m_Audio;
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAudioPlugin, TraceDebug, "After delete");
|
2021-04-12 11:35:39 +00:00
|
|
|
m_Audio = nullptr;
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAudioPlugin, TraceDebug, "Before DestroyRspPlugin");
|
2021-04-12 11:35:39 +00:00
|
|
|
// g_Settings->UnknownSetting_AUDIO = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
DestroyRspPlugin();
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAudioPlugin, TraceDebug, "After DestroyRspPlugin");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugins::DestroyRspPlugin(void)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_RSP == nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceRSPPlugin, TraceDebug, "Before close");
|
2016-04-18 09:38:20 +00:00
|
|
|
m_RSP->Close(m_MainWindow);
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceRSPPlugin, TraceDebug, "Before delete");
|
2016-01-27 09:11:59 +00:00
|
|
|
delete m_RSP;
|
2021-04-12 11:35:39 +00:00
|
|
|
m_RSP = nullptr;
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceRSPPlugin, TraceDebug, "After delete");
|
2021-04-12 11:35:39 +00:00
|
|
|
// g_Settings->UnknownSetting_RSP = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugins::DestroyControlPlugin(void)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_Control == nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceControllerPlugin, TraceDebug, "Before close");
|
2016-04-18 09:38:20 +00:00
|
|
|
m_Control->Close(m_MainWindow);
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceControllerPlugin, TraceDebug, "Before delete");
|
2016-01-27 09:11:59 +00:00
|
|
|
delete m_Control;
|
2021-04-12 11:35:39 +00:00
|
|
|
m_Control = nullptr;
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceControllerPlugin, TraceDebug, "After delete");
|
2021-04-12 11:35:39 +00:00
|
|
|
// g_Settings->UnknownSetting_CTRL = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugins::SetRenderWindows(RenderWindow * MainWindow, RenderWindow * SyncWindow)
|
|
|
|
{
|
2016-08-07 08:27:14 +00:00
|
|
|
WriteTrace(TracePlugins, TraceDebug, "MainWindow = %p SyncWindow = %p", MainWindow, SyncWindow);
|
2016-01-27 09:11:59 +00:00
|
|
|
m_MainWindow = MainWindow;
|
|
|
|
m_SyncWindow = SyncWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugins::RomOpened(void)
|
|
|
|
{
|
2016-08-07 08:27:14 +00:00
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Start");
|
2016-06-16 10:59:13 +00:00
|
|
|
|
2016-04-18 09:38:20 +00:00
|
|
|
m_Gfx->RomOpened(m_MainWindow);
|
|
|
|
m_RSP->RomOpened(m_MainWindow);
|
|
|
|
m_Audio->RomOpened(m_MainWindow);
|
|
|
|
m_Control->RomOpened(m_MainWindow);
|
2016-06-16 10:59:13 +00:00
|
|
|
|
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Done");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugins::RomClosed(void)
|
|
|
|
{
|
2016-08-07 08:27:14 +00:00
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Start");
|
2016-06-16 10:59:13 +00:00
|
|
|
|
2016-04-18 09:38:20 +00:00
|
|
|
m_Gfx->RomClose(m_MainWindow);
|
|
|
|
m_RSP->RomClose(m_MainWindow);
|
|
|
|
m_Audio->RomClose(m_MainWindow);
|
|
|
|
m_Control->RomClose(m_MainWindow);
|
2016-06-16 10:59:13 +00:00
|
|
|
|
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Done");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CPlugins::Initiate(CN64System * System)
|
|
|
|
{
|
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Start");
|
2021-05-18 11:51:36 +00:00
|
|
|
// Check to make sure we have the plugin available to be used
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_Gfx == nullptr) { return false; }
|
|
|
|
if (m_Audio == nullptr) { return false; }
|
|
|
|
if (m_RSP == nullptr) { return false; }
|
|
|
|
if (m_Control == nullptr) { return false; }
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "GFX initiate starting");
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_Gfx->Initiate(System, m_MainWindow)) { return false; }
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "GFX initiate done");
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAudioPlugin, TraceDebug, "Audio initiate starting");
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_Audio->Initiate(System, m_MainWindow)) { return false; }
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAudioPlugin, TraceDebug, "Audio initiate done");
|
|
|
|
WriteTrace(TraceControllerPlugin, TraceDebug, "Control initiate starting");
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_Control->Initiate(System, m_MainWindow)) { return false; }
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceControllerPlugin, TraceDebug, "Control initiate done");
|
|
|
|
WriteTrace(TraceRSPPlugin, TraceDebug, "RSP initiate starting");
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_RSP->Initiate(this, System)) { return false; }
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceRSPPlugin, TraceDebug, "RSP initiate done");
|
2016-01-27 09:11:59 +00:00
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Done");
|
2016-06-16 10:59:13 +00:00
|
|
|
m_initilized = true;
|
2016-01-27 09:11:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPlugins::ResetInUiThread(CN64System * System)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
#ifdef _WIN32
|
2016-01-27 09:11:59 +00:00
|
|
|
return m_MainWindow->ResetPluginsInUiThread(this, System);
|
2016-04-18 09:38:20 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CPlugins::Reset(CN64System * System)
|
|
|
|
{
|
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Start");
|
|
|
|
|
|
|
|
bool bGfxChange = _stricmp(m_GfxFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str()) != 0;
|
|
|
|
bool bAudioChange = _stricmp(m_AudioFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Audio).c_str()) != 0;
|
|
|
|
bool bRspChange = _stricmp(m_RSPFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_RSP).c_str()) != 0;
|
|
|
|
bool bContChange = _stricmp(m_ControlFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Controller).c_str()) != 0;
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// If GFX and audio has changed we also need to force reset of RSP
|
2016-01-27 09:11:59 +00:00
|
|
|
if (bGfxChange || bAudioChange)
|
2016-09-26 10:51:55 +00:00
|
|
|
{
|
2016-01-27 09:11:59 +00:00
|
|
|
bRspChange = true;
|
2016-09-26 10:51:55 +00:00
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
if (bGfxChange) { DestroyGfxPlugin(); }
|
|
|
|
if (bAudioChange) { DestroyAudioPlugin(); }
|
|
|
|
if (bRspChange) { DestroyRspPlugin(); }
|
|
|
|
if (bContChange) { DestroyControlPlugin(); }
|
|
|
|
|
|
|
|
CreatePlugins();
|
|
|
|
|
|
|
|
if (m_Gfx && bGfxChange)
|
|
|
|
{
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "GFX initiate starting");
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_Gfx->Initiate(System, m_MainWindow)) { return false; }
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "GFX initiate done");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
if (m_Audio && bAudioChange)
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAudioPlugin, TraceDebug, "Audio initiate starting");
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_Audio->Initiate(System, m_MainWindow)) { return false; }
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceAudioPlugin, TraceDebug, "Audio initiate done");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
if (m_Control && bContChange)
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceControllerPlugin, TraceDebug, "Control initiate starting");
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_Control->Initiate(System, m_MainWindow)) { return false; }
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceControllerPlugin, TraceDebug, "Control initiate done");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
if (m_RSP && bRspChange)
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceRSPPlugin, TraceDebug, "RSP initiate starting");
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_RSP->Initiate(this, System)) { return false; }
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceRSPPlugin, TraceDebug, "RSP initiate done");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
2018-12-20 10:19:14 +00:00
|
|
|
|
|
|
|
if (System)
|
|
|
|
{
|
|
|
|
System->RefreshSyncToAudio();
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
WriteTrace(TracePlugins, TraceDebug, "Done");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlugins::ConfigPlugin(void* hParent, PLUGIN_TYPE Type)
|
|
|
|
{
|
2017-09-25 07:12:32 +00:00
|
|
|
if (g_BaseSystem)
|
|
|
|
{
|
|
|
|
g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_Settings);
|
|
|
|
}
|
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
switch (Type)
|
|
|
|
{
|
|
|
|
case PLUGIN_TYPE_RSP:
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_RSP == nullptr || m_RSP->DllConfig == nullptr) { break; }
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_RSP->Initialized())
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (!m_RSP->Initiate(this, nullptr))
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_RSP->DllConfig(hParent);
|
|
|
|
break;
|
2022-06-27 10:02:38 +00:00
|
|
|
case PLUGIN_TYPE_VIDEO:
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_Gfx == nullptr || m_Gfx->DllConfig == nullptr) { break; }
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_Gfx->Initialized())
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (!m_Gfx->Initiate(nullptr, m_MainWindow))
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_Gfx->DllConfig(hParent);
|
|
|
|
break;
|
|
|
|
case PLUGIN_TYPE_AUDIO:
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_Audio == nullptr || m_Audio->DllConfig == nullptr) { break; }
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_Audio->Initialized())
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (!m_Audio->Initiate(nullptr, m_MainWindow))
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_Audio->DllConfig(hParent);
|
2021-02-02 03:10:12 +00:00
|
|
|
if (g_BaseSystem)
|
|
|
|
{
|
|
|
|
g_BaseSystem->RefreshSyncToAudio();
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
break;
|
|
|
|
case PLUGIN_TYPE_CONTROLLER:
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_Control == nullptr || m_Control->DllConfig == nullptr) { break; }
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_Control->Initialized())
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (!m_Control->Initiate(nullptr, m_MainWindow))
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_Control->DllConfig(hParent);
|
|
|
|
break;
|
2016-11-27 20:34:02 +00:00
|
|
|
case PLUGIN_TYPE_NONE:
|
|
|
|
default:
|
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
2017-09-25 07:12:32 +00:00
|
|
|
|
|
|
|
if (g_BaseSystem)
|
|
|
|
{
|
|
|
|
g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_Settings);
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DummyCheckInterrupts(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DummyFunction(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPlugins::CopyPlugins(const stdstr & DstDir) const
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
// Copy GFX plugin
|
2016-01-27 09:11:59 +00:00
|
|
|
CPath srcGfxPlugin(m_PluginDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str());
|
|
|
|
CPath dstGfxPlugin(DstDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str());
|
2016-08-07 08:27:14 +00:00
|
|
|
dstGfxPlugin.SetName(stdstr_f("%s-copy", dstGfxPlugin.GetName().c_str()).c_str());
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
if (!dstGfxPlugin.DirectoryExists())
|
|
|
|
{
|
|
|
|
dstGfxPlugin.DirectoryCreate();
|
|
|
|
}
|
|
|
|
if (!srcGfxPlugin.CopyTo(dstGfxPlugin))
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TracePlugins, TraceError, "Failed to copy %s to %s", (const char *)srcGfxPlugin, (const char *)dstGfxPlugin);
|
2016-01-27 09:11:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Copy m_Audio plugin
|
2016-01-27 09:11:59 +00:00
|
|
|
CPath srcAudioPlugin(m_PluginDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Audio).c_str());
|
|
|
|
CPath dstAudioPlugin(DstDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Audio).c_str());
|
2016-08-07 08:27:14 +00:00
|
|
|
dstAudioPlugin.SetName(stdstr_f("%s-copy", dstAudioPlugin.GetName().c_str()).c_str());
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!dstAudioPlugin.DirectoryExists())
|
|
|
|
{
|
|
|
|
dstAudioPlugin.DirectoryCreate();
|
|
|
|
}
|
|
|
|
if (!srcAudioPlugin.CopyTo(dstAudioPlugin))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-18 11:51:36 +00:00
|
|
|
// Copy RSP plugin
|
2016-01-27 09:11:59 +00:00
|
|
|
CPath srcRSPPlugin(m_PluginDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_RSP).c_str());
|
|
|
|
CPath dstRSPPlugin(DstDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_RSP).c_str());
|
2016-08-07 08:27:14 +00:00
|
|
|
dstRSPPlugin.SetName(stdstr_f("%s-copy", dstRSPPlugin.GetName().c_str()).c_str());
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!dstRSPPlugin.DirectoryExists())
|
|
|
|
{
|
|
|
|
dstRSPPlugin.DirectoryCreate();
|
|
|
|
}
|
|
|
|
if (!srcRSPPlugin.CopyTo(dstRSPPlugin))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Copy Controller plugin
|
2016-01-27 09:11:59 +00:00
|
|
|
CPath srcContPlugin(m_PluginDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Controller).c_str());
|
|
|
|
CPath dstContPlugin(DstDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Controller).c_str());
|
2016-08-07 08:27:14 +00:00
|
|
|
dstContPlugin.SetName(stdstr_f("%s-copy", dstContPlugin.GetName().c_str()).c_str());
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!dstContPlugin.DirectoryExists())
|
|
|
|
{
|
|
|
|
dstContPlugin.DirectoryCreate();
|
|
|
|
}
|
|
|
|
if (!srcContPlugin.CopyTo(dstContPlugin))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2015-11-15 20:10:01 +00:00
|
|
|
}
|