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 = ModLoader.LoadBuildProperties(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); }
public void SetMod(ModLoader.LoadingMod mod) { if (modFile == null || modFile.version != mod.modFile.version || !modFile.hash.SequenceEqual(mod.modFile.hash)) SetNeedsReload(); modFile = mod.modFile; properties = mod.properties; }
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); }
private static void LoadMod(TmodFile modFile, BuildProperties properties) { AddAssemblyResolver(); string fileName = Path.GetFileNameWithoutExtension(modFile.Name); Interface.loadMods.SetProgressReading(fileName, 0, 2); Assembly modCode; string rootDirectory; if (modFile.HasFile("All")) { modCode = Assembly.Load(modFile.GetFile("All")); } else { modCode = Assembly.Load(modFile.GetFile(windows ? "Windows" : "Other")); } Interface.loadMods.SetProgressReading(fileName, 1, 2); using (MemoryStream memoryStream = new MemoryStream(modFile.GetFile("Resources"))) { using (BinaryReader reader = new BinaryReader(memoryStream)) { rootDirectory = reader.ReadString(); for (string path = reader.ReadString(); path != "end"; path = reader.ReadString()) { byte[] data = reader.ReadBytes(reader.ReadInt32()); files[path] = data; if (Main.dedServ) { continue; } string extension = Path.GetExtension(path); switch (extension) { case ".png": string texturePath = Path.ChangeExtension(path, null); using (MemoryStream buffer = new MemoryStream(data)) { textures[texturePath] = Texture2D.FromStream(Main.instance.GraphicsDevice, buffer); } break; case ".wav": string soundPath = Path.ChangeExtension(path, null); using (MemoryStream buffer = new MemoryStream(data)) { sounds[soundPath] = SoundEffect.FromStream(buffer); } break; case ".mp3": string mp3Path = Path.ChangeExtension(path, null); string wavCacheFilename = mp3Path.Replace('/', '_') + "_" + properties.version + ".wav"; if (WAVCacheIO.WAVCacheAvailable(wavCacheFilename)) { sounds[mp3Path] = SoundEffect.FromStream(WAVCacheIO.GetWavStream(wavCacheFilename)); break; } ushort wFormatTag = 1; ushort nChannels; uint nSamplesPerSec; uint nAvgBytesPerSec; ushort nBlockAlign; ushort wBitsPerSample = 16; const int headerSize = 44; MemoryStream output = new MemoryStream(headerSize + data.Length); using (MemoryStream yourMp3FileStream = new MemoryStream(data)) { using (MP3Sharp.MP3Stream input = new MP3Sharp.MP3Stream(yourMp3FileStream)) { using (BinaryWriter writer = new BinaryWriter(output, Encoding.UTF8)) { output.Position = headerSize; input.CopyTo(output); UInt32 wavDataLength = (UInt32)output.Length - headerSize; output.Position = 0; nChannels = (ushort)input.ChannelCount; nSamplesPerSec = (uint)input.Frequency; nBlockAlign = (ushort)(nChannels * (wBitsPerSample / 8)); nAvgBytesPerSec = (uint)(nSamplesPerSec * nChannels * (wBitsPerSample / 8)); //write the header writer.Write("RIFF".ToCharArray()); //4 writer.Write((UInt32)(wavDataLength + 36)); // 4 writer.Write("WAVE".ToCharArray()); //4 writer.Write("fmt ".ToCharArray()); //4 writer.Write(16); //4 writer.Write(wFormatTag); // writer.Write((ushort)nChannels); writer.Write(nSamplesPerSec); writer.Write(nAvgBytesPerSec); writer.Write(nBlockAlign); writer.Write(wBitsPerSample); writer.Write("data".ToCharArray()); writer.Write((UInt32)(wavDataLength)); output.Position = 0; WAVCacheIO.SaveWavStream(output, wavCacheFilename); sounds[mp3Path] = SoundEffect.FromStream(output); } } } break; } } } } Type[] classes = modCode.GetTypes(); foreach (Type type in classes) { if (type.IsSubclassOf(typeof(Mod))) { Mod mod = (Mod)Activator.CreateInstance(type); mod.file = modFile.Name; mod.buildVersion = properties.modBuildVersion; mod.code = modCode; mod.Init(); if (mod.Name == "Terraria") { throw new DuplicateNameException("Mods cannot be named Terraria"); } if (mods.ContainsKey(mod.Name)) { throw new DuplicateNameException("Two mods share the internal name " + mod.Name); } if (rootDirectory != mod.Name) { throw new MissingResourceException("Mod name " + mod.Name + " does not match source directory name " + rootDirectory); } mods[mod.Name] = mod; loadOrder.Push(mod.Name); } } }
internal static TmodFile[] FindMods() { Directory.CreateDirectory(ModPath); string[] fileNames = Directory.GetFiles(ModPath, "*.tmod", SearchOption.TopDirectoryOnly); IList<TmodFile> files = new List<TmodFile>(); foreach (string fileName in fileNames) { TmodFile file = new TmodFile(fileName); file.Read(); if (file.ValidMod()) { files.Add(file); } } return files.ToArray(); }
private static void LoadMod(TmodFile modFile, BuildProperties properties) { AddAssemblyResolver(); Interface.loadMods.SetProgressReading(Path.GetFileNameWithoutExtension(modFile.Name)); Assembly modCode; string rootDirectory; if (modFile.HasFile("All")) { modCode = Assembly.Load(modFile.GetFile("All")); } else { modCode = Assembly.Load(modFile.GetFile(windows ? "Windows" : "Other")); } using (MemoryStream memoryStream = new MemoryStream(modFile.GetFile("Resources"))) { using (BinaryReader reader = new BinaryReader(memoryStream)) { memoryStream.Seek(reader.ReadInt32(), SeekOrigin.Current); rootDirectory = reader.ReadString(); for (string path = reader.ReadString(); path != "end"; path = reader.ReadString()) { byte[] data = reader.ReadBytes(reader.ReadInt32()); files[path] = data; string extension = Path.GetExtension(path); switch (extension) { case ".png": string texturePath = Path.ChangeExtension(path, null); using (MemoryStream buffer = new MemoryStream(data)) { textures[texturePath] = Texture2D.FromStream(Main.instance.GraphicsDevice, buffer); } break; case ".wav": string soundPath = Path.ChangeExtension(path, null); using (MemoryStream buffer = new MemoryStream(data)) { sounds[soundPath] = SoundEffect.FromStream(buffer); } break; case ".mp3": // TODO, better way to do this? string mp3Path = Path.ChangeExtension(path, null); MemoryStream wavData = new MemoryStream(); MemoryStream wavFile = new MemoryStream(); ushort wFormatTag = 1; ushort nChannels; uint nSamplesPerSec; uint nAvgBytesPerSec; ushort nBlockAlign; ushort wBitsPerSample = 16; using (MemoryStream buffer = new MemoryStream(data)) { using (MP3Sharp.MP3Stream s = new MP3Sharp.MP3Stream(buffer)) { s.CopyTo(wavData); nChannels = (ushort)s.ChannelCount; nSamplesPerSec = (uint)s.Frequency; } } nBlockAlign = (ushort)(nChannels * (wBitsPerSample / 8)); nAvgBytesPerSec = (uint)(nSamplesPerSec * nChannels * (wBitsPerSample / 8)); using (BinaryWriter bw = new BinaryWriter(wavFile)) { bw.Write("RIFF".ToCharArray()); bw.Write((UInt32)(wavData.Length + 36)); bw.Write("WAVE".ToCharArray()); bw.Write("fmt ".ToCharArray()); bw.Write(16); bw.Write(wFormatTag); bw.Write(nChannels); bw.Write(nSamplesPerSec); bw.Write(nAvgBytesPerSec); bw.Write(nBlockAlign); bw.Write(wBitsPerSample); bw.Write("data".ToCharArray()); bw.Write((UInt32)(wavData.Length)); bw.Write(wavData.ToArray()); } using (MemoryStream buffer = new MemoryStream(wavFile.ToArray())) { sounds[mp3Path] = SoundEffect.FromStream(buffer); } break; } } } } Type[] classes = modCode.GetTypes(); foreach (Type type in classes) { if (type.IsSubclassOf(typeof(Mod))) { Mod mod = (Mod)Activator.CreateInstance(type); mod.file = modFile.Name; mod.code = modCode; mod.Init(); if (mods.ContainsKey(mod.Name)) { throw new DuplicateNameException("Two mods share the internal name " + mod.Name); } if (rootDirectory != mod.Name) { throw new MissingResourceException("Mod name " + mod.Name + " does not match source directory name " + rootDirectory); } mods[mod.Name] = mod; } } }
internal static BuildProperties ReadModFile(TmodFile modFile) { BuildProperties properties = new BuildProperties(); byte[] data; using (MemoryStream memoryStream = new MemoryStream(modFile.GetFile("Info"))) { using (BinaryReader reader = new BinaryReader(memoryStream)) { properties.modBuildVersion = reader.ReadString(); data = reader.ReadBytes(reader.ReadInt32()); } } if (data.Length == 0) { return properties; } using (MemoryStream memoryStream = new MemoryStream(data)) { using (BinaryReader reader = new BinaryReader(memoryStream)) { for (string tag = reader.ReadString(); tag.Length > 0; tag = reader.ReadString()) { if (tag == "dllReferences") { List<string> dllReferences = new List<string>(); for (string reference = reader.ReadString(); reference.Length > 0; reference = reader.ReadString()) { dllReferences.Add(reference); } properties.dllReferences = dllReferences.ToArray(); } if (tag == "modReferences") { List<string> modReferences = new List<string>(); for (string reference = reader.ReadString(); reference.Length > 0; reference = reader.ReadString()) { modReferences.Add(reference); } properties.modReferences = modReferences.ToArray(); } if (tag == "author") { properties.author = reader.ReadString(); } if (tag == "version") { properties.version = reader.ReadString(); } if (tag == "displayName") { properties.displayName = reader.ReadString(); } if (tag == "homepage") { properties.homepage = reader.ReadString(); } if (tag == "description") { properties.description = reader.ReadString(); } if (tag == "noCompile") { properties.noCompile = true; } if (tag == "!hideCode") { properties.hideCode = false; } if (tag == "!hideResources") { properties.hideResources = false; } if (tag == "includeSource") { properties.includeSource = true; } } } } return properties; }
internal static BuildProperties LoadBuildProperties(TmodFile modFile) { BuildProperties properties = new BuildProperties(); byte[] data; using (MemoryStream memoryStream = new MemoryStream(modFile.GetFile("Resources"))) { using (BinaryReader reader = new BinaryReader(memoryStream)) { data = reader.ReadBytes(reader.ReadInt32()); } } if (data.Length == 0) { return properties; } using (MemoryStream memoryStream = new MemoryStream(data)) { using (BinaryReader reader = new BinaryReader(memoryStream)) { for (string tag = reader.ReadString(); tag.Length > 0; tag = reader.ReadString()) { if (tag == "dllReferences") { List<string> dllReferences = new List<string>(); for (string reference = reader.ReadString(); reference.Length > 0; reference = reader.ReadString()) { dllReferences.Add(reference); } properties.dllReferences = dllReferences.ToArray(); } if (tag == "modReferences") { List<string> modReferences = new List<string>(); for (string reference = reader.ReadString(); reference.Length > 0; reference = reader.ReadString()) { modReferences.Add(reference); } properties.modReferences = modReferences.ToArray(); } if (tag == "author") { properties.author = reader.ReadString(); } if (tag == "version") { properties.version = reader.ReadString(); } if (tag == "displayName") { properties.displayName = reader.ReadString(); } } } } return properties; }
private static BuildingMod ReadProperties(string modFolder, IBuildStatus status) { if (modFolder.EndsWith("\\") || modFolder.EndsWith("/")) modFolder = modFolder.Substring(0, modFolder.Length - 1); var modName = Path.GetFileName(modFolder); status.SetStatus("Reading Properties: " + modName); BuildProperties properties; try { properties = BuildProperties.ReadBuildFile(modFolder); } catch (Exception e) { ErrorLogger.LogBuildError("Failed to load " + Path.Combine(modFolder, "build.txt") + Environment.NewLine + e); return null; } var file = Path.Combine(ModPath, modName + ".tmod"); var modFile = new TmodFile(file) { name = modName, version = properties.version }; return new BuildingMod(modFile, properties, modFolder); }
public bool Matches(TmodFile mod) => name == mod.name && version == mod.version && hash.SequenceEqual(mod.hash);
internal static void ReceiveMod(BinaryReader reader) { if (downloadingMod == null) return; try { if (downloadingFile == null) { Interface.downloadMod.SetDownloading(reader.ReadString()); Interface.downloadMod.SetCancel(() => { downloadingFile?.Close(); downloadingMod = null; Netplay.disconnect = true; Main.menuMode = 0; }); Main.menuMode = Interface.downloadModID; downloadingLength = reader.ReadInt64(); downloadingFile = new FileStream(downloadingMod.path, FileMode.Create); return; } var bytes = reader.ReadBytes((int) Math.Min(downloadingLength - downloadingFile.Position, CHUNK_SIZE)); downloadingFile.Write(bytes, 0, bytes.Length); Interface.downloadMod.SetProgress(downloadingFile.Position, downloadingLength); if (downloadingFile.Position == downloadingLength) { downloadingFile.Close(); var mod = new TmodFile(downloadingMod.path); mod.Read(); var ex = mod.ValidMod(); if (ex != null) throw ex; if (!downloadingMod.Matches(mod)) throw new Exception("Hash mismatch"); if (downloadingMod.signed && !mod.ValidModBrowserSignature) throw new Exception("Mod was not signed by the Mod Browser"); ModLoader.EnableMod(mod); if (downloadQueue.Count > 0) DownloadNextMod(); else OnModsDownloaded(true); } } catch (Exception e) { try { downloadingFile?.Close(); } catch {} File.Delete(downloadingMod.path); ErrorLogger.LogException(e, "An error occured while downloading "+downloadingMod.name); downloadingMod = null; } }
private static BuildProperties ReadBuildProperties(string modDir) { string propertiesFile = modDir + Path.DirectorySeparatorChar + "build.txt"; BuildProperties properties = new BuildProperties(); if (!File.Exists(propertiesFile)) { return properties; } string[] lines = File.ReadAllLines(propertiesFile); foreach (string line in lines) { if (line.Length == 0) { continue; } int split = line.IndexOf('='); string property = line.Substring(0, split).Trim(); string value = line.Substring(split + 1).Trim(); if (value.Length == 0) { continue; } switch (property) { case "dllReferences": string[] dllReferences = value.Split(','); for (int k = 0; k < dllReferences.Length; k++) { string dllReference = dllReferences[k].Trim(); if (dllReference.Length > 0) { dllReferences[k] = dllReference; } } properties.dllReferences = dllReferences; break; case "modReferences": string[] modReferences = value.Split(','); for (int k = 0; k < modReferences.Length; k++) { string modReference = modReferences[k].Trim(); if (modReference.Length > 0) { modReferences[k] = modReference; } } properties.modReferences = modReferences; break; case "author": properties.author = value; break; case "version": properties.version = value; break; case "displayName": properties.displayName = value; break; } } foreach (string modReference in properties.modReferences) { TmodFile refFile = new TmodFile(ModPath + Path.DirectorySeparatorChar + modReference + ".tmod"); refFile.Read(); if (!refFile.ValidMod()) { ErrorLogger.LogModReferenceError(refFile.Name); return null; } byte[] data1 = refFile.GetFile("Windows"); byte[] data2 = refFile.GetFile("Other"); string refFileName = ModSourcePath + Path.DirectorySeparatorChar + modReference; File.WriteAllBytes(refFileName + "1.dll", refFile.GetFile("Windows")); File.WriteAllBytes(refFileName + "2.dll", refFile.GetFile("Other")); } return properties; }
private static void LoadMod(TmodFile modFile, BuildProperties properties) { AddAssemblyResolver(); Interface.loadMods.SetProgressReading(Path.GetFileNameWithoutExtension(modFile.Name)); Assembly modCode; string rootDirectory; modCode = Assembly.Load(modFile.GetFile(windows ? "Windows" : "Other")); using (MemoryStream memoryStream = new MemoryStream(modFile.GetFile("Resources"))) { using (BinaryReader reader = new BinaryReader(memoryStream)) { memoryStream.Seek(reader.ReadInt32(), SeekOrigin.Current); rootDirectory = reader.ReadString(); for (string path = reader.ReadString(); path != "end"; path = reader.ReadString()) { byte[] data = reader.ReadBytes(reader.ReadInt32()); files[path] = data; string extension = Path.GetExtension(path); switch (extension) { case ".png": string texturePath = Path.ChangeExtension(path, null); using (MemoryStream buffer = new MemoryStream(data)) { textures[texturePath] = Texture2D.FromStream(Main.instance.GraphicsDevice, buffer); } break; case ".wav": string soundPath = Path.ChangeExtension(path, null); using (MemoryStream buffer = new MemoryStream(data)) { sounds[soundPath] = SoundEffect.FromStream(buffer); } break; } } } } Type[] classes = modCode.GetTypes(); foreach (Type type in classes) { if (type.IsSubclassOf(typeof(Mod))) { Mod mod = (Mod)Activator.CreateInstance(type); mod.file = modFile.Name; mod.code = modCode; mod.Init(); if (mods.ContainsKey(mod.Name)) { throw new DuplicateNameException("Two mods share the internal name " + mod.Name); } if (rootDirectory != mod.Name) { throw new MissingResourceException("Mod name " + mod.Name + " does not match source directory name " + rootDirectory); } mods[mod.Name] = mod; } } }
internal static bool do_BuildMod(object threadContext) { Interface.buildMod.SetReading(); BuildProperties properties = BuildProperties.ReadBuildFile(modToBuild); if (!CreateModReferenceDlls(properties)) { if (!buildAll) { Main.menuMode = Interface.errorMessageID; } return false; } LoadReferences(); byte[] windowsData; byte[] otherData; if (properties.noCompile) { string modDir = modToBuild + Path.DirectorySeparatorChar; if (File.Exists(modDir + "All.dll")) { windowsData = File.ReadAllBytes(modDir + "All.dll"); otherData = File.ReadAllBytes(modDir + "All.dll"); } else if (File.Exists(modDir + "Windows.dll") && File.Exists(modDir + "Other.dll")) { windowsData = File.ReadAllBytes(modDir + "Windows.dll"); otherData = File.ReadAllBytes(modDir + "Other.dll"); } else { ErrorLogger.LogDllBuildError(modToBuild); if (!buildAll) { Main.menuMode = Interface.errorMessageID; } return false; } } else { Interface.buildMod.SetCompiling(0); windowsData = CompileMod(modToBuild, properties, true); Interface.buildMod.SetCompiling(1); otherData = CompileMod(modToBuild, properties, false); if (windowsData == null || otherData == null) { if (!buildAll) { Main.menuMode = Interface.errorMessageID; } return false; } } Interface.buildMod.SetBuildText(); string file = ModPath + Path.DirectorySeparatorChar + Path.GetFileName(modToBuild) + ".tmod"; byte[] propertiesData = properties.ToBytes(); TmodFile modFile = new TmodFile(file); using (MemoryStream memoryStream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(memoryStream)) { writer.Write(version); writer.Write(propertiesData.Length); writer.Write(propertiesData); writer.Flush(); modFile.AddFile("Info", memoryStream.ToArray()); } } using (MemoryStream memoryStream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(memoryStream)) { writer.Write(Path.GetFileName(modToBuild)); string[] resources = Directory.GetFiles(modToBuild, "*", SearchOption.AllDirectories); foreach (string resource in resources) { if (properties.ignoreFile(resource.Replace(modToBuild + Path.DirectorySeparatorChar, null))) { continue; } if (Path.GetExtension(resource) == ".cs" && !properties.includeSource) { continue; } if (Path.GetFileName(resource) == "Thumbs.db") { continue; } if (resource.Substring(modToBuild.Length + 1) == "build.txt") { continue; } string resourcePath = resource.Replace(ModSourcePath + Path.DirectorySeparatorChar, null); resourcePath = resourcePath.Replace(Path.DirectorySeparatorChar, '/'); byte[] buffer = File.ReadAllBytes(resource); writer.Write(resourcePath); writer.Write(buffer.Length); writer.Write(buffer); } writer.Write("end"); writer.Flush(); modFile.AddFile("Resources", memoryStream.ToArray()); } } bool same = windowsData.Length == otherData.Length; if (same) { for (int k = 0; k < windowsData.Length; k++) { if (windowsData[k] != otherData[k]) { same = false; break; } } } if (same) { modFile.AddFile("All", windowsData); } else { modFile.AddFile("Windows", windowsData); modFile.AddFile("Other", otherData); } modFile.Save(); EnableMod(file); if (!buildAll) { Main.menuMode = reloadAfterBuild ? Interface.reloadModsID : 0; } return true; }
private static bool FindReferencedMods(BuildProperties properties, Dictionary<string, LoadingMod> mods) { foreach (var refName in properties.RefNames(true)) { if (mods.ContainsKey(refName)) continue; var modFile = new TmodFile(Path.Combine(ModPath, refName + ".tmod")); modFile.Read(); var ex = modFile.ValidMod(); if (ex != null) { ErrorLogger.LogBuildError("Mod reference " + refName + " " + ex); return false; } var mod = new LoadingMod(modFile, BuildProperties.ReadModFile(modFile)); mods[refName] = mod; FindReferencedMods(mod.properties, mods); } return true; }
internal static bool CreateModReferenceDlls(BuildProperties properties) { TmodFile[] refFiles = new TmodFile[properties.modReferences.Length]; for (int k = 0; k < properties.modReferences.Length; k++) { string modReference = properties.modReferences[k]; string filePath = ModLoader.ModPath + Path.DirectorySeparatorChar + modReference + ".tmod"; TmodFile refFile = new TmodFile(filePath); refFile = new TmodFile(filePath); refFile.Read(); if (!refFile.ValidMod()) { ErrorLogger.LogModReferenceError(refFile.Name); return false; } refFiles[k] = refFile; } for (int k = 0; k < refFiles.Length; k++) { TmodFile refFile = refFiles[k]; string modReference = properties.modReferences[k]; byte[] data1; byte[] data2; if (refFile.HasFile("All")) { data1 = refFile.GetFile("All"); data2 = refFile.GetFile("All"); } else { data1 = refFile.GetFile("Windows"); data2 = refFile.GetFile("Other"); } string refFileName = ModLoader.ModSourcePath + Path.DirectorySeparatorChar + modReference; File.WriteAllBytes(refFileName + "1.dll", data1); File.WriteAllBytes(refFileName + "2.dll", data2); } return true; }
public BuildingMod(TmodFile modFile, BuildProperties properties, string path) : base(modFile, properties) { this.path = path; }
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 += new UIElement.MouseEvent(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 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); 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; } } } }
internal static bool do_BuildMod(object threadContext) { Interface.buildMod.SetReading(); BuildProperties properties = ReadBuildProperties(modToBuild); if (properties == null) { if (!buildAll) { Main.menuMode = Interface.errorMessageID; } return false; } LoadReferences(); string file1 = ModPath + Path.DirectorySeparatorChar + Path.GetFileName(modToBuild) + ".tmod1"; string file2 = ModPath + Path.DirectorySeparatorChar + Path.GetFileName(modToBuild) + ".tmod2"; Interface.buildMod.SetCompiling(); if (!CompileMod(modToBuild, properties, true) || !CompileMod(modToBuild, properties, false)) { File.Delete(file1); File.Delete(file2); if (!buildAll) { Main.menuMode = Interface.errorMessageID; } return false; } Interface.buildMod.SetBuildText(); string file = ModPath + Path.DirectorySeparatorChar + Path.GetFileName(modToBuild) + ".tmod"; byte[] propertiesData = PropertiesToBytes(properties); TmodFile modFile = new TmodFile(file); using (MemoryStream memoryStream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(memoryStream)) { writer.Write(propertiesData.Length); writer.Write(propertiesData); writer.Write(Path.GetFileName(modToBuild)); string[] resources = Directory.GetFiles(modToBuild, "*", SearchOption.AllDirectories); foreach (string resource in resources) { if (Path.GetExtension(resource) == ".cs") { continue; } if (resource.Substring(modToBuild.Length + 1) == "build.txt") { continue; } string resourcePath = resource.Replace(ModSourcePath + Path.DirectorySeparatorChar, null); resourcePath = resourcePath.Replace(Path.DirectorySeparatorChar, '/'); byte[] buffer = File.ReadAllBytes(resource); writer.Write(resourcePath); writer.Write(buffer.Length); writer.Write(buffer); } writer.Write("end"); writer.Flush(); modFile.AddFile("Resources", memoryStream.ToArray()); } } modFile.AddFile("Windows", File.ReadAllBytes(file1)); modFile.AddFile("Other", File.ReadAllBytes(file2)); modFile.Save(); File.Delete(file1); File.Delete(file2); EnableMod(file); if (!buildAll) { Main.menuMode = reloadAfterBuild ? Interface.reloadModsID : 0; } return true; }