コード例 #1
0
        public override void Complete()
        {
            Success = true;
            base.Complete();

            try {
                var mod = new TmodFile(ModHeader.path);
                using (mod.Open()) { }

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

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

                ModLoader.EnableMod(mod.name);
            }
            catch (Exception e) {
                Cancel();
                ShowError(e);
            }
        }
コード例 #2
0
        internal static void PublishModCommandLine(string modName, string passphrase, string steamid64)
        {
            try {
                InstallVerifier.IsGoG          = true;
                ModLoader.SteamID64            = steamid64;
                ModLoader.modBrowserPassphrase = passphrase;

                if (string.IsNullOrWhiteSpace(ModLoader.modBrowserPassphrase) || string.IsNullOrWhiteSpace(ModLoader.SteamID64))
                {
                    throw new Exception("-passphrase and -steamid64 are required for publishing via command line");
                }

                LocalMod localMod;
                var      modPath = Path.Combine(ModLoader.ModPath, modName + ".tmod");
                var      modFile = new TmodFile(modPath);
                using (modFile.Open())                 // savehere, -tmlsavedirectory, normal (test linux too)
                    localMod = new LocalMod(modFile);

                PublishModInner(modFile, localMod.properties, true);
            }
            catch (Exception e) {
                Console.WriteLine("Something went wrong with command line mod publishing.");
                Console.WriteLine(e.ToString());
                Environment.Exit(1);
            }
            Environment.Exit(0);
        }
コード例 #3
0
        static void Downgrade(string file)
        {
            TmodFile tmodFile = new TmodFile(file);

            using (tmodFile.Open())
            {
                tmodFile.Downgrade();
                tmodFile.Save(file.Replace(".tmod", "_down.tmod"));
            }
        }
コード例 #4
0
        static void Upgrade(string file)
        {
            TmodFile tmf = new TmodFile(file);

            using (tmf.Open())
            {
                tmf.Upgrade();
                tmf.Save(file.Replace(".tmod", "_up.tmod"));
            }
        }
コード例 #5
0
        public void Patch()
        {
            string o = Path.GetFileName(file).Replace(".dll", ".tmod");

            if (!File.Exists(o))
            {
                throw new Exception("未找到相应tmod文件");
            }

            TmodFile tmf = new TmodFile(o);

            using (tmf.Open())
            {
                tmf.ReplacePrimaryAssembly(File.ReadAllBytes(file), false);
            }

            tmf.Save(o.Substring(0, o.Length - 5) + "_Patched.tmod");
        }
コード例 #6
0
ファイル: Dumper.cs プロジェクト: tyhnoone/ModLoacalizer2
		public void Dump()
		{
			string o = Path.GetFileName(file).Replace(".tmod", ".dll");
			if (File.Exists(o))
			{
				File.Copy(o, o + ".bak");
			}
			
			TmodFile tmf = new TmodFile(file);
			byte[] data;
			using (tmf.Open())
			{
				data = tmf.GetPrimaryAssembly(false);
			}
			if (data == null)
				throw new Exception("未找到dll");
			File.WriteAllBytes(o, data);
		}
コード例 #7
0
ファイル: Program.cs プロジェクト: tyhnoone/ModLoacalizer2
        static TExecutor GetExecutor(ProgramArgs args)
        {
            if (!File.Exists(args.FilePath))
            {
                Console.Error.WriteLine("未找到mod文件。");
                return(null);
            }

            TmodFile file = new TmodFile(args.FilePath);

            using (file.Open()) { }

            if (args.IsDump)
            {
                return(new Dumper(args, file));
            }

            return(new Patcher(args, file));
        }
コード例 #8
0
ファイル: Localizer.cs プロジェクト: sgkoishi/Localizer
        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());
            }
        }
コード例 #9
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);
                }
            }
        }
コード例 #10
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;
            }
        }