コード例 #1
0
        public void SimpleWorkerTest()
        {
            string[] fileNames = new[]
            {
                "music0.obj",
                "music1.obj",
                "music2.obj",
                "music3.obj",
                "music4.obj",
                "music5.obj",
                "rail.obj",
                "texl.obj",
                "wmset.obj",
                "wmsetXX.obj",
                "wmx.obj",
                "chara.one"
            };

            Memory.Init(null, null, null, null);

            ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_WORLD);

            //Console.WriteLine(aw.archive);
            string[] wmxPath = aw.GetListOfFiles();
            Console.WriteLine("Files in Archive (" + Memory.Archives.A_WORLD + ")");
            for (int i = 0; i < wmxPath.Length; i++)
            {
                string filePath = wmxPath[i];
                Console.WriteLine(i + 1 + ".) " + filePath);
            }

            // From the wiki we know, that there are 12 files in the archive
            // http://wiki.ffrtt.ru/index.php/FF8#World_map_files
            Assert.AreEqual(wmxPath.Length, fileNames.Length);
        }
コード例 #2
0
        /// <summary>
        /// Should be called only once
        /// </summary>
        public static void Init()
        {
            Memory.Log.WriteLine($"{nameof(Fields)} :: {nameof(Initializer)} :: {nameof(Init)}");
            var aw = ArchiveWorker.Load(Memory.Archives.A_FIELD);

            // ReSharper disable once StringLiteralTypo
            var mapData = aw.GetArchive("mapdata.fs");

            if (mapData == null)
            {
                return;
            }
            // ReSharper disable once StringLiteralTypo
            const string map   = "maplist";
            var          bytes = mapData.GetBinaryFile(map);

            if (bytes == null)
            {
                return;
            }
            var mapList = System.Text.Encoding.UTF8.GetString(bytes)
                          .Replace("\r", "")
                          .Split('\n');

            //Memory.FieldHolder.FieldMemory = new int[1024];
            Memory.FieldHolder.Fields = mapList;
            FieldId.FieldId_          = mapList;
        }
コード例 #3
0
            // ReSharper disable once UnusedMember.Local
            private static void MergeArchiveToZzz(ArchiveBase aw)
            {
                if (aw == null)
                {
                    return;
                }

                void Merge(Archive a)
                {
                    Log.WriteLine($"{nameof(Archive)}::{nameof(Init)}::{nameof(Merge)}\n\t{a} to {ZZZ_MAIN}");
                    string      fs    = a.FS;
                    ArchiveBase child = ArchiveWorker.Load(a);
                    FI          fi    = aw.ArchiveMap.FindString(ref fs, out int _);

                    aw.ArchiveMap.MergeMaps(child.ArchiveMap, fi.Offset);
                }

                Merge(A_BATTLE);
                Merge(A_FIELD);
                Merge(A_MAGIC);
                Merge(A_MAIN);
                Merge(A_MENU);
                Merge(A_WORLD);
                aw.GetListOfFiles(true);
                ArchiveBase.PurgeCache();
                A_BATTLE = ZZZ_MAIN;
                A_FIELD  = ZZZ_MAIN;
                A_MAGIC  = ZZZ_MAIN;
                A_MAIN   = ZZZ_MAIN;
                A_MENU   = ZZZ_MAIN;
                A_WORLD  = ZZZ_MAIN;
            }
コード例 #4
0
        public static void Init()
        {
            Memory.Log.WriteLine($"{nameof(InitDebuggerBattle)} :: {nameof(Init)}");
            var aw       = ArchiveWorker.Load(Memory.Archives.A_BATTLE);
            var sceneOut = aw.GetBinaryFile("scene.out");

            Memory.Encounters = Battle.Encounters.Read(sceneOut);
            Battle.Mag.Init();
            //Memory.Encounters.CurrentIndex = 87;
        }
コード例 #5
0
ファイル: Items_In_Menu.cs プロジェクト: stantoxt/OpenVIII
        public static ItemsInMenu Read()
        {
            var aw     = ArchiveWorker.Load(Memory.Archives.A_MENU);
            var buffer = aw.GetBinaryFile("mitem.bin");

            if (buffer != null)
            {
                using (var br = new BinaryReader(new MemoryStream(buffer)))
                {
                    return(Read(br));
                }
            }
            return(default);
コード例 #6
0
        private static void LoadWorld()
        {
            ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_WORLD);

            string wmPath = aw.GetListOfFiles().Where(x => x.ToLower().Contains($"wmset{Extended.GetLanguageShort(true)}.obj")).Select(x => x).First();

            using (World.Wmset wmset = new World.Wmset(aw.GetBinaryFile(wmPath)))
            {
                _worldEncounters     = wmset.Encounters.SelectMany(x => x.Select(y => y)).Distinct().ToHashSet();
                WorldEncountersLunar = wmset.EncountersLunar.SelectMany(x => x.Select(y => y)).Distinct().ToHashSet();
            }
            //rail = new rail(aw.GetBinaryFile(railFile));
        }
コード例 #7
0
        private static void LoadWorld()
        {
            var aw = ArchiveWorker.Load(Memory.Archives.A_WORLD);

            // ReSharper disable once StringLiteralTypo
            var wmPath = $"wmset{Extended.GetLanguageShort(true)}.obj";

            using (var worldMapSettings = new Wmset(aw.GetBinaryFile(wmPath)))
            {
                _worldEncounters     = worldMapSettings.Encounters.SelectMany(x => x.Select(y => y)).Distinct().ToHashSet();
                WorldEncountersLunar = worldMapSettings.EncountersLunar.SelectMany(x => x.Select(y => y)).Distinct().ToHashSet();
            }
            //rail = new rail(aw.GetBinaryFile(railFile));
        }
