[Project64] remove windows.h from plugin handling

This commit is contained in:
zilmar 2016-01-18 05:48:19 +11:00
parent 92e617d284
commit e8468687ac
13 changed files with 240 additions and 178 deletions

View File

@ -1,13 +1,61 @@
#include "stdafx.h" #include "stdafx.h"
#include "Util.h" #include "Util.h"
#ifdef _WIN32
#include <windows.h> #include <windows.h>
#include <Tlhelp32.h> #include <Tlhelp32.h>
#else
#include <unistd.h>
#endif
pjutil::DynLibHandle pjutil::DynLibOpen(const char *pccLibraryPath, bool ShowErrors)
{
if (pccLibraryPath == NULL)
{
return NULL;
}
UINT LastErrorMode = SetErrorMode(ShowErrors ? 0 : SEM_FAILCRITICALERRORS);
pjutil::DynLibHandle lib = (pjutil::DynLibHandle)LoadLibrary(pccLibraryPath);
SetErrorMode(LastErrorMode);
return lib;
}
void * pjutil::DynLibGetProc(pjutil::DynLibHandle LibHandle, const char * ProcedureName)
{
if (ProcedureName == NULL)
return NULL;
return GetProcAddress((HMODULE)LibHandle, ProcedureName);
}
void pjutil::DynLibClose(pjutil::DynLibHandle LibHandle)
{
FreeLibrary((HMODULE)LibHandle);
}
#ifdef _WIN32
static void EmptyThreadFunction(void)
{
}
void pjutil::DynLibCallDllMain(void)
{
//jabo had a bug so I call CreateThread so the dllmain in the plugins will get called again with thread attached
DWORD ThreadID;
HANDLE hthread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)EmptyThreadFunction, NULL, 0, &ThreadID);
CloseHandle(hthread);
}
#endif
void pjutil::Sleep(uint32_t timeout) void pjutil::Sleep(uint32_t timeout)
{ {
#ifdef _WIN32
::Sleep(timeout); ::Sleep(timeout);
#else
sleep(timeout);
#endif
} }
#ifdef _WIN32
bool pjutil::TerminatedExistingExe() bool pjutil::TerminatedExistingExe()
{ {
bool bTerminated = false; bool bTerminated = false;
@ -59,4 +107,5 @@ bool pjutil::TerminatedExistingExe()
CloseHandle(nSearch); CloseHandle(nSearch);
} }
return bTerminated; return bTerminated;
} }
#endif

View File

@ -4,6 +4,14 @@
class pjutil class pjutil
{ {
public: public:
typedef void * DynLibHandle;
static DynLibHandle DynLibOpen(const char *pccLibraryPath, bool ShowErrors = true);
static void * DynLibGetProc(DynLibHandle LibHandle, const char * ProcedureName);
static void DynLibClose(DynLibHandle LibHandle);
#ifdef _WIN32
static void DynLibCallDllMain(void);
#endif
static void Sleep(uint32_t timeout); static void Sleep(uint32_t timeout);
static bool TerminatedExistingExe(); static bool TerminatedExistingExe();

View File

@ -15,15 +15,17 @@
#include <Project64-core/N64System/Mips/RegisterClass.h> #include <Project64-core/N64System/Mips/RegisterClass.h>
#include <Project64-core/N64System/N64Class.h> #include <Project64-core/N64System/N64Class.h>
#include "AudioPlugin.h" #include "AudioPlugin.h"
#ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#endif
CAudioPlugin::CAudioPlugin() : CAudioPlugin::CAudioPlugin() :
AiLenChanged(NULL), AiLenChanged(NULL),
AiReadLength(NULL), AiReadLength(NULL),
ProcessAList(NULL), ProcessAList(NULL),
m_hAudioThread(NULL), m_hAudioThread(NULL),
AiUpdate(NULL), AiUpdate(NULL),
AiDacrateChanged(NULL) AiDacrateChanged(NULL)
{ {
} }
@ -36,7 +38,7 @@ CAudioPlugin::~CAudioPlugin()
bool CAudioPlugin::LoadFunctions(void) bool CAudioPlugin::LoadFunctions(void)
{ {
// Find entries for functions in DLL // Find entries for functions in DLL
void(__cdecl *InitiateAudio) (void); void(CALL *InitiateAudio)(void);
LoadFunction(InitiateAudio); LoadFunction(InitiateAudio);
LoadFunction(AiDacrateChanged); LoadFunction(AiDacrateChanged);
LoadFunction(AiLenChanged); LoadFunction(AiLenChanged);
@ -85,11 +87,11 @@ bool CAudioPlugin::Initiate(CN64System * System, RenderWindow * Window)
uint32_t * AI__DACRATE_REG; uint32_t * AI__DACRATE_REG;
uint32_t * AI__BITRATE_REG; uint32_t * AI__BITRATE_REG;
void(__cdecl *CheckInterrupts)(void); void(CALL *CheckInterrupts)(void);
}; };
//Get Function from DLL //Get Function from DLL
int32_t(__cdecl *InitiateAudio)(AUDIO_INFO Audio_Info); int32_t(CALL *InitiateAudio)(AUDIO_INFO Audio_Info);
LoadFunction(InitiateAudio); LoadFunction(InitiateAudio);
if (InitiateAudio == NULL) { return false; } if (InitiateAudio == NULL) { return false; }
@ -137,10 +139,9 @@ bool CAudioPlugin::Initiate(CN64System * System, RenderWindow * Window)
m_Initialized = InitiateAudio(Info) != 0; m_Initialized = InitiateAudio(Info) != 0;
//jabo had a bug so I call CreateThread so his dllmain gets called again #ifdef _WIN32
DWORD ThreadID; //jabo had a bug so I call CreateThread so his dllmain gets called again
HANDLE hthread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DummyFunction, NULL, 0, &ThreadID); pjutil::DynLibCallDllMain();
CloseHandle(hthread);
if (System != NULL) if (System != NULL)
{ {
@ -151,6 +152,7 @@ bool CAudioPlugin::Initiate(CN64System * System, RenderWindow * Window)
WriteTrace(TraceAudioPlugin, TraceDebug, "Terminate Audio Thread"); WriteTrace(TraceAudioPlugin, TraceDebug, "Terminate Audio Thread");
TerminateThread(m_hAudioThread, 0); TerminateThread(m_hAudioThread, 0);
} }
DWORD ThreadID;
m_hAudioThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AudioThread, (LPVOID)this, 0, &ThreadID); m_hAudioThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AudioThread, (LPVOID)this, 0, &ThreadID);
} }
@ -159,6 +161,7 @@ bool CAudioPlugin::Initiate(CN64System * System, RenderWindow * Window)
DacrateChanged(System->SystemType()); DacrateChanged(System->SystemType());
} }
} }
#endif
return m_Initialized; return m_Initialized;
} }

View File

@ -13,16 +13,15 @@
#include <Project64-core/N64System/N64RomClass.h> #include <Project64-core/N64System/N64RomClass.h>
#include <Project64-core/N64System/Mips/RegisterClass.h> #include <Project64-core/N64System/Mips/RegisterClass.h>
#include "ControllerPlugin.h" #include "ControllerPlugin.h"
#include <Windows.h>
CControl_Plugin::CControl_Plugin(void) : CControl_Plugin::CControl_Plugin(void) :
WM_KeyDown(NULL), WM_KeyDown(NULL),
WM_KeyUp(NULL), WM_KeyUp(NULL),
RumbleCommand(NULL), RumbleCommand(NULL),
GetKeys(NULL), GetKeys(NULL),
ReadController(NULL), ReadController(NULL),
ControllerCommand(NULL), ControllerCommand(NULL),
m_AllocatedControllers(false) m_AllocatedControllers(false)
{ {
memset(&m_PluginControllers, 0, sizeof(m_PluginControllers)); memset(&m_PluginControllers, 0, sizeof(m_PluginControllers));
memset(&m_Controllers, 0, sizeof(m_Controllers)); memset(&m_Controllers, 0, sizeof(m_Controllers));
@ -37,7 +36,7 @@ CControl_Plugin::~CControl_Plugin()
bool CControl_Plugin::LoadFunctions(void) bool CControl_Plugin::LoadFunctions(void)
{ {
// Find entries for functions in DLL // Find entries for functions in DLL
void(__cdecl *InitiateControllers)(void); void(CALL *InitiateControllers)(void);
LoadFunction(InitiateControllers); LoadFunction(InitiateControllers);
LoadFunction(ControllerCommand); LoadFunction(ControllerCommand);
LoadFunction(GetKeys); LoadFunction(GetKeys);
@ -65,60 +64,60 @@ bool CControl_Plugin::LoadFunctions(void)
bool CControl_Plugin::Initiate(CN64System * System, RenderWindow * Window) bool CControl_Plugin::Initiate(CN64System * System, RenderWindow * Window)
{ {
CONTROL_INFO ControlInfo;
uint8_t Buffer[100]; uint8_t Buffer[100];
for (int32_t i = 0; i < 4; i++) for (int32_t i = 0; i < 4; i++)
{ {
m_PluginControllers[i].Present = FALSE; m_PluginControllers[i].Present = false;
m_PluginControllers[i].RawData = FALSE; m_PluginControllers[i].RawData = false;
m_PluginControllers[i].Plugin = PLUGIN_NONE; m_PluginControllers[i].Plugin = PLUGIN_NONE;
} }
if (m_PluginInfo.Version >= 0x0101)
{
ControlInfo.Controls = m_PluginControllers;
ControlInfo.HEADER = (System == NULL ? Buffer : g_Rom->GetRomAddress());
ControlInfo.hinst = GetModuleHandle(NULL);
ControlInfo.hMainWindow = Window ? (HWND)Window->GetWindowHandle() : NULL;
ControlInfo.MemoryBswaped = TRUE;
}
// Test Plugin version // Test Plugin version
if (m_PluginInfo.Version == 0x0100) if (m_PluginInfo.Version == 0x0100)
{ {
//Get Function from DLL //Get Function from DLL
void(__cdecl *InitiateControllers_1_0)(HWND hMainWindow, CONTROL Controls[4]); void(CALL *InitiateControllers_1_0)(void * hMainWindow, CONTROL Controls[4]);
InitiateControllers_1_0 = (void(__cdecl *)(HWND, CONTROL *))GetProcAddress((HMODULE)m_hDll, "InitiateControllers"); _LoadFunction("InitiateControllers",InitiateControllers_1_0);
if (InitiateControllers_1_0 == NULL) { return false; } if (InitiateControllers_1_0 == NULL) { return false; }
InitiateControllers_1_0((HWND)Window->GetWindowHandle(), m_PluginControllers); InitiateControllers_1_0(Window->GetWindowHandle(), m_PluginControllers);
m_Initialized = true; m_Initialized = true;
} }
else if (m_PluginInfo.Version == 0x0101) else if (m_PluginInfo.Version >= 0x0101)
{ {
//Get Function from DLL CONTROL_INFO ControlInfo;
void(__cdecl *InitiateControllers_1_1)(CONTROL_INFO ControlInfo); ControlInfo.Controls = m_PluginControllers;
InitiateControllers_1_1 = (void(__cdecl *)(CONTROL_INFO))GetProcAddress((HMODULE)m_hDll, "InitiateControllers"); ControlInfo.HEADER = (System == NULL ? Buffer : g_Rom->GetRomAddress());
if (InitiateControllers_1_1 == NULL) { return false; } ControlInfo.hinst = Window ? Window->GetModuleInstance() : NULL;
ControlInfo.hMainWindow = Window ? Window->GetWindowHandle() : NULL;
ControlInfo.MemoryBswaped = true;
InitiateControllers_1_1(ControlInfo); if (m_PluginInfo.Version == 0x0101)
m_Initialized = true; {
} //Get Function from DLL
else if (m_PluginInfo.Version >= 0x0102) void(CALL *InitiateControllers_1_1)(CONTROL_INFO ControlInfo);
{ _LoadFunction("InitiateControllers",InitiateControllers_1_1);
//Get Function from DLL if (InitiateControllers_1_1 == NULL) { return false; }
void(__cdecl *InitiateControllers_1_2)(CONTROL_INFO * ControlInfo);
InitiateControllers_1_2 = (void(__cdecl *)(CONTROL_INFO *))GetProcAddress((HMODULE)m_hDll, "InitiateControllers");
if (InitiateControllers_1_2 == NULL) { return false; }
InitiateControllers_1_2(&ControlInfo); InitiateControllers_1_1(ControlInfo);
m_Initialized = true; m_Initialized = true;
}
else if (m_PluginInfo.Version >= 0x0102)
{
//Get Function from DLL
void(CALL *InitiateControllers_1_2)(CONTROL_INFO * ControlInfo);
_LoadFunction("InitiateControllers",InitiateControllers_1_2);
if (InitiateControllers_1_2 == NULL) { return false; }
InitiateControllers_1_2(&ControlInfo);
m_Initialized = true;
}
} }
//jabo had a bug so I call CreateThread so his dllmain gets called again #ifdef _WIN32
DWORD ThreadID; //jabo had a bug so I call CreateThread so his dllmain gets called again
HANDLE hthread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DummyFunction, NULL, 0, &ThreadID); pjutil::DynLibCallDllMain();
CloseHandle(hthread); #endif
return m_Initialized; return m_Initialized;
} }
@ -178,7 +177,7 @@ void CControl_Plugin::SetControl(CControl_Plugin const * const Plugin)
} }
CCONTROL::CCONTROL(int32_t &Present, int32_t &RawData, int32_t &PlugType) : CCONTROL::CCONTROL(int32_t &Present, int32_t &RawData, int32_t &PlugType) :
m_Present(Present), m_RawData(RawData), m_PlugType(PlugType) m_Present(Present), m_RawData(RawData), m_PlugType(PlugType)
{ {
m_Buttons.Value = 0; m_Buttons.Value = 0;
} }

View File

@ -14,25 +14,24 @@
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h> #include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/Mips/RegisterClass.h> #include <Project64-core/N64System/Mips/RegisterClass.h>
#include "GFXPlugin.h" #include "GFXPlugin.h"
#include <Windows.h>
CGfxPlugin::CGfxPlugin() : CGfxPlugin::CGfxPlugin() :
CaptureScreen(NULL), CaptureScreen(NULL),
ChangeWindow(NULL), ChangeWindow(NULL),
DrawScreen(NULL), DrawScreen(NULL),
DrawStatus(NULL), DrawStatus(NULL),
MoveScreen(NULL), MoveScreen(NULL),
ProcessDList(NULL), ProcessDList(NULL),
ProcessRDPList(NULL), ProcessRDPList(NULL),
ShowCFB(NULL), ShowCFB(NULL),
UpdateScreen(NULL), UpdateScreen(NULL),
ViStatusChanged(NULL), ViStatusChanged(NULL),
ViWidthChanged(NULL), ViWidthChanged(NULL),
SoftReset(NULL), SoftReset(NULL),
GetRomBrowserMenu(NULL), GetRomBrowserMenu(NULL),
OnRomBrowserMenuItem(NULL), OnRomBrowserMenuItem(NULL),
GetDebugInfo(NULL), GetDebugInfo(NULL),
InitiateDebugger(NULL) InitiateDebugger(NULL)
{ {
memset(&m_GFXDebug, 0, sizeof(m_GFXDebug)); memset(&m_GFXDebug, 0, sizeof(m_GFXDebug));
} }
@ -46,7 +45,7 @@ CGfxPlugin::~CGfxPlugin()
bool CGfxPlugin::LoadFunctions(void) bool CGfxPlugin::LoadFunctions(void)
{ {
// Find entries for functions in DLL // Find entries for functions in DLL
int32_t(__cdecl *InitiateGFX) (void * Gfx_Info); int32_t(CALL *InitiateGFX) (void * Gfx_Info);
LoadFunction(InitiateGFX); LoadFunction(InitiateGFX);
LoadFunction(ChangeWindow); LoadFunction(ChangeWindow);
LoadFunction(DrawScreen); LoadFunction(DrawScreen);
@ -94,8 +93,9 @@ bool CGfxPlugin::LoadFunctions(void)
} }
if (GetDebugInfo != NULL) if (GetDebugInfo != NULL)
{
GetDebugInfo(&m_GFXDebug); GetDebugInfo(&m_GFXDebug);
}
return true; return true;
} }
@ -108,8 +108,8 @@ bool CGfxPlugin::Initiate(CN64System * System, RenderWindow * Window)
typedef struct typedef struct
{ {
HWND hWnd; /* Render window */ void * hWnd; /* Render window */
HWND hStatusBar; /* if render window does not have a status bar then this is NULL */ void * hStatusBar; /* if render window does not have a status bar then this is NULL */
int32_t MemoryBswaped; // If this is set to TRUE, then the memory has been pre int32_t MemoryBswaped; // If this is set to TRUE, then the memory has been pre
// bswap on a dword (32 bits) boundry // bswap on a dword (32 bits) boundry
@ -148,19 +148,19 @@ bool CGfxPlugin::Initiate(CN64System * System, RenderWindow * Window)
uint32_t * VI__X_SCALE_REG; uint32_t * VI__X_SCALE_REG;
uint32_t * VI__Y_SCALE_REG; uint32_t * VI__Y_SCALE_REG;
void(__cdecl *CheckInterrupts)(void); void(CALL *CheckInterrupts)(void);
} GFX_INFO; } GFX_INFO;
//Get Function from DLL //Get Function from DLL
int32_t(__cdecl *InitiateGFX)(GFX_INFO Gfx_Info); int32_t(CALL *InitiateGFX)(GFX_INFO Gfx_Info);
InitiateGFX = (int32_t(__cdecl *)(GFX_INFO))GetProcAddress((HMODULE)m_hDll, "InitiateGFX"); _LoadFunction("InitiateGFX",InitiateGFX);
if (InitiateGFX == NULL) { return false; } if (InitiateGFX == NULL) { return false; }
GFX_INFO Info = { 0 }; GFX_INFO Info = { 0 };
Info.MemoryBswaped = TRUE; Info.MemoryBswaped = true;
Info.hWnd = (HWND)Window->GetWindowHandle(); Info.hWnd = Window->GetWindowHandle();
Info.hStatusBar = (HWND)Window->GetStatusBar(); Info.hStatusBar = Window->GetStatusBar();
Info.CheckInterrupts = DummyCheckInterrupts; Info.CheckInterrupts = DummyCheckInterrupts;
// We are initializing the plugin before any rom is loaded so we do not have any correct // We are initializing the plugin before any rom is loaded so we do not have any correct
@ -224,20 +224,20 @@ bool CGfxPlugin::Initiate(CN64System * System, RenderWindow * Window)
m_Initialized = InitiateGFX(Info) != 0; m_Initialized = InitiateGFX(Info) != 0;
//jabo had a bug so I call CreateThread so his dllmain gets called again #ifdef _WIN32
DWORD ThreadID; //jabo had a bug so I call CreateThread so his dllmain gets called again
HANDLE hthread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DummyFunction, NULL, 0, &ThreadID); pjutil::DynLibCallDllMain();
CloseHandle(hthread); #endif
return m_Initialized; return m_Initialized;
} }
void CGfxPlugin::UnloadPluginDetails(void) void CGfxPlugin::UnloadPluginDetails(void)
{ {
if (m_hDll != NULL) if (m_LibHandle != NULL)
{ {
FreeLibrary((HMODULE)m_hDll); pjutil::DynLibClose(m_LibHandle);
m_hDll = NULL; m_LibHandle = NULL;
} }
memset(&m_GFXDebug, 0, sizeof(m_GFXDebug)); memset(&m_GFXDebug, 0, sizeof(m_GFXDebug));

View File

@ -10,21 +10,20 @@
****************************************************************************/ ****************************************************************************/
#include "stdafx.h" #include "stdafx.h"
#include "PluginBase.h" #include "PluginBase.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_LibHandle(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));
} }
@ -37,31 +36,21 @@ CPlugin::~CPlugin()
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_LibHandle != NULL)
{ {
UnloadPlugin(); UnloadPlugin();
} }
// Try to load the plugin DLL // Try to load the plugin DLL
//Try to load the DLL library //Try to load the DLL library
if (bHaveDebugger()) m_LibHandle = pjutil::DynLibOpen(FileName, bHaveDebugger());
{ if (m_LibHandle == NULL)
m_hDll = LoadLibrary(FileName);
}
else
{
UINT LastErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
m_hDll = LoadLibrary(FileName);
SetErrorMode(LastErrorMode);
}
if (m_hDll == NULL)
{ {
return false; return false;
} }
// Get DLL information // Get DLL information
void(__cdecl *GetDllInfo) (PLUGIN_INFO * PluginInfo); void(CALL *GetDllInfo) (PLUGIN_INFO * PluginInfo);
LoadFunction(GetDllInfo); LoadFunction(GetDllInfo);
if (GetDllInfo == NULL) { return false; } if (GetDllInfo == NULL) { return false; }
@ -69,14 +58,14 @@ 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"); LoadFunction(CloseDLL);
RomOpen = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "RomOpen"); LoadFunction(RomOpen);
RomClosed = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "RomClosed"); LoadFunction(RomClosed);
PluginOpened = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "PluginLoaded"); _LoadFunction("PluginLoaded", PluginOpened);
DllConfig = (void(__cdecl *)(void *)) GetProcAddress((HMODULE)m_hDll, "DllConfig"); LoadFunction(DllConfig);
DllAbout = (void(__cdecl *)(void *)) GetProcAddress((HMODULE)m_hDll, "DllAbout"); LoadFunction(DllAbout);
SetSettingInfo3 = (void(__cdecl *)(PLUGIN_SETTINGS3 *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo3"); LoadFunction(SetSettingInfo3);
if (SetSettingInfo3) if (SetSettingInfo3)
{ {
PLUGIN_SETTINGS3 info; PLUGIN_SETTINGS3 info;
@ -84,7 +73,7 @@ bool CPlugin::Load(const char * FileName)
SetSettingInfo3(&info); SetSettingInfo3(&info);
} }
SetSettingInfo2 = (void(__cdecl *)(PLUGIN_SETTINGS2 *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo2"); LoadFunction(SetSettingInfo2);
if (SetSettingInfo2) if (SetSettingInfo2)
{ {
PLUGIN_SETTINGS2 info; PLUGIN_SETTINGS2 info;
@ -92,7 +81,7 @@ bool CPlugin::Load(const char * FileName)
SetSettingInfo2(&info); SetSettingInfo2(&info);
} }
SetSettingInfo = (void(__cdecl *)(PLUGIN_SETTINGS *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo"); LoadFunction(SetSettingInfo);
if (SetSettingInfo) if (SetSettingInfo)
{ {
PLUGIN_SETTINGS info; PLUGIN_SETTINGS info;
@ -114,7 +103,9 @@ bool CPlugin::Load(const char * FileName)
} }
if (RomClosed == NULL) if (RomClosed == NULL)
{
return false; return false;
}
if (!LoadFunctions()) if (!LoadFunctions())
{ {
@ -150,7 +141,9 @@ void CPlugin::RomOpened()
void CPlugin::RomClose() void CPlugin::RomClose()
{ {
if (!m_RomOpen) if (!m_RomOpen)
{
return; return;
}
WriteTrace(PluginTraceType(), TraceDebug, "Before Rom Close"); WriteTrace(PluginTraceType(), TraceDebug, "Before Rom Close");
RomClosed(); RomClosed();
@ -186,11 +179,11 @@ void CPlugin::UnloadPlugin()
{ {
WriteTrace(PluginTraceType(), TraceDebug, "(%s): unloading", PluginType()); WriteTrace(PluginTraceType(), TraceDebug, "(%s): unloading", PluginType());
memset(&m_PluginInfo, 0, sizeof(m_PluginInfo)); memset(&m_PluginInfo, 0, sizeof(m_PluginInfo));
if (m_hDll != NULL) if (m_LibHandle != NULL)
{ {
UnloadPluginDetails(); UnloadPluginDetails();
FreeLibrary((HMODULE)m_hDll); pjutil::DynLibClose(m_LibHandle);
m_hDll = NULL; m_LibHandle = NULL;
} }
DllAbout = NULL; DllAbout = NULL;
@ -256,5 +249,5 @@ bool CPlugin::ValidPluginVersion(PLUGIN_INFO & PluginInfo)
if (PluginInfo.Version == 0x0102) { return true; } if (PluginInfo.Version == 0x0102) { return true; }
break; break;
} }
return FALSE; return false;
} }

View File

@ -12,7 +12,8 @@
#include <Project64-core/Settings/DebugSettings.h> #include <Project64-core/Settings/DebugSettings.h>
#include <Project64-core/TraceModulesProject64.h> #include <Project64-core/TraceModulesProject64.h>
#include "PluginClass.h" #include <Project64-core/Plugins/PluginClass.h>
#include <Common/Util.h>
#if defined(_WIN32) #if defined(_WIN32)
#define CALL __cdecl #define CALL __cdecl
@ -60,17 +61,18 @@ protected:
void(CALL *SetSettingInfo2) (PLUGIN_SETTINGS2 *); void(CALL *SetSettingInfo2) (PLUGIN_SETTINGS2 *);
void(CALL *SetSettingInfo3) (PLUGIN_SETTINGS3 *); void(CALL *SetSettingInfo3) (PLUGIN_SETTINGS3 *);
void * m_hDll; pjutil::DynLibHandle m_LibHandle;
bool m_Initialized, m_RomOpen; bool m_Initialized, m_RomOpen;
PLUGIN_INFO m_PluginInfo; PLUGIN_INFO m_PluginInfo;
// Loads a function pointer from the currently loaded DLL // Loads a function pointer from the currently loaded DLL
template <typename T> void _LoadFunctionVoid(const char * szFunctionName, void ** functionPointer)
void _LoadFunction(const char * szFunctionName, T & functionPointer) { {
functionPointer = (T)GetProcAddress((HMODULE)m_hDll, szFunctionName); *functionPointer = pjutil::DynLibGetProc(m_LibHandle, szFunctionName);
} }
// Simple wrapper around _LoadFunction() to avoid having to specify the same two arguments // Simple wrapper around _LoadFunction() to avoid having to specify the same two arguments
// i.e. _LoadFunction("CloseDLL", CloseDLL); // i.e. _LoadFunction("CloseDLL", CloseDLL);
#define LoadFunction(functionName) _LoadFunction(#functionName, functionName) #define LoadFunction(functionName) _LoadFunctionVoid(#functionName, (void **)&functionName)
#define _LoadFunction(functionName,function) _LoadFunctionVoid(functionName, (void **)&function)
}; };

View File

@ -11,17 +11,17 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/N64Class.h> #include <Project64-core/N64System/N64Class.h>
#include <Project64-core/Plugins/PluginClass.h>
#include <Common/path.h> #include <Common/path.h>
#include "PluginClass.h"
CPlugins::CPlugins(const stdstr & PluginDir) : CPlugins::CPlugins(const stdstr & PluginDir) :
m_MainWindow(NULL), m_MainWindow(NULL),
m_SyncWindow(NULL), m_SyncWindow(NULL),
m_PluginDir(PluginDir), m_PluginDir(PluginDir),
m_Gfx(NULL), m_Gfx(NULL),
m_Audio(NULL), m_Audio(NULL),
m_RSP(NULL), m_RSP(NULL),
m_Control(NULL) m_Control(NULL)
{ {
CreatePlugins(); CreatePlugins();
g_Settings->RegisterChangeCB(Plugin_RSP_Current, this, (CSettings::SettingChangedFunc)PluginChanged); g_Settings->RegisterChangeCB(Plugin_RSP_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
@ -288,7 +288,7 @@ bool CPlugins::Reset(CN64System * System)
if (m_Gfx && bGfxChange) if (m_Gfx && bGfxChange)
{ {
WriteTrace(TraceGFXPlugin, TraceDebug, "Gfx Initiate Starting"); WriteTrace(TraceGFXPlugin, TraceDebug, "Gfx Initiate Starting");
if (!m_Gfx->Initiate(System, m_MainWindow)) { return false; } if (!m_Gfx->Initiate(System, m_MainWindow)) { return false; }
WriteTrace(TraceGFXPlugin, TraceDebug, "Gfx Initiate Done"); WriteTrace(TraceGFXPlugin, TraceDebug, "Gfx Initiate Done");
} }
if (m_Audio && bAudioChange) if (m_Audio && bAudioChange)
@ -306,7 +306,7 @@ bool CPlugins::Reset(CN64System * System)
if (m_RSP && bRspChange) if (m_RSP && bRspChange)
{ {
WriteTrace(TraceRSPPlugin, TraceDebug, "RSP Initiate Starting"); WriteTrace(TraceRSPPlugin, TraceDebug, "RSP Initiate Starting");
if (!m_RSP->Initiate(this, System)) { return false; } if (!m_RSP->Initiate(this, System)) { return false; }
WriteTrace(TraceRSPPlugin, TraceDebug, "RSP Initiate Done"); WriteTrace(TraceRSPPlugin, TraceDebug, "RSP Initiate Done");
} }
WriteTrace(TracePlugins, TraceDebug, "Done"); WriteTrace(TracePlugins, TraceDebug, "Done");

View File

@ -90,6 +90,7 @@ __interface RenderWindow
virtual bool ResetPluginsInUiThread(CPlugins * plugins, CN64System * System) = 0; virtual bool ResetPluginsInUiThread(CPlugins * plugins, CN64System * System) = 0;
virtual void * GetWindowHandle(void) const = 0; virtual void * GetWindowHandle(void) const = 0;
virtual void * GetStatusBar(void) const = 0; virtual void * GetStatusBar(void) const = 0;
virtual void * GetModuleInstance(void) const = 0;
}; };
class CPlugins : class CPlugins :

View File

@ -15,16 +15,15 @@
#include "RSPPlugin.h" #include "RSPPlugin.h"
#include "GFXPlugin.h" #include "GFXPlugin.h"
#include "AudioPlugin.h" #include "AudioPlugin.h"
#include <Windows.h>
void DummyFunc1(int a) { a += 1; } void DummyFunc1(int a) { a += 1; }
CRSP_Plugin::CRSP_Plugin(void) : CRSP_Plugin::CRSP_Plugin(void) :
DoRspCycles(NULL), DoRspCycles(NULL),
EnableDebugging(NULL), EnableDebugging(NULL),
m_CycleCount(0), m_CycleCount(0),
GetDebugInfo(NULL), GetDebugInfo(NULL),
InitiateDebugger(NULL) InitiateDebugger(NULL)
{ {
memset(&m_RSPDebug, 0, sizeof(m_RSPDebug)); memset(&m_RSPDebug, 0, sizeof(m_RSPDebug));
} }
@ -38,7 +37,7 @@ CRSP_Plugin::~CRSP_Plugin()
bool CRSP_Plugin::LoadFunctions(void) bool CRSP_Plugin::LoadFunctions(void)
{ {
// Find entries for functions in DLL // Find entries for functions in DLL
void(__cdecl *InitiateRSP)(void); void(CALL *InitiateRSP)(void);
LoadFunction(InitiateRSP); LoadFunction(InitiateRSP);
LoadFunction(DoRspCycles); LoadFunction(DoRspCycles);
_LoadFunction("GetRspDebugInfo", GetDebugInfo); _LoadFunction("GetRspDebugInfo", GetDebugInfo);
@ -59,8 +58,9 @@ bool CRSP_Plugin::LoadFunctions(void)
// Get debug info if able // Get debug info if able
if (GetDebugInfo != NULL) if (GetDebugInfo != NULL)
{
GetDebugInfo(&m_RSPDebug); GetDebugInfo(&m_RSPDebug);
}
return true; return true;
} }
@ -73,7 +73,7 @@ bool CRSP_Plugin::Initiate(CPlugins * Plugins, CN64System * System)
typedef struct typedef struct
{ {
HINSTANCE hInst; void * hInst;
int MemoryBswaped; /* If this is set to TRUE, then the memory has been pre int MemoryBswaped; /* If this is set to TRUE, then the memory has been pre
bswap on a dword (32 bits) boundry */ bswap on a dword (32 bits) boundry */
uint8_t * RDRAM; uint8_t * RDRAM;
@ -101,21 +101,21 @@ bool CRSP_Plugin::Initiate(CPlugins * Plugins, CN64System * System)
uint32_t * DPC__PIPEBUSY_REG; uint32_t * DPC__PIPEBUSY_REG;
uint32_t * DPC__TMEM_REG; uint32_t * DPC__TMEM_REG;
void(__cdecl *CheckInterrupts)(void); void(CALL *CheckInterrupts)(void);
void(__cdecl *ProcessDlist)(void); void(CALL *ProcessDlist)(void);
void(__cdecl *ProcessAlist)(void); void(CALL *ProcessAlist)(void);
void(__cdecl *ProcessRdpList)(void); void(CALL *ProcessRdpList)(void);
void(__cdecl *ShowCFB)(void); void(CALL *ShowCFB)(void);
} RSP_INFO_1_1; } RSP_INFO_1_1;
RSP_INFO_1_1 Info = { 0 }; RSP_INFO_1_1 Info = { 0 };
Info.hInst = GetModuleHandle(NULL); Info.hInst = Plugins->MainWindow()->GetModuleInstance();
Info.CheckInterrupts = DummyCheckInterrupts; Info.CheckInterrupts = DummyCheckInterrupts;
Info.MemoryBswaped = (System == NULL); // only true when the system's not yet loaded Info.MemoryBswaped = (System == NULL); // only true when the system's not yet loaded
//Get Function from DLL //Get Function from DLL
void(__cdecl *InitiateRSP) (RSP_INFO_1_1 Audio_Info, uint32_t * Cycles); void(CALL *InitiateRSP) (RSP_INFO_1_1 Audio_Info, uint32_t * Cycles);
LoadFunction(InitiateRSP); LoadFunction(InitiateRSP);
if (InitiateRSP == NULL) { return false; } if (InitiateRSP == NULL) { return false; }
@ -193,10 +193,10 @@ bool CRSP_Plugin::Initiate(CPlugins * Plugins, CN64System * System)
InitiateRSP(Info, &m_CycleCount); InitiateRSP(Info, &m_CycleCount);
m_Initialized = true; m_Initialized = true;
//jabo had a bug so I call CreateThread so his dllmain gets called again #ifdef _WIN32
DWORD ThreadID; //jabo had a bug so I call CreateThread so his dllmain gets called again
HANDLE hthread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DummyFunction, NULL, 0, &ThreadID); pjutil::DynLibCallDllMain();
CloseHandle(hthread); #endif
return m_Initialized; return m_Initialized;
} }

View File

@ -0,0 +1 @@
#include "../stdafx.h"

View File

@ -24,14 +24,14 @@ LRESULT CALLBACK MainGui_Proc(HWND WndHandle, DWORD uMsg, DWORD wParam, DWORD lP
extern BOOL set_about_field(HWND hDlg, int nIDDlgItem, const wchar_t * config_string, const wchar_t * language_string); extern BOOL set_about_field(HWND hDlg, int nIDDlgItem, const wchar_t * config_string, const wchar_t * language_string);
CMainGui::CMainGui(bool bMainWindow, const char * WindowTitle) : CMainGui::CMainGui(bool bMainWindow, const char * WindowTitle) :
CRomBrowser(m_hMainWindow, m_hStatusWnd), CRomBrowser(m_hMainWindow, m_hStatusWnd),
m_ThreadId(GetCurrentThreadId()), m_ThreadId(GetCurrentThreadId()),
m_bMainWindow(bMainWindow), m_bMainWindow(bMainWindow),
m_Created(false), m_Created(false),
m_AttachingMenu(false), m_AttachingMenu(false),
m_MakingVisible(false), m_MakingVisible(false),
m_ResetPlugins(false), m_ResetPlugins(false),
m_ResetInfo(NULL) m_ResetInfo(NULL)
{ {
m_Menu = NULL; m_Menu = NULL;
@ -273,6 +273,11 @@ void CMainGui::ChangeWinSize(long width, long height)
MoveWindow(m_hMainWindow, wndpl.rcNormalPosition.left, wndpl.rcNormalPosition.top, rc1.right - rc1.left, rc1.bottom - rc1.top, TRUE); MoveWindow(m_hMainWindow, wndpl.rcNormalPosition.left, wndpl.rcNormalPosition.top, rc1.right - rc1.left, rc1.bottom - rc1.top, TRUE);
} }
void * CMainGui::GetModuleInstance(void) const
{
return GetModuleHandle(NULL);
}
void CMainGui::AboutBox(void) void CMainGui::AboutBox(void)
{ {
DialogBoxParamW(GetModuleHandle(NULL), MAKEINTRESOURCEW(IDD_About), m_hMainWindow, (DLGPROC)AboutBoxProc, (LPARAM)this); DialogBoxParamW(GetModuleHandle(NULL), MAKEINTRESOURCEW(IDD_About), m_hMainWindow, (DLGPROC)AboutBoxProc, (LPARAM)this);

View File

@ -89,6 +89,7 @@ public:
//Get Window Handle //Get Window Handle
void * GetWindowHandle(void) const { return m_hMainWindow; } void * GetWindowHandle(void) const { return m_hMainWindow; }
void * GetStatusBar(void) const { return m_hStatusWnd; } void * GetStatusBar(void) const { return m_hStatusWnd; }
void * GetModuleInstance(void) const;
private: private:
CMainGui(void); // Disable default constructor CMainGui(void); // Disable default constructor