project64/Source/nragev20/NRagePluginV2.h

395 lines
12 KiB
C
Raw Normal View History

2016-01-27 09:11:59 +00:00
/*
N-Rage`s Dinput8 Plugin
(C) 2002, 2006 Norbert Wladyka
2016-01-27 09:11:59 +00:00
Author`s Email: norbert.wladyka@chello.at
Website: http://go.to/nrage
2016-01-27 09:11:59 +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
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
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
2016-01-27 09:11:59 +00:00
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
// 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
/*
11/09/2015 Comment by 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.
*/
2016-01-27 09:11:59 +00:00
CONTROL * controllers;
// BOOL MemoryBswaped; // If this is set to TRUE, then the memory has been pre-bswap'd on a DWORD (32-bit) boundary, only effects header.
2020-02-09 11:36:49 +00:00
// 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.
2020-02-09 11:36:49 +00:00
BYTE bEffType; // What rumble effects does this device support?
union INPUTSTATE // The last polled data from this device
2020-02-09 11:36:49 +00:00
{
DIJOYSTATE joyState;
DIMOUSESTATE2 mouseState;
BYTE rgbButtons[256]; // Keyboard state
2020-02-09 11:36:49 +00:00
} 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 N-Rage. Emulator turbo buttons, macros, stuff like that.
2016-01-27 09:11:59 +00:00
typedef struct _MODIFIER
{
BUTTON btnButton; // Button to associate with
2020-02-09 11:36:49 +00:00
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
// Absolute
2020-02-09 11:36:49 +00:00
#define MM_ABS 1
// 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
typedef struct _CONTROLLER // An N64 controller
2016-01-27 09:11:59 +00:00
{
unsigned fPlugged; // Is the controller "plugged" / connected? (i.e. does the emulator see a controller on this port?)
unsigned fXInput; // Is the controller an XInput device?
unsigned fN64Mouse; // Is the controller an 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
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
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
unsigned fPakInitialized; // Has our pak been initialized? Used to make sure we don't try to write to a memory pak that doesn't point to anything.
unsigned fPakCRCError; // The ROM sends CRC data when it tries to write to a memory pak. Is the CRC incorrect? Usually indicates a bad ROM.
unsigned PakType; // What type of controller pak? Memory pak? Rumble pak? Transfer pak? etc.
unsigned fVisualRumble; // Is visual rumble enabled for this controller?
2016-01-27 09:11:59 +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
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
BYTE bStickRange; // Our "range modifier"
2016-01-27 09:11:59 +00:00
long wAxeBuffer[4]; // Makes pseudo-relative movement possible through keyboard or buttons and also acts as a mouse buffer
2016-01-27 09:11:59 +00:00
WORD wMouseSensitivityX; // Set per N64 controller, that's OK
2020-02-09 11:36:49 +00:00
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
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
MODIFIER *pModifiers; // Array of modifiers
2016-01-27 09:11:59 +00:00
void *pPakData; // Pointer to pak Data (specific): see PakIO.h
2020-02-09 11:36:49 +00:00
// pPakData->bPakType will always be a BYTE indicating what the current pak type is
2016-01-27 09:11:59 +00:00
XCONTROLLER xiController; // To handle an XInput-enabled controller (comment by tecnicors)
2016-01-27 09:11:59 +00:00
} CONTROLLER, *LPCONTROLLER;
// This is the index of WORD PROFILE.Button[X]
2016-01-27 09:11:59 +00:00
// 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
// Because you can assign buttons to it, we need 4 of them
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:
2016-01-27 09:11:59 +00:00
// BYTE bBtnType: Determines the device and general type of control
// BYTE bAxisID: AxeIndentifier, which tells which range of the axes/POV is important
// BYTE bOffset: Offset in the DirectInput data structure
2016-01-27 09:11:59 +00:00
// 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, which tells which range of the axes/POV is important
2016-01-27 09:11:59 +00:00
// Positive range of a the axes
2020-02-09 11:36:49 +00:00
#define AI_AXE_P 0
// 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
2016-01-27 09:11:59 +00:00
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 array size 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