SDL: Make gameinput.cpp c++98-compatible

From 5924f36dc6e3d00cf3d25f81d18c5e1bce75ed7c Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Tue, 28 Jul 2026 03:49:08 +0200
Subject: [PATCH] Make gameinput.cpp c++98-compatible

---
 CMakeLists.txt                           | 21 +++++------
 src/core/windows/gameinput/gameinput.cpp | 45 +++++++++++++++++-------
 src/core/windows/gameinput/gameinput.h   |  7 +++-
 3 files changed, 46 insertions(+), 27 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6ecbae2c4244d..cf861077238ab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2348,21 +2348,16 @@ elseif(WINDOWS OR CYGWIN)
 
   set(HAVE_GAMEINPUT_H 1)
   sdl_include_directories(PRIVATE SYSTEM "${SDL3_SOURCE_DIR}/src/core/windows/gameinput")
-  if("cxx_std_11" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
-    sdl_sources("${SDL3_SOURCE_DIR}/src/core/windows/gameinput/gameinput.cpp")
-    sdl_compile_features(cxx_std_11)
-    if(USE_GCC OR USE_CLANG)
-      # Avoid a dependency on libstdc++-X.dll for `__gxx_personality_seh0`
-      check_c_compiler_flag(-fno-exceptions COMPILER_SUPPORTS_FNO_EXCEPTIONS)
-      if(COMPILER_SUPPORTS_FNO_EXCEPTIONS)
-        set_property(SOURCE "${SDL3_SOURCE_DIR}/src/core/windows/gameinput/gameinput.cpp" APPEND PROPERTY COMPILE_OPTIONS "-fno-exceptions")
-        set_property(SOURCE "${SDL3_SOURCE_DIR}/src/core/windows/gameinput/gameinput.cpp" PROPERTY SKIP_PRECOMPILE_HEADERS 1)
-      endif()
+  sdl_sources("${SDL3_SOURCE_DIR}/src/core/windows/gameinput/gameinput.cpp")
+  if(USE_GCC OR USE_CLANG)
+    # Avoid a dependency on libstdc++-X.dll for `__gxx_personality_seh0`
+    check_c_compiler_flag(-fno-exceptions COMPILER_SUPPORTS_FNO_EXCEPTIONS)
+    if(COMPILER_SUPPORTS_FNO_EXCEPTIONS)
+      set_property(SOURCE "${SDL3_SOURCE_DIR}/src/core/windows/gameinput/gameinput.cpp" APPEND PROPERTY COMPILE_OPTIONS "-fno-exceptions")
+      set_property(SOURCE "${SDL3_SOURCE_DIR}/src/core/windows/gameinput/gameinput.cpp" PROPERTY SKIP_PRECOMPILE_HEADERS 1)
     endif()
-    set(SDL_GAMEINPUT_DYNAMIC 0)
-  else()
-    set(SDL_GAMEINPUT_DYNAMIC 1)
   endif()
+  set(SDL_GAMEINPUT_DYNAMIC 0)
 
   check_include_file(dxgi1_5.h HAVE_DXGI1_5_H)
   check_include_file(dxgi1_6.h HAVE_DXGI1_6_H)
diff --git a/src/core/windows/gameinput/gameinput.cpp b/src/core/windows/gameinput/gameinput.cpp
index ba62658870a1d..3841c1ec191f9 100644
--- a/src/core/windows/gameinput/gameinput.cpp
+++ b/src/core/windows/gameinput/gameinput.cpp
@@ -37,6 +37,9 @@
 #include <stdint.h>
 
 // Start SDL modifications
+
+// !! File has been modified for compatibility with pre-c++11 toolchains
+
 #ifndef RRF_SUBKEY_WOW6432KEY
 #define RRF_SUBKEY_WOW6432KEY 0x00020000
 #endif
@@ -45,6 +48,11 @@
 #define wcscpy_s(DST, DST_SIZE, SRC) SDL_wcslcpy(DST, SRC, DST_SIZE)
 #define wcscat_s(DST, DST_SIZE, SRC) SDL_wcslcat(DST, SRC, DST_SIZE)
 
+#if __cplusplus < 2011003L
+#define noexcept
+#define nullptr NULL
+#endif
+
 // Additional changes:
 // - Removed unused `static uint32_t g_productType = PRODUCT_UNDEFINED;`
 // - Removed unused `static HMODULE g_ntdllDll = nullptr;`
@@ -102,6 +110,13 @@ template <typename T>
 class Vector
 {
 public:
+    Vector()
+        : m_data(nullptr)
+        , m_count(0)
+        , m_capacity(0)
+    {
+    }
+
     ~Vector()
     {
         if (m_data != nullptr)
@@ -163,9 +178,9 @@ class Vector
     }
 
 private:
-    T*     m_data = nullptr;
-    size_t m_count = 0;
-    size_t m_capacity = 0;
+    T*     m_data;
+    size_t m_count;
+    size_t m_capacity;
 };
 
 template <typename T>
@@ -244,8 +259,8 @@ class String
     Vector<T> m_string;
 };
 
-using WString = String<wchar_t>;
-using AString = String<char>;
+typedef String<wchar_t> WString;
+typedef String<char> AString;
 
 
 //
@@ -344,10 +359,11 @@ static HRESULT GetApplicationDirectory(
 static HRESULT GetRedistDirectory(
     _Inout_ WString* redistDir) noexcept
 {
-    constexpr const wchar_t* RedistDirRegPath = L"SOFTWARE\\Microsoft\\GameInput";
-    constexpr const wchar_t* RedistDirValueName = L"RedistDir";
+    static const wchar_t* RedistDirRegPath = L"SOFTWARE\\Microsoft\\GameInput";
+    static const wchar_t* RedistDirValueName = L"RedistDir";
 
-    decltype(RegGetValueW)* regGetValue = nullptr;
+    typedef LONG (WINAPI *RegGetValueW_t)(HKEY,LPCWSTR,LPCWSTR,DWORD,LPDWORD,PVOID,LPDWORD);
+    RegGetValueW_t regGetValue = nullptr;
     RETURN_IF_FAILED(LoadSystemModuleProc(
         &g_advapi32Dll,
         L"advapi32.dll",
@@ -386,21 +402,24 @@ static HRESULT GetFileVersion(
 {
     *version = 0;
 
-    decltype(GetFileVersionInfoSizeW)* getFileVersionInfoSize = nullptr;
+    typedef DWORD (WINAPI *GetFileVersionInfoSizeW_t)(LPCWSTR,LPDWORD);
+    GetFileVersionInfoSizeW_t getFileVersionInfoSize = nullptr;
     RETURN_IF_FAILED(LoadSystemModuleProc(
         &g_versionDll,
         L"version.dll",
         "GetFileVersionInfoSizeW",
         &getFileVersionInfoSize));
 
-    decltype(GetFileVersionInfoW)* getFileVersionInfo = nullptr;
+    typedef BOOL (WINAPI *GetFileVersionInfoW_t)(LPCWSTR,DWORD,DWORD,LPVOID);
+    GetFileVersionInfoW_t getFileVersionInfo = nullptr;
     RETURN_IF_FAILED(LoadSystemModuleProc(
         &g_versionDll,
         L"version.dll",
         "GetFileVersionInfoW",
         &getFileVersionInfo));
 
-    decltype(VerQueryValueW)* verQueryValue = nullptr;
+    typedef BOOL (WINAPI *VerQueryValueW_t)(LPCVOID,LPCWSTR,LPVOID*,PUINT);
+    VerQueryValueW_t verQueryValue = nullptr;
     RETURN_IF_FAILED(LoadSystemModuleProc(
         &g_versionDll,
         L"version.dll",
@@ -586,7 +605,7 @@ static HRESULT GameInputCreateWithVersion(
         RETURN_IF_FAILED(LoadGameInputDll(&g_gameInputDll));
     }
 
-    using GameInputInitializeFn = HRESULT (*)(
+    typedef HRESULT (*GameInputInitializeFn)(
         _In_ REFIID riid,
         _COM_Outptr_ LPVOID* ppv);
 
@@ -602,7 +621,7 @@ static HRESULT GameInputCreateWithVersion(
         // did not find it via above query, we must be running an old version of GameInput
         // which only supports the v0 API. Don't attempt to use it for newer API versions.
 
-        using GameInputCreateFn = HRESULT (*)(
+        typedef HRESULT (*GameInputCreateFn)(
             _COM_Outptr_ LPVOID* ppv);
 
         GameInputCreateFn gameInputCreate = nullptr;
diff --git a/src/core/windows/gameinput/gameinput.h b/src/core/windows/gameinput/gameinput.h
index f3b94756781ff..0193878f656ac 100644
--- a/src/core/windows/gameinput/gameinput.h
+++ b/src/core/windows/gameinput/gameinput.h
@@ -568,12 +568,17 @@ interface IGameInputForceFeedbackEffect;
 interface IGameInputMapper;
 
 typedef uint64_t GameInputCallbackToken;
-
+// start SDL modifications
+#if 0
+// end SDL modifications
 constexpr GUID GAMEINPUT_HAPTIC_LOCATION_NONE          = { 0x00000000, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };
 constexpr GUID GAMEINPUT_HAPTIC_LOCATION_GRIP_LEFT     = { 0x08c707c2, 0x66bb, 0x406c, { 0xa8, 0x4a, 0xdf, 0xe0, 0x85, 0x12, 0x0a, 0x92 } };
 constexpr GUID GAMEINPUT_HAPTIC_LOCATION_GRIP_RIGHT    = { 0x155a0b77, 0x8bb2, 0x40db, { 0x86, 0x90, 0xb6, 0xd4, 0x11, 0x26, 0xdf, 0xc1 } };
 constexpr GUID GAMEINPUT_HAPTIC_LOCATION_TRIGGER_LEFT  = { 0x8de4d896, 0x5559, 0x4081, { 0x86, 0xe5, 0x17, 0x24, 0xcc, 0x07, 0xc6, 0xbc } };
 constexpr GUID GAMEINPUT_HAPTIC_LOCATION_TRIGGER_RIGHT = { 0xff0cb557, 0x3af5, 0x406b, { 0x8b, 0x0f, 0x55, 0x5a, 0x2d, 0x92, 0xa2, 0x20 } };
+// start SDL modifications
+#endif
+// end SDL modifications
 
 const uint32_t GAMEINPUT_HAPTIC_MAX_LOCATIONS              = 8;
 const uint32_t GAMEINPUT_HAPTIC_MAX_AUDIO_ENDPOINT_ID_SIZE = 256;