summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorerorcun <erorcunerorcun@hotmail.com.tr>2021-01-22 21:40:28 +0100
committererorcun <erorcunerorcun@hotmail.com.tr>2021-01-22 21:43:49 +0100
commit226e3b83dafbff6e59b8d351441026c5a6a4bf25 (patch)
treeff214ec3d124746ae08fba9ef1128f286c89c772 /src/core
parentfix (diff)
downloadre3-226e3b83dafbff6e59b8d351441026c5a6a4bf25.tar
re3-226e3b83dafbff6e59b8d351441026c5a6a4bf25.tar.gz
re3-226e3b83dafbff6e59b8d351441026c5a6a4bf25.tar.bz2
re3-226e3b83dafbff6e59b8d351441026c5a6a4bf25.tar.lz
re3-226e3b83dafbff6e59b8d351441026c5a6a4bf25.tar.xz
re3-226e3b83dafbff6e59b8d351441026c5a6a4bf25.tar.zst
re3-226e3b83dafbff6e59b8d351441026c5a6a4bf25.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ControllerConfig.cpp87
-rw-r--r--src/core/ControllerConfig.h4
-rw-r--r--src/core/Frontend.cpp18
-rw-r--r--src/core/MenuScreensCustom.cpp17
-rw-r--r--src/core/main.h2
-rw-r--r--src/core/re3.cpp57
6 files changed, 103 insertions, 82 deletions
diff --git a/src/core/ControllerConfig.cpp b/src/core/ControllerConfig.cpp
index ee3cb959..6e9db6e3 100644
--- a/src/core/ControllerConfig.cpp
+++ b/src/core/ControllerConfig.cpp
@@ -31,6 +31,9 @@ CControllerConfigManager::CControllerConfigManager()
void CControllerConfigManager::MakeControllerActionsBlank()
{
+#ifdef LOAD_INI_SETTINGS
+ ms_padButtonsInited = 0;
+#endif
for (int32 i = 0; i < MAX_CONTROLLERTYPES; i++)
{
for (int32 j = 0; j < MAX_CONTROLLERACTIONS; j++)
@@ -345,6 +348,10 @@ void CControllerConfigManager::InitDefaultControlConfigMouse(CMouseControllerSta
}
}
+#ifdef LOAD_INI_SETTINGS
+uint32 CControllerConfigManager::ms_padButtonsInited = 0;
+#endif
+
void CControllerConfigManager::InitDefaultControlConfigJoyPad(uint32 buttons)
{
m_bFirstCapture = true;
@@ -353,6 +360,22 @@ void CControllerConfigManager::InitDefaultControlConfigJoyPad(uint32 buttons)
if (buttons > 16)
btn = 16;
+#ifdef LOAD_INI_SETTINGS
+ uint32 buttonMin = ms_padButtonsInited;
+ if (buttonMin >= btn)
+ return;
+
+ ms_padButtonsInited = btn;
+
+ #define IF_BTN_IN_RANGE(n) \
+ case n: \
+ if (n <= buttonMin) \
+ return;
+#else
+ #define IF_BTN_IN_RANGE(n) \
+ case n:
+#endif
+
// Now we use SDL Game Controller DB
#if defined RW_D3D9 || defined RWLIBS
if ( AllValidWinJoys.m_aJoys[JOYSTICK1].m_nVendorID == 0x3427
@@ -365,49 +388,49 @@ void CControllerConfigManager::InitDefaultControlConfigJoyPad(uint32 buttons)
switch (btn)
{
- case 16:
+ IF_BTN_IN_RANGE(16)
SetControllerKeyAssociatedWithAction(GO_LEFT, 16, JOYSTICK);
- case 15:
+ IF_BTN_IN_RANGE(15)
SetControllerKeyAssociatedWithAction(GO_BACK, 15, JOYSTICK);
- case 14:
+ IF_BTN_IN_RANGE(14)
SetControllerKeyAssociatedWithAction(GO_RIGHT, 14, JOYSTICK);
- case 13:
+ IF_BTN_IN_RANGE(13)
SetControllerKeyAssociatedWithAction(GO_FORWARD, 13, JOYSTICK);
- case 12:
- case 11:
+ IF_BTN_IN_RANGE(12)
+ IF_BTN_IN_RANGE(11)
SetControllerKeyAssociatedWithAction(PED_LOOKBEHIND, 11, JOYSTICK);
SetControllerKeyAssociatedWithAction(TOGGLE_SUBMISSIONS, 11, JOYSTICK);
- case 10:
+ IF_BTN_IN_RANGE(10)
SetControllerKeyAssociatedWithAction(VEHICLE_HORN, 10, JOYSTICK);
- case 9:
+ IF_BTN_IN_RANGE(9)
SetControllerKeyAssociatedWithAction(CAMERA_CHANGE_VIEW_ALL_SITUATIONS, 9, JOYSTICK);
- case 8:
+ IF_BTN_IN_RANGE(8)
SetControllerKeyAssociatedWithAction(VEHICLE_HANDBRAKE, 8, JOYSTICK);
SetControllerKeyAssociatedWithAction(PED_LOCK_TARGET, 8, JOYSTICK);
- case 7:
+ IF_BTN_IN_RANGE(7)
SetControllerKeyAssociatedWithAction(PED_CENTER_CAMERA_BEHIND_PLAYER, 7, JOYSTICK);
SetControllerKeyAssociatedWithAction(VEHICLE_CHANGE_RADIO_STATION, 7, JOYSTICK);
- case 6:
+ IF_BTN_IN_RANGE(6)
SetControllerKeyAssociatedWithAction(PED_CYCLE_WEAPON_RIGHT, 6, JOYSTICK);
SetControllerKeyAssociatedWithAction(VEHICLE_LOOKRIGHT, 6, JOYSTICK);
- case 5:
+ IF_BTN_IN_RANGE(5)
SetControllerKeyAssociatedWithAction(PED_CYCLE_WEAPON_LEFT, 5, JOYSTICK);
SetControllerKeyAssociatedWithAction(VEHICLE_LOOKLEFT, 5, JOYSTICK);
/*******************************************************************************************/
- case 4:
+ IF_BTN_IN_RANGE(4)
SetControllerKeyAssociatedWithAction(VEHICLE_BRAKE, 4, JOYSTICK);
SetControllerKeyAssociatedWithAction(PED_JUMPING, 4, JOYSTICK);
SetControllerKeyAssociatedWithAction(PED_SNIPER_ZOOM_IN, 4, JOYSTICK);
- case 3:
+ IF_BTN_IN_RANGE(3)
SetControllerKeyAssociatedWithAction(VEHICLE_ACCELERATE, 3, JOYSTICK);
SetControllerKeyAssociatedWithAction(PED_SPRINT, 3, JOYSTICK);
SetControllerKeyAssociatedWithAction(PED_SNIPER_ZOOM_OUT, 3, JOYSTICK);
- case 2:
+ IF_BTN_IN_RANGE(2)
SetControllerKeyAssociatedWithAction(PED_FIREWEAPON, 2, JOYSTICK);
#ifdef BIND_VEHICLE_FIREWEAPON
SetControllerKeyAssociatedWithAction(VEHICLE_FIREWEAPON, 2, JOYSTICK);
#endif
- case 1:
+ IF_BTN_IN_RANGE(1)
SetControllerKeyAssociatedWithAction(VEHICLE_ENTER_EXIT, 1, JOYSTICK);
/*******************************************************************************************/
}
@@ -416,46 +439,46 @@ void CControllerConfigManager::InitDefaultControlConfigJoyPad(uint32 buttons)
{
switch (btn)
{
- case 16:
+ IF_BTN_IN_RANGE(16)
SetControllerKeyAssociatedWithAction(GO_LEFT, 16, JOYSTICK);
- case 15:
+ IF_BTN_IN_RANGE(15)
SetControllerKeyAssociatedWithAction(GO_BACK, 15, JOYSTICK);
- case 14:
+ IF_BTN_IN_RANGE(14)
SetControllerKeyAssociatedWithAction(GO_RIGHT, 14, JOYSTICK);
- case 13:
+ IF_BTN_IN_RANGE(13)
SetControllerKeyAssociatedWithAction(GO_FORWARD, 13, JOYSTICK);
- case 12:
- case 11:
+ IF_BTN_IN_RANGE(12)
+ IF_BTN_IN_RANGE(11)
SetControllerKeyAssociatedWithAction(PED_LOOKBEHIND, 11, JOYSTICK);
SetControllerKeyAssociatedWithAction(TOGGLE_SUBMISSIONS, 11, JOYSTICK);
- case 10:
+ IF_BTN_IN_RANGE(10)
SetControllerKeyAssociatedWithAction(VEHICLE_HORN, 10, JOYSTICK);
- case 9:
+ IF_BTN_IN_RANGE(9)
SetControllerKeyAssociatedWithAction(CAMERA_CHANGE_VIEW_ALL_SITUATIONS, 9, JOYSTICK);
- case 8:
+ IF_BTN_IN_RANGE(8)
SetControllerKeyAssociatedWithAction(VEHICLE_HANDBRAKE, 8, JOYSTICK);
SetControllerKeyAssociatedWithAction(PED_LOCK_TARGET, 8, JOYSTICK);
- case 7:
+ IF_BTN_IN_RANGE(7)
SetControllerKeyAssociatedWithAction(PED_CENTER_CAMERA_BEHIND_PLAYER, 7, JOYSTICK);
SetControllerKeyAssociatedWithAction(VEHICLE_CHANGE_RADIO_STATION, 7, JOYSTICK);
- case 6:
+ IF_BTN_IN_RANGE(6)
SetControllerKeyAssociatedWithAction(PED_CYCLE_WEAPON_RIGHT, 6, JOYSTICK);
SetControllerKeyAssociatedWithAction(VEHICLE_LOOKRIGHT, 6, JOYSTICK);
- case 5:
+ IF_BTN_IN_RANGE(5)
SetControllerKeyAssociatedWithAction(PED_CYCLE_WEAPON_LEFT, 5, JOYSTICK);
SetControllerKeyAssociatedWithAction(VEHICLE_LOOKLEFT, 5, JOYSTICK);
/*******************************************************************************************/
- case 4:
+ IF_BTN_IN_RANGE(4)
SetControllerKeyAssociatedWithAction(VEHICLE_ENTER_EXIT, 4, JOYSTICK);
- case 3:
+ IF_BTN_IN_RANGE(3)
SetControllerKeyAssociatedWithAction(VEHICLE_BRAKE, 3, JOYSTICK);
SetControllerKeyAssociatedWithAction(PED_JUMPING, 3, JOYSTICK);
SetControllerKeyAssociatedWithAction(PED_SNIPER_ZOOM_IN, 3, JOYSTICK);
- case 2:
+ IF_BTN_IN_RANGE(2)
SetControllerKeyAssociatedWithAction(VEHICLE_ACCELERATE, 2, JOYSTICK);
SetControllerKeyAssociatedWithAction(PED_SPRINT, 2, JOYSTICK);
SetControllerKeyAssociatedWithAction(PED_SNIPER_ZOOM_OUT, 2, JOYSTICK);
- case 1:
+ IF_BTN_IN_RANGE(1)
SetControllerKeyAssociatedWithAction(PED_FIREWEAPON, 1, JOYSTICK);
#ifdef BIND_VEHICLE_FIREWEAPON
SetControllerKeyAssociatedWithAction(VEHICLE_FIREWEAPON, 1, JOYSTICK);
diff --git a/src/core/ControllerConfig.h b/src/core/ControllerConfig.h
index d3c2293d..295f03b9 100644
--- a/src/core/ControllerConfig.h
+++ b/src/core/ControllerConfig.h
@@ -141,6 +141,10 @@ public:
tControllerConfigBind m_aSettings[MAX_CONTROLLERACTIONS][MAX_CONTROLLERTYPES];
bool m_aSimCheckers[MAX_SIMS][MAX_CONTROLLERTYPES];
bool m_bMouseAssociated;
+
+#ifdef LOAD_INI_SETTINGS
+ static uint32 ms_padButtonsInited;
+#endif
CControllerConfigManager();
diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp
index 707184d5..bd72a15f 100644
--- a/src/core/Frontend.cpp
+++ b/src/core/Frontend.cpp
@@ -3730,8 +3730,13 @@ CMenuManager::LoadSettings()
CFileMgr::SetDir("");
#ifdef LOAD_INI_SETTINGS
- LoadINISettings();
- LoadINIControllerSettings(); // Calling that after LoadINISettings is important because of gSelectedJoystickName loading
+ if (LoadINISettings()) {
+ LoadINIControllerSettings();
+ } else {
+ // no re3.ini, create it
+ SaveINISettings();
+ SaveINIControllerSettings();
+ }
#endif
m_PrefsVsync = m_PrefsVsyncDisp;
@@ -3828,12 +3833,6 @@ CMenuManager::SaveSettings()
CFileMgr::SetDir("");
#else
- static bool firstTime = true;
- // In other conditions we already call SaveINIControllerSettings explicitly.
- if (firstTime) {
- SaveINIControllerSettings();
- firstTime = false;
- }
SaveINISettings();
#endif
}
@@ -5605,6 +5604,9 @@ CMenuManager::SwitchMenuOnAndOff()
#endif
ShutdownJustMenu();
SaveSettings();
+#ifdef LOAD_INI_SETTINGS
+ SaveINIControllerSettings();
+#endif
m_bStartUpFrontEndRequested = false;
pControlEdit = nil;
m_bShutDownFrontEndRequested = false;
diff --git a/src/core/MenuScreensCustom.cpp b/src/core/MenuScreensCustom.cpp
index 07223608..3eee8dd2 100644
--- a/src/core/MenuScreensCustom.cpp
+++ b/src/core/MenuScreensCustom.cpp
@@ -16,6 +16,7 @@
#include "Collision.h"
#include "ModelInfo.h"
#include "Pad.h"
+#include "ControllerConfig.h"
// Menu screens array is at the bottom of the file.
@@ -292,6 +293,7 @@ void ScreenModeAfterChange(int8 before, int8 after)
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
wchar selectedJoystickUnicode[128];
+int cachedButtonNum = -1;
wchar* DetectJoystickDraw(bool* disabled, bool userHovering) {
int numButtons;
@@ -320,6 +322,7 @@ wchar* DetectJoystickDraw(bool* disabled, bool userHovering) {
strcpy(gSelectedJoystickName, joyname);
PSGLOBAL(joy1id) = found;
+ cachedButtonNum = numButtons;
}
}
if (PSGLOBAL(joy1id) == -1)
@@ -329,6 +332,18 @@ wchar* DetectJoystickDraw(bool* disabled, bool userHovering) {
return selectedJoystickUnicode;
}
+
+void DetectJoystickGoBack() {
+ if (cachedButtonNum != -1) {
+#ifdef LOAD_INI_SETTINGS
+ ControlsManager.InitDefaultControlConfigJoyPad(cachedButtonNum);
+ SaveINIControllerSettings();
+#else
+ // Otherwise no way to save gSelectedJoystickName or ms_padButtonsInited anyway :shrug: Why do you even use this config.??
+#endif
+ cachedButtonNum = -1;
+ }
+}
#endif
CMenuScreenCustom aScreens[MENUPAGES] = {
@@ -836,7 +851,7 @@ CMenuScreenCustom aScreens[MENUPAGES] = {
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
// MENUPAGE_DETECT_JOYSTICK
{ "FEC_JOD", MENUPAGE_CONTROLLER_PC, MENUPAGE_CONTROLLER_PC,
- new CCustomScreenLayout({MENUSPRITE_MAINMENU, 40, 60, 20, FONT_BANK, FESCREEN_LEFT_ALIGN, false, MEDIUMTEXT_X_SCALE, MEDIUMTEXT_Y_SCALE}), nil,
+ new CCustomScreenLayout({MENUSPRITE_MAINMENU, 40, 60, 20, FONT_BANK, FESCREEN_LEFT_ALIGN, false, MEDIUMTEXT_X_SCALE, MEDIUMTEXT_Y_SCALE}), DetectJoystickGoBack,
MENUACTION_LABEL, "FEC_JPR", { nil, SAVESLOT_NONE, MENUPAGE_NONE },
MENUACTION_CFO_DYNAMIC, "FEC_JDE", { new CCFODynamic(nil, nil, nil, DetectJoystickDraw, nil) },
diff --git a/src/core/main.h b/src/core/main.h
index eacfd8e1..9f181101 100644
--- a/src/core/main.h
+++ b/src/core/main.h
@@ -45,7 +45,7 @@ void TheModelViewer(void);
#endif
#ifdef LOAD_INI_SETTINGS
-void LoadINISettings();
+bool LoadINISettings();
void SaveINISettings();
void LoadINIControllerSettings();
void SaveINIControllerSettings();
diff --git a/src/core/re3.cpp b/src/core/re3.cpp
index 48e8a6bc..42e59e6e 100644
--- a/src/core/re3.cpp
+++ b/src/core/re3.cpp
@@ -244,6 +244,14 @@ const char *iniKeyboardButtons[] = {"ESC","F1","F2","F3","F4","F5","F6","F7","F8
void LoadINIControllerSettings()
{
+#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
+ ReadIniIfExists("Controller", "JoystickName", gSelectedJoystickName, 128);
+#endif
+ // 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)) {
+ ControlsManager.ms_padButtonsInited = cfg.category_size("Bindings") != 0 ? 16 : 0;
+ }
+
for (int32 i = 0; i < MAX_CONTROLLERACTIONS; i++) {
char value[128];
if (ReadIniIfExists("Bindings", iniControllerActions[i], value, 128)) {
@@ -335,12 +343,17 @@ void SaveINIControllerSettings()
StoreIni("Bindings", iniControllerActions[i], value, 128);
}
+#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
+ StoreIni("Controller", "JoystickName", gSelectedJoystickName, 128);
+#endif
+ StoreIni("Controller", "PadButtonsInited", ControlsManager.ms_padButtonsInited);
cfg.write_file("re3.ini");
}
-void LoadINISettings()
+bool LoadINISettings()
{
- cfg.load_file("re3.ini");
+ if (!cfg.load_file("re3.ini"))
+ return false;
#ifdef IMPROVED_VIDEOMODE
ReadIniIfExists("VideoMode", "Width", &FrontEndMenuManager.m_nPrefsWidth);
@@ -394,40 +407,6 @@ void LoadINISettings()
ReadIniIfExists("Draw", "FixSprites", &CDraw::ms_bFixSprites);
#endif
-#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
- // Written by assuming the codes below will run after _InputInitialiseJoys().
- std::string strval = cfg.get("Controller", "JoystickName", "");
- const char *value = strval.c_str();
- strcpy(gSelectedJoystickName, value);
-
- if(gSelectedJoystickName[0] != '\0') {
- for (int i = 0; i <= GLFW_JOYSTICK_LAST; i++) {
- if (glfwJoystickPresent(i) && strncmp(gSelectedJoystickName, glfwGetJoystickName(i), strlen(gSelectedJoystickName)) == 0) {
- if (PSGLOBAL(joy1id) != -1) {
- PSGLOBAL(joy2id) = PSGLOBAL(joy1id);
- }
- PSGLOBAL(joy1id) = i;
- int count;
- glfwGetJoystickButtons(PSGLOBAL(joy1id), &count);
-
- // We need to init and reload bindings, because;
- // 1-joypad button number may differ with saved/prvly connected one
- // 2-bindings are not init'ed if there is no joypad at the start
- ControlsManager.InitDefaultControlConfigJoyPad(count);
- CFileMgr::SetDirMyDocuments();
- int32 gta3set = CFileMgr::OpenFile("gta3.set", "r");
- if (gta3set) {
- ControlsManager.LoadSettings(gta3set);
- CFileMgr::CloseFile(gta3set);
- }
- CFileMgr::SetDir("");
- // We call LoadINIControllerSettings after this func., so calling here isn't needed
- break;
- }
- }
- }
-#endif
-
#ifdef CUSTOM_FRONTEND_OPTIONS
bool migrate = cfg.category_size("FrontendOptions") != 0;
for (int i = 0; i < MENUPAGES; i++) {
@@ -453,6 +432,8 @@ void LoadINISettings()
}
}
#endif
+
+ return true;
}
void SaveINISettings()
@@ -508,10 +489,6 @@ void SaveINISettings()
#ifdef FIX_SPRITES
StoreIni("Draw", "FixSprites", CDraw::ms_bFixSprites);
#endif
-
-#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
- StoreIni("Controller", "JoystickName", gSelectedJoystickName, 128);
-#endif
#ifdef CUSTOM_FRONTEND_OPTIONS
for (int i = 0; i < MENUPAGES; i++) {
for (int j = 0; j < NUM_MENUROWS; j++) {