Advertisement
godzcheater

XUIS Class

Nov 8th, 2012
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.48 KB | None | 0 0
  1. namespace XboxClasses.FileFormats.XUIS
  2. {
  3.     public class XUIS
  4.     {
  5.         public static XUIS CreateXUIZ(IO.IO IO)
  6.         {
  7.             XUIS XUIS = new XUIS();
  8.             XUIS.IO = IO;
  9.             XUIS.Write();
  10.  
  11.             return XUIS;
  12.         }
  13.         public void DumpInfo()
  14.         {
  15.             System.Console.WriteLine("Flags[0]: " + Flags[0]);
  16.             System.Console.WriteLine("Flags[1]: " + Flags[1]);
  17.             for (System.UInt16 Index = 0; Index < Strings.Count; Index++)
  18.                 System.Console.WriteLine("String[" + Index + "]: " + Strings[Index]);
  19.         }
  20.  
  21.         #region vars
  22.         public IO.IO IO;
  23.  
  24.         public System.Byte[] Flags { get; set; }
  25.  
  26.         public System.Collections.Generic.List<System.String> Strings { get; set; }
  27.         #endregion
  28.  
  29.         #region init
  30.         public XUIS(IO.IO _IO) { IO = _IO; Read(); }
  31.         public XUIS(System.String FilePath) { IO = new IO.IO(FilePath, System.IO.FileMode.Open, true); Read(); }
  32.         internal XUIS()
  33.         {
  34.             Flags = new System.Byte[] { 2, 2 };
  35.             Strings = new System.Collections.Generic.List<System.String>();
  36.         }
  37.         #endregion
  38.  
  39.         #region voids
  40.         public void Read()
  41.         {
  42.             IO.BaseStream.Position = 0;
  43.             if (IO.Reader.ReadInt32() != 1481984339)//"XUIS"
  44.             {
  45.                 IO.BaseStream.Close();
  46.                 throw new InvalidHeader(new System.Exception("Invalid Magic"));
  47.             }
  48.             Flags = IO.Reader.ReadBytes(2);
  49.             if (IO.Reader.ReadUInt32() != IO.BaseStream.Length)
  50.             {
  51.                 IO.BaseStream.Close();
  52.                 throw new InvalidHeader(new System.Exception("Invalid FileSize"));
  53.             }
  54.             System.UInt16 Count = IO.Reader.ReadUInt16();
  55.             Strings = new System.Collections.Generic.List<System.String>();
  56.             for (System.UInt16 Index = 0; Index < Count; Index++)
  57.             {
  58.                 if (Flags[0] == 2)
  59.                     Strings.Add(IO.Reader.ReadUTF8String());
  60.                 else if (Flags[0] == 1)
  61.                     Strings.Add(IO.Reader.ReadUNIString(IO.Reader.ReadUInt16()));
  62.                 if (Flags[1] == 1)
  63.                     IO.BaseStream.Position += 4;
  64.             }
  65.         }
  66.         public void Write()
  67.         {
  68.             IO.BaseStream.Position = 10;
  69.             IO.Writer.WriteUInt16((System.UInt16)Strings.Count);
  70.             for (System.UInt16 Index = 0; Index < Strings.Count; Index++)
  71.                 if (Flags[0] == 2)
  72.                     IO.Writer.WriteUTF8String(Strings[Index] + "\0");
  73.                 else
  74.                 {
  75.                     IO.Writer.WriteUInt16((System.UInt16)Strings[Index].Length);
  76.                     IO.Writer.WriteUNIString(Strings[Index]);
  77.                 }
  78.             IO.BaseStream.SetLength(IO.BaseStream.Position);
  79.             IO.BaseStream.Position = 0;
  80.             IO.Writer.WriteInt32(1481984339);
  81.             IO.Writer.WriteBytes(Flags);
  82.             IO.Writer.WriteUInt32((System.UInt32)IO.BaseStream.Length);
  83.             IO.BaseStream.Flush();
  84.         }
  85.         #endregion
  86.  
  87.         #region functions
  88.         public override System.String ToString()
  89.         {
  90.             return "Xbox User Interface Strings";
  91.         }
  92.         #endregion
  93.  
  94.         public class InvalidHeader : System.Exception
  95.         {
  96.             public InvalidHeader(System.Exception Inner) : base("Invalid file header", Inner) { }
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement