Пример #1
0
        static RimValiPatches()
        {
            Harmony rimValiHarmony = new Harmony("RimVali.patches");

            Log.Message("[RimVali] Started patches.", false);
            try {
                rimValiHarmony.PatchAll();



                //Graphics

                /*rimValiHarmony.Patch(AccessTools.Method(typeof(PawnGraphicSet), "ResolveAllGraphics"), new HarmonyMethod(typeof(ResolvePatch), "ResolveGraphics"), null);
                 * rimValiHarmony.Patch(AccessTools.Method(typeof(ApparelGraphicRecordGetter), "TryGetGraphicApparel"), null, new HarmonyMethod(typeof(Avali_ApparelGraphicRecordGetter_TryGetGraphicApparel_AvaliSpecificHat_Patch), "Avali_SpecificHatPatch"));
                 * rimValiHarmony.Patch(AccessTools.Method(typeof(PawnRenderer), "RenderPortrait"), null, new HarmonyMethod(typeof(RenderPatch), "Portrait"));*/

                int methodsPatched = rimValiHarmony.GetPatchedMethods().EnumerableCount();
                Log.Message("[RimVali] Patches completed. " + methodsPatched.ToString() + " methods patched. [RimVali]");
            }
            catch (Exception error)
            {
                Log.Warning("[RimVali] A patch has failed! Patches completed: " + rimValiHarmony.GetPatchedMethods().EnumerableCount().ToString());
                Log.Error(error.ToString());
            }
        }
Пример #2
0
        // [DllImport("kernel32.dll", SetLastError = true)]
        // [return: MarshalAs((UnmanagedType.Bool))]
        // static extern bool AllocConsole();
        //
        // public static void Main(string[] args)
        // {
        //  AllocConsole();
        //
        //  InitializeModLoader();
        // }

        public static void InitializeModLoader()
        {
            ModLogger.Init(GetLoaderRootFolder() + "\\Output.log");

            ModLogger.Log("Good Company Mod Loader initialized!");

            Harmony  harmony  = new Harmony("com.github.seppahbaws.gcmodloader");
            Assembly assembly = Assembly.GetExecutingAssembly();

            harmony.PatchAll(assembly);
            // harmony.PatchAll();

            ModLogger.LogInfo($"Patched {harmony.GetPatchedMethods().ToArray().Length} methods.");

            foreach (var method in harmony.GetPatchedMethods())
            {
                ModLogger.Log($"Patched method: {method}");
            }

            ModLogger.LogInfo("All mods loaded");

            // Harmony harmony = new Harmony("com.github.seppahbaws.gcmodloader");
            // Assembly assembly = Assembly.LoadFile("E:\\SSDLibrary\\steamapps\\common\\Good Company\\BepInEx\\plugins\\GoodCompanyTestMod.dll");
            // ModLogger.Log($"Mod name: {assembly.FullName}");
            // harmony.PatchAll(assembly);

            LogLoadedAssemblies();

            // ModLogger.Log($"DOORSTOP_PROCESS_PATH = {Environment.GetEnvironmentVariable("DOORSTOP_PROCESS_PATH")}");

            ModLogger.LogInfo($"mod loader rood folder: \"{GetLoaderRootFolder()}\"");
            ModLogger.LogInfo($"mods folder: \"{GetModsFolder()}\"");

            LoadMods(harmony);
        }
Пример #3
0
 public virtual void OnEnabled()
 {
     // patch main class
     Harmony.PatchAll(this.GetType());
     // patch nested types
     foreach (var type in this.GetType().GetNestedTypes())
     {
         Harmony.PatchAll(type);
     }
     Log($"Enabled {Name}, patched methods: {Harmony.GetPatchedMethods().Count()}");
 }
Пример #4
0
        private void Awake()
        {
            WorkshopImprovementsConfig.Bind(this);

            _harmony.PatchAll();
            var patchedMethods = _harmony.GetPatchedMethods();
        }
Пример #5
0
        public Core(ModContentPack content) : base(content)
        {
            Log("Hello, world!");
            Instance    = this;
            ContentPack = content;

            // Apply harmony patches.
            var harmony = new Harmony("co.uk.epicguru.disco");

            try
            {
                harmony.PatchAll();
            }
            catch (Exception e)
            {
                Error("Failed to apply 1 or more harmony patches! Mod will not work as intended. Contact author.", e);
            }
            finally
            {
                Log(
                    $"Patched {harmony.GetPatchedMethods().EnumerableCount()} methods:\n{string.Join(",\n", harmony.GetPatchedMethods())}");
            }

            // Create MonoBehaviour hook.
            var go = new GameObject("Disco! hook");

            go.AddComponent <UnityHook>();
            Log("Created Unity hook game object.");
        }
Пример #6
0
    public void Init(object gameInstance)
    {
        var harmony = new Harmony("ClipboardFixPlugin");

        harmony.PatchAll();
        harmony.GetPatchedMethods().Do(_ => {});
    }
Пример #7
0
        public static void InspectPatches(Harmony harmony)
        {
            try
            {
                LogMessage("Existing patches:");

                IEnumerable <MethodBase> myOriginalMethods = harmony.GetPatchedMethods();
                foreach (MethodBase method in myOriginalMethods)
                {
                    Patches patches = Harmony.GetPatchInfo(method);
                    if (patches != null)
                    {
                        foreach (var patch in patches.Prefixes)
                        {
                            // already patched
                            LogMessage("index: " + patch.index);
                            LogMessage("owner: " + patch.owner);
                            LogMessage("patch method: " + patch.PatchMethod);
                            LogMessage("priority: " + patch.priority);
                            LogMessage("before: " + patch.before.Join());
                            LogMessage("after: " + patch.after.Join());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogMessage("Patches inspection failed.");
                LogMessage(string.Format("Exception: {0}", e));
            }
        }
Пример #8
0
        public override void Load()
        {
            var log = new LogBuffer();

            log.Write($"{ModName} loading.");

            if (UseHarmony)
            {
                var harmony = new Harmony(GUID.Create().ToString());
                harmony.PatchAll(GetType().Assembly);

                var i = 0;
                foreach (var patchedMethod in harmony.GetPatchedMethods())
                {
                    log.Write($"\r\nPatched: {patchedMethod.DeclaringType?.FullName}:{patchedMethod}");
                    i++;
                }
                log.Write($"\r\nPatched {i} methods.");
            }

            Init();

            log.Write($"\r\n{ModName} loaded.");
            log.Flush();
        }
Пример #9
0
        public static bool ReportCompatibilityIssues(Harmony harmonyInstance, string sectionName)
        {
            IEnumerable <MethodBase> myOriginalMethods = harmonyInstance.GetPatchedMethods();

            HarmonyLib.Patches patches;
            bool          Result = false;
            StringBuilder PossibleConflictsInfo = new StringBuilder("");

            foreach (MethodBase MyMethod in myOriginalMethods)
            {
                // get info about all Patches on OriginalMethod
                patches = Harmony.GetPatchInfo(MyMethod);
                if (patches.CheckForCompetition(harmonyInstance, out string DebugInfo, Settings.Instance.HarmonyCheckupIgnoreList.ToReadOnlyCollection()))
                {
                    Result = true;
                    if (PossibleConflictsInfo.Length <= 0)
                    {
                        PossibleConflictsInfo.Append($"[{DateTime.Now:dd.MM.yyyy HH:mm:ss}] - {sectionName}.\nForeign patches checkup for method {MyMethod.DeclaringType.FullName}.{MyMethod.Name}, used by AllegianceOverhaul, revealed possible conflicts!{DebugInfo}");
                    }
                    else
                    {
                        PossibleConflictsInfo.Append($"\nPatches checkup for method {MyMethod.DeclaringType.FullName}.{MyMethod.Name}, used by AllegianceOverhaul, revealed possible conflicts!{DebugInfo}");
                    }
                }
            }
            if (Result)
            {
                LoggingHelper.Log(PossibleConflictsInfo.ToString());
            }
            return(Result);
        }
Пример #10
0
 public static void LogPatchedMethods(this Harmony harmony)
 {
     foreach (var method in harmony.GetPatchedMethods())
     {
         Log.Info($"harmony({harmony.Id}) patched: {method.DeclaringType.FullName}::{method.Name}", true);
     }
 }
Пример #11
0
 /// <summary>
 /// Produces a human-readable list of all methods patched by a single Harmony instance and their respective patches.
 /// </summary>
 /// <param name="instance">A Harmony instance that can be queried for patch information.</param>
 public static string DescribePatchedMethods(Harmony instance)
 {
     try {
         return(DescribePatchedMethodsList(instance.GetPatchedMethods()));
     } catch (Exception e) {
         return($"Could not retrieve patched methods from Harmony instance (id: {instance.Id}):\n{e}");
     }
 }
 public static void Execute()
 {
     Debug.Log("Creating harmony instance");
     Harmony.DEBUG   = true;
     HarmonyInstance = new Harmony("com.planetbase.multiplayermod.harmony");
     Debug.Log("Patching game!");
     HarmonyInstance.PatchAll();
     Debug.Log($"Installed {HarmonyInstance.GetPatchedMethods().Count()} patches!");
 }
Пример #13
0
        public InfestationBaitMod(ModContentPack content) : base(content)
        {
            Harmony harmonyInstance = new Harmony("NavySeal5.InfestationBait");

            harmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
            var methods = harmonyInstance.GetPatchedMethods();

            this.settings = this.GetSettings <InfestationBaitSettings>();
        }
Пример #14
0
        protected override void OnSubModuleLoad()
        {
            base.OnSubModuleLoad();
            Harmony harmony = new Harmony("fun.wangyanan.patch.use.sourcehanserifc.fonts");

            if (harmony.GetPatchedMethods().IsEmpty())
            {
                new Harmony("fun.wangyanan.patch.use.sourcehanserifc.fonts").PatchAll();
            }
        }
Пример #15
0
        public override void StartClientSide(ICoreClientAPI api)
        {
            harmonyInstance.PatchAll();
            StringBuilder builder = new StringBuilder("Harmony Patched Methods: ");

            foreach (var val in harmonyInstance.GetPatchedMethods())
            {
                builder.Append(val.Name + ", ");
            }
            api.Logger.Notification(builder.ToString());
        }
Пример #16
0
        protected override void OnSubModuleLoad()
        {
            base.OnSubModuleLoad();
#if DEBUG
            Harmony.DEBUG = true;
#endif
            Harmony harmony = new Harmony("com.ukie.formations-fix");

            harmony.PatchAll(typeof(SubModule).Assembly);
            var originalMethods = harmony.GetPatchedMethods();
        }
Пример #17
0
        protected override void OnSubModuleLoad()
        {
            base.OnSubModuleLoad();
            Harmony harmony = new Harmony("fun.wangyanan.patch.custom.chinese.fonts");

            if (harmony.GetPatchedMethods().IsEmpty())
            {
                new Harmony("fun.wangyanan.patch.custom.chinese.fonts").PatchAll();
                enableFont();
            }
        }
Пример #18
0
        public void Disable(UnityModManager.ModEntry modEntry, bool unpatch = false)
        {
            _logger = modEntry.Logger;

            using (ProcessLogger process = new ProcessLogger(_logger))
            {
                process.Log("Disabling.");

                Enabled = false;

                // use try-catch to prevent the progression being disrupt by exceptions
                if (_eventHandlers != null)
                {
                    process.Log("Raising events: OnDisable()");
                    for (int i = _eventHandlers.Count - 1; i >= 0; i--)
                    {
                        try { _eventHandlers[i].HandleModDisable(); }
                        catch (Exception e) { Error(e); }
                    }
                    _eventHandlers = null;
                }

                if (unpatch)
                {
                    Harmony harmonyInstance = new Harmony(modEntry.Info.Id);
                    foreach (MethodBase method in harmonyInstance.GetPatchedMethods().ToList())
                    {
                        Patches             patchInfo = Harmony.GetPatchInfo(method);
                        IEnumerable <Patch> patches   =
                            patchInfo.Transpilers.Concat(patchInfo.Postfixes).Concat(patchInfo.Prefixes)
                            .Where(patch => patch.owner == modEntry.Info.Id);
                        if (patches.Any())
                        {
                            process.Log($"Unpatching: {patches.First().PatchMethod.DeclaringType.FullName} from {method.DeclaringType.FullName}.{method.Name}");
                            foreach (Patch patch in patches)
                            {
                                try { harmonyInstance.Unpatch(method, patch.PatchMethod); }
                                catch (Exception e) { Error(e); }
                            }
                        }
                    }
                    Patched = false;
                }

                modEntry.OnSaveGUI -= HandleSaveGUI;
                Core     = null;
                Settings = null;
                Version  = null;
                _logger  = null;

                process.Log("Disabled.");
            }
        }
Пример #19
0
        static Main()
        {
            var harmony = new Harmony("com.ogliss.rimworld.mod.AdeptusMechanicus.Kroot");

            harmony.PatchAll(Assembly.GetExecutingAssembly());
            int patches = harmony.GetPatchedMethods().Select(new Func <MethodBase, Patches>(Harmony.GetPatchInfo)).SelectMany((Patches p) => p.Prefixes.Concat(p.Postfixes).Concat(p.Transpilers)).Count((Patch p) => p.owner.Contains(harmony.Id));

            if (Prefs.DevMode)
            {
                Log.Message(string.Format("Adeptus Xenobiologis: Kroot: successfully completed {0} harmony patches.", patches), false);
            }
        }
Пример #20
0
        static Dyspareunia()
        {
            Log("Dyspareunia is starting.");
            harmony = new Harmony("nuttysquabble.dyspareunia");

            harmony.Patch(typeof(SexUtility).GetMethod("Aftersex", new Type[] { typeof(Pawn), typeof(Pawn), typeof(bool), typeof(bool), typeof(bool), typeof(xxx.rjwSextype) }), prefix: new HarmonyMethod(typeof(Dyspareunia).GetMethod("SexUtility_Prefix")));
            harmony.Patch(typeof(Hediff_PartBaseNatural).GetMethod("Tick"), postfix: new HarmonyMethod(typeof(Dyspareunia).GetMethod("PartBase_Tick_Postfix")));
            harmony.Patch(typeof(Hediff_PartBaseArtifical).GetMethod("Tick"), postfix: new HarmonyMethod(typeof(Dyspareunia).GetMethod("PartBase_Tick_Postfix")));
            harmony.Patch(typeof(Hediff_BasePregnancy).GetMethod("PostBirth"), postfix: new HarmonyMethod(typeof(Dyspareunia).GetMethod("Hediff_BasePregnancy_Patch")));

            Log("Dyspareunia initialization is complete. " + harmony.GetPatchedMethods().EnumerableCount() + " patches applied.");
        }
Пример #21
0
        private void PatchGame()
        {
            Mod.Logger.Event("Loading harmony for patching...");
            _harmony = new Harmony("com.xxmicloxx.vsvolumetricshading");
            _harmony.PatchAll();

            var myOriginalMethods = _harmony.GetPatchedMethods();

            foreach (var method in myOriginalMethods)
            {
                Mod.Logger.Event("Patched " + method.FullDescription());
            }
        }
Пример #22
0
        private void Awake()
        {
            // Plugin startup logic
            logger = Logger;
            Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
            var harmony = new Harmony(PluginInfo.PLUGIN_GUID);

            harmony.PatchAll();
            foreach (var method in harmony.GetPatchedMethods())
            {
                Logger.LogInfo($"Patched method {method.Name}");
            }
        }
Пример #23
0
        public Core(ModContentPack content) : base(content)
        {
            Log("Hello, world!");
            Instance    = this;
            ContentPack = content;

            // Apply harmony patches.
            HarmonyInstance = new Harmony("co.uk.epicguru.rimforge");
            try
            {
                HarmonyInstance.PatchAll();
            }
            catch (Exception e)
            {
                Error("Failed to apply 1 or more harmony patches! Mod will not work as intended. Contact author.", e);
            }
            finally
            {
                Log($"Patched {HarmonyInstance.GetPatchedMethods().EnumerableCount()} methods:\n{string.Join(",\n", HarmonyInstance.GetPatchedMethods())}");
            }

            // Create MonoBehaviour hook.
            var go = new GameObject("RimForge hook");

            go.AddComponent <UnityHook>();

            // When the game closes, shut down this particle processing thread.
            UnityHook.UponApplicationQuit += () =>
            {
                MapEffectHandler.ThreadedHandler?.Stop();
            };

            if (CECompat.IsCEActive)
            {
                Log("Combat Extended detected! Running in Combat Extended mode.");
            }

            // Blessing skill def, used to make recipes that only blessed pawns can do.
            BlessingSkillDef = new SkillDef()
            {
                defName        = "RF_BlessingSkill_RuntimeGenerated",
                label          = "Blessing of Zir (trait)",
                skillLabel     = "Blessing of Zir (trait)",
                description    = "Requirement: pawn must have the Blessing of Zir trait.",
                modContentPack = Content,
                usuallyDefinedInBackstories = false,
                pawnCreatorSummaryVisible   = false
            };

            LongEventHandler.QueueLongEvent(StartupLoading.DoLoadLate, "RF.LoadLabel", false, null);
        }
Пример #24
0
        public void Awake()
        {
            Logger = base.Logger;
            Settings.InitConfig(Config);
            harmony.PatchAll(Assembly.GetExecutingAssembly());
            int patchedMethods = 0;

            foreach (MethodBase method in harmony.GetPatchedMethods())
            {
                Logger.LogInfo("Patched " + method.DeclaringType.Name + "." + method.Name);
                patchedMethods++;
            }
            Logger.LogInfo(patchedMethods + " patches applied\n");
        }
Пример #25
0
 protected override void OnGameStart(Game game, IGameStarter gameStarterObject)
 {
     if (game.GameType is Campaign)
     {
         //The current game is a campaign
         CampaignGameStarter campaignStarter = (CampaignGameStarter)gameStarterObject;
         campaignStarter.AddBehavior(new CustomSaveBehavior());
         Harmony harmony = new Harmony("fun.wangyanan.patch.villagerate");
         if (harmony.GetPatchedMethods().IsEmpty())
         {
             new Harmony("fun.wangyanan.patch.villagerate").PatchAll();
         }
     }
 }
Пример #26
0
        public static void DevLog(this ManualLogSource log, Harmony harmony)
        {
            foreach (MethodBase method in harmony.GetPatchedMethods())
            {
                Patches patches = Harmony.GetPatchInfo(method);
                log.DevLog(string.Format("{0}::{1} patchers:", method.DeclaringType.FullName, method.Name));

                log.DevLog(string.Join(" ", patches.Owners.ToArray()));
                LogPatchSegment(log, method, patches.Prefixes, "Prefixes:");
                LogPatchSegment(log, method, patches.Transpilers, "Transpilers:");
                LogPatchSegment(log, method, patches.Postfixes, "Postfixes:");
                LogPatchSegment(log, method, patches.Finalizers, "Postfixes:");
            }
        }
Пример #27
0
        public void CheckDetour()
        {
            if (isFirstTime && Loader.HarmonyDetourInited)
            {
                isFirstTime = false;
                DebugLog.LogToFileOnly("ThreadingExtension.OnBeforeSimulationFrame: First frame detected. Checking detours.");
                //Caculate goverment salary
                RealCityEconomyExtension.CaculateGovermentSalary();
                //reset playereducation fee
                RealCityEconomyExtension.RefreshPlayerEducationFee();

                if (Loader.HarmonyDetourFailed)
                {
                    string error = "RealCity HarmonyDetourInit is failed, Send RealCity.txt to Author.";
                    DebugLog.LogToFileOnly(error);
                    UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", error, true);
                }
                else
                {
                    var harmony = new Harmony(HarmonyDetours.Id);
                    var methods = harmony.GetPatchedMethods();
                    int i       = 0;
                    foreach (var method in methods)
                    {
                        var info = Harmony.GetPatchInfo(method);
                        if (info.Owners?.Contains(HarmonyDetours.Id) == true)
                        {
                            DebugLog.LogToFileOnly($"Harmony patch method = {method.FullDescription()}");
                            if (info.Prefixes.Count != 0)
                            {
                                DebugLog.LogToFileOnly("Harmony patch method has PreFix");
                            }
                            if (info.Postfixes.Count != 0)
                            {
                                DebugLog.LogToFileOnly("Harmony patch method has PostFix");
                            }
                            i++;
                        }
                    }

                    if (i != HarmonyPatchNum)
                    {
                        string error = $"RealCity HarmonyDetour Patch Num is {i}, Right Num is {HarmonyPatchNum} Send RealCity.txt to Author.";
                        DebugLog.LogToFileOnly(error);
                        UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", error, true);
                    }
                }
            }
        }
Пример #28
0
        public override void StartPre(ICoreAPI api)
        {
            // string path = "C:/Users/dark/Desktop/harmony.log.txt";
            // if (File.Exists(path)) File.Delete(path);
            // Harmony.DEBUG = true;

            harmonyInstance = new Harmony(Mod.Info.ModID);
            harmonyInstance.PatchAll();

            api.Logger.Notification("[" + Mod.Info.ModID + "] Harmony Patched Methods: ");
            foreach (var val in harmonyInstance.GetPatchedMethods())
            {
                api.Logger.Notification("[" + Mod.Info.ModID + "]         " + val.DeclaringType + "." + val.Name);
            }
        }
Пример #29
0
        private void Awake()
        {
            Func <List <ItemData> > playerItemsLookup = () => Player.m_localPlayer?.GetInventory()?.GetAllItems() ?? new List <ItemData>();

            PackageableItemsMenuManager   = new RotatingMenuManager <ItemData>(playerItemsLookup, i => i.IsPackageable(), i => Localization.instance.Localize(i.m_shared.m_name));
            UnPackageableItemsMenuManager = new RotatingMenuManager <ItemData>(playerItemsLookup, i => i.IsUnpackageable(), i => i.m_shared.m_name);

            ShippableMetalBarsConfig.Bind(this);

            ExtendedItemData.NewExtendedItemData  += ShippableItemData.OnNewExtendedItemData;
            ExtendedItemData.LoadExtendedItemData += ShippableItemData.OnLoadExtendedItemData;

            _harmony.PatchAll();
            var patchedMethods = _harmony.GetPatchedMethods();
        }
Пример #30
0
            static Main()
            {
                //LongEventHandler.ExecuteWhenFinished(() => {
                var harmony = new Harmony("EdB.PrepareCarefully");

                harmony.PatchAll(Assembly.GetExecutingAssembly());

                HashSet <ValueTuple <Type, String> > patchedMethods = new HashSet <ValueTuple <Type, string> >();

                foreach (var m in harmony.GetPatchedMethods())
                {
                    patchedMethods.Add((m.DeclaringType, m.Name));
                }
                if (patchedMethods.Count != 3 ||
                    !patchedMethods.Contains((typeof(Page_ConfigureStartingPawns), "PreOpen")) ||
                    !patchedMethods.Contains((typeof(Page_ConfigureStartingPawns), "DoWindowContents")) ||
                    !patchedMethods.Contains((typeof(Verse.Game), "InitNewGame"))
                    )
                {
                    String methodsMessage = String.Join(", ", harmony.GetPatchedMethods().Select(i => i.DeclaringType + "." + i.Name));
                    Log.Warning("[Prepare Carefully] Did not patch all of the expected methods.  The following patched methods were found: "
                                + (!methodsMessage.NullOrEmpty() ? methodsMessage : "none"));
                }
            }