Exemplo n.º 1
0
        internal static Macro LoadFromXml(XmlElement MacroNode)
        {
            Macro M = new Macro();

            if (MacroNode.Attributes["name"] != null)
            {
                M.Name_ = MacroNode.Attributes["name"].InnerText;
            }
            Encoding E = new FFXIEncoding();

            for (int i = 0; i < 6; ++i)
            {
                XmlNode CommandNode = MacroNode.SelectSingleNode(String.Format("command[@line = {0}]", i + 1));
                if (CommandNode != null && CommandNode is XmlElement)
                {
                    string CommandText = String.Empty;
                    foreach (XmlNode XN in CommandNode.ChildNodes)
                    {
                        if (XN is XmlText)
                        {
                            CommandText += XN.InnerText;
                        }
                    }
                    M.Commands_[i] = CommandText;
                }
            }
            return(M);
        }
Exemplo n.º 2
0
    public static MacroFolder Load(string PathName, string FolderName) {
    FileStream DATFile = null;
      if (File.Exists(PathName)) {
        try { DATFile = new FileStream(PathName, FileMode.Open, FileAccess.Read, FileShare.Read); }
        catch { }
      }
    BinaryReader BR = null;
      if (DATFile != null) {
        try {
          BR = new BinaryReader(DATFile, Encoding.ASCII);
          if (BR.BaseStream.Length != 7624 || BR.ReadUInt32() != 1) {
            BR.Close();
            BR = null;
          }
          if (BR != null) {
            BR.ReadUInt32(); // Unknown - sometimes zero, sometimes 0x80000000
          byte[] StoredMD5 = BR.ReadBytes(16); // MD5 Checksum of the rest of the data
#if VerifyChecksum
            {
            byte[] Data = BR.ReadBytes(7600);
              BR.BaseStream.Seek(-7600, SeekOrigin.Current);
            MD5 Hash = new MD5CryptoServiceProvider();
            byte[] ComputedMD5 = Hash.ComputeHash(Data);
              for (int i = 0; i < 16; ++i) {
                if (StoredMD5[i] != ComputedMD5[i]) {
                string Message = String.Format("MD5 Checksum failure for {0}:\n- Stored Hash  :", PathName);
                  for (int j = 0; j < 16; ++j)
                    Message += String.Format(" {0:X2}", StoredMD5[j]);
                  Message += "\n- Computed Hash:";
                  for (int j = 0; j < 16; ++j)
                    Message += String.Format(" {0:X2}", ComputedMD5[j]);
                  Message += '\n';
                  MessageBox.Show(null, Message, "Warning");
                  break;
                }
              }
            }
#endif
          }
        } catch { }
      }
    MacroSet MS = new MacroSet(FolderName);
      MS.FileName_ = PathName;
      MS.Folders.Add(new MacroFolder("Top Bar (Control)"));
      MS.Folders.Add(new MacroFolder("Bottom Bar (Alt)"));
    Encoding E = new FFXIEncoding();
      for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 10; ++j)
          MS.Folders[i].Macros.Add((BR != null) ? Macro.ReadFromDATFile(BR, E) : new Macro());
      }
      MS.LockTree();
      if (BR != null)
        BR.Close();
      return MS;
    }
Exemplo n.º 3
0
 private static void LoadData()
 {
     AutoTranslator.Data_ = new MessageGroupCollection();
       try {
       string DataFilePath = Path.Combine(POL.GetApplicationPath(AppID.FFXI), "ROM/76/23.DAT");
       FileStream FS = new FileStream(DataFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
       Encoding E = new FFXIEncoding();
       BinaryReader BR = new BinaryReader(FS, E);
     while (FS.Position < FS.Length)
       AutoTranslator.Data_.Add(AutoTranslator.ReadMessageGroup(BR, E));
     BR.Close();
       } catch (Exception E) { Console.WriteLine(E.ToString()); }
 }
Exemplo n.º 4
0
 private static void LoadData()
 {
     AutoTranslator.Data_ = new MessageGroupCollection();
     try {
         string       DataFilePath = Path.Combine(POL.GetApplicationPath(AppID.FFXI), "ROM/76/23.DAT");
         FileStream   FS           = new FileStream(DataFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
         Encoding     E            = new FFXIEncoding();
         BinaryReader BR           = new BinaryReader(FS, E);
         while (FS.Position < FS.Length)
         {
             AutoTranslator.Data_.Add(AutoTranslator.ReadMessageGroup(BR, E));
         }
         BR.Close();
     } catch (Exception E) { Console.WriteLine(E.ToString()); }
 }
Exemplo n.º 5
0
 internal static Macro LoadFromXml(XmlElement MacroNode)
 {
     Macro M = new Macro();
     if (MacroNode.Attributes["name"] != null)
     {
         M.Name_ = MacroNode.Attributes["name"].InnerText;
     }
     Encoding E = new FFXIEncoding();
     for (int i = 0; i < 6; ++i)
     {
         XmlNode CommandNode = MacroNode.SelectSingleNode(String.Format("command[@line = {0}]", i + 1));
         if (CommandNode != null && CommandNode is XmlElement)
         {
             string CommandText = String.Empty;
             foreach (XmlNode XN in CommandNode.ChildNodes)
             {
                 if (XN is XmlText)
                 {
                     CommandText += XN.InnerText;
                 }
             }
             M.Commands_[i] = CommandText;
         }
     }
     return M;
 }
Exemplo n.º 6
0
 private void TranslateItemFile(int JPFileNumber, int ENFileNumber)
 {
     if (!this.mnuTranslateItemNames.Checked && !this.mnuTranslateItemDescriptions.Checked)
     {
         return;
     }
     if (!this.BackupFile(JPFileNumber))
     {
         return;
     }
     try
     {
         string JFileName = FFXI.GetFilePath(JPFileNumber);
         string EFileName = FFXI.GetFilePath(ENFileNumber);
         this.AddLogEntry(String.Format(I18N.GetText("TranslatingItems"), JFileName));
         this.AddLogEntry(String.Format(I18N.GetText("UsingEnglishFile"), EFileName));
         FileStream JStream = new FileStream(JFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
         FileStream EStream = new FileStream(EFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
         if ((JStream.Length % 0xc00) != 0)
         {
             this.AddLogEntry(I18N.GetText("ItemFileSizeBad"));
             goto TranslationDone;
         }
         if (JStream.Length != EStream.Length)
         {
             this.AddLogEntry(I18N.GetText("FileSizeMismatch"));
             goto TranslationDone;
         }
         Things.Item.Type T;
         {
             BinaryReader BR = new BinaryReader(JStream);
             Things.Item.DeduceType(BR, out T);
             BR = new BinaryReader(EStream);
             Things.Item.Type ET;
             Things.Item.DeduceType(BR, out ET);
             if (T != ET)
             {
                 this.AddLogEntry(I18N.GetText("ItemTypeMismatch"));
                 goto TranslationDone;
             }
         }
         ushort StringBase = 0;
         switch (T)
         {
         case Things.Item.Type.Armor:
             StringBase = 36;
             break;
         case Things.Item.Type.Item:
             StringBase = 20;
             break;
         case Things.Item.Type.PuppetItem:
             StringBase = 24;
             break;
         case Things.Item.Type.UsableItem:
             StringBase = 16;
             break;
         case Things.Item.Type.Weapon:
             StringBase = 44;
             break;
         case Things.Item.Type.Slip:
             StringBase = 80;
             break;
         default:
             this.AddLogEntry(I18N.GetText("ItemTypeBad"));
             goto TranslationDone;
         }
         long ItemCount = JStream.Length / 0xc00;
         byte[] JData = new byte[0x280];
         byte[] EData = new byte[0x280];
         MemoryStream JMemStream = new MemoryStream(JData, true);
         MemoryStream EMemStream = new MemoryStream(EData, false);
         FFXIEncoding E = new FFXIEncoding();
         for (long i = 0; i < ItemCount; ++i)
         {
             JStream.Seek(i * 0xc00, SeekOrigin.Begin);
             JStream.Read(JData, 0, 0x280);
             EStream.Seek(i * 0xc00, SeekOrigin.Begin);
             EStream.Read(EData, 0, 0x280);
             FFXIEncryption.Rotate(JData, 5);
             FFXIEncryption.Rotate(EData, 5);
             // Read English or Japanese Name
             List<byte> Name = new List<byte>();
             {
                 MemoryStream MS = null;
                 if (this.mnuTranslateItemNames.Checked)
                 {
                     MS = EMemStream;
                 }
                 else
                 {
                     MS = JMemStream;
                 }
                 MS.Position = StringBase + 4;
                 BinaryReader BR = new BinaryReader(MS);
                 MS.Position = StringBase + 0x1c + BR.ReadUInt32();
                 while (MS.Position < 0x280)
                 {
                     int B = MS.ReadByte();
                     if (B <= 0)
                     {
                         break;
                     }
                     Name.Add((byte)B);
                 }
                 Name.Add(0);
                 while (Name.Count % 4 != 0)
                 {
                     Name.Add(0);
                 }
             }
             // Read English or Japanese Description
             List<byte> Description = new List<byte>();
             {
                 MemoryStream MS = null;
                 if (this.mnuTranslateItemDescriptions.Checked)
                 {
                     EMemStream.Position = StringBase + 4 + 8 * 4;
                     MS = EMemStream;
                 }
                 else
                 {
                     JMemStream.Position = StringBase + 4 + 8 * 1;
                     MS = JMemStream;
                 }
                 BinaryReader BR = new BinaryReader(MS);
                 MS.Position = StringBase + 0x1c + BR.ReadUInt32();
                 while (MS.Position < 0x280)
                 {
                     int B = MS.ReadByte();
                     if (B <= 0)
                     {
                         break;
                     }
                     Description.Add((byte)B);
                 }
                 Description.Add(0);
                 while (Description.Count % 4 != 0)
                 {
                     Description.Add(0);
                 }
             }
             {
                 // Construct a new string table
                 BinaryWriter BW = new BinaryWriter(JMemStream);
                 Array.Clear(JData, StringBase, 0x280 - StringBase);
                 JMemStream.Position = StringBase;
                 uint NameOffset = 0x14; // Right after the string table header
                 uint DescOffset = NameOffset + (uint)Name.Count + 28;
                 BW.Write((uint)2); // String Count
                 BW.Write(NameOffset); // Entry #1
                 BW.Write((uint)0);
                 BW.Write(DescOffset); // Entry #2
                 BW.Write((uint)0);
                 // String #1 - Padding + text bytes
                 BW.Write((uint)1);
                 BW.Write((ulong)0);
                 BW.Write((ulong)0);
                 BW.Write((ulong)0);
                 BW.Write(Name.ToArray());
                 // String #2 - Padding + text bytes
                 BW.Write((uint)1);
                 BW.Write((ulong)0);
                 BW.Write((ulong)0);
                 BW.Write((ulong)0);
                 BW.Write(Description.ToArray());
                 // End marker
                 BW.Write((uint)1);
             }
             // Update file data
             FFXIEncryption.Rotate(JData, 3);
             JStream.Seek(i * 0xc00, SeekOrigin.Begin);
             JStream.Write(JData, 0, 0x280);
         }
         TranslationDone:
         JStream.Close();
         EStream.Close();
     }
     catch
     {
         this.LogFailure("TranslateItemFile");
     }
 }
Exemplo n.º 7
0
 private void TranslateAutoTranslatorFile(int JPFileNumber, int ENFileNumber)
 {
     if (!this.BackupFile(JPFileNumber))
     {
         return;
     }
     try
     {
         string JFileName = FFXI.GetFilePath(JPFileNumber);
         string EFileName = FFXI.GetFilePath(ENFileNumber);
         this.AddLogEntry(String.Format(I18N.GetText("TranslatingAutoTrans"), JFileName));
         this.AddLogEntry(String.Format(I18N.GetText("UsingEnglishFile"), EFileName));
         FileStream ATStream = new FileStream(JFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
         MemoryStream NewStream = new MemoryStream();
         BinaryReader JBR = new BinaryReader(ATStream);
         BinaryWriter JBW = new BinaryWriter(NewStream);
         BinaryReader EBR = new BinaryReader(new FileStream(EFileName, FileMode.Open, FileAccess.Read));
         FFXIEncoding E = new FFXIEncoding();
         while (ATStream.Position != ATStream.Length)
         {
             {
                 // Validate & Copy ID
                 uint JID = JBR.ReadUInt32();
                 uint EID = EBR.ReadUInt32();
                 if ((JID & 0xffff) != 0x102)
                 {
                     this.AddLogEntry(String.Format(I18N.GetText("ATBadJPID"), JID));
                     goto TranslationDone;
                 }
                 if ((EID & 0xffff) != 0x202)
                 {
                     this.AddLogEntry(String.Format(I18N.GetText("ATBadENID"), EID));
                     goto TranslationDone;
                 }
                 if ((EID & 0xffff0000) != (JID & 0xffff0000))
                 {
                     this.AddLogEntry(String.Format(I18N.GetText("ATIDMismatch"), JID, EID));
                     goto TranslationDone;
                 }
                 JBW.Write(JID);
             }
             // Group name -> use English
             JBW.Write(EBR.ReadBytes(32));
             JBR.BaseStream.Position += 32;
             // Completion Text -> based on config
             if (this.mnuPreserveJapaneseATCompletion.Checked)
             {
                 JBW.Write(JBR.ReadBytes(32));
                 EBR.BaseStream.Position += 32;
             }
             else
             {
                 byte[] EnglishCompletion = E.GetBytes(E.GetString(EBR.ReadBytes(32)).ToLowerInvariant());
                 // we want it lowercase
                 if (EnglishCompletion.Length != 32)
                 {
                     this.AddLogEntry(String.Format(I18N.GetText("ATLowercaseProblem"), EnglishCompletion.Length));
                     goto TranslationDone;
                 }
                 JBW.Write(EnglishCompletion);
                 JBR.BaseStream.Position += 32;
             }
             uint JEntryCount = JBR.ReadUInt32();
             uint EEntryCount = EBR.ReadUInt32();
             if (JEntryCount != EEntryCount)
             {
                 this.AddLogEntry(String.Format(I18N.GetText("ATCountMismatch"), JEntryCount, EEntryCount));
                 goto TranslationDone;
             }
             JBW.Write(JEntryCount);
             long EntryBytesPos = JBW.BaseStream.Position;
             JBW.Write((uint)0);
             JBR.BaseStream.Position += 4;
             EBR.BaseStream.Position += 4;
             for (uint i = 0; i < JEntryCount; ++i)
             {
                 // Validate & Copy ID
                 uint JID = JBR.ReadUInt32();
                 uint EID = EBR.ReadUInt32();
                 if ((JID & 0xffff) != 0x102)
                 {
                     this.AddLogEntry(String.Format(I18N.GetText("ATBadJPID"), JID));
                     goto TranslationDone;
                 }
                 if ((EID & 0xffff) != 0x202)
                 {
                     this.AddLogEntry(String.Format(I18N.GetText("ATBadENID"), EID));
                     goto TranslationDone;
                 }
                 if ((EID & 0xffff0000) != (JID & 0xffff0000))
                 {
                     this.AddLogEntry(String.Format(I18N.GetText("ATIDMismatch"), JID, EID));
                     goto TranslationDone;
                 }
                 JBW.Write(JID);
                 // Display text -> use English
                 byte[] EnglishText = EBR.ReadBytes(EBR.ReadByte());
                 JBW.Write((byte)EnglishText.Length);
                 JBW.Write(EnglishText);
                 JBR.BaseStream.Position += 1 + JBR.ReadByte();
                 // Completion Text -> based on config
                 if (this.mnuPreserveJapaneseATCompletion.Checked)
                 {
                     byte[] JapaneseText = JBR.ReadBytes(JBR.ReadByte());
                     JBW.Write((byte)JapaneseText.Length);
                     JBW.Write(JapaneseText);
                 }
                 else
                 {
                     byte[] LowerEnglishText = E.GetBytes(E.GetString(EnglishText).ToLowerInvariant());
                     JBW.Write((byte)LowerEnglishText.Length);
                     JBW.Write(LowerEnglishText);
                     JBR.BaseStream.Position += 1 + JBR.ReadByte();
                 }
             }
             long EndOfGroupPos = JBW.BaseStream.Position;
             JBW.BaseStream.Position = EntryBytesPos;
             JBW.Write((uint)(EndOfGroupPos - EntryBytesPos - 4));
             JBW.BaseStream.Position = EndOfGroupPos;
         }
         ATStream.Seek(0, SeekOrigin.Begin);
         ATStream.Write(NewStream.ToArray(), 0, (int)NewStream.Length);
         ATStream.SetLength(NewStream.Length);
         TranslationDone:
         ATStream.Close();
         NewStream.Close();
         EBR.Close();
     }
     catch
     {
         this.LogFailure("TranslateAutoTranslator");
     }
 }
Exemplo n.º 8
0
        public static MacroFolder Load(string PathName, string FolderName)
        {
            FileStream DATFile = null;

            if (File.Exists(PathName))
            {
                try { DATFile = new FileStream(PathName, FileMode.Open, FileAccess.Read, FileShare.Read); }
                catch { }
            }
            BinaryReader BR = null;

            if (DATFile != null)
            {
                try {
                    BR = new BinaryReader(DATFile, Encoding.ASCII);
                    if (BR.BaseStream.Length != 7624 || BR.ReadUInt32() != 1)
                    {
                        BR.Close();
                        BR = null;
                    }
                    if (BR != null)
                    {
                        BR.ReadUInt32();                     // Unknown - sometimes zero, sometimes 0x80000000
                        byte[] StoredMD5 = BR.ReadBytes(16); // MD5 Checksum of the rest of the data
#if VerifyChecksum
                        {
                            byte[] Data = BR.ReadBytes(7600);
                            BR.BaseStream.Seek(-7600, SeekOrigin.Current);
                            MD5    Hash        = new MD5CryptoServiceProvider();
                            byte[] ComputedMD5 = Hash.ComputeHash(Data);
                            for (int i = 0; i < 16; ++i)
                            {
                                if (StoredMD5[i] != ComputedMD5[i])
                                {
                                    string Message = String.Format("MD5 Checksum failure for {0}:\n- Stored Hash  :", PathName);
                                    for (int j = 0; j < 16; ++j)
                                    {
                                        Message += String.Format(" {0:X2}", StoredMD5[j]);
                                    }
                                    Message += "\n- Computed Hash:";
                                    for (int j = 0; j < 16; ++j)
                                    {
                                        Message += String.Format(" {0:X2}", ComputedMD5[j]);
                                    }
                                    Message += '\n';
                                    MessageBox.Show(null, Message, "Warning");
                                    break;
                                }
                            }
                        }
#endif
                    }
                } catch { }
            }
            MacroSet MS = new MacroSet(FolderName);
            MS.FileName_ = PathName;
            MS.Folders.Add(new MacroFolder("Top Bar (Control)"));
            MS.Folders.Add(new MacroFolder("Bottom Bar (Alt)"));
            Encoding E = new FFXIEncoding();
            for (int i = 0; i < 2; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    MS.Folders[i].Macros.Add((BR != null) ? Macro.ReadFromDATFile(BR, E) : new Macro());
                }
            }
            MS.LockTree();
            if (BR != null)
            {
                BR.Close();
            }
            return(MS);
        }