2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project 64 - A Nintendo 64 emulator. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2010-06-07 02:23:58 +00:00
|
|
|
#include "stdafx.h"
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
CControl_Plugin::CControl_Plugin(void) :
|
2012-10-04 01:45:30 +00:00
|
|
|
m_AllocatedControllers(false),
|
|
|
|
WM_KeyDown(NULL),
|
|
|
|
WM_KeyUp(NULL),
|
|
|
|
RumbleCommand(NULL),
|
|
|
|
GetKeys(NULL),
|
|
|
|
ReadController(NULL),
|
2015-01-30 21:01:21 +00:00
|
|
|
ControllerCommand(NULL)
|
2012-10-04 01:45:30 +00:00
|
|
|
{
|
2015-01-30 21:01:21 +00:00
|
|
|
memset(&m_PluginControllers, 0, sizeof(m_PluginControllers));
|
|
|
|
memset(&m_Controllers, 0, sizeof(m_Controllers));
|
2012-10-04 01:45:30 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
CControl_Plugin::~CControl_Plugin()
|
2012-10-04 01:45:30 +00:00
|
|
|
{
|
2015-01-30 21:01:21 +00:00
|
|
|
Close();
|
2008-09-18 03:15:49 +00:00
|
|
|
UnloadPlugin();
|
2015-01-30 21:01:21 +00:00
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
bool CControl_Plugin::LoadFunctions ( void )
|
|
|
|
{
|
|
|
|
// Find entries for functions in DLL
|
|
|
|
void (__cdecl *InitiateControllers)( void );
|
|
|
|
LoadFunction(InitiateControllers);
|
|
|
|
LoadFunction(ControllerCommand);
|
|
|
|
LoadFunction(GetKeys);
|
|
|
|
LoadFunction(ReadController);
|
|
|
|
LoadFunction(WM_KeyDown);
|
|
|
|
LoadFunction(WM_KeyUp);
|
|
|
|
LoadFunction(RumbleCommand);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Make sure dll had all needed functions
|
2015-01-30 21:01:21 +00:00
|
|
|
if (InitiateControllers == NULL) { UnloadPlugin(); return false; }
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
if (m_PluginInfo.Version >= 0x0102)
|
2013-04-24 05:03:21 +00:00
|
|
|
{
|
2015-01-30 21:01:21 +00:00
|
|
|
if (PluginOpened == NULL) { UnloadPlugin(); return false; }
|
2013-04-24 05:03:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
// Allocate our own controller
|
|
|
|
m_AllocatedControllers = true;
|
|
|
|
for (int i = 0; i < 4; i++)
|
2008-12-04 10:41:51 +00:00
|
|
|
{
|
2015-01-30 21:01:21 +00:00
|
|
|
m_Controllers[i] = new CCONTROL(m_PluginControllers[i].Present, m_PluginControllers[i].RawData, m_PluginControllers[i].Plugin);
|
2008-12-04 10:41:51 +00:00
|
|
|
}
|
2015-01-30 21:01:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-12-04 10:41:51 +00:00
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
bool CControl_Plugin::Initiate(CN64System * System, CMainGui * RenderWindow)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++)
|
2008-12-01 18:19:49 +00:00
|
|
|
{
|
2015-01-30 21:01:21 +00:00
|
|
|
m_PluginControllers[i].Present = FALSE;
|
|
|
|
m_PluginControllers[i].RawData = FALSE;
|
|
|
|
m_PluginControllers[i].Plugin = PLUGIN_NONE;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
// Test Plugin version
|
|
|
|
if (m_PluginInfo.Version == 0x0100)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
//Get Function from DLL
|
|
|
|
void (__cdecl *InitiateControllers_1_0)( HWND hMainWindow, CONTROL Controls[4] );
|
2012-10-04 01:45:30 +00:00
|
|
|
InitiateControllers_1_0 = (void (__cdecl *)(HWND, CONTROL *))GetProcAddress( (HMODULE)m_hDll, "InitiateControllers" );
|
2008-09-18 03:15:49 +00:00
|
|
|
if (InitiateControllers_1_0 == NULL) { return false; }
|
|
|
|
InitiateControllers_1_0((HWND)RenderWindow->m_hMainWindow,m_PluginControllers);
|
2015-04-20 20:01:18 +00:00
|
|
|
m_Initialized = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2015-01-30 21:01:21 +00:00
|
|
|
else if (m_PluginInfo.Version >= 0x0101)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
typedef struct {
|
|
|
|
HWND hMainWindow;
|
|
|
|
HINSTANCE hinst;
|
|
|
|
|
|
|
|
BOOL MemoryBswaped; // If this is set to TRUE, then the memory has been pre
|
|
|
|
// bswap on a dword (32 bits) boundry, only effects header.
|
|
|
|
// eg. the first 8 bytes are stored like this:
|
|
|
|
// 4 3 2 1 8 7 6 5
|
|
|
|
BYTE * HEADER; // This is the rom header (first 40h bytes of the rom)
|
|
|
|
CONTROL *Controls; // A pointer to an array of 4 controllers .. eg:
|
|
|
|
// CONTROL Controls[4];
|
|
|
|
} CONTROL_INFO;
|
|
|
|
|
|
|
|
//Get Function from DLL
|
|
|
|
void (__cdecl *InitiateControllers_1_1)( CONTROL_INFO * ControlInfo );
|
2012-10-04 01:45:30 +00:00
|
|
|
InitiateControllers_1_1 = (void (__cdecl *)(CONTROL_INFO *))GetProcAddress( (HMODULE)m_hDll, "InitiateControllers" );
|
2008-09-18 03:15:49 +00:00
|
|
|
if (InitiateControllers_1_1 == NULL) { return false; }
|
|
|
|
|
|
|
|
CONTROL_INFO ControlInfo;
|
2015-01-30 21:01:21 +00:00
|
|
|
BYTE Buffer[100];
|
|
|
|
|
|
|
|
ControlInfo.Controls = m_PluginControllers;
|
|
|
|
ControlInfo.HEADER = (System == NULL ? Buffer : g_Rom->GetRomAddress());
|
|
|
|
ControlInfo.hinst = GetModuleHandle(NULL);
|
|
|
|
ControlInfo.hMainWindow = (HWND)RenderWindow->m_hMainWindow;
|
|
|
|
ControlInfo.MemoryBswaped = TRUE;
|
|
|
|
|
|
|
|
InitiateControllers_1_1(&ControlInfo);
|
2015-04-20 20:01:18 +00:00
|
|
|
m_Initialized = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//jabo had a bug so I call CreateThread so his dllmain gets called again
|
|
|
|
DWORD ThreadID;
|
2015-01-30 21:01:21 +00:00
|
|
|
HANDLE hthread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DummyFunction, NULL, 0, &ThreadID);
|
2008-09-18 03:15:49 +00:00
|
|
|
CloseHandle(hthread);
|
|
|
|
|
2015-04-20 20:01:18 +00:00
|
|
|
return m_Initialized;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
void CControl_Plugin::UnloadPluginDetails(void)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
if (m_AllocatedControllers)
|
2013-01-03 08:51:00 +00:00
|
|
|
{
|
2015-01-30 21:01:21 +00:00
|
|
|
for (int count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
delete m_Controllers[count];
|
|
|
|
m_Controllers[count] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
m_AllocatedControllers = false;
|
|
|
|
ControllerCommand = NULL;
|
|
|
|
GetKeys = NULL;
|
|
|
|
ReadController = NULL;
|
|
|
|
WM_KeyDown = NULL;
|
|
|
|
WM_KeyUp = NULL;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
void CControl_Plugin::UpdateKeys (void)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
if (!m_AllocatedControllers) { return; }
|
2015-01-30 21:01:21 +00:00
|
|
|
for (int cont = 0; cont < sizeof(m_Controllers) / sizeof(m_Controllers[0]); cont++)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
if (!m_Controllers[cont]->m_Present) { continue; }
|
|
|
|
if (!m_Controllers[cont]->m_RawData) {
|
|
|
|
GetKeys(cont,&m_Controllers[cont]->m_Buttons);
|
|
|
|
} else {
|
2015-03-11 19:50:30 +00:00
|
|
|
g_Notify->BreakPoint(__FILEW__,__LINE__);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-30 21:01:21 +00:00
|
|
|
if (ReadController) { ReadController(-1, NULL); }
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-31 00:21:08 +00:00
|
|
|
void CControl_Plugin::SetControl(CControl_Plugin const * const Plugin)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
if (m_AllocatedControllers) {
|
|
|
|
for (int count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++) {
|
|
|
|
delete m_Controllers[count];
|
|
|
|
m_Controllers[count] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_AllocatedControllers = false;
|
|
|
|
for (int count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++) {
|
|
|
|
m_Controllers[count] = Plugin->m_Controllers[count];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
CCONTROL::CCONTROL(DWORD &Present, DWORD &RawData, int &PlugType) :
|
|
|
|
m_Present(Present), m_RawData(RawData), m_PlugType(PlugType)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
m_Buttons.Value = 0;
|
2015-01-31 19:27:27 +00:00
|
|
|
}
|