/// <summary> /// Your own user code starts here. /// If this is your first time, do consider reading the notice above. /// It contains some very useful information. /// </summary> public static unsafe void Init() { #if DEBUG Debugger.Launch(); #endif // Create new allocator. Allocator = new Allocator(); // :3 Bindings.PrintWarning("Initializing: The ONE Archive Expandonger"); OneFileLoadHAnimationHook = FunctionHook <OneFileLoadHAnimation> .Create(0x0042F600, OneFileLoadHAnimationImpl).Activate(); OneFileLoadClumpHook = FunctionHook <OneFileLoadClump> .Create(0x0042F440, OneFileLoadClumpImpl).Activate(); OneFileLoadTextureDictionaryHook = FunctionHook <OneFileLoadTextureDictionary> .Create(0x0042F3C0, OneFileLoadTextureDictionaryImpl).Activate(); OneFileLoadSplineHook = FunctionHook <OneFileLoadSpline> .Create(0x0042F4B0, OneFileLoadSplineImpl).Activate(); OneFileLoadDeltaMorphHook = FunctionHook <OneFileLoadDeltaMorph> .Create(0x0042F520, OneFileLoadDeltaMorphImpl).Activate(); OneFileLoadWorldHook = FunctionHook <OneFileLoadWorld> .Create(0x0042F590, OneFileLoadWorldImpl).Activate(); OneFileLoadUVAnimHook = FunctionHook <OneFileLoadUVAnim> .Create(0x0042F670, OneFileLoadUVAnimImpl).Activate(); OneFileLoadMaestroHook = FunctionHook <OneFileLoadMaestro> .Create(0x0042F6F0, OneFileLoadMaestroImpl).Activate(); OneFileLoadCameraTmbHook = FunctionHook <OneFileLoadCameraTmb> .Create(0x0042F770, OneFileLoadCameraTmbImpl).Activate(); Bindings.PrintText("Your .ONE Archives have now been expandonged!"); GC.Collect(); }
/// <summary> /// Your own user code starts here. /// If this is your first time, do consider reading the notice above. /// It contains some very useful information. /// </summary> public static void Init() { /* * Reloaded Mod Loader Utility: Steam Hook * Architectures supported: X86, X64 * * Hooks the Steam function responsible for checking if the game should be * restarted and just says "no, it shouldn't". */ #if DEBUG Debugger.Launch(); #endif // PS. I know the code below could be written better, but I wrote it FOR CLARITY. // Get directory of executing executable. string steamAPI32 = Path.GetFullPath(SteamAPI32); string steamAPI64 = Path.GetFullPath(SteamAPI64); // X86 if (IntPtr.Size == 4) { if (File.Exists(steamAPI32)) { // Load file and get address of export. IntPtr libraryAddress = Native.LoadLibraryW(steamAPI32); IntPtr restartAppIfNecessaryPtr = Native.GetProcAddress(libraryAddress, FunctionName); // Hook! if (restartAppIfNecessaryPtr != IntPtr.Zero) { restartIfNecessaryHook32 = FunctionHook <SteamAPI_RestartAppIfNecessary> .Create((long)restartAppIfNecessaryPtr, FunctionDelegate).Activate(); } } } // X64 if (IntPtr.Size == 8) { if (File.Exists(steamAPI64)) { // Load file and get address of export. IntPtr libraryAddress = Native.LoadLibraryW(steamAPI64); IntPtr restartAppIfNecessaryPtr = Native.GetProcAddress(libraryAddress, FunctionName); // If the debugger tells you that those two numbers are 0, it's bullshit. // It's a debugger bug, you'll see it right after the next if statement. // Hook! if (restartAppIfNecessaryPtr != IntPtr.Zero) { restartIfNecessaryHook64 = X64FunctionHook <SteamAPI_RestartAppIfNecessary> .Create((long)restartAppIfNecessaryPtr, FunctionDelegate).Activate(); } } } }
/// <summary> /// For class definition, see Class Summary <see cref="MemoryTracer"/>. /// Hooks Sonic Heroes' free & malloc functions and exposes delegates which /// you may use to either alter the parameters of the function or act. /// </summary> public MemoryTracer() { // Hook the game functions. _mallocHook = FunctionHook <Malloc> .Create(0x0067B475, MallocHookImpl).Activate(); _freeHook = FunctionHook <Free> .Create(0x0067B35D, FreeHookImpl).Activate(); MallocFunction = _mallocHook.OriginalFunction; FreeFunction = _freeHook.OriginalFunction; }
/// <summary> /// Your own user code starts here. /// If this is your first time, do consider reading the notice above. /// It contains some very useful information. /// </summary> public static void Init() { /* * Reloaded Mod Loader Sample: File Redirector (New) * Architectures supported: X86, X64 * * This sample mod builds upon the File Monitor sample, providing universal file redirection for modifications * which implement a `Plugins/Redirector/` folder. * * This is the same NtCreateFile hook as seen in the monitor, except that, we instead build * a list of files present within enabled mods' `Plugins/Redirector/` folder and build a dictionary mapping * a path to path. * * In our hooks, we just check if the file path exists in the dictionary, and override it if so. */ // Debugger.Launch(); // This should automatically resolve to ntdll.dll as it is already registered by Windows. // The handle should return from already loaded library in memory, following the standard search strategy. IntPtr ntdllHandle = Reloaded.Process.Native.Native.LoadLibraryW("ntdll"); // Get the addresses of our desired NtCreateFile IntPtr ntCreateFilePointer = Reloaded.Process.Native.Native.GetProcAddress(ntdllHandle, "NtCreateFile"); // Retreieve all enabled mods using utility functions in libReloaded. _currentGameConfig = GameConfig.GetGameConfigFromExecutablePath(ExecutingGameLocation); _enabledMods = GameConfig.GetAllEnabledMods(_currentGameConfig); _enabledMods = GameConfig.TopologicallySortConfigurations(_enabledMods); // Generate a list of new filesystemwatchers which will let us monitor redirector folders in real time. _fileSystemWatcherDictionary = new Dictionary <ModConfig, FileSystemWatcher>(); // Build a dictionary of enabled mods. BuildFileRedirectionDictionary(_enabledMods, _currentGameConfig); // Hook the obtained function pointers. // X86 if (IntPtr.Size == 4) { if (ntCreateFilePointer != IntPtr.Zero) { _ntCreateFileHook = FunctionHook <NtCreateFile> .Create((long)ntCreateFilePointer, NtCreateFileImpl).Activate(); } } // X64 else if (IntPtr.Size == 8) { if (ntCreateFilePointer != IntPtr.Zero) { _ntCreateFileHook64 = X64FunctionHook <NtCreateFile> .Create((long)ntCreateFilePointer, NtCreateFileImpl).Activate(); } } }
/// <summary> /// Your own user code starts here. /// If this is your first time, do consider reading the notice above. /// It contains some very useful information. /// </summary> public static void Init() { /* * Reloaded Mod Loader Sample: File Monitor * Architectures supported: X86, X64 * * Gets our Windows API function pointers by first grabbing a handle to Kernel32 where * the individual functions are located and then calling the GetProcAddress() Windows API * function in order to obtain the address of the exported functions. * * We then hook the functions using the Reloaded Hooking classes, print to console the fileName * parameter and redirect to the original functions. */ // Debugger.Launch(); // This should automatically resolve to kernel32.dll as it is already registered by Windows. // The handle should return from already loaded library in memory, following the standard search strategy. IntPtr kernel32Handle = Reloaded.Process.Native.Native.LoadLibraryW("kernel32"); // Get the addresses of the CreateFileA, CreateFileW, CreateFile functions. IntPtr createFileAPointer = Reloaded.Process.Native.Native.GetProcAddress(kernel32Handle, "CreateFileA"); IntPtr createFileWPointer = Reloaded.Process.Native.Native.GetProcAddress(kernel32Handle, "CreateFileW"); // Hook the obtained function pointers. // X86 if (IntPtr.Size == 4) { if (createFileWPointer != IntPtr.Zero) { _createFileWHook = FunctionHook <CreateFileW> .Create((long)createFileWPointer, CreateFileWImpl).Activate(); } if (createFileAPointer != IntPtr.Zero) { _createFileAHook = FunctionHook <CreateFileA> .Create((long)createFileAPointer, CreateFileAImpl).Activate(); } } // X64 else if (IntPtr.Size == 8) { if (createFileWPointer != IntPtr.Zero) { _createFileWHook64 = X64FunctionHook <CreateFileW> .Create((long)createFileWPointer, CreateFileWImpl).Activate(); } if (createFileAPointer != IntPtr.Zero) { _createFileAHook64 = X64FunctionHook <CreateFileA> .Create((long)createFileAPointer, CreateFileAImpl).Activate(); } } }
/// <summary> /// Instantiates the DirectX overlay, by first finding the applicable /// version of DirectX for the application and then finding the individual /// details. For more details, see <see cref="DX11Overlay"/> /// /// Note: The delegates you will need to call the original function are members of this class, see <see cref="PresentHook"/> and <see cref="ResizeTargetHook"/> /// Note: This method is blocking and Reloaded mods are required to return in order /// to boot up the games, please do not assign this statically - instead assign it in a background thread! /// </summary> /// <param name="DXGIPresentDelegate"> /// A delegate type to use for DirectX rendering. The delegate type should /// contain an appropriate DirectX <see cref="DXGISwapChain_PresentDelegate"/> /// object for drawing overlays. /// </param> /// <param name="DXGIResizeTargetDelegate"> /// A delegate or function of type of <see cref="DXGISwapChain_ResizeTargetDelegate"/> to call when DXGI Buffer /// commits a resolution change or windowed/fullscreen change. /// </param> /// <param name="hookDelay"> /// Specifies the amount of time to wait until the hook is instantiation begins. /// Some games are known to crash if DirectX is hooked too early. /// </param> /// <remarks>The delegates you will need to call the original function are members of this class, see <see cref="PresentHook"/> and <see cref="ResizeTargetHook"/></remarks> public static async Task <DX11Overlay> CreateDirectXOverlay(DXGISwapChain_PresentDelegate DXGIPresentDelegate, DXGISwapChain_ResizeTargetDelegate DXGIResizeTargetDelegate, int hookDelay) { // Wait the hook delay. await Task.Delay(hookDelay); // Create a new self-object. DX11Overlay dx11Overlay = new DX11Overlay(); // Wait for DirectX Direct3DVersion direct3DVersion = await DXHookCommon.GetDirectXVersion(); // Return nothing if not D3D9 if (direct3DVersion != Direct3DVersion.Direct3D11 && direct3DVersion != Direct3DVersion.Direct3D11_1 && direct3DVersion != Direct3DVersion.Direct3D11_3 && direct3DVersion != Direct3DVersion.Direct3D11_4) { Bindings.PrintError( "libReloaded Hooking: DirectX 11 module not found, the application is either not " + "a DirectX 11 application or uses an unsupported version of DirectX."); return(null); } // Instantiate DX9 hook dx11Overlay.DirectX11Hook = new DX11Hook();; // Obtain Virtual Function Table Entries VirtualFunctionTable.TableEntry presentTableEntry = dx11Overlay.DirectX11Hook.DXGISwapChainFunctions[(int)IDXGISwapChain.Present]; VirtualFunctionTable.TableEntry resizeTableEntry = dx11Overlay.DirectX11Hook.DXGISwapChainFunctions[(int)IDXGISwapChain.ResizeTarget]; // Hook relevant DirectX functions. if (IntPtr.Size == 4) { // X86 dx11Overlay.PresentHook = FunctionHook <DXGISwapChain_PresentDelegate> .Create((long)presentTableEntry.FunctionPointer, DXGIPresentDelegate); dx11Overlay.ResizeTargetHook = FunctionHook <DXGISwapChain_ResizeTargetDelegate> .Create((long)resizeTableEntry.FunctionPointer, DXGIResizeTargetDelegate); } else if (IntPtr.Size == 8) { // X64 dx11Overlay.PresentHook64 = X64FunctionHook <DXGISwapChain_PresentDelegate> .Create((long)presentTableEntry.FunctionPointer, DXGIPresentDelegate); dx11Overlay.ResizeTargetHook64 = X64FunctionHook <DXGISwapChain_ResizeTargetDelegate> .Create((long)resizeTableEntry.FunctionPointer, DXGIResizeTargetDelegate); } // Return our DX9Overlay return(dx11Overlay); }
/// <summary> /// Instantiates the DirectX overlay, by first finding the applicable /// version of DirectX for the application and then finding the individual /// details. For more details, see <see cref="DX9Overlay"/> /// Note: This method is blocking and Reloaded mods are required to return in order /// to boot up the games, please do not assign this statically - instead assign it in a background thread! /// </summary> /// <param name="renderDelegate"> /// A delegate type to use for DirectX rendering. The delegate type should /// contain an appropriate DirectX <see cref="Direct3D9Device_EndSceneDelegate"/> /// object for drawing overlays. /// </param> /// <param name="resetDelegate"> /// A delegate or function of type of <see cref="Direct3D9Device_ResetDelegate"/> to call when D3D9 fires its Reset function, /// called on resolution change or windowed/fullscreen change - we can reset some things as well. /// </param> /// <param name="hookDelay"> /// Specifies the amount of time to wait until the hook is instantiation begins. /// Some games are known to crash if DirectX is hooked too early. /// </param> public static async Task <DX9Overlay> CreateDirectXOverlay(Direct3D9Device_EndSceneDelegate renderDelegate, Direct3D9Device_ResetDelegate resetDelegate, int hookDelay) { // Wait the hook delay. await Task.Delay(hookDelay); // Create a new self-object. DX9Overlay dx9Overlay = new DX9Overlay(); // Wait for DirectX Direct3DVersion direct3DVersion = await DXHookCommon.GetDirectXVersion(); // Return nothing if not D3D9 if (direct3DVersion != Direct3DVersion.Direct3D9) { Bindings.PrintError( "libReloaded Hooking: DirectX 9 module not found, the application is either not" + "a DirectX 9 application or uses an unsupported version of DirectX."); return(null); } // Instantiate DX9 hook dx9Overlay.DirectX9Hook = new DX9Hook(); // Obtain Virtual Function Table Entries VirtualFunctionTable.TableEntry endSceneTableEntry = dx9Overlay.DirectX9Hook.DirectXFunctions[(int)Direct3DDevice9.EndScene]; VirtualFunctionTable.TableEntry resetTableEntry = dx9Overlay.DirectX9Hook.DirectXFunctions[(int)Direct3DDevice9.Reset]; // Hook relevant DirectX functions. if (IntPtr.Size == 4) { // X86 dx9Overlay.EndSceneHook = FunctionHook <Direct3D9Device_EndSceneDelegate> .Create((long)endSceneTableEntry.FunctionPointer, renderDelegate); dx9Overlay.ResetHook = FunctionHook <Direct3D9Device_ResetDelegate> .Create((long)resetTableEntry.FunctionPointer, resetDelegate); } else if (IntPtr.Size == 8) { // X64 dx9Overlay.EndSceneHook64 = X64FunctionHook <Direct3D9Device_EndSceneDelegate> .Create((long)endSceneTableEntry.FunctionPointer, renderDelegate); dx9Overlay.ResetHook64 = X64FunctionHook <Direct3D9Device_ResetDelegate> .Create((long)resetTableEntry.FunctionPointer, resetDelegate); } // Return our DX9Overlay return(dx9Overlay); }
/// <summary> /// Your own user code starts here. /// If this is your first time, do consider reading the notice above. /// It contains some very useful information. /// </summary> public static void Init() { /* * Reloaded Mod Loader Sample: File Monitor (New) * Architectures supported: X86, X64 * * Retrieves our Windows API function pointer by first grabbing a handle to Ntdll where * the individual function is located then calls the GetProcAddress() Windows API function * in order to obtain the address of the exported function. * * We then hook the function using the Reloaded hooking classes, print to console the filename * and redirect to the original function. */ // Debugger.Launch(); // This should automatically resolve to ntdll.dll as it is already registered by Windows. // The handle should return from already loaded library in memory, following the standard search strategy. IntPtr ntdllHandle = Reloaded.Process.Native.Native.LoadLibraryW("ntdll"); // Get the addresses of our desired NtCreateFile IntPtr ntCreateFilePointer = Reloaded.Process.Native.Native.GetProcAddress(ntdllHandle, "NtCreateFile"); // Hook the obtained function pointers. // X86 if (IntPtr.Size == 4) { if (ntCreateFilePointer != IntPtr.Zero) { _ntCreateFileHook = FunctionHook <NtCreateFile> .Create((long)ntCreateFilePointer, NtCreateFileImpl).Activate(); } } // X64 else if (IntPtr.Size == 8) { if (ntCreateFilePointer != IntPtr.Zero) { _ntCreateFileHook64 = X64FunctionHook <NtCreateFile> .Create((long)ntCreateFilePointer, NtCreateFileImpl).Activate(); } } }
/// <summary> /// Your own user code starts here. /// If this is your first time, do consider reading the notice above. /// It contains some very useful information. /// </summary> public static unsafe void Init() { #if DEBUG Debugger.Launch(); #endif // Get graphics settings _graphicsSettings = Settings.GraphicsSettings.ParseConfig(ModDirectory); Settings.GraphicsSettings.WriteConfig(_graphicsSettings, ModDirectory); // Will add comments if they are not present. // Hooks _rwCameraSetViewWindowHook = FunctionHook <RWAspect.RwCameraSetViewWindow> .Create(0x0064AC80, RwCameraSetViewWindowImpl).Activate(); _cameraBuildPerspClipPlanesHook = FunctionHook <RWAspect.CameraBuildPerspClipPlanes> .Create(0x0064AF80, CameraBuildPerspClipPlanesImpl).Activate(); _readConfigFromIniHook = FunctionHook <ReadConfigfromINI> .Create(0x00629CE0, ReadConfigFromIniImpl).Activate(); // Patches PatchHardcodedResolutions(); PatchWindowStyle(); if (_graphicsSettings.StupidlyFastLoadTimes) { GameProcess.WriteMemory((IntPtr)0x0078A578, (double)9999999999F); } if (_graphicsSettings.EnableAspectHack) { _someTitlecardCreateHook = FunctionHook <TObjCamera_Init> .Create(0x0061D3B0, TObjCameraInitHook).Activate(); } if (_graphicsSettings.Disable2PFrameskip) { GameProcess.WriteMemory((IntPtr)0x402D07, new byte[] { 0x90 }); } if (_graphicsSettings.D3D9Settings.Enable) { _dx9Device = new Device(_graphicsSettings.D3D9Settings, ModDirectory); } }
/* Entry Point */ public static unsafe void Init() { #if DEBUG Debugger.Launch(); #endif // Setup controllers. var controllerManager = new ControllerManager(); playerOneController = new ReloadedController(Player.PlayerOne, controllerManager); playerTwoController = new ReloadedController(Player.PlayerTwo, controllerManager); playerThreeController = new ReloadedController(Player.PlayerThree, controllerManager); playerFourController = new ReloadedController(Player.PlayerFour, controllerManager); // Hook get controls function. psPADServerHook = FunctionHook <psPADServerPC> .Create(0x444F30, PSPADServerImpl).Activate(); // Copy the old function to a new place and create a function from it. byte[] periMakeRepeatBytes = GameProcess.ReadMemory((IntPtr)0x00434FF0, 0xDD); IntPtr functionPtr = MemoryBufferManager.Add(periMakeRepeatBytes); periMakeRepeatFunction = FunctionWrapper.CreateWrapperFunction <sGamePeri__MakeRepeatCount>((long)functionPtr); periMakeRepeatCountHook = FunctionHook <sGamePeri__MakeRepeatCount> .Create(0x00434FF0, MakeRepeatCountImpl).Activate(); }
/// <summary> /// Hooks an individual virtual function table entry in a virtual function table. /// </summary> /// <typeparam name="TFunction">Delegate type marked with complete ReloadedFunction Attribute/X64 Reloaded Function Attribute that defines the individual function properties.</typeparam> /// <param name="tableEntry">The individual Virtual function table entry to hook.</param> /// <param name="delegateType">The delegate type of your own individual function, such as an instance of the delegate.</param> /// <returns>Delegate to assign back to ReloadedFunction marked game function.</returns> public static FunctionHook <TFunction> CreateFunctionHook86 <TFunction>(this VirtualFunctionTable.TableEntry tableEntry, TFunction delegateType) { return(FunctionHook <TFunction> .Create((long)tableEntry.FunctionPointer, delegateType)); }
// Constructor public VictoryTracker() { _tObjTeamExecHook = FunctionHook <TObjTeam_Exec> .Create(0x005B10E0, CheckScoreIncrementHookFunction).Activate(); }
// Constructor public Heroes() { _moviePlayHook = FunctionHook <MOVIE_PLAY> .Create(0x00643DE0, MoviePlayImpl).Activate(); _movieEndHook = FunctionHook <MOVIE_END> .Create(0x00643E00, MovieEndImpl).Activate(); }