Beispiel #1
0
        /// <summary>
        /// Start loading scripts and applying keys & scripts events.
        /// </summary>
        private static void Start()
        {
            LoadScripts();

            GetGameMemory(_gameProcessName);
            CallPreScriptMethod();
            Log.Print(NFSScriptLoader.INFO_TAG,
                $"Delaying the loader's thread for {(WaitBeforeLoad / 1000)} seconds before initializing.");
            // TODO FIXME: this is a very bad way to do this...
            Thread.Sleep(WaitBeforeLoad);
            Log.Print(NFSScriptLoader.INFO_TAG, "Delay is over, initializing.");
            // Step 1
            if (NFS.IsGameRunning())
            {
                CallInitScriptMethod();
                WaitForGameLoad();

                ApplyAndLoadIntPtrs();
                Log.Print(NFSScriptLoader.INFO_TAG, "Game is fully loaded.");

                CallMainScriptMethod();

                _timer = new Tick {Interval = UpdateTick};
                _timer.Elapsed += Update_Elapsed;
                _timer.Start();

                SetKeyboardHook();
            }
            else Environment.Exit(0);
        }
Beispiel #2
0
        /// <summary>
        /// Start loading scripts and applying keys & scripts events.
        /// </summary>
        private static void Start()
        {
            LoadScripts();

            GetGameMemory(gameProcessName);
            CallPreScriptMethod();
            Log.Print(NFSScriptLoader.INFO_TAG, string.Format("{0} {1} {2}", "Delaying the loader's thread for", (WAIT_BEFORE_LOAD / 1000), "seconds before initializing."));
            Thread.Sleep(WAIT_BEFORE_LOAD);
            Log.Print(NFSScriptLoader.INFO_TAG, "Delay is over, initializing.");
            // Step 1
            if (NFS.IsGameRunning())
            {
                CallInitScriptMethod();
                WaitForGameLoad();

                ApplyAndLoadIntPtrs();
                Log.Print(NFSScriptLoader.INFO_TAG, "Game is fully loaded.");

                CallMainScriptMethod();

                timer          = new Tick();
                timer.Interval = UPDATE_TICK;
                timer.Elapsed += Update_Elapsed;
                timer.Start();

                SetKeyboardHook();
            }
            else
            {
                Environment.Exit(0);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Update elapsed event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void Update_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (!NFS.IsGameRunning())
            {
                Log.Print(NFSScriptLoader.INFO_TAG, "Game is not running.");
                Terminate();                
            }

            CallScriptsEvents();
            for (var i = 0; i < _scripts.Count; i++)
            {
                if (_scripts[i].HasUpdate)
                    _scripts[i].CallModFunction(ModScript.ModMethod.Update);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Wait till the game loads.
        /// </summary>
        private static void WaitForGameLoad()
        {
            Log.Print(NFSScriptLoader.INFO_TAG, "Waiting for the game to fully load. (Disabled in Most Wanted)");
            switch (_currentNFSGame)
            {
                case NFSGame.Undetermined:
                    break;

                case NFSGame.Underground:
                    while (GameMemory.ReadByte((IntPtr)UGAddresses.GenericAddrs.STATIC_IS_GAME_LOADED) != 0x01 && NFS.IsGameRunning())
                    {
                        Thread.Sleep(100);
                    }
                    break;

                case NFSGame.Underground2:
                    while (GameMemory.ReadByte((IntPtr)UG2Addresses.GenericAddrs.STATIC_IS_GAME_LOADED) != 0x01 && NFS.IsGameRunning())
                    {
                        Thread.Sleep(100);
                    }
                    break;

                case NFSGame.MW:
                    break;

                case NFSGame.Carbon:
                    while (GameMemory.ReadByte((IntPtr)CarbonAddresses.GenericAddrs.STATIC_IS_GAME_LOADED) != 0x01 && NFS.IsGameRunning())
                    {
                        Thread.Sleep(100);
                    }
                    break;

                case NFSGame.ProStreet:
                    while(GameMemory.ReadByte((IntPtr)ProStreetAddresses.GenericAddrs.STATIC_IS_GAME_LOADED) != 0x01 && NFS.IsGameRunning())
                    {
                        Thread.Sleep(100);
                    }
                    break;

                case NFSGame.Undercover:
                    while (GameMemory.ReadByte((IntPtr)UndercoverAddresses.GenericAddrs.STATIC_IS_GAME_LOADED) != 0x01 && NFS.IsGameRunning())
                    {
                        Thread.Sleep(100);
                    }
                    break;

                case NFSGame.World:
                    while (GameMemory.ReadByte((IntPtr)GameMemory.getBaseAddress + WorldAddresses.GenericAddrs.NON_STATIC_IS_GAME_LOADED) != 0x01 && NFS.IsGameRunning())
                    {
                        Thread.Sleep(100);
                    }
                    break;
            }
        }