示例#1
0
        public static void Patch()
        {
            ReloadRequired = false;
            frameCounter   = 0;
            if (ModsExtraInfo == null)
            {
                ModsExtraInfo = new Dictionary <string, string>();
            }

            var refHolder      = false;
            var reloadRequired = "Terraria.ModLoader.Config.ConfigManager".Type().Method("ModNeedsReload");

            Localizer.Harmony.Patch(reloadRequired, postfix: new HarmonyMethod(NoroHelper.MethodInfo(() => ModNeedsReloadPostfix(ref refHolder))));

            var onInit = "Terraria.ModLoader.UI.UIModItem".Type().Method("OnInitialize");

            Localizer.Harmony.Patch(onInit, postfix: new HarmonyMethod(NoroHelper.MethodInfo(() => UIModItemPostfix(null))));

            var drawSelf = "Terraria.ModLoader.UI.UIModItem".Type().Method("DrawSelf");

            Localizer.Harmony.Patch(drawSelf, postfix: new HarmonyMethod(NoroHelper.MethodInfo(() => DrawSelfPostfix(null, null))));

            var populateFromJson = "Terraria.ModLoader.UI.ModBrowser.UIModBrowser".Type().Method("PopulateFromJson");

            Localizer.Harmony.Patch(populateFromJson, prefix: new HarmonyMethod(NoroHelper.MethodInfo(() => PopulateFromJsonPrefix())),
                                    postfix: new HarmonyMethod(NoroHelper.MethodInfo(() => PopulateFromJsonPostfix())));
        }
示例#2
0
        protected override void ImportInternal(LdstrFile file, IMod mod, CultureInfo culture)
        {
            entries = new Dictionary <MethodBase, LdstrEntry>();

            var module    = mod.Code.ManifestModule;
            var entryDict = file.LdstrEntries;

            foreach (var entryPair in entryDict)
            {
                Utils.SafeWrap(() =>
                {
                    if (!HaveTranslation(entryPair.Value))
                    {
                        return;
                    }

                    Utils.LogDebug($"Finding method: [{entryPair.Key}]");
                    var method = Utils.FindMethodByID(module, entryPair.Key);
                    if (method == null)
                    {
                        Utils.LogDebug($"Cannot find.");
                        return;
                    }

                    entries.Add(method, entryPair.Value);

                    harmony.Patch(method, transpiler: new HarmonyMethod(NoroHelper.MethodInfo(() => Transpile(null, null))));

                    Utils.LogDebug($"Patched: {entryPair.Key}");
                });
            }
        }
示例#3
0
        private static IEnumerable <CodeInstruction> PopulateModBrowserTranspiler(IEnumerable <CodeInstruction> instructions)
        {
            var result = instructions.ToList();

            ReplaceLdstr("http://javid.ddns.net/tModLoader/listmods.php", GetModListURL(), result);
            for (int i = 0; i < result.Count; i++)
            {
                if (result[i].opcode == OpCodes.Callvirt && $"{result[i].operand}".Contains("UploadValuesCompleted"))
                {
                    result.Insert(i + 1, new CodeInstruction(result[i + 1]));
                    result.Insert(i + 2, new CodeInstruction(OpCodes.Call, NoroHelper.MethodInfo(() => UpdateHeader(null))));
                    break;
                }
            }

            return(result);
        }
示例#4
0
        public static void Patch()
        {
            Utils.LogInfo($"Patching ModBrowser, tML version: {ModLoader.version}");

            HarmonyInstance = HarmonyInstance.Create("ModBrowserMirror");

            try
            {
                if (!string.IsNullOrEmpty(GetModListURL()))
                {
                    var populateModBrowser = "Terraria.ModLoader.UI.ModBrowser.UIModBrowser".Type()
                                             .GetMethods(NoroHelper.Any)
                                             .FirstOrDefault(m => m.Name.Contains("<PopulateModBrowser>"));
                    HarmonyInstance.Patch(populateModBrowser, null, null, new HarmonyMethod(NoroHelper.MethodInfo(() => PopulateModBrowserTranspiler(null))));
                    Utils.LogInfo("PopulateModBrowser Patched");
                }

                if (!string.IsNullOrEmpty(GetModDownloadURL()))
                {
                    var fromJson = "Terraria.ModLoader.UI.ModBrowser.UIModDownloadItem".Type().Method("FromJson");
                    HarmonyInstance.Patch(fromJson, null, null, new HarmonyMethod(NoroHelper.MethodInfo(() => FromJSONTranspiler(null))));
                    Utils.LogInfo("FromJson Patched");

                    if (!string.IsNullOrEmpty(GetModDescURL()))
                    {
                        var onActivate = "Terraria.ModLoader.UI.UIModInfo".Type()
                                         .GetMethods(NoroHelper.Any)
                                         .FirstOrDefault(m => m.Name.Contains("<OnActivate>"));
                        HarmonyInstance.Patch(onActivate, null, null, new HarmonyMethod(NoroHelper.MethodInfo(() => OnActivateTranspiler(null))));
                        Utils.LogInfo("OnActivate Patched");
                    }
                }
                Utils.LogInfo("ModBrowser Patched");
            }
            catch (Exception e)
            {
                Utils.LogInfo($"ModBrowser Patch exception: {e}");
            }
        }
        public RefreshLanguageService()
        {
            _instance = this;
            items     = new List <WeakReference>();

            _harmony = HarmonyInstance.Create(nameof(RefreshLanguageService));
            _harmony.Patch(typeof(ModItem).GetConstructors()[0], null, new HarmonyMethod(NoroHelper.MethodInfo(() => OnModItemCtor(null))));
        }
示例#6
0
        public Localizer()
        {
            Instance        = this;
            LoadedLocalizer = new LoadedModWrapper("Terraria.ModLoader.Core.AssemblyManager".Type().ValueOf("loadedMods").Invoke("get_Item", "!Localizer"));
            this.SetField("<File>k__BackingField", LoadedLocalizer.File);
            this.SetField("<Code>k__BackingField", LoadedLocalizer.Code);
            Log = LogManager.GetLogger(nameof(Localizer));

            Harmony = HarmonyInstance.Create(nameof(Localizer));
            Harmony.Patch("Terraria.ModLoader.Core.AssemblyManager".Type().Method("Instantiate"), new HarmonyMethod(NoroHelper.MethodInfo(() => AfterLocalizerCtorHook(null))));

            State    = OperationTiming.BeforeModCtor;
            TmodFile = Instance.ValueOf <TmodFile>("File");
            Init();
            _initiated = true;
        }