@@ -205,21 +205,20 @@ class InputManager
205205
206206 SDL_Init (SDL_INIT_GAMEPAD | SDL_INIT_VIDEO);
207207
208+ // Need to setup SDL_Window for SDL to see keyboard events
208209 SDL_PropertiesID props = SDL_CreateProperties ();
209- if (props == 0 )
210- {
211- spdlog::error (__FUNCTION__ " : failed to create properties ({})" , SDL_GetError ());
212- }
213- else
210+ if (props)
214211 {
215212 SDL_SetStringProperty (props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, " OutRun2006Tweaks" );
216213 SDL_SetNumberProperty (props, SDL_PROP_WINDOW_CREATE_RESIZABLE_BOOLEAN, true );
217214 SDL_SetNumberProperty (props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, 1280 );
218215 SDL_SetNumberProperty (props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, 720 );
219216 SDL_SetPointerProperty (props, SDL_PROP_WINDOW_CREATE_WIN32_HWND_POINTER, hwnd);
220217
221- window = SDL_CreateWindowWithProperties (props); // Needed for SDL keyboard events
218+ window = SDL_CreateWindowWithProperties (props);
222219 }
220+ else
221+ spdlog::error (__FUNCTION__ " : failed to create properties ({}), keyboard might not work with UseNewInput properly!" , SDL_GetError ());
223222
224223 setupKeyboardBindings ();
225224 }
@@ -488,12 +487,6 @@ class InputManager
488487};
489488InputManager InputManager::instance;
490489
491- void InputManager_Init (HWND window)
492- {
493- if (Settings::UseNewInput)
494- InputManager::instance.init (window);
495- }
496-
497490void InputManager_Update ()
498491{
499492 if (Settings::UseNewInput)
@@ -559,6 +552,13 @@ class NewInputHook : public Hook
559552 return VolumeSwitch_hook.ccall <int >(volumeId);
560553 }
561554
555+ inline static SafetyHookMid WindowInit_hook = {};
556+ static void WindowInit_dest (SafetyHookContext& ctx)
557+ {
558+ if (Settings::UseNewInput)
559+ InputManager::instance.init ((HWND)ctx.ebp );
560+ }
561+
562562public:
563563 std::string_view description () override
564564 {
@@ -577,6 +577,7 @@ class NewInputHook : public Hook
577577 GetVolume_hook = safetyhook::create_inline (Module::exe_ptr (0x53720 ), GetVolume_dest);
578578 GetVolumeOld_hook = safetyhook::create_inline (Module::exe_ptr (0x53750 ), GetVolumeOld_dest);
579579 VolumeSwitch_hook = safetyhook::create_inline (Module::exe_ptr (0x53780 ), VolumeSwitch_dest);
580+ WindowInit_hook = safetyhook::create_mid (Module::exe_ptr (0xEB2B ), WindowInit_dest);
580581
581582 return true ;
582583 }
0 commit comments