internal static void initializePatch(Harmony.HarmonyInstance instance) { foreach (MethodInfo method in typeof(OvSpritebatchNew).GetMethods(BindingFlags.Static | BindingFlags.Public).Where(m => m.Name == "Draw")) { instance.Patch(typeof(SpriteBatch).GetMethod("Draw", method.GetParameters().Select(p => p.ParameterType).Where(t => !t.Name.Contains("SpriteBatch")).ToArray()), new Harmony.HarmonyMethod(method), null, null); } }
internal static void setUpEventHandlers() { fieldInfoChache = new Dictionary <Type, FieldInfo[]>(); propInfoChache = new Dictionary <Type, PropertyInfo[]>(); Helper.Events.GameLoop.Saving += (s, e) => { Replace(); }; Helper.Events.GameLoop.Saved += (s, e) => { RebuildFromActions(); }; Helper.Events.GameLoop.SaveLoaded += (s, e) => { Rebuild(); }; Helper.Events.GameLoop.SaveLoaded += (s, e) => { Game1.objectSpriteSheet.Tag = "cod_objects"; Game1.bigCraftableSpriteSheet.Tag = "cod_objects"; }; Harmony.HarmonyInstance instance = Harmony.HarmonyInstance.Create("PytK.Savehandler.SyncFix"); instance.Patch(typeof(NewDaySynchronizer).GetMethod("start"), new Harmony.HarmonyMethod(typeof(SaveHandler), "Replace", null), null, null); }
internal static void initializePatch(Harmony.HarmonyInstance instance) { foreach (MethodInfo method in typeof(SpritbatchFixNew).GetMethods(BindingFlags.Static | BindingFlags.Public).Where(m => m.Name == "Draw")) { try { instance.Patch(typeof(SpriteBatch).GetMethod("Draw", method.GetParameters().Select(p => p.ParameterType.Name.Contains("Texture2D") ? typeof(Texture2D) : p.ParameterType.Name.Contains("Color") ? typeof(Color) : p.ParameterType).Where(t => !t.Name.Contains("SpriteBatch")).ToArray()), new Harmony.HarmonyMethod(method), null, null); } catch (Exception e) { VisualizeMod._monitor.Log(method.Name + "(" + string.Join(",", method.GetParameters().Select(p => p.ParameterType.ToString())) + ")", StardewModdingAPI.LogLevel.Error); VisualizeMod._monitor.Log(e.Message + ":" + e.StackTrace, StardewModdingAPI.LogLevel.Error); } } foreach (MethodInfo method in typeof(SpritbatchFixNew).GetMethods(BindingFlags.Static | BindingFlags.Public).Where(m => m.Name == "DrawString")) { try { instance.Patch(typeof(SpriteBatch).GetMethod("DrawString", method.GetParameters().Select(p => p.ParameterType.Name.Contains("Color") ? typeof(Color) : p.ParameterType).Where(t => !t.Name.Contains("SpriteBatch")).ToArray()), new Harmony.HarmonyMethod(method), null, null); } catch (Exception e) { VisualizeMod._monitor.Log(method.Name + "(" + string.Join(",", method.GetParameters().Select(p => p.ParameterType.ToString())) + ")", StardewModdingAPI.LogLevel.Error); VisualizeMod._monitor.Log(e.Message + ":" + e.StackTrace, StardewModdingAPI.LogLevel.Error); } } }
public static void patchModLoad() { Harmony.HarmonyInstance harmony = Harmony.HarmonyInstance.Create("Platonymous.ModUpdater"); harmony.Patch( original: Type.GetType("StardewModdingAPI.Framework.SCore, StardewModdingAPI").GetMethod("CheckForUpdatesAsync", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance), prefix: new Harmony.HarmonyMethod(Harmony.AccessTools.DeclaredMethod(typeof(ModUpdaterMod), nameof(CheckForUpdatesAsync))) ); harmony.Patch( original: Type.GetType("StardewModdingAPI.Framework.SCore, StardewModdingAPI").GetMethod("TryLoadMod", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance), prefix: new Harmony.HarmonyMethod(Harmony.AccessTools.DeclaredMethod(typeof(ModUpdaterMod), nameof(TryLoadMod))) ); }
internal static void setUpEventHandlers() { fieldInfoChache = new Dictionary <Type, FieldInfo[]>(); propInfoChache = new Dictionary <Type, PropertyInfo[]>(); Helper.Events.GameLoop.SaveLoaded += (s, e) => { Game1.objectSpriteSheet.Tag = "cod_objects"; Game1.bigCraftableSpriteSheet.Tag = "cod_objects"; }; Harmony.HarmonyInstance instance = Harmony.HarmonyInstance.Create("PytK.Savehandler.SyncFix"); }
static bool Load(UnityModManager.ModEntry modEntry) { try { logger = modEntry.Logger; harmony = Harmony.HarmonyInstance.Create(modEntry.Info.Id); harmony.PatchAll(Assembly.GetExecutingAssembly()); } catch (Exception ex) { DebugError(ex); throw ex; } return(true); }
static Core() { try { MelonUtils.Setup(); } catch (Exception ex) { MelonLogger.Error("MelonUtils.Setup Exception: " + ex.ToString()); throw ex; } Harmony.HarmonyInstance harmonyInstance = Harmony.HarmonyInstance.Create("MelonLoader"); try { harmonyInstance.Patch(typeof(Thread).GetProperty("CurrentCulture", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), new Harmony.HarmonyMethod(typeof(Core).GetMethod("GetCurrentCulturePrefix", BindingFlags.NonPublic | BindingFlags.Static))); } catch (Exception ex) { MelonLogger.Warning("Thread.CurrentCulture Exception: " + ex.ToString()); } try { harmonyInstance.Patch(typeof(Thread).GetProperty("CurrentUICulture", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), new Harmony.HarmonyMethod(typeof(Core).GetMethod("GetCurrentCulturePrefix", BindingFlags.NonPublic | BindingFlags.Static))); } catch (Exception ex) { MelonLogger.Warning("Thread.CurrentUICulture Exception: " + ex.ToString()); } try { ((AppDomainSetup)typeof(AppDomain).GetProperty("SetupInformationNoCopy", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(AppDomain.CurrentDomain, new object[0])).ApplicationBase = MelonUtils.GameDirectory; } catch (Exception ex) { MelonLogger.Warning("AppDomainSetup.ApplicationBase Exception: " + ex.ToString()); } Directory.SetCurrentDirectory(MelonUtils.GameDirectory); AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveHandler; AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += AssemblyResolveHandler; try { MelonPreferences.LegacyCheck(); } catch (Exception ex) { MelonLogger.Error("MelonPreferences.LegacyCheck Exception: " + ex.ToString()); MelonPreferences.WasError = true; } try { MelonPreferences.Load_Internal(); } catch (Exception ex) { MelonLogger.Error("MelonPreferences.Load_Internal Exception: " + ex.ToString()); MelonPreferences.WasError = true; } if (MelonPreferences.WasLegacyLoaded) { try { MelonPreferences.Save_Internal(); } catch (Exception ex) { MelonLogger.Error("MelonPreferences.Save_Internal Exception: " + ex.ToString()); MelonPreferences.WasError = true; } } MelonPreferences.SaveAfterEntryCreation = true; try { bHaptics_NativeLibrary.Load(); } catch (Exception ex) { MelonLogger.Error("bHaptics_NativeLibrary.Load Exception: " + ex.ToString()); bHaptics.WasError = true; } }
public static void DoPatch() { var harmony = HarmonyInstance.Create("com.github.harmony.rust"); harmony.PatchAll(Assembly.GetExecutingAssembly()); }