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/N64Rom.h>
|
|
|
|
#include <Project64-core/N64System/Mips/Register.h>
|
2016-01-27 09:11:59 +00:00
|
|
|
#include "ControllerPlugin.h"
|
|
|
|
|
|
|
|
CControl_Plugin::CControl_Plugin(void) :
|
2021-04-12 11:35:39 +00:00
|
|
|
WM_KeyDown(nullptr),
|
|
|
|
WM_KeyUp(nullptr),
|
|
|
|
RumbleCommand(nullptr),
|
|
|
|
GetKeys(nullptr),
|
|
|
|
ReadController(nullptr),
|
|
|
|
ControllerCommand(nullptr),
|
2016-01-27 09:11:59 +00:00
|
|
|
m_AllocatedControllers(false)
|
|
|
|
{
|
|
|
|
memset(&m_PluginControllers, 0, sizeof(m_PluginControllers));
|
|
|
|
memset(&m_Controllers, 0, sizeof(m_Controllers));
|
|
|
|
}
|
|
|
|
|
|
|
|
CControl_Plugin::~CControl_Plugin()
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
Close(nullptr);
|
2016-01-27 09:11:59 +00:00
|
|
|
UnloadPlugin();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CControl_Plugin::LoadFunctions(void)
|
|
|
|
{
|
|
|
|
// Find entries for functions in DLL
|
|
|
|
void(CALL *InitiateControllers)(void);
|
|
|
|
LoadFunction(InitiateControllers);
|
|
|
|
LoadFunction(ControllerCommand);
|
|
|
|
LoadFunction(GetKeys);
|
|
|
|
LoadFunction(ReadController);
|
|
|
|
LoadFunction(WM_KeyDown);
|
|
|
|
LoadFunction(WM_KeyUp);
|
|
|
|
LoadFunction(RumbleCommand);
|
2022-01-09 11:13:12 +00:00
|
|
|
LoadFunction(WM_KillFocus);
|
|
|
|
LoadFunction(EmulationPaused);
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Make sure DLL had all needed functions
|
2021-04-12 11:35:39 +00:00
|
|
|
if (InitiateControllers == nullptr) { UnloadPlugin(); return false; }
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
if (m_PluginInfo.Version >= 0x0102)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (PluginOpened == nullptr) { UnloadPlugin(); return false; }
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate our own controller
|
|
|
|
m_AllocatedControllers = true;
|
|
|
|
for (int32_t i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
m_Controllers[i] = new CCONTROL(m_PluginControllers[i].Present, m_PluginControllers[i].RawData, m_PluginControllers[i].Plugin);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CControl_Plugin::Initiate(CN64System * System, RenderWindow * Window)
|
|
|
|
{
|
2016-06-16 10:59:13 +00:00
|
|
|
static uint8_t Buffer[100];
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
for (int32_t i = 0; i < 4; i++)
|
|
|
|
{
|
2022-01-09 11:13:12 +00:00
|
|
|
m_PluginControllers[i].Present = PRESENT_NONE;
|
2016-01-27 09:11:59 +00:00
|
|
|
m_PluginControllers[i].RawData = false;
|
|
|
|
m_PluginControllers[i].Plugin = PLUGIN_NONE;
|
|
|
|
}
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Test plugin version
|
2016-01-27 09:11:59 +00:00
|
|
|
if (m_PluginInfo.Version == 0x0100)
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
// Get function from DLL
|
2016-01-27 09:11:59 +00:00
|
|
|
void(CALL *InitiateControllers_1_0)(void * hMainWindow, CONTROL Controls[4]);
|
2016-04-18 09:38:20 +00:00
|
|
|
_LoadFunction("InitiateControllers", InitiateControllers_1_0);
|
2021-04-12 11:35:39 +00:00
|
|
|
if (InitiateControllers_1_0 == nullptr) { return false; }
|
2016-04-18 09:38:20 +00:00
|
|
|
#ifdef _WIN32
|
2016-01-27 09:11:59 +00:00
|
|
|
InitiateControllers_1_0(Window->GetWindowHandle(), m_PluginControllers);
|
2016-04-18 09:38:20 +00:00
|
|
|
#else
|
2021-04-12 11:35:39 +00:00
|
|
|
InitiateControllers_1_0(nullptr, m_PluginControllers);
|
2016-04-18 09:38:20 +00:00
|
|
|
#endif
|
2016-01-27 09:11:59 +00:00
|
|
|
m_Initialized = true;
|
|
|
|
}
|
|
|
|
else if (m_PluginInfo.Version >= 0x0101)
|
|
|
|
{
|
|
|
|
CONTROL_INFO ControlInfo;
|
|
|
|
ControlInfo.Controls = m_PluginControllers;
|
2021-04-12 11:35:39 +00:00
|
|
|
ControlInfo.HEADER = (System == nullptr ? Buffer : g_Rom->GetRomAddress());
|
2016-04-18 09:38:20 +00:00
|
|
|
#ifdef _WIN32
|
2021-04-12 11:35:39 +00:00
|
|
|
ControlInfo.hinst = Window ? Window->GetModuleInstance() : nullptr;
|
|
|
|
ControlInfo.hMainWindow = Window ? Window->GetWindowHandle() : nullptr;
|
2016-04-18 09:38:20 +00:00
|
|
|
#else
|
2021-04-12 11:35:39 +00:00
|
|
|
ControlInfo.hinst = nullptr;
|
|
|
|
ControlInfo.hMainWindow = nullptr;
|
2016-04-18 09:38:20 +00:00
|
|
|
#endif
|
2016-01-27 09:11:59 +00:00
|
|
|
ControlInfo.MemoryBswaped = true;
|
|
|
|
|
|
|
|
if (m_PluginInfo.Version == 0x0101)
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
// Get function from DLL
|
2016-01-27 09:11:59 +00:00
|
|
|
void(CALL *InitiateControllers_1_1)(CONTROL_INFO ControlInfo);
|
2016-04-18 09:38:20 +00:00
|
|
|
_LoadFunction("InitiateControllers", InitiateControllers_1_1);
|
2021-04-12 11:35:39 +00:00
|
|
|
if (InitiateControllers_1_1 == nullptr) { return false; }
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
InitiateControllers_1_1(ControlInfo);
|
|
|
|
m_Initialized = true;
|
|
|
|
}
|
|
|
|
else if (m_PluginInfo.Version >= 0x0102)
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
// Get function from DLL
|
2016-01-27 09:11:59 +00:00
|
|
|
void(CALL *InitiateControllers_1_2)(CONTROL_INFO * ControlInfo);
|
2016-04-18 09:38:20 +00:00
|
|
|
_LoadFunction("InitiateControllers", InitiateControllers_1_2);
|
2021-04-12 11:35:39 +00:00
|
|
|
if (InitiateControllers_1_2 == nullptr) { return false; }
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
InitiateControllers_1_2(&ControlInfo);
|
|
|
|
m_Initialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_Initialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CControl_Plugin::UnloadPluginDetails(void)
|
|
|
|
{
|
|
|
|
if (m_AllocatedControllers)
|
|
|
|
{
|
|
|
|
for (int32_t count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++)
|
|
|
|
{
|
|
|
|
delete m_Controllers[count];
|
2021-04-12 11:35:39 +00:00
|
|
|
m_Controllers[count] = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_AllocatedControllers = false;
|
2021-04-12 11:35:39 +00:00
|
|
|
ControllerCommand = nullptr;
|
|
|
|
GetKeys = nullptr;
|
|
|
|
ReadController = nullptr;
|
|
|
|
WM_KeyDown = nullptr;
|
|
|
|
WM_KeyUp = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CControl_Plugin::UpdateKeys(void)
|
|
|
|
{
|
|
|
|
if (!m_AllocatedControllers) { return; }
|
|
|
|
for (int32_t cont = 0; cont < sizeof(m_Controllers) / sizeof(m_Controllers[0]); cont++)
|
|
|
|
{
|
2020-07-07 02:06:10 +00:00
|
|
|
if (!m_Controllers[cont]->Present()) { continue; }
|
2016-01-27 09:11:59 +00:00
|
|
|
if (!m_Controllers[cont]->m_RawData)
|
|
|
|
{
|
|
|
|
GetKeys(cont, &m_Controllers[cont]->m_Buttons);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
|
|
|
}
|
|
|
|
}
|
2021-04-12 11:35:39 +00:00
|
|
|
if (ReadController) { ReadController(-1, nullptr); }
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CControl_Plugin::SetControl(CControl_Plugin const * const Plugin)
|
|
|
|
{
|
|
|
|
if (m_AllocatedControllers)
|
|
|
|
{
|
|
|
|
for (int32_t count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++)
|
|
|
|
{
|
|
|
|
delete m_Controllers[count];
|
2021-04-12 11:35:39 +00:00
|
|
|
m_Controllers[count] = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_AllocatedControllers = false;
|
|
|
|
for (int32_t count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++)
|
|
|
|
{
|
|
|
|
m_Controllers[count] = Plugin->m_Controllers[count];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCONTROL::CCONTROL(int32_t &Present, int32_t &RawData, int32_t &PlugType) :
|
|
|
|
m_Present(Present), m_RawData(RawData), m_PlugType(PlugType)
|
|
|
|
{
|
|
|
|
m_Buttons.Value = 0;
|
|
|
|
}
|