Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <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.Client.Print("Text");
- Reloaded.Client.PrintError("Error");
- Reloaded.Client.PrintInfo("Info");
- Reloaded.Client.PrintWarning("Warning");
- // 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.
- Debugger.Launch();
- IntPtr kernel32Handle = Native.LoadLibrary("kernel32");
- IntPtr createFileA = Native.GetProcAddress(kernel32Handle, "CreateFileA");
- createFileHook = FunctionHook<CreateFileA>.CreateFunctionHook((long)createFileA, CreateFileOverride);
- }
- /*
- Common to Calling and Hooking Game Function
- */
- /// <summary>
- /// Function delegate for CreateFileA, the function the game uses to obtain handles to files it will load.
- /// </summary>
- /// <param name="filename"></param>
- /// <param name="access"></param>
- /// <param name="share"></param>
- /// <param name="securityAttributes"></param>
- /// <param name="creationDisposition"></param>
- /// <param name="flagsAndAttributes"></param>
- /// <param name="templateFile"></param>
- /// <returns></returns>
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- [ReloadedFunction(SourceRegisters = new Register[0], ReturnRegister = Register.eax, Cleanup = StackCleanup.Callee)]
- public delegate IntPtr CreateFileA
- (
- [MarshalAs(UnmanagedType.LPStr)] string filename,
- [MarshalAs(UnmanagedType.U4)] FileAccess access,
- [MarshalAs(UnmanagedType.U4)] FileShare share,
- IntPtr securityAttributes,
- [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
- [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
- IntPtr templateFile
- );
- /*
- Hooking of Game Function
- */
- private static FunctionHook<CreateFileA> createFileHook;
- public static IntPtr CreateFileOverride(string filename, FileAccess fileAccess, FileShare fileShare, IntPtr securityAttributes, FileMode creationDisposition, FileAttributes flagsAndAttributes, IntPtr templateFile)
- {
- Reloaded.Client.Print($"Loading File {filename}");
- return createFileHook.OriginalFunction(filename, fileAccess, fileShare, securityAttributes, creationDisposition, flagsAndAttributes, templateFile);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement