public override void OnModLoad() { MonoModHooks.RequestNativeAccess(); new Hook(typeof(ModLoader).GetCachedMethod("Mods_Unload"), typeof(UnloadValueSettingSystem).GetCachedMethod(nameof(HijackUnloading))).Apply(); }
public override void Load() { if (mode > 0) { MonoModHooks.RequestNativeAccess(); } switch (mode) { case 0: OnMain.DrawCursor += Wrap; break; case 1: new Hook(new OnMain.orig_DrawCursor(Main.DrawCursor), new OnMain.hook_DrawCursor(Wrap)); break; case 2: new Detour(new OnMain.orig_DrawCursor(Main.DrawCursor), new OnMain.orig_DrawCursor(Replace)); break; case 3: new NativeDetour(new OnMain.orig_DrawCursor(Main.DrawCursor), new OnMain.orig_DrawCursor(Replace)); break; } }
public override void OnModLoad() { MonoModHooks.RequestNativeAccess(); new Hook( typeof(ModLoader).Assembly.GetType("Terraria.ModLoader.MenuLoader") !.GetCachedMethod( "UpdateAndDrawModMenu"), typeof(ModMenuSplashTextSystem).GetCachedMethod(nameof(OverlaySplashText))).Apply(); }
public static void Load() { On.Terraria.IO.WorldFile.saveWorld_bool_bool += SaveWorld; On.Terraria.IO.WorldFile.loadWorld += LoadWorld; MonoModHooks.RequestNativeAccess(); ProjectDimensionHook.do_worldGenCallBack_Hook += do_worldGenCallBack; On.Terraria.Player.Spawn += Spawn; On.Terraria.Main.DrawToMap_Section += DrawToMap_Section; On.Terraria.GameContent.UI.States.UIWorldLoad.DrawSelf += DrawSelfLoad; }
public override bool Autoload(ref string name) { MonoModHooks.RequestNativeAccess(); IDetour d = new Hook(typeof(PlayerHooks).GetMethod("UpdateBadLifeRegen"), typeof(DoTResistancePlayer).GetMethod("ReduceDoT")); d.Apply(); return(base.Autoload(ref name)); }
private static void HookIntoLoad() { MonoModHooks.RequestNativeAccess(); new Hook( typeof(ModContent).GetMethod("LoadModContent", BindingFlags.NonPublic | BindingFlags.Static), typeof(Fargowiltas).GetMethod(nameof(LoadHook), BindingFlags.NonPublic | BindingFlags.Static)).Apply(); HookEndpointManager.Modify( typeof(ModContent).GetMethod("Load", BindingFlags.NonPublic | BindingFlags.Static), Delegate.CreateDelegate(typeof(ILContext.Manipulator), typeof(Fargowiltas).GetMethod(nameof(ModifyLoading), BindingFlags.NonPublic | BindingFlags.Static) ?? throw new Exception("Couldn't create IL manipulator."))); }
public override void Load() { Reflection.InitializeCaches(); MonoModHooks.RequestNativeAccess(); FallingTileTextures = new Dictionary <int, Texture2D>(); fallingTileAlphaMask = GetTexture("GameHelpers/FallingTileAlphaMask"); disposeList = new List <IDisposable>(); TerrariaAssembly = typeof(Main).Assembly; ModAssemblies = ModLoader.Mods.Skip(1).ToDictionary(m => m.Name, m => m.Code); // initialize on load so libvaxy-dependent mods function when using this StackInspectHandler.Initialize(); HookHandler.ApplyHooks(); }
// TODO: Make it possible to call original method easily + pass in an instance of the caller internal static void ApplyDetours() { MonoModHooks.RequestNativeAccess(); foreach (MethodInfo method in Reflection.GetMethodsWithAttribute <DetourAttribute>()) { DetourAttribute attribute = method.GetCustomAttribute <DetourAttribute>(); string modName = attribute.typeName.Split('.')[0]; if (!Libvaxy.ModAssemblies.ContainsKey(modName)) { Libvaxy.Logger.Warn("Attempted to detour an unknown / unloaded mod, ignoring and moving on..."); continue; } Type targetMethodType = Libvaxy.ModAssemblies[modName].GetType(attribute.typeName); if (targetMethodType == null) { throw new LibvaxyException("Could not find the target type to perform detour"); } MethodInfo targetMethod = Reflection.GetMethodInfo(targetMethodType, attribute.methodName, attribute.parameterTypes ?? new Type[0]); // TODO: move these checks elsewhere as a utility if (targetMethod == null) { throw new LibvaxyException("Could not find the target method to perform detour"); } if (!Reflection.GetParameterTypes(method).SequenceEqual(Reflection.GetParameterTypes(targetMethod))) { throw new LibvaxyException("The target method and detour method do not have matching parameter types"); } if (method.ReturnType != targetMethod.ReturnType) { throw new LibvaxyException("The target method and detour method do not have matching return types"); } Libvaxy.DisposeOnUnload(new Detour(targetMethod, method)); Libvaxy.Logger.Info($"Registered detour from {targetMethod.FullMemberName()}\nTo: {method.FullMemberName()}"); } }
public static void ApplyHook(MethodInfo from, MethodInfo to) { MonoModHooks.RequestNativeAccess(); new Hook(from, to).Apply(); }