Ejemplo n.º 1
0
            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;
            }
Ejemplo n.º 2
0
            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);
            }
Ejemplo n.º 3
0
 public CMacroFile(string fileName, FFXIATPhraseLoader loaderReference)
 {
     this.Load(fileName, loaderReference);
 }
Ejemplo n.º 4
0
 public SearchForPhrase(FFXIATPhraseLoader reference)
 {
     InitializeComponent();
     sfpvisible = false; // default value
     this.ATPhrasesReference = reference;
 }