Esempio n. 1
0
        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);
        }
Esempio n. 2
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);
        }