Beispiel #1
0
        public void TestSetDefaultsTkAnimMetadata()
        {
            var header = new MBINHeader();

            header.SetDefaults(typeof(NMS.Toolkit.TkAnimMetadata), MBINHeader.Format.V0);

            Assert.AreEqual(MBINHeader.MBIN_MAGIC, header.MagicID);
            Assert.AreEqual(MBINHeader.MBIN_VERSION, header.FormatID);
            Assert.AreEqual(MBINHeader.TKANIMMETADATA_TAG, header.Timestamp);
            Assert.AreEqual(TKANIMMETADATA_GUID, header.TemplateGUID);
            Assert.AreEqual("", header.TemplateName);
            Assert.AreEqual(MBINHeader.TKANIMMETADATA_PADDING, header.EndPadding);

            Assert.AreEqual(VERSION_STRING, header.GetMBINVersion().ToString());
        }
Beispiel #2
0
        public void TestSetDefaultsV0TkGeometry()
        {
            var header = new MBINHeader();

            header.SetDefaultsV0(typeof(NMS.Toolkit.TkGeometryData));

            Assert.AreEqual(MBINHeader.MBIN_MAGIC_PC, header.MagicID);
            Assert.AreEqual(MBINHeader.MBIN_VERSION, header.FormatID);
            Assert.AreEqual(MBINHeader.TKGEOMETRYDATA_TAG, header.Timestamp);
            Assert.AreEqual(TKGEOMETRYDATA_GUID, header.TemplateGUID);
            Assert.AreEqual("", header.TemplateName);
            Assert.AreEqual(MBINHeader.TKGEOMETRYDATA_PADDING, header.EndPadding);

            Assert.AreEqual(VERSION_STRING, header.GetMBINVersion().ToString());
        }
Beispiel #3
0
        public void TestSetDefaultsCommon()
        {
            var header = new MBINHeader();

            header.SetDefaults(format: MBINHeader.Format.V0);

            Assert.AreEqual(MBINHeader.MBIN_MAGIC, header.MagicID);
            Assert.AreEqual(MBINHeader.MBIN_VERSION, header.FormatID);
            Assert.AreEqual(0ul, header.Timestamp);
            Assert.AreEqual(0ul, header.TemplateGUID);
            Assert.AreEqual("", header.TemplateName);
            Assert.AreEqual(0ul, header.EndPadding);

            Assert.AreEqual(VERSION_STRING, header.GetMBINVersion().ToString());
        }
        public void TestSetDefaultsCommon()
        {
            var header = new MBINHeader();

            header.SetDefaults(format: MBINHeader.Format.V1);

            Assert.AreEqual(MBINHeader.MBIN_MAGIC, header.MagicID);
            Assert.AreEqual(MBINHeader.MBIN_VERSION, header.FormatID);
            Assert.AreEqual(MBINHeader.MBINCVER_TAG, header.Tag);
            Assert.AreEqual(VERSION_ID, header.MbinVersion);
            Assert.AreEqual("", header.TemplateName);
            Assert.AreEqual(END_PADDING, header.EndPadding);

            Assert.AreEqual(VERSION_STRING, header.GetMBINVersion().ToString());
        }
        public void TestSetDefaultsImplicitTkGeometry()
        {
            var header = new MBINHeader();

            header.SetDefaults(typeof(NMS.Toolkit.TkGeometryData));

            Assert.AreEqual(MBINHeader.MBIN_MAGIC_PC, header.MagicID);
            Assert.AreEqual(FORMAT_ID0, header.FormatID);
            Assert.AreEqual(MBINHeader.TKGEOMETRYDATA_TAG, header.VersionID);
            Assert.AreEqual(TKGEOMETRYDATA_GUID, header.TemplateGUID);
            Assert.AreEqual("", header.TemplateName);
            Assert.AreEqual(MBINHeader.TKGEOMETRYDATA_PADDING, header.MetaOffset);

            Assert.AreEqual(MBINHeader.MBIN_VERSION, header.FormatNMS);
            Assert.AreEqual(FORMAT_V0, header.FormatAPI);
        }
        public void TestSetDefaultsImplicitCommon()
        {
            var header = new MBINHeader();

            header.SetDefaults();

            Assert.AreEqual(MBINHeader.MBIN_MAGIC, header.MagicID);
            Assert.AreEqual(FORMAT_ID2, header.FormatID);
            Assert.AreEqual(VERSION_ID, header.VersionID);
            Assert.AreEqual(0ul, header.TemplateGUID);
            Assert.AreEqual("", header.TemplateName);
            Assert.AreEqual(0ul, header.MetaOffset);

            Assert.AreEqual(MBINHeader.MBIN_VERSION, header.FormatNMS);
            Assert.AreEqual(FORMAT_V2, header.FormatAPI);

            Assert.AreEqual(NMS_VERSION_STRING, header.VersionNMS.ToString());
            Assert.AreEqual(API_VERSION_STRING, header.VersionAPI.ToString());
        }
Beispiel #7
0
 public bool Load(bool getVersion = false)
 {
     _io.Stream.Position = 0;
     Header = (MBINHeader)NMSTemplate.DeserializeBinaryTemplate(_io.Reader, "MBINHeader");
     if (getVersion)
     {
         string mbinVer = Header.Tag;
         Console.WriteLine(mbinVer.Substring(8));
     }
     else
     {
         if (Header.Tag.Contains("MBIN"))        // check whether the file has been generated by MBINCompiler basically
         {
             string ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
             if (Header.Tag != String.Format("MBINCver{0}", ver.Substring(0, ver.Length - 2)))
             {
                 Console.WriteLine("Incorrect version");
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #8
0
        public bool Load(bool getVersion = false)
        {
            _io.Stream.Position = 0;
            Header = (MBINHeader)NMSTemplate.DeserializeBinaryTemplate(_io.Reader, "MBINHeader");
            if (getVersion)
            {
                string mbinVer = Header.GetMBINVersion();
                Console.WriteLine(mbinVer.Substring(8));
            }

            /*else
             * {
             *  if (Header.Tag == 0x726576434E49424D)        // check whether the file has been generated by MBINCompiler basically
             *  {
             *      string ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
             *      if (Header.Tag != String.Format("MBINCver{0}", ver.Substring(0, ver.Length - 2)))
             *      {
             *          Console.WriteLine("Incorrect version");
             *          return false;
             *      }
             *  }
             * }*/
            return(true);
        }
Beispiel #9
0
 public bool Load()
 {
     _io.Stream.Position = 0;
     Header = (MBINHeader)NMSTemplate.DeserializeBinaryTemplate(_io.Reader, "MBINHeader");
     return(true);
 }
Beispiel #10
0
        static void Init(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            string        vanillaMBINPath = null;
            List <string> patchFiles      = new List <string>();

            // [0] = vanilla file
            // [1] = custom file 1
            // [2] = custom file 2
            // [...] = ...
            if (args.Length < 3)
            {
                PopulateDirectoryInfo(out vanillaMBINPath, out patchFiles);
            }
            else
            {
                vanillaMBINPath = args[0];
                if (!File.Exists(vanillaMBINPath))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("ERROR: The file you input does not exist!");
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("Failed to find: " + vanillaMBINPath);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Press enter to quit...");
                    Console.ReadLine();
                    return;
                }
                foreach (string data in args.Skip(1))
                {
                    if (!File.Exists(data))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("ERROR: The file you input does not exist!");
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("Failed to find: " + data);
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Press enter to quit...");
                        Console.ReadLine();
                        return;
                    }
                    patchFiles.Add(data);
                }
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Loading up all of the MBIN files...");

            FileStream vanillaMBIN = File.OpenRead(vanillaMBINPath);

            FileStream[] otherMBINs = new FileStream[patchFiles.Count];
            for (int idx = 0; idx < patchFiles.Count; idx++)
            {
                otherMBINs[idx] = File.OpenRead(patchFiles[idx]);
            }

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("Processing MBIN File: {0}", vanillaMBINPath);

            MBINFile[] otherBnkObjects = new MBINFile[otherMBINs.Length];
            MBINFile   vanillaFile     = new MBINFile(vanillaMBIN);

            vanillaFile.Load();

            for (int idx = 0; idx < otherBnkObjects.Length; idx++)
            {
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine("Processing MBIN File: {0}", patchFiles[idx]);
                MBINFile newFile = new MBINFile(otherMBINs[idx]);
                newFile.Load();
                otherBnkObjects[idx] = newFile;
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Done processing MBIN files! Enumerating... Please be present so that you may resolve any file conflicts.");

            MultiMBINEnumerator iterator = new MultiMBINEnumerator(vanillaFile, otherBnkObjects, vanillaMBINPath, patchFiles);
            EXmlData            newData  = iterator.PatchEverything();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Done enumerating BNK files! Saving in the same directory as the EXE...");

            string name = "MergedMBIN-" + DateTime.Now.ToFileTimeUtc().ToString() + ".MBIN";

            //FileStream save = File.OpenWrite(@".\" + name);

            // Since the MBINFile class refuses to populate the data properly (Am I just not getting how to use it? Ech.)
            // It kept throwing null pointer exceptions when I called SetData. wtf?

            // Edit: Turns out I have to specify the header myself. wat.
            // Monkey if you're reading this, I love you nohomo it's just this is written really awkwardly and I'm not used to it.
            using (MBINFile outFile = new MBINFile(@".\" + name)) {
                NMSTemplate template = NMSTemplate.DeserializeEXml(newData);
                MBINHeader  header   = new MBINHeader();
                header.SetDefaults();

                outFile.Header = header;
                outFile.SetData(template);
                outFile.Save();
            }

            vanillaMBIN.Dispose();
            foreach (FileStream str in otherMBINs)
            {
                str.Dispose();
            }

            Console.Write("Saved as ");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(name);
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Press enter to quit.");
            Console.ReadLine();
        }
 public void TestStringToUlong()
 {
     Assert.AreEqual(VERSION_ID, MBINHeader.StringToUlong(VERSION_STRING_PADDED));
 }