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()))); }
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}"); }); } }
public RefreshLanguageService() { _instance = this; items = new List <WeakReference>(); _harmony = HarmonyInstance.Create(nameof(RefreshLanguageService)); _harmony.Patch(typeof(ModItem).GetConstructors()[0], null, NoroHelper.HarmonyMethod(() => OnModItemCtor(null))); }
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); }
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", "Instantiate", prefix: NoroHelper.HarmonyMethod(() => AfterLocalizerCtorHook(null))); State = OperationTiming.BeforeModCtor; TmodFile = Instance.ValueOf <TmodFile>("File"); Init(); _initiated = true; }
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 static void Patch() { ReloadRequired = false; frameCounter = 0; if (ModsExtraInfo == null) { ModsExtraInfo = new Dictionary <string, string>(); } var refHolder = false; Localizer.Harmony.Patch("Terraria.ModLoader.Config.ConfigManager", "ModNeedsReload", postfix: NoroHelper.HarmonyMethod(() => ModNeedsReloadPostfix(ref refHolder))); Localizer.Harmony.Patch("Terraria.ModLoader.UI.UIModItem", "OnInitialize", postfix: NoroHelper.HarmonyMethod(() => UIModItemPostfix(null))); Localizer.Harmony.Patch("Terraria.ModLoader.UI.UIModItem", "DrawSelf", postfix: NoroHelper.HarmonyMethod(() => DrawSelfPostfix(null, null))); Localizer.Harmony.Patch("Terraria.ModLoader.UI.ModBrowser.UIModBrowser", "PopulateFromJson", prefix: NoroHelper.HarmonyMethod(() => PopulateFromJsonPrefix()), postfix: NoroHelper.HarmonyMethod(() => PopulateFromJsonPostfix())); }
public static void Patch() { Utils.LogInfo($"Patching ModBrowser, tML version: {ModLoader.version}"); HarmonyInstance = HarmonyInstance.Create(nameof(Patches)); if (LanguageManager.Instance.ActiveCulture == GameCulture.Chinese) { try { #region Download Mod List if (!string.IsNullOrEmpty(GetModListURL())) { HarmonyInstance.Patch("Terraria.ModLoader.UI.ModBrowser.UIModBrowser", "<PopulateModBrowser>", exactMatch: false, transpiler: NoroHelper.HarmonyMethod(() => PopulateModBrowserTranspiler(null))); Utils.LogInfo("PopulateModBrowser Patched"); } #endregion #region Get Mod Download URL if (!string.IsNullOrEmpty(GetModDownloadURL())) { HarmonyInstance.Patch("Terraria.ModLoader.UI.ModBrowser.UIModDownloadItem", "FromJson", transpiler: NoroHelper.HarmonyMethod(() => FromJSONTranspiler(null))); Utils.LogInfo("FromJson Patched"); if (!string.IsNullOrEmpty(GetModDescURL())) { HarmonyInstance.Patch("Terraria.ModLoader.UI.UIModInfo", "<OnActivate>", exactMatch: false, transpiler: NoroHelper.HarmonyMethod(() => OnActivateTranspiler(null))); Utils.LogInfo("OnActivate Patched"); } } #endregion #region List My Mods // Terraria.ModLoader.UI.UIManagePublished.OnActivate // "http://javid.ddns.net/tModLoader/listmymods.php" #endregion #region Publish Mod // Terraria.ModLoader.UI.UIModSourceItem.PublishMod // "http://javid.ddns.net/tModLoader/publishmod.php" #endregion #region Unpublish Mod // Terraria.ModLoader.UI.UIModManageItem.UnpublishMod // "http://javid.ddns.net/tModLoader/unpublishmymod.php" #endregion #region Register Link // Terraria.ModLoader.UI.UIEnterPassphraseMenu.VisitRegisterWebpage // Terraria.ModLoader.UI.UIEnterSteamIDMenu.VisitRegisterWebpage // "http://javid.ddns.net/tModLoader/register.php" #endregion #region Direct Mod Listing // Terraria.ModLoader.UI.ModBrowser.UIModBrowser.<>c.<ShowOfflineTroubleshootingMessage> // "http://javid.ddns.net/tModLoader/DirectModDownloadListing.php" HarmonyInstance.Patch("Terraria.ModLoader.UI.ModBrowser.UIModBrowser.<>c", "<ShowOfflineTroubleshootingMessage>", exactMatch: false, transpiler: NoroHelper.HarmonyMethod(() => DirectModListingTranspiler(null))); Utils.LogInfo("DirectModListing Patched"); #endregion #region Query Mod Download URL // Terraria.ModLoader.Interface.ServerModBrowserMenu // "http://javid.ddns.net/tModLoader/tools/querymoddownloadurl.php?modname=" #endregion #region Error Report // No plan #endregion #region ModCompile HarmonyInstance.Patch("Terraria.ModLoader.UI.UIDeveloperModeHelp", "DownloadModCompile", transpiler: NoroHelper.HarmonyMethod(() => ModCompileTranspiler(null))); Utils.LogInfo("DownloadModCompile Patched"); #endregion #region Mod Update HarmonyInstance.Patch("Terraria.ModLoader.UI.DownloadManager.DownloadModFile", "PreCopy", prefix: NoroHelper.HarmonyMethod(() => PreCopyPrefix(null))); Utils.LogInfo("PreCopy Patched"); #endregion Utils.LogInfo("ModBrowser Patched"); } catch (Exception e) { Utils.LogInfo($"ModBrowser Patch exception: {e}"); } } try { HarmonyInstance.Patch("Terraria.ModLoader.UI.DownloadManager.DownloadFile", "SetupDownloadRequest", postfix: NoroHelper.HarmonyMethod(() => PostSetupDownloadRequest(null))); Utils.LogInfo("SetupDownloadRequest Patched"); } catch (Exception e) { Utils.LogInfo($"ModBrowser Patch exception: {e}"); } }