public static string GetVerboseModInfo(Mod mod, BuildPropertiesEditor editor) { string info = ""; if (editor.ModReferences.Count > 0) { IEnumerable <string> depMods = editor.ModReferences.SafeSelect((kv2) => { string depMod = kv2.Key; if (kv2.Value != default(Version)) { depMod += "@" + kv2.Value.ToString(); } return(depMod); }); info += "mod dependencies: [" + string.Join(", ", depMods) + "]"; } if (editor.DllReferences.Length > 0) { info += ", dll dependencies: [" + string.Join(", ", editor.DllReferences) + "]"; } return(info); }
public static string GetBasicModInfo(Mod mod, BuildPropertiesEditor editor) { string info = mod.DisplayName + " v" + mod.Version + " by " + editor.Author; if (editor.Side != ModSide.Both) { info += " (" + Enum.GetName(typeof(ModSide), editor.Side) + " only)"; } return(info); }
public string GetModDataFromActiveMod(string modName, string fieldName) { Mod mod = ModLoader.GetMod(modName); if (mod == null) { return(null); } var buildEdit = BuildPropertiesEditor.GetBuildPropertiesForModFile(mod.File); string data = (string)buildEdit.GetField(fieldName); return(string.IsNullOrEmpty(data) ? "" : data); }
private IList <Tuple <string, string> > GetRecommendsFromActiveMod(string modName) { Mod mod = ModLoader.GetMod(modName); if (mod == null) { return(null); } //byte[] fileData = ModHelpers.UnsafeLoadFileFromMod( mod.File, "description.txt" ); //recommendations.txt //if( fileData == null ) { // return new List<Tuple<string, string>>(); //} var buildEdit = BuildPropertiesEditor.GetBuildPropertiesForModFile(mod.File); string description = (string)buildEdit.GetField("description"); byte[] descData = Encoding.UTF8.GetBytes(string.IsNullOrEmpty(description) ? "" : description); return(this.ParseRecommendationsFromModDescription(descData)); }
public UIModData(UITheme theme, int?idx, Mod mod, bool will_draw_own_hover_elements = true) { var self = this; TmodFile modfile = mod.File; this.Mod = mod; this.WillDrawOwnHoverElements = will_draw_own_hover_elements; this.Author = null; this.HomepageUrl = null; this.HasIconLoaded = false; this.LatestAvailableVersion = default(Version); if (HamstarHelpersMod.Instance.Config.IsCheckingModVersions) { BuildPropertiesEditor props = modfile != null? BuildPropertiesEditor.GetBuildPropertiesForModFile(modfile) : (BuildPropertiesEditor)null; if (props != null) { this.Author = (string)props.GetField("author"); this.HomepageUrl = (string)props.GetField("homepage"); } } // Container this.SetPadding(4f); this.Width.Set(0f, 1f); this.Height.Set(64, 0f); float title_offset = 72f; // Mod index if (idx != null) { var mod_idx_elem = new UIText((int)idx + ""); mod_idx_elem.Left.Set(title_offset, 0f); this.Append((UIElement)mod_idx_elem); title_offset += 16f; } // Mod title string mod_title = this.Mod.DisplayName + " " + this.Mod.Version.ToString(); if (!String.IsNullOrEmpty(this.HomepageUrl)) { this.TitleElem = new UIWebUrl(theme, mod_title, this.HomepageUrl, false); } else { this.TitleElem = new UIText(mod_title); } this.TitleElem.Left.Set(88f, 0f); this.Append((UIElement)this.TitleElem); // Mod author if (this.Author != null) { this.AuthorElem = new UIText("By: " + this.Author, 0.7f); this.AuthorElem.Top.Set(20f, 0f); this.AuthorElem.Left.Set(title_offset, 0f); this.Append((UIElement)this.AuthorElem); } // Mod icon if (modfile != null && modfile.HasFile("icon.png")) { var stream = new MemoryStream(modfile.GetFile("icon.png")); var icon_tex = Texture2D.FromStream(Main.graphics.GraphicsDevice, stream); if (icon_tex.Width == 80 && icon_tex.Height == 80) { this.IconElem = new UIImage(icon_tex); this.IconElem.Top.Set(-4f, 0f); this.IconElem.Left.Set(-4f, 0f); this.IconElem.MarginTop = -8f; this.IconElem.MarginLeft = -4f; this.IconElem.ImageScale = 0.7f; this.Append(this.IconElem); } } // Mod config button if (ModMetaDataManager.HasConfig(mod)) { var config_button = new UITextPanelButton(theme, "Open Config File"); config_button.Width.Set(160f, 0f); config_button.HAlign = 1f; config_button.VAlign = 1f; this.Append(config_button); this.ConfigButton = config_button; this.ConfigButton.OnClick += delegate(UIMouseEvent evt, UIElement from_elem) { string path = ModMetaDataManager.GetConfigRelativePath(mod); string fullpath = Main.SavePath + Path.DirectorySeparatorChar + path; try { Process.Start(fullpath); } catch (Exception e) { try { string dir = new FileInfo(fullpath).Directory.FullName; Process.Start(dir); } catch (Exception) { } Main.NewText("Couldn't open config file " + path + ": " + e.Message, Color.Red); } }; } }