コード例 #8
0
        public static void Init(bool bForce = false)
        {
            if (BAlreadyInitialized && !bForce)
            {
                return;
            }

            var mfc = new List <MainFieldChara>();

            var aw   = ArchiveWorker.Load(Memory.Archives.A_FIELD);
            var test = aw.GetListOfFiles();

            var collectionEntry = test.Where(x => x.ToLower().Contains("main_chr")).ToList().AsReadOnly();

            if (!collectionEntry.Any())
            {
                return;
            }
            var fieldArchiveName = collectionEntry.First();
            var fieldArchive     = aw.GetArchive(fieldArchiveName);
            var test2            = fieldArchive.GetListOfFiles();

            foreach (var fieldArchiveFileName in test2)
            {
                //if (test_[i].Contains("d008.mch"))
                //    continue;
                if (string.IsNullOrWhiteSpace(fieldArchiveFileName))
                {
                    continue;
                }
                var oneBytes = fieldArchive.GetBinaryFile(fieldArchiveFileName);

                if (oneBytes.Length < 64) //Hello Kazuo Suzuki! I will skip your dummy files
                {
                    continue;
                }

                var currentLocalChara = ReadMainChara(oneBytes);

                // Have to accomodate both Linux and Windows paths
                var dotIndex = fieldArchiveFileName.LastIndexOf(".");
                var localId  = int.Parse(fieldArchiveFileName.Substring(dotIndex - 3, 3));
                currentLocalChara.ID = localId;
                mfc.Add(currentLocalChara);
            }
            MainFieldCharacters = mfc.ToArray();
            BAlreadyInitialized = true;
        }
コード例 #9
0
ファイル: FieldCharaOne.cs プロジェクト: hollow87/OpenVIII
        public static void Init(bool bForce = false)
        {
            if (bAlreadyInitialized && !bForce)
            {
                return;
            }

            List <MainFieldChara> mfc = new List <MainFieldChara>();

            ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_FIELD);

            string[] test = aw.GetListOfFiles();

            var CollectionEntry = test.Where(x => x.ToLower().Contains("main_chr"));

            if (!CollectionEntry.Any())
            {
                return;
            }
            string fieldArchiveName = CollectionEntry.First();
            var    fieldArchive     = aw.GetArchive(fieldArchiveName);

            string[] test_ = fieldArchive.GetListOfFiles();

            for (int i = 0; i < test_.Length; i++)
            {
                //if (test_[i].Contains("d008.mch"))
                //    continue;
                if (string.IsNullOrWhiteSpace(test_[i]))
                {
                    continue;
                }
                byte[] oneb = fieldArchive.GetBinaryFile(test_[i]);

                if (oneb.Length < 64) //Hello Kazuo Suzuki! I will skip your dummy files
                {
                    continue;
                }

                MainFieldChara currentLocalChara = ReadMainChara(oneb);
                int            localId           = int.Parse(Path.GetFileNameWithoutExtension(test_[i]).Substring(1, 3));
                currentLocalChara.id = localId;
                mfc.Add(currentLocalChara);
            }
            MainFieldCharacters = mfc.ToArray();
            bAlreadyInitialized = true;
        }
コード例 #10
0
ファイル: Stage.cs プロジェクト: hollow87/OpenVIII
        public static BinaryReader Open()
        {
            ArchiveBase aw       = ArchiveWorker.Load(Memory.Archives.A_BATTLE);
            string      filename = Memory.Encounters.Filename;

            Memory.Log.WriteLine($"{nameof(Battle)} :: Loading {nameof(Camera)} :: {filename}");
            byte[] stageBuffer = aw.GetBinaryFile(filename);

            BinaryReader br;
            MemoryStream ms;

            if (stageBuffer == null)
            {
                return(null);
            }
            return(br = new BinaryReader(ms = new MemoryStream(stageBuffer)));
        }
コード例 #11
0
ファイル: FieldCharaOne.cs プロジェクト: hollow87/OpenVIII
        public FieldCharaOne(int fieldId)
        {
            if (!FieldMainCharaOne.bAlreadyInitialized)
            {
                FieldMainCharaOne.Init();
            }
            ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_FIELD);

            string[] test = aw.GetListOfFiles();

            var CollectionEntry = test.Where(x => x.IndexOf(Memory.FieldHolder.fields[Memory.FieldHolder.FieldID], StringComparison.OrdinalIgnoreCase) >= 0);

            if (!CollectionEntry.Any())
            {
                return;
            }
            string fieldArchivename = CollectionEntry.First();
            var    fieldArchive     = aw.GetArchive(fieldArchivename);


            string[] test_ = fieldArchive.GetListOfFiles();


            string one;

            //string main_chr;
            try
            {
                one = test_.First(x => x.EndsWith(".one", StringComparison.OrdinalIgnoreCase));
            }
            catch
            {
                return;
            }

            byte[] oneb = fieldArchive.GetBinaryFile(one);
            if (oneb.Length == 0)
            {
                return;
            }
            ReadBuffer(oneb);
        }
コード例 #12
0
        public FieldCharaOne(int fieldId)
        {
            _fieldId = fieldId;
            if (!FieldMainCharaOne.BAlreadyInitialized)
            {
                FieldMainCharaOne.Init();
            }
            var aw   = ArchiveWorker.Load(Memory.Archives.A_FIELD);
            var test = aw.GetListOfFiles();

            var collectionEntry = test.Where(x => x.IndexOf(Memory.FieldHolder.Fields[Memory.FieldHolder.FieldID], StringComparison.OrdinalIgnoreCase) >= 0).ToList().AsReadOnly();

            if (!collectionEntry.Any())
            {
                return;
            }
            var fieldArchiveName = collectionEntry.First();
            var fieldArchive     = aw.GetArchive(fieldArchiveName);

            var test2 = fieldArchive.GetListOfFiles();

            string one;

            //string main_chr;
            try
            {
                one = test2.First(x => x.EndsWith(".one", StringComparison.OrdinalIgnoreCase));
            }
            catch
            {
                return;
            }

            var oneBytes = fieldArchive.GetBinaryFile(one);

            if (oneBytes.Length == 0)
            {
                return;
            }
            ReadBuffer(oneBytes);
        }
コード例 #13
0
        public Search(FF8String searchstring)
        {
            _s = searchstring;
            foreach (Memory.Archive a in ArchiveList)
            {
                ArchiveBase aw  = ArchiveWorker.Load(a);
                string[]    lof = aw.GetListOfFiles();
                foreach (string f in lof)
                {
                    string ext = Path.GetExtension(f);
                    if (_skipExtension.Any(x => ext != null && x.IndexOf(ext, StringComparison.OrdinalIgnoreCase) >= 0))
                    {
                        continue;
                    }
                    Debug.WriteLine($"Searching {f}, in {a} for {searchstring}");
                    //byte[] bf = aw.GetBinaryFile(f);
                    //SearchBin(bf, a.ToString(), f);
                    using (BinaryReader br = new BinaryReader(new MemoryStream(aw.GetBinaryFile(f))))
                    {
                        SearchBin(br, a.ToString(), f);
                    }
                }
            }
            foreach (string a in Files)
            {
                Debug.WriteLine($"Searching {a}, for {searchstring}");
                using (BinaryReader br = new BinaryReader(File.OpenRead(a))) //new FileStream(a, FileMode.Open, FileAccess.Read, FileShare.None, 65536)))//
                {
                    br.BaseStream.Seek(0, SeekOrigin.Begin);
                    //byte[] bf = br.ReadBytes((int)br.BaseStream.Length);

                    //SearchBin(bf, a, "");
                    SearchBin(br, a, "");
                }
            }
        }
コード例 #14
0
        protected DatFile(int fileId, EntityType entityType, int additionalFileId = -1, DatFile skeletonReference = null, Sections flags = Sections.All)
        {
            Flags = flags;

            ID    = fileId;
            AltID = additionalFileId;
            var middle = string.Empty;

            switch (entityType)
            {
            case EntityType.Monster:
                _prefix  = "c0m";
                FileName = $"{_prefix}{ID:D03}";
                break;

            case EntityType.Character:
            case EntityType.Weapon:
                _prefix  = "d";
                middle   = entityType == EntityType.Character ? "c" : "w";
                FileName = $"{_prefix}{ID:x}{middle}{AltID:D03}";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(entityType), entityType, null);
            }
            Memory.Log.WriteLine($"{nameof(DatFile)} Creating new BattleDat with {fileId},{entityType},{additionalFileId}");
            var aw = ArchiveWorker.Load(Memory.Archives.A_BATTLE);

            EntityType = entityType;
            string path;
            var    search = "";

            if (!string.IsNullOrWhiteSpace(middle))
            {
                search = $"d{fileId:x}{middle}";
                IEnumerable <string> test = aw.GetListOfFiles()
                                            .Where(x => x.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0).ToArray();
                path = test.FirstOrDefault(x => x.ToLower().Contains(FileName));

                if (string.IsNullOrWhiteSpace(path) && test.Any() && entityType == EntityType.Character)
                {
                    path = test.First();
                }
            }
            else
            {
                path = aw.GetListOfFiles().FirstOrDefault(x => x.ToLower().Contains(FileName));
            }

            if (!string.IsNullOrWhiteSpace(path))
            {
                Buffer = aw.GetBinaryFile(path);
            }
            if (Buffer == null || Buffer.Length < 0)
            {
                Memory.Log.WriteLine($"Search String: {search} Not Found skipping {entityType}; So resulting file buffer is null.");
                return;
            }
            ExportFile();
            using (Br = new BinaryReader(new MemoryStream(Buffer)))
            {
                DatHeader = DatHeader.CreateInstance(Br);
            }

            LoadFile(skeletonReference);
            FindAllLowHighPoints();
        }
コード例 #15
0
ファイル: Kernel_bin.cs プロジェクト: stantoxt/OpenVIII
        /// <summary>
        /// Read binary data from into structures and arrays
        /// </summary>
        /// <see cref="http://forums.qhimm.com/index.php?topic=16923.msg240609#msg240609"/>
        /// <seealso cref="https://github.com/alexfilth/doomtrain"/>
        /// <seealso cref="https://github.com/alexfilth/doomtrain/wiki/Kernel.bin"/>
        public KernelBin()
        {
            Memory.Log.WriteLine($"{nameof(KernelBin)} :: new ");
            ArchiveBase aw = ArchiveWorker.Load(ArchiveString);

            byte[]     buffer       = aw.GetBinaryFile(Memory.Strings[Strings.FileID.KERNEL].GetFilenames()[0]);
            List <Loc> subPositions = Memory.Strings[Strings.FileID.KERNEL].GetFiles().subPositions;

            MemoryStream ms;

            if (buffer == null)
            {
                return;
            }
            using (BinaryReader br = new BinaryReader(ms = new MemoryStream(buffer)))
            {
                ms.Seek(subPositions[BattleCommand.ID], SeekOrigin.Begin);
                BattleCommands = BattleCommand.Read(br);
                ms.Seek(subPositions[Magic_Data.id], SeekOrigin.Begin);
                MagicData = Magic_Data.Read(br);
                ms.Seek(subPositions[Junctionable_GFs_Data.id], SeekOrigin.Begin);
                JunctionableGFsData = Junctionable_GFs_Data.Read(br);
                ms.Seek(subPositions[Enemy_Attacks_Data.id], SeekOrigin.Begin);
                EnemyAttacksData = Enemy_Attacks_Data.Read(br);
                ms.Seek(subPositions[Weapons_Data.id], SeekOrigin.Begin);
                WeaponsData = Weapons_Data.Read(br);
                ms.Seek(subPositions[Renzokuken_Finishers_Data.id], SeekOrigin.Begin);
                RenzokukenFinishersData = Renzokuken_Finishers_Data.Read(br);
                ms.Seek(subPositions[Character_Stats.id], SeekOrigin.Begin);
                CharacterStats = Character_Stats.Read(br);
                ms.Seek(subPositions[BattleItemData.ID], SeekOrigin.Begin);
                BattleItemsData    = BattleItemData.Read(br);
                NonBattleItemsData = Non_battle_Items_Data.Read();
                ms.Seek(subPositions[Non_Junctionable_GFs_Attacks_Data.id], SeekOrigin.Begin);
                NonJunctionableGFsAttacksData = Non_Junctionable_GFs_Attacks_Data.Read(br);
                ms.Seek(subPositions[Command_ability_data.id], SeekOrigin.Begin);
                CommandAbilityData = Command_ability_data.Read(br);
                ms.Seek(subPositions[Kernel.JunctionAbilities.ID], SeekOrigin.Begin);
                JunctionAbilities = Kernel.JunctionAbilities.Read(br);
                ms.Seek(subPositions[Kernel.CommandAbilities.ID], SeekOrigin.Begin);
                CommandAbilities = Kernel.CommandAbilities.Read(br);
                ms.Seek(subPositions[StatPercentageAbilities.ID], SeekOrigin.Begin);
                StatPercentAbilities = StatPercentageAbilities.Read(br);
                ms.Seek(subPositions[Kernel.CharacterAbilities.ID], SeekOrigin.Begin);
                CharacterAbilities = Kernel.CharacterAbilities.Read(br);
                ms.Seek(subPositions[Kernel.PartyAbilities.ID], SeekOrigin.Begin);
                PartyAbilities = Kernel.PartyAbilities.Read(br);
                ms.Seek(subPositions[Kernel.GFAbilities.ID], SeekOrigin.Begin);
                GFAbilities = Kernel.GFAbilities.Read(br);
                ms.Seek(subPositions[Kernel.MenuAbilities.ID], SeekOrigin.Begin);
                MenuAbilities = Kernel.MenuAbilities.Read(br);
                ms.Seek(subPositions[Temporary_character_limit_breaks.id], SeekOrigin.Begin);
                TemporaryCharacterLimitBreaks = Temporary_character_limit_breaks.Read(br);
                ms.Seek(subPositions[Blue_Magic_Quistis_limit_break.id], SeekOrigin.Begin);
                BlueMagicQuistisLimitBreak = Blue_Magic_Quistis_limit_break.Read(br);
                //ms.Seek(subPositions[Quistis_limit_break_parameters.BattleID], SeekOrigin.Begin);
                //QuistisLimitBreakParameters = Quistis_limit_break_parameters.Read(br);
                ms.Seek(subPositions[Shot_Irvine_limit_break.id], SeekOrigin.Begin);
                ShotIrvineLimitBreak = Shot_Irvine_limit_break.Read(br);
                ms.Seek(subPositions[Duel_Zell_limit_break.id], SeekOrigin.Begin);
                DuelZellLimitBreak = Duel_Zell_limit_break.Read(br);
                ms.Seek(subPositions[Zell_limit_break_parameters.id], SeekOrigin.Begin);
                ZellLimitBreakParameters = Zell_limit_break_parameters.Read(br);
                ms.Seek(subPositions[Rinoa_limit_breaks_part_1.id], SeekOrigin.Begin);
                RinoaLimitBreaksPart1 = Rinoa_limit_breaks_part_1.Read(br);
                ms.Seek(subPositions[Rinoa_limit_breaks_part_2.id], SeekOrigin.Begin);
                RinoaLimitBreaksPart2 = Rinoa_limit_breaks_part_2.Read(br);
                ms.Seek(subPositions[Slot_array.id], SeekOrigin.Begin);
                SlotArray = Slot_array.Read(br);
                ms.Seek(subPositions[Selphie_limit_break_sets.id], SeekOrigin.Begin);
                SelphieLimitBreakSets = Selphie_limit_break_sets.Read(br);
                ms.Seek(subPositions[Kernel.Devour.id], SeekOrigin.Begin);
                List <Devour> tmp = Kernel.Devour.Read(br);
                tmp.Add(new Devour {
                    Description = Memory.Strings.Read(Strings.FileID.KERNEL, 30, 112)
                });
                Devour = tmp;
                ms.Seek(subPositions[Misc_section.id], SeekOrigin.Begin);
                MiscSection      = Misc_section.Read(br);
                MiscTextPointers = Misc_text_pointers.Read();

                Dictionary <Abilities, Ability> allAbilities = new Dictionary <Abilities, Ability>(Kernel.MenuAbilities.Count + Kernel.JunctionAbilities.Count + Kernel.CommandAbilities.Count + StatPercentageAbilities.Count + Kernel.CharacterAbilities.Count + Kernel.PartyAbilities.Count + Kernel.GFAbilities.Count);
                foreach (Abilities ability in (Abilities[])(Enum.GetValues(typeof(Abilities))))
                {
                    combine(MenuAbilities);
                    combine(StatPercentAbilities);
                    combine(JunctionAbilities);
                    combine(CommandAbilities);
                    combine(CharacterAbilities);
                    combine(PartyAbilities);
                    combine(GFAbilities);
                    void combine <T>(IReadOnlyDictionary <Abilities, T> dict)
                        where T : Ability
                    {
                        if (!dict.TryGetValue(ability, out T a))
                        {
                            return;
                        }
                        allAbilities.Add(ability, a);
                    }
                }

                AllAbilities = allAbilities;
                Dictionary <Abilities, EquippableAbility> equippableAbilities = new Dictionary <Abilities, EquippableAbility>(
                    StatPercentageAbilities.Count +
                    Kernel.CharacterAbilities.Count +
                    Kernel.PartyAbilities.Count +
                    Kernel.GFAbilities.Count);
                foreach (Abilities ability in (Abilities[])(Enum.GetValues(typeof(Abilities))))
                {
                    if (StatPercentAbilities.ContainsKey(ability))
                    {
                        equippableAbilities[ability] = StatPercentAbilities[ability];
                    }
                    else if (CharacterAbilities.ContainsKey(ability))
                    {
                        equippableAbilities[ability] = CharacterAbilities[ability];
                    }
                    else if (PartyAbilities.ContainsKey(ability))
                    {
                        equippableAbilities[ability] = PartyAbilities[ability];
                    }
                    else if (CharacterAbilities.ContainsKey(ability))
                    {
                        equippableAbilities[ability] = CharacterAbilities[ability];
                    }
                }
                EquippableAbilities = equippableAbilities;
            }
        }
コード例 #16
0
ファイル: Archive.cs プロジェクト: murmuzia/OpenVIII-monogame
        public bool Init(ushort?inputFieldID = null, Sections flags = Sections.ALL)
        {
            Flags = flags;
            Memory.SuppressDraw = true;
            var aw   = ArchiveWorker.Load(Memory.Archives.A_FIELD);
            var test = aw.GetListOfFiles();

            //TODO fix endless look on FieldID 50.
            ID = inputFieldID ?? Memory.FieldHolder.FieldID;
            var count = (Memory.FieldHolder.Fields?.Length ?? 0);

            if (ID >= count)
            {
                return(false);
            }
            FileName    = Memory.FieldHolder.GetString(ID);
            ArchiveName = test.FirstOrDefault(x => x.IndexOf(FileName, StringComparison.OrdinalIgnoreCase) >= 0);
            if (string.IsNullOrWhiteSpace(ArchiveName))
            {
                Memory.Log.WriteLine($"FileNotFound :: {ID} - {FileName.ToUpper()}");
                Mod = FieldModes.Disabled;
                return(false);
            }

            var fieldArchive = aw.GetArchive(ArchiveName);
            var listOfFiles  = fieldArchive.GetListOfFiles();

            string findString(string s) =>
            listOfFiles.FirstOrDefault(x => x.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0);

            byte[] getFile(string s)
            {
                s = findString(Path.GetFileNameWithoutExtension(ArchiveName) + s);
                return(!string.IsNullOrWhiteSpace(s) ? fieldArchive.GetBinaryFile(s) : null);
            }

            if (!flags.HasFlag(Sections.MIM | Sections.MAP) ||
                (Background = Background.Load(getFile(".mim"), getFile(".map"))) == null)
            {
                Mod = FieldModes.Disabled;
            }
            if (flags.HasFlag(Sections.CA | Sections.ID))
            {
                Cameras  = Cameras.CreateInstance(getFile(".ca"));
                WalkMesh = WalkMesh.Load(getFile(".ID"), Cameras);
            }

            //let's start with scripts
            var sJsm = findString(".jsm");
            var sSy  = findString(".sy");

            if (flags.HasFlag(Sections.JSM | Sections.SYM) && !string.IsNullOrWhiteSpace(sJsm) && (FileName != "test3"))
            {
                JSMObjects = Scripts.Jsm.File.Read(fieldArchive.GetBinaryFile(sJsm));

                if (Mod != FieldModes.NoJSM)
                {
                    if (!string.IsNullOrWhiteSpace(sSy))
                    {
                        var symObjects = Sym.Reader.FromBytes(fieldArchive.GetBinaryFile(sSy));

                        Services    = Initializer.GetServices();
                        EventEngine = ServiceId.Field[Services].Engine;
                        EventEngine.Reset();
                        for (var objIndex = 0; objIndex < JSMObjects.Count; objIndex++)
                        {
                            var obj         = JSMObjects[objIndex];
                            var fieldObject = new FieldObject(obj.Id, symObjects.GetObjectOrDefault(objIndex).Name);

                            foreach (var script in obj.Scripts)
                            {
                                fieldObject.Scripts.Add(script.ScriptId, script.Segment.GetExecuter());
                            }

                            EventEngine.RegisterObject(fieldObject);
                        }

                        Mod++;
                    }
                    else
                    {
                        Debug.WriteLine($"FileNotFound :: {FileName.ToUpper()}.sy");
                        //sy file might be optional.
                        //Mod = Field_modes.NoJSM;
                    }
                }
            }
            else
            {
                Mod = FieldModes.NoJSM;
                //goto end;
            }

            //if (flags.HasFlag(Sections.MCH))
            //{
            //    byte[] mchB = getFile(".mch");//Field character models
            //}

            //if (flags.HasFlag(Sections.ONE))
            //{
            //    byte[] oneB = getFile(".one");//Field character models container
            //}
            //if (flags.HasFlag(Sections.MSD))
            //{
            //    byte[] msdB = getFile(".msd");//dialogs
            //}
            if (flags.HasFlag(Sections.INF))
            {
                var infData = getFile(".inf");//gateways
                if (infData != null && infData.Length > 0)
                {
                    INF = INF.Load(infData);
                }
            }

            if (flags.HasFlag(Sections.TDW))
            {
                var tdwData = getFile(".tdw");//extra font
                if (tdwData != null && tdwData.Length > 0)
                {
                    TDW = new TDW(tdwData);
                }
            }

            if (flags.HasFlag(Sections.MSK))
            {
                var mskData = getFile(".msk");//movie cam
                if (mskData != null && mskData.Length > 0)
                {
                    MSK = new MSK(mskData);
                }
            }
            if (flags.HasFlag(Sections.RAT | Sections.MRT))
            {
                var ratData = getFile(".rat"); //battle on field
                var mrtData = getFile(".mrt"); //battle on field
                if (ratData != null && mrtData != null && ratData.Length > 0 && mrtData.Length > 0)
                {
                    MrtRat = new MrtRat(mrtData, ratData);
                }
            }
            //if (flags.HasFlag(Sections.PMD))
            //{
            //    byte[] pmdB = getFile(".pmd");//particle info
            //    if (pmdB != null && pmdB.Length > 4)
            //        using (FileStream fs = new FileStream(Path.Combine(Path.GetTempPath(),
            //            $"{Memory.FieldHolder.GetString()}.pmd"), FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
            //            fs.Write(pmdB, 0, pmdB.Length);
            //}
            if (flags.HasFlag(Sections.PMP))
            {
                var pmpData = getFile(".pmp");//particle graphic?
                if (pmpData != null && pmpData.Length > 4)
                {
                    PMP = new PMP(pmpData);
                }
            }
            if (flags.HasFlag(Sections.SFX))
            {
                var sfxData = getFile(".sfx");//sound effects
                if (sfxData != null && sfxData.Length > 0)
                {
                    SFX = new SFX(sfxData);
                }
            }

            if (Mod == FieldModes.NoJSM && Background == null)
            {
                Mod = FieldModes.Disabled;
            }
            return(SFX != null || PMP != null || MrtRat != null || MSK != null || TDW != null || INF != null ||
                   JSMObjects != null || EventEngine != null || Cameras != null || WalkMesh != null ||
                   Background != null || Services != null);
        }
