Exemple #1
0
        bool TryToEnableThrottling()
        {
            var mod = LoadedModManager.RunningMods.FirstOrDefault(m => m.PackageId == "brrainz.harmony");

            if (mod == null)
            {
                return(false);
            }

            void wrapperForSafety()
            {
                var harmony = new HarmonyLib.Harmony(Content.PackageId);
                {
                    var target  = HarmonyLib.AccessTools.Method(typeof(RealTime), nameof(RealTime.Update));
                    var postfix = HarmonyLib.AccessTools.Method(typeof(FrameRateControlMod), nameof(ThrottleEngine));

                    harmony.Patch(target, postfix: new HarmonyLib.HarmonyMethod(postfix));
                }
                {
                    var target  = HarmonyLib.AccessTools.Method(typeof(TickManager), nameof(TickManager.DoSingleTick));
                    var postfix = HarmonyLib.AccessTools.Method(typeof(FrameRateControlMod), nameof(SetWorstAllowedFPS));

                    harmony.Patch(target, postfix: new HarmonyLib.HarmonyMethod(postfix));
                }
            };

            try {
                wrapperForSafety();
            } catch (Exception e) {
                Log.Warning("FrameRateControl :: Despite HarmonyMod being loaded we can't patch, something went very wrong...\n" + e);
                return(false);
            }

            return(true);
        }
Exemple #2
0
        public override void Setup()
        {
            HarmonyLib.Harmony harmony = new HarmonyLib.Harmony("DemeoIntegration");

            harmony.Patch(typeof(ModdingAPI).GetMethod("GetInstalledMods", BindingFlags.Public | BindingFlags.Instance),
                          typeof(Demeo_Module).GetMethod("GetInstalledMods", BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod());

            harmony.Patch(typeof(GameStateMachine).GetMethod("GetConnectionString", BindingFlags.Public | BindingFlags.Static),
                          typeof(Demeo_Module).GetMethod("GetConnectionString", BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod());

            MelonCompatibilityLayer.AddRefreshPluginsEvent(Refresh);
            MelonCompatibilityLayer.AddRefreshModsEvent(Refresh);
            Refresh();
        }
        protected override void OnGameStart(Game game, IGameStarter gameStarter)
        {
            if (game.GameType is Campaign)
            {
                workshopsSaved = new List <Workshop>();
                var harmony     = new HarmonyLib.Harmony("MBWorkshopSaver");
                var original    = typeof(ChangeOwnerOfWorkshopAction).GetMethod("ApplyByWarDeclaration");
                var newfunc     = typeof(SaveMyWorkshops).GetMethod("ApplyByWarDeclaration");
                var returnFalse = typeof(SaveMyWorkshops).GetMethod("returnFalse");
                harmony.Patch(original, new HarmonyLib.HarmonyMethod(returnFalse), new HarmonyLib.HarmonyMethod(newfunc));

                CampaignGameStarter campaignStarter = (CampaignGameStarter)gameStarter;
                campaignStarter.AddBehavior(new workshopworker());
            }
            base.BeginGameStart(game);
        }
Exemple #4
0
        public override void Setup()
        {
            HarmonyLib.Harmony harmony = new HarmonyLib.Harmony("DemeoIntegration");

            harmony.Patch(typeof(GameStateMachine).GetMethod("GetConnectionString", BindingFlags.Public | BindingFlags.Static),
                          typeof(Demeo_Module).GetMethod("GetConnectionString", BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod());

            if (MelonUtils.IsGameIl2Cpp())
            {
                Il2Cpp.Patch(harmony);
            }
            else
            {
                Mono.Patch(harmony);
            }

            MelonCompatibilityLayer.AddRefreshPluginsEvent(Refresh);
            MelonCompatibilityLayer.AddRefreshModsEvent(Refresh);
            Refresh();
        }
Exemple #5
0
 internal static void Patch(HarmonyLib.Harmony harmony)
 {
     harmony.Patch(typeof(ModdingAPI).GetMethod("GetInstalledMods", BindingFlags.Public | BindingFlags.Instance),
                   typeof(Il2Cpp).GetMethod("GetInstalledMods", BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod());
 }