Esempio n. 1
0
        protected override void DerefPointer(Process game)
        {
            boxPtr.Clear();
            // normal deref
            originDP.DerefOffsets(game, out originPtr);

            // signature scan for trigger corners
            IntPtr startPtr;

            startSearch.DerefOffsets(game, out startPtr);
            SignatureScanner scanner = new SignatureScanner(game, startPtr, searchLength);
            SigScanTarget    target  = new SigScanTarget(signature);
            var targets = scanner.ScanAll(target).ToList();

            boxPtr.AddRange(targets);
        }
        public override void OnGameAttached(GameState state)
        {
            _ccHandler.Init(state);


            server = state.GetModule("server.dll");
            client = state.GetModule("client.dll");
            engine = state.GetModule("engine.dll");

            var serverScanner = new SignatureScanner(state.GameProcess, server.BaseAddress, server.ModuleMemorySize);

            if (GameMemory.GetBaseEntityMemberOffset("m_angAbsRotation", state.GameProcess, serverScanner, out _baseEntityAngleOffset))
            {
                Debug.WriteLine("CBaseEntity::m_angAbsRotation offset = 0x" + _baseEntityAngleOffset.ToString("X"));
            }

            if (GameMemory.GetBaseEntityMemberOffset("m_vecAngVelocity", state.GameProcess, serverScanner, out _baseEntityAngleVelOffset))
            {
                Debug.WriteLine("CBaseEntity::m_vecAngVelocity offset = 0x" + _baseEntityAngleVelOffset.ToString("X"));
            }

            SigScanTarget _latest_Client_Trg = new SigScanTarget(0, Encoding.ASCII.GetBytes("ClientCommand, 0 length string supplied."));

            _latest_Client_Trg.OnFound = (proc, scanner, ptr) =>
            {
                byte[] b      = BitConverter.GetBytes(ptr.ToInt32());
                var    target = new SigScanTarget(2,
                                                  $"80 3D ?? ?? ?? ?? 00 75 ?? 68 {b[0]:X02} {b[1]:X02} {b[2]:X02} {b[3]:X02}"); // cmp byte ptr [clientcmdptr],00
                IntPtr ptrPtr = scanner.Scan(target);
                if (ptrPtr == IntPtr.Zero)
                {
                    return(IntPtr.Zero);
                }
                IntPtr ret;
                proc.ReadPointer(ptrPtr, out ret);
                Debug.WriteLine("CVEngineServer::ClientCommand szOut ptr is 0x" + ret.ToString("X"));
                return(ret);
            };

            var engineScanner = new SignatureScanner(state.GameProcess, engine.BaseAddress, engine.ModuleMemorySize);

            _endingsWatcher.ResetAll();

            _endingSeriousCount = 0;
            _latestClientCmd    = new StringWatcher(engineScanner.Scan(_latest_Client_Trg), 50);
            _endingsWatcher.Add(_latestClientCmd);
        }
        private static void ScanIsInteracting(string signature)
        {
            var target = new SigScanTarget(0x34, signature);

            foreach (var page in Game.MemoryPages())
            {
                var scanner = new SignatureScanner(Game, page.BaseAddress, (int)page.RegionSize);
                var ptr     = scanner.Scan(target);

                if (ptr == IntPtr.Zero)
                {
                    continue;
                }
                _isInteractingDP = new DeepPointer(ptr);
                return;
            }
        }
Esempio n. 4
0
        public static IntPtr SigScan(string target)
        {
            var    scantarget = new SigScanTarget(target);
            IntPtr scan       = IntPtr.Zero;

            foreach (var page in FzzyComponent.process.MemoryPages(true).Reverse())
            {
                var scanner = new SignatureScanner(FzzyComponent.process, page.BaseAddress, (int)page.RegionSize);
                var s       = scanner.Scan(scantarget);
                if (s != IntPtr.Zero)
                {
                    scan = s;
                    break;
                }
            }

            return(scan);
        }
