public CMacroFile(FFXIATPhraseLoader loadreference) { this.version = 0; this._changed = false; MD5Digest = new byte[16]; if (this.Macros == null) this.Macros = new CMacro[20]; this.fName = null; for (int i = 0; i < 20; i++) { this.Macros[i] = new CMacro(); this.Macros[i].MacroNumber = i; } this._FileNumber = 0; this.ATPhraseLoaderReference = loadreference; if (loadreference != null) this.FFXIEncoding = loadreference.FFXIConvert; _thisNode = null; _ctrlNode = null; _altNode = null; }
public bool Load(string fileName, FFXIATPhraseLoader loaderReference) { try { if (loaderReference != null) { if (this.ATPhraseLoaderReference == null) this.ATPhraseLoaderReference = loaderReference; if (this.FFXIEncoding == null) this.FFXIEncoding = loaderReference.FFXIConvert; } FileInfo f = new FileInfo(fileName); if (!f.Exists) { this.Clear(); return false; } if (!IsMacroFile(f)) // Can't access IsMacroFile() from here... Switched it to static, Duh... return false; BinaryReader BR = new BinaryReader(File.Open(fileName, FileMode.Open, FileAccess.Read)); byte[] FillerBytes = new byte[4]; // Read the first four bytes, should come out as an int (01 00 00 00) // This is the basics of an FFXI Macro File... ugh. this.version = BR.ReadUInt32(); if (this.version != 1) { BR.Close(); return false; } int first_index = -1, last_index = -1; first_index = fileName.LastIndexOf('r'); last_index = fileName.LastIndexOf('.'); this.FileNumber = -1; if (fileName.Contains("\\mcr") && fileName.Contains(".dat")) { if ((first_index != -1) && (last_index != -1)) { string number = fileName.Substring(first_index + 1, last_index - (first_index + 1)); if (number == String.Empty) this.FileNumber = 0; else { try { this.FileNumber = Convert.ToInt32(number, 10); } catch (System.FormatException) { LogMessage.Log(fileName + ": Number Parsing Error (not mcr#.dat, but mcr#xxxxxx.dat"); this.FileNumber = -1; } finally { LogMessage.Log(fileName + ":" + this.FileNumber); } } } } FillerBytes = BR.ReadBytes(4); if (this.MD5Digest == null) this.MD5Digest = new byte[16]; this.MD5Digest = BR.ReadBytes(16); this.Changed = false; // it hasn't been updated, it's fresh. // HEADER HAS BEEN READ AT THIS POINT. /*Begin Reading MacroFormat * (0 filler bytes, * 6 lines of 61 chars (61st is null), * 9 chars (9th is null), 1 byte for null) repeat 20 times. */ // Create CMacros Array if (this.Macros == null) this.Macros = new CMacro[20]; for (int i = 0; i < 20; i++) { // Read Lead Null Bytes if (this.Macros[i] == null) this.Macros[i] = new CMacro(); FillerBytes = BR.ReadBytes(4); this.Macros[i].MacroNumber = i; for (int x = 0; x < 6; x++) { if (this.ATPhraseLoaderReference == null) this.Macros[i].Line[x] = this.FFXIEncoding.GetString(BR.ReadBytes(61)); else { String encoded = this.FFXIEncoding.GetString(BR.ReadBytes(61)); String convertedString = String.Empty; for (int c = 0; c < encoded.Length; c++) { if ((encoded[c] == FFXIEncoding.StartMarker) && ((c + 9) < encoded.Length) && (encoded[c + 9] == FFXIEncoding.EndMarker)) { byte one = Convert.ToByte(String.Format("0x{0}{1}", encoded[c + 1], encoded[c + 2]), 16); byte two = Convert.ToByte(String.Format("0x{0}{1}", encoded[c + 3], encoded[c + 4]), 16); byte three = Convert.ToByte(String.Format("0x{0}{1}", encoded[c + 5], encoded[c + 6]), 16); byte four = Convert.ToByte(String.Format("0x{0}{1}", encoded[c + 7], encoded[c + 8]), 16); if (two == 0x00) two = (byte)Preferences.Language; if (Preferences.Language == FFXIATPhraseLoader.ffxiLanguages.LANG_ALL) two = (byte)Preferences.Program_Language; // default to a non-special settable FFXIATPhrase atp = ATPhraseLoaderReference.GetPhraseByID(one, two, three, four); if (atp == null) { convertedString += encoded[c]; } else { convertedString += atp.ToString(); c += 9; } } else convertedString += encoded[c]; } this.Macros[i].Line[x] = convertedString; } } this.Macros[i].Name = this.FFXIEncoding.GetString(BR.ReadBytes(9)); FillerBytes[0] = BR.ReadByte(); // Read last null byte if (this.Macros[i].thisNode != null) { this.Macros[i].thisNode.Text = this.Macros[i].DisplayName(); } } BR.Close(); } // If the end of the stream is reached while reading // the data_en, ignore the error and use the // default settings for the remaining values. catch (UnauthorizedAccessException) { return false; } catch (EndOfStreamException) { return false; } this.fName = fileName; return true; }
public itemFormat(BinaryReader br, FFXIEncoding FFXIConvert) { String[] ItemTexts = new String[9]; itemHeader = new itemHeaderFormat(br); long data_pos = 0; UInt32 num_strings = 0, offset = 0, flags = 0; // Objects (General Items) skip 6 bytes // Objects (General Items) skip 10 bytes (another 4 [UINT32]) sometime before January 8, 2014) if ((itemHeader.ID <= 0x0FFF) && (itemHeader.ID >= 0x0000)) br.BaseStream.Position = itemHeader.HeaderSize + 10; // Usable items skip 2 bytes // Usable Items skip 6 bytes as of March 10, 2008 Update (new UINT32) // Usable Items skip another 4 bytes (total of 10) sometime before January 8, 2014 (new UINT32) else if ((itemHeader.ID <= 0x1FFF) && (itemHeader.ID >= 0x1000)) br.BaseStream.Position = itemHeader.HeaderSize + 10; // Gil skip just 2 bytes else if (itemHeader.ID == 0xFFFF) br.BaseStream.Position = itemHeader.HeaderSize + 2; // Puppet Items, skip 8 bytes else if ((itemHeader.ID <= 0x27FF) && (itemHeader.ID >= 0x2000)) br.BaseStream.Position = itemHeader.HeaderSize + 10; // Unknown is 0x04 bytes not 0x02 // Armor Specific Info, 22 bytes to skip to get to text // 26 in March 10, 2008 Update (new UINT32) else if ((itemHeader.ID <= 0x3FFF) && (itemHeader.ID >= 0x2800)) br.BaseStream.Position = itemHeader.HeaderSize + 26; // Weapon Specific Info, 30 bytes to skip // 34 bytes in March 10, 2008 Update (new UINT32) else if ((itemHeader.ID <= 0x6FFF) && (itemHeader.ID >= 0x4000)) br.BaseStream.Position = itemHeader.HeaderSize + 34; // Unknown, should not have anything in the way... else br.BaseStream.Position = itemHeader.HeaderSize + 2; data_pos = br.BaseStream.Position; num_strings = br.ReadUInt32(); long fallback_pos = 0; for (int i = 0; (i < num_strings); i++) { // if (num_strings >= 5) //{ int x = i; } offset = br.ReadUInt32(); flags = br.ReadUInt32(); fallback_pos = br.BaseStream.Position; // Indicator (UInt32) + UInt32 x 6 Padding before text br.BaseStream.Position = data_pos + offset + 28; byte[] b = new byte[4]; int counter = 0; do { if (br.BaseStream.Position >= br.BaseStream.Length) break; if (b == null) b = new byte[4]; else if ((counter + 4) > b.Length) Array.Resize(ref b, (int)(counter + 4)); b[counter++] = br.ReadByte(); b[counter++] = br.ReadByte(); b[counter++] = br.ReadByte(); b[counter++] = br.ReadByte(); if (b[counter - 1] == 0x00) break; } while (true); /*if (i > ItemTexts.Length) { i = i+0; break; }*/ ItemTexts[i] = FFXIConvert.GetString(b).Trim().Trim("\0\u0001.".ToCharArray()); br.BaseStream.Position = fallback_pos; } text = ItemTexts[0]; if (num_strings <= 4) // Japanese (no log name, same as shortname) logtext = text; else if (num_strings <= 5) // English (shortname, logname is position 3) logtext = ItemTexts[2]; else if (num_strings <= 6) // French (shortname, logname is position 4) logtext = ItemTexts[3]; else if (num_strings <= 9) logtext = ItemTexts[4]; else logtext = text; }
public d_msgFile(BinaryReader _bfile, FFXIEncoding FFXIConvert) : this() { if (_bfile == null) return; _header = new d_msgHeaderFormat(_bfile); if (_bfile.BaseStream.Length != _header.FileSize) { _header = null; return; } _entry_list = new d_msgEntryFormat[_header.EntryCount]; for (int counter = 0; counter < _header.EntryCount; counter++) _entry_list[counter] = new d_msgEntryFormat(_bfile, _header, FFXIConvert); _bfile.Close(); _bfile = null; }
public d_msgFile(String fi, FFXIEncoding FFXIConvert) : this(GetBinaryReader(fi), FFXIConvert) { }
public d_msgEntryFormat(BinaryReader _bfile, d_msgHeaderFormat _header, FFXIEncoding FFXIConvert) { if (_bfile.BaseStream.Position == _bfile.BaseStream.Length) return; // Loader for the new way as of April 2007 long start_of_data_block = _bfile.BaseStream.Position; long saved_pos = _bfile.BaseStream.Position; UInt32 string_count; if (_header.ToCSize == 0) // no ToC, use EntrySize { #region if _header.ToCSize == 0 (Use EntrySize) start_of_data_block = _bfile.BaseStream.Position; if (_header.AreBitsFlipped) string_count = ~(_bfile.ReadUInt32()); else string_count = _bfile.ReadUInt32(); if ((string_count < 1) || (string_count > 100)) { _bfile.BaseStream.Position = start_of_data_block + _header.EntrySize; return; } data = new String[string_count]; byte[] b; UInt32 type = 0; for (int str_cnt = 0; str_cnt < string_count; str_cnt++) { data[str_cnt] = String.Empty; if (_header.AreBitsFlipped) { offset = ~(_bfile.ReadUInt32()); length = ~(_bfile.ReadUInt32()); // Use "length" for flags } else { offset = _bfile.ReadUInt32(); length = _bfile.ReadUInt32(); // Use "length" for flags } saved_pos = _bfile.BaseStream.Position; _bfile.BaseStream.Position = start_of_data_block + offset; type = _bfile.ReadUInt32(); if (_header.AreBitsFlipped) type = ~type; b = new byte[4]; if ((length == 1) && (str_cnt == 0) && (string_count > 3)) // It's not a String. { // Hack right now for Key Items. MessageID = (byte)(type & 0x00FF); // already converted. GroupID = (byte)((type & 0xFF00) >> 8); _bfile.BaseStream.Position = saved_pos; continue; } else if (length == 1) { _bfile.BaseStream.Position = saved_pos; continue; } _bfile.BaseStream.Position += 24; // add 24 bytes to get to actual text. byte[] b_xfer = null; do { b[0] = _bfile.ReadByte(); b[1] = _bfile.ReadByte(); b[2] = _bfile.ReadByte(); b[3] = _bfile.ReadByte(); if (_header.AreBitsFlipped) { b[0] = (byte)(~((uint)b[0])); b[1] = (byte)(~((uint)b[1])); b[2] = (byte)(~((uint)b[2])); b[3] = (byte)(~((uint)b[3])); } if (b_xfer == null) b_xfer = new byte[4]; else Array.Resize(ref b_xfer, b_xfer.Length + 4); b_xfer[b_xfer.Length - 4] = b[0]; b_xfer[b_xfer.Length - 3] = b[1]; b_xfer[b_xfer.Length - 2] = b[2]; b_xfer[b_xfer.Length - 1] = b[3]; if (b[3] == 0x00) break; } while (true); data[str_cnt] = FFXIConvert.GetString(b_xfer).Trim('\0'); _bfile.BaseStream.Position = saved_pos; } _bfile.BaseStream.Position = start_of_data_block + _header.EntrySize; #endregion } else if (_header.EntrySize == 0) // use ToCSize { #region if _header.EntrySize == 0 (Use ToCSize) start_of_data_block = _header.HeaderSize + _header.ToCSize; offset = _bfile.ReadUInt32(); length = _bfile.ReadUInt32(); if (_header.AreBitsFlipped) { offset = ~offset; length = ~length; } saved_pos = _bfile.BaseStream.Position; _bfile.BaseStream.Position = start_of_data_block + offset + 40; data = new String[1]; if (_header.AreBitsFlipped) data[0] = FFXIConvert.GetString(Fix(_bfile.ReadBytes((int)length - 40))).Trim('\0'); else data[0] = FFXIConvert.GetString(_bfile.ReadBytes((int)length - 40)).Trim('\0'); _bfile.BaseStream.Position = saved_pos; #endregion } else return; }
public FFXIATPhraseLoader(int langpref, bool loadobjs, bool loadkeys, bool loadatphrases, String text) { if (this._FFXIConvert == null) this._FFXIConvert = new FFXIEncoding(); if (((langpref >= ffxiLanguages.NUM_LANG_MIN) && (langpref <= ffxiLanguages.NUM_LANG_MAX)) || (langpref == ffxiLanguages.LANG_ALL)) this.LanguagePreference = langpref; this.LoadItems = loadobjs; this.LoadKeyItems = loadkeys; this.LoadAutoTranslatePhrases = loadatphrases; // Load autotranslate phrases here. string s = GetRegistryKey(); if ((s == String.Empty) || (s == null)) { if (LanguagePreference == ffxiLanguages.LANG_ALL) System.Windows.Forms.MessageBox.Show("Unable to load " + Languages[0] + " Auto-Translate Phrases. FFXI Installation Not Found!", "Error While Loading Phrases"); else System.Windows.Forms.MessageBox.Show("Unable to load " + Languages[LanguagePreference] + " Auto-Translate Phrases. FFXI Installation Not Found!", "Error While Loading Phrases"); return; } if (text.CompareTo("LOAD FILE LIST") == 0) { LoadAllFiles(s); return; } try { SplashScreen.EncodingVersion = String.Format("Yekyaa's Encoding v{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); if (text != String.Empty) SplashScreen.TextToDisplay = text; SplashScreen.ProgressVisibility = false; if (langpref != ffxiLanguages.LANG_ALL) { SplashScreen.ShowSplashScreen(LanguagePreference); if (this.LoadAutoTranslatePhrases || this.LoadKeyItems || this.LoadItems) { SplashScreen.SetStatus("Loading Information..."); SplashScreen.ClearProgress(); Thread.Sleep(600); LoadFileIDs(s); SplashScreen.ProgressVisibility = true; if (this.LoadAutoTranslatePhrases) { SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[LanguagePreference] + " Job Lists..."); //ThreadPool.QueueUserWorkItem((WaitCallback)delegate { LoadJobList(); }); LoadJobList(); SplashScreen.EndProgress(); Thread.Sleep(250); SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[LanguagePreference] + " Area Lists..."); //ThreadPool.QueueUserWorkItem((WaitCallback)delegate { LoadAreaList(); }); LoadAreaList(); SplashScreen.EndProgress(); Thread.Sleep(100); SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[LanguagePreference] + " Ability Info..."); //ThreadPool.QueueUserWorkItem((WaitCallback)delegate { LoadAbilityInfo(); }); LoadAbilityInfo(); SplashScreen.EndProgress(); Thread.Sleep(100); SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[LanguagePreference] + " Spell Info..."); //ThreadPool.QueueUserWorkItem((WaitCallback)delegate { LoadSpellInfo(); }); LoadSpellInfo(); SplashScreen.EndProgress(); Thread.Sleep(100); } if (this.LoadItems) { SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[LanguagePreference] + " Item Info..."); //ThreadPool.QueueUserWorkItem((WaitCallback)delegate { LoadItemInfo(); }); LoadItemInfo(); SplashScreen.EndProgress(); Thread.Sleep(100); } if (this.LoadKeyItems) { SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[LanguagePreference] + " Key Item Info..."); //ThreadPool.QueueUserWorkItem((WaitCallback)delegate { LoadKeyItemInfo(); }); LoadKeyItemInfo(); SplashScreen.EndProgress(); Thread.Sleep(100); } if (this.LoadAutoTranslatePhrases) { SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[LanguagePreference] + " Auto-Translate Phrases..."); LoadAutoTranslateFile(); SplashScreen.EndProgress(); } SplashScreen.SetStatus("Loading " + Languages[LanguagePreference] + " Information Completed."); } else Thread.Sleep(5000); // if none are set, still show splashscreen for 5s } else { SplashScreen.ShowSplashScreen(ffxiLanguages.LANG_ALL); if (this.LoadAutoTranslatePhrases || this.LoadKeyItems || this.LoadItems) { SplashScreen.SetStatus("Loading Information..."); SplashScreen.ClearProgress(); Thread.Sleep(600); LoadFileIDs(s); SplashScreen.ProgressVisibility = true; for (int i = ffxiLanguages.NUM_LANG_MIN; i <= ffxiLanguages.NUM_LANG_MAX; i++) { SplashScreen.PictureBox = SplashScreen.Icons[i]; if (this.LoadAutoTranslatePhrases) { SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[i] + " Job Lists..."); LoadJobList(i); SplashScreen.EndProgress(); Thread.Sleep(250); SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[i] + " Area Lists..."); LoadAreaList(i); SplashScreen.EndProgress(); Thread.Sleep(100); SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[i] + " Ability Info..."); LoadAbilityInfo(i); SplashScreen.EndProgress(); Thread.Sleep(100); SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[i] + " Spell Info..."); LoadSpellInfo(i); SplashScreen.EndProgress(); Thread.Sleep(100); } if (this.LoadItems) { SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[i] + " Item Info..."); LoadItemInfo(i); SplashScreen.EndProgress(); Thread.Sleep(100); } if (this.LoadKeyItems) { SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[i] + " Key Item Info..."); LoadKeyItemInfo(i); SplashScreen.EndProgress(); Thread.Sleep(100); } if (this.LoadAutoTranslatePhrases) { SplashScreen.ClearProgress(); SplashScreen.SetStatus("Loading " + Languages[i] + " Auto-Translate Phrases..."); LoadAutoTranslateFile(i); SplashScreen.EndProgress(); } SplashScreen.SetStatus("Loading " + Languages[i] + " Information Completed."); } } else Thread.Sleep(5000); // if none are set, still show splashscreen for 5s SplashScreen.ProgressVisibility = false; } } catch (System.IO.FileNotFoundException e) { System.Windows.Forms.MessageBox.Show(String.Format("Error while loading Files:\r\n{0} -- {1}", e.FileName, e.Message), "Error found!"); _ATPhrases = null; _ATKeys_Items = null; // Do Not Rethrow this exception. It doesn't work out well. } finally { JobList = null; AreaList = null; AbilityInfo = null; SpellInfo = null; _fileNumberArrayList = null; SplashScreen.CloseForm(); } }