Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

The Monolithic Win32 API Workaround Thread #1

Open
flibitijibibo opened this issue Feb 28, 2017 · 4 comments
Open

The Monolithic Win32 API Workaround Thread #1

flibitijibibo opened this issue Feb 28, 2017 · 4 comments

Comments

@flibitijibibo
Copy link
Collaborator

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
Copy link
Owner

0x0ade commented Feb 28, 2017

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 ba89104 for you, too

@0x0ade
Copy link
Owner

0x0ade commented Feb 28, 2017

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: 99155f5

@0x0ade
Copy link
Owner

0x0ade commented Mar 1, 2017

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): 72c9fbe

Stardew Valley doesn't seem to actually use this. Neither does it use UnloadKeyboardLayout, yet I also stubbed it in case another game might: 9921d35

@flibitijibibo
Copy link
Collaborator Author

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants