Пример #1
0
        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);
        }
Пример #2
0
        public static string GetEacPath()
        {
            string GetEacPathInternal()
            {
                var propFile = Instance.GetFileStream("Info");

                var buildProp = Tr().GetType("Terraria.ModLoader.Core.BuildProperties")
                                .Method("ReadFromStream", propFile);

                var eacPath = buildProp.Field("eacPath") as string;

                return(eacPath);
            }

            if (TmodFile.IsOpen)
            {
                return(GetEacPathInternal());
            }

            using (TmodFile.Open())
            {
                return(GetEacPathInternal());
            }
        }
Пример #3
0
 public BuildingMod(TmodFile modFile, BuildProperties properties, string path) : base(modFile, properties)
 {
     this.path = path;
 }
Пример #4
0
        private void PublishUploadDataComplete(object s, UploadDataCompletedEventArgs e, TmodFile theTModFile)
        {
            if (e.Error != null)
            {
                if (e.Cancelled)
                {
                    Main.menuMode = Interface.modSourcesID;
                    return;
                }
                UIModBrowser.LogModBrowserException(e.Error);
                return;
            }
            var result         = e.Result;
            int responseLength = result.Length;

            if (result.Length > 256 && result[result.Length - 256 - 1] == '~')
            {
                using (var fileStream = File.Open(theTModFile.path, FileMode.Open, FileAccess.ReadWrite))
                    using (var fileReader = new BinaryReader(fileStream))
                        using (var fileWriter = new BinaryWriter(fileStream)) {
                            fileReader.ReadBytes(4);                           // "TMOD"
                            fileReader.ReadString();                           // ModLoader.version.ToString()
                            fileReader.ReadBytes(20);                          // hash
                            if (fileStream.Length - fileStream.Position > 256) // Extrememly basic check in case ReadString errors?
                            {
                                fileWriter.Write(result, result.Length - 256, 256);
                            }
                        }
                responseLength -= 257;
            }
            string response = Encoding.UTF8.GetString(result, 0, responseLength);

            UIModBrowser.LogModPublishInfo(response);
        }
Пример #5
0
        private static void PublishUploadDataComplete(object s, UploadDataCompletedEventArgs e, TmodFile theTModFile)
        {
            if (e.Error != null)
            {
                if (e.Cancelled)
                {
                    Main.menuMode = Interface.modSourcesID;
                    return;
                }
                UIModBrowser.LogModBrowserException(e.Error);
                return;
            }

            if (ModLoader.TryGetMod(theTModFile.Name, out var mod))
            {
                mod.Close();
            }

            var    result   = e.Result;
            string response = HandlePublishResponse(theTModFile, result);

            UIModBrowser.LogModPublishInfo(response);
        }
Пример #6
0
 internal static void DisableMod(TmodFile mod)
 {
     SetModActive(mod, false);
 }
Пример #7
0
        internal static bool IsEnabled(TmodFile mod)
        {
            string enablePath = Path.ChangeExtension(mod.path, "enabled");

            return(!File.Exists(enablePath) || File.ReadAllText(enablePath) != "false");
        }
Пример #8
0
 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);
     }
 }
Пример #9
0
        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))
                {
                    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":
                            string       mp3Path    = Path.ChangeExtension(path, null);
                            ushort       wFormatTag = 1;
                            ushort       nChannels;
                            uint         nSamplesPerSec;
                            uint         nAvgBytesPerSec;
                            ushort       nBlockAlign;
                            ushort       wBitsPerSample = 16;
                            MemoryStream output         = new MemoryStream();
                            using (MemoryStream yourMp3FileStream = new MemoryStream(data))
                                using (var input = new MP3Sharp.MP3Stream(yourMp3FileStream))
                                    using (var writer = new BinaryWriter(output, Encoding.UTF8))
                                    {
                                        var headerSize = 44;
                                        output.Position = headerSize;
                                        input.CopyTo(output);
                                        UInt32 wavDataLength = (UInt32)output.Length - 44;
                                        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;
                                        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.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;
                    loadOrder.Push(mod.Name);
                }
            }
        }
Пример #10
0
 public static string GetFolderPath(this TmodFile file, params string[] paths)
 {
     return(Path.Combine(file.Name, Path.Combine(paths)));
 }
        public static BuildPropertiesInterface GetBuildPropertiesForModFile(TmodFile modfile)
        {
            var editor = BuildPropertiesEditor.GetBuildPropertiesForModFile(modfile);

            return(new BuildPropertiesInterface(editor));
        }
Пример #12
0
        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;
                    }
                }
            }
        }
Пример #13
0
 public TExecutor(Program.ProgramArgs args, TmodFile modFile)
 {
     Args    = args;
     ModFile = modFile;
 }
Пример #14
0
        public Stream OpenStream(string assetName) => new MemoryStream(file.GetBytes(assetName));         //This has to return a seekable stream, so we can't just return the deflate one.

        //Etc
        public void Dispose()
        {
            file = null;

            ClearRejections();
        }
Пример #15
0
 public TModContentSource(TmodFile file)
 {
     this.file = file ?? throw new ArgumentNullException(nameof(file));
 }
Пример #16
0
        // Receive a mod when connecting to server
        internal static void ReceiveMod(BinaryReader reader)
        {
            if (downloadingMod == null)
            {
                return;
            }

            try {
                if (downloadingFile == null)
                {
                    Interface.progress.Show(displayText: reader.ReadString(), cancel: CancelDownload);

                    ModLoader.GetMod(downloadingMod.name)?.Close();
                    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.progress.Progress = downloadingFile.Position / (float)downloadingLength;

                if (downloadingFile.Position == downloadingLength)
                {
                    downloadingFile.Close();
                    var mod = new TmodFile(downloadingMod.path);
                    using (mod.Open()) { }

                    if (!downloadingMod.Matches(mod))
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModHashMismatch"));
                    }

                    if (downloadingMod.signed && !mod.ValidModBrowserSignature)
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModNotSigned"));
                    }

                    ModLoader.EnableMod(mod.name);
                    if (downloadQueue.Count > 0)
                    {
                        DownloadNextMod();
                    }
                    else
                    {
                        OnModsDownloaded(true);
                    }
                }
            }
            catch (Exception e) {
                try {
                    downloadingFile?.Close();
                    File.Delete(downloadingMod.path);
                }
                catch (Exception exc2) {
                    Logging.tML.Error("Unknown error during mod sync", exc2);
                }

                var msg = Language.GetTextValue("tModLoader.MPErrorModDownloadError", downloadingMod.name);
                Logging.tML.Error(msg, e);
                Interface.errorMessage.Show(msg + e, 0);

                Netplay.disconnect = true;
                downloadingMod     = null;
            }
        }
Пример #17
0
 public bool Matches(TmodFile mod) => name == mod.name && version == mod.version && hash.SequenceEqual(mod.hash);
Пример #18
0
        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();
            Interface.buildMod.SetCompiling();
            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
            {
                windowsData = CompileMod(modToBuild, properties, true);
                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(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());
                }
            }
            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);
        }
Пример #19
0
 public LoadingMod(TmodFile modFile, BuildProperties properties)
 {
     this.modFile    = modFile;
     this.properties = properties;
 }
 public static Services.Tml.BuildPropertiesEditor GetBuildPropertiesForModFile(TmodFile modFile)
 {
     return(Services.Tml.BuildPropertiesEditor.GetBuildPropertiesForModFile(modFile));
 }
Пример #21
0
 internal static void EnableMod(TmodFile mod)
 {
     SetModActive(mod, true);
 }
Пример #22
0
        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(TmodFile.LoadedState.Info);

                    if (!downloadingMod.Matches(mod))
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModHashMismatch"));
                    }

                    if (downloadingMod.signed && !mod.ValidModBrowserSignature)
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModNotSigned"));
                    }

                    ModLoader.EnableMod(mod.name);

                    if (downloadQueue.Count > 0)
                    {
                        DownloadNextMod();
                    }
                    else
                    {
                        OnModsDownloaded(true);
                    }
                }
            }
            catch (Exception e)
            {
                try
                {
                    downloadingFile?.Close();
                }
                catch { }

                File.Delete(downloadingMod.path);
                ErrorLogger.LogException(e, Language.GetTextValue("tModLoader.MPErrorModDownloadError", downloadingMod.name));
                downloadingMod = null;
            }
        }
Пример #23
0
        private static void PublishModInner(TmodFile modFile, BuildProperties bp, bool commandLine = false)
        {
            var files = new List <UploadFile>();

            files.Add(new UploadFile {
                Name     = "file",
                Filename = Path.GetFileName(modFile.path),
                //    ContentType = "text/plain",
                Content = File.ReadAllBytes(modFile.path)
            });
            if (modFile.HasFile("icon.png"))               // Test this on server
            {
                using (modFile.Open())
                    files.Add(new UploadFile {
                        Name     = "iconfile",
                        Filename = "icon.png",
                        Content  = modFile.GetBytes("icon.png")
                    });
            }
            //if (bp.beta)
            //	throw new WebException(Language.GetTextValue("tModLoader.BetaModCantPublishError"));
            if (bp.buildVersion != modFile.TModLoaderVersion)
            {
                throw new WebException(Language.GetTextValue("OutdatedModCantPublishError.BetaModCantPublishError"));
            }

            var values = new NameValueCollection
            {
                { "displayname", bp.displayName },
                { "displaynameclean", string.Join("", ChatManager.ParseMessage(bp.displayName, Color.White).Where(x => x.GetType() == typeof(TextSnippet)).Select(x => x.Text)) },
                { "name", modFile.Name },
                { "version", "v" + bp.version },
                { "author", bp.author },
                { "homepage", bp.homepage },
                { "description", bp.description },
                { "steamid64", ModLoader.SteamID64 },
                { "modloaderversion", "tModLoader v" + modFile.TModLoaderVersion },
                { "passphrase", ModLoader.modBrowserPassphrase },
                { "modreferences", String.Join(", ", bp.modReferences.Select(x => x.mod)) },
                { "modside", bp.side.ToFriendlyString() },
            };

            if (values["steamid64"].Length != 17)
            {
                throw new WebException($"The steamid64 '{values["steamid64"]}' is invalid, verify that you are logged into Steam and don't have a pirated copy of Terraria.");
            }
            if (string.IsNullOrEmpty(values["author"]))
            {
                throw new WebException($"You need to specify an author in build.txt");
            }
            ServicePointManager.Expect100Continue = false;
            string url = "http://javid.ddns.net/tModLoader/publishmod.php";

            using (PatientWebClient client = new PatientWebClient()) {
                ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, policyErrors) => true;
                Interface.progress.Show(displayText: $"Uploading: {modFile.Name}", gotoMenu: Interface.modSourcesID, cancel: client.CancelAsync);

                var boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x", System.Globalization.NumberFormatInfo.InvariantInfo);
                client.Headers["Content-Type"] = "multipart/form-data; boundary=" + boundary;
                //boundary = "--" + boundary;
                byte[] data = UploadFile.GetUploadFilesRequestData(files, values, boundary);
                if (commandLine)
                {
                    var    result   = client.UploadData(new Uri(url), data);                // could use async version for progress output maybe
                    string response = HandlePublishResponse(modFile, result);
                    Console.WriteLine(Language.GetTextValue("tModLoader.MBServerResponse", response));
                    if (result.Length <= 256 || result[result.Length - 256 - 1] != '~')
                    {
                        throw new Exception("Publish failed due to invalid response from server");
                    }
                }
                else
                {
                    client.UploadDataCompleted   += (s, e) => PublishUploadDataComplete(s, e, modFile);
                    client.UploadProgressChanged += (s, e) => Interface.progress.Progress = (float)e.BytesSent / e.TotalBytesToSend;
                    client.UploadDataAsync(new Uri(url), data);
                }
            }
        }
Пример #24
0
        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);
                    }
                };
            }
        }
Пример #25
0
        public Dumper(TmodFile mod)
        {
            _mod = mod;

            _assembly = _mod.GetPrimaryAssembly(false);
        }
Пример #26
0
        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;
                    }
                }
            }
        }
Пример #27
0
        internal static BuildProperties ReadModFile(TmodFile modFile)
        {
            BuildProperties properties = new BuildProperties();

            byte[] data = modFile.GetFile("Info");

            if (data.Length == 0)
            {
                return(properties);
            }

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data)))
            {
                for (string tag = reader.ReadString(); tag.Length > 0; tag = reader.ReadString())
                {
                    if (tag == "dllReferences")
                    {
                        properties.dllReferences = ReadList(reader).ToArray();
                    }
                    if (tag == "modReferences")
                    {
                        properties.modReferences = ReadList(reader).Select(ModReference.Parse).ToArray();
                    }
                    if (tag == "weakReferences")
                    {
                        properties.weakReferences = ReadList(reader).Select(ModReference.Parse).ToArray();
                    }
                    if (tag == "sortAfter")
                    {
                        properties.sortAfter = ReadList(reader).ToArray();
                    }
                    if (tag == "sortBefore")
                    {
                        properties.sortBefore = ReadList(reader).ToArray();
                    }
                    if (tag == "author")
                    {
                        properties.author = reader.ReadString();
                    }
                    if (tag == "version")
                    {
                        properties.version = new 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;
                    }
                    if (tag == "includePDB")
                    {
                        properties.includePDB = true;
                    }
                    if (tag == "editAndContinue")
                    {
                        properties.editAndContinue = true;
                    }
                    if (tag == "side")
                    {
                        properties.side = (ModSide)reader.ReadByte();
                    }
                }
            }
            return(properties);
        }
Пример #28
0
 internal static BuildProperties ReadModFile(TmodFile modFile)
 {
     return(ReadFromStream(modFile.GetStream("Info")));
 }
Пример #29
0
 internal static byte[] GetModAssembly(TmodFile modFile, bool?xna = null) => modFile.GetBytes(GetModAssemblyFileName(modFile, xna));
Пример #30
0
 internal void SetMod(TmodFile mod)
 {
     this.mod = mod;
 }