godzcheater

COD MW2/3 GPD Setting

Mar 10th, 2012
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.83 KB | None | 0 0
  1.     public class GPD_Setting
  2.     {
  3.         public XboxClasses.IO.IO IO;
  4.  
  5.         public System.String Magic = "SEMV";
  6.         public System.Int32 Unknown = 1;
  7.         public System.Int32 Unknown2 = 1;
  8.         public System.Collections.Generic.List<Dvar> Dvars = new System.Collections.Generic.List<Dvar>();
  9.  
  10.         public GPD_Setting(XboxClasses.IO.IO _IO) { IO = _IO; }
  11.  
  12.         public void Read()
  13.         {
  14.             IO.Open(0);
  15.             Magic = IO.Reader.ReadASCII(4);
  16.             if (Magic != "SEMV")
  17.             {
  18.                 throw new System.Exception("Invalid Setting magic: " + Magic);
  19.             }
  20.             Unknown = IO.Reader.ReadInt32();
  21.             Unknown2 = IO.Reader.ReadInt32();
  22.  
  23.             Dvars.Clear();
  24.             while (IO.Position < IO.Length)
  25.             {
  26.                 Dvar Dvar = new Dvar();
  27.                 Dvar.Read(ref IO);
  28.  
  29.                 Dvars.Add(Dvar);
  30.             }
  31.         }
  32.         public void Write()
  33.         {
  34.             IO.Open(0);
  35.             if (Magic != "SEMV")
  36.             {
  37.                 throw new System.Exception("Invalid Setting magic: " + Magic);
  38.             }
  39.             IO.Writer.WriteASCII(Magic);
  40.             IO.Writer.WriteInt32(Unknown);
  41.             IO.Writer.WriteInt32(Unknown2);
  42.             for (System.Int32 i = 0; i < Dvars.Count; i++)
  43.             {
  44.                 Dvars[i].Write(ref IO);
  45.             }
  46.         }
  47.     }
  48.     public class Dvar
  49.     {
  50.         public System.Byte Index = 0;
  51.         public DvarType Type = DvarType.Byte;
  52.         public System.Byte[] data = new System.Byte[0];
  53.  
  54.         public void Read(ref XboxClasses.IO.IO IO)
  55.         {
  56.             Index = IO.Reader.ReadByte();
  57.             Type = (DvarType)IO.Reader.ReadByte();
  58.             if (Type == DvarType.Byte || Type == DvarType.SByte)
  59.             {
  60.                 data = IO.Reader.ReadBytes(1);
  61.             }
  62.             else if (Type == DvarType.Int32 || Type == DvarType.UInt32 || Type == DvarType.Single)
  63.             {
  64.                 data = IO.Reader.ReadBytes(4);
  65.             }
  66.             else if(Type == DvarType.String)
  67.             {
  68.                 System.Collections.Generic.List<System.Byte> ByteList = new System.Collections.Generic.List<System.Byte>();
  69.                 ByteList.Add(IO.Reader.ReadByte());
  70.                 ByteList.Add(IO.Reader.ReadByte());
  71.                 ByteList.Add(IO.Reader.ReadByte());
  72.                 ByteList.Add(IO.Reader.ReadByte());
  73.                 while (true)
  74.                 {
  75.                     System.Byte TempByte = IO.Reader.ReadByte();
  76.                     ByteList.Add(TempByte);
  77.                     if (TempByte == 0)
  78.                     {
  79.                         break;
  80.                     }
  81.                 }
  82.                 data = ByteList.ToArray();
  83.             }
  84.         }
  85.         public void Write(ref XboxClasses.IO.IO IO)
  86.         {
  87.             IO.Writer.WriteUInt8(Index);
  88.             IO.Writer.WriteUInt8((System.Byte)Type);
  89.             IO.Writer.Write(data);
  90.         }
  91.  
  92.         public object Value
  93.         {
  94.             get
  95.             {
  96.                 if (Type == DvarType.Byte || Type == DvarType.SByte)
  97.                 {
  98.                     return data[0];
  99.                 }
  100.                 else if (Type == DvarType.Int32)
  101.                 {
  102.                     return System.BitConverter.ToInt32(data, 0);
  103.                 }
  104.                 else if (Type == DvarType.UInt32)
  105.                 {
  106.                     return System.BitConverter.ToUInt32(data, 0);
  107.                 }
  108.                 else if (Type == DvarType.Single)
  109.                 {
  110.                     return System.BitConverter.ToSingle(data, 0);
  111.                 }
  112.                 else if (Type == DvarType.String)
  113.                 {
  114.                     System.Collections.Generic.List<System.Byte> String = new System.Collections.Generic.List<System.Byte>();
  115.                     for (System.Int32 i = 4; i < data.Length - 1; i++)
  116.                     {
  117.                         String.Add(data[i]);
  118.                     }
  119.                     return System.Text.Encoding.ASCII.GetString(String.ToArray());
  120.                 }
  121.                 return "Unknown settingtype";
  122.             }
  123.             set
  124.             {
  125.                 if (Type == DvarType.Byte || Type == DvarType.SByte)
  126.                 {
  127.                     data = new System.Byte[1] { (System.Byte)value };
  128.                 }
  129.                 else if (Type == DvarType.Int32)
  130.                 {
  131.                     data = System.BitConverter.GetBytes((System.Int32)value);
  132.                 }
  133.                 else if (Type == DvarType.UInt32)
  134.                 {
  135.                     data = System.BitConverter.GetBytes((System.UInt32)value);
  136.                 }
  137.                 else if (Type == DvarType.Single)
  138.                 {
  139.                     data = System.BitConverter.GetBytes((System.Single)value);
  140.                 }
  141.                 else if (Type == DvarType.String)
  142.                 {
  143.                     System.Byte[] StringBytes = System.Text.Encoding.ASCII.GetBytes((System.String)value);
  144.                     System.Collections.Generic.List<System.Byte> ByteList = new System.Collections.Generic.List<System.Byte>();
  145.                     ByteList.Add(data[0]);
  146.                     ByteList.Add(data[1]);
  147.                     ByteList.Add(data[2]);
  148.                     ByteList.Add(data[3]);
  149.                     for (System.Int32 i = 0; i < StringBytes.Length; i++)
  150.                     {
  151.                         ByteList.Add(StringBytes[i]);
  152.                     }
  153.                     ByteList.Add(0);
  154.                     data = ByteList.ToArray();
  155.                 }
  156.             }
  157.         }
  158.     }
  159.     public enum DvarType : byte
  160.     {
  161.         Byte = 1,
  162.         SByte = 2,
  163.         Int32 = 3,
  164.         UInt32 = 4,
  165.         Single = 5,
  166.         String = 6,
  167.     }
Advertisement
Add Comment
Please, Sign In to add comment