//Splash is 640x400 16BPP typical TIM with palette of ggg bbbbb a rrrrr gg private void ReadSplash() { if (string.IsNullOrWhiteSpace(filename)) { return; } string fn = Path.GetFileNameWithoutExtension(filename); //Debug.Assert(!fn.Equals("ff8", StringComparison.OrdinalIgnoreCase)); ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_MAIN); byte[] buffer = aw.GetBinaryFile(filename); TIM_OVERTURE tim = new TIM_OVERTURE(buffer); if ((fn.Equals("ff8", StringComparison.OrdinalIgnoreCase)) || (fn.IndexOf("loop", StringComparison.OrdinalIgnoreCase) >= 0)) { tim.IgnoreAlpha = true; } tex = TextureHandler.Create(fn, tim, 0);//TIM2.Overture(buffer); //using (FileStream fs = File.Create(Path.Combine("D:\\main", Path.GetFileNameWithoutExtension(filename) + ".png"))) // splashTex.SaveAsPng(fs, splashTex.Width, splashTex.Height); GC.Collect(); GC.WaitForPendingFinalizers(); }
public void GetArchive(Memory.Archive archive, out StreamWithRangeValues fi, out ArchiveBase fs, out StreamWithRangeValues fl) { Memory.Log.WriteLine($"{nameof(ArchiveBase)}::{nameof(GetArchive)} - Reading: {archive.FI}, {archive.FS}, {archive.FL}"); fi = GetStreamWithRangeValues(archive.FI); fs = this; fl = GetStreamWithRangeValues(archive.FL); }
/// <summary> /// Fetch strings from kernel.bin /// </summary> /// <see cref="http://www.balamb.pl/qh/kernel-pointers.htm"/> protected override void LoadArchiveFiles() { Settings = (FF8StringReference.Settings.MultiCharByte | FF8StringReference.Settings.Namedic); ArchiveBase aw = ArchiveWorker.Load(Archive); Files = new StringFile(56); MemoryStream ms = null; byte[] buffer = aw.GetBinaryFile(Filenames[0], true); if (buffer != null) { using (BinaryReader br = new BinaryReader(ms = new MemoryStream(buffer))) { GetFileLocations(br); //index, grab, skip StringLocations = new Dictionary <uint, Tuple <uint, uint, uint> > { //working { 0, new Tuple <uint, uint, uint>(31, 2, 4) }, { 1, new Tuple <uint, uint, uint>(32, 2, 56) }, { 2, new Tuple <uint, uint, uint>(33, 2, 128) }, { 3, new Tuple <uint, uint, uint>(34, 1, 18) },//38,58,178, or 78 { 4, new Tuple <uint, uint, uint>(35, 1, 10) }, { 5, new Tuple <uint, uint, uint>(36, 2, 20) }, { 6, new Tuple <uint, uint, uint>(37, 1, 34) },//+1interval 70 //character names here. { 7, new Tuple <uint, uint, uint>(38, 2, 20) }, { 8, new Tuple <uint, uint, uint>(39, 1, 0) }, { 9, new Tuple <uint, uint, uint>(40, 1, 18) }, { 11, new Tuple <uint, uint, uint>(41, 2, 4) }, { 12, new Tuple <uint, uint, uint>(42, 2, 4) }, { 13, new Tuple <uint, uint, uint>(43, 2, 4) }, { 14, new Tuple <uint, uint, uint>(44, 2, 4) }, { 15, new Tuple <uint, uint, uint>(45, 2, 4) }, { 16, new Tuple <uint, uint, uint>(46, 2, 4) }, { 17, new Tuple <uint, uint, uint>(47, 2, 4) }, { 18, new Tuple <uint, uint, uint>(48, 2, 20) }, { 19, new Tuple <uint, uint, uint>(49, 2, 12) }, { 21, new Tuple <uint, uint, uint>(50, 2, 20) }, { 22, new Tuple <uint, uint, uint>(51, 2, 28) }, { 24, new Tuple <uint, uint, uint>(52, 2, 4) }, { 25, new Tuple <uint, uint, uint>(53, 1, 18) }, { 28, new Tuple <uint, uint, uint>(54, 1, 10) }, { 30, new Tuple <uint, uint, uint>(55, 1, 0) }, }; for (uint key = 0; key < Files.subPositions.Count; key++) { Loc fpos = Files.subPositions[(int)key]; if (StringLocations.ContainsKey(key)) { Get_Strings_BinMSG(br, Filenames[0], key, Files.subPositions[(int)(StringLocations[key].Item1)].Seek, StringLocations[key].Item2, StringLocations[key].Item3); } } ms = null; } } }
protected virtual void Init() { if (Entries == null) { ArchiveBase aw = ArchiveWorker.Load(ArchiveString); InitEntries(aw); InsertCustomEntries(); InitTextures <TEX>(aw); } }
private static void InitNames(ArchiveBase aw) { if (loopsnames == null && namesnames == null && logonames == null) { string[] lof = aw.GetListOfFiles(); loopsnames = lof.Where(x => x.IndexOf(loops, StringComparison.OrdinalIgnoreCase) > -1).OrderBy(x => x, StringComparer.OrdinalIgnoreCase).ToList(); namesnames = lof.Where(x => x.IndexOf(names, StringComparison.OrdinalIgnoreCase) > -1).OrderBy(x => x, StringComparer.OrdinalIgnoreCase).ToList(); logonames = lof.Where(x => x.IndexOf("ff8.lzs", StringComparison.OrdinalIgnoreCase) > -1).OrderBy(x => x, StringComparer.OrdinalIgnoreCase).ToList(); } }
public static void Init() { Memory.Log.WriteLine($"{nameof(Init_debugger_battle)} :: {nameof(Init)}"); ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_BATTLE); byte[] sceneOut = aw.GetBinaryFile("scene.out"); Memory.Encounters = Battle.Encounters.Read(sceneOut); Battle.Mag.Init(); //Memory.Encounters.CurrentIndex = 87; }
protected override void LoadArchiveFiles() { Files = new StringFile(118); GetFileLocations(); ArchiveBase aw = ArchiveWorker.Load(Archive, true); MemoryStream ms = null; byte[] buffer = aw.GetBinaryFile(Filenames[0], true); if (buffer != null) { using (BinaryReader br = new BinaryReader(ms = new MemoryStream(buffer))) { //string contain padding values at start of file //then location data before strings StringsPadLoc = new uint[] { (uint)SectionID.tkmnmes1, (uint)SectionID.tkmnmes2, (uint)SectionID.tkmnmes3 }; //only location data before strings StringsLoc = new uint[] { 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 116 }; //complexstr has locations in first file, //and they have 8 bytes of stuff at the start of each entry, 6 bytes UNK and ushort length? //also can have multiple null ending strings per entry. ComplexStr = new Dictionary <uint, List <uint> > { { 74, new List <uint> { 75, 76, 77, 78, 79, 80 } } }; //these files come in pairs. the bin has string offsets and 6 bytes of other data //msg is where the strings are. BinMSG = new Dictionary <uint, uint> { { 106, 111 }, { 107, 112 }, { 108, 113 }, { 109, 114 }, { 110, 115 } }; for (uint key = 0; key < Files.subPositions.Count; key++) { Loc fpos = Files.subPositions[(int)key]; bool pad = (Array.IndexOf(StringsPadLoc, key) >= 0); if (pad || Array.IndexOf(StringsLoc, key) >= 0) { Get_Strings_Offsets(br, Filenames[0], key, pad); } else if (BinMSG.ContainsKey(key)) { Get_Strings_BinMSG(br, Filenames[0], key, Files.subPositions[(int)BinMSG[key]].Seek, 1, 6); } else if (ComplexStr.ContainsKey(key)) { Get_Strings_ComplexStr(br, Filenames[0], key, ComplexStr[key]); } } ms = null; } } }
public Splash(int splashNum, bool bNames = true, bool bLogo = false) { if (splashNum > 0x0f) { return; } ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_MAIN); InitNames(aw); GetName(splashNum, bNames, bLogo); ReadSplash(); }
protected static bool CacheTryGetValue(string path, out ArchiveBase value) { if (!Cache.TryGetValue(path, out value)) { return(false); } if (value != null) { value.Used = DateTime.Now; } return(true); }
private ArchiveWorker(Memory.Archive archive, StreamWithRangeValues fI, ArchiveBase fS, StreamWithRangeValues fL, bool skipList = false) { ArchiveMap = new ArchiveMap(fI, fL, fS.GetMaxSize(archive)); Archive = archive; FsArchive = fS; //FS = null; if (!skipList) { GetListOfFiles(); } IsOpen = true; }
protected void GetFileLocations() { ArchiveBase aw = ArchiveWorker.Load(Archive, true); MemoryStream ms = null; byte[] buffer = aw.GetBinaryFile(Filenames[1], true); if (buffer != null) { using (BinaryReader br = new BinaryReader(ms = new MemoryStream(buffer))) { GetFileLocations(br); ms = null; } } }
protected virtual void InitEntries(ArchiveBase aw = null) { if (Entries != null) { return; } if (aw == null) { aw = ArchiveWorker.Load(ArchiveString); } MemoryStream ms; var buffer = aw.GetBinaryFile(IndexFilename); if (buffer == null) { return; } using (var br = new BinaryReader(ms = new MemoryStream(buffer))) { Count = br.ReadUInt32(); var locations = new ushort[Count]; Entries = new Dictionary <uint, Entry>((int)Count); for (uint i = 0; i < Count; i++) { locations[i] = br.ReadUInt16(); ms.Seek(2, SeekOrigin.Current); } byte fid = 0; Entry last = null; for (uint i = 0; i < Count; i++) { ms.Seek(locations[i] + 6, SeekOrigin.Begin); var t = br.ReadByte(); if (t == 0 || t == 96) // known invalid entries in sp2 files have this value. there might be more to it. { Count = i; break; } Entries[i] = new Entry(); Entries[i].LoadfromStreamSP2(br, locations[i], last, ref fid); last = Entries[i]; } } }
public static Data LoadInitOut() { Memory.Log.WriteLine($"{nameof(Saves)} :: {nameof(Data)} :: {nameof(LoadInitOut)} "); ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_MAIN, true); byte[] buffer = aw.GetBinaryFile("init.out"); if (buffer != null && buffer.Length > 0) { using (BinaryReader br = new BinaryReader(new MemoryStream(buffer))) { Data data = new Data(); data.ReadInitOut(br); return(data); } } return(null); }
public void LoadFonts() { Memory.Log.WriteLine($"{nameof(Font)} :: {nameof(LoadFonts)} "); ArchiveBase aw = ArchiveWorker.Load(Memory.Archives.A_MENU); byte[] bufferTex = aw.GetBinaryFile("sysfnt.tex"); TEX tex = new TEX(bufferTex); sysfnt = tex.GetTexture((int)ColorID.White); sysfntbig = TextureHandler.Create("sysfld{0:00}.tex", tex, 2, 1, (int)ColorID.White); byte[] bufferTDW = aw.GetBinaryFile("sysfnt.tdw"); TDW tim = new TDW(bufferTDW); charWidths = tim.CharWidths; menuFont = tim.GetTexture((ushort)ColorID.White); }
protected virtual void InitTextures <T>(ArchiveBase aw = null) where T : Texture_Base, new() { var count = (int)Props.Sum(x => x.Count); if (Textures == null) { Textures = new List <TextureHandler>(count); } if (Textures.Count <= 0) { if (aw == null) { aw = ArchiveWorker.Load(ArchiveString); } T tex; Scale = new Dictionary <uint, Vector2>(count); var b = 0; for (var j = 0; j < Props.Count; j++) { for (uint i = 0; i < Props[j].Count; i++) { tex = new T(); var buffer = aw.GetBinaryFile(string.Format(Props[j].Filename, i + TextureStartOffset)); if (buffer != null) { tex.Load(buffer); if (Props[j].Big != null && ForceOriginal == false && b < Props[j].Big.Count) { var th = TextureHandler.Create(Props[j].Big[b].Filename, tex, 2, Props[j].Big[b++].Split / 2); Textures.Add(th); Scale[i] = Vector2.One; } else { var th = TextureHandler.Create(Props[j].Filename, tex); Textures.Add(th); Scale[i] = th.GetScale(); //scale might not be used outside of texturehandler. } } } } } }
protected static bool CacheTryAdd(string key, ArchiveBase value) { if (!Cache.TryAdd(key, value)) { return(false); } if (value != null) { value.Used = value.Created = DateTime.Now; } if ((Oldest.Count() - MaxInCache) > 0) { Oldest.Where(x => x.Key != key).Reverse().Skip(MaxInCache) .ForEach(x => Cache.TryRemove(x.Key, out var _)); } return(true); }
private ArchiveZzz(Memory.Archive archive, bool skipList = false) { ArchiveBase tempArchive = null; ParentPath = FindParentPath(archive); if (ParentPath != null && ParentPath.Count > 0) { foreach (Memory.Archive p in ParentPath) { if (p.IsDir) { tempArchive = ArchiveBase.Load(p); } else if (tempArchive != null) { throw new Exception("zzz shouldn't be inside an archive."); } } } Archive = archive; if (tempArchive != null) { archive.SetFilename(tempArchive.GetListOfFiles() .FirstOrDefault(x => x.IndexOf(archive.ZZZ, StringComparison.OrdinalIgnoreCase) > 0)); } Memory.Log.WriteLine($"{nameof(ArchiveZzz)}:: opening archiveFile: {archive}"); if (string.IsNullOrWhiteSpace(archive)) { return; } using (BinaryReader br = Open()) { if (br == null) { return; } ArchiveMap = Header.Load(br); } if (!skipList) { GetListOfFiles(); } IsOpen = true; }
protected void LoadArchiveFiles_Simple() { ArchiveBase aw = ArchiveWorker.Load(Archive, true); MemoryStream ms; byte[] buffer = aw.GetBinaryFile(Filenames[0], true); if (buffer != null) { using (BinaryReader br = new BinaryReader(ms = new MemoryStream(buffer, true))) { Files = new StringFile(1); Files.subPositions.Add(new Loc { Seek = 0, Length = uint.MaxValue }); Get_Strings_Offsets(br, Filenames[0], 0); ms = null; } } }
/// <summary> /// Saves the active archive and file list. /// </summary> /// <param name="archive">Memory.Archive</param> /// <param name="skipList">If list generation is unneeded you can skip it by setting true</param> private ArchiveWorker(Memory.Archive archive, bool skipList = false) { if (archive.IsDir) { Memory.Log.WriteLine($"{nameof(ArchiveWorker)}:: opening directory: {archive}"); IsDir = true; } else { Memory.Log.WriteLine($"{nameof(ArchiveWorker)}:: opening archiveFile: {archive}"); } Archive = archive; ParentPath = FindParentPath(archive); ArchiveBase tempArchive = null; if (ParentPath != null && ParentPath.Count > 0) { foreach (var p in ParentPath) { if (tempArchive != null) { tempArchive = tempArchive.GetArchive(p); } else if (p.IsDir || p.IsFile) { tempArchive = ArchiveBase.Load(p); } } } if (tempArchive != null) { tempArchive.GetArchive(archive, out var fi, out FsArchive, out var fl); ArchiveMap = new ArchiveMap(fi, fl, tempArchive.GetMaxSize(archive)); } if (!skipList) { GetListOfFiles(); } IsOpen = true; }
/// <summary> /// Load Archive with out storing FS in byte[] works for archive that aren't compressed. /// </summary> /// <param name="path">Archive file archive.</param> /// <param name="fI">Stream containing the FI file</param> /// <param name="fS">Archive where the FS file is.</param> /// <param name="fL">Stream containing the FL file</param> /// <param name="skipList">Skip generating list of files</param> /// <returns>ArchiveWorker</returns> public static ArchiveBase Load(Memory.Archive path, StreamWithRangeValues fI, ArchiveBase fS, StreamWithRangeValues fL, bool skipList = false) { if (CacheTryGetValue(path, out var value)) { return(value); } value = new ArchiveWorker(path, fI, fS, fL, skipList); if (!value.IsOpen) { value = null; } if (CacheTryAdd(path, value)) { } return(value); }
public static IReadOnlyDictionary <Abilities, Equipable_Ability> EquipableAbilities => s_equipableAbilities; // contains 4 types; /// <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 Kernel_bin() { Memory.Log.WriteLine($"{nameof(Kernel_bin)} :: 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 = null; if (buffer != null) { using (BinaryReader br = new BinaryReader(ms = new MemoryStream(buffer))) { ms.Seek(subPositions[Battle_Commands.id], SeekOrigin.Begin); s_battleCommands = Battle_Commands.Read(br); ms.Seek(subPositions[Magic_Data.id], SeekOrigin.Begin); s_magicData = Magic_Data.Read(br); ms.Seek(subPositions[Junctionable_GFs_Data.id], SeekOrigin.Begin); s_junctionableGFsData = Junctionable_GFs_Data.Read(br); ms.Seek(subPositions[Enemy_Attacks_Data.id], SeekOrigin.Begin); s_enemyAttacksData = Enemy_Attacks_Data.Read(br); ms.Seek(subPositions[Weapons_Data.id], SeekOrigin.Begin); s_weaponsData = Weapons_Data.Read(br); ms.Seek(subPositions[Renzokuken_Finishers_Data.id], SeekOrigin.Begin); s_renzokukenFinishersData = Renzokuken_Finishers_Data.Read(br); ms.Seek(subPositions[Character_Stats.id], SeekOrigin.Begin); s_characterStats = Character_Stats.Read(br); ms.Seek(subPositions[Battle_Items_Data.id], SeekOrigin.Begin); s_battleItemsData = Battle_Items_Data.Read(br); s_nonbattleItemsData = Non_battle_Items_Data.Read(); ms.Seek(subPositions[Non_Junctionable_GFs_Attacks_Data.id], SeekOrigin.Begin); s_nonJunctionableGFsAttacksData = Non_Junctionable_GFs_Attacks_Data.Read(br); ms.Seek(subPositions[Command_ability_data.id], SeekOrigin.Begin); s_commandabilitydata = Command_ability_data.Read(br); ms.Seek(subPositions[Junction_abilities.id], SeekOrigin.Begin); s_junctionabilities = Junction_abilities.Read(br); ms.Seek(subPositions[Command_abilities.id], SeekOrigin.Begin); s_commandabilities = Command_abilities.Read(br); ms.Seek(subPositions[Stat_percent_abilities.id], SeekOrigin.Begin); s_statpercentabilities = Stat_percent_abilities.Read(br); ms.Seek(subPositions[Character_abilities.id], SeekOrigin.Begin); s_characterabilities = Character_abilities.Read(br); ms.Seek(subPositions[Party_abilities.id], SeekOrigin.Begin); s_partyabilities = Party_abilities.Read(br); ms.Seek(subPositions[GF_abilities.id], SeekOrigin.Begin); s_gFabilities = GF_abilities.Read(br); ms.Seek(subPositions[Menu_abilities.id], SeekOrigin.Begin); s_menuabilities = Menu_abilities.Read(br); ms.Seek(subPositions[Temporary_character_limit_breaks.id], SeekOrigin.Begin); s_temporarycharacterlimitbreaks = Temporary_character_limit_breaks.Read(br); ms.Seek(subPositions[Blue_magic_Quistis_limit_break.id], SeekOrigin.Begin); s_bluemagicQuistislimitbreak = Blue_magic_Quistis_limit_break.Read(br); //ms.Seek(subPositions[Quistis_limit_break_parameters.id], SeekOrigin.Begin); //Quistislimitbreakparameters = Quistis_limit_break_parameters.Read(br); ms.Seek(subPositions[Shot_Irvine_limit_break.id], SeekOrigin.Begin); s_shotIrvinelimitbreak = Shot_Irvine_limit_break.Read(br); ms.Seek(subPositions[Duel_Zell_limit_break.id], SeekOrigin.Begin); s_duelZelllimitbreak = Duel_Zell_limit_break.Read(br); ms.Seek(subPositions[Zell_limit_break_parameters.id], SeekOrigin.Begin); s_zelllimitbreakparameters = Zell_limit_break_parameters.Read(br); ms.Seek(subPositions[Rinoa_limit_breaks_part_1.id], SeekOrigin.Begin); s_rinoalimitbreakspart1 = Rinoa_limit_breaks_part_1.Read(br); ms.Seek(subPositions[Rinoa_limit_breaks_part_2.id], SeekOrigin.Begin); s_rinoalimitbreakspart2 = Rinoa_limit_breaks_part_2.Read(br); ms.Seek(subPositions[Slot_array.id], SeekOrigin.Begin); s_slotarray = Slot_array.Read(br); ms.Seek(subPositions[Selphie_limit_break_sets.id], SeekOrigin.Begin); s_selphielimitbreaksets = Selphie_limit_break_sets.Read(br); ms.Seek(subPositions[Devour.id], SeekOrigin.Begin); s_devour_ = Devour.Read(br); s_devour_.Add(new Devour { Description = Memory.Strings.Read(Strings.FileID.KERNEL, 30, 112) }); ms.Seek(subPositions[Misc_section.id], SeekOrigin.Begin); s_miscsection = Misc_section.Read(br); s_misctextpointers = Misc_text_pointers.Read(); s_allAbilities = new Dictionary <Abilities, Ability>( Menu_abilities.count + Junction_abilities.count + Command_abilities.count + Stat_percent_abilities.count + Character_abilities.count + Party_abilities.count + GF_abilities.count); foreach (Abilities ability in (Abilities[])(Enum.GetValues(typeof(Abilities)))) { combine(Menuabilities); combine(Statpercentabilities); combine(Junctionabilities); combine(Commandabilities); combine(Characterabilities); combine(Partyabilities); combine(GFabilities); bool combine <T>(IReadOnlyDictionary <Abilities, T> dict) where T : Ability { if (dict.TryGetValue(ability, out T a)) { s_allAbilities.Add(ability, a); return(true); } return(false); } } s_equipableAbilities = new Dictionary <Abilities, Equipable_Ability>( Stat_percent_abilities.count + Character_abilities.count + Party_abilities.count + GF_abilities.count); foreach (Abilities ability in (Abilities[])(Enum.GetValues(typeof(Abilities)))) { if (Statpercentabilities.ContainsKey(ability)) { s_equipableAbilities[ability] = Statpercentabilities[ability]; } else if (Characterabilities.ContainsKey(ability)) { s_equipableAbilities[ability] = Characterabilities[ability]; } else if (Partyabilities.ContainsKey(ability)) { s_equipableAbilities[ability] = Partyabilities[ability]; } else if (Characterabilities.ContainsKey(ability)) { s_equipableAbilities[ability] = Characterabilities[ability]; } } ms = null; } } }
/// <summary> /// not used in magzine there is no sp2 file. /// </summary> /// <param name="aw"></param> protected override void InitEntries(ArchiveBase aw = null) { }