Esempio n. 1
0
        public UndoableMapModel CreateFromHpi(string hpipath, string mappath, bool readOnly)
        {
            MapModel m;

            using (var hpi = new HpiArchive(hpipath))
            {
                var otaPath = HpiPath.ChangeExtension(mappath, ".ota");

                TdfNode n;

                var otaFileInfo   = hpi.FindFile(otaPath);
                var otaFileBuffer = new byte[otaFileInfo.Size];
                hpi.Extract(otaFileInfo, otaFileBuffer);
                using (var ota = new MemoryStream(otaFileBuffer))
                {
                    n = TdfNode.LoadTdf(ota);
                }

                var tntFileInfo   = hpi.FindFile(mappath);
                var tntFileBuffer = new byte[tntFileInfo.Size];
                hpi.Extract(tntFileInfo, tntFileBuffer);
                using (var s = new TntReader(new MemoryStream(tntFileBuffer)))
                {
                    m = this.mapModelFactory.FromTntAndOta(s, n);
                }
            }

            return(new UndoableMapModel(m, hpipath, readOnly));
        }
Esempio n. 2
0
        public UndoableMapModel CreateFromTnt(string filename)
        {
            MapModel m;

            var otaFileName = filename.Substring(0, filename.Length - 4) + ".ota";

            if (File.Exists(otaFileName))
            {
                TdfNode attrs;
                using (var ota = File.OpenRead(otaFileName))
                {
                    attrs = TdfNode.LoadTdf(ota);
                }

                using (var s = new TntReader(filename))
                {
                    m = this.mapModelFactory.FromTntAndOta(s, attrs);
                }
            }
            else
            {
                using (var s = new TntReader(filename))
                {
                    m = this.mapModelFactory.FromTnt(s);
                }
            }

            return(new UndoableMapModel(m, filename, false));
        }
Esempio n. 3
0
        public static Fbi ReadUnitFromFbi(string file)
        {
            TdfNode root;

            using (var f = new StreamReader(file, Encoding.GetEncoding(1252)))
            {
                root = TdfNode.LoadTdf(f);
            }

            var unitInfo = root.Keys["UNITINFO"];
            var unit     = ToFbi(file, unitInfo);

            return(unit);
        }
Esempio n. 4
0
        public static void WriteUnitFbiFile(Fbi unit)
        {
            TdfNode sourceRoot;

            using (var f = new StreamReader(unit.File, Encoding.GetEncoding(1252)))
            {
                sourceRoot = TdfNode.LoadTdf(f);
            }

            var targetUnitInfo = ToTdfNode(unit);

            var instructions = TdfCompare.ComputePropertyMapping(sourceRoot.Keys["UNITINFO"], targetUnitInfo, 1);

            TdfCompare.PerformInstructions(unit.File, instructions);
        }
Esempio n. 5
0
        protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file)
        {
            var fileBuffer = new byte[file.Size];

            archive.Extract(file, fileBuffer);

            TdfNode n;

            using (var tdf = new MemoryStream(fileBuffer))
            {
                n = TdfNode.LoadTdf(tdf);
            }

            this.Records.AddRange(
                n.Keys.Values.Select(FeatureRecord.FromTdfNode));
        }
Esempio n. 6
0
        public static IEnumerable <Tdf> ReadWeaponFromTdf(string file)
        {
            TdfNode root;

            using (var f = new StreamReader(file, Encoding.GetEncoding(1252)))
            {
                root = TdfNode.LoadTdf(f);
            }

            foreach (var entry in root.Keys)
            {
                var weaponInfo = entry.Value;

                var tdf = ToTdf(file, weaponInfo);
                yield return(tdf);
            }
        }
Esempio n. 7
0
        public static void WriteWeaponTdfFile(Tdf weapon)
        {
            TdfNode sourceRoot;

            using (var f = new StreamReader(weapon.File, Encoding.GetEncoding(1252)))
            {
                sourceRoot = TdfNode.LoadTdf(f);
            }

            var targetWeaponInfo = ToTdfNode(weapon);

            var instructions = TdfCompare.ComputePropertyMapping(sourceRoot.Keys[weapon.ID], targetWeaponInfo, 1);

            if (sourceRoot.Keys[weapon.ID].Keys.ContainsKey("DAMAGE"))
            {
                instructions.AddRange(TdfCompare.ComputePropertyMapping(sourceRoot.Keys[weapon.ID].Keys["DAMAGE"], targetWeaponInfo.Keys["DAMAGE"], 2));
            }

            TdfCompare.PerformInstructions(weapon.File, instructions);
        }