示例#1
0
        /// <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();
                    }
                }
            }
        }
示例#2
0
        /// <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();
                }
            }
        }
示例#3
0
        /// <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();
                }
            }
        }
示例#4
0
        /// <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);
        }
示例#5
0
        /// <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);
        }
示例#6
0
        /// <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();
                }
            }
        }
示例#7
0
 /// <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 X64FunctionHook <TFunction> CreateFunctionHook64 <TFunction>(this VirtualFunctionTable.TableEntry tableEntry, TFunction delegateType)
 {
     return(X64FunctionHook <TFunction> .Create((long)tableEntry.FunctionPointer, delegateType));
 }