コード例 #17
0
ファイル: Archive.cs プロジェクト: hollow87/OpenVIII
        public bool Init(ushort?inputFieldID = null, Sections flags = Sections.ALL)
        {
            Flags = flags;
            Memory.SuppressDraw = true;
            ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_FIELD);

            string[] test = aw.GetListOfFiles();
            //TODO fix endless look on FieldID 50.
            ID = inputFieldID ?? Memory.FieldHolder.FieldID;
            int count = (Memory.FieldHolder.fields?.Length ?? 0);

            if (ID >= count ||
                ID < 0)
            {
                return(false);
            }
            FileName    = Memory.FieldHolder.GetString(ID);
            ArchiveName = test.FirstOrDefault(x => x.IndexOf(FileName, StringComparison.OrdinalIgnoreCase) >= 0);
            if (string.IsNullOrWhiteSpace(ArchiveName))
            {
                Debug.WriteLine($"FileNotFound :: {ID} - {FileName.ToUpper()}");
                Mod = Field_modes.DISABLED;
                return(false);
            }

            ArchiveBase fieldArchive = aw.GetArchive(ArchiveName);

            string[] filelist = fieldArchive.GetListOfFiles();
            string findstr(string s) =>
            filelist.FirstOrDefault(x => x.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0);

            byte[] getfile(string s)
            {
                s = findstr(s);
                if (!string.IsNullOrWhiteSpace(s))
                {
                    return(fieldArchive.GetBinaryFile(s));
                }
                else
                {
                    return(null);
                }
            }

            if (!flags.HasFlag(Sections.MIM | Sections.MAP) || (Background = Background.Load(getfile(".mim"), getfile(".map"))) == null)
            {
                Mod = Field_modes.DISABLED;
            }
            if (flags.HasFlag(Sections.CA | Sections.ID))
            {
                Cameras  = Cameras.Load(getfile(".ca"));
                WalkMesh = WalkMesh.Load(getfile(".id"), Cameras);
            }

            //let's start with scripts
            string s_jsm = findstr(".jsm");
            string s_sy  = findstr(".sy");

            if (flags.HasFlag(Sections.JSM | Sections.SYM) && !string.IsNullOrWhiteSpace(s_jsm) && (FileName != "test3"))
            {
                //try
                //{
                jsmObjects = Scripts.Jsm.File.Read(fieldArchive.GetBinaryFile(s_jsm));
                //}
                //catch (Exception e)
                //{
                //   Debug.WriteLine(e);
                //Mod = Field_modes.NOJSM;
                //}
                if (Mod != Field_modes.NOJSM)
                {
                    Sym.GameObjects symObjects;
                    if (!string.IsNullOrWhiteSpace(s_sy))
                    {
                        symObjects = Sym.Reader.FromBytes(fieldArchive.GetBinaryFile(s_sy));

                        services    = Initializer.GetServices();
                        EventEngine = ServiceId.Field[services].Engine;
                        EventEngine.Reset();
                        for (int objIndex = 0; objIndex < jsmObjects.Count; objIndex++)
                        {
                            Scripts.Jsm.GameObject obj         = jsmObjects[objIndex];
                            FieldObject            fieldObject = new FieldObject(obj.Id, symObjects.GetObjectOrDefault(objIndex).Name);

                            foreach (Scripts.Jsm.GameScript script in obj.Scripts)
                            {
                                fieldObject.Scripts.Add(script.ScriptId, script.Segment.GetExecuter());
                            }

                            EventEngine.RegisterObject(fieldObject);
                        }

                        Mod++;
                    }
                    else
                    {
                        Debug.WriteLine($"FileNotFound :: {FileName.ToUpper()}.sy");
                        //sy file might be optional.
                        //Mod = Field_modes.NOJSM;
                    }
                }
            }
            else
            {
                Mod = Field_modes.NOJSM;
                //goto end;
            }

            //if (flags.HasFlag(Sections.MCH))
            //{
            //    byte[] mchb = getfile(".mch");//Field character models
            //}

            //if (flags.HasFlag(Sections.ONE))
            //{
            //    byte[] oneb = getfile(".one");//Field character models container
            //}
            //if (flags.HasFlag(Sections.MSD))
            //{
            //    byte[] msdb = getfile(".msd");//dialogs
            //}
            if (flags.HasFlag(Sections.INF))
            {
                byte[] infb = getfile(".inf");//gateways
                if (infb != null && infb.Length > 0)
                {
                    inf = INF.Load(infb);
                }
            }

            if (flags.HasFlag(Sections.TDW))
            {
                byte[] tdwb = getfile(".tdw");//extra font
                if (tdwb != null && tdwb.Length > 0)
                {
                    tdw = new TDW(tdwb);
                }
            }

            if (flags.HasFlag(Sections.MSK))
            {
                byte[] mskb = getfile(".msk");//movie cam
                if (mskb != null && mskb.Length > 0)
                {
                    msk = new MSK(mskb);
                }
            }
            if (flags.HasFlag(Sections.RAT | Sections.MRT))
            {
                byte[] ratb = getfile(".rat"); //battle on field
                byte[] mrtb = getfile(".mrt"); //battle on field
                if (ratb != null && mrtb != null && ratb.Length > 0 && mrtb.Length > 0)
                {
                    MrtRat = new MrtRat(mrtb, ratb);
                }
            }
            //if (flags.HasFlag(Sections.PMD))
            //{
            //    byte[] pmdb = getfile(".pmd");//particle info
            //    if (pmdb != null && pmdb.Length > 4)
            //        using (FileStream fs = new FileStream(Path.Combine(Path.GetTempPath(),
            //            $"{Memory.FieldHolder.GetString()}.pmd"), FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
            //            fs.Write(pmdb, 0, pmdb.Length);
            //}
            if (flags.HasFlag(Sections.PMP))
            {
                byte[] pmpb = getfile(".pmp");//particle graphic?
                if (pmpb != null && pmpb.Length > 4)
                {
                    pmp = new PMP(pmpb);
                }
            }
            if (flags.HasFlag(Sections.SFX))
            {
                byte[] sfxb = getfile(".sfx");//sound effects
                if (sfxb != null && sfxb.Length > 0)
                {
                    sfx = new SFX(sfxb);
                }
            }

            if (Mod == Field_modes.NOJSM && Background == null)
            {
                Mod = Field_modes.DISABLED;
            }
            if (sfx == null &&
                pmp == null &&
                MrtRat == null &&
                msk == null &&
                tdw == null &&
                inf == null &&
                jsmObjects == null &&
                EventEngine == null &&
                Cameras == null &&
                WalkMesh == null &&
                Background == null &&
                services == null)
            {
                return(false);
            }
            return(true);
        }
コード例 #18
0
        /// <summary>
        /// Read binary data from into structures and arrays
        /// </summary>
        /// <see cref="http://forums.qhimm.com/index.php?topic=16923.msg240609#msg240609"/>
        /// <seealso cref="https://github.com/alexfilth/doomtrain"/>
        /// <seealso cref="https://github.com/alexfilth/doomtrain/wiki/Kernel.bin"/>
        private KernelBin()
        {
            Memory.Log.WriteLine($"{nameof(KernelBin)} :: new ");
            var aw           = ArchiveWorker.Load(ArchiveString);
            var buffer       = aw.GetBinaryFile(Memory.Strings[Strings.FileID.Kernel].GetFileNames()[0]);
            var subPositions = Memory.Strings[Strings.FileID.Kernel].GetFiles().SubPositions;

            MemoryStream ms;

            if (buffer == null)
            {
                return;
            }
            using (var br = new BinaryReader(ms = new MemoryStream(buffer)))
            {
                ms.Seek(subPositions[BattleCommand.ID], SeekOrigin.Begin);
                BattleCommands = BattleCommand.Read(br);
                ms.Seek(subPositions[Kernel.MagicData.ID], SeekOrigin.Begin);
                MagicData = Kernel.MagicData.Read(br);
                ms.Seek(subPositions[Kernel.JunctionableGFsData.ID], SeekOrigin.Begin);
                JunctionableGFsData = Kernel.JunctionableGFsData.Read(br);
                ms.Seek(subPositions[Kernel.EnemyAttacksData.ID], SeekOrigin.Begin);
                EnemyAttacksData = Kernel.EnemyAttacksData.Read(br, BattleCommands);
                ms.Seek(subPositions[Kernel.WeaponsData.ID], SeekOrigin.Begin);
                WeaponsData = Kernel.WeaponsData.Read(br);
                ms.Seek(subPositions[Kernel.RenzokukenFinishersData.ID], SeekOrigin.Begin);
                RenzokukenFinishersData = Kernel.RenzokukenFinishersData.Read(br);
                ms.Seek(subPositions[Kernel.CharacterStats.ID], SeekOrigin.Begin);
                CharacterStats = Kernel.CharacterStats.Read(br);
                ms.Seek(subPositions[BattleItemData.ID], SeekOrigin.Begin);
                BattleItemsData    = BattleItemData.Read(br);
                NonBattleItemsData = Kernel.NonBattleItemsData.Read();
                ms.Seek(subPositions[Kernel.NonJunctionableGFsAttacksData.ID], SeekOrigin.Begin);
                NonJunctionableGFsAttacksData = Kernel.NonJunctionableGFsAttacksData.Read(br);
                ms.Seek(subPositions[Kernel.CommandAbilityData.ID], SeekOrigin.Begin);
                CommandAbilityData = Kernel.CommandAbilityData.Read(br);
                ms.Seek(subPositions[Kernel.JunctionAbilities.ID], SeekOrigin.Begin);
                JunctionAbilities = Kernel.JunctionAbilities.Read(br);
                ms.Seek(subPositions[Kernel.CommandAbility.ID], SeekOrigin.Begin);
                CommandAbilities = Kernel.CommandAbility.Read(br, BattleCommands);
                ms.Seek(subPositions[StatPercentageAbilities.ID], SeekOrigin.Begin);
                StatPercentAbilities = StatPercentageAbilities.Read(br);
                ms.Seek(subPositions[Kernel.CharacterAbilities.ID], SeekOrigin.Begin);
                CharacterAbilities = Kernel.CharacterAbilities.Read(br);
                ms.Seek(subPositions[Kernel.PartyAbilities.ID], SeekOrigin.Begin);
                PartyAbilities = Kernel.PartyAbilities.Read(br);
                ms.Seek(subPositions[Kernel.GFAbilities.ID], SeekOrigin.Begin);
                GFAbilities = Kernel.GFAbilities.Read(br);
                ms.Seek(subPositions[Kernel.MenuAbilities.ID], SeekOrigin.Begin);
                MenuAbilities = Kernel.MenuAbilities.Read(br);
                ms.Seek(subPositions[Kernel.TemporaryCharacterLimitBreaks.ID], SeekOrigin.Begin);
                TemporaryCharacterLimitBreaks = Kernel.TemporaryCharacterLimitBreaks.Read(br);
                ms.Seek(subPositions[Kernel.BlueMagicQuistisLimitBreak.ID], SeekOrigin.Begin);
                BlueMagicQuistisLimitBreak = Kernel.BlueMagicQuistisLimitBreak.Read(br);
                //ms.Seek(subPositions[Quistis_limit_break_parameters.ID], SeekOrigin.Begin);
                //QuistisLimitBreakParameters = Quistis_limit_break_parameters.Read(br);
                ms.Seek(subPositions[Kernel.ShotIrvineLimitBreak.ID], SeekOrigin.Begin);
                ShotIrvineLimitBreak = Kernel.ShotIrvineLimitBreak.Read(br);
                ms.Seek(subPositions[Kernel.DuelZellLimitBreak.ID], SeekOrigin.Begin);
                DuelZellLimitBreak = Kernel.DuelZellLimitBreak.Read(br);
                ms.Seek(subPositions[Kernel.ZellLimitBreakParameters.ID], SeekOrigin.Begin);
                ZellLimitBreakParameters = Kernel.ZellLimitBreakParameters.Read(br);
                ms.Seek(subPositions[Kernel.RinoaLimitBreaksPart1.ID], SeekOrigin.Begin);
                RinoaLimitBreaksPart1 = Kernel.RinoaLimitBreaksPart1.Read(br);
                ms.Seek(subPositions[Kernel.RinoaLimitBreaksPart2.ID], SeekOrigin.Begin);
                RinoaLimitBreaksPart2 = Kernel.RinoaLimitBreaksPart2.Read(br);
                ms.Seek(subPositions[Kernel.SlotArray.ID], SeekOrigin.Begin);
                SlotArray = Kernel.SlotArray.Read(br);
                ms.Seek(subPositions[Kernel.SelphieLimitBreakSets.ID], SeekOrigin.Begin);
                SelphieLimitBreakSets = Kernel.SelphieLimitBreakSets.Read(br);
                ms.Seek(subPositions[Kernel.Devour.ID], SeekOrigin.Begin);
                //List<Devour> tmp = Kernel.Devour.Read(br);
                //tmp.Add(new Devour { Description = Memory.Strings.Read(Strings.FileID.KERNEL, 30, 112) });
                Devour = Kernel.Devour.Read(br);
                ms.Seek(subPositions[Kernel.MiscSection.ID], SeekOrigin.Begin);
                MiscSection      = Kernel.MiscSection.Read(br);
                MiscTextPointers = Kernel.MiscTextPointers.Read();

                var allAbilities = new Dictionary <Abilities, IAbility>(
                    Kernel.MenuAbilities.Count + Kernel.JunctionAbilities.Count + Kernel.CommandAbility.Count +
                    StatPercentageAbilities.Count + Kernel.CharacterAbilities.Count + Kernel.PartyAbilities.Count +
                    Kernel.GFAbilities.Count);

                var equippableAbilities =
                    new Dictionary <Abilities, IEquippableAbility>(
                        StatPercentageAbilities.Count +
                        Kernel.CharacterAbilities.Count +
                        Kernel.PartyAbilities.Count +
                        Kernel.GFAbilities.Count);

                foreach (var ability in (Abilities[])(Enum.GetValues(typeof(Abilities))))
                {
                    combine(MenuAbilities);
                    combine(StatPercentAbilities);
                    combine(JunctionAbilities);
                    combine(CommandAbilities);
                    combine(CharacterAbilities);
                    combine(PartyAbilities);
                    combine(GFAbilities);

                    combine2(StatPercentAbilities);
                    combine2(CharacterAbilities);
                    combine2(PartyAbilities);
                    combine2(CharacterAbilities);

                    void combine <T>(IReadOnlyDictionary <Abilities, T> dict)
                        where T : IAbility
                    {
                        if (!dict.TryGetValue(ability, out var a) || allAbilities.ContainsKey(ability))
                        {
                            return;
                        }
                        allAbilities.Add(ability, a);
                    }

                    void combine2 <T>(IReadOnlyDictionary <Abilities, T> dict)
                        where T : IEquippableAbility
                    {
                        if (!dict.TryGetValue(ability, out var a) || equippableAbilities.ContainsKey(ability))
                        {
                            return;
                        }
                        equippableAbilities.Add(ability, a);
                    }
                }
                AllAbilities        = allAbilities;
                EquippableAbilities = equippableAbilities;
            }
        }