public VFESecurityCE(ModContentPack content) : base(content)
 {
     harmonyInstance = new Harmony("Andross.VFESecurityCE");
 }
        static ReplacementCode()
        {
            Harmony harmony = new Harmony(id: "rimworld.erdelf.prisoner_ransom");

            harmony.Patch(original: typeof(FactionDialogMaker).GetMethod(name: "FactionDialogFor"), prefix: null, postfix: new HarmonyMethod(typeof(ReplacementCode), nameof(FactionDialogForPostFix)));
        }
示例#3
0
 public override void Patch(Harmony harmony)
 {
     PatchPostfix(harmony, TARGET_METHOD);
 }
示例#4
0
        private void Awake()
        {
            var harmony = new Harmony("com.shinyshoe.restartbattle");

            harmony.PatchAll();
        }
示例#5
0
 public static void Apply()
 {
     Harmony.CreateAndPatchAll(typeof(Hooks));
 }
示例#6
0
 private static void EnableHarmonyPatches()
 {
     _harmonyInstance = new Harmony(ModGuid);
     _harmonyInstance.PatchAll();
 }
示例#7
0
 public ZLevelsMod(ModContentPack pack) : base(pack)
 {
     settings = GetSettings <ZLevelsSettings>();
     harmony  = new Harmony("ZLevels.Mod");
     harmony.PatchAll();
 }
        // Use this to prepare some "dynamic functions" we will use
        //   (for faster performance, b/c apparently the reflection
        //   is sloooooow.  From what i hear.)
        static bool Prepare(Harmony instance)
        {
            if (ModLister.GetActiveModWithIdentifier("netrve.dsgui") != null)
            {
                return(false);
            }

            /* Build a dynamic method to do:
             * void RePosition(Thing t, IntVec3 pos) {
             *   t.positionInt=pos;  // directly set internal private field
             * }
             *
             * Use this approach for speed.
             */
            DynamicMethod dm = new DynamicMethod("directly set thing's positionInt",
                                                 null, // return type void
                                                 new Type[] { typeof(Thing), typeof(IntVec3) },
                                                 true  // skip JIT visibility checks - which is whole point
                                                       //   we want to access a private field!
                                                 );
            ILGenerator il = dm.GetILGenerator();

            // build our function from IL.  Because why not
            il.Emit(OpCodes.Ldarg_0); //put Thing on stack
            il.Emit(OpCodes.Ldarg_1); //put position on stack
            // store field:
            il.Emit(OpCodes.Stfld, typeof(Thing).GetField("positionInt",
                                                          BindingFlags.Instance |
                                                          BindingFlags.GetField |
                                                          BindingFlags.SetField |
                                                          BindingFlags.NonPublic));
            il.Emit(OpCodes.Ret); //don't forget
            // Create the delegate that completes the dynamic method:
            //   (I'm just quoting the MSIL documentation, I don't
            //    actually know what I'm doing)
            SetPosition = (Action <Thing, IntVec3>)dm.CreateDelegate(typeof(Action <,>).MakeGenericType(typeof(Thing), typeof(IntVec3)));
            /*****     Now do the same for AHlO - call the private method directly     *****/
            dm = new DynamicMethod("directly call AddHumanlikeOrders",
                                   null, // return type void
                                   new Type[] { typeof(Vector3), typeof(Pawn), typeof(List <FloatMenuOption>) },
                                   true  // skip JIT visibility checks
                                   );
            il = dm.GetILGenerator();
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldarg_1);
            il.Emit(OpCodes.Ldarg_2);
            il.Emit(OpCodes.Call, typeof(FloatMenuMakerMap).GetMethod("AddHumanlikeOrders",
                                                                      BindingFlags.Static | BindingFlags.NonPublic));
            il.Emit(OpCodes.Ret);
            AHlO = (Action <Vector3, Pawn, List <FloatMenuOption> >)dm
                   .CreateDelegate(typeof(Action <, ,>).MakeGenericType(typeof(Vector3), typeof(Pawn), typeof(List <FloatMenuOption>)));

            return(true);

            Utils.Warn(RightClickMenu, "Loading AddHumanlikeOrders menu code: "
                       + Settings.useDeepStorageRightClickLogic);



            return(Settings.useDeepStorageRightClickLogic);
        }
示例#9
0
 private void Awake()
 {
     harmony = new Harmony($"{GUID}.harmony");
     HarmonyWrapper.PatchAll(typeof(Hooks), harmony);
 }
示例#10
0
 internal static void Unpatch(Harmony harmony)
 {
     harmony.Unpatch(_original, _transpile);
 }
示例#11
0
        static Main()
        {
            var harmony = new Harmony("com.alphabiomes");

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }
示例#12
0
 internal static void Patch(Harmony harmony)
 {
     harmony.Patch(_original, null, null, new HarmonyMethod(_transpile));
 }
