public UIModItem(TmodFile mod) { this.mod = mod.Name; this.BorderColor = new Color(89, 116, 213) * 0.7f; this.dividerTexture = TextureManager.Load("Images/UI/Divider"); this.innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground"); this.Height.Set(90f, 0f); this.Width.Set(0f, 1f); base.SetPadding(6f); base.OnClick += new UIElement.MouseEvent(this.ToggleEnabled); BuildProperties properties = BuildProperties.ReadModFile(mod); string text = properties.displayName.Length > 0 ? properties.displayName : Path.GetFileNameWithoutExtension(mod.Name); if (properties.version.Length > 0) { text += " " + properties.version; } if (properties.author.Length > 0) { text += " - by " + properties.author; } this.modName = new UIText(text, 1f, false); this.modName.Left.Set(10f, 0f); this.modName.Top.Set(5f, 0f); base.Append(this.modName); this.enabled = ModLoader.IsEnabled(mod.Name); }
// load Code and Info files into the cache // unfortunately this will recompress files individually which were previously decompressed, but that'll have to do private void Upgrade() { Interface.loadMods.SubProgressText = $"Upgrading: {Path.GetFileName(path)}"; Logging.tML.InfoFormat("Upgrading: {0}", Path.GetFileName(path)); using (var deflateStream = new DeflateStream(fileStream, CompressionMode.Decompress)) using (var reader = new BinaryReader(deflateStream)) { name = reader.ReadString(); version = new Version(reader.ReadString()); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { AddFile(reader.ReadString(), reader.ReadBytes(reader.ReadInt32())); } } // update buildVersion var info = BuildProperties.ReadModFile(this); info.buildVersion = tModLoaderVersion; AddFile("Info", info.ToBytes()); // write to the new format (also updates the file offset table) Save(); // clear all the file contents from AddFile ResetCache(); // Save closes the file so re-open it fileStream = File.OpenRead(path); // Read contract fulfilled }
// load Code and Info files into the cache // unfortunately this will recompress files individually which were previously decompressed, but that'll have to do private void Upgrade() { Interface.loadMods.SubProgressText = $"Upgrading: {Path.GetFileName(path)}"; Logging.tML.InfoFormat("Upgrading: {0}", Path.GetFileName(path)); using (var deflateStream = new DeflateStream(fileStream, CompressionMode.Decompress)) using (var reader = new BinaryReader(deflateStream)) { name = reader.ReadString(); version = new Version(reader.ReadString()); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { AddFile(reader.ReadString(), reader.ReadBytes(reader.ReadInt32())); } } // update buildVersion var info = BuildProperties.ReadModFile(this); info.buildVersion = tModLoaderVersion; AddFile("Info", info.ToBytes()); Save(); Read(); }
private void Publish(UIMouseEvent evt, UIElement listeningElement) { Main.PlaySound(10, -1, -1, 1); try { TmodFile[] modFiles = ModLoader.FindMods(); bool ok = false; TmodFile theTModFile = null; foreach (TmodFile tModFile in modFiles) { if (Path.GetFileName(tModFile.Name).Equals(@Path.GetFileName(mod) + @".tmod")) { ok = true; theTModFile = tModFile; } } if (!ok) { throw new Exception(); } System.Net.ServicePointManager.Expect100Continue = false; string filename = @ModLoader.ModPath + @Path.DirectorySeparatorChar + @Path.GetFileName(mod) + @".tmod"; string url = "http://javid.ddns.net/tModLoader/publishmod.php"; using (var stream = File.Open(filename, FileMode.Open)) { var files = new[] { new IO.UploadFile { Name = "file", Filename = Path.GetFileName(filename), // ContentType = "text/plain", Stream = stream } }; BuildProperties bp = BuildProperties.ReadModFile(theTModFile); var values = new NameValueCollection { { "displayname", bp.displayName }, { "name", Path.GetFileNameWithoutExtension(filename) }, { "version", bp.version }, { "author", bp.author }, { "homepage", bp.homepage }, { "description", bp.description }, { "steamid64", Steamworks.SteamUser.GetSteamID().ToString() }, { "modloaderversion", bp.modBuildVersion }, }; byte[] result = IO.UploadFile.UploadFiles(url, files, values); string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); ErrorLogger.LogModPublish(s); } } catch (WebException e) { ErrorLogger.LogModBrowserException(e); } }
public UIModItem(TmodFile mod) { this.mod = mod.Name; this.BorderColor = new Color(89, 116, 213) * 0.7f; this.dividerTexture = TextureManager.Load("Images/UI/Divider"); this.innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground"); this.Height.Set(90f, 0f); this.Width.Set(0f, 1f); base.SetPadding(6f); //base.OnClick += new UIElement.MouseEvent(this.ToggleEnabled); properties = BuildProperties.ReadModFile(mod); string text = properties.displayName.Length > 0 ? properties.displayName : Path.GetFileNameWithoutExtension(mod.Name); if (properties.version.Length > 0) { text += " " + properties.version; } if (properties.author.Length > 0) { text += " - by " + properties.author; } this.modName = new UIText(text, 1f, false); this.modName.Left.Set(10f, 0f); this.modName.Top.Set(5f, 0f); base.Append(this.modName); this.enabled = ModLoader.IsEnabled(mod.Name); UITextPanel button = new UITextPanel("More info", 1f, false); button.Width.Set(100f, 0f); button.Height.Set(30f, 0f); button.Left.Set(430f, 0f); button.Top.Set(40f, 0f); button.PaddingTop -= 2f; button.PaddingBottom -= 2f; button.OnMouseOver += new UIElement.MouseEvent(FadedMouseOver); button.OnMouseOut += new UIElement.MouseEvent(FadedMouseOut); button.OnClick += new UIElement.MouseEvent(this.Moreinfo); base.Append(button); button2 = new UITextPanel(this.enabled ? "Click to Disable" : "Click to Enable", 1f, false); button2.Width.Set(100f, 0f); button2.Height.Set(30f, 0f); button2.Left.Set(275f, 0f); button2.Top.Set(40f, 0f); button2.PaddingTop -= 2f; button2.PaddingBottom -= 2f; button2.OnMouseOver += new UIElement.MouseEvent(FadedMouseOver); button2.OnMouseOut += new UIElement.MouseEvent(FadedMouseOut); button2.OnClick += new UIElement.MouseEvent(this.ToggleEnabled); base.Append(button2); }
public void UploadComplete(object sender, UploadValuesCompletedEventArgs e) { if (e.Error != null) { if (e.Cancelled) { } else { HttpStatusCode httpStatusCode = GetHttpStatusCode(e.Error); if (httpStatusCode == HttpStatusCode.ServiceUnavailable) { SetHeading("Mod Browser OFFLINE (Busy)"); } else { SetHeading("Mod Browser OFFLINE (Unknown)"); } } loading = false; reloadButton.SetText("Reload browser"); } else if (!e.Cancelled) { reloadButton.SetText("Populating browser..."); byte[] result = e.Result; string response = Encoding.UTF8.GetString(result); if (SynchronizationContext.Current == null) { SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); } Task.Factory .StartNew(ModLoader.FindMods) .ContinueWith(task => { TmodFile[] modFiles = task.Result; List <BuildProperties> modBuildProperties = new List <BuildProperties>(); foreach (TmodFile tmodfile in modFiles) { modBuildProperties.Add(BuildProperties.ReadModFile(tmodfile)); } PopulateFromJSON(modBuildProperties, response); loading = false; reloadButton.SetText("Reload browser"); }, TaskScheduler.FromCurrentSynchronizationContext()); } }
private void Upgrade() { Interface.loadMods.SubProgressText = $"Upgrading: {Path.GetFileName(path)}"; Logging.tML.InfoFormat("Upgrading: {0}", Path.GetFileName(path)); using (var deflateStream = new DeflateStream(fileStream, CompressionMode.Decompress, true)) using (var reader = new BinaryReader(deflateStream)) { name = reader.ReadString(); version = new Version(reader.ReadString()); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { AddFile(reader.ReadString(), reader.ReadBytes(reader.ReadInt32())); } } // update buildVersion var info = BuildProperties.ReadModFile(this); info.buildVersion = tModLoaderVersion; // TODO should be turn this into .info? Generally files starting with . are ignored, at least on Windows (and are much harder to accidentally delete or even manually create) AddFile("Info", info.ToBytes()); // make a backup fileStream.Seek(0, SeekOrigin.Begin); var backupFolder = Path.Combine(Path.GetDirectoryName(path), "UpgradeBackup"); Directory.CreateDirectory(backupFolder); using (var backupStream = File.OpenWrite(Path.Combine(backupFolder, Path.GetFileName(path)))) fileStream.CopyTo(backupStream); // write to the new format (also updates the file offset table) Save(); // clear all the file contents from AddFile ResetCache(); // Save closes the file so re-open it fileStream = File.OpenRead(path); // Read contract fulfilled }
public void UploadComplete(Object sender, UploadValuesCompletedEventArgs e) { if (e.Error != null) { if (e.Cancelled) { } else { HttpStatusCode httpStatusCode = GetHttpStatusCode(e.Error); if (httpStatusCode == HttpStatusCode.ServiceUnavailable) { SetHeading("Mod Browser OFFLINE (Busy)"); } else { SetHeading("Mod Browser OFFLINE (Unknown)"); } } } else if (!e.Cancelled) { byte[] result = e.Result; string response = System.Text.Encoding.UTF8.GetString(result); // TODO: UI will still be unresponsive here TmodFile[] modFiles = ModLoader.FindMods(); List <BuildProperties> modBuildProperties = new List <BuildProperties>(); foreach (TmodFile tmodfile in modFiles) { modBuildProperties.Add(BuildProperties.ReadModFile(tmodfile)); } PopulateFromJSON(modBuildProperties, response); } loading = false; reloadButton.SetText("Reload Mods"); }
private void Publish(UIMouseEvent evt, UIElement listeningElement) { if (ModLoader.modBrowserPassphrase == "") { Main.menuMode = Interface.enterPassphraseMenuID; Interface.enterPassphraseMenu.SetGotoMenu(Interface.modSourcesID); return; } Main.PlaySound(10, -1, -1, 1); try { TmodFile[] modFiles = ModLoader.FindMods(); bool ok = false; TmodFile theTModFile = null; foreach (TmodFile tModFile in modFiles) { if (Path.GetFileName(tModFile.path).Equals(@Path.GetFileName(mod) + @".tmod")) { ok = true; theTModFile = tModFile; } } if (!ok) { throw new Exception(); } System.Net.ServicePointManager.Expect100Continue = false; string filename = @ModLoader.ModPath + @Path.DirectorySeparatorChar + @Path.GetFileName(mod) + @".tmod"; string url = "http://javid.ddns.net/tModLoader/publishmod.php"; byte[] result; using (var stream = File.Open(filename, FileMode.Open)) { var files = new[] { new IO.UploadFile { Name = "file", Filename = Path.GetFileName(filename), // ContentType = "text/plain", Stream = stream } }; BuildProperties bp = BuildProperties.ReadModFile(theTModFile); var values = new NameValueCollection { { "displayname", bp.displayName }, { "name", Path.GetFileNameWithoutExtension(filename) }, { "version", "v" + bp.version }, { "author", bp.author }, { "homepage", bp.homepage }, { "description", bp.description }, { "steamid64", ModLoader.SteamID64 }, { "modloaderversion", "tModLoader v" + theTModFile.tModLoaderVersion }, { "passphrase", ModLoader.modBrowserPassphrase } }; result = IO.UploadFile.UploadFiles(url, files, values); } int responseLength = result.Length; if (result.Length > 256 && result[result.Length - 256 - 1] == '~') { Array.Copy(result, result.Length - 256, theTModFile.signature, 0, 256); theTModFile.Save(); responseLength -= 257; } string s = System.Text.Encoding.UTF8.GetString(result, 0, responseLength); ErrorLogger.LogModPublish(s); } catch (WebException e) { ErrorLogger.LogModBrowserException(e); } }
public UIModItem(TmodFile mod) { this.mod = mod; this.BorderColor = new Color(89, 116, 213) * 0.7f; this.dividerTexture = TextureManager.Load("Images/UI/Divider"); this.innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground"); this.Height.Set(90f, 0f); this.Width.Set(0f, 1f); base.SetPadding(6f); //base.OnClick += this.ToggleEnabled; properties = BuildProperties.ReadModFile(mod); string text = properties.displayName.Length > 0 ? properties.displayName : mod.name; text += " v" + mod.version; if (mod.tModLoaderVersion < new Version(0, 10)) { text += " [c/FF0000:(Old mod, enable at own risk)]"; } int modIconAdjust = 0; if (mod.HasFile("icon.png")) { var modIconTexture = Texture2D.FromStream(Main.instance.GraphicsDevice, new MemoryStream(mod.GetFile("icon.png"))); if (modIconTexture.Width == 80 && modIconTexture.Height == 80) { modIcon = new UIImage(modIconTexture); modIcon.Left.Set(0f, 0f); modIcon.Top.Set(0f, 0f); Append(modIcon); modIconAdjust += 85; } } this.modName = new UIText(text, 1f, false); this.modName.Left.Set(modIconAdjust + 10f, 0f); this.modName.Top.Set(5f, 0f); base.Append(this.modName); this.enabled = ModLoader.IsEnabled(mod); UITextPanel <string> button = new UITextPanel <string>(Language.GetTextValue("tModLoader.ModsMoreInfo"), 1f, false); button.Width.Set(100f, 0f); button.Height.Set(30f, 0f); button.Left.Set(430f, 0f); button.Top.Set(40f, 0f); button.PaddingTop -= 2f; button.PaddingBottom -= 2f; button.OnMouseOver += UICommon.FadedMouseOver; button.OnMouseOut += UICommon.FadedMouseOut; button.OnClick += this.Moreinfo; base.Append(button); button2 = new UITextPanel <string>(this.enabled ? Language.GetTextValue("tModLoader.ModsDisable") : Language.GetTextValue("tModLoader.ModsEnable"), 1f, false); button2.Width.Set(100f, 0f); button2.Height.Set(30f, 0f); button2.Left.Set(button.Left.Pixels - button2.Width.Pixels - 5f, 0f); button2.Top.Set(40f, 0f); button2.PaddingTop -= 2f; button2.PaddingBottom -= 2f; button2.OnMouseOver += UICommon.FadedMouseOver; button2.OnMouseOut += UICommon.FadedMouseOut; button2.OnClick += this.ToggleEnabled; base.Append(button2); if (properties.modReferences.Length > 0 && !enabled) { string refs = String.Join(", ", properties.modReferences.Select(x => x.mod)); Texture2D icon = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.ButtonExclamation.png")); UIHoverImage modReferenceIcon = new UIHoverImage(icon, "This mod depends on: " + refs + "\n (click to enable)"); modReferenceIcon.Left.Set(button2.Left.Pixels - 24f, 0f); modReferenceIcon.Top.Set(47f, 0f); modReferenceIcon.OnClick += (a, b) => { var referencedMods = properties.modReferences.Select(x => x.mod); var foundMods = ModLoader.FindMods(); var referencedtModFiles = foundMods.Where(x => referencedMods.Contains(x.name)); foreach (var referencedMod in referencedtModFiles) { ModLoader.EnableMod(referencedMod); } Main.menuMode = Interface.modsMenuID; var missingMods = referencedMods.Where(modstring => foundMods.All(modfile => modfile.name != modstring)); if (missingMods.Count() > 0) { Interface.infoMessage.SetMessage("The following mods were not found: " + String.Join(",", missingMods)); Interface.infoMessage.SetGotoMenu(Interface.modsMenuID); Main.menuMode = Interface.infoMessageID; } }; base.Append(modReferenceIcon); } if (mod.ValidModBrowserSignature) { keyImage = new UIHoverImage(Main.itemTexture[ID.ItemID.GoldenKey], Language.GetTextValue("tModLoader.ModsOriginatedFromModBrowser")); keyImage.Left.Set(-20, 1f); base.Append(keyImage); } if (ModLoader.ModLoaded(mod.name)) { Mod loadedMod = ModLoader.GetMod(mod.name); int[] values = { loadedMod.items.Count, loadedMod.npcs.Count, loadedMod.tiles.Count, loadedMod.walls.Count, loadedMod.buffs.Count, loadedMod.mountDatas.Count }; string[] strings = { " items", " NPCs", " tiles", " walls", " buffs", " mounts" }; int xOffset = -40; for (int i = 0; i < values.Length; i++) { if (values[i] > 0) { Texture2D iconTexture = Main.instance.infoIconTexture[i]; keyImage = new UIHoverImage(iconTexture, values[i] + strings[i]); keyImage.Left.Set(xOffset, 1f); base.Append(keyImage); xOffset -= 18; } } } }
public override void OnActivate() { if (!loaded) { modList.Clear(); TmodFile[] modFiles = ModLoader.FindMods(); List <BuildProperties> modBuildProperties = new List <BuildProperties>(); foreach (TmodFile tmodfile in modFiles) { modBuildProperties.Add(BuildProperties.ReadModFile(tmodfile)); } XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc = GetDataFromUrl("http://javid.ddns.net/tModLoader/listmods.php"); } catch (WebException e) { if (e.Status == WebExceptionStatus.Timeout) { uITextPanel.SetText("Mod Browser OFFLINE", 0.8f, true); return; } } catch (Exception e) { ErrorLogger.LogModBrowserException(e); return; } foreach (XmlNode xmlNode in xmlDoc.DocumentElement) { string displayname = xmlNode.SelectSingleNode("displayname").InnerText; string name = xmlNode.SelectSingleNode("name").InnerText; string version = xmlNode.SelectSingleNode("version").InnerText; string author = xmlNode.SelectSingleNode("author").InnerText; string description = xmlNode.SelectSingleNode("description").InnerText; string download = xmlNode.SelectSingleNode("download").InnerText; string timeStamp = xmlNode.SelectSingleNode("updateTimeStamp").InnerText; int downloads; Int32.TryParse(xmlNode.SelectSingleNode("downloads").InnerText, out downloads); bool exists = false; bool update = false; foreach (BuildProperties bp in modBuildProperties) { if (bp.displayName.Equals(displayname)) { exists = true; if (!bp.version.Equals(version)) { update = true; } } } // if (!exists || update) // { UIModDownloadItem modItem = new UIModDownloadItem(/*this, */ displayname, name, version, author, description, download, downloads, timeStamp, update, exists); modList.Add(modItem); // } } loaded = true; } }
public UIModItem(TmodFile mod) { this.mod = mod; this.BorderColor = new Color(89, 116, 213) * 0.7f; this.dividerTexture = TextureManager.Load("Images/UI/Divider"); this.innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground"); this.Height.Set(90f, 0f); this.Width.Set(0f, 1f); base.SetPadding(6f); //base.OnClick += this.ToggleEnabled; properties = BuildProperties.ReadModFile(mod); string text = properties.displayName.Length > 0 ? properties.displayName : mod.name; text += " v" + mod.version; if (properties.author.Length > 0) { text += " - by " + properties.author; } this.modName = new UIText(text, 1f, false); this.modName.Left.Set(10f, 0f); this.modName.Top.Set(5f, 0f); base.Append(this.modName); this.enabled = ModLoader.IsEnabled(mod); UITextPanel <string> button = new UITextPanel <string>("More info", 1f, false); button.Width.Set(100f, 0f); button.Height.Set(30f, 0f); button.Left.Set(430f, 0f); button.Top.Set(40f, 0f); button.PaddingTop -= 2f; button.PaddingBottom -= 2f; button.OnMouseOver += UICommon.FadedMouseOver; button.OnMouseOut += UICommon.FadedMouseOut; button.OnClick += this.Moreinfo; base.Append(button); button2 = new UITextPanel <string>(this.enabled ? "Click to Disable" : "Click to Enable", 1f, false); button2.Width.Set(100f, 0f); button2.Height.Set(30f, 0f); button2.Left.Set(275f, 0f); button2.Top.Set(40f, 0f); button2.PaddingTop -= 2f; button2.PaddingBottom -= 2f; button2.OnMouseOver += UICommon.FadedMouseOver; button2.OnMouseOut += UICommon.FadedMouseOut; button2.OnClick += this.ToggleEnabled; base.Append(button2); if (mod.ValidModBrowserSignature) { keyImage = new UIHoverImage(Main.itemTexture[ID.ItemID.GoldenKey], "This mod originated from the Mod Browser"); keyImage.Left.Set(-20, 1f); base.Append(keyImage); } if (ModLoader.ModLoaded(mod.name)) { Mod loadedMod = ModLoader.GetMod(mod.name); int[] values = { loadedMod.items.Count, loadedMod.npcs.Count, loadedMod.tiles.Count, loadedMod.walls.Count, loadedMod.buffs.Count, loadedMod.mountDatas.Count }; string[] strings = { " items", " NPCs", " tiles", " walls", " buffs", " mounts" }; int xOffset = -40; for (int i = 0; i < values.Length; i++) { if (values[i] > 0) { Texture2D iconTexture = ModLoader.GetTexture("Terraria/UI" + Path.DirectorySeparatorChar + "InfoIcon_" + i); keyImage = new UIHoverImage(iconTexture, values[i] + strings[i]); keyImage.Left.Set(xOffset, 1f); base.Append(keyImage); xOffset -= 18; } } } }
public UIModItem(TmodFile mod) { this.mod = mod; this.BorderColor = new Color(89, 116, 213) * 0.7f; this.dividerTexture = TextureManager.Load("Images/UI/Divider"); this.innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground"); this.Height.Set(90f, 0f); this.Width.Set(0f, 1f); base.SetPadding(6f); //base.OnClick += this.ToggleEnabled; properties = BuildProperties.ReadModFile(mod); string text = properties.displayName.Length > 0 ? properties.displayName : mod.name; text += " v" + mod.version; if (mod.tModLoaderVersion < new Version(0, 10)) { text += " [c/FF0000:(Old mod, enable at own risk)]"; } this.modName = new UIText(text, 1f, false); this.modName.Left.Set(10f, 0f); this.modName.Top.Set(5f, 0f); base.Append(this.modName); this.enabled = ModLoader.IsEnabled(mod); UITextPanel <string> button = new UITextPanel <string>("More info", 1f, false); button.Width.Set(100f, 0f); button.Height.Set(30f, 0f); button.Left.Set(430f, 0f); button.Top.Set(40f, 0f); button.PaddingTop -= 2f; button.PaddingBottom -= 2f; button.OnMouseOver += UICommon.FadedMouseOver; button.OnMouseOut += UICommon.FadedMouseOut; button.OnClick += this.Moreinfo; base.Append(button); button2 = new UITextPanel <string>(this.enabled ? "Disable" : "Enable", 1f, false); button2.Width.Set(100f, 0f); button2.Height.Set(30f, 0f); button2.Left.Set(button.Left.Pixels - button2.Width.Pixels - 5f, 0f); button2.Top.Set(40f, 0f); button2.PaddingTop -= 2f; button2.PaddingBottom -= 2f; button2.OnMouseOver += UICommon.FadedMouseOver; button2.OnMouseOut += UICommon.FadedMouseOut; button2.OnClick += this.ToggleEnabled; base.Append(button2); if (properties.modReferences.Length > 0 && !enabled) { string refs = String.Join(", ", properties.modReferences.Select(x => x.mod)); UIHoverImage modReferenceIcon = new UIHoverImage(Main.quicksIconTexture, "This mod depends on: " + refs); modReferenceIcon.Left.Set(button2.Left.Pixels - 10f, 0f); modReferenceIcon.Top.Set(50f, 0f); base.Append(modReferenceIcon); } if (mod.ValidModBrowserSignature) { keyImage = new UIHoverImage(Main.itemTexture[ID.ItemID.GoldenKey], "This mod originated from the Mod Browser"); keyImage.Left.Set(-20, 1f); base.Append(keyImage); } if (ModLoader.ModLoaded(mod.name)) { Mod loadedMod = ModLoader.GetMod(mod.name); int[] values = { loadedMod.items.Count, loadedMod.npcs.Count, loadedMod.tiles.Count, loadedMod.walls.Count, loadedMod.buffs.Count, loadedMod.mountDatas.Count }; string[] strings = { " items", " NPCs", " tiles", " walls", " buffs", " mounts" }; int xOffset = -40; for (int i = 0; i < values.Length; i++) { if (values[i] > 0) { Texture2D iconTexture = Main.instance.infoIconTexture[i]; keyImage = new UIHoverImage(iconTexture, values[i] + strings[i]); keyImage.Left.Set(xOffset, 1f); base.Append(keyImage); xOffset -= 18; } } } }
public override void OnActivate() { if (!loaded) { uITextPanel.SetText("Mod Browser", 0.8f, true); modListAll.Clear(); TmodFile[] modFiles = ModLoader.FindMods(); List <BuildProperties> modBuildProperties = new List <BuildProperties>(); foreach (TmodFile tmodfile in modFiles) { modBuildProperties.Add(BuildProperties.ReadModFile(tmodfile)); } XmlDocument xmlDoc = new XmlDocument(); try { // xmlDoc = GetDataFromUrl("http://javid.ddns.net/tModLoader/listmods.php"); System.Net.ServicePointManager.Expect100Continue = false; string url = "http://javid.ddns.net/tModLoader/listmods.php"; IO.UploadFile[] files = new IO.UploadFile[0]; var values = new NameValueCollection { { "modloaderversion", ModLoader.version }, }; byte[] result = IO.UploadFile.UploadFiles(url, files, values); xmlDoc.LoadXml(System.Text.Encoding.UTF8.GetString(result, 0, result.Length)); } catch (WebException e) { if (e.Status == WebExceptionStatus.Timeout) { uITextPanel.SetText("Mod Browser OFFLINE (Busy)", 0.8f, true); return; } if (e.Status == WebExceptionStatus.ProtocolError) { var resp = (HttpWebResponse)e.Response; if (resp.StatusCode == HttpStatusCode.NotFound) { uITextPanel.SetText("Mod Browser OFFLINE (404)", 0.8f, true); return; } uITextPanel.SetText("Mod Browser OFFLINE..", 0.8f, true); return; } } catch (Exception e) { ErrorLogger.LogModBrowserException(e); return; } try { foreach (XmlNode xmlNode in xmlDoc.DocumentElement) { if (xmlNode.Name.Equals("update")) { updateAvailable = true; updateText = xmlNode.SelectSingleNode("message").InnerText; updateURL = xmlNode.SelectSingleNode("url").InnerText; } else if (xmlNode.Name.Equals("modlist")) { foreach (XmlNode xmlNode2 in xmlNode) { string displayname = xmlNode2.SelectSingleNode("displayname").InnerText; string name = xmlNode2.SelectSingleNode("name").InnerText; string version = xmlNode2.SelectSingleNode("version").InnerText; string author = xmlNode2.SelectSingleNode("author").InnerText; string description = xmlNode2.SelectSingleNode("description").InnerText; string homepage = xmlNode2.SelectSingleNode("homepage").InnerText; string download = xmlNode2.SelectSingleNode("download").InnerText; string timeStamp = xmlNode2.SelectSingleNode("updateTimeStamp").InnerText; int downloads; Int32.TryParse(xmlNode2.SelectSingleNode("downloads").InnerText, out downloads); bool exists = false; bool update = false; foreach (BuildProperties bp in modBuildProperties) { if (bp.displayName.Equals(displayname)) { exists = true; if (!bp.version.Equals(version)) { update = true; } } } UIModDownloadItem modItem = new UIModDownloadItem(displayname, name, version, author, description, homepage, download, downloads, timeStamp, update, exists); modListAll.Add(modItem); } SortList(null, null); } } } catch (Exception e) { ErrorLogger.LogModBrowserException(e); return; } loaded = true; } }
private void Publish(UIMouseEvent evt, UIElement listeningElement) { if (ModLoader.modBrowserPassphrase == "") { Main.menuMode = Interface.enterPassphraseMenuID; Interface.enterPassphraseMenu.SetGotoMenu(Interface.modSourcesID); return; } Main.PlaySound(10, -1, -1, 1); try { TmodFile[] modFiles = ModLoader.FindMods(); bool ok = false; TmodFile theTModFile = null; foreach (TmodFile tModFile in modFiles) { if (Path.GetFileName(tModFile.path).Equals(@Path.GetFileName(mod) + @".tmod")) { ok = true; theTModFile = tModFile; } } if (!ok) { throw new Exception(); } System.Net.ServicePointManager.Expect100Continue = false; string filename = @ModLoader.ModPath + @Path.DirectorySeparatorChar + @Path.GetFileName(mod) + @".tmod"; string url = "http://javid.ddns.net/tModLoader/publishmod.php"; using (var iconStream = theTModFile.HasFile("icon.png") ? new MemoryStream(theTModFile.GetFile("icon.png")) : null) using (var stream = File.Open(filename, FileMode.Open)) { var files = new List <UploadFile>(); files.Add(new IO.UploadFile { Name = "file", Filename = Path.GetFileName(filename), // ContentType = "text/plain", Stream = stream } ); if (iconStream != null) { files.Add(new IO.UploadFile { Name = "iconfile", Filename = "icon.png", Stream = iconStream } ); } BuildProperties bp = BuildProperties.ReadModFile(theTModFile); var values = new NameValueCollection { { "displayname", bp.displayName }, { "name", Path.GetFileNameWithoutExtension(filename) }, { "version", "v" + bp.version }, { "author", bp.author }, { "homepage", bp.homepage }, { "description", bp.description }, { "steamid64", ModLoader.SteamID64 }, { "modloaderversion", "tModLoader v" + theTModFile.tModLoaderVersion }, { "passphrase", ModLoader.modBrowserPassphrase }, { "modreferences", String.Join(", ", bp.modReferences.Select(x => x.mod)) }, { "modside", bp.side.ToFriendlyString() }, }; using (PatientWebClient client = new PatientWebClient()) { ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return(true); }); Interface.uploadMod.SetDownloading(Path.GetFileNameWithoutExtension(filename)); Interface.uploadMod.SetCancel(() => { Main.menuMode = Interface.modSourcesID; client.CancelAsync(); }); client.UploadProgressChanged += (s, e) => Interface.uploadMod.SetProgress(e); client.UploadDataCompleted += (s, e) => PublishUploadDataComplete(s, e, theTModFile); var boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x", System.Globalization.NumberFormatInfo.InvariantInfo); client.Headers["Content-Type"] = "multipart/form-data; boundary=" + boundary; boundary = "--" + boundary; byte[] data = IO.UploadFile.GetUploadFilesRequestData(files, values); client.UploadDataAsync(new Uri(url), data); } Main.menuMode = Interface.uploadModID; } } catch (WebException e) { ErrorLogger.LogModBrowserException(e); } }
private Exception _Extract(TmodFile mod) { StreamWriter log = null; try { var dir = Path.Combine(Main.SavePath, "Mod Reader", mod.name); if (Directory.Exists(dir)) { Directory.Delete(dir, true); } Directory.CreateDirectory(dir); log = new StreamWriter(Path.Combine(dir, "tModReader.txt")) { AutoFlush = true }; var buildProperties = BuildProperties.ReadModFile(mod); if (buildProperties.hideCode) { log.WriteLine("The modder has chosen to hide the code from tModReader."); } else if (!buildProperties.includeSource) { log.WriteLine("The modder has not chosen to include their source code."); } if (buildProperties.hideResources) { log.WriteLine("The modder has chosen to hide resources (ie. images) from tModReader."); } log.WriteLine("Files:"); int i = 0; foreach (var entry in mod) { var name = entry.Key; //this access is not threadsafe, but it should be atomic enough to not cause issues loadProgress.SetText(name); loadProgress.SetProgress(i++ / (float)mod.FileCount); bool hidden = codeExtensions.Contains(Path.GetExtension(name)) ? buildProperties.hideCode : buildProperties.hideResources; if (hidden) { log.Write("[hidden] "); } log.WriteLine(name); if (!hidden) { var path = Path.Combine(dir, name); Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllBytes(path, entry.Value); } } } catch (Exception e) { log?.WriteLine(e); return(e); } finally { log?.Close(); } return(null); }