Exemple #1
0
        /// <summary>
        /// Should be called only once
        /// </summary>
        public static void Init()
        {
            Memory.Log.WriteLine($"{nameof(Fields)} :: {nameof(Initializer)} :: {nameof(Init)}");
            ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_FIELD);

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

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

            byte[] bytes = mapData.GetBinaryFile(map);
            if (bytes == null)
            {
                return;
            }
            string[] mapList = System.Text.Encoding.UTF8.GetString(bytes)
                               .Replace("\r", "")
                               .Split('\n');

            //Memory.FieldHolder.FieldMemory = new int[1024];
            Memory.FieldHolder.fields = mapList;
            FieldId.FieldId_          = mapList;
        }
Exemple #2
0
        public static Items_In_Menu Read()
        {
            ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_MENU);

            byte[] buffer = aw.GetBinaryFile("mitem.bin");
            if (buffer != null)
            {
                using (BinaryReader br = new BinaryReader(new MemoryStream(buffer)))
                {
                    return(Read(br));
                }
            }
            return(default);
        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));
        }
Exemple #4
0
        /// <summary>
        /// Should be called only once
        /// </summary>
        public static void Init()
        {
            Memory.Log.WriteLine($"{nameof(Fields)} :: {nameof(Initializer)} :: {nameof(Init)}");
            ArchiveWorker aw = new ArchiveWorker(Memory.Archives.A_FIELD);

            ArchiveBase mapdata = aw.GetArchive("mapdata.fs");

            if (mapdata != null)
            {
                string   map      = mapdata.GetListOfFiles()[0];
                string[] maplistb = System.Text.Encoding.UTF8.GetString(mapdata.GetBinaryFile(map))
                                    .Replace("\r", "")
                                    .Split('\n');
                Memory.FieldHolder.fields = maplistb;
                FieldId.FieldId_          = maplistb;
            }
        }
Exemple #5
0
        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)));
        }
Exemple #6
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, "");
                }
            }
        }
Exemple #7
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"/>
        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;
            }
        }
Exemple #8
0
        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);
        }