private void PublishUploadDataComplete(object s, UploadDataCompletedEventArgs e, TmodFile theTModFile)
        {
            if (e.Error != null)
            {
                if (e.Cancelled)
                {
                    Main.menuMode = Interface.modSourcesID;
                    return;
                }
                ErrorLogger.LogModBrowserException(e.Error);
                return;
            }
            var result         = e.Result;
            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 response = Encoding.UTF8.GetString(result, 0, responseLength);

            ErrorLogger.LogModPublish(response);
        }
示例#2
0
        static void Downgrade(string file)
        {
            TmodFile tmodFile = new TmodFile(file);

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

            using (tmf.Open())
            {
                tmf.Upgrade();
                tmf.Save(file.Replace(".tmod", "_up.tmod"));
            }
        }
示例#4
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");
        }
        private void Save()
        {
            var tmp = Path.GetTempFileName();

            _module.Write(tmp);
            _mod.WritePrimaryAssembly(File.ReadAllBytes(tmp), false);

            if (_monoAssembly != null)
            {
                tmp = Path.GetTempFileName();
                _monoModule.Write(tmp);
                _mod.WritePrimaryAssembly(File.ReadAllBytes(tmp), true);
            }

            _mod.Save(string.Format(DefaultConfigurations.OutputFileNameFormat, _mod.Name));
#if DEBUG
            _module.Write("test-mod.dll");
            _monoModule?.Write("test-mod-mono.dll");
#endif
        }
示例#6
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);
     }
 }
示例#7
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);
        }