Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace XboxClasses.FileFormats.XUIS
- {
- public class XUIS
- {
- public static XUIS CreateXUIZ(IO.IO IO)
- {
- XUIS XUIS = new XUIS();
- XUIS.IO = IO;
- XUIS.Write();
- return XUIS;
- }
- public void DumpInfo()
- {
- System.Console.WriteLine("Flags[0]: " + Flags[0]);
- System.Console.WriteLine("Flags[1]: " + Flags[1]);
- for (System.UInt16 Index = 0; Index < Strings.Count; Index++)
- System.Console.WriteLine("String[" + Index + "]: " + Strings[Index]);
- }
- #region vars
- public IO.IO IO;
- public System.Byte[] Flags { get; set; }
- public System.Collections.Generic.List<System.String> Strings { get; set; }
- #endregion
- #region init
- public XUIS(IO.IO _IO) { IO = _IO; Read(); }
- public XUIS(System.String FilePath) { IO = new IO.IO(FilePath, System.IO.FileMode.Open, true); Read(); }
- internal XUIS()
- {
- Flags = new System.Byte[] { 2, 2 };
- Strings = new System.Collections.Generic.List<System.String>();
- }
- #endregion
- #region voids
- public void Read()
- {
- IO.BaseStream.Position = 0;
- if (IO.Reader.ReadInt32() != 1481984339)//"XUIS"
- {
- IO.BaseStream.Close();
- throw new InvalidHeader(new System.Exception("Invalid Magic"));
- }
- Flags = IO.Reader.ReadBytes(2);
- if (IO.Reader.ReadUInt32() != IO.BaseStream.Length)
- {
- IO.BaseStream.Close();
- throw new InvalidHeader(new System.Exception("Invalid FileSize"));
- }
- System.UInt16 Count = IO.Reader.ReadUInt16();
- Strings = new System.Collections.Generic.List<System.String>();
- for (System.UInt16 Index = 0; Index < Count; Index++)
- {
- if (Flags[0] == 2)
- Strings.Add(IO.Reader.ReadUTF8String());
- else if (Flags[0] == 1)
- Strings.Add(IO.Reader.ReadUNIString(IO.Reader.ReadUInt16()));
- if (Flags[1] == 1)
- IO.BaseStream.Position += 4;
- }
- }
- public void Write()
- {
- IO.BaseStream.Position = 10;
- IO.Writer.WriteUInt16((System.UInt16)Strings.Count);
- for (System.UInt16 Index = 0; Index < Strings.Count; Index++)
- if (Flags[0] == 2)
- IO.Writer.WriteUTF8String(Strings[Index] + "\0");
- else
- {
- IO.Writer.WriteUInt16((System.UInt16)Strings[Index].Length);
- IO.Writer.WriteUNIString(Strings[Index]);
- }
- IO.BaseStream.SetLength(IO.BaseStream.Position);
- IO.BaseStream.Position = 0;
- IO.Writer.WriteInt32(1481984339);
- IO.Writer.WriteBytes(Flags);
- IO.Writer.WriteUInt32((System.UInt32)IO.BaseStream.Length);
- IO.BaseStream.Flush();
- }
- #endregion
- #region functions
- public override System.String ToString()
- {
- return "Xbox User Interface Strings";
- }
- #endregion
- public class InvalidHeader : System.Exception
- {
- public InvalidHeader(System.Exception Inner) : base("Invalid file header", Inner) { }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement