mirror of
https://git.rip/DMCA_FUCKER/re3.git
synced 2024-11-05 08:25:54 +00:00
Detect joystick menu for XInput
This commit is contained in:
parent
425f360363
commit
675aef29cf
|
@ -326,6 +326,11 @@ uint32 CControllerConfigManager::ms_padButtonsInited = 0;
|
||||||
|
|
||||||
void CControllerConfigManager::InitDefaultControlConfigJoyPad(uint32 buttons)
|
void CControllerConfigManager::InitDefaultControlConfigJoyPad(uint32 buttons)
|
||||||
{
|
{
|
||||||
|
#ifdef XINPUT
|
||||||
|
// No manual bindings for you, honey.
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
m_bFirstCapture = true;
|
m_bFirstCapture = true;
|
||||||
|
|
||||||
uint32 btn = buttons;
|
uint32 btn = buttons;
|
||||||
|
|
|
@ -206,7 +206,7 @@ enum eMenuScreen
|
||||||
#ifdef GRAPHICS_MENU_OPTIONS
|
#ifdef GRAPHICS_MENU_OPTIONS
|
||||||
MENUPAGE_GRAPHICS_SETTINGS,
|
MENUPAGE_GRAPHICS_SETTINGS,
|
||||||
#endif
|
#endif
|
||||||
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
MENUPAGE_DETECT_JOYSTICK,
|
MENUPAGE_DETECT_JOYSTICK,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,13 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#if defined DETECT_JOYSTICK_MENU && defined XINPUT
|
||||||
|
#include <windows.h>
|
||||||
|
#include <xinput.h>
|
||||||
|
#if !defined(PSAPI_VERSION) || (PSAPI_VERSION > 1)
|
||||||
|
#pragma comment( lib, "Xinput9_1_0.lib" )
|
||||||
|
#else
|
||||||
|
#pragma comment( lib, "Xinput.lib" )
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "crossplatform.h"
|
#include "crossplatform.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
@ -277,11 +286,13 @@ void ScreenModeAfterChange(int8 before, int8 after)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
wchar selectedJoystickUnicode[128];
|
wchar selectedJoystickUnicode[128];
|
||||||
int cachedButtonNum = -1;
|
int cachedButtonNum = -1;
|
||||||
|
|
||||||
wchar* DetectJoystickDraw(bool* disabled, bool userHovering) {
|
wchar* DetectJoystickDraw(bool* disabled, bool userHovering) {
|
||||||
|
|
||||||
|
#if defined RW_GL3 && !defined LIBRW_SDL2
|
||||||
int numButtons;
|
int numButtons;
|
||||||
int found = -1;
|
int found = -1;
|
||||||
const char *joyname;
|
const char *joyname;
|
||||||
|
@ -312,6 +323,40 @@ wchar* DetectJoystickDraw(bool* disabled, bool userHovering) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (PSGLOBAL(joy1id) == -1)
|
if (PSGLOBAL(joy1id) == -1)
|
||||||
|
#elif defined XINPUT
|
||||||
|
int found = -1;
|
||||||
|
XINPUT_STATE xstate;
|
||||||
|
memset(&xstate, 0, sizeof(XINPUT_STATE));
|
||||||
|
if (userHovering) {
|
||||||
|
for (int i = 0; i <= 3; i++) {
|
||||||
|
if (XInputGetState(i, &xstate) == ERROR_SUCCESS) {
|
||||||
|
if (xstate.Gamepad.bLeftTrigger || xstate.Gamepad.bRightTrigger) {
|
||||||
|
found = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (int j = XINPUT_GAMEPAD_DPAD_UP; j != XINPUT_GAMEPAD_Y << 1; j = (j << 1)) {
|
||||||
|
if (xstate.Gamepad.wButtons & j) {
|
||||||
|
found = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found != -1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found != -1 && CPad::XInputJoy1 != found) {
|
||||||
|
if (CPad::XInputJoy1 != -1 && CPad::XInputJoy1 != found)
|
||||||
|
CPad::XInputJoy2 = CPad::XInputJoy1;
|
||||||
|
else
|
||||||
|
CPad::XInputJoy2 = -1;
|
||||||
|
|
||||||
|
CPad::XInputJoy1 = found;
|
||||||
|
cachedButtonNum = 0; // fake too, because xinput bypass CControllerConfig
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sprintf(gSelectedJoystickName, "%d", CPad::XInputJoy1); // fake, on xinput we only store gamepad ids(thanks MS) so this is a temp variable to be used below
|
||||||
|
if (CPad::XInputJoy1 == -1)
|
||||||
|
#endif
|
||||||
AsciiToUnicode("Not found", selectedJoystickUnicode);
|
AsciiToUnicode("Not found", selectedJoystickUnicode);
|
||||||
else
|
else
|
||||||
AsciiToUnicode(gSelectedJoystickName, selectedJoystickUnicode);
|
AsciiToUnicode(gSelectedJoystickName, selectedJoystickUnicode);
|
||||||
|
@ -567,7 +612,7 @@ CMenuScreenCustom aScreens[] = {
|
||||||
#else
|
#else
|
||||||
MENUACTION_KEYBOARDCTRLS,"FEC_RED", {nil, SAVESLOT_NONE, MENUPAGE_KEYBOARD_CONTROLS}, 320, 150, MENUALIGN_CENTER,
|
MENUACTION_KEYBOARDCTRLS,"FEC_RED", {nil, SAVESLOT_NONE, MENUPAGE_KEYBOARD_CONTROLS}, 320, 150, MENUALIGN_CENTER,
|
||||||
#endif
|
#endif
|
||||||
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
MENUACTION_CHANGEMENU, "FEC_JOD", {nil, SAVESLOT_NONE, MENUPAGE_DETECT_JOYSTICK}, 0, 0, MENUALIGN_CENTER,
|
MENUACTION_CHANGEMENU, "FEC_JOD", {nil, SAVESLOT_NONE, MENUPAGE_DETECT_JOYSTICK}, 0, 0, MENUALIGN_CENTER,
|
||||||
#endif
|
#endif
|
||||||
MENUACTION_CHANGEMENU, "FEC_MOU", {nil, SAVESLOT_NONE, MENUPAGE_MOUSE_CONTROLS}, 0, 0, MENUALIGN_CENTER,
|
MENUACTION_CHANGEMENU, "FEC_MOU", {nil, SAVESLOT_NONE, MENUPAGE_MOUSE_CONTROLS}, 0, 0, MENUALIGN_CENTER,
|
||||||
|
@ -715,7 +760,7 @@ CMenuScreenCustom aScreens[] = {
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
// MENUPAGE_DETECT_JOYSTICK
|
// MENUPAGE_DETECT_JOYSTICK
|
||||||
{ "FEC_JOD", MENUPAGE_CONTROLLER_PC, new CCustomScreenLayout({0, 0, 0, false, false, 30}), DetectJoystickGoBack,
|
{ "FEC_JOD", MENUPAGE_CONTROLLER_PC, new CCustomScreenLayout({0, 0, 0, false, false, 30}), DetectJoystickGoBack,
|
||||||
MENUACTION_LABEL, "FEC_JPR", { nil, SAVESLOT_NONE, MENUPAGE_NONE }, 0, 0, 0,
|
MENUACTION_LABEL, "FEC_JPR", { nil, SAVESLOT_NONE, MENUPAGE_NONE }, 0, 0, 0,
|
||||||
|
|
|
@ -1585,8 +1585,14 @@ void CPad::AddToPCCheatString(char c)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef XINPUT
|
#ifdef XINPUT
|
||||||
|
int CPad::XInputJoy1 = 0;
|
||||||
|
int CPad::XInputJoy2 = 1;
|
||||||
void CPad::AffectFromXinput(uint32 pad)
|
void CPad::AffectFromXinput(uint32 pad)
|
||||||
{
|
{
|
||||||
|
pad = pad == 0 ? XInputJoy1 : XInputJoy2;
|
||||||
|
if (pad == -1) // LoadINIControllerSettings can set it to -1
|
||||||
|
return;
|
||||||
|
|
||||||
XINPUT_STATE xstate;
|
XINPUT_STATE xstate;
|
||||||
memset(&xstate, 0, sizeof(XINPUT_STATE));
|
memset(&xstate, 0, sizeof(XINPUT_STATE));
|
||||||
if (XInputGetState(pad, &xstate) == ERROR_SUCCESS)
|
if (XInputGetState(pad, &xstate) == ERROR_SUCCESS)
|
||||||
|
|
|
@ -276,6 +276,8 @@ public:
|
||||||
void SetDrunkInputDelay(int32 delay) { DrunkDrivingBufferUsed = delay; }
|
void SetDrunkInputDelay(int32 delay) { DrunkDrivingBufferUsed = delay; }
|
||||||
|
|
||||||
#ifdef XINPUT
|
#ifdef XINPUT
|
||||||
|
static int XInputJoy1;
|
||||||
|
static int XInputJoy2;
|
||||||
void AffectFromXinput(uint32 pad);
|
void AffectFromXinput(uint32 pad);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -298,8 +298,8 @@ enum Config {
|
||||||
#if !defined(RW_GL3) && defined(_WIN32)
|
#if !defined(RW_GL3) && defined(_WIN32)
|
||||||
#define XINPUT
|
#define XINPUT
|
||||||
#endif
|
#endif
|
||||||
#if !defined(_WIN32) && !defined(__SWITCH__)
|
#if defined XINPUT || (defined RW_GL3 && !defined LIBRW_SDL2 && !defined __SWITCH__)
|
||||||
#define DONT_TRUST_RECOGNIZED_JOYSTICKS // Then we'll only rely on GLFW gamepad DB, and expect user to enter Controller->Detect joysticks if his joystick isn't on that list.
|
#define DETECT_JOYSTICK_MENU // Then we'll expect user to enter Controller->Detect joysticks if his joystick isn't detected at the start.
|
||||||
#endif
|
#endif
|
||||||
#define DETECT_PAD_INPUT_SWITCH // Adds automatic switch of pad related stuff between controller and kb/m
|
#define DETECT_PAD_INPUT_SWITCH // Adds automatic switch of pad related stuff between controller and kb/m
|
||||||
#define KANGAROO_CHEAT
|
#define KANGAROO_CHEAT
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#define WITHWINDOWS
|
#define WITHWINDOWS
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#if defined DETECT_JOYSTICK_MENU && defined XINPUT
|
||||||
|
#include <xinput.h>
|
||||||
|
#if !defined(PSAPI_VERSION) || (PSAPI_VERSION > 1)
|
||||||
|
#pragma comment( lib, "Xinput9_1_0.lib" )
|
||||||
|
#else
|
||||||
|
#pragma comment( lib, "Xinput.lib" )
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "Occlusion.h"
|
#include "Occlusion.h"
|
||||||
#include "Credits.h"
|
#include "Credits.h"
|
||||||
|
@ -37,7 +45,7 @@
|
||||||
#include "MBlur.h"
|
#include "MBlur.h"
|
||||||
#include "ControllerConfig.h"
|
#include "ControllerConfig.h"
|
||||||
|
|
||||||
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
#include "crossplatform.h"
|
#include "crossplatform.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -249,8 +257,32 @@ const char *iniKeyboardButtons[] = {"ESC","F1","F2","F3","F4","F5","F6","F7","F8
|
||||||
|
|
||||||
void LoadINIControllerSettings()
|
void LoadINIControllerSettings()
|
||||||
{
|
{
|
||||||
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
|
#ifdef XINPUT
|
||||||
|
int storedJoy1 = -1;
|
||||||
|
if (ReadIniIfExists("Controller", "JoystickName", &storedJoy1)) {
|
||||||
|
CPad::XInputJoy1 = -1;
|
||||||
|
CPad::XInputJoy2 = -1;
|
||||||
|
XINPUT_STATE xstate;
|
||||||
|
memset(&xstate, 0, sizeof(XINPUT_STATE));
|
||||||
|
|
||||||
|
// Firstly confirm & set joy 1
|
||||||
|
if (XInputGetState(storedJoy1, &xstate) == ERROR_SUCCESS) {
|
||||||
|
CPad::XInputJoy1 = storedJoy1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i <= 3; i++) {
|
||||||
|
if (XInputGetState(i, &xstate) == ERROR_SUCCESS) {
|
||||||
|
if (CPad::XInputJoy1 == -1)
|
||||||
|
CPad::XInputJoy1 = i;
|
||||||
|
else if (CPad::XInputJoy2 == -1 && i != CPad::XInputJoy1)
|
||||||
|
CPad::XInputJoy2 = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
ReadIniIfExists("Controller", "JoystickName", gSelectedJoystickName, 128);
|
ReadIniIfExists("Controller", "JoystickName", gSelectedJoystickName, 128);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
// force to default GTA behaviour (never overwrite bindings on joy change/initialization) if user init'ed/set bindings before we introduced that
|
// force to default GTA behaviour (never overwrite bindings on joy change/initialization) if user init'ed/set bindings before we introduced that
|
||||||
if (!ReadIniIfExists("Controller", "PadButtonsInited", &ControlsManager.ms_padButtonsInited)) {
|
if (!ReadIniIfExists("Controller", "PadButtonsInited", &ControlsManager.ms_padButtonsInited)) {
|
||||||
|
@ -348,8 +380,12 @@ void SaveINIControllerSettings()
|
||||||
StoreIni("Bindings", iniControllerActions[i], value, 128);
|
StoreIni("Bindings", iniControllerActions[i], value, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
|
#ifdef XINPUT
|
||||||
|
StoreIni("Controller", "JoystickName", CPad::XInputJoy1);
|
||||||
|
#else
|
||||||
StoreIni("Controller", "JoystickName", gSelectedJoystickName, 128);
|
StoreIni("Controller", "JoystickName", gSelectedJoystickName, 128);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
StoreIni("Controller", "PadButtonsInited", ControlsManager.ms_padButtonsInited);
|
StoreIni("Controller", "PadButtonsInited", ControlsManager.ms_padButtonsInited);
|
||||||
cfg.write_file("reVC.ini");
|
cfg.write_file("reVC.ini");
|
||||||
|
|
|
@ -75,7 +75,7 @@ void CapturePad(RwInt32 padID);
|
||||||
void joysChangeCB(int jid, int event);
|
void joysChangeCB(int jid, int event);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
extern char gSelectedJoystickName[128];
|
extern char gSelectedJoystickName[128];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ static psGlobalType PsGlobal;
|
||||||
size_t _dwMemAvailPhys;
|
size_t _dwMemAvailPhys;
|
||||||
RwUInt32 gGameState;
|
RwUInt32 gGameState;
|
||||||
|
|
||||||
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
char gSelectedJoystickName[128] = "";
|
char gSelectedJoystickName[128] = "";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -852,7 +852,7 @@ void joysChangeCB(int jid, int event);
|
||||||
|
|
||||||
bool IsThisJoystickBlacklisted(int i)
|
bool IsThisJoystickBlacklisted(int i)
|
||||||
{
|
{
|
||||||
#ifndef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifndef DETECT_JOYSTICK_MENU
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
if (glfwJoystickIsGamepad(i))
|
if (glfwJoystickIsGamepad(i))
|
||||||
|
@ -917,7 +917,7 @@ void _InputInitialiseJoys()
|
||||||
if (PSGLOBAL(joy1id) != -1) {
|
if (PSGLOBAL(joy1id) != -1) {
|
||||||
int count;
|
int count;
|
||||||
glfwGetJoystickButtons(PSGLOBAL(joy1id), &count);
|
glfwGetJoystickButtons(PSGLOBAL(joy1id), &count);
|
||||||
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
strcpy(gSelectedJoystickName, glfwGetJoystickName(PSGLOBAL(joy1id)));
|
strcpy(gSelectedJoystickName, glfwGetJoystickName(PSGLOBAL(joy1id)));
|
||||||
#endif
|
#endif
|
||||||
ControlsManager.InitDefaultControlConfigJoyPad(count);
|
ControlsManager.InitDefaultControlConfigJoyPad(count);
|
||||||
|
@ -2182,7 +2182,7 @@ void joysChangeCB(int jid, int event)
|
||||||
if (event == GLFW_CONNECTED && !IsThisJoystickBlacklisted(jid)) {
|
if (event == GLFW_CONNECTED && !IsThisJoystickBlacklisted(jid)) {
|
||||||
if (PSGLOBAL(joy1id) == -1) {
|
if (PSGLOBAL(joy1id) == -1) {
|
||||||
PSGLOBAL(joy1id) = jid;
|
PSGLOBAL(joy1id) = jid;
|
||||||
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
strcpy(gSelectedJoystickName, glfwGetJoystickName(jid));
|
strcpy(gSelectedJoystickName, glfwGetJoystickName(jid));
|
||||||
#endif
|
#endif
|
||||||
// This is behind LOAD_INI_SETTINGS, because otherwise the Init call below will destroy/overwrite your bindings.
|
// This is behind LOAD_INI_SETTINGS, because otherwise the Init call below will destroy/overwrite your bindings.
|
||||||
|
|
|
@ -120,6 +120,10 @@ DWORD _dwOperatingSystemVersion;
|
||||||
RwUInt32 gGameState;
|
RwUInt32 gGameState;
|
||||||
CJoySticks AllValidWinJoys;
|
CJoySticks AllValidWinJoys;
|
||||||
|
|
||||||
|
#ifdef DETECT_JOYSTICK_MENU
|
||||||
|
char gSelectedJoystickName[128] = "";
|
||||||
|
#endif
|
||||||
|
|
||||||
// What is that for anyway?
|
// What is that for anyway?
|
||||||
#ifndef IMPROVED_VIDEOMODE
|
#ifndef IMPROVED_VIDEOMODE
|
||||||
static RwBool defaultFullscreenRes = TRUE;
|
static RwBool defaultFullscreenRes = TRUE;
|
||||||
|
|
Loading…
Reference in a new issue