Пример #1
0
 /// <summary>
 /// Adds the techs for every registered building to the database.
 /// </summary>
 internal static void AddAllTechs()
 {
     if (buildingTable == null)
     {
         throw new InvalidOperationException("Building table not loaded");
     }
     lock (PSharedData.GetLock(PRegistry.KEY_BUILDING_LOCK)) {
         PRegistry.LogPatchDebug("Register techs for {0:D} buildings".F(
                                     buildingTable.Count));
         foreach (var building in buildingTable)
         {
             if (building != null)
             {
                 var trBuilding = Traverse.Create(building);
                 // Building is of type object because it is in another assembly
                 var addTech = Traverse.Create(building).Method(nameof(AddTech));
                 if (addTech.MethodExists())
                 {
                     addTech.GetValue();
                 }
                 else
                 {
                     PRegistry.LogPatchWarning("Invalid building technology!");
                 }
             }
         }
     }
 }
Пример #2
0
 public override void OnLoad(Harmony harmony)
 {
     try {
         var method = typeof(Mod).GetMethodSafe(nameof(Mod.SetCrashed), false);
         if (method != null)
         {
             harmony.Patch(method, prefix: new HarmonyMethod(typeof(
                                                                 ModUpdateDatePatches), nameof(OnModCrash)));
         }
         SafeMode = false;
         PUtil.InitLibrary();
         new PPatchManager(harmony).RegisterPatchClass(typeof(ModUpdateDatePatches));
         new POptions().RegisterOptions(this, typeof(ModUpdateInfo));
         new PLocalization().Register();
         ModUpdateInfo.LoadSettings();
         base.OnLoad(harmony);
         ThisMod = mod;
         // Shut off AVC
         PRegistry.PutData("PLib.VersionCheck.ModUpdaterActive", true);
         if (ModUpdateInfo.Settings?.AutoUpdate == true)
         {
             PRegistry.PutData("PLib.VersionCheck.PassiveSteamUpdate", true);
         }
     } catch (Exception e) {
         // AAAAAAAAH!
         PUtil.LogWarning("Mod Updater failed to load! Entering safe mode...");
         PUtil.LogExcWarn(e);
         SafeMode = true;
     }
 }
Пример #3
0
 /// <summary>
 /// Adds the techs for every registered building to the database.
 /// </summary>
 internal static void AddAllTechs()
 {
     if (buildingTable == null)
     {
         throw new InvalidOperationException("Building table not loaded");
     }
     lock (PSharedData.GetLock(PRegistry.KEY_BUILDING_LOCK)) {
         PRegistry.LogPatchDebug("Register techs for {0:D} buildings".F(
                                     buildingTable.Count));
         foreach (var building in buildingTable)
         {
             if (building != null)
             {
                 try {
                     var trBuilding = Traverse.Create(building);
                     // Building is of type object because it is in another assembly
                     var addTech = Traverse.Create(building).Method(nameof(AddTech));
                     if (addTech.MethodExists())
                     {
                         addTech.GetValue();
                     }
                     else
                     {
                         PRegistry.LogPatchWarning("Invalid building technology!");
                     }
                 } catch (System.Reflection.TargetInvocationException e) {
                     // Log errors when registering building from another mod
                     PUtil.LogError("Unable to add building tech for " +
                                    building.GetType().Assembly?.GetNameSafe() + ":");
                     PUtil.LogException(e.GetBaseException());
                 }
             }
         }
     }
 }
Пример #4
0
 public override void OnLoad(Harmony harmony)
 {
     base.OnLoad(harmony);
     PUtil.InitLibrary();
     PRegistry.PutData("Bugs.FlowUtilityNetworkConduits", true);
     new PVersionCheck().Register(this, new SteamVersionChecker());
 }
Пример #5
0
        public override void OnLoad(Harmony harmony)
        {
            base.OnLoad(harmony);
            var options = FastTrackOptions.Instance;

            onWorldGenLoad.Reset();
            PUtil.InitLibrary();
            LocString.CreateLocStringKeys(typeof(FastTrackStrings.UI));
            new PLocalization().Register();
            new POptions().RegisterOptions(this, typeof(FastTrackOptions));
            new PPatchManager(harmony).RegisterPatchClass(typeof(FastTrackMod));
            new PVersionCheck().Register(this, new SteamVersionChecker());
            // In case this goes in stock bug fix later
            if (options.UnstackLights)
            {
                PRegistry.PutData("Bugs.StackedLights", true);
            }
            PRegistry.PutData("Bugs.AnimFree", true);
            PRegistry.PutData("Bugs.MassStringsReadOnly", true);
            if (options.MiscOpts)
            {
                PRegistry.PutData("Bugs.ElementTagInDetailsScreen", true);
            }
            // This patch is Windows only apparently
            var target = typeof(Global).GetMethodSafe(nameof(Global.TestDataLocations), false);

            if (options.MiscOpts && target != null && typeof(Global).GetFieldSafe(
                    nameof(Global.saveFolderTestResult), true) != null)
            {
                harmony.Patch(target, prefix: new HarmonyMethod(typeof(FastTrackMod),
                                                                nameof(RemoveTestDataLocations)));
#if DEBUG
                PUtil.LogDebug("Patched Global.TestDataLocations");
#endif
            }
            else
            {
                PUtil.LogDebug("Skipping TestDataLocations patch");
            }
            // Another potentially Windows only patch
            target = typeof(Game).Assembly.GetType(nameof(InitializeCheck), false)?.
                     GetMethodSafe(nameof(InitializeCheck.CheckForSavePathIssue), false);
            if (options.MiscOpts && target != null)
            {
                harmony.Patch(target, prefix: new HarmonyMethod(typeof(FastTrackMod),
                                                                nameof(SkipInitCheck)));
#if DEBUG
                PUtil.LogDebug("Patched InitializeCheck.Awake");
#endif
            }
            else
            {
                PUtil.LogDebug("Skipping InitializeCheck patch");
            }
            GameRunning = false;
        }
Пример #6
0
        /// <summary>
        /// Starts the automatic version check for all mods.
        /// </summary>
        internal void RunVersionCheck()
        {
            var allMods = PRegistry.Instance.GetAllComponents(ID);

            // See if Mod Updater triggered master disable
            if (!PRegistry.GetData <bool>("PLib.VersionCheck.ModUpdaterActive") &&
                allMods != null)
            {
                new AllVersionCheckTask(allMods, this).Run();
            }
        }
Пример #7
0
 public static void Patch(Harmony harmony)
 {
     if (!PRegistry.GetData <bool>(PATCH_KEY))
     {
         OnRefreshUserMenuDelegate = Traverse.Create <ManualDeliveryKG>()
                                     .Field <EventSystem.IntraObjectHandler <ManualDeliveryKG> >(nameof(OnRefreshUserMenuDelegate)).Value;
         harmony.Patch(typeof(ManualDeliveryKG), nameof(OnSpawn),
                       postfix: new HarmonyMethod(typeof(ManualDeliveryKGPatch), nameof(OnSpawn)));
         harmony.Patch(typeof(ManualDeliveryKG), nameof(OnCleanUp),
                       prefix: new HarmonyMethod(typeof(ManualDeliveryKGPatch), nameof(OnCleanUp)));
         harmony.PatchTranspile(typeof(ManualDeliveryKG), "OnRefreshUserMenu",
                                transpiler: new HarmonyMethod(typeof(ManualDeliveryKGPatch), nameof(Transpiler)));
         PRegistry.PutData(PATCH_KEY, true);
     }
 }
        internal static void FixDiggable(Harmony instance)
        {
            const string BUG_KEY = "Bugs.DisableNeutroniumDig";

            if (!StockBugFixOptions.Instance.AllowNeutroniumDig && !PRegistry.GetData <bool>(
                    BUG_KEY))
            {
#if DEBUG
                PUtil.LogDebug("Disabling Neutronium digging");
#endif
                PRegistry.PutData(BUG_KEY, true);
                instance.Patch(typeof(Diggable).GetMethodSafe("OnSolidChanged", false,
                                                              PPatchTools.AnyArguments), prefix: new HarmonyMethod(
                                   typeof(StockBugsPatches), nameof(PrefixSolidChanged)));
            }
        }
Пример #9
0
        public override void OnLoad(Harmony instance)
        {
            base.OnLoad(instance);
            PUtil.InitLibrary();
            var pm = new PPatchManager(instance);

            pm.RegisterPatchClass(typeof(StockBugsPatches));
            pm.RegisterPatchClass(typeof(SweepFixPatches));
            FixModUpdateRace(instance);
            PRegistry.PutData("Bugs.TepidizerPulse", true);
            PRegistry.PutData("Bugs.TraitExclusionSpacedOut", true);
            PRegistry.PutData("Bugs.TropicalPacuRooms", true);
            PRegistry.PutData("Bugs.AutosaveDragFix", true);
            new POptions().RegisterOptions(this, typeof(StockBugFixOptions));
            new PVersionCheck().Register(this, new SteamVersionChecker());
        }
        public override void OnLoad(Harmony instance)
        {
            base.OnLoad(instance);
            PUtil.InitLibrary();
            var pm = new PPatchManager(instance);

            pm.RegisterPatchClass(typeof(StockBugsPatches));
#if false
            pm.RegisterPatchClass(typeof(SweepFixPatches));
#endif
            FixModUpdateRace(instance);
            PRegistry.PutData("Bugs.FishReleaseCount", true);
            PRegistry.PutData("Bugs.TepidizerPulse", true);
            PRegistry.PutData("Bugs.TraitExclusionSpacedOut", true);
            PRegistry.PutData("Bugs.JoyReactionFix", true);
            new POptions().RegisterOptions(this, typeof(StockBugFixOptions));
            new PVersionCheck().Register(this, new SteamVersionChecker());
        }
        /// <summary>
        /// Fixes the race condition in Steam.UpdateMods.
        /// </summary>
        /// <param name="instance">The Harmony instance to use for patching.</param>
        private void FixModUpdateRace(Harmony instance)
        {
            var          steamMod = PPatchTools.GetTypeSafe("KMod.Steam");
            const string BUG_KEY  = "Bugs.ModUpdateRace";

            if (steamMod != null && !PRegistry.GetData <bool>(BUG_KEY))
            {
                // Transpile UpdateMods only for Steam versions (not EGS)
#if DEBUG
                PUtil.LogDebug("Transpiling Steam.UpdateMods()");
#endif
                PRegistry.PutData(BUG_KEY, true);
                instance.Patch(steamMod.GetMethodSafe("UpdateMods", false, PPatchTools.
                                                      AnyArguments), transpiler: new HarmonyMethod(typeof(StockBugsPatches),
                                                                                                   nameof(TranspileUpdateMods)));
                instance.Patch(typeof(MainMenu).GetMethodSafe("OnSpawn", false), postfix:
                               new HarmonyMethod(typeof(StockBugsPatches), nameof(PostfixMenuSpawn)));
            }
        }
Пример #12
0
        public override void Process(uint when, object _)
        {
            if (patches.TryGetValue(when, out PrivateRunList atTime) && atTime != null &&
                atTime.Count > 0)
            {
                string stage = RunAt.ToString(when);
#if DEBUG
                PRegistry.LogPatchDebug("Executing {0:D} handler(s) from {1} for stage {2}".F(
                                            atTime.Count, Assembly.GetExecutingAssembly().GetNameSafe() ?? "?", stage));
#endif
                foreach (var patch in atTime)
                {
                    try {
                        patch.Run(harmony);
                    } catch (TargetInvocationException e) {
                        // Use the inner exception
                        PUtil.LogError("Error running patches for stage " + stage + ":");
                        PUtil.LogException(e.GetBaseException());
                    }
                }
Пример #13
0
        public override void OnLoad(Harmony harmony)
        {
            var method = typeof(Mod).GetMethodSafe(nameof(Mod.SetCrashed), false);

            if (method != null)
            {
                harmony.Patch(method, prefix: new HarmonyMethod(typeof(ModUpdateDatePatches),
                                                                nameof(OnModCrash)));
            }
            PUtil.InitLibrary();
            new PPatchManager(harmony).RegisterPatchClass(typeof(ModUpdateDatePatches));
            new POptions().RegisterOptions(this, typeof(ModUpdateInfo));
            new PLocalization().Register();
            ModUpdateInfo.LoadSettings();
            base.OnLoad(harmony);
            ThisMod = mod;
            // Shut off AVC
            PRegistry.PutData("PLib.VersionCheck.ModUpdaterActive", true);
            if (ModUpdateInfo.Settings?.PassiveMode == true)
            {
                PRegistry.PutData("PLib.VersionCheck.PassiveSteamUpdate", true);
            }
        }
Пример #14
0
        public override void OnAllModsLoaded(Harmony harmony, IReadOnlyList <Mod> mods)
        {
            const string ASDF         = "Bugs.AutosaveDragFix";
            const string PACU_SAYS_NO = "Bugs.TropicalPacuRooms";
            var          options      = FastTrackOptions.Instance;

            base.OnAllModsLoaded(harmony, mods);
            if (options.MeshRendererOptions == FastTrackOptions.MeshRendererSettings.All &&
                mods != null)
            {
                CheckTileCompat(harmony, mods);
            }
            // Die pacu bug die
            if (options.AllocOpts && !PRegistry.GetData <bool>(PACU_SAYS_NO))
            {
                GamePatches.DecorProviderRefreshFix.ApplyPatch(harmony);
                PRegistry.PutData(PACU_SAYS_NO, true);
            }
            if (options.FastUpdatePickups)
            {
                CheckFetchCompat(harmony);
            }
            if (!PRegistry.GetData <bool>(ASDF))
            {
                // Fix the annoying autosave bug
                harmony.Patch(typeof(Timelapser), "SaveScreenshot", postfix: new HarmonyMethod(
                                  typeof(FastTrackMod), nameof(FastTrackMod.FixTimeLapseDrag)));
                PRegistry.PutData(ASDF, true);
            }
            if (options.FastReachability)
            {
                GamePatches.FastCellChangeMonitor.CreateInstance();
            }
            // Fix those world strings
            UIPatches.FormatStringPatches.ApplyPatch(harmony);
        }