public Hooks(IReloadedHooks hooks, InitPath initPath, GetStartPosition getStartPosition, GetEndPosition getEndPosition, GetBragPosition getBragPosition) { InitPathHook = hooks.CreateHook(initPath, 0x00439020).Activate(); GetStartPositionHook = hooks.CreateHook(getStartPosition, 0x00426F10).Activate(); GetEndPositionHook = hooks.CreateHook(getEndPosition, 0x00426FD0).Activate(); GetBragPositionHook = hooks.CreateHook(getBragPosition, 0x00427010).Activate(); }
/* Setup */ public SteamHook(IReloadedHooks hooks, Logger logger, string applicationFolder) { _applicationFolder = applicationFolder; var steamApiPath = Environment.Is64BitProcess ? Path.GetFullPath(SteamAPI64) : Path.GetFullPath(SteamAPI32); if (!File.Exists(steamApiPath)) { return; } // Hook relevant functions var libraryAddress = Native.Kernel32.LoadLibraryW(steamApiPath); _restartAppIfNecessaryHook = HookExportedFunction <RestartAppIfNecessary>(libraryAddress, RestartAppIfNecessaryName, RestartAppIfNecessaryImpl); _isSteamRunningHook = HookExportedFunction <IsSteamRunning>(libraryAddress, IsSteamRunningName, IsSteamRunningImpl); // Drop steam_appid.txt DropSteamAppId(logger); // Local function. IHook <T> HookExportedFunction <T>(IntPtr libraryHandle, string functionName, T handler) { var functionPtr = Native.Kernel32.GetProcAddress(libraryHandle, functionName); if (functionPtr == IntPtr.Zero) { logger.SteamWriteLineAsync($"{functionName} not found.", logger.ColorWarning); return(null); } logger.SteamWriteLineAsync($"{functionName} hooked successfully.", logger.ColorSuccess); return(hooks.CreateHook <T>(handler, (long)functionPtr).Activate()); } }
public Mod(ILogger logger, IReloadedHooks hooks) { _logger = logger; _hooks = hooks; _process = Process.GetCurrentProcess(); using var scanner = new Scanner(_process, _process.MainModule); //var result = scanner.CompiledFindPattern("48 8B C4 53 41 56 41 57 48 83 EC 50"); var result = scanner.CompiledFindPattern("4C 89 44 24 18 48 89 54 24 10 48 89 4C 24 08 55 53 56 57 48 8D 6C 24 D8"); var functionAddress = result.Offset + (long)_process.MainModule.BaseAddress; #if DEBUG _logger.WriteLine($"Address: {functionAddress:X}"); #endif _loadFileHook = _hooks.CreateHook <LoadFile>(LoadFileFunc, functionAddress).Activate(); }