示例#13
0
        static HarmonyInstance()
        {
            var harmony = new Harmony("com.ogliss.rimworld.mod.OgsLasers");

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }
示例#14
0
        static HarmonyPatches()
        {
            var harmony = new Harmony("com.zilla.pauseonresearch");

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }
示例#15
0
    public void Awake()
    {
        Instance = this;

        MainThreadQueue.Initialize();

        GameInfo            = GetComponent <KMGameInfo>();
        SettingWarning      = gameObject.Traverse("UI", "SettingWarning");
        AdvantageousWarning = gameObject.Traverse("UI", "AdvantageousWarning");
        Tips.TipMessage     = gameObject.Traverse("UI", "TipMessage");
        BetterCasePicker.BombCaseGenerator = GetComponentInChildren <BombCaseGenerator>();
        DemandBasedLoading.LoadingScreen   = gameObject.Traverse <CanvasGroup>("UI", "LoadingModules");

        CaseGeneratorWarning = MakeSettingWarning("CaseGenerator");
        DBMLWarning          = MakeSettingWarning("DemandBasedModLoading");
        HoldablesWarning     = MakeSettingWarning("Holdables");

        modConfig = new ModConfig <TweakSettings>("TweakSettings", OnReadError);
        UpdateSettings();
        StartCoroutine(Modes.LoadDefaultSettings());

        if (!Harmony.HasAnyPatches("qkrisi.harmonymod"))
        {
            HarmonyPatchInfo.HarmonyTexture = GetComponent <TweaksStorage>().HarmonyTexture;
            Patching.EnsurePatch("Harmony", typeof(ModInfoPatch), typeof(WorkshopPatch), typeof(ReloadPatch), typeof(ContinueButtonPatch),
                                 typeof(ManualButtonPatch), typeof(InstructionPatch), typeof(ModManagerPatch), typeof(ChangeButtonText));
        }

        DemandBasedLoading.EverLoadedModules = !settings.DemandBasedModLoading;
        DemandBasedSettingCache = settings.DemandBasedModLoading;

        HoldablesSettingCache = settings.Holdables;

        bool changeFadeTime = settings.FadeTime >= 0;

        FreeplayDevice.MAX_SECONDS_TO_SOLVE = float.MaxValue;
        FreeplayDevice.MIN_MODULE_COUNT     = 1;

        // Force the graphics quality to "Mod Quality", otherwise features might not render correctly.
        QualitySettings.SetQualityLevel(2);
        AbstractPlatformUtil.Instance.OriginalQualityLevel = 2;

        if (settings.EnableModsOnlyKey)
        {
            var lastFreeplaySettings = FreeplaySettings.CreateDefaultFreeplaySettings();
            lastFreeplaySettings.OnlyMods = true;
            ProgressionManager.Instance.RecordLastFreeplaySettings(lastFreeplaySettings);
        }

        UpdateSettingWarnings();
        AdvantageousWarning.SetActive(false);

        // Setup API/properties other mods to interact with
        GameObject infoObject = new GameObject("Tweaks_Info", typeof(TweaksProperties));

        infoObject.transform.parent = gameObject.transform;

        TweaksAPI.Setup();

        // Watch the TweakSettings file for Time Mode state being changed in the office.
        FileSystemWatcher watcher = new FileSystemWatcher(Path.Combine(Application.persistentDataPath, "Modsettings"), "TweakSettings.json")
        {
            NotifyFilter = NotifyFilters.LastWrite
        };

        watcher.Changed += (object source, FileSystemEventArgs e) =>
        {
            if (ModConfig <TweakSettings> .SerializeSettings(userSettings) == ModConfig <TweakSettings> .SerializeSettings(modConfig.Read()))
            {
                return;
            }

            UpdateSettings();
            UpdateSettingWarnings();

            MainThreadQueue.Enqueue(() => StartCoroutine(ModifyFreeplayDevice(false)));
        };

        // Setup the leaderboard controller to block the leaderboard submission requests.
        LeaderboardController.Install();

        GetTweaks();

        // Create a fake case with a bunch of anchors to trick the game when using CaseGenerator.
        TweaksCaseGeneratorCase = new GameObject("TweaksCaseGenerator");
        TweaksCaseGeneratorCase.transform.SetParent(transform);
        var kmBomb = TweaksCaseGeneratorCase.AddComponent <KMBomb>();

        kmBomb.IsHoldable      = false;
        kmBomb.WidgetAreas     = new List <GameObject>();
        kmBomb.visualTransform = transform;
        kmBomb.Faces           = new List <KMBombFace>();

        TweaksCaseGeneratorCase.AddComponent <ModBomb>();

        var kmBombFace = TweaksCaseGeneratorCase.AddComponent <KMBombFace>();

        kmBombFace.Anchors = new List <Transform>();
        kmBomb.Faces.Add(kmBombFace);

        for (int i = 0; i <= 9001; i++)
        {
            kmBombFace.Anchors.Add(transform);
        }

        // Handle scene changes
        UnityEngine.SceneManagement.SceneManager.sceneLoaded += (Scene scene, LoadSceneMode _) =>
        {
            UpdateSettings();
            UpdateSettingWarnings();

            Modes.settings = Modes.modConfig.Read();
            Modes.modConfig.Write(Modes.settings);

            if ((scene.name == "mainScene" || scene.name == "gameplayScene") && changeFadeTime)
            {
                SceneManager.Instance.RapidFadeInTime = settings.FadeTime;
            }

            switch (scene.name)
            {
            case "mainScene":
                if (changeFadeTime)
                {
                    SceneManager.Instance.SetupState.FadeInTime          =
                        SceneManager.Instance.SetupState.FadeOutTime     =
                            SceneManager.Instance.UnlockState.FadeInTime = settings.FadeTime;
                }

                break;

            case "gameplayLoadingScene":
                var gameplayLoadingManager = FindObjectOfType <GameplayLoadingManager>();
                if (settings.InstantSkip)
                {
                    gameplayLoadingManager.MinTotalLoadTime = 0;
                }
                if (changeFadeTime)
                {
                    gameplayLoadingManager.FadeInTime      =
                        gameplayLoadingManager.FadeOutTime = settings.FadeTime;
                }

                ReflectedTypes.UpdateTypes();

                ReflectedTypes.CurrencyAPIEndpointField?.SetValue(null, settings.FixFER ? "https://api.ratesapi.io/api" : "http://api.fixer.io");

                if (
                    AdvantageousFeaturesEnabled &&
                    GameplayState.MissionToLoad != Assets.Scripts.Missions.FreeplayMissionGenerator.FREEPLAY_MISSION_ID &&
                    GameplayState.MissionToLoad != ModMission.CUSTOM_MISSION_ID
                    )
                {
                    StartCoroutine(ShowAdvantageousWarning());
                }

                break;

            case "gameplayScene":
                if (changeFadeTime)
                {
                    SceneManager.Instance.GameplayState.FadeInTime      =
                        SceneManager.Instance.GameplayState.FadeOutTime = settings.FadeTime;
                }

                break;
            }
        };

        // Handle state changes
        GameInfo.OnStateChange += (KMGameInfo.State state) =>
        {
            OnStateChanged(CurrentState, state);

            // Transitioning away from another state
            if (state == KMGameInfo.State.Transitioning)
            {
                if (CurrentState == KMGameInfo.State.Setup)
                {
                    DemandBasedLoading.DisabledModsCount = 0;
                }

                if (CurrentState != KMGameInfo.State.Gameplay)
                {
                    DemandBasedLoading.HandleTransitioning();
                }
            }

            CurrentState = state;
            watcher.EnableRaisingEvents = state == KMGameInfo.State.Setup;

            if (state == KMGameInfo.State.Gameplay)
            {
                if (AdvantageousFeaturesEnabled)
                {
                    LeaderboardController.DisableLeaderboards();
                }

                TwitchPlaysActiveCache = TwitchPlaysActive;
                CurrentModeCache       = CurrentMode;

                BombStatus.Instance.widgetsActivated = false;
                BombStatus.Instance.HUD.SetActive(settings.BombHUD);
                BombStatus.Instance.ConfidencePrefab.gameObject.SetActive(CurrentMode != Mode.Zen);
                BombStatus.Instance.StrikesPrefab.color = CurrentMode == Mode.Time ? Color.yellow : Color.red;

                Modes.Multiplier = Modes.settings.TimeModeStartingMultiplier;
                BombStatus.Instance.UpdateMultiplier();
                bombWrappers.Clear();
                StartCoroutine(CheckForBombs());

                if (GameplayState.BombSeedToUse == -1)
                {
                    GameplayState.BombSeedToUse = settings.MissionSeed;
                }
            }
            else if (state == KMGameInfo.State.Setup)
            {
                ReloadPatch.ResetDict();
                if (ReflectedTypes.LoadedModsField.GetValue(ModManager.Instance) is Dictionary <string, Mod> loadedMods)
                {
                    Mod tweaksMod = loadedMods.Values.FirstOrDefault(mod => mod.ModID == "Tweaks");
                    if (tweaksMod != null && CaseGeneratorSettingCache != settings.CaseGenerator)
                    {
                        if (settings.CaseGenerator)
                        {
                            tweaksMod.ModObjects.Add(TweaksCaseGeneratorCase);
                        }
                        else
                        {
                            tweaksMod.ModObjects.Remove(TweaksCaseGeneratorCase);
                        }

                        CaseGeneratorSettingCache = settings.CaseGenerator;
                    }
                }

                StartCoroutine(Tips.ShowTip());
                StartCoroutine(ModifyFreeplayDevice(true));
                StartCoroutine(ModifyHoldables());
                GetComponentInChildren <ModSelectorExtension>().FindAPI();
                TweaksAPI.SetTPProperties(!TwitchPlaysActive);

                GameplayState.BombSeedToUse = -1;

                UpdateSettingWarnings();

                UpdateBombCreator();
            }
            else if (state == KMGameInfo.State.Transitioning)
            {
                // Because the settings are checked on a scene change and there is no scene change from exiting the gameplay room,
                // we need to update the settings here in case the user changed their HideTOC settings.
                UpdateSettings();

                bool modified       = false;
                var  ModMissionToCs = ModManager.Instance.ModMissionToCs;
                foreach (var metaData in ModMissionToCs)
                {
                    modified |= ModToCMetaData.Add(metaData);
                }

                var unloadedMods = (Dictionary <string, Mod>)ReflectedTypes.UnloadedModsField.GetValue(ModManager.Instance);
                if (unloadedMods != null)
                {
                    foreach (var unloadedMod in unloadedMods.Values)
                    {
                        var tocs = (List <ModTableOfContentsMetaData>)ReflectedTypes.TocsField.GetValue(unloadedMod);
                        if (tocs != null)
                        {
                            foreach (var metaData in tocs)
                            {
                                modified |= ModToCMetaData.Remove(metaData);
                            }
                        }
                    }
                }

                var newToCs = ModToCMetaData.Where(metaData => !settings.HideTOC.Any(pattern => Localization.GetLocalizedString(metaData.DisplayNameTerm).Like(pattern)));
                modified |= newToCs.Count() != ModMissionToCs.Count || !newToCs.All(ModMissionToCs.Contains);
                ModMissionToCs.Clear();
                ModMissionToCs.AddRange(newToCs);

                if (modified)
                {
                    SetupState.LastBombBinderTOCIndex = 0;
                    SetupState.LastBombBinderTOCPage  = 0;
                }
            }
        };
    }
