public static int GetOffset(GameOffset type) { var foundOffset = _offsets.FirstOrDefault(offset => offset.Key == type).Value; if (foundOffset == 0) { var searchSuccess = FindOffset(type); if (!searchSuccess) { // Offset search failed! Abort! Abort! MessageBox.Show( $"A critical error occurred while scanning for offsets:\n\nUnable to locate offset:\n{type}\n\nThe application will now exit.", "Critical error", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } foundOffset = _offsets.FirstOrDefault(offset => offset.Key == type).Value; } return(foundOffset); }
private static bool FindOffset(GameOffset offsetType) { // Build a table of offsets from the current process _sigScan.Process = GameMemory.Process; _sigScan.Address = GameMemory.Process.MainModule.BaseAddress; _sigScan.Size = GameMemory.Process.MainModule.ModuleMemorySize; var patternData = _bytePatterns.First(pattern => pattern.Type == offsetType); var pointer = _sigScan.FindPattern(patternData.Pattern, patternData.PatternOffset); if (pointer == IntPtr.Zero) { return(false); } var offset = GameMemory.Read <IntPtr>((int)pointer, false); _offsets.Add(patternData.Type, (int)offset); return(true); }