static bool Prefix(object __instance, ref string __result)
        {
            var hasWiiUTitleKeys = !string.IsNullOrEmpty((string)AccessTools.DeclaredProperty(ReflectionHelper.Settings, "TicketsPath").GetValue(__instance));

            __result = hasWiiUTitleKeys ? "http://3ds.titlekeys.gq/" : string.Empty;
            return(false);
        }
Пример #2
0
        public void Test_AccessTools_Property2()
        {
            var classType = typeof(AccessToolsClass);

            Assert.NotNull(AccessTools.Property(classType, "Property1"));
            Assert.NotNull(AccessTools.DeclaredProperty(classType, "Property1"));
            Assert.Null(AccessTools.Property(classType, "unknown"));
            Assert.Null(AccessTools.DeclaredProperty(classType, "unknown"));

            var subclassType = typeof(AccessToolsSubClass);

            Assert.NotNull(AccessTools.Property(subclassType, "Property1"));
            Assert.Null(AccessTools.DeclaredProperty(subclassType, "Property1"));
            Assert.Null(AccessTools.Property(subclassType, "unknown"));
            Assert.Null(AccessTools.DeclaredProperty(subclassType, "unknown"));

            var structType = typeof(AccessToolsStruct);

            Assert.NotNull(AccessTools.Property(structType, "Property1"));
            Assert.NotNull(AccessTools.DeclaredProperty(structType, "Property1"));
            Assert.Null(AccessTools.Property(structType, "unknown"));
            Assert.Null(AccessTools.DeclaredProperty(structType, "unknown"));

            var interfaceType = typeof(IAccessToolsType);

            Assert.NotNull(AccessTools.Property(interfaceType, "Property1"));
            Assert.NotNull(AccessTools.DeclaredProperty(interfaceType, "Property1"));
            Assert.Throws(typeof(NullReferenceException), () => AccessTools.Property(interfaceType, "unknown"));             // TODO: should return null, not throw NRE
            Assert.Null(AccessTools.DeclaredProperty(interfaceType, "unknown"));
        }
Пример #3
0
        public virtual void Setup()
        {
            System.Diagnostics.Trace.Listeners.Clear();
            var property = AccessTools.DeclaredProperty(typeof(UIResourceManager), nameof(UIResourceManager.WidgetFactory));

            property.SetValue(null, new MockWidgetFactory());
        }
Пример #4
0
        public void Test_AccessTools_Property2()
        {
            var classType = typeof(AccessToolsClass);

            Assert.NotNull(AccessTools.Property(classType, "Property1"));
            Assert.NotNull(AccessTools.DeclaredProperty(classType, "Property1"));
            Assert.Null(AccessTools.Property(classType, "unknown"));
            Assert.Null(AccessTools.DeclaredProperty(classType, "unknown"));

            var subclassType = typeof(AccessToolsSubClass);

            Assert.NotNull(AccessTools.Property(subclassType, "Property1"));
            Assert.Null(AccessTools.DeclaredProperty(subclassType, "Property1"));
            Assert.Null(AccessTools.Property(subclassType, "unknown"));
            Assert.Null(AccessTools.DeclaredProperty(subclassType, "unknown"));

            var structType = typeof(AccessToolsStruct);

            Assert.NotNull(AccessTools.Property(structType, "Property1"));
            Assert.NotNull(AccessTools.DeclaredProperty(structType, "Property1"));
            Assert.Null(AccessTools.Property(structType, "unknown"));
            Assert.Null(AccessTools.DeclaredProperty(structType, "unknown"));

            var interfaceType = typeof(IAccessToolsType);

            Assert.NotNull(AccessTools.Property(interfaceType, "Property1"));
            Assert.NotNull(AccessTools.DeclaredProperty(interfaceType, "Property1"));
            Assert.Null(AccessTools.Property(interfaceType, "unknown"));
            Assert.Null(AccessTools.DeclaredProperty(interfaceType, "unknown"));
        }
Пример #5
0
        static HarmonyPatches()
        {
#if DEBUG
            Harmony.DEBUG = true;
#endif

            // Default: RimWorld.TimeControls - draws a horizontal line over the time controls UI when ForcedNormalSpeed.
            // Default: Verse.TickManager     - forces speed to 0 (paused) or x1 when ForcedNormalSpeed.
            Harmony    harmony            = new Harmony("dingo.rimworld.no_forced_slowdown");
            MethodInfo doTimeControlsGUI  = AccessTools.Method(typeof(TimeControls), nameof(TimeControls.DoTimeControlsGUI));
            MethodInfo tickRateMultiplier = AccessTools.DeclaredProperty(typeof(TickManager), nameof(TickManager.TickRateMultiplier)).GetGetMethod();

#if DEBUG
            // Check for null references
            // Log.Message($"No Forced Slowdown :: MethodInfo _ForcedNormalSpeed = {AccessTools.DeclaredProperty(typeof(TimeSlower), nameof(TimeSlower.ForcedNormalSpeed)).GetGetMethod()}");
            Log.Message($"No Forced Slowdown :: MethodInfo _ModdedForcedNormalSpeed = {Call_ShouldTriggerForcedNormalSpeed.ToString()}");
            Log.Message($"No Forced Slowdown :: MethodInfo doTimeControlsGUI = {doTimeControlsGUI.ToString()}");
            Log.Message($"No Forced Slowdown :: MethodInfo tickRateMultiplier = {tickRateMultiplier.ToString()}");
#endif

            // Since Verse.TimeSlower.ForcedNormalSpeed gets inlined, we use HarmonyTranspiler patches
            harmony.Patch(doTimeControlsGUI, null, null, new HarmonyMethod(typeof(HarmonyPatches), nameof(HarmonyPatches.Patch_TimeControls_DoTimeControlsGUI)));
            harmony.Patch(tickRateMultiplier, null, null, new HarmonyMethod(typeof(HarmonyPatches), nameof(HarmonyPatches.Patch_TickManager_TickRateMultiplier)));

#if DEBUG
            Log.Message("No Forced Slowdown :: Injected Harmony patches.");
#endif
        }
Пример #6
0
        private static MethodBase GetOriginalMethod(HarmonyMethod attribute)
        {
            if (attribute.declaringType == null)
            {
                return(null);
            }

            switch (attribute.methodType)
            {
            case MethodType.Normal:
                if (attribute.methodName == null)
                {
                    return(null);
                }
                return(AccessTools.DeclaredMethod(attribute.declaringType, attribute.methodName, attribute.argumentTypes));

            case MethodType.Getter:
                if (attribute.methodName == null)
                {
                    return(null);
                }
                return(AccessTools.DeclaredProperty(attribute.declaringType, attribute.methodName)
                       .GetGetMethod(true));

            case MethodType.Setter:
                if (attribute.methodName == null)
                {
                    return(null);
                }
                return(AccessTools.DeclaredProperty(attribute.declaringType, attribute.methodName)
                       .GetSetMethod(true));

            case MethodType.Constructor:
                return(AccessTools.GetDeclaredConstructors(attribute.declaringType)
                       .FirstOrDefault((ConstructorInfo c) =>
                {
                    if (c.IsStatic)
                    {
                        return false;
                    }
                    ParameterInfo[] parameters = c.GetParameters();
                    if (attribute.argumentTypes == null && parameters.Length == 0)
                    {
                        return true;
                    }
                    return parameters
                    .Select((p) => p.ParameterType)
                    .SequenceEqual(attribute.argumentTypes);
                }));

            case MethodType.StaticConstructor:
                return(AccessTools.GetDeclaredConstructors(attribute.declaringType)
                       .FirstOrDefault(c => c.IsStatic));
            }

            return(null);
        }
Пример #7
0
        public static MethodBase GetOriginalMethod(HarmonyMethod attr)
        {
            if (attr.declaringType == null)
            {
                return(null);
            }

            if (attr.methodType == null)
            {
                attr.methodType = MethodType.Normal;
            }

            switch (attr.methodType)
            {
            case MethodType.Normal:
                if (attr.methodName == null)
                {
                    return(null);
                }

                return(AccessTools.DeclaredMethod(
                           attr.declaringType,
                           attr.methodName,
                           attr.argumentTypes));

            case MethodType.Getter:
                if (attr.methodName == null)
                {
                    return(null);
                }

                return(AccessTools.DeclaredProperty(attr.declaringType, attr.methodName)
                       .GetGetMethod(true));

            case MethodType.Setter:
                if (attr.methodName == null)
                {
                    return(null);
                }

                return(AccessTools.DeclaredProperty(attr.declaringType, attr.methodName)
                       .GetSetMethod(true));

            case MethodType.Constructor:
                return(AccessTools.DeclaredConstructor(attr.declaringType, attr.argumentTypes));

            case MethodType.StaticConstructor:
                return(AccessTools.GetDeclaredConstructors(attr.declaringType)
                       .FirstOrDefault(c => c.IsStatic));
            }

            return(null);
        }
Пример #8
0
        public void Test_AccessTools_Property2()
        {
            var type = typeof(AccessToolsClass);

            Assert.NotNull(AccessTools.Property(type, "Property"));
            Assert.NotNull(AccessTools.DeclaredProperty(type, "Property"));

            var subtype = typeof(AccessToolsSubClass);

            Assert.NotNull(AccessTools.Property(subtype, "Property"));
            Assert.Null(AccessTools.DeclaredProperty(subtype, "Property"));
        }
Пример #9
0
 internal PropertyInfo GetPropertyInfo(Type type, string name)
 {
     if (properties.TryGetValue(type, out var propertiesByType) == false)
     {
         propertiesByType = new Dictionary <string, PropertyInfo>();
         properties.Add(type, propertiesByType);
     }
     if (propertiesByType.TryGetValue(name, out var property) == false)
     {
         property = AccessTools.DeclaredProperty(type, name);
         propertiesByType.Add(name, property);
     }
     return(property);
 }
Пример #10
0
        public void ProcessPacket(StatisticsPlanetDataPacket packet, NebulaConnection conn)
        {
            var property = AccessTools.DeclaredProperty(typeof(PlanetFactory), "planet");

            for (int i = 0; i < packet.PlanetsIds.Length; i++)
            {
                if (GameMain.data.factories[i] == null)
                {
                    GameMain.data.factories[i] = new PlanetFactory();
                    PlanetData pd = GameMain.galaxy.PlanetById(packet.PlanetsIds[i]);
                    pd.factoryIndex = i;
                    property.SetValue(GameMain.data.factories[i], pd, null);
                }
                if (GameMain.statistics.production.factoryStatPool[i] == null)
                {
                    GameMain.statistics.production.factoryStatPool[i] = new FactoryProductionStat();
                    GameMain.statistics.production.factoryStatPool[i].Init();
                }
            }
        }
Пример #11
0
        // Copied from Harmony.PatchProcessor
        public static MethodBase GetMethod(Type type, string methodName, MethodType methodType, Type[] args)
        {
            if (type == null)
            {
                return(null);
            }

            switch (methodType)
            {
            case MethodType.Normal:
                if (methodName == null)
                {
                    return(null);
                }
                return(AccessTools.DeclaredMethod(type, methodName, args));

            case MethodType.Getter:
                if (methodName == null)
                {
                    return(null);
                }
                return(AccessTools.DeclaredProperty(type, methodName).GetGetMethod(true));

            case MethodType.Setter:
                if (methodName == null)
                {
                    return(null);
                }
                return(AccessTools.DeclaredProperty(type, methodName).GetSetMethod(true));

            case MethodType.Constructor:
                return(AccessTools.DeclaredConstructor(type, args));

            case MethodType.StaticConstructor:
                return(AccessTools.GetDeclaredConstructors(type)
                       .Where(c => c.IsStatic)
                       .FirstOrDefault());
            }

            return(null);
        }
Пример #12
0
        private static void DoPatch()
        {
            HarmonyInstance harmony = HarmonyInstance.Create("zaneyork.CustomLocalization");

            harmony.Patch(
                original: AccessTools.DeclaredMethod(typeof(TitleContainer), "OpenStream"),
                prefix: new HarmonyMethod(typeof(TitleContainerRewrites.OpenStreamRewrite), nameof(TitleContainerRewrites.OpenStreamRewrite.Prefix))
                );
            harmony.Patch(
                original: AccessTools.DeclaredMethod(typeof(StartupPreferences), "readSettings"),
                postfix: new HarmonyMethod(typeof(StartupPreferencesRewrites.ReadSettingsRewrite), nameof(StartupPreferencesRewrites.ReadSettingsRewrite.Postfix))
                );
            harmony.Patch(
                original: AccessTools.DeclaredMethod(typeof(StartupPreferences), "writeSettings"),
                prefix: new HarmonyMethod(typeof(StartupPreferencesRewrites.WriteSettingsRewrite), nameof(StartupPreferencesRewrites.WriteSettingsRewrite.Prefix)),
                postfix: new HarmonyMethod(typeof(StartupPreferencesRewrites.WriteSettingsRewrite), nameof(StartupPreferencesRewrites.WriteSettingsRewrite.Postfix))
                );
            harmony.Patch(
                original: AccessTools.DeclaredMethod(typeof(StartupPreferences), "writeSettings"),
                prefix: new HarmonyMethod(typeof(StartupPreferencesRewrites.WriteSettingsRewrite), nameof(StartupPreferencesRewrites.WriteSettingsRewrite.Prefix)),
                postfix: new HarmonyMethod(typeof(StartupPreferencesRewrites.WriteSettingsRewrite), nameof(StartupPreferencesRewrites.WriteSettingsRewrite.Postfix))
                );
            harmony.Patch(
                original: AccessTools.DeclaredMethod(typeof(SpriteText), "OnLanguageChange"),
                prefix: new HarmonyMethod(typeof(SpriteTextRewrites.OnLanguageChangeRewrite), nameof(SpriteTextRewrites.OnLanguageChangeRewrite.Prefix))
                );
            harmony.Patch(
                original: AccessTools.DeclaredMethod(typeof(SpriteText), "setUpCharacterMap"),
                prefix: new HarmonyMethod(typeof(SpriteTextRewrites.SetUpCharacterMapRewrite), nameof(SpriteTextRewrites.SetUpCharacterMapRewrite.Prefix))
                );
            harmony.Patch(
                original: AccessTools.DeclaredMethod(typeof(LocalizedContentManager), "LanguageCodeString"),
                prefix: new HarmonyMethod(typeof(LocalizedContentManagerRewrites.LanguageCodeStringRewrite), nameof(LocalizedContentManagerRewrites.LanguageCodeStringRewrite.Prefix))
                );
            harmony.Patch(
                original: AccessTools.DeclaredProperty(typeof(LocalizedContentManager), "CurrentLanguageLatin").GetMethod,
                prefix: new HarmonyMethod(typeof(LocalizedContentManagerRewrites.GetCurrentLanguageLatinRewrite), nameof(LocalizedContentManagerRewrites.GetCurrentLanguageLatinRewrite.Prefix))
                );

            Type mobileMenuType = AccessTools.TypeByName("StardewValley.Menus.LanguageSelectionMobile");

            if (mobileMenuType != null)
            {
                harmony.Patch(
                    original: AccessTools.DeclaredMethod(mobileMenuType, "draw", new Type[] { typeof(SpriteBatch) }),
                    prefix: new HarmonyMethod(typeof(LanguageSelectionMobileRewrites.DrawRewrite), nameof(LanguageSelectionMobileRewrites.DrawRewrite.Prefix))
                    );
                harmony.Patch(
                    original: AccessTools.DeclaredMethod(mobileMenuType, "releaseLeftClick"),
                    prefix: new HarmonyMethod(typeof(LanguageSelectionMobileRewrites.ReleaseLeftClickRewrite), nameof(LanguageSelectionMobileRewrites.ReleaseLeftClickRewrite.Prefix))
                    );
                harmony.Patch(
                    original: AccessTools.DeclaredMethod(mobileMenuType, "setCurrentItemIndex"),
                    prefix: new HarmonyMethod(typeof(LanguageSelectionMobileRewrites.SetCurrentItemIndexRewrite), nameof(LanguageSelectionMobileRewrites.SetCurrentItemIndexRewrite.Prefix))
                    );
                harmony.Patch(
                    original: AccessTools.DeclaredMethod(mobileMenuType, "SetupButtons"),
                    transpiler: new HarmonyMethod(typeof(LanguageSelectionMobileRewrites.SetupButtonsRewrite), nameof(LanguageSelectionMobileRewrites.SetupButtonsRewrite.Transpiler))
                    );
            }
        }
 static MethodBase TargetMethod()
 {
     return(AccessTools.DeclaredProperty(ReflectionHelper.Settings, "ShowDownloadManagerTip").GetGetMethod(true));
 }
 static MethodBase TargetMethod()
 {
     return(AccessTools.DeclaredProperty(ReflectionHelper.NusGrabberForm.Type, "Proxy").GetGetMethod(true));
 }
 static MethodBase TargetMethod()
 {
     return(AccessTools.DeclaredProperty(ReflectionHelper.Settings.Type, "DonationKey").GetGetMethod(true));
 }
        public void Setup()
        {
            var property = AccessTools.DeclaredProperty(typeof(UIResourceManager), nameof(UIResourceManager.WidgetFactory));

            property.SetValue(null, new MockWidgetFactory());
        }
Пример #17
0
 static MethodBase TargetMethod()
 {
     return(AccessTools.DeclaredProperty(ReflectionHelper.Settings, "Show552Warning").GetGetMethod(true));
 }
        internal static void AddSimulationObserver(this MapEvent mapEvent)
        {
            var prop = AccessTools.DeclaredProperty(typeof(MapEvent), "BattleObserver");

            prop.SetValue(mapEvent, new SimulationObserver());
        }
Пример #19
0
 static MethodBase TargetMethod()
 {
     return(AccessTools.DeclaredProperty(ReflectionHelper.Settings, "TicketsPath").GetGetMethod(true));
 }