Ejemplo n.º 1
0
            public void LoadAssemblies()
            {
                if (!NeedsReload)
                {
                    return;
                }

                try
                {
                    using (modFile.EnsureOpen()) {
                        foreach (var dll in properties.dllReferences)
                        {
                            LoadAssembly(EncapsulateReferences(modFile.GetBytes("lib/" + dll + ".dll")));
                        }

                        assembly    = LoadAssembly(EncapsulateReferences(modFile.GetMainAssembly()), modFile.GetMainPDB());
                        NeedsReload = false;
                    }
                }
                catch (Exception e)
                {
                    e.Data["mod"] = Name;
                    throw;
                }
            }
Ejemplo n.º 2
0
        private static void Internal_LoadItemID()
        {
            byte[]   raw   = null;
            TmodFile file1 = typeof(Mod).GetProperty("File", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(IMPCN.instance) as TmodFile;

            foreach (TmodFile.FileEntry item in file1)
            {
                if (item.Name.EndsWith("itemID.txt"))
                {
                    raw = file1.GetBytes(item);
                    break;
                }
            }
            string[] data = Encoding.UTF8.GetString(raw).Split('\n');
            foreach (string line in data)
            {
                string[] d = line.Split(',');
                if (d.Length != 2)
                {
                    HasLoaded = false;
                    throw new Exception("F**k me.");
                }

                string className = d[0];
                int    itemID    = int.Parse(d[1]);
                try
                {
                    idDict.Add(itemID, className);
                    getIdDict.Add(className, itemID);
                }
                catch (Exception)
                {
                }
            }
        }
Ejemplo n.º 3
0
        private static void Internal_LoadJson(string file, Dictionary <string, string> dict)
        {
            byte[]   raw   = null;
            TmodFile file1 = typeof(Mod).GetProperty("File", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(IMPCN.instance) as TmodFile;

            foreach (TmodFile.FileEntry item in file1)
            {
                if (item.Name.EndsWith(file))
                {
                    raw = file1.GetBytes(item);
                    break;
                }
            }
            JObject jobj = JObject.Parse(Encoding.UTF8.GetString(raw));

            foreach (JProperty item in jobj["ItemName"])
            {
                try
                {
                    Main.NewText("Adding: " + item.Name);
                    dict.Add(item.Name, item.Value.Value <string>());
                }
                catch (Exception)
                {
                    continue;
                }
            }
        }
Ejemplo n.º 4
0
        private static void Internal_LoadOldImproved1344Name()
        {
            byte[]   raw   = null;
            TmodFile file1 = typeof(Mod).GetProperty("File", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(IMPCN.instance) as TmodFile;

            foreach (TmodFile.FileEntry item in file1)
            {
                if (item.Name.EndsWith("old_improved_1344.json"))
                {
                    raw = file1.GetBytes(item);
                    break;
                }
            }
            JArray jarr = JArray.Parse(Encoding.UTF8.GetString(raw));

            foreach (JObject jobj in jarr)
            {
                try
                {
                    int    id        = jobj["Id"].Value <int>();
                    string className = idDict[id];
                    string content   = jobj["Content"].Value <string>();
                    old_improved_1344Dict.Add(className, content);
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 5
0
 internal static byte[] GetModAssembly(TmodFile modFile, bool?xna = null) => modFile.GetBytes(GetModAssemblyFileName(modFile, xna));
Ejemplo n.º 6
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);
                }
            }
        }
Ejemplo n.º 7
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.