Exemplo n.º 1
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;
            }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
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;
            }
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
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, "");
                }
            }
        }
Exemplo n.º 8
0
        public static void Init()
        {
            Memory.Log.WriteLine($"{nameof(Music)} :: {nameof(Init)}");
            // PC 2000 version has an CD audio track for eyes on me. I don't think we can play that.
            const MusicId unkPrefix         = (MusicId)999;
            const MusicId altLoserPrefix    = (MusicId)512;
            const MusicId loserPrefix       = (MusicId)0;
            const MusicId eyesOnMePrefix    = (MusicId)513;
            const MusicId altEyesOnMePrefix = (MusicId)22;

            string[] ext = { ".ogg", ".sgt", ".wav", ".mp3" };
            //Roses and Wine V07 moves most of the sgt files to dmusic_backup
            //it leaves a few files behind. I think because RaW doesn't replace everything.
            //ogg files stored in:
            string RaW_ogg_pt = Extended.GetUnixFullPath(Path.Combine(Memory.FF8DIR, "RaW", "GLOBAL", "Music"));
            // From what I gather the OGG files and the sgt files have the same numerical prefix. I
            // might try to add the functionality to the debug screen monday.

            string dmusic_pt    = Extended.GetUnixFullPath(Path.Combine(Memory.FF8DIRdata, "Music", "dmusic_backup"));
            string music_pt     = Extended.GetUnixFullPath(Path.Combine(Memory.FF8DIRdata, "Music", "dmusic"));
            string music_wav_pt = Extended.GetUnixFullPath(Path.Combine(Memory.FF8DIRdata, "Music"));

            // goal of dicmusic is to be able to select a track by prefix. it adds an list of files
            // with the same prefix. so you can later on switch out which one you want.
            AddMusicPath(RaW_ogg_pt);
            AddMusicPath(music_wav_pt);
            AddMusicPath(dmusic_pt);
            AddMusicPath(music_pt);
            if (!Memory.dicMusic.ContainsKey(eyesOnMePrefix) && Memory.dicMusic.ContainsKey(altEyesOnMePrefix))
            {
                Memory.dicMusic.Add(eyesOnMePrefix, Memory.dicMusic[altEyesOnMePrefix]);
            }
            ArchiveBase a = ArchiveZzz.Load(Memory.Archives.ZZZ_OTHER);

            string[] list = a?.GetListOfFiles();
            if (list != null && list.Length > 0)
            {
                ZZZ = true;
                foreach (string m in list.Where(x => ext.Any(y => x.EndsWith(y, StringComparison.OrdinalIgnoreCase))))
                {
                    AddMusic(m);
                }
            }
            void AddMusicPath(string p)
            {
                if (!string.IsNullOrWhiteSpace(p) && Directory.Exists(p))
                {
                    foreach (string m in Directory.GetFiles(p).Where(x => ext.Any(y => x.EndsWith(y, StringComparison.OrdinalIgnoreCase))))
                    {
                        AddMusic(m);
                    }
                }
            }

            void AddMusic(string m)
            {
                if (ushort.TryParse(Path.GetFileName(m).Substring(0, 3), out ushort key))
                {
                    //mismatched prefix's go here
                    if ((MusicId)key == altLoserPrefix)
                    {
                        key = (ushort)loserPrefix; //loser.ogg and sgt don't match.
                    }
                }
                else if (m.IndexOf("eyes_on_me", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    key = (ushort)eyesOnMePrefix;
                }
                else
                {
                    key = (ushort)unkPrefix;
                }

                if (!Memory.dicMusic.ContainsKey((MusicId)key))
                {
                    Memory.dicMusic.Add((MusicId)key, new List <string> {
                        m
                    });
                }
                else
                {
                    Memory.dicMusic[(MusicId)key].Add(m);
                }
            }
        }
Exemplo n.º 9
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);
        }