示例#16
0
 public override void PostInitialize(Harmony plibInstance)
 {
     InvokeAllProcess(RunAt.AfterModsLoad, null);
 }
示例#17
0
 public void Awake()
 {
     Logger = base.Logger;
     Extension.Logger.logger = Logger;
     Harmony.CreateAndPatchAll(typeof(Patches));
 }
示例#18
0
 public static void InitHooks(Harmony hi)
 {
     hi.PatchAll(typeof(ShortcutKeyHooks));
 }
示例#19
0
 void Awake()
 {
     Harmony.CreateAndPatchAll(typeof(DeathAnnouncerValheimClientMod));
 }
        private void Awake()
        {
            for (int maleNum = 0; maleNum < _danColliderHeadLength.Length; maleNum++)
            {
                (_fingerColliderLength[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Finger Collider: Length", 0.6f, "Lenght of the finger colliders.")).SettingChanged += (s, e) =>
                { UpdateFingerColliders(); };
                (_fingerColliderRadius[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Finger Collider: Radius", 0.2f, "Radius of the finger colliders.")).SettingChanged += (s, e) =>
                { UpdateFingerColliders(); };
                (_danColliderHeadLength[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Penis Collider: Length of Head", 0.35f, "Distance from the center of the head bone to the tip, used for collision purposes.")).SettingChanged += (s, e) =>
                { UpdateDanColliders(); };
                (_danColliderRadius[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Penis Collider: Radius of Shaft", 0.32f, "Radius of the shaft collider.")).SettingChanged += (s, e) =>
                { UpdateDanColliders(); };
                (_danColliderVerticalCenter[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Penis Collider: Vertical Center", -0.03f, "Vertical Center of the shaft collider")).SettingChanged += (s, e) =>
                { UpdateDanColliders(); };
                (_danLengthSquishFactor[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Penis: Squish Length Factor", 0.6f, new ConfigDescription("How much the length of the penis squishes after it has passed the squish threshold", new AcceptableValueRange <float>(0, 1)))).SettingChanged += (s, e) =>
                { UpdateDanOptions(); };
                (_danGirthSquishFactor[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Penis: Squish Girth Factor", 0.4f, new ConfigDescription("How much the girth of the penis squishes after it has passed the squish threshold", new AcceptableValueRange <float>(0, 1)))).SettingChanged += (s, e) =>
                { UpdateDanOptions(); };
                (_danSquishThreshold[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Penis: Squish Threshold", 0.2f, new ConfigDescription("Allows the penis to begin squishing (shorten length increase girth) after this amount of the penis has penetrated.", new AcceptableValueRange <float>(0, 1)))).SettingChanged += (s, e) =>
                { UpdateDanOptions(); };
                (_danSquishOralGirth[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Penis: Squish Oral Girth", false, "Allows the penis to squish (increase girth) during oral.")).SettingChanged += (s, e) =>
                { UpdateDanOptions(); };
                (_useFingerColliders[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Finger Collider: Enable", true, "Use finger colliders")).SettingChanged += (s, e) =>
                { UpdateDanOptions(); };
                (_simplifyPenetration[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Simplify Penetration Calculation", false, "Simplifys penetration calclation by always having it target the same internal point.  Only valid for BP penis uncensors.")).SettingChanged += (s, e) =>
                { UpdateDanOptions(); };
                (_simplifyOral[maleNum] = Config.Bind("Male " + (maleNum + 1) + " Options", "Simplify Oral Calculation", false, "Simplifys oral penetration calclation by always having it target the same internal point.  Only valid for BP penis uncensors.")).SettingChanged += (s, e) =>
                { UpdateDanOptions(); };
            }

            (_clippingDepth = Config.Bind("Female Options", "Clipping Depth", 0.25f, "Set how close to body surface to limit penis for clipping purposes. Smaller values will result in more clipping through the body, larger values will make the shaft wander further away from the intended penetration point.")).SettingChanged += (s, e) =>
            { UpdateCollisionOptions(); };
            for (int offset = 0; offset < frontOffsets.Count; offset++)
            {
                (_frontCollisionOffset[offset] = Config.Bind("Female Options", "Clipping Offset: Front Collision " + offset, frontOffsets[offset], "Individual offset on colision point, to improve clipping")).SettingChanged += (s, e) =>
                { UpdateCollisionOptions(); }
            }
            ;
            for (int offset = 0; offset < backOffsets.Count; offset++)
            {
                (_backCollisionOffset[offset] = Config.Bind("Female Options", "Clipping Offset: Back Collision " + offset, backOffsets[offset], "Individual offset on colision point, to improve clipping")).SettingChanged += (s, e) =>
                { UpdateCollisionOptions(); }
            }
            ;
            (_kokanOffsetForward = Config.Bind("Female Options", "Target Offset: V****a Vertical", -0.15f, "Vertical offset of the v****a target")).SettingChanged += (s, e) =>
            { UpdateCollisionOptions(); };
            (_kokanOffsetUp = Config.Bind("Female Options", "Target Offset: V****a Depth", 0.0f, "Depth offset of the v****a target")).SettingChanged += (s, e) =>
            { UpdateCollisionOptions(); };
            (_headOffsetForward = Config.Bind("Female Options", "Target Offset: Mouth Depth", 0.0f, "Depth offset of the mouth target")).SettingChanged += (s, e) =>
            { UpdateCollisionOptions(); };
            (_headOffsetUp = Config.Bind("Female Options", "Target Offset: Mouth Vertical", 0.03f, "Vertical offset of the mouth target")).SettingChanged += (s, e) =>
            { UpdateCollisionOptions(); };
            (_useKokanFix = Config.Bind("Female Options", "Joint Adjustment: Missionary Correction", false, "NOTE: There is an Illusion bug that causes the v****a to appear sunken in certain missionary positions.  It is best to use Advanced Bonemod and adjust your female character's cf_J_Kokan Offset Y to 0.001.  If you don't do that, enabling this option will attempt to fix the problem by guessing where the bone should be")).SettingChanged += (s, e) =>
            { UpdateCollisionOptions(); };
            (_kokanFixPositionY = Config.Bind("Female Options", "Joint Adjustment: Missionary Position Y", -0.075f, "Amount to adjust the V****a bone position Y for certain Missionary positions to correct its appearance")).SettingChanged += (s, e) =>
            { UpdateCollisionOptions(); };
            (_kokanFixPositionZ = Config.Bind("Female Options", "Joint Adjustment: Missionary Position Z", 0.0625f, "Amount to adjust the V****a bone position Z for certain Missionary positions to correct its appearance")).SettingChanged += (s, e) =>
            { UpdateCollisionOptions(); };
            (_kokanFixRotationX = Config.Bind("Female Options", "Joint Adjustment: Missionary Rotation X", 10.0f, "Amount to adjust the V****a bone rotation X for certain Missionary positions to correct its appearance")).SettingChanged += (s, e) =>
            { UpdateCollisionOptions(); };

            harmony = new Harmony("HS2_BetterPenetration");
            SceneManager.sceneLoaded   += SceneManager_sceneLoaded;
            SceneManager.sceneUnloaded += SceneManager_sceneUnloaded;
        }
示例#21
0
 public override void Patch(Harmony harmony)
 {
     PatchMultiple(harmony, TARGET_METHOD, true, true, false, false);
 }
示例#22
0
            public static void Init()
            {
                Harmony.CreateAndPatchAll(typeof(Hooks), nameof(KoiClothesOverlayController));

#if EC
                ExtendedSave.CardBeingImported += importedData =>
                {
                    if (importedData.TryGetValue(KoiClothesOverlayMgr.GUID, out var pluginData) && pluginData != null)
                    {
                        var dic = ReadOverlayExtData(pluginData);

                        // Only keep 1st coord
                        foreach (var coordKey in dic.Keys.ToList())
                        {
                            if (coordKey != 0)
                            {
#if DEBUG
                                UnityEngine.Debug.Log("Removing coord " + coordKey);
#endif
                                dic.Remove(coordKey);
                            }
                            else
                            {
                                var group = dic[coordKey];
                                if (group == null)
                                {
                                    dic.Remove(coordKey);
                                    continue;
                                }
#if EC
                                // Convert shoe overlays to EC format (1 pair instead of 2)
                                if (group.TryGetValue("ct_shoes_outer", out var data))
                                {
                                    group["ct_shoes"] = data;
                                    group.Remove("ct_shoes_outer");
                                }
#endif
                                // Neither EC or KKS use inner shoes
                                group.Remove("ct_shoes_inner");
                            }
                        }

                        CleanupTextureList(dic);

                        if (dic.Count == 0)
                        {
                            importedData.Remove(KoiClothesOverlayMgr.GUID);
                        }
                        else
                        {
                            SetOverlayExtData(dic, pluginData);
                        }
                    }
                };
#elif KKS
                ExtendedSave.CardBeingImported += (data, mapping) =>
                {
                    if (data.TryGetValue(KoiClothesOverlayMgr.GUID, out var pluginData) && pluginData != null)
                    {
                        var dic = ReadOverlayExtData(pluginData);
                        // Map coords into a new dictionary based on the mapping
                        var outDic = new Dictionary <ChaFileDefine.CoordinateType, Dictionary <string, ClothesTexData> >(dic.Count);
                        foreach (var map in mapping)
                        {
                            // Discard unused
                            if (map.Value == null)
                            {
                                continue;
                            }

                            dic.TryGetValue((ChaFileDefine.CoordinateType)map.Key, out var value);
                            if (value != null)
                            {
                                // KKS doesn't have inner shoes
                                value.Remove("ct_shoes_inner");
                                outDic[(ChaFileDefine.CoordinateType)map.Value.Value] = value;
                            }
                        }

                        CleanupTextureList(outDic);

                        // Overwrite with the new dictionary
                        if (outDic.Count == 0)
                        {
                            data.Remove(KoiClothesOverlayMgr.GUID);
                        }
                        else
                        {
                            SetOverlayExtData(outDic, pluginData);
                        }
                    }
                };
#endif
            }
        internal static void Patch(Harmony harmony)
        {
            PatchUtils.PatchClass(harmony);

            Logger.Log($"CraftTreePatcher is done.", LogLevel.Debug);
        }
示例#24
0
        public void Start()
        {
            var harmony = new Harmony("TormentedEmu.Mods.A19");

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }
 private void Awake() => Harmony.CreateAndPatchAll(typeof(KK_FixPartySettings), nameof(KK_FixPartySettings));
示例#26
0
        void Awake()
        {
            Harmony harmony = new Harmony("mod.randomspawn");

            harmony.PatchAll();
        }
示例#27
0
 public StudioCharaFolders()
 {
     Harmony.CreateAndPatchAll(typeof(StudioCharaFolders));
 }
示例#28
0
 public override void OnEnabled()
 {
     Harmony = new Harmony("com.ghost.scpsl");
     Harmony.PatchAll();
 }
示例#29
0
 public static void Init()
 {
     Harmony.CreateAndPatchAll(typeof(VoicePitchUnlocker));
 }
示例#30
0
        public static void exportTranspiledMethods()
        {
            AssemblyName aName = new AssemblyName("RimWorldTranspiles");
            //PermissionSet requiredPermission = new PermissionSet(PermissionState.Unrestricted);
            AssemblyBuilder        ab                       = AppDomain.CurrentDomain.DefineDynamicAssembly(aName, AssemblyBuilderAccess.RunAndSave);
            ConstructorInfo        Constructor2             = typeof(SecurityPermissionAttribute).GetConstructors()[0];
            SecurityAction         requestMinimum           = SecurityAction.RequestMinimum;
            PropertyInfo           skipVerificationProperty = Property(typeof(SecurityPermissionAttribute), "SkipVerification");
            CustomAttributeBuilder sv2                      = new CustomAttributeBuilder(Constructor2, new object[] { requestMinimum },
                                                                                         new PropertyInfo[] { skipVerificationProperty }, new object[] { true });

            ab.SetCustomAttribute(sv2);

            //System.Security.AllowPartiallyTrustedCallersAttribute Att = new System.Security.AllowPartiallyTrustedCallersAttribute();
            //ConstructorInfo Constructor1 = Att.GetType().GetConstructors()[0];
            //object[] ObjectArray1 = new object[0];
            //CustomAttributeBuilder AttribBuilder1 = new CustomAttributeBuilder(Constructor1, ObjectArray1);
            //ab.SetCustomAttribute(AttribBuilder1);
            ModuleBuilder             modBuilder  = ab.DefineDynamicModule(aName.Name, aName.Name + ".dll");
            UnverifiableCodeAttribute ModAtt      = new System.Security.UnverifiableCodeAttribute();
            ConstructorInfo           Constructor = ModAtt.GetType().GetConstructors()[0];

            object[] ObjectArray = new object[0];
            CustomAttributeBuilder ModAttribBuilder = new CustomAttributeBuilder(Constructor, ObjectArray);

            modBuilder.SetCustomAttribute(ModAttribBuilder);
            Dictionary <string, TypeBuilder> typeBuilders    = new Dictionary <string, TypeBuilder>();
            IEnumerable <MethodBase>         originalMethods = Harmony.GetAllPatchedMethods();

            foreach (MethodBase originalMethod in originalMethods)
            {
                Patches patches         = Harmony.GetPatchInfo(originalMethod);
                int     transpiledCount = patches.Transpilers.Count;
                if (transpiledCount == 0)
                {
                    continue;
                }
                if (originalMethod is MethodInfo methodInfo) // add support for constructors as well
                {
                    Type   returnType     = methodInfo.ReturnType;
                    string typeTranspiled = originalMethod.DeclaringType.FullName + "_Transpiled";
                    if (!typeBuilders.TryGetValue(typeTranspiled, out TypeBuilder tb))
                    {
                        tb = modBuilder.DefineType(typeTranspiled, TypeAttributes.Public);
                        typeBuilders[typeTranspiled] = tb;
                    }
                    ParameterInfo[] parameterInfos = methodInfo.GetParameters();
                    List <Type>     types          = new List <Type>();

                    int parameterOffset = 1;
                    if (!methodInfo.Attributes.HasFlag(MethodAttributes.Static))
                    {
                        types.Add(methodInfo.DeclaringType);
                        parameterOffset = 2;
                    }
                    foreach (ParameterInfo parameterInfo in parameterInfos)
                    {
                        types.Add(parameterInfo.ParameterType);
                    }
                    MethodBuilder mb = tb.DefineMethod(originalMethod.Name, MethodAttributes.Public | MethodAttributes.Static, returnType, types.ToArray());
                    if (typeTranspiled.Equals("Verse.PawnGenerator_Transpiled") && !originalMethod.Name.Equals(""))
                    {
                        Log.Message(originalMethod.Name);
                    }
                    if (!methodInfo.Attributes.HasFlag(MethodAttributes.Static))
                    {
                        ParameterAttributes pa = new ParameterAttributes();
                        ParameterBuilder    pb = mb.DefineParameter(1, pa, methodInfo.DeclaringType.Name);
                    }

                    foreach (ParameterInfo parameterInfo in parameterInfos)
                    {
                        ParameterAttributes pa = new ParameterAttributes();
                        if (parameterInfo.IsOut)
                        {
                            pa |= ParameterAttributes.Out;
                        }
                        if (parameterInfo.IsIn)
                        {
                            pa |= ParameterAttributes.In;
                        }
                        if (parameterInfo.IsLcid)
                        {
                            pa |= ParameterAttributes.Lcid;
                        }
                        if (parameterInfo.IsOptional)
                        {
                            pa |= ParameterAttributes.Optional;
                        }
                        if (parameterInfo.IsRetval)
                        {
                            pa |= ParameterAttributes.Retval;
                        }
                        if (parameterInfo.HasDefaultValue)
                        {
                            pa |= ParameterAttributes.HasDefault;
                        }
                        ParameterBuilder pb = mb.DefineParameter(parameterInfo.Position + parameterOffset, pa, parameterInfo.Name);
                        if (parameterInfo.HasDefaultValue && parameterInfo.DefaultValue != null)
                        {
                            pb.SetConstant(parameterInfo.DefaultValue);
                        }
                    }
                    ILGenerator il = mb.GetILGenerator();
                    //il.Emit(OpCodes.Nop);
                    //MethodCopier methodCopier = new MethodCopier(originalMethod, il);
                    //List<Label> endLabels = new List<Label>();
                    //_ = methodCopier.Finalize(null, endLabels, out var hasReturnCode);
                    //List<CodeInstruction> ciList = MethodCopier.GetInstructions(il, originalMethod, 9999);
                    MethodInfo methodInfo2 = UpdateWrapper(originalMethod, il);
                    //Log.Message(ciList.ToString());
                    //List<CodeInstruction> currentInstructions = PatchProcessor.GetCurrentInstructions(originalMethod);
                    //Dictionary<Label, Label> labels = new Dictionary<Label, Label>();

                    //MethodBody methodBody = methodInfo.GetMethodBody();
                    //IList<LocalVariableInfo> localvars = methodBody.LocalVariables;
                    //LocalBuilder[] localBuildersOrdered = new LocalBuilder[255];
                    //foreach (LocalVariableInfo localVar in localvars)
                    //{
                    //    Type type = localVar.LocalType;
                    //    LocalBuilder newLocalBuilder = il.DeclareLocal(type);
                    //    localBuildersOrdered[localVar.LocalIndex] = newLocalBuilder;
                    //}
                    //IList<ExceptionHandlingClause> exceptionHandlingClauses = methodBody.ExceptionHandlingClauses;

                    ////LocalBuilder[] localBuildersOrdered = new LocalBuilder[255];
                    ////int localBuildersOrderedMax = 0;
                    ////foreach (CodeInstruction currentInstruction in currentInstructions)
                    ////{
                    ////    object operand = currentInstruction.operand;
                    ////    if (operand is LocalBuilder localBuilder)
                    ////    {
                    ////        localBuildersOrdered[localBuilder.LocalIndex] = localBuilder;
                    ////        localBuildersOrderedMax = Math.Max(localBuildersOrderedMax, localBuilder.LocalIndex);
                    ////    }
                    ////}
                    ////Dictionary<LocalBuilder, LocalBuilder> localBuilders = new Dictionary<LocalBuilder, LocalBuilder>();
                    ////for (int i = 0; i <= localBuildersOrderedMax; i++)
                    ////{
                    ////    LocalBuilder localBuilderOrdered = localBuildersOrdered[i];
                    ////    if (localBuilderOrdered == null)
                    ////    {
                    ////        il.DeclareLocal(typeof(object));
                    ////    }
                    ////    else
                    ////    {
                    ////        LocalBuilder newLocalBuilder = il.DeclareLocal(localBuilderOrdered.LocalType);
                    ////        localBuilders.Add(localBuilderOrdered, newLocalBuilder);
                    ////    }
                    ////}

                    //foreach (CodeInstruction currentInstruction in currentInstructions)
                    //{
                    //    bool endFinally = false;
                    //    foreach (Label label in currentInstruction.labels)
                    //    {
                    //        if (!labels.TryGetValue(label, out Label translatedLabel))
                    //        {
                    //            translatedLabel = il.DefineLabel();
                    //            labels[label] = translatedLabel;
                    //        }
                    //        il.MarkLabel(translatedLabel);
                    //    }

                    //    //int i = il.ILOffset;
                    //    //foreach (ExceptionHandlingClause Clause in exceptionHandlingClauses)
                    //    //{
                    //    //    if (Clause.Flags != ExceptionHandlingClauseOptions.Clause &&
                    //    //       Clause.Flags != ExceptionHandlingClauseOptions.Finally)
                    //    //        continue;

                    //    //    // Look for an ending of an exception block first!
                    //    //    if (Clause.HandlerOffset + Clause.HandlerLength == i)
                    //    //        il.EndExceptionBlock();

                    //    //    // If this marks the beginning of a try block, emit that
                    //    //    if (Clause.TryOffset == i)
                    //    //        il.BeginExceptionBlock();

                    //    //    // Also check for the beginning of a catch block
                    //    //    if (Clause.HandlerOffset == i && Clause.Flags == ExceptionHandlingClauseOptions.Clause)
                    //    //        il.BeginCatchBlock(Clause.CatchType);

                    //    //    // Lastly, check for a finally block
                    //    //    if (Clause.HandlerOffset == i && Clause.Flags == ExceptionHandlingClauseOptions.Finally)
                    //    //        il.BeginFinallyBlock();
                    //    //}

                    //    foreach (ExceptionBlock block in currentInstruction.blocks)
                    //    {
                    //        switch (block.blockType) {
                    //            case ExceptionBlockType.BeginExceptionBlock:
                    //                {
                    //                    il.BeginExceptionBlock();
                    //                    break;
                    //                }
                    //            case ExceptionBlockType.BeginCatchBlock:
                    //                {
                    //                    il.BeginCatchBlock(block.catchType);
                    //                    break;
                    //                }
                    //            case ExceptionBlockType.BeginExceptFilterBlock:
                    //                {
                    //                    il.BeginExceptFilterBlock();
                    //                    break;
                    //                }
                    //            case ExceptionBlockType.BeginFaultBlock:
                    //                {
                    //                    il.BeginFaultBlock();
                    //                    break;
                    //                }
                    //            case ExceptionBlockType.BeginFinallyBlock:
                    //                {
                    //                    il.BeginFinallyBlock();
                    //                    break;
                    //                }
                    //            case ExceptionBlockType.EndExceptionBlock:
                    //                {
                    //                    //il.EndExceptionBlock();
                    //                    endFinally = true;
                    //                    break;
                    //                }
                    //            default:
                    //                {
                    //                    Log.Error("Unknown ExceptionBlock");
                    //                    break;
                    //                }
                    //        }
                    //    }

                    //    OpCode opcode = currentInstruction.opcode;
                    //    object operand = currentInstruction.operand;
                    //    switch (operand)
                    //    {
                    //        case null:
                    //            {
                    //                il.Emit(opcode);
                    //                break;
                    //            }
                    //        case byte operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case sbyte operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case short operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case int operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case MethodInfo operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case SignatureHelper operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case ConstructorInfo operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case Type operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case long operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case float operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case double operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case Label operandCasted:
                    //            {
                    //                if (!labels.TryGetValue(operandCasted, out Label translatedLabel))
                    //                {
                    //                    translatedLabel = il.DefineLabel();
                    //                    labels[operandCasted] = translatedLabel;
                    //                }
                    //                il.Emit(opcode, translatedLabel);
                    //                break;
                    //            }
                    //        case Label[] operandCasted:
                    //            {
                    //                List<Label> newLabels = new List<Label>();
                    //                foreach (Label operandCasted1 in operandCasted)
                    //                {
                    //                    if (!labels.TryGetValue(operandCasted1, out Label translatedLabel))
                    //                    {
                    //                        translatedLabel = il.DefineLabel();
                    //                        labels[operandCasted1] = translatedLabel;
                    //                    }
                    //                    newLabels.Add(translatedLabel);
                    //                }
                    //                il.Emit(opcode, newLabels.ToArray());
                    //                break;
                    //            }
                    //        case FieldInfo operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case string operandCasted:
                    //            {
                    //                il.Emit(opcode, operandCasted);
                    //                break;
                    //            }
                    //        case LocalBuilder operandCasted:
                    //            {
                    //                il.Emit(opcode, localBuildersOrdered[operandCasted.LocalIndex]);
                    //                break;
                    //            }
                    //        default:
                    //            {
                    //                Log.Error("UNKNOWN OPERAND");
                    //                break;
                    //            }
                    //    }
                    //    if (endFinally)
                    //    {
                    //        il.EndExceptionBlock();
                    //        //endFinally = true;
                    //    }
                    //}
                }
            }
            foreach (KeyValuePair <string, TypeBuilder> tb in typeBuilders)
            {
                tb.Value.CreateType();
            }
            ab.Save(aName.Name + ".dll");


            //ReImport DLL and create detour
            Assembly loadedAssembly = Assembly.UnsafeLoadFrom(aName.Name + ".dll");
            IEnumerable <TypeInfo>    transpiledTypes = loadedAssembly.DefinedTypes;
            Dictionary <string, Type> tTypeDictionary = new Dictionary <string, Type>();

            foreach (TypeInfo transpiledType in transpiledTypes)
            {
                tTypeDictionary.Add(transpiledType.FullName, transpiledType.AsType());
            }

            foreach (MethodBase originalMethod in originalMethods)
            {
                Patches patches         = Harmony.GetPatchInfo(originalMethod);
                int     transpiledCount = patches.Transpilers.Count;
                if (transpiledCount > 0)
                {
                    if (originalMethod is MethodInfo methodInfo) // add support for constructors as well
                    {
                        Type            transpiledType = tTypeDictionary[originalMethod.DeclaringType.FullName + "_Transpiled"];
                        ParameterInfo[] parameterInfos = methodInfo.GetParameters();
                        List <Type>     types          = new List <Type>();

                        if (!methodInfo.Attributes.HasFlag(MethodAttributes.Static))
                        {
                            types.Add(methodInfo.DeclaringType);
                        }
                        foreach (ParameterInfo parameterInfo in parameterInfos)
                        {
                            types.Add(parameterInfo.ParameterType);
                        }
                        MethodInfo replacement = Method(transpiledType, originalMethod.Name, types.ToArray());
                        Memory.DetourMethod(originalMethod, replacement);
                    }
                }
            }
        }