Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add preliminary Unix compatibility (using Mono; resolves #1384) #1380

Merged
merged 23 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
887bdc7
Move PlatformSpecificLinkedLibs and implementations to common and rename
YoshiRulz Nov 28, 2018
76ce601
Specify file ext. at LoadPlatformSpecific call site
YoshiRulz Nov 28, 2018
e2c470d
Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton
YoshiRulz Nov 28, 2018
0ebae40
Inline var Resolver
YoshiRulz Nov 28, 2018
89b1fbe
Use PlatformLinkedLibManager internally
YoshiRulz Nov 28, 2018
eb4bef4
Move plugin load check to LinkedLibManager, use LinkedLibManager
YoshiRulz Nov 29, 2018
54b507f
Interpolate
YoshiRulz Nov 29, 2018
83a53bd
Return exit code from dlclose/FreeLibrary
YoshiRulz Nov 29, 2018
fa9ce50
Skip all calls to externs in BlipBufDll when using mono
YoshiRulz Nov 30, 2018
4ee82d2
Use PlatformLinkedLibManager in SevenZipLibraryManager
YoshiRulz Nov 30, 2018
81665f1
Add expected return value to workaround (from testing on Win32)
YoshiRulz Nov 30, 2018
79d740f
Remove ".dll" from DllImport attr, remove temporary workaround, see d…
YoshiRulz Dec 1, 2018
e86f03b
Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper)
YoshiRulz Dec 1, 2018
318fd36
Update OpenTK again but better (for #1384)
YoshiRulz Dec 2, 2018
e95d855
Add Mono run script
YoshiRulz Dec 3, 2018
d3e978c
Add libblip_buf.so (temporary)
YoshiRulz Dec 3, 2018
c168ab1
Add distro detection, add "already running" and "unknown distro" mess…
YoshiRulz Dec 9, 2018
140465d
Gray-out Lua Console on Unix
YoshiRulz Dec 10, 2018
e7af84d
Extract superclass from EmuLuaLibrary, add shell implementation for Unix
YoshiRulz Dec 14, 2018
37445d6
Specify libdl version, Fedora doesn't have the versionless symlink
YoshiRulz Dec 14, 2018
cca7c29
Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix
YoshiRulz Dec 15, 2018
ef8a783
Transform OpenTK keyboard input into a `List<KeyEvent>` and read that
YoshiRulz Dec 18, 2018
67d9222
Remove debug `using ...;`
YoshiRulz Dec 20, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Assets/EmuHawkMono.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
cd "$(dirname "$0")"
if [ "$(ps -C "mono" -o "cmd" --no-headers | grep "EmuHawk.exe")" ]; then
echo "EmuHawk is already running, exiting..."
exit 0
fi
libpath=""
if [ "$(command -v lsb_release)" ]; then
case "$(lsb_release -i | cut -c17- | tr -d "\n")" in
"Arch"|"ManjaroLinux") libpath="/usr/lib/wine";;
"Ubuntu"|"LinuxMint") libpath="/usr/lib/x86_64-linux-gnu/wine";;
esac
fi
if [ -z "$libpath" ]; then
printf "%s\n" "Unknown distro, assuming WINE library location is /usr/lib/wine..."
libpath="/usr/lib/wine"
fi
LD_LIBRARY_PATH="$libpath" mono ./EmuHawk.exe
Binary file added Assets/libblip_buf.so
Binary file not shown.
18 changes: 11 additions & 7 deletions BizHawk.Client.Common/7z/LibraryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ You should have received a copy of the GNU Lesser General Public License
along with SevenZipSharp. If not, see <http://www.gnu.org/licenses/>.
*/

using BizHawk.Common;

using System;
using System.Collections.Generic;
#if !WINCE && !MONO
Expand Down Expand Up @@ -87,6 +89,8 @@ internal static class SevenZipLibraryManager
// private static string _LibraryVersion;
private static bool? _modifyCapabale;

private static readonly PlatformLinkedLibSingleton.PlatformLinkedLibManager libLoader = PlatformLinkedLibSingleton.LinkedLibManager;

private static void InitUserInFormat(object user, InArchiveFormat format)
{
if (!_inArchives.ContainsKey(user))
Expand Down Expand Up @@ -148,16 +152,16 @@ public static void LoadLibrary(object user, Enum format)
//{
// throw new SevenZipLibraryException("DLL file does not exist.");
//}
if ((_modulePtr = NativeMethods.LoadLibrary(_libraryFileName)) == IntPtr.Zero)
if ((_modulePtr = libLoader.LoadPlatformSpecific(_libraryFileName)) == IntPtr.Zero)
{
//try a different directory
string alternateFilename = Path.Combine(Path.Combine(Path.GetDirectoryName(_libraryFileName),"dll"),"7z.dll");
if ((_modulePtr = NativeMethods.LoadLibrary(alternateFilename)) == IntPtr.Zero)
if ((_modulePtr = libLoader.LoadPlatformSpecific(alternateFilename)) == IntPtr.Zero)
throw new SevenZipLibraryException("failed to load library.");
}
if (NativeMethods.GetProcAddress(_modulePtr, "GetHandlerProperty") == IntPtr.Zero)
if (libLoader.GetProcAddr(_modulePtr, "GetHandlerProperty") == IntPtr.Zero)
{
NativeMethods.FreeLibrary(_modulePtr);
libLoader.FreePlatformSpecific(_modulePtr);
throw new SevenZipLibraryException("library is invalid.");
}
}
Expand Down Expand Up @@ -431,7 +435,7 @@ public static void FreeLibrary(object user, Enum format)
if (_totalUsers == 0)
{
#if !WINCE && !MONO
NativeMethods.FreeLibrary(_modulePtr);
libLoader.FreePlatformSpecific(_modulePtr);

#endif
_modulePtr = IntPtr.Zero;
Expand Down Expand Up @@ -466,7 +470,7 @@ public static IInArchive InArchive(InArchiveFormat format, object user)
}
var createObject = (NativeMethods.CreateObjectDelegate)
Marshal.GetDelegateForFunctionPointer(
NativeMethods.GetProcAddress(_modulePtr, "CreateObject"),
libLoader.GetProcAddr(_modulePtr, "CreateObject"),
typeof(NativeMethods.CreateObjectDelegate));
if (createObject == null)
{
Expand Down Expand Up @@ -525,7 +529,7 @@ public static IOutArchive OutArchive(OutArchiveFormat format, object user)
}
var createObject = (NativeMethods.CreateObjectDelegate)
Marshal.GetDelegateForFunctionPointer(
NativeMethods.GetProcAddress(_modulePtr, "CreateObject"),
libLoader.GetProcAddr(_modulePtr, "CreateObject"),
typeof(NativeMethods.CreateObjectDelegate));
if (createObject == null)
{
Expand Down
12 changes: 1 addition & 11 deletions BizHawk.Client.Common/7z/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,8 @@ public delegate int CreateObjectDelegate(
[MarshalAs(UnmanagedType.Interface)] out object outObject);

#endregion

[DllImport("kernel32.dll", BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string fileName);

[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FreeLibrary(IntPtr hModule);

[DllImport("kernel32.dll", BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string procName);
#endif

#if WINCE
[DllImport("7z.dll", EntryPoint="CreateObject")]
public static extern int CreateCOMObject(
Expand Down
2 changes: 0 additions & 2 deletions BizHawk.Client.Common/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,5 @@ public static SystemInfo SystemInfo
}

public static Dictionary<string, object> UserBag = new Dictionary<string, object>();

public static bool RunningOnUnix = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
}
}
2 changes: 2 additions & 0 deletions BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,8 @@
<Compile Include="tools\Lua\Libraries\EmuLuaLibrary.Input.cs" />
<Compile Include="tools\Lua\Libraries\EmuLuaLibrary.Savestate.cs" />
<Compile Include="tools\Lua\Libraries\EmuLuaLibrary.Tastudio.cs" />
<Compile Include="tools\Lua\Libraries\NotReallyLuaLibrary.cs" />
<Compile Include="tools\Lua\Libraries\PlatformEmuLuaLibrary.cs" />
<Compile Include="tools\Lua\LuaAutocompleteInstaller.cs" />
<Compile Include="tools\Lua\LuaCanvas.cs">
<SubType>Form</SubType>
Expand Down
37 changes: 20 additions & 17 deletions BizHawk.Client.EmuHawk/Input/Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
using System.Linq;
using System.Collections.Generic;
using System.Threading;
#if WINDOWS

using SlimDX.DirectInput;
#else
using OpenTK.Input;
#endif

using BizHawk.Common;
using BizHawk.Client.Common;
Expand Down Expand Up @@ -116,19 +113,17 @@ public enum ModifierKey

private Input()
{
#if WINDOWS
UpdateThread = new Thread(UpdateThreadProc)
{
IsBackground = true,
Priority = ThreadPriority.AboveNormal //why not? this thread shouldn't be very heavy duty, and we want it to be responsive
};
UpdateThread.Start();
#endif
}

public static void Initialize()
{
if (Global.RunningOnUnix)
if (PlatformLinkedLibSingleton.RunningOnUnix)
{
OTK_Keyboard.Initialize();
// OTK_Gamepad.Initialize();
Expand All @@ -145,10 +140,11 @@ public static void Initialize()

public static void Cleanup()
{
#if WINDOWS
KeyInput.Cleanup();
GamePad.Cleanup();
#endif
if (!PlatformLinkedLibSingleton.RunningOnUnix)
{
KeyInput.Cleanup();
GamePad.Cleanup();
}
}

public enum InputEventType
Expand Down Expand Up @@ -331,14 +327,22 @@ public List<Tuple<string, float>> GetFloats()
return FloatValuesCopy;
}

#if WINDOWS
void UpdateThreadProc()
{
for (; ; )
while (true)
{
var keyEvents = KeyInput.Update().Concat(IPCKeyInput.Update());
GamePad.UpdateAll();
GamePad360.UpdateAll();
var keyEvents = PlatformLinkedLibSingleton.RunningOnUnix
? OTK_Keyboard.Update()
: KeyInput.Update().Concat(IPCKeyInput.Update());
if (PlatformLinkedLibSingleton.RunningOnUnix)
{
//TODO
}
else
{
GamePad.UpdateAll();
GamePad360.UpdateAll();
}

//this block is going to massively modify data structures that the binding method uses, so we have to lock it all
lock (this)
Expand Down Expand Up @@ -441,7 +445,6 @@ void UpdateThreadProc()
Thread.Sleep(10);
}
}
#endif

public void StartListeningForFloatEvents()
{
Expand Down
38 changes: 34 additions & 4 deletions BizHawk.Client.EmuHawk/Input/OTK_Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,47 @@ namespace BizHawk.Client.EmuHawk
{
public static class OTK_Keyboard
{
private static OpenTK.Input.KeyboardState _kbState;
private static readonly Dictionary<Key, SlimDX.DirectInput.Key> KeyEnumMap = new Dictionary<Key, SlimDX.DirectInput.Key>
{
// A-Z
{Key.A, SlimDX.DirectInput.Key.A}, {Key.B, SlimDX.DirectInput.Key.B}, {Key.C, SlimDX.DirectInput.Key.C}, {Key.D, SlimDX.DirectInput.Key.D}, {Key.E, SlimDX.DirectInput.Key.E}, {Key.F, SlimDX.DirectInput.Key.F}, {Key.G, SlimDX.DirectInput.Key.G}, {Key.H, SlimDX.DirectInput.Key.H}, {Key.I, SlimDX.DirectInput.Key.I}, {Key.J, SlimDX.DirectInput.Key.J}, {Key.K, SlimDX.DirectInput.Key.K}, {Key.L, SlimDX.DirectInput.Key.L}, {Key.M, SlimDX.DirectInput.Key.M}, {Key.N, SlimDX.DirectInput.Key.N}, {Key.O, SlimDX.DirectInput.Key.O}, {Key.P, SlimDX.DirectInput.Key.P}, {Key.Q, SlimDX.DirectInput.Key.Q}, {Key.R, SlimDX.DirectInput.Key.R}, {Key.S, SlimDX.DirectInput.Key.S}, {Key.T, SlimDX.DirectInput.Key.T}, {Key.U, SlimDX.DirectInput.Key.U}, {Key.V, SlimDX.DirectInput.Key.V}, {Key.W, SlimDX.DirectInput.Key.W}, {Key.X, SlimDX.DirectInput.Key.X}, {Key.Y, SlimDX.DirectInput.Key.Y}, {Key.Z, SlimDX.DirectInput.Key.Z},
// 0-9
{Key.Number1, SlimDX.DirectInput.Key.D1}, {Key.Number2, SlimDX.DirectInput.Key.D2}, {Key.Number3, SlimDX.DirectInput.Key.D3}, {Key.Number4, SlimDX.DirectInput.Key.D4}, {Key.Number5, SlimDX.DirectInput.Key.D5}, {Key.Number6, SlimDX.DirectInput.Key.D6}, {Key.Number7, SlimDX.DirectInput.Key.D7}, {Key.Number8, SlimDX.DirectInput.Key.D8}, {Key.Number9, SlimDX.DirectInput.Key.D9}, {Key.Number0, SlimDX.DirectInput.Key.D0},
// misc. printables (ASCII order)
{Key.Space, SlimDX.DirectInput.Key.Space}, {Key.Quote, SlimDX.DirectInput.Key.Apostrophe}, {Key.Comma, SlimDX.DirectInput.Key.Comma}, {Key.Minus, SlimDX.DirectInput.Key.Minus}, {Key.Period, SlimDX.DirectInput.Key.Period}, {Key.Slash, SlimDX.DirectInput.Key.Slash}, {Key.Semicolon, SlimDX.DirectInput.Key.Semicolon}, {Key.Plus, SlimDX.DirectInput.Key.Equals}, {Key.BracketLeft, SlimDX.DirectInput.Key.LeftBracket}, {Key.BackSlash, SlimDX.DirectInput.Key.Backslash}, {Key.BracketRight, SlimDX.DirectInput.Key.RightBracket}, {Key.Tilde, SlimDX.DirectInput.Key.Grave},
// misc. (alphabetically)
{Key.BackSpace, SlimDX.DirectInput.Key.Backspace}, {Key.CapsLock, SlimDX.DirectInput.Key.CapsLock}, {Key.Delete, SlimDX.DirectInput.Key.Delete}, {Key.Down, SlimDX.DirectInput.Key.DownArrow}, {Key.End, SlimDX.DirectInput.Key.End}, {Key.Enter, SlimDX.DirectInput.Key.Return}, {Key.Escape, SlimDX.DirectInput.Key.Escape}, {Key.Home, SlimDX.DirectInput.Key.Home}, {Key.Insert, SlimDX.DirectInput.Key.Insert}, {Key.Left, SlimDX.DirectInput.Key.LeftArrow}, {Key.PageDown, SlimDX.DirectInput.Key.PageDown}, {Key.PageUp, SlimDX.DirectInput.Key.PageUp}, {Key.Pause, SlimDX.DirectInput.Key.Pause}, {Key.Right, SlimDX.DirectInput.Key.RightArrow}, {Key.ScrollLock, SlimDX.DirectInput.Key.ScrollLock}, {Key.Tab, SlimDX.DirectInput.Key.Tab}, {Key.Up, SlimDX.DirectInput.Key.UpArrow},
// modifier
{Key.WinLeft, SlimDX.DirectInput.Key.LeftWindowsKey}, {Key.WinRight, SlimDX.DirectInput.Key.RightWindowsKey}, {Key.ControlLeft, SlimDX.DirectInput.Key.LeftControl}, {Key.ControlRight, SlimDX.DirectInput.Key.RightControl}, {Key.AltLeft, SlimDX.DirectInput.Key.LeftAlt}, {Key.AltRight, SlimDX.DirectInput.Key.RightAlt}, {Key.ShiftLeft, SlimDX.DirectInput.Key.LeftShift}, {Key.ShiftRight, SlimDX.DirectInput.Key.RightShift},

// function
{Key.F1, SlimDX.DirectInput.Key.F1}, {Key.F2, SlimDX.DirectInput.Key.F2}, {Key.F3, SlimDX.DirectInput.Key.F3}, {Key.F4, SlimDX.DirectInput.Key.F4}, {Key.F5, SlimDX.DirectInput.Key.F5}, {Key.F6, SlimDX.DirectInput.Key.F6}, {Key.F7, SlimDX.DirectInput.Key.F7}, {Key.F8, SlimDX.DirectInput.Key.F8}, {Key.F9, SlimDX.DirectInput.Key.F9}, {Key.F10, SlimDX.DirectInput.Key.F10}, {Key.F11, SlimDX.DirectInput.Key.F11}, {Key.F12, SlimDX.DirectInput.Key.F12},
// keypad (alphabetically)
{Key.Keypad0, SlimDX.DirectInput.Key.NumberPad0}, {Key.Keypad1, SlimDX.DirectInput.Key.NumberPad1}, {Key.Keypad2, SlimDX.DirectInput.Key.NumberPad2}, {Key.Keypad3, SlimDX.DirectInput.Key.NumberPad3}, {Key.Keypad4, SlimDX.DirectInput.Key.NumberPad4}, {Key.Keypad5, SlimDX.DirectInput.Key.NumberPad5}, {Key.Keypad6, SlimDX.DirectInput.Key.NumberPad6}, {Key.Keypad7, SlimDX.DirectInput.Key.NumberPad7}, {Key.Keypad8, SlimDX.DirectInput.Key.NumberPad8}, {Key.Keypad9, SlimDX.DirectInput.Key.NumberPad9}, {Key.KeypadAdd, SlimDX.DirectInput.Key.NumberPadPlus}, {Key.KeypadDecimal, SlimDX.DirectInput.Key.NumberPadPeriod}, {Key.KeypadDivide, SlimDX.DirectInput.Key.NumberPadSlash}, {Key.KeypadEnter, SlimDX.DirectInput.Key.NumberPadEnter}, {Key.KeypadMultiply, SlimDX.DirectInput.Key.NumberPadStar}, {Key.KeypadSubtract, SlimDX.DirectInput.Key.NumberPadMinus}
};

private static readonly List<KeyInput.KeyEvent> _eventList = new List<KeyInput.KeyEvent>();
private static KeyboardState _kbState;

public static void Initialize ()
{
_kbState = OpenTK.Input.Keyboard.GetState();
_kbState = Keyboard.GetState();
}

public static void Update ()
public static IEnumerable<KeyInput.KeyEvent> Update ()
{
_eventList.Clear();
var lastState = _kbState;
try
{
_kbState = OpenTK.Input.Keyboard.GetState();
_kbState = Keyboard.GetState();
foreach (KeyValuePair<Key, SlimDX.DirectInput.Key> entry in KeyEnumMap)
{
if (lastState.IsKeyUp(entry.Key) && _kbState.IsKeyDown(entry.Key))
_eventList.Add(new KeyInput.KeyEvent { Key = entry.Value, Pressed = true });
else if (lastState.IsKeyDown(entry.Key) && _kbState.IsKeyUp(entry.Key))
_eventList.Add(new KeyInput.KeyEvent { Key = entry.Value, Pressed = false });
}
}
catch
{
Expand All @@ -30,6 +59,7 @@ public static void Update ()
System.Console.WriteLine("OpenTK Keyboard thread is angry.");
}
}
return _eventList;
}

public static bool IsPressed (Key key)
Expand Down
1 change: 1 addition & 0 deletions BizHawk.Client.EmuHawk/MainForm.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,7 @@ private void ToolsSubMenu_DropDownOpened(object sender, EventArgs e)
RamSearchMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["RAM Search"].Bindings;
HexEditorMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Hex Editor"].Bindings;
LuaConsoleMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Lua Console"].Bindings;
LuaConsoleMenuItem.Enabled = GlobalWin.Tools.IsAvailable<LuaConsole>();
CheatsMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Cheats"].Bindings;
TAStudioMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["TAStudio"].Bindings;
VirtualPadMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Virtual Pad"].Bindings;
Expand Down
4 changes: 0 additions & 4 deletions BizHawk.Client.EmuHawk/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,11 +1119,7 @@ public void ToggleFullscreen(bool allowSuppress = false)

private void OpenLuaConsole()
{
#if WINDOWS
GlobalWin.Tools.Load<LuaConsole>();
#else
MessageBox.Show("Sorry, Lua is not supported on this platform.", "Lua not supported", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
}

public void NotifyLogWindowClosing()
Expand Down
Loading