Example #1
0
        /// <summary>
        /// Get the hook callback.
        /// </summary>
        /// <param name="nCode"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            IntPtr mainWindowHandle = gameMemory.GetMainProcess().MainWindowHandle;

            if ((currentNFSGame != NFSGame.World && !NFS.IsGameMinimized()) || (currentNFSGame == NFSGame.World && NFS.IsGameFocused()))
            {
                if (nCode >= 0 && wParam == (IntPtr)257) // OnKeyUp
                {
                    int num = Marshal.ReadInt32(lParam);

                    if (num == resetKey)
                    {
                        Restart();
                    }

                    for (int i = 0; i < scripts.Count; i++)
                    {
                        if (scripts[i].HasOnKeyUp)
                        {
                            scripts[i].CallModFunction(ModScript.ModMethod.OnKeyUp, (NFSSKeys)num);
                        }
                    }
                }

                if (nCode >= 0 && wParam == (IntPtr)256) // OnKeyDown
                {
                    int num = Marshal.ReadInt32(lParam);
                    for (int i = 0; i < scripts.Count; i++)
                    {
                        if (scripts[i].HasOnKeyDown)
                        {
                            scripts[i].CallModFunction(ModScript.ModMethod.OnKeyDown, (NFSSKeys)num);
                        }
                    }
                }
            }

            return(NativeMethods.CallNextHookEx(_hookID, nCode, wParam, lParam));
        }
Example #2
0
        /// <summary>
        /// Get the hook callback.
        /// </summary>
        /// <param name="nCode">classic EA param that does nothing</param>
        /// <param name="wParam">event param</param>
        /// <param name="lParam">key num param</param>
        /// <returns></returns>
        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            var mainWindowHandle = GameMemory.GetMainProcess().MainWindowHandle;

            if ((_currentNFSGame == NFSGame.World || NFS.IsGameMinimized()) &&
                (_currentNFSGame != NFSGame.World || !NFS.IsGameFocused()))
                return NativeMethods.CallNextHookEx(_hookId, nCode, wParam, lParam);
            if (nCode >= 0 && wParam == (IntPtr)257) // OnKeyUp
            {                    
                var num = Marshal.ReadInt32(lParam);

                if (num == ResetKey)
                    Restart();

                foreach (var script in _scripts)
                {
                    if (script.HasOnKeyUp)
                    {
                        script.CallModFunction(ModScript.ModMethod.OnKeyUp, (NFSSKeys)num);
                    }
                }
            }

            if (nCode < 0 || wParam != (IntPtr) 256) // OnKeyDown
                return NativeMethods.CallNextHookEx(_hookId, nCode, wParam, lParam);
            {
                var num = Marshal.ReadInt32(lParam);
                foreach (var script in _scripts)
                {
                    if (script.HasOnKeyDown)
                    {
                        script.CallModFunction(ModScript.ModMethod.OnKeyDown, (NFSSKeys)num);
                    }
                }
            }

            return NativeMethods.CallNextHookEx(_hookId, nCode, wParam, lParam);
        }