Esempio n. 5
0
        public override void OnGameAttached(GameState state)
        {
            var bink = state.GetModule("video_bink.dll");

            Trace.Assert(bink != null);

            var binkScanner = new SignatureScanner(state.GameProcess, bink.BaseAddress, bink.ModuleMemorySize);

            SigScanTarget target = new SigScanTarget(11, "C7 05 ?? ?? ?? ?? ?? ?? ?? ?? B9 ?? ?? ?? ??");

            target.OnFound = (proc, scanner, ptr) => {
                ptr = proc.ReadPointer(ptr) + 0xC;
                Debug.WriteLine("bink is video playing pointer found at 0x" + ptr.ToString("X"));
                return(ptr);
            };

            _videoPlaying = new MemoryWatcher <byte>(binkScanner.Scan(target));
        }
Esempio n. 6
0
        /// <summary>
        /// Initialize signature scanners and sigscan.
        /// </summary>
        private static void Init()
        {
            Log("Starting with default values", false);

            Action <string, IntPtr> SigReport = (name, ptr) =>
            {
                Console.WriteLine("[INIT] " + name + (ptr == IntPtr.Zero ? " WAS NOT FOUND" : " is 0x" + ptr.ToString("X")));
            };

            SigScanTarget _entListSig = new SigScanTarget(6,
                                                          "40 ?? 48 ?? ?? ??",
                                                          "48 ?? ?? ?? ?? ?? ??", // MOV RAX,qword ptr [DAT_1814e3bc0]
                                                          "8b ?? 48 ?? ?? ?? ?? ?? ?? 48 ?? ?? ff ?? ?? ?? ?? ?? 4c ?? ??");

            _entListSig.OnFound = (proc, scanner, ptr) => GetPointer(ptr, 3, 7);

            SigScanTarget _gamePathSig = new SigScanTarget(7,
                                                           "48 8B 97 ?? ?? ?? ??",
                                                           "48 8D 0D ?? ?? ?? ??", // LEA RCX,[mapname]
                                                           "48 8B 5C 24 ??");

            _gamePathSig.OnFound = (proc, scanner, ptr) => GetPointer(ptr, 3, 7);

            ProcessModuleWow64Safe[] modules = game.ModulesWow64Safe();

            ProcessModuleWow64Safe server = modules.FirstOrDefault(x => x.ModuleName.ToLower() == "server.dll");
            ProcessModuleWow64Safe engine = modules.FirstOrDefault(x => x.ModuleName.ToLower() == "engine2.dll");

            while (server == null || engine == null)
            {
                Console.WriteLine("[INIT] Modules aren't yet loaded! Waiting 1 second until next try");
                Thread.Sleep(1000);
            }
            var serverScanner = new SignatureScanner(game, server.BaseAddress, server.ModuleMemorySize);
            var engineScanner = new SignatureScanner(game, engine.BaseAddress, engine.ModuleMemorySize);

            _entListPtr  = serverScanner.Scan(_entListSig); SigReport("entity list", _entListPtr);
            _gamePathPtr = engineScanner.Scan(_gamePathSig); SigReport("game path / map name", _gamePathPtr);

            Console.WriteLine("gamepath " + game.ReadString(_gamePathPtr, 255) + "             ");

            _mapName = new StringWatcher(_mapNamePtr, 255);
            _watchers.Add(_mapName);
        }
Esempio n. 7
0
        override protected bool Inject()
        {
            if (_injected)
            {
                return(true);
            }

            var scanTarget = new SigScanTarget(0,
                                               "40 57",                //  push rdi
                                               "41 56",                //  push r14
                                               "48 83 EC 28",          //  rsp, 28
                                               "80 B9 ?? ?? ?? ?? 00", //  cmp byte ptr[rcx + 00000228], 00
                                               "45 0F B6 F0"           //  movzx r14d, r8l
                                               );
            var scanner = new SignatureScanner(_dsProcess, _dsProcess.Modules[0].BaseAddress, _dsProcess.Modules[0].ModuleMemorySize);

            try
            {
                //allocate mem for detour function body
                if ((_detourFuncBodyPtr = _dsProcess.AllocateMemory(1000)) == IntPtr.Zero)
                {
                    throw new Win32Exception();
                }

                //scan for injection point
                _detourPtr = scanner.Scan(scanTarget);
                if (_detourPtr == IntPtr.Zero)
                {
                    throw new Win32Exception();
                }

                //read bytes from instruction point.
                _overwrittenBytes = _dsProcess.ReadBytes(_detourPtr, _overrideLength);
                if (_overwrittenBytes == null)
                {
                    throw new Win32Exception();
                }

                //build detour function body
                var detourFuncBodyBytes = new List <byte>()
                {
                };
                detourFuncBodyBytes.AddRange(_overwrittenBytes);
                detourFuncBodyBytes.AddRange(new byte[] { 0x48, 0x89, 0x0D, 0x22, 0x00, 0x00, 0x00, 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00 });
                byte[] returnAddressBytes = BitConverter.GetBytes(((long)(_detourPtr + 0x0E)));
                detourFuncBodyBytes.AddRange(returnAddressBytes);

                //build detour
                var detourBytes = new List <byte>()
                {
                    0xFF, 0x25, 0x00, 0x00, 0x00, 0x00
                };
                detourBytes.AddRange(BitConverter.GetBytes(((long)_detourFuncBodyPtr)));
                detourBytes.AddRange(new byte[] { 0x90 });

                //write memory.
                _dsProcess.Suspend();
                //write injection function
                if (!_dsProcess.WriteBytes(_detourFuncBodyPtr, detourFuncBodyBytes.ToArray()))
                {
                    throw new Win32Exception();
                }
                //write detour
                if (!_dsProcess.WriteBytes(_detourPtr, detourBytes.ToArray()))
                {
                    throw new Win32Exception();
                }
                _dsProcess.Resume();
            }
            catch
            {
                _dsProcess.FreeMemory(_detourFuncBodyPtr);
                _dsProcess.Resume();
                return(false);
            }
            _injected = true;
            Trace.WriteLine("World Flag Injection: success");
            Thread.Sleep(100); //wait a bit for the process to pass through the injection
            return(true);
        }
Esempio n. 8
0
        override protected bool Inject()
        {
            if (_injected)
            {
                return(true);
            }

            //this injection point seems a bit f****d up. It gets rewritten when the player enters certain locations. Shouldn't be a problem though.
            var scanTarget = new SigScanTarget(0,
                                               "0F 28 C6",                //  movaps xmm0, xmm6
                                               "F3 0F 59 05 ?? ?? ?? ??", //  mulss xmm0, [????????]
                                               "F3 48 0F 2C C0",          //  cvttss2si rax, eax
                                               "01 81"                    //  add [timerPtr], eax
                                               );
            var scanner = new SignatureScanner(_dsProcess, _dsProcess.Modules[0].BaseAddress, _dsProcess.Modules[0].ModuleMemorySize);

            try
            {
                //allocate mem for detour function body
                if ((_detourFuncBodyPtr = _dsProcess.AllocateMemory(1000)) == IntPtr.Zero)
                {
                    throw new Win32Exception();
                }

                //scan for injection point
                _detourPtr = scanner.Scan(scanTarget);
                if (_detourPtr == IntPtr.Zero)
                {
                    throw new Win32Exception();
                }
                _detourPtr = _detourPtr + 0x1D; //inject 0x1D bytes after scanner target

                //read bytes from instruction point.
                _overwrittenBytes = _dsProcess.ReadBytes(_detourPtr, _overrideLength);
                if (_overwrittenBytes == null)
                {
                    throw new Win32Exception();
                }
                //build detour function body
                var detourFuncBodyBytes = new List <byte>()
                {
                };
                detourFuncBodyBytes.AddRange(_overwrittenBytes);
                detourFuncBodyBytes.AddRange(new byte[] { 0x41, 0x56, 0x4C, 0x8B, 0xF0, 0x49, 0x81, 0xC6 });
                detourFuncBodyBytes.AddRange(_overwrittenBytes.ToList().GetRange(2, 4).ToArray());
                detourFuncBodyBytes.AddRange(new byte[] { 0x4C, 0x89, 0x34, 0x25 });
                detourFuncBodyBytes.AddRange(BitConverter.GetBytes((int)(_detourFuncBodyPtr + 0x41)));
                detourFuncBodyBytes.AddRange(new byte[] { 0x41, 0x5E });
                detourFuncBodyBytes.AddRange(new byte[] { 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00 });
                detourFuncBodyBytes.AddRange(BitConverter.GetBytes((long)(_detourPtr + 0x16)));

                //build detour
                var detourBytes = new List <byte>()
                {
                    0xFF, 0x25, 0x00, 0x00, 0x00, 0x00
                };
                detourBytes.AddRange(BitConverter.GetBytes(((long)_detourFuncBodyPtr)));
                detourBytes.AddRange(new byte[] { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 });
                //write memory.
                _dsProcess.Suspend();
                //write injection function
                if (!_dsProcess.WriteBytes(_detourFuncBodyPtr, detourFuncBodyBytes.ToArray()))
                {
                    throw new Win32Exception();
                }
                //write detour
                if (!_dsProcess.WriteBytes(_detourPtr, detourBytes.ToArray()))
                {
                    throw new Win32Exception();
                }
                _dsProcess.Resume();
            }
            catch
            {
                _dsProcess.FreeMemory(_detourFuncBodyPtr);
                _dsProcess.Resume();
                return(false);
            }
            _injected = true;
            Trace.WriteLine("Timer Injection: success");
            Thread.Sleep(100); //wait a bit for the process to pass through the injection
            return(true);
        }
Esempio n. 9
0
        void MemoryReadThread()
        {
            Debug.WriteLine("[NoLoads] MemoryReadThread");

            while (!_cancelSource.IsCancellationRequested)
            {
                try
                {
                    Debug.WriteLine("[NoLoads] Waiting for UA.exe...");

                    while ((game = GetGameProcess()) == null)
                    {
                        Thread.Sleep(250);
                        if (_cancelSource.IsCancellationRequested)
                        {
                            return;
                        }

                        isLoading = true;

                        if (isLoading != prevIsLoading)
                        {
                            loadingStarted = true;

                            // pause game timer
                            _uiThread.Post(d =>
                            {
                                if (OnLoadStarted != null)
                                {
                                    OnLoadStarted(this, EventArgs.Empty);
                                }
                            }, null);
                        }

                        prevIsLoading = true;

                        SetInjectionLabelInSettings(InjectionStatus.NoProcess, IntPtr.Zero);
                    }

                    Debug.WriteLine("[NoLoads] Got games process!");

                    uint frameCounter = 0;

                    while (!game.HasExited)
                    {
                        if (!isLevelSystemHooked)
                        {
                            #region Hooking
                            #region BeforeIntroductionOfILCPP-internals
                            if (gameVersion < GameVersions.v1_4)
                            {
                                if (_settings.RescansLimit != 0 && failedScansCount >= _settings.RescansLimit)
                                {
                                    var result = MessageBox.Show("Failed to find the pattern during the 3 scan loops. Want to retry scans?", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation);
                                    if (result == DialogResult.Cancel)
                                    {
                                        _ignorePIDs.Add(game.Id);
                                    }
                                    else
                                    {
                                        failedScansCount = 0;
                                    }
                                    //Should refresh game pages... hopefully. The memory pages extansion is really poop.
                                    game = null;

                                    SetInjectionLabelInSettings(InjectionStatus.FailedScanning, IntPtr.Zero);
                                }
                                //Hook only if the process is at least 15s old (since it takes forever with allocating stuff)
                                else if (game.UserProcessorTime >= TimeSpan.FromSeconds(15))
                                {
                                    SetInjectionLabelInSettings(InjectionStatus.Scanning, IntPtr.Zero);
                                    var sigScanTarget = new SigScanTarget(
                                        "48 8B EC " +
                                        "48 83 EC 30 " +
                                        "48 89 75 F8 " +
                                        "48 8B F1 " +
                                        "48 8B 46 10 " +
                                        "48 85 C0 " +
                                        "?? ?? " +
                                        "48 8B 46 10 " +
                                        "48 8B C8 " +
                                        "48 89 45 F0 " +
                                        "FF 50 18 " +
                                        "48 8B 45 F0 ");


                                    LevelSystemInstancePointer = game.AllocateMemory(IntPtr.Size);
                                    Debug.WriteLine("[NOLOADS] injectedPtrForLevelSystemPtr allocated at: " + LevelSystemInstancePointer.ToString("X8"));
                                    var injectedPtrForLevelSystemBytes = BitConverter.GetBytes(LevelSystemInstancePointer.ToInt64());

                                    originalFunctionAddress = IntPtr.Zero;
                                    var contentOfAHook = new List <byte>();
                                    contentOfAHook.AddRange(OriginalInstructionBytesBefore14);
                                    contentOfAHook.AddRange(new byte[] { 0x48, 0xB8 });                                                                               //mov rax,....
                                    contentOfAHook.AddRange(injectedPtrForLevelSystemBytes);                                                                          //address for rax^^
                                    contentOfAHook.AddRange(new byte[] { 0x48, 0x89, 0x08 });                                                                         //mov [rax], rcx
                                    contentOfAHook.AddRange(new byte[] { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }); //14 nops for jmp back (actually needs I think 2 less)

                                    Debug.WriteLine("[NOLOADS] Scanning for signature (LevelSystem:Update)");
                                    foreach (var page in game.MemoryPages())
                                    {
                                        var scanner = new SignatureScanner(game, page.BaseAddress, (int)page.RegionSize);
                                        if ((originalFunctionAddress = scanner.Scan(sigScanTarget)) != IntPtr.Zero)
                                        {
                                            break;
                                        }
                                    }

                                    if (originalFunctionAddress == IntPtr.Zero)
                                    {
                                        failedScansCount++;
                                        Debug.WriteLine("[NOLOADS] Failed scans: " + failedScansCount);
                                        game.FreeMemory(LevelSystemInstancePointer);
                                    }
                                    else
                                    {
                                        Debug.WriteLine("[NOLOADS] FOUND SIGNATURE AT: 0x" + originalFunctionAddress.ToString("X8"));
                                        codeDetour = game.AllocateMemory(contentOfAHook.Count);
                                        game.Suspend();

                                        try
                                        {
                                            var oInitPtr        = game.WriteBytes(codeDetour, contentOfAHook.ToArray());
                                            var detourInstalled = game.WriteDetour(originalFunctionAddress, 14, codeDetour);
                                            var returnInstalled = game.WriteJumpInstruction(codeDetour + contentOfAHook.Count - 15, originalFunctionAddress + 14);
                                            isLevelSystemHooked = true;
                                            SetInjectionLabelInSettings(InjectionStatus.Injected, LevelSystemInstancePointer);
                                        }
                                        catch
                                        {
                                            SetInjectionLabelInSettings(InjectionStatus.FailedToInject, IntPtr.Zero);
                                            throw;
                                        }
                                        finally
                                        {
                                            game.Resume();
                                        }
                                    }
                                }
                                else
                                {
                                    SetInjectionLabelInSettings(InjectionStatus.FoundProcessWaiting, IntPtr.Zero);
                                }
                            }
                            #endregion
                            #region ILCPPInternals
                            else
                            {
                                LevelSystemInstancePointer = game.AllocateMemory(IntPtr.Size);
                                Debug.WriteLine("[NOLOADS] injectedPtrForLevelSystemPtr allocated at: " + LevelSystemInstancePointer.ToString("X8"));
                                var injectedPtrForLevelSystemBytes = BitConverter.GetBytes(LevelSystemInstancePointer.ToInt64());

                                originalFunctionAddress = game.ModulesWow64Safe().First(x => x.ModuleName.ToLower() == "gameassembly.dll").BaseAddress + 0x120D382;
                                var contentOfAHook = new List <byte>();
                                contentOfAHook.AddRange(OriginalInstructionBytesV14);
                                contentOfAHook.AddRange(new byte[] { 0x48, 0xB8 });                                                                               //mov rax,....
                                contentOfAHook.AddRange(injectedPtrForLevelSystemBytes);                                                                          //address for rax^^
                                contentOfAHook.AddRange(new byte[] { 0x48, 0x89, 0x38 });                                                                         //mov [rax], rdi (rdi is base of an object)
                                contentOfAHook.AddRange(new byte[] { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }); //14 nops for jmp back (actually needs I think 2 less)

                                //Thankfully no longer need to do sig scans... f**k sigscans
                                Debug.WriteLine("[NOLOADS] INJECTING AT: 0x" + originalFunctionAddress.ToString("X8"));
                                codeDetour = game.AllocateMemory(contentOfAHook.Count);
                                game.Suspend();

                                try
                                {
                                    var oInitPtr        = game.WriteBytes(codeDetour, contentOfAHook.ToArray());
                                    var detourInstalled = game.WriteDetour(originalFunctionAddress, OriginalInstructionBytesV14.Length, codeDetour);
                                    var returnInstalled = game.WriteJumpInstruction(codeDetour + contentOfAHook.Count - 15, originalFunctionAddress + OriginalInstructionBytesV14.Length);
                                    isLevelSystemHooked = true;
                                    SetInjectionLabelInSettings(InjectionStatus.Injected, LevelSystemInstancePointer);
                                }
                                catch
                                {
                                    SetInjectionLabelInSettings(InjectionStatus.FailedToInject, IntPtr.Zero);
                                    throw;
                                }
                                finally
                                {
                                    game.Resume();
                                }
                            }
                            #endregion

                            #endregion
                        }
                        else
                        {
                            switch (gameVersion)
                            {
                            case GameVersions.v1_00:
                                currentLevelName = game.ReadString(game.ReadPointer(game.ReadPointer(LevelSystemInstancePointer) + 0x50) + 0x14, ReadStringType.UTF16, 30);
                                isLoading        = !(game.ReadValue <bool>(game.ReadPointer(LevelSystemInstancePointer) + 0xB2));
                                break;

                            case GameVersions.v1_02:
                                currentLevelName = game.ReadString(game.ReadPointer(game.ReadPointer(LevelSystemInstancePointer) + 0x50) + 0x14, ReadStringType.UTF16, 30);
                                isLoading        = !(game.ReadValue <bool>(game.ReadPointer(LevelSystemInstancePointer) + 0xB2));
                                break;

                            case GameVersions.v1_1:
                                currentLevelName = game.ReadString(game.ReadPointer(game.ReadPointer(LevelSystemInstancePointer) + 0x50) + 0x14, ReadStringType.UTF16, 30);
                                isLoading        = !(game.ReadValue <bool>(game.ReadPointer(LevelSystemInstancePointer) + 0xB2));
                                break;

                            case GameVersions.v1_3:
                                currentLevelName = game.ReadString(game.ReadPointer(game.ReadPointer(LevelSystemInstancePointer) + 0x50) + 0x14, ReadStringType.UTF16, 30);
                                isLoading        = !(game.ReadValue <bool>(game.ReadPointer(LevelSystemInstancePointer) + 0xBA));
                                break;

                            default:
                                currentLevelName = game.ReadString(game.ReadPointer(game.ReadPointer(LevelSystemInstancePointer) + 0x50) + 0x14, ReadStringType.UTF16, 30);
                                isLoading        = !(game.ReadValue <bool>(game.ReadPointer(LevelSystemInstancePointer) + 0x62));
                                break;
                            }

                            if (isLoading != prevIsLoading || currentLevelName != prevLevelName)
                            {
#if DEBUG
                                if (currentLevelName != prevLevelName)
                                {
                                    Debug.WriteLine("Level changed from " + prevLevelName + " -> " + currentLevelName);
                                }
#endif

                                if (isLoading || (currentLevelName != null && LevelsExcludedFromAutosplitting.Contains(currentLevelName)))
                                {
                                    Debug.WriteLine(String.Format("[NoLoads] Load Start - {0}", frameCounter));

                                    loadingStarted = true;

                                    // pause game timer
                                    _uiThread.Post(d =>
                                    {
                                        if (OnLoadStarted != null)
                                        {
                                            OnLoadStarted(this, EventArgs.Empty);
                                        }
                                    }, null);
                                }
                                else
                                {
                                    Debug.WriteLine(String.Format("[NoLoads] Load End - {0}", frameCounter));

                                    if (loadingStarted)
                                    {
                                        loadingStarted = false;

                                        // unpause game timer
                                        _uiThread.Post(d =>
                                        {
                                            if (OnLoadFinished != null)
                                            {
                                                OnLoadFinished(this, EventArgs.Empty);
                                            }
                                        }, null);

                                        _uiThread.Post(d =>
                                        {
                                            if (OnFirstLevelLoad != null)
                                            {
                                                OnFirstLevelLoad(this, EventArgs.Empty);
                                            }
                                        }, null);
                                    }
                                }

                                if (currentLevelName != prevLevelName && prevLevelName != null && currentLevelName != null && !LevelsExcludedFromAutosplitting.Contains(currentLevelName) && !LevelsExcludedFromAutosplitting.Contains(prevLevelName))
                                {
                                    _uiThread.Post(d =>
                                    {
                                        if (OnLevelChanged != null)
                                        {
                                            OnLevelChanged(this, EventArgs.Empty);
                                        }
                                    }, null);
                                }
                            }

                            prevIsLoading = isLoading;
                            prevLevelName = currentLevelName;
                            frameCounter++;

                            Thread.Sleep(15);

                            if (_cancelSource.IsCancellationRequested)
                            {
                                return;
                            }
                        }
                    }

                    // pause game timer on exit or crash
                    _uiThread.Post(d =>
                    {
                        if (OnLoadStarted != null)
                        {
                            OnLoadStarted(this, EventArgs.Empty);
                        }
                    }, null);
                    isLoading = true;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    Thread.Sleep(1000);
                }
            }
        }
Esempio n. 10
0
        void MemoryReadThread()
        {
            Debug.WriteLine("[NoLoads] MemoryReadThread");

            while (!_cancelSource.IsCancellationRequested)
            {
                try
                {
                    Debug.WriteLine("[NoLoads] Waiting for Build.exe...");

                    while ((game = GetGameProcess()) == null)
                    {
                        Thread.Sleep(250);
                        if (_cancelSource.IsCancellationRequested)
                        {
                            return;
                        }

                        isLoading = true;

                        if (isLoading != prevIsLoading)
                        {
                            loadingStarted = true;

                            // pause game timer
                            _uiThread.Post(d =>
                            {
                                if (OnLoadStarted != null)
                                {
                                    OnLoadStarted(this, EventArgs.Empty);
                                }
                            }, null);
                        }

                        prevIsLoading = true;

                        SetInjectionLabelInSettings(InjectionStatus.NoProcess, IntPtr.Zero);
                    }

                    Debug.WriteLine("[NoLoads] Got games process!");

                    uint frameCounter = 0;

                    while (!game.HasExited)
                    {
                        if (currentIsPausedAddress == IntPtr.Zero)
                        {
                            #region Hooking
                            if (_settings.RescansLimit != 0 && failedScansCount >= _settings.RescansLimit)
                            {
                                var result = MessageBox.Show("Failed to find the pattern during the 3 scan loops. Want to retry scans?", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation);
                                if (result == DialogResult.Cancel)
                                {
                                    _ignorePIDs.Add(game.Id);
                                }
                                else
                                {
                                    failedScansCount = 0;
                                }
                                //Should refresh game pages... hopefully. The memory pages extansion is really poop.
                                game = null;

                                SetInjectionLabelInSettings(InjectionStatus.FailedScanning, IntPtr.Zero);
                            }
                            //Hook only if the process is at least 15s old (since it takes forever with allocating stuff)
                            else if (game.UserProcessorTime >= TimeSpan.FromSeconds(15))
                            {
                                SetInjectionLabelInSettings(InjectionStatus.Scanning, IntPtr.Zero);

                                var    sigScanTarget            = new SigScanTarget(SigScanPattern_InventoryStatusUpdateCurrentTimePlayed);
                                IntPtr StartOfUpdateCurrentTime = IntPtr.Zero;

                                Debug.WriteLine("[NOLOADS] Scanning for signature (InventoryStats:UpdateCurrentTimePlayed)");
                                foreach (var page in game.MemoryPages())
                                {
                                    var scanner = new SignatureScanner(game, page.BaseAddress, (int)page.RegionSize);
                                    if ((StartOfUpdateCurrentTime = scanner.Scan(sigScanTarget)) != IntPtr.Zero)
                                    {
                                        break;
                                    }
                                }


                                if (StartOfUpdateCurrentTime == IntPtr.Zero)
                                {
                                    failedScansCount++;
                                    Debug.WriteLine("[NOLOADS] Failed scans: " + failedScansCount);
                                }
                                else
                                {
                                    currentIsPausedAddress = StartOfUpdateCurrentTime + 0x9;
                                    Debug.WriteLine("[NOLOADS] FOUND SIGNATURE FOR _isPaused AT: 0x" + currentIsPausedAddress.ToString("X8"));

                                    SetInjectionLabelInSettings(InjectionStatus.Found, currentIsPausedAddress);
                                }
                            }
                            else
                            {
                                SetInjectionLabelInSettings(InjectionStatus.FoundProcessWaiting, IntPtr.Zero);
                            }
                            #endregion
                        }
                        else
                        {
                            var addy = new IntPtr(game.ReadValue <int>(currentIsPausedAddress));
                            isLoading = game.ReadValue <byte>(addy) == 0;

                            if (isLoading != prevIsLoading)
                            {
                                if (isLoading)
                                {
                                    Debug.WriteLine(String.Format("[NoLoads] Load Start - {0}", frameCounter));

                                    loadingStarted = true;

                                    // pause game timer
                                    _uiThread.Post(d =>
                                    {
                                        if (OnLoadStarted != null)
                                        {
                                            OnLoadStarted(this, EventArgs.Empty);
                                        }
                                    }, null);
                                }
                                else
                                {
                                    Debug.WriteLine(String.Format("[NoLoads] Load End - {0}", frameCounter));

                                    if (loadingStarted)
                                    {
                                        loadingStarted = false;

                                        // unpause game timer
                                        _uiThread.Post(d =>
                                        {
                                            if (OnLoadFinished != null)
                                            {
                                                OnLoadFinished(this, EventArgs.Empty);
                                            }
                                        }, null);

                                        _uiThread.Post(d =>
                                        {
                                            if (OnFirstLevelLoad != null)
                                            {
                                                OnFirstLevelLoad(this, EventArgs.Empty);
                                            }
                                        }, null);
                                    }
                                }
                            }

                            prevIsLoading = isLoading;
                            frameCounter++;

                            Thread.Sleep(15);

                            if (_cancelSource.IsCancellationRequested)
                            {
                                return;
                            }
                        }
                    }

                    // pause game timer on exit or crash
                    _uiThread.Post(d =>
                    {
                        if (OnLoadStarted != null)
                        {
                            OnLoadStarted(this, EventArgs.Empty);
                        }
                    }, null);
                    isLoading = true;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    Thread.Sleep(1000);
                }
            }
        }
Esempio n. 11
0
        public override void OnGameAttached(GameState state)
        {
            ProcessModuleWow64Safe server = state.GetModule("server.dll");
            var scanner = new SignatureScanner(state.GameProcess, server.BaseAddress, server.ModuleMemorySize);

            this.EndOffsetTicks = 0;


            IntPtr getStringPtr(string str)
            {
                return(scanner.Scan(new SigScanTarget(0, str.ConvertToHex() + " 00")));
            }

            IntPtr getPtrRef(IntPtr ptr, SignatureScanner scanner, params string[] prefixes)
            {
                if (ptr == IntPtr.Zero)
                {
                    return(ptr);
                }
                string        ptrStr = ptr.GetByteString();
                SigScanTarget target = new SigScanTarget();

                prefixes.ToList().ForEach(x => target.AddSignature(0, x + " " + ptrStr));
                return(scanner.Scan(target));
            }

            IntPtr        ptr;
            SigScanTarget target;

            if ((ptr = getPtrRef(getStringPtr("n_max"), scanner, "68")) == IntPtr.Zero)
            {
                return;
            }

            bool found = false;

            target         = new SigScanTarget(1, "68");
            target.OnFound = (f_proc, f_scanner, f_ptr) =>
            {
                IntPtr ptr = f_proc.ReadPointer(f_ptr);
                found = !(ptr.ToInt32() < scanner.Address.ToInt32() ||
                          ptr.ToInt32() > scanner.Address.ToInt32() + scanner.Size);

                return(f_ptr);
            };

            var scanner2 = new SignatureScanner(state.GameProcess, ptr + 10, 0x1000);

            while ((ptr = scanner2.Scan(target)) != IntPtr.Zero &&
                   !found &&
                   scanner2.Size > 6)
            {
                scanner2 = new SignatureScanner(
                    state.GameProcess,
                    ptr,
                    scanner2.Address.ToInt32() + 0x1000 - ptr.ToInt32());
            }

            if (ptr == IntPtr.Zero)
            {
                return;
            }

            ptr    = state.GameProcess.ReadPointer(ptr);
            target = new SigScanTarget(2, "80 ?? ?? ?? ?? 00 00 74");
            target.AddSignature(2, "8A ?? ?? ?? 00 00 84");

            scanner2 = new SignatureScanner(state.GameProcess, ptr, 0x100);
            ptr      = scanner2.Scan(target);

            _nihiDeadOffset = state.GameProcess.ReadValue <int>(ptr);
            Debug.WriteLine("nihi dead bool offset is 0x" + _nihiDeadOffset.ToString("x"));
        }