0x0ade / XnaToFna

Relink games / tools using the XNA Framework 4.0 to use FNA instead
zlib License
51 stars 5 forks source link

The Monolithic Win32 API Workaround Thread #1

Open flibitijibibo opened 7 years ago

flibitijibibo commented 7 years ago

This is where we dump stack traces from Win32 things that haven't been worked around yet or have regressed in some way.

Starting with Stardew Valley, using the stardewFNA script:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: user32.dll
  at (wrapper managed-to-native) StardewValley.KeyboardInput:CallWindowProc (intptr,intptr,uint,intptr,intptr)
  at StardewValley.KeyboardInput.HookProc (System.IntPtr hWnd, System.UInt32 msg, System.IntPtr wParam, System.IntPtr lParam) [0x00000] in <8735ddc4c49943f59d59831f1ffc73cf>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /builddir/build/BUILD/mono-4.6.2/mcs/class/corlib/System.Reflection/MonoMethod.cs:305 
   --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0004d] in /builddir/build/BUILD/mono-4.6.2/mcs/class/corlib/System.Reflection/MonoMethod.cs:313 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /builddir/build/BUILD/mono-4.6.2/mcs/class/referencesource/mscorlib/system/reflection/methodbase.cs:229 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00107] in /builddir/build/BUILD/mono-4.6.2/mcs/class/corlib/System/Delegate.cs:461 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x0000b] in /builddir/build/BUILD/mono-4.6.2/mcs/class/corlib/System/MulticastDelegate.cs:67 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in /builddir/build/BUILD/mono-4.6.2/mcs/class/corlib/System/Delegate.cs:406 
  at XnaToFna.PInvokeHelper.CallWindowHook (System.IntPtr hWnd, System.UInt32 Msg, System.IntPtr wParam, System.IntPtr lParam) [0x00033] in /home/flibitijibibo/.wine/drive_c/Program Files/Steam/steamapps/common/Stardew Valley/XnaToFna/src/Helper/PInvokeHooks/PInvokeHooks.cs:105 
  at XnaToFna.PInvokeHelper.CallWindowHook (XnaToFna.ProxyForms.Messages Msg, System.IntPtr wParam, System.IntPtr lParam) [0x0003d] in <4ffdb51268804542a4c7a670fe1965f0>:0 
  at XnaToFna.PInvokeHelper.CallHooks (XnaToFna.ProxyForms.Messages Msg, System.IntPtr wParam, System.IntPtr lParam, XnaToFna.ProxyForms.Message& lParamMsg, System.Boolean global, System.Boolean window, System.Boolean allWindows) [0x00063] in /home/flibitijibibo/.wine/drive_c/Program Files/Steam/steamapps/common/Stardew Valley/XnaToFna/src/Helper/PInvokeHooks/PInvokeHooks.cs:58 
  at XnaToFna.PInvokeHelper.CallHooks (XnaToFna.ProxyForms.Messages Msg, System.IntPtr wParam, XnaToFna.ProxyForms.Message lParamMsg, System.Boolean global, System.Boolean window, System.Boolean allWindows) [0x0001e] in /home/flibitijibibo/.wine/drive_c/Program Files/Steam/steamapps/common/Stardew Valley/XnaToFna/src/Helper/PInvokeHooks/PInvokeHooks.cs:42 
  at XnaToFna.PInvokeHelper.CallHooks (XnaToFna.ProxyForms.Messages Msg, System.IntPtr wParam, System.IntPtr lParam, System.Boolean global, System.Boolean window, System.Boolean allWindows) [0x0002e] in <4ffdb51268804542a4c7a670fe1965f0>:0 
  at XnaToFna.KeyboardEvents.CharEntered (System.Char c) [0x0000b] in <4ffdb51268804542a4c7a670fe1965f0>:0 
  at Microsoft.Xna.Framework.Input.TextInputEXT.OnTextInput (System.Char c) [0x00012] in /home/flibitijibibo/.wine/drive_c/Program Files/Steam/steamapps/common/Stardew Valley/XnaToFna/lib-projs/FNA/src/Input/TextInputEXT.cs:51 
  at Microsoft.Xna.Framework.SDL2_FNAPlatform.RunLoop (Microsoft.Xna.Framework.Game game) [0x005ee] in /home/flibitijibibo/.wine/drive_c/Program Files/Steam/steamapps/common/Stardew Valley/XnaToFna/lib-projs/FNA/src/FNAPlatform/SDL2_FNAPlatform.cs:785 
  at Microsoft.Xna.Framework.Game.Run () [0x00038] in /home/flibitijibibo/.wine/drive_c/Program Files/Steam/steamapps/common/Stardew Valley/XnaToFna/lib-projs/FNA/src/Game.cs:424 
  at StardewValley.Program.Main (System.String[] args) [0x00028] in <8735ddc4c49943f59d59831f1ffc73cf>:0
0x0ade commented 7 years ago

The CallWindowProc issue was caused by me accidentally moving over the CallWindowProc replacement from PInvokeHooks to PInvokeHelper to differentiate between actual hooks and hook calling / management methods.

This specific issue should now be fixed with https://github.com/0x0ade/XnaToFna/commit/ba891045491f0be7bf037aa2f01e0dcc97acf646 for you, too

0x0ade commented 7 years ago

Nevertheless, there are still two unhooked Win32 calls left in Stardew Valley...

[XnaToFna] [PreProcess] [PInvokeHooks] Found unhooked call to LoadKeyboardLayout (System.Int64 StardewValley.KeyboardLayout::LoadKeyboardLayout(System.String,System.UInt32))
[XnaToFna] [PreProcess] [PInvokeHooks] Found unhooked call to GetKeyboardLayoutName (System.Int64 StardewValley.KeyboardLayout::GetKeyboardLayoutName(System.Text.StringBuilder))

... and to keep track of what still needs to be done, mouse event messages still need to be implemented. DLC Quest seems to listen to Win32 mouse messages.
EDIT: The following commit took care of the Win32 mouse event messages: https://github.com/0x0ade/XnaToFna/commit/99155f5e8797a274f22d34453169832101b3ab46

0x0ade commented 7 years ago

LoadKeyboardLayout and GetKeyboardLayoutName are now stubbed to behave as if they'd always succeed, but as if the only locale available is EN-US (0x00000409): https://github.com/0x0ade/XnaToFna/commit/72c9fbee18c1d0765388590a93e3b80fa6bbdd60

Stardew Valley doesn't seem to actually use this. Neither does it use UnloadKeyboardLayout, yet I also stubbed it in case another game might: https://github.com/0x0ade/XnaToFna/commit/9921d35db5192440b128f70bfee4598dc9441b34

flibitijibibo commented 7 years ago

The only other time I ever saw it was in Dust: AET to do GetKeyFromScancode-type defaults. It's honestly more rare than it should be.