Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GPD_Setting
- {
- public XboxClasses.IO.IO IO;
- public System.String Magic = "SEMV";
- public System.Int32 Unknown = 1;
- public System.Int32 Unknown2 = 1;
- public System.Collections.Generic.List<Dvar> Dvars = new System.Collections.Generic.List<Dvar>();
- public GPD_Setting(XboxClasses.IO.IO _IO) { IO = _IO; }
- public void Read()
- {
- IO.Open(0);
- Magic = IO.Reader.ReadASCII(4);
- if (Magic != "SEMV")
- {
- throw new System.Exception("Invalid Setting magic: " + Magic);
- }
- Unknown = IO.Reader.ReadInt32();
- Unknown2 = IO.Reader.ReadInt32();
- Dvars.Clear();
- while (IO.Position < IO.Length)
- {
- Dvar Dvar = new Dvar();
- Dvar.Read(ref IO);
- Dvars.Add(Dvar);
- }
- }
- public void Write()
- {
- IO.Open(0);
- if (Magic != "SEMV")
- {
- throw new System.Exception("Invalid Setting magic: " + Magic);
- }
- IO.Writer.WriteASCII(Magic);
- IO.Writer.WriteInt32(Unknown);
- IO.Writer.WriteInt32(Unknown2);
- for (System.Int32 i = 0; i < Dvars.Count; i++)
- {
- Dvars[i].Write(ref IO);
- }
- }
- }
- public class Dvar
- {
- public System.Byte Index = 0;
- public DvarType Type = DvarType.Byte;
- public System.Byte[] data = new System.Byte[0];
- public void Read(ref XboxClasses.IO.IO IO)
- {
- Index = IO.Reader.ReadByte();
- Type = (DvarType)IO.Reader.ReadByte();
- if (Type == DvarType.Byte || Type == DvarType.SByte)
- {
- data = IO.Reader.ReadBytes(1);
- }
- else if (Type == DvarType.Int32 || Type == DvarType.UInt32 || Type == DvarType.Single)
- {
- data = IO.Reader.ReadBytes(4);
- }
- else if(Type == DvarType.String)
- {
- System.Collections.Generic.List<System.Byte> ByteList = new System.Collections.Generic.List<System.Byte>();
- ByteList.Add(IO.Reader.ReadByte());
- ByteList.Add(IO.Reader.ReadByte());
- ByteList.Add(IO.Reader.ReadByte());
- ByteList.Add(IO.Reader.ReadByte());
- while (true)
- {
- System.Byte TempByte = IO.Reader.ReadByte();
- ByteList.Add(TempByte);
- if (TempByte == 0)
- {
- break;
- }
- }
- data = ByteList.ToArray();
- }
- }
- public void Write(ref XboxClasses.IO.IO IO)
- {
- IO.Writer.WriteUInt8(Index);
- IO.Writer.WriteUInt8((System.Byte)Type);
- IO.Writer.Write(data);
- }
- public object Value
- {
- get
- {
- if (Type == DvarType.Byte || Type == DvarType.SByte)
- {
- return data[0];
- }
- else if (Type == DvarType.Int32)
- {
- return System.BitConverter.ToInt32(data, 0);
- }
- else if (Type == DvarType.UInt32)
- {
- return System.BitConverter.ToUInt32(data, 0);
- }
- else if (Type == DvarType.Single)
- {
- return System.BitConverter.ToSingle(data, 0);
- }
- else if (Type == DvarType.String)
- {
- System.Collections.Generic.List<System.Byte> String = new System.Collections.Generic.List<System.Byte>();
- for (System.Int32 i = 4; i < data.Length - 1; i++)
- {
- String.Add(data[i]);
- }
- return System.Text.Encoding.ASCII.GetString(String.ToArray());
- }
- return "Unknown settingtype";
- }
- set
- {
- if (Type == DvarType.Byte || Type == DvarType.SByte)
- {
- data = new System.Byte[1] { (System.Byte)value };
- }
- else if (Type == DvarType.Int32)
- {
- data = System.BitConverter.GetBytes((System.Int32)value);
- }
- else if (Type == DvarType.UInt32)
- {
- data = System.BitConverter.GetBytes((System.UInt32)value);
- }
- else if (Type == DvarType.Single)
- {
- data = System.BitConverter.GetBytes((System.Single)value);
- }
- else if (Type == DvarType.String)
- {
- System.Byte[] StringBytes = System.Text.Encoding.ASCII.GetBytes((System.String)value);
- System.Collections.Generic.List<System.Byte> ByteList = new System.Collections.Generic.List<System.Byte>();
- ByteList.Add(data[0]);
- ByteList.Add(data[1]);
- ByteList.Add(data[2]);
- ByteList.Add(data[3]);
- for (System.Int32 i = 0; i < StringBytes.Length; i++)
- {
- ByteList.Add(StringBytes[i]);
- }
- ByteList.Add(0);
- data = ByteList.ToArray();
- }
- }
- }
- }
- public enum DvarType : byte
- {
- Byte = 1,
- SByte = 2,
- Int32 = 3,
- UInt32 = 4,
- Single = 5,
- String = 6,
- }
Advertisement
Add Comment
Please, Sign In to add comment