project64/Source/nragev20/NRagePluginV2.h

399 lines
13 KiB
C
Raw Normal View History

2016-01-27 09:11:59 +00:00
/*
2020-02-09 11:36:49 +00:00
N-Rage`s Dinput8 Plugin
(C) 2002, 2006 Norbert Wladyka
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
Author`s Email: norbert.wladyka@chello.at
Website: http://go.to/nrage
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the free Software Foundation; either version 2 of the License, or
(at your option) any later version.
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
You should have received a copy of the GNU General Public License
along with this program; if not, write to the free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
2016-01-27 09:11:59 +00:00
#ifndef _NRAGEPLUGIN_
#define _NRAGEPLUGIN_
#include <dinput.h>
2016-01-27 09:11:59 +00:00
#include "XInputController.h"
/////////////////////////////////////////////////////////////////////////////////
//General Plugin
2020-02-09 11:36:49 +00:00
#define TIMER_MESSAGEWINDOW 123
2016-01-27 09:11:59 +00:00
// maximum number of devices other than SysMouse
2020-02-09 11:36:49 +00:00
#define MAX_DEVICES 32
2016-01-27 09:11:59 +00:00
// maximum number of modifiers
2020-02-09 11:36:49 +00:00
#define MAX_MODIFIERS 256
#define DEFAULT_STICKRANGE 66
#define DEFAULT_DEADZONE 5
#define DEFAULT_RUMBLETYP RUMBLE_EFF1
#define DEFAULT_RUMBLESTRENGTH 80
#define DEFAULT_MOUSESENSIVITY 100
#define DEFAULT_PAKTYPE PAK_MEM
#define DEFAULT_MOUSEMOVE MM_BUFF
#define PAK_NONE 0
#define PAK_MEM 1
#define PAK_RUMBLE 2
#define PAK_TRANSFER 3
#define PAK_VOICE 4
#define PAK_ADAPTOID 7
2016-01-27 09:11:59 +00:00
// just used to display text in GUI
2020-02-09 11:36:49 +00:00
#define PAK_NONRAW 16
2016-01-27 09:11:59 +00:00
typedef struct _EMULATOR_INFO
{
2020-02-09 11:36:49 +00:00
bool fInitialisedPlugin;
HWND hMainWindow;
HINSTANCE hinst;
LANGID Language;
bool fDisplayShortPop; // do we display shortcut message popups?
2016-01-27 09:11:59 +00:00
/*
* 2015.11.09 cxd4
* Added to keep the real address of the CONTROL array stored.
*
* This became necessary due to conflicts between specs #1.0, #1.1 and #1.2.
*/
CONTROL * controllers;
2020-02-09 11:36:49 +00:00
// 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)
2016-01-27 09:11:59 +00:00
} EMULATOR_INFO, *LPEMULATOR_INFO;
typedef struct _DEVICE
{
2020-02-09 11:36:49 +00:00
LPDIRECTINPUTDEVICE8 didHandle;
TCHAR szProductName[MAX_PATH];
BYTE bProductCounter;
GUID guidInstance;
DWORD dwDevType; // can be DI8DEVTYPE_KEYBOARD, DI8DEVTYPE_MOUSE, etc
BYTE bEffType; // What rumble effects does this device support?
union INPUTSTATE // the last polled data from this device
{
DIJOYSTATE joyState;
DIMOUSESTATE2 mouseState;
BYTE rgbButtons[256]; // keyboard state
} stateAs;
2016-01-27 09:11:59 +00:00
} DEVICE, *LPDEVICE;
typedef struct _BUTTON
{
2020-02-09 11:36:49 +00:00
bool fPrevPressed; // Was this button pressed last time we checked? (not to be saved in config)
BYTE bOffset; // Offset in the DirectInput data structure
BYTE bAxisID; // Tells which range of the Axe/POV is important (see AI_AXE_P, AI_POV_UP, etc)
BYTE bBtnType; // Type of device/button: Keyboard key, Joystick axis, Joystick button, Mouse axis, etc
LPDEVICE parentDevice; // pointer to the DEVICE this assignment came from
2016-01-27 09:11:59 +00:00
} BUTTON, *LPBUTTON;
// Modifiers are a feature built into NRage. Emulator turbo buttons, macros, stuff like that.
typedef struct _MODIFIER
{
2020-02-09 11:36:49 +00:00
BUTTON btnButton; // button to associate with
BYTE bModType; // Type of modifier (None, Movement, Macro, Config)
BOOL fToggle; // false if you have to hold the button down to activate, true if the modifier toggles on button press
BOOL fStatus; // if true, control defaults to ACTIVE, and deactivates on button press
DWORD32 dwSpecific; // will be cast to MODSPEC_MOVE, MODSPEC_MACRO, or MODSPEC_CONFIG
2016-01-27 09:11:59 +00:00
} MODIFIER, *LPMODIFIER;
// bModType (modifiers)
2020-02-09 11:36:49 +00:00
#define MDT_NONE 0
#define MDT_MOVE 1
#define MDT_MACRO 2
#define MDT_CONFIG 3
2016-01-27 09:11:59 +00:00
// buffered
2020-02-09 11:36:49 +00:00
#define MM_BUFF 0
2016-01-27 09:11:59 +00:00
// absolute
2020-02-09 11:36:49 +00:00
#define MM_ABS 1
2016-01-27 09:11:59 +00:00
// deadpan
2020-02-09 11:36:49 +00:00
#define MM_DEAD 2
2016-01-27 09:11:59 +00:00
// Number of analog axes. Standard N64 controller has just 2: X and Y joystick.
2020-02-09 11:36:49 +00:00
#define PF_AXESETS 2
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
typedef struct _CONTROLLER // AN N64 CONTROLLER
2016-01-27 09:11:59 +00:00
{
2020-02-09 11:36:49 +00:00
unsigned fPlugged; // is the controller "plugged" (i.e. does the emulator see a controller on this port?)
unsigned fXInput; // is the controller an xInput device?
unsigned fN64Mouse; // is the controller a N64 Mouse (Relative)?
unsigned fRawData; // are we using RAW mode for this controller?
unsigned fIsAdaptoid; // is it an adaptoid?
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
unsigned fKeyboard; // does it use a keyboard?
unsigned fMouse; // does it use a mouse?
unsigned fGamePad; // does it use a gamepad/joystick?
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
unsigned fRealN64Range; // does it have the "Real N64 Range" flag set?
unsigned bAxisSet; // which set of axes are we using? (Control 1, Control 2)
unsigned bMouseMoveX; // does it use buffered/absolute mouse for X? MM_BUFF, MM_ABS, MM_DEAD
unsigned bMouseMoveY; // does it use buffered/absolute mouse for Y?
unsigned fKeyAbsoluteX; // does it use absolute key for X?
unsigned fKeyAbsoluteY; // does it use absolute key for Y?
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
unsigned fPakInitialized; // Has our pak been initialized? Used to make sure we don't try to write to a mempak that doesn't point to anything.
unsigned fPakCRCError; // The ROM sends CRC data when it tries to write to a mempak. Is the CRC incorrect? Usually indicates a bad ROM.
unsigned PakType; // what type of controller pak? mempak? rumble? transfer? etc
unsigned fVisualRumble; // is visual rumble enabled for this controller?
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
unsigned bBackgroundInput; // allow input while main window isn't focused?
2019-04-20 04:44:04 +00:00
unsigned XcheckTime; // checks for newly connected gamepads timer
2020-02-09 11:36:49 +00:00
BYTE bRumbleTyp; // what type of rumble effect? none, constant, ramp, or direct?
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
GUID guidFFDevice; // GUID of the device that rumble gets sent to
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
BYTE bStickRange; // our "range modifier".
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
long wAxeBuffer[4]; // makes pseudo-relative Movement possible through keyboard or buttons
// also acts as a mouse buffer
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
WORD wMouseSensitivityX; // set per N64 controller, that's OK
WORD wMouseSensitivityY;
BYTE bPadDeadZone; // our manual dead zone, set per N64 controller
BYTE bRumbleStrength; // set per N64 controller
unsigned short nModifiers; // number of modifiers
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
bool bRapidFireEnabled;
BYTE bRapidFireRate;
BYTE bRapidFireCounter;
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
TCHAR szMempakFile[MAX_PATH + 1]; // MemPak-FileName
TCHAR szTransferRom[MAX_PATH + 1]; // GameBoyRom-Filename
TCHAR szTransferSave[MAX_PATH + 1]; // GameBoyEEPRom-Filename
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
BUTTON aButton[14 + PF_AXESETS * 4]; // Ten buttons, 4 d-pad directions times two (for Config 1 and Config 2)
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
MODIFIER *pModifiers; // Array of Modifiers
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
void *pPakData; // Pointer to Pak Data (specific): see PakIO.h
// pPakData->bPakType will always be a BYTE indicating what the current pak type is
2016-01-27 09:11:59 +00:00
2020-02-09 11:36:49 +00:00
XCONTROLLER xiController; // To handle an XInput enabled controller --tecnicors
2016-01-27 09:11:59 +00:00
} CONTROLLER, *LPCONTROLLER;
// This is the Index of WORD PROFILE.Button[X]
// Buttons:
2020-02-09 11:36:49 +00:00
#define PF_DPADR 0
#define PF_DPADL 1
#define PF_DPADD 2
#define PF_DPADU 3
#define PF_START 4
#define PF_TRIGGERZ 5
#define PF_BBUTTON 6
#define PF_ABUTTON 7
2016-01-27 09:11:59 +00:00
#define PF_CBUTTONR 8
2020-02-09 11:36:49 +00:00
#define PF_CBUTTONL 9
2016-01-27 09:11:59 +00:00
#define PF_CBUTTOND 10
#define PF_CBUTTONU 11
2020-02-09 11:36:49 +00:00
#define PF_TRIGGERR 12
#define PF_TRIGGERL 13
2016-01-27 09:11:59 +00:00
// Analog Stick
// cause you can assign Buttons to it, I need 4 of 'em
2020-02-09 11:36:49 +00:00
#define PF_APADR 14
#define PF_APADL 15
#define PF_APADD 16
#define PF_APADU 17
2016-01-27 09:11:59 +00:00
// second Set
2020-02-09 11:36:49 +00:00
// #define PF_APADR 18
// #define PF_APADL 19
// #define PF_APADD 20
// #define PF_APADU 21
2016-01-27 09:11:59 +00:00
// Data Format of DWORD Controller.Button:
//
// BYTE bBtnType : Determines the Device and general Type of Control
// BYTE bAxisID : AxeIndentifier, Tells which range of the Axe/POV is important
// BYTE bOffset : Offset in the DirectInput data structure
// BYTE bBtnType : Determines the Device and general Type of Control
2020-02-09 11:36:49 +00:00
#define DT_UNASSIGNED 0
2016-01-27 09:11:59 +00:00
// Joystick
2020-02-09 11:36:49 +00:00
#define DT_JOYBUTTON 1
#define DT_JOYAXE 2
#define DT_JOYPOV 3
#define DT_JOYSLIDER 4
2016-01-27 09:11:59 +00:00
// Keyboard
2020-02-09 11:36:49 +00:00
#define DT_KEYBUTTON 5
2016-01-27 09:11:59 +00:00
// Mouse
2020-02-09 11:36:49 +00:00
#define DT_MOUSEBUTTON 6
#define DT_MOUSEAXE 7
2016-01-27 09:11:59 +00:00
// BYTE bAxisID : AxeIndentifier, Tells which range of the Axe/POV is important
// Positive Range of an Axe
2020-02-09 11:36:49 +00:00
#define AI_AXE_P 0
2016-01-27 09:11:59 +00:00
// Negative Range
2020-02-09 11:36:49 +00:00
#define AI_AXE_N 1
2016-01-27 09:11:59 +00:00
// Applies to POVs obviously
2020-02-09 11:36:49 +00:00
#define AI_POV_UP 0
#define AI_POV_RIGHT 1
#define AI_POV_DOWN 2
#define AI_POV_LEFT 3
2016-01-27 09:11:59 +00:00
// BYTE bOffset : Offset in the DirectInput data structure
typedef union _MODSPEC_MOVE
{
2020-02-09 11:36:49 +00:00
DWORD dwValue;
struct
{
short XModification;
short YModification;
};
2016-01-27 09:11:59 +00:00
} MODSPEC_MOVE, *LPMODSPEC_MOVE;
typedef union _MODSPEC_MACRO
{
2020-02-09 11:36:49 +00:00
DWORD dwValue;
struct
{
unsigned short aButtons;
unsigned short aFlags;
};
struct
{
unsigned fDigitalRight : 1;
unsigned fDigitalLeft : 1;
unsigned fDigitalDown : 1;
unsigned fDigitalUp : 1;
unsigned fStart : 1;
unsigned fTriggerZ : 1;
unsigned fBButton : 1;
unsigned fAButton : 1;
unsigned fCRight : 1;
unsigned fCLeft : 1;
unsigned fCDown : 1;
unsigned fCUp : 1;
unsigned fTriggerR : 1;
unsigned fTriggerL : 1;
unsigned : 2;
unsigned fAnalogRight : 1;
unsigned fAnalogLeft : 1;
unsigned fAnalogDown : 1;
unsigned fAnalogUp : 1;
unsigned fRapidFire : 1;
unsigned fRapidFireRate : 1;
unsigned fPrevFireState : 1;
unsigned fPrevFireState2 : 1;
};
2016-01-27 09:11:59 +00:00
} MODSPEC_MACRO, *LPMODSPEC_MACRO;
typedef union _MODSPEC_CONFIG
{
2020-02-09 11:36:49 +00:00
DWORD dwValue;
struct
{
BYTE bAnalogStick;
BYTE bMouse;
BYTE bKeyboard;
};
struct
{
unsigned fChangeAnalogConfig : 1;
unsigned fAnalogStickMode : 7;
unsigned fChangeMouseXAxis : 1;
unsigned fChangeMouseYAxis : 1;
unsigned : 6;
unsigned fChangeKeyboardXAxis : 1;
unsigned fChangeKeyboardYAxis : 1;
unsigned : 6;
};
2016-01-27 09:11:59 +00:00
} MODSPEC_CONFIG, *LPMODSPEC_CONFIG;
2020-02-09 11:36:49 +00:00
#define SC_NOPAK 0
#define SC_MEMPAK 1
#define SC_RUMBPAK 2
#define SC_TRANSPAK 3
#define SC_VOICEPAK 4
#define SC_ADAPTPAK 5
#define SC_SWMEMRUMB 6
#define SC_SWMEMADAPT 7
2016-01-27 09:11:59 +00:00
// total arraysize of aButtons in SHORTCUTSPL;
// make sure you update this if you change the list above
2020-02-09 11:36:49 +00:00
#define SC_TOTAL 8
2016-01-27 09:11:59 +00:00
typedef struct _SHORTCUTSPL
{
2020-02-09 11:36:49 +00:00
BUTTON aButtons[SC_TOTAL];
//BUTTON NoPakButton;
//BUTTON MemPakButton;
//BUTTON RumblePakButton;
//BUTTON TransferPakButton;
//BUTTON VoicePakButton;
//BUTTON AdaptoidPakButton;
//BUTTON SwMemRumbleButton;
//BUTTON SwMemAdaptoidButton;
2016-01-27 09:11:59 +00:00
} SHORTCUTSPL, *LPSHORTCUTSPL;
typedef struct _SHORTCUTS
{
2020-02-09 11:36:49 +00:00
SHORTCUTSPL Player[4];
BUTTON bMouseLock;
2016-01-27 09:11:59 +00:00
} SHORTCUTS, *LPSHORTCUTS;
typedef struct _MSHORTCUT {
2020-02-09 11:36:49 +00:00
int iControl;
int iShortcut;
} MSHORTCUT, *LPMSHORTCUT; // shortcut message
2016-01-27 09:11:59 +00:00
#define CHECK_WHITESPACES( str ) ( str == '\r' || str == '\n' || str == '\t' )
extern HANDLE g_hHeap;
extern HMODULE g_hDirectInputDLL;
extern HMODULE g_hXInputDLL;
extern HMODULE g_hResourceDLL;
extern EMULATOR_INFO g_strEmuInfo;
extern TCHAR g_aszDefFolders[3][MAX_PATH];
extern TCHAR g_aszLastBrowse[6][MAX_PATH];
extern int g_nDevices;
extern DEVICE g_devList[MAX_DEVICES];
extern DEVICE g_sysMouse;
extern CONTROLLER g_pcControllers[4];
extern SHORTCUTS g_scShortcuts;
extern LPDIRECTINPUTDEVICE8 g_apFFDevice[4];
extern LPDIRECTINPUTEFFECT g_apdiEffect[4];
extern CRITICAL_SECTION g_critical;
extern bool g_bRunning;
extern bool g_bConfiguring;
extern bool g_bExclusiveMouse;
extern int g_iFirstController;
int WarningMessage(UINT uTextID, UINT uType);
int FindDeviceinList(const TCHAR *pszProductName, BYTE bProductCounter, bool fFindSimilar);
int FindDeviceinList(REFGUID rGUID);
void freePakData(CONTROLLER *pcController);
void freeModifiers(CONTROLLER *pcController);
void CheckShortcuts();
bool ErrorMessage(UINT uID, DWORD dwError, bool fUserChoose);
#endif