/// <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; }
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; }
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); }
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); }