public static MacroBook[] Load(Character C) { string BookNameFile = C.GetUserFileName("mcr.ttl"); if (!File.Exists(BookNameFile)) { return(null); } BinaryReader BR = new BinaryReader(new FileStream(BookNameFile, FileMode.Open, FileAccess.Read), Encoding.ASCII); int BookCount = 1; if ((BR.BaseStream.Length - 0x18) % 16 != 0 || BR.ReadUInt32() != 1) { BR.Close(); return(null); } else { BookCount = (int)((BR.BaseStream.Length - 0x18) / 16); } BR.BaseStream.Seek(0x18, SeekOrigin.Begin); List <MacroBook> Books = new List <MacroBook>(); for (int i = 0; i < BookCount; ++i) { MacroBook MB = new MacroBook(BookNameFile, i, new string(BR.ReadChars(16)).TrimEnd('\0')); for (int j = 0; j < 10; ++j) { MB.Folders.Add(MacroSet.Load(C.GetUserFileName(string.Format("mcr{0:#####}.dat", 10 * i + j)), string.Format("Macro Set {0}", j + 1))); } Books.Add(MB); } BR.Close(); return(Books.ToArray()); }
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; }
public CharacterMacros(Character C) : base(C.Name) { MacroBook[] Books = MacroBook.Load(C); if (Books != null) { this.Folders.AddRange(Books); } else { for (int j = 0; j < 10; ++j) { this.Folders.Add(MacroSet.Load(C.GetUserFileName(string.Format("mcr{0:#####}.dat", j)), string.Format("Macro Set {0}", j + 1))); } } }
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); }