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 CMacroFile(string fileName, FFXIATPhraseLoader loaderReference) { this.Load(fileName, loaderReference); }
public SearchForPhrase(FFXIATPhraseLoader reference) { InitializeComponent(); sfpvisible = false; // default value this.ATPhrasesReference = reference; }
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; }
private void MainForm_Load(object sender, EventArgs e) { string s = Environment.CommandLine; if (!File.Exists("FFXI_ME_v2.chm")) { this.helpMainToolStripMenuItem.Visible = false; this.toolStripSeparator3.Visible = false; } int i = s.IndexOf('\"', 1); // file names are probably in quotes when run from Windows. if ((i != -1) && (i < (s.Length - 1))) s = s.Remove(i + 1); LogMessage.LogF("## Running {0} on {1} {2}", s, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString()); LogMessage.LogF("{0}", (Preferences.ShowDebugInfo == true) ? "Debugging Active!" : "Normal Operation Active."); LogMessage.LogF("Checking if East Asian Support is installed."); RegistryKey codepages = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Nls\CodePage"); if (codepages == null) { LogMessage.LogF("..No Code Pages In The Registry Could Be Found, Attempting to continue"); } else { string _932 = (string)codepages.GetValue("932"); // check for shift-jis string _1251 = (string)codepages.GetValue("1251"); string _1252 = (string)codepages.GetValue("1252"); bool notfound = false; if ((_932 == null) || (_932 == String.Empty)) { LogMessage.LogF("..Japanese (Shift-JIS) support not found"); notfound = true; } else LogMessage.LogF("..Japanese (Shift-JIS) support found"); if ((_1251 == null) || (_1251 == String.Empty)) { LogMessage.LogF("..Cyrillic (Windows) support not found"); notfound = true; } else LogMessage.LogF("..Cyrillic (Windows) support found"); if ((_1252 == null) || (_1252 == String.Empty)) { LogMessage.LogF("..Western European (Windows) support not found"); notfound = true; } else LogMessage.LogF("..Western European (Windows) support found"); if (notfound) { if (DialogResult.Cancel == MessageBox.Show( "Japanese, Cyrillic, or Western European support not found.\r\n" + "Please install East Asian Language Support via the Control Panel\r\n" + "under \"Regional and Language Options\" on the \"Language\" tab.\r\n" + "Hit OK to run FFXI ME!, Cancel to Exit.", "Language Support not installed.", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)) { LogMessage.LogF("..East Asian support not found, User chose to exit"); this.Close(); return; } } } this.CursorCopy = null; this.CursorLink = null; this.CreateCursors(); SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged); //MessageBox.Show("Download .NET 2.0 here\r\n" + @"http://www.microsoft.com/downloads/details.aspx?FamilyID=0856EACB-4362-4B0D-8EDD-AAB15C5E04F5&displaylang=en"); LogMessage.LogF("Loading Preferences..."); LoadPreferences(); LogMessage.LogF("..Done Loading Preferences."); if (MainForm.ShowOptionsDialog) { LogMessage.LogF("Options Requested..."); OptionsDialog od = new OptionsDialog("FFXI ME! v2 Options"); od.StartPosition = FormStartPosition.CenterScreen; if (od.ShowDialog() == DialogResult.OK) { SavePreferences(); LogMessage.LogF("Options screen loaded and saved"); } LogMessage.LogF("Exiting application"); this.Close(); return; } try { _ATPhraseLoader = new FFXIATPhraseLoader(Preferences.Language, Preferences.LoadItems, Preferences.LoadKeyItems, Preferences.LoadAutoTranslatePhrases, String.Format("Yekyaa's FFXI ME! v{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString())); } catch (FileNotFoundException exception) { LogMessage.LogF("Missing file in FFXI directory installation: ", exception.FileName); LogMessage.LogF("...Attempting to continue without the Auto-Translate Phrases."); } atphraseBW.DoWork += BuildATBackground; atphraseBW.RunWorkerAsync("buildATMenu"); specialsBW.DoWork += BuildSpecialsBackground; specialsBW.RunWorkerAsync("buildSpecialsMenu"); if (_ATPhraseLoader != null) { this._FFXIInstallPath = this.ATPhraseLoader.GetRegistryKey();// MainFormGetRegistryKey(); } if (buttons == null) buttons = new Button[20]; buttons[0] = buttonCtrl1; buttons[1] = buttonCtrl2; buttons[2] = buttonCtrl3; buttons[3] = buttonCtrl4; buttons[4] = buttonCtrl5; buttons[5] = buttonCtrl6; buttons[6] = buttonCtrl7; buttons[7] = buttonCtrl8; buttons[8] = buttonCtrl9; buttons[9] = buttonCtrl0; buttons[10] = buttonAlt1; buttons[11] = buttonAlt2; buttons[12] = buttonAlt3; buttons[13] = buttonAlt4; buttons[14] = buttonAlt5; buttons[15] = buttonAlt6; buttons[16] = buttonAlt7; buttons[17] = buttonAlt8; buttons[18] = buttonAlt9; buttons[19] = buttonAlt0; }