/* 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 FourPlayerPatch(IReloadedHooks hooks, IReloadedHooksUtilities hooksUtilities) { _hooks = hooks; _hooksUtilities = hooksUtilities; _titleHook = Functions.TitleSequenceTask.Hook(TitleSequenceImpl).Activate(); _charaSelectHook = Functions.CharaSelectTask.Hook(CharacterSelectImpl).Activate(); }
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(); }
public static NativeFunctions GetInstance(IReloadedHooks hooks) { if (_instanceMade) { return(_instance); } var ntdllHandle = LoadLibraryW("ntdll"); var ntCreateFilePointer = GetProcAddress(ntdllHandle, "NtCreateFile"); var ntReadFilePointer = GetProcAddress(ntdllHandle, "NtReadFile"); var ntSetInformationFile = GetProcAddress(ntdllHandle, "NtSetInformationFile"); var ntQueryInformationFile = GetProcAddress(ntdllHandle, "NtQueryInformationFile"); _instance = new NativeFunctions() { NtCreateFile = hooks.CreateFunction <NtCreateFile>((long)ntCreateFilePointer), NtReadFile = hooks.CreateFunction <NtReadFile>((long)ntReadFilePointer), NtSetInformationFile = hooks.CreateFunction <NtSetInformationFile>((long)ntSetInformationFile), NtQueryInformationFile = hooks.CreateFunction <NtQueryInformationFile>((long)ntQueryInformationFile), }; _instanceMade = true; return(_instance); }
public GraphicsEssentials(string modFolder, IReloadedHooks hooks) { _config = new ConfigReadWriter(modFolder).FromJson(); _defaultSettingsHook = new DefaultSettingsHook(_config.DefaultSettings, hooks); NativeResolutionPatcher.Patch(_config.Width, _config.Height); WindowStylePatcher.Patch(_config.BorderlessWindowed, _config.ResizableWindowed); if (_config.StupidlyFastLoadTimes) { LoadTimeHack.Patch(); } if (_config.Disable2PFrameskip) { DisableFrameskipPatch.Patch(); } if (_config.HighAspectRatioCrashFix) { _crashFixHook = new StageLoadCrashFixHook(hooks); } _clippingPlanesHook = new ClippingPlanesHook(_config.AspectRatioLimit, hooks); _aspectRatioHook = new AspectRatioHook(_config.AspectRatioLimit, hooks); _resolutionVariablePatcher = new ResolutionVariablePatcher(_config.AspectRatioLimit); _renderHooks = new RenderHooks(_config.AspectRatioLimit, hooks); Task.Run(MessagePump); }
public IndirectHook(IntPtr addressToFunctionPointer, TFunction function, IReloadedHooks hookFactory) { mAddressToFunctionPointer = addressToFunctionPointer; OriginalFunctionAddress = *( IntPtr * )mAddressToFunctionPointer; OriginalFunction = hookFactory.CreateWrapper <TFunction>((long)OriginalFunctionAddress, out IntPtr originalFunctionWrapperAddress); OriginalFunctionWrapperAddress = OriginalFunctionAddress; ReverseWrapper = hookFactory.CreateReverseWrapper(function); }
public FileAccessServer(IReloadedHooks hookFactory, NativeFunctions functions) { _hooks = new FileAccessServerHooks( functions.NtCreateFile.Hook(NtCreateFileImpl), functions.NtReadFile.Hook(NtReadFileImpl), functions.NtSetInformationFile.Hook(NtSetInformationFileImpl), functions.NtQueryinformationFile.Hook(NtQueryInformationFileImpl), ImportAddressTableHooker.Hook <CloseHandleDelegate>(hookFactory, "kernel32.dll", "CloseHandle", CloseHandleImpl)); }
public ReloadedHooksTest() { _nativeCalculator = new NativeCalculator(); _hooks = new ReloadedHooks(); _addFunction = _hooks.CreateFunction <AddFunction>((long)_nativeCalculator.Add); _subtractFunction = _hooks.CreateFunction <SubtractFunction>((long)_nativeCalculator.Subtract); _divideFunction = _hooks.CreateFunction <DivideFunction>((long)_nativeCalculator.Divide); _multiplyFunction = _hooks.CreateFunction <MultiplyFunction>((long)_nativeCalculator.Multiply); }
public NativeFunctions(IntPtr ntCreateFile, IntPtr ntReadFile, IntPtr ntSetInformationFile, IntPtr ntQueryInformationFile, IntPtr setFilePointer, IntPtr closeHandle, IReloadedHooks hooks) { NtCreateFile = hooks.CreateFunction <NtCreateFile>((long)ntCreateFile); NtReadFile = hooks.CreateFunction <NtReadFile>((long)ntReadFile); NtSetInformationFile = hooks.CreateFunction <NtSetInformationFile>((long)ntSetInformationFile); NtQueryinformationFile = hooks.CreateFunction <NtQueryInformationFile>((long)ntQueryInformationFile); SetFilePointer = hooks.CreateFunction <SetFilePointer>(( long )setFilePointer); CloseHandle = hooks.CreateFunction <CloseHandleDelegate>(( long )closeHandle); }
public void Start(IModLoaderV1 loader) { ModLoader = (IModLoader)loader; ModLoader.GetController <IReloadedHooks>().TryGetTarget(out var hooks); Hooks = hooks; /* Your mod code starts here. */ var logger = (ILogger)ModLoader.GetLogger(); SDK.Init(Hooks, new PrsInstance()); _server = new Server(logger); }
public GetRaceModeHook(IReloadedHooks hooks) { _hooks = hooks; var hook = new string[] { "use32", // Callee Register Backup $"mov [{(IntPtr)_pinnable.Pointer}], eax" }; _getRaceModeHook = hooks.CreateAsmHook(hook, 0x0046C116, AsmHookBehaviour.ExecuteAfter).Activate(); }
public StageCollection(IModLoader loader, IReloadedHooks hooks) { _modLoader = loader; _logger = (ILogger)_modLoader.GetLogger(); _redirectorController = _modLoader.GetController <IRedirectorController>(); _hooks = new Hooks.Hooks(hooks, InitSplineImpl, GetStartPositionImpl, GetEndPositionImpl, GetBragPositionImpl); // Populate Default Stages foreach (StageId stageId in (StageId[])Enum.GetValues(typeof(StageId))) { _allStages.Add(new DefaultStage(stageId)); } }
public DX9Hook(IReloadedHooks _hooks) { // Obtain the pointer to the IDirect3DDevice9 instance by creating our own blank windows form and creating a // IDirect3DDevice9 targeting that form. The returned device should be the same one as used by the program. using (var direct3D = new Direct3D()) using (var renderForm = new Form()) using (var device = new Device(direct3D, 0, DeviceType.NullReference, IntPtr.Zero, CreateFlags.HardwareVertexProcessing, new PresentParameters() { BackBufferWidth = 1, BackBufferHeight = 1, DeviceWindowHandle = renderForm.Handle })) { Direct3D9VTable = _hooks.VirtualFunctionTableFromObject(direct3D.NativePointer, Enum.GetNames(typeof(IDirect3D9)).Length); DeviceVTable = _hooks.VirtualFunctionTableFromObject(device.NativePointer, Enum.GetNames(typeof(IDirect3DDevice9)).Length); } }
public XpShare(Utils utils, IMemory memory, IReloadedHooks hooks, Config configuration) { Configuration = configuration; _utils = utils; _memory = memory; _hooks = hooks; List <Task> initTasks = new List <Task>(); initTasks.Add(Task.Run(() => InitXpHook())); initTasks.Add(Task.Run(() => InitDateLocation())); initTasks.Add(Task.Run(() => InitXpLocation())); initTasks.Add(Task.Run(() => InitPartyLocation())); Task.WaitAll(initTasks.ToArray()); }
public static IHook <TFunction> Hook <TFunction>(IReloadedHooks hookFactory, string libraryName, string functionName, TFunction function) { const int IMAGE_DIRECTORY_ENTRY_IMPORT = 1; var cleanLibraryName = Path.GetFileNameWithoutExtension(libraryName); var imageBase = GetModuleHandle(null); var dosHeaders = (IMAGE_DOS_HEADERS *)imageBase; var ntHeaders = (IMAGE_NT_HEADERS32 *)(imageBase + dosHeaders->e_lfanew); var importsDirectory = ntHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]; var importDescriptor = (IMAGE_IMPORT_DESCRIPTOR *)(importsDirectory.VirtualAddress + (uint)imageBase); while (importDescriptor->Name != 0) { var importLibraryName = new string((sbyte *)((long)imageBase + importDescriptor->Name)); var cleanImportLibraryName = Path.GetFileNameWithoutExtension(importLibraryName); if (cleanImportLibraryName.Equals(cleanLibraryName, StringComparison.OrdinalIgnoreCase)) { var importLibrary = LoadLibrary(importLibraryName); if (importLibrary != IntPtr.Zero) { var originalFirstThunk = (IMAGE_THUNK_DATA32 *)((long)imageBase + importDescriptor->OriginalFirstThunk); var firstThunk = (IMAGE_THUNK_DATA32 *)((long)imageBase + importDescriptor->FirstThunk); while (originalFirstThunk->AddressOfData != 0) { var importFunctionName = (IMAGE_IMPORT_BY_NAME *)((long)imageBase + originalFirstThunk->AddressOfData); if (importFunctionName->Name == functionName) { return(new IndirectHook <TFunction>(new IntPtr(&firstThunk->Function), function, hookFactory)); } ++originalFirstThunk; ++firstThunk; } } } ++importDescriptor; } return(null); }
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(); }
public DX11Hook(IReloadedHooks _hooks) { // Define Device dx11Device; SwapChain dxgiSwapChain; var renderForm = new Form(); // Get Table Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, GetSwapChainDescription(renderForm.Handle), out dx11Device, out dxgiSwapChain); VTable = _hooks.VirtualFunctionTableFromObject(dx11Device.NativePointer, Enum.GetNames(typeof(ID3D11Device)).Length); DXGIVTable = _hooks.VirtualFunctionTableFromObject(dxgiSwapChain.NativePointer, Enum.GetNames(typeof(IDXGISwapChain)).Length); // Cleanup dxgiSwapChain.Dispose(); dx11Device.Dispose(); renderForm.Dispose(); }
public Mod(IReloadedHooks hooks, ILogger logger) { _logger = logger; _hooks = hooks; _process = Process.GetCurrentProcess(); foreach (ProcessModule module in _process.Modules) { if (module.ModuleName == "tguiinterface.dll") { Memory.Instance.SafeWrite(module.BaseAddress + 0x150C0, 0x000008C2); logger.WriteLine("[Disable Mouse Accelleration]: Successfully Patched TGuiInterface.dll!"); continue; } } // TODO: Implement some mod logic }
public static NativeFunctions GetInstance(IReloadedHooks hooks) { if (_instanceMade) { return(_instance); } var ntdllHandle = LoadLibraryW("ntdll"); var ntCreateFilePointer = GetProcAddress(ntdllHandle, "NtCreateFile"); var ntReadFilePointer = GetProcAddress(ntdllHandle, "NtReadFile"); var setFilePointer = GetProcAddress(ntdllHandle, "NtSetInformationFile"); var getFileSize = GetProcAddress(ntdllHandle, "NtQueryInformationFile"); _instance = new NativeFunctions(ntCreateFilePointer, ntReadFilePointer, setFilePointer, getFileSize, hooks); _instanceMade = true; return(_instance); }
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("F6 40 08 04 0F 84 DF 01 00 00"); var injectLocation = result.Offset + (long)_process.MainModule.BaseAddress; //test byte ptr[rax + 08],04 //jne "Digimon Story CS.exe.unpacked.exe" + 00171ddb //cmp EDI, 0x14 //je "Digimon Story CS.exe.unpacked.exe" + 00171f3d //jmp "Digimon Story CS.exe.unpacked.exe" + 171D5E string[] asmCode = { //here we use ecx to hold the jump address temporarily $"use64", $"test byte [rax + 08],04", $"mov rcx, " + String.Format("0x{0:X8}", 0x00171ddb + (long)_process.MainModule.BaseAddress).ToString(), $"jne jumptorcx", $"cmp edi, 0x14", $"mov rcx, " + String.Format("0x{0:X8}", 0x00171f3d + (long)_process.MainModule.BaseAddress).ToString(), $"je jumptorcx", $"mov rcx, " + String.Format("0x{0:X8}", 0x171D5E + (long)_process.MainModule.BaseAddress).ToString(), $"jumptorcx:", $"jmp rcx" }; #if DEBUG _logger.WriteLine($"Inject Location Offset: {result.Offset:X}"); _logger.WriteLine($"Inject Location: {injectLocation:X}"); foreach (var asm in asmCode) { _logger.WriteLine(asm); } #endif _asmHook = _hooks.CreateAsmHook(asmCode, injectLocation, Reloaded.Hooks.Definitions.Enums.AsmHookBehaviour.DoNotExecuteOriginal); _asmHook.Activate(); }
public static NativeFunctions GetInstance(IReloadedHooks hooks) { if (_instanceMade) { return(_instance); } var ntdllHandle = LoadLibraryW("ntdll"); var ntCreateFilePointer = GetProcAddress(ntdllHandle, "NtCreateFile"); var ntReadFilePointer = GetProcAddress(ntdllHandle, "NtReadFile"); var ntSetInformationFilePtr = GetProcAddress(ntdllHandle, "NtSetInformationFile"); var ntQueryInformationFilePtr = GetProcAddress(ntdllHandle, "NtQueryInformationFile"); var kernel32Handle = LoadLibraryW("kernel32"); var setFilePointerPtr = GetProcAddress(kernel32Handle, "SetFilePointer"); var closeHandlePtr = GetProcAddress(kernel32Handle, "CloseHandle"); _instance = new NativeFunctions(ntCreateFilePointer, ntReadFilePointer, ntSetInformationFilePtr, ntQueryInformationFilePtr, setFilePointerPtr, closeHandlePtr, hooks); _instanceMade = true; return(_instance); }
public DX9Hook(IReloadedHooks _hooks) { // Obtain the pointer to the IDirect3DDevice9 instance by creating our own blank windows form and creating a // IDirect3DDevice9 targeting that form. The returned device should be the same one as used by the program. using (var direct3D = new Direct3D()) using (var renderForm = new Form()) using (var device = new Device(direct3D, 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.HardwareVertexProcessing, GetParameters(direct3D, renderForm.Handle))) { Direct3D9VTable = _hooks.VirtualFunctionTableFromObject(direct3D.NativePointer, Enum.GetNames(typeof(IDirect3D9)).Length); DeviceVTable = _hooks.VirtualFunctionTableFromObject(device.NativePointer, Enum.GetNames(typeof(IDirect3DDevice9)).Length); using var texture = new Texture(device, 128, 128, 0, Usage.None, Format.X8R8G8B8, Pool.Default); Texture9VTable = _hooks.VirtualFunctionTableFromObject(texture.NativePointer, Enum.GetNames(typeof(IDirect3DTexture9)).Length); } using (var direct3D = new Direct3DEx()) using (var renderForm = new Form()) using (var device = new DeviceEx(direct3D, 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.HardwareVertexProcessing, GetParameters(direct3D, renderForm.Handle))) { DeviceExVTable = _hooks.VirtualFunctionTableFromObject(direct3D.NativePointer, Enum.GetNames(typeof(IDirect3D9)).Length); Direct3D9ExVTable = _hooks.VirtualFunctionTableFromObject(device.NativePointer, Enum.GetNames(typeof(IDirect3DDevice9)).Length); } }
/// <summary> /// Encapsulates a function. /// </summary> /// <param name="address">The address of the function in question.</param> /// <param name="hooks">Provides the hooking capability for this class.</param> public Function(long address, IReloadedHooks hooks) { Address = address; Hooks = hooks; }
public NativeFunctions(IntPtr ntCreateFile, IntPtr ntReadFile, IntPtr ntSetInformationFile, IntPtr ntQueryInformationFile, IReloadedHooks hooks) { NtCreateFile = hooks.CreateFunction <NtCreateFile>((long)ntCreateFile); NtReadFile = hooks.CreateFunction <NtReadFile>((long)ntReadFile); SetFilePointer = hooks.CreateFunction <NtSetInformationFile>((long)ntSetInformationFile); GetFileSize = hooks.CreateFunction <NtQueryInformationFile>((long)ntQueryInformationFile); }
/// <summary> /// Initializes the library. /// </summary> /// <param name="_hooks">Instance of the Reloaded.Hooks library.</param> public static void Init(IReloadedHooks _hooks) { Hooks = _hooks; }
/// <summary> /// Initializes the Heroes SDK as a Reloaded II mod, setting the shared library to be used. /// </summary> public static void Init(IReloadedHooks hooks, IPrsInstance prs) { ReloadedHooks = hooks; Prs = prs; }
/// <summary> /// Initializes the library. /// </summary> /// <param name="_hooks">Instance of the Reloaded.Hooks library.</param> /// <param name="_debug">Specifies a method to receive debugging printouts.</param> public static void Init(IReloadedHooks _hooks, Action <string> _debug = null) { Hooks = _hooks; Debug = _debug; }
/// <summary> /// Encapsulates a function. /// </summary> /// <param name="address">The address of the function in question.</param> /// <param name="hooks">Provides the hooking capability for this class.</param> public Function(nuint address, IReloadedHooks hooks) { _address = address; Hooks = hooks; }
public GraphicsEssentials(string modFolder, string configDirectory, IReloadedHooks hooks) { _configurator = new Configurator(configDirectory); _configurator.Migrate(modFolder, configDirectory); _config = _configurator.GetConfiguration <Config.Config>(0); _defaultSettingsHook = new DefaultSettingsHook(_config.DefaultSettings); NativeResolutionPatcher.Patch(_config.Width, _config.Height); WindowStylePatcher.Patch(_config.BorderlessWindowed, _config.ResizableWindowed); if (_config.StupidlyFastLoadTimes) { LoadTimeHack.Patch(); } if (_config.Disable2PFrameskip) { DisableFrameskipPatch.Patch(); } if (_config.HighAspectRatioCrashFix) { _crashPatch = new StageLoadCrashPatch(); } if (_config.DontSlowdownOnFocusLost) { DontSlowdownOnFocusLoss.Patch(); } _clippingPlanesHook = new ClippingPlanesHook(_config.AspectRatioLimit); _aspectRatioHook = new AspectRatioHook(_config.AspectRatioLimit); _resolutionVariablePatcher = new ResolutionVariablePatcher(); _renderHooks = new RenderHooks(_config.AspectRatioLimit, hooks); Task.Run(MessagePump); Task.Run(async() => { while (Window.WindowHandle == IntPtr.Zero) { await Task.Delay(32); } int left = 0; int top = 0; if (_config.CenterWindow) { var monitor = User32.MonitorFromWindow(Window.WindowHandle, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); var info = new User32.MONITORINFO { cbSize = (uint)Struct.GetSize <User32.MONITORINFO>() }; if (User32.GetMonitorInfo(monitor, ref info)) { left += (info.rcMonitor.Width - _config.Width) / 2; top += (info.rcMonitor.Height - _config.Height) / 2; } } User32.MoveWindow(Window.WindowHandle, left, top, _config.Width, _config.Height, false); await Task.Delay(32); _resizeEventHook.ForceSizeChangeCheck(); }).ConfigureAwait(false); }
/// <summary> /// Initializes the Riders SDK as a Reloaded II mod, setting the shared library to be used. /// </summary> public static void Init(IReloadedHooks hooks) { ReloadedHooks = hooks; MemoryPermissions.Change(); }