diff --git a/Runtime.meta b/Runtime.meta new file mode 100644 index 0000000..8f63095 --- /dev/null +++ b/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: afa6abacc71057c9a9ac26998ea7001e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Event.cs b/Runtime/Event.cs new file mode 100644 index 0000000..f47edad --- /dev/null +++ b/Runtime/Event.cs @@ -0,0 +1,18 @@ +using System.Runtime.InteropServices; + +namespace SkyHook +{ + [StructLayout(LayoutKind.Sequential)] + public struct SkyHookEvent + { + public ulong Time; + public short Type; + public uint Key; + } + + public enum EventType + { + KeyPressed, + KeyReleased + } +} \ No newline at end of file diff --git a/Runtime/Event.cs.meta b/Runtime/Event.cs.meta new file mode 100644 index 0000000..b51a88f --- /dev/null +++ b/Runtime/Event.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 71a9f666dcf69d17895d94f120487cf7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/SkyHook.Unity.asmdef b/Runtime/SkyHook.Unity.asmdef new file mode 100644 index 0000000..cb7da05 --- /dev/null +++ b/Runtime/SkyHook.Unity.asmdef @@ -0,0 +1,21 @@ +{ + "name": "SkyHook.Unity", + "rootNamespace": "", + "references": [], + "includePlatforms": [ + "Editor", + "LinuxStandalone64", + "CloudRendering", + "macOSStandalone", + "WindowsStandalone32", + "WindowsStandalone64" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Runtime/SkyHook.Unity.asmdef.meta b/Runtime/SkyHook.Unity.asmdef.meta new file mode 100644 index 0000000..22472af --- /dev/null +++ b/Runtime/SkyHook.Unity.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5277a9c527b33a210bfa8bb54a667bf4 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/SkyHookException.cs b/Runtime/SkyHookException.cs new file mode 100644 index 0000000..ba95428 --- /dev/null +++ b/Runtime/SkyHookException.cs @@ -0,0 +1,9 @@ +using System; + +namespace SkyHook +{ + public class SkyHookException : Exception + { + public SkyHookException(string message) : base(message) { } + } +} \ No newline at end of file diff --git a/Runtime/SkyHookException.cs.meta b/Runtime/SkyHookException.cs.meta new file mode 100644 index 0000000..de06377 --- /dev/null +++ b/Runtime/SkyHookException.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0bcd47f1c888fa9c685231dbe5ee5e09 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/SkyHookManager.cs b/Runtime/SkyHookManager.cs new file mode 100644 index 0000000..a7f2b7a --- /dev/null +++ b/Runtime/SkyHookManager.cs @@ -0,0 +1,86 @@ +using UnityEngine; + +namespace SkyHook +{ + public class SkyHookManager : MonoBehaviour + { + private static SkyHookManager _instance; + + internal static bool IsFocused; + + public bool requireFocus = true; + + private bool _started; + + public static SkyHookManager Instance + { + get + { + if (_instance) return _instance; + + var obj = new GameObject("SkyHook Manager"); + + _instance = obj.AddComponent(); + + DontDestroyOnLoad(_instance); + + return _instance; + } + } + + private void HookCallback(SkyHookEvent ev) + { + Debug.Log($"{ev.Type} {ev.Key} {ev.Time}"); + } + + private void StartHook() + { + var result = SkyHookNative.StartHook(HookCallback); + + if (result != null) + { + throw new SkyHookException(result); + } + + _started = true; + } + + private void StopHook() + { + if (!_started) return; + + var result = SkyHookNative.StopHook(); + + if (result != null) + { + throw new SkyHookException(result); + } + + _started = false; + } + + public static void Start() + { + Instance.StartHook(); + } + + public static void Stop() + { + Instance.StopHook(); + } + + private void OnDestroy() + { + Debug.Log("Destroy"); + StopHook(); + } + + private void Run() + { + if (requireFocus) + { + IsFocused = Application.isFocused; + } + } + } +} \ No newline at end of file diff --git a/Runtime/SkyHookManager.cs.meta b/Runtime/SkyHookManager.cs.meta new file mode 100644 index 0000000..5cb6e41 --- /dev/null +++ b/Runtime/SkyHookManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3bbea13638e782043b24c6ca237e1145 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/SkyHookNative.cs b/Runtime/SkyHookNative.cs new file mode 100644 index 0000000..0652a5a --- /dev/null +++ b/Runtime/SkyHookNative.cs @@ -0,0 +1,17 @@ +using System.Runtime.InteropServices; + +namespace SkyHook +{ + internal class SkyHookNative + { + public delegate void Callback(SkyHookEvent ev); + + private const string LIB = "skyhook"; + + [DllImport(LIB, EntryPoint = "start_hook", CallingConvention = CallingConvention.Cdecl)] + public static extern string StartHook(Callback callback); + + [DllImport(LIB, EntryPoint = "stop_hook", CallingConvention = CallingConvention.Cdecl)] + public static extern string StopHook(); + } +} \ No newline at end of file diff --git a/Runtime/SkyHookNative.cs.meta b/Runtime/SkyHookNative.cs.meta new file mode 100644 index 0000000..e10bdb8 --- /dev/null +++ b/Runtime/SkyHookNative.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 974a62ff1f0eca7fd9e983217ddad701 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/plugins.meta b/plugins.meta new file mode 100644 index 0000000..4598117 --- /dev/null +++ b/plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4fea41e2cee5d4ff3832de5cd5c0f959 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/plugins/i686.meta b/plugins/i686.meta new file mode 100644 index 0000000..16c2b9d --- /dev/null +++ b/plugins/i686.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2a170cb9c843facdaae41a2ec128149c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/plugins/i686/skyhook.dll b/plugins/i686/skyhook.dll new file mode 100755 index 0000000..d58093e Binary files /dev/null and b/plugins/i686/skyhook.dll differ diff --git a/plugins/i686/skyhook.dll.meta b/plugins/i686/skyhook.dll.meta new file mode 100644 index 0000000..fe606cd --- /dev/null +++ b/plugins/i686/skyhook.dll.meta @@ -0,0 +1,63 @@ +fileFormatVersion: 2 +guid: a9d394d2428104e008ccad309aac73a6 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 1 + Exclude Linux64: 0 + Exclude OSXUniversal: 0 + Exclude Win: 0 + Exclude Win64: 1 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: Windows + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: None + - first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: x86 + - first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: None + userData: + assetBundleName: + assetBundleVariant: diff --git a/plugins/x86_64.meta b/plugins/x86_64.meta new file mode 100644 index 0000000..0134162 --- /dev/null +++ b/plugins/x86_64.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 89f86fe0a57397009914615d01bb0a10 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/plugins/x86_64/libskyhook.so b/plugins/x86_64/libskyhook.so new file mode 100755 index 0000000..87ac84d Binary files /dev/null and b/plugins/x86_64/libskyhook.so differ diff --git a/plugins/x86_64/libskyhook.so.meta b/plugins/x86_64/libskyhook.so.meta new file mode 100644 index 0000000..45877fc --- /dev/null +++ b/plugins/x86_64/libskyhook.so.meta @@ -0,0 +1,63 @@ +fileFormatVersion: 2 +guid: 3fe709bbc3d4a927fb0d7e518e19b911 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux64: 0 + Exclude OSXUniversal: 1 + Exclude Win: 0 + Exclude Win64: 0 + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + OS: Linux + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: None + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: x86_64 + userData: + assetBundleName: + assetBundleVariant: diff --git a/plugins/x86_64/skyhook.dll b/plugins/x86_64/skyhook.dll new file mode 100755 index 0000000..bce0df0 Binary files /dev/null and b/plugins/x86_64/skyhook.dll differ diff --git a/plugins/x86_64/skyhook.dll.meta b/plugins/x86_64/skyhook.dll.meta new file mode 100644 index 0000000..9432cc0 --- /dev/null +++ b/plugins/x86_64/skyhook.dll.meta @@ -0,0 +1,63 @@ +fileFormatVersion: 2 +guid: ec214c927694799828418d2a065c10f6 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux64: 0 + Exclude OSXUniversal: 0 + Exclude Win: 0 + Exclude Win64: 0 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + OS: Windows + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: x86_64 + - first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: None + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: x86_64 + userData: + assetBundleName: + assetBundleVariant: