Esempio n. 1
0
        public override void Entry(IModHelper helper)
        {
            //helper.Events.Player.InventoryChanged += InventoryChanged;
            _config  = helper.ReadConfig <Config>();
            addcrows = new AddCrowsPatch(Monitor);

            /*
             *
             * haxorSprinklerName = translate.Get("haxorsprinkler.name");
             * haxorSprinklerDescription = _translate.Get("haxorsprinkler.description");
             * haxorScarecrowName = translate.Get("haxorscarecrow.name");
             * haxorScarecrowDescription = translate.Get("haxorscarecrow.description");
             */
            //Lets get the translations. See if this fixes the bloody issues
            HaxorSprinkler.TranslatedName        = helper.Translation.Get("haxorsprinkler.name");
            HaxorSprinkler.TranslatedDescription = helper.Translation.Get("haxorsprinkler.description");
            HaxorScarecrow.TranslatedName        = helper.Translation.Get("haxorscarecrow.name");
            HaxorScarecrow.TranslatedDescription = helper.Translation.Get("haxorscarecrow.description");
            //Lets activate the asset editor
            helper.Content.AssetEditors.Add(new AssetEditor(helper, Monitor, helper.Translation, _config));


            //Events that happen in the game
            helper.Events.GameLoop.DayStarted += OnDayStarted;
            helper.Events.GameLoop.SaveLoaded += OnSaveLoaded;



            //Apply Harmony Patches
            var harmony = HarmonyInstance.Create(this.ModManifest.UniqueID);

            Monitor.Log("Patching Farm.addCrows with AddCrowsPatch");
            harmony.Patch(
                original: AccessTools.Method(typeof(Farm), nameof(Farm.addCrows), new Type[] {  }),
                prefix: new HarmonyMethod(typeof(AddCrowsPatch), nameof(AddCrowsPatch.Prefix))
                );

            Monitor.Log("Patching Object.IsSprinkler with IsSprinklerPatch");
            harmony.Patch(
                original: AccessTools.Method(typeof(SObject), nameof(SObject.IsSprinkler), new Type[] {  }),
                prefix: new HarmonyMethod(typeof(IsSprinklerPatch), nameof(IsSprinklerPatch.Prefix))
                );

            Monitor.Log("Patching Object.GetBaseRadiusForSprinkler with GetBaseRadiusForSprinklerPatch");
            harmony.Patch(
                original: AccessTools.Method(typeof(SObject), nameof(SObject.GetBaseRadiusForSprinkler), new Type[] { }),
                prefix: new HarmonyMethod(typeof(GetBaseRadiusForSprinklerPatch), nameof(GetBaseRadiusForSprinklerPatch.Prefix))
                );
        }
Esempio n. 2
0
        public override void Entry(IModHelper helper)
        {
            helper.Events.GameLoop.DayStarted += OnDayStarted;

            // Harmony Original Code credit goes to Cat from the SDV Modding Discord, I modified his Harmony code.
            try
            {
                HarmonyInstance Harmony = HarmonyInstance.Create("mizzion.onesprinkleronescarecrow");

                //Now we set up the patches, will use a dictionary, just in case I need to expand later. Idea of using Harmony this way came from Cat#2506's mod  from the SDV discord
                IDictionary <string, Type> replacements = new Dictionary <string, Type>
                {
                    [nameof(Farm.addCrows)] = typeof(AddCrowsPatch)
                };

                IList <Type> typesToPatch = new List <Type>();
                typesToPatch.Add(typeof(Farm));


                //Go through and set up the patching
                foreach (Type t in typesToPatch)
                {
                    foreach (KeyValuePair <string, Type> replacement in replacements)
                    {
                        MethodInfo original = t.GetMethods(BindingFlags.Instance | BindingFlags.Public).FirstOrDefault(m => m.Name == replacement.Key);

                        MethodInfo prefix = replacement.Value
                                            .GetMethods(BindingFlags.Static | BindingFlags.Public).FirstOrDefault(item => item.Name == "Prefix");
                        MethodInfo postfix = replacement.Value
                                             .GetMethods(BindingFlags.Static | BindingFlags.Public).FirstOrDefault(item => item.Name == "Postfix");

                        //this.Monitor.Log($"Patching {original} with {prefix} {postfix}", LogLevel.Trace);
                        this.Monitor.Log($"Patching {original} with {prefix} {postfix}", LogLevel.Trace);

                        Harmony.Patch(original, prefix == null ? null : new HarmonyMethod(prefix),
                                      postfix == null ? null : new HarmonyMethod(postfix));
                    }
                }
            }
            catch (Exception ex)
            {
                Monitor.Log($"There was an error setting up harmony.\n {ex}", LogLevel.Trace);
            }
            addcrows = new AddCrowsPatch(Monitor);
        }