Advertisement
sewer56lol

SHeroes CreateFileA Hook- Reloaded Mod Loader

Apr 21st, 2018
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 KB | None | 0 0
  1.        /// <summary>
  2.         /// Your own user code starts here.
  3.         /// If this is your first time, do consider reading the notice above.
  4.         /// It contains some very useful information.
  5.         /// </summary>
  6.         public static void Init()
  7.         {
  8.             Reloaded.Client.Print("Text");
  9.             Reloaded.Client.PrintError("Error");
  10.             Reloaded.Client.PrintInfo("Info");
  11.             Reloaded.Client.PrintWarning("Warning");
  12.  
  13.             // This should automatically resolve to kernel32.dll as it is already registered by Windows.
  14.             // The handle should return from already loaded library in memory, following the standard search strategy.
  15.             Debugger.Launch();
  16.             IntPtr kernel32Handle = Native.LoadLibrary("kernel32");
  17.             IntPtr createFileA = Native.GetProcAddress(kernel32Handle, "CreateFileA");
  18.  
  19.             createFileHook = FunctionHook<CreateFileA>.CreateFunctionHook((long)createFileA, CreateFileOverride);
  20.         }
  21.  
  22.         /*
  23.             Common to Calling and Hooking Game Function
  24.         */
  25.  
  26.         /// <summary>
  27.         /// Function delegate for CreateFileA, the function the game uses to obtain handles to files it will load.
  28.         /// </summary>
  29.         /// <param name="filename"></param>
  30.         /// <param name="access"></param>
  31.         /// <param name="share"></param>
  32.         /// <param name="securityAttributes"></param>
  33.         /// <param name="creationDisposition"></param>
  34.         /// <param name="flagsAndAttributes"></param>
  35.         /// <param name="templateFile"></param>
  36.         /// <returns></returns>
  37.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  38.         [ReloadedFunction(SourceRegisters = new Register[0], ReturnRegister = Register.eax, Cleanup = StackCleanup.Callee)]
  39.         public delegate IntPtr CreateFileA
  40.         (
  41.             [MarshalAs(UnmanagedType.LPStr)] string filename,
  42.             [MarshalAs(UnmanagedType.U4)] FileAccess access,
  43.             [MarshalAs(UnmanagedType.U4)] FileShare share,
  44.             IntPtr securityAttributes,
  45.             [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
  46.             [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
  47.             IntPtr templateFile
  48.         );
  49.  
  50.         /*
  51.             Hooking of Game Function
  52.         */
  53.         private static FunctionHook<CreateFileA> createFileHook;
  54.  
  55.         public static IntPtr CreateFileOverride(string filename, FileAccess fileAccess, FileShare fileShare, IntPtr securityAttributes, FileMode creationDisposition, FileAttributes flagsAndAttributes, IntPtr templateFile)
  56.         {
  57.             Reloaded.Client.Print($"Loading File {filename}");
  58.             return createFileHook.OriginalFunction(filename, fileAccess, fileShare, securityAttributes, creationDisposition, flagsAndAttributes, templateFile);
  59.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement