Advertisement
Astekk

Ghosts All Client Stats [XBOX]

Jan 4th, 2015
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.17 KB | None | 0 0
  1.    
  2.  
  3.     /*
  4.     in the process of porting this to ps3 :D
  5.      
  6.     Sv_SetClientStats for mw3 and ghost.
  7.     MW3 - 0x22D2E4
  8.     Ghosts - 0x68EE10
  9.     */
  10.      
  11.     /*
  12.     EXAMPLE USAGE (Will set squad points to 1500):
  13.      
  14.     uint clientIndex = ??;
  15.     SetStat<int>(clientIndex, 0x4C2C, 1500);
  16.     */
  17.         public class msg_t
  18.         {
  19.             public uint DataBuffer;
  20.             public uint CommandSize;
  21.             public uint MessageLength;
  22.             public bool Overflowed;
  23.      
  24.             public msg_t()
  25.             {
  26.                 CommandSize = 0x400;
  27.                 DataBuffer = xbc.AllocateMemory(CommandSize);
  28.                 MessageLength = 0;
  29.                 Overflowed = false;
  30.             }
  31.      
  32.             private void UpdateOverflowedBoolean()
  33.             {
  34.                 if (MessageLength > CommandSize)
  35.                 {
  36.                     Overflowed = true;
  37.                 }
  38.             }
  39.      
  40.             private bool IsValidType(Type t)
  41.             {
  42.                 if (t == typeof(bool) || t == typeof(byte) || t == typeof(short) || t == typeof(int) ||
  43.                     t == typeof(long) || t == typeof(ushort) || t == typeof(uint) || t == typeof(ulong) ||
  44.                     t == typeof(float) || t == typeof(double) || t == typeof(string) || t == typeof(byte[]))
  45.                 {
  46.                     return true;
  47.                 }
  48.                 return false;
  49.             }
  50.      
  51.             public void Append<T>(T value, bool littleEndian = false)
  52.             {
  53.                 Type t = typeof(T);
  54.      
  55.                 if (!IsValidType(t))
  56.                 {
  57.                     throw new Exception("msg_t.AppendMessage: Invalid type!");
  58.                 }
  59.      
  60.                 if (t == typeof(bool))
  61.                 {
  62.                     xbc.WriteInt32(DataBuffer + MessageLength, ((bool)(object)value == true) ? 1 : 0);
  63.                     MessageLength += 4;
  64.                 }
  65.                 else if (t == typeof(string))
  66.                 {
  67.                     xbc.WriteString(DataBuffer + MessageLength, (string)(object)value, false);
  68.                     MessageLength += (uint)Encoding.UTF8.GetBytes((string)(object)value).Length;
  69.                 }
  70.                 else if (t == typeof(byte[]))
  71.                 {
  72.                     byte[] bytes = (byte[])(object)value;
  73.                     xbc.SetMemory(DataBuffer + MessageLength, bytes);
  74.                     MessageLength += (uint)bytes.Length;
  75.                 }
  76.                 else if (t == typeof(byte))
  77.                 {
  78.                     xbc.WriteByte(DataBuffer + MessageLength, (byte)(object)value);
  79.                     MessageLength += 1;
  80.                 }
  81.                 else
  82.                 {
  83.                     var bytes = typeof(BitConverter)
  84.                         .GetMethod("GetBytes", new Type[] { value.GetType() })
  85.                         .Invoke(null, new object[] { value });
  86.      
  87.                     byte[] data = (byte[])(object)bytes;
  88.                     if (!littleEndian) Array.Reverse(data);
  89.      
  90.                     xbc.SetMemory(DataBuffer + MessageLength, data);
  91.                     MessageLength += (uint)data.Length;
  92.                 }
  93.      
  94.                 UpdateOverflowedBoolean();
  95.             }
  96.      
  97.             public byte[] GetBytes()
  98.             {
  99.                 if (Overflowed)
  100.                 {
  101.                     throw new Exception("msg_t.GetBytes: Message overflowed buffer!");
  102.                 }
  103.      
  104.                 byte[] bytes = new byte[0x18];
  105.                 BitHelper.WriteUInt32(bytes, 0x00, 0);
  106.                 BitHelper.WriteUInt32(bytes, 0x04, 0);
  107.                 BitHelper.WriteUInt32(bytes, 0x08, DataBuffer);
  108.                 BitHelper.WriteUInt32(bytes, 0x0C, 0);
  109.                 BitHelper.WriteUInt32(bytes, 0x10, CommandSize);
  110.                 BitHelper.WriteUInt32(bytes, 0x14, MessageLength);
  111.                 return bytes;
  112.             }
  113.         }
  114.      
  115.             public uint Client_s(uint clientIndex)
  116.             {
  117.                 uint r9 = 0x839EE000;
  118.                 uint r8 = 0x207E90;
  119.                 uint r10 = 0x6FA80;
  120.                 uint r11 = xbc.ReadUInt32(r9 + r8);
  121.                 r10 = clientIndex * r10;
  122.                 return r10 + r11;
  123.             }
  124.      
  125.             public void SV_SendClientStatMessage(uint clientIndex, msg_t msg)
  126.             {
  127.                 uint addy = xbc.AllocateMemory((uint)0x18);
  128.                 xbc.SetMemory(addy, msg.GetBytes());
  129.                 xbc.Call<uint>(0x824DE710, Client_s(clientIndex), 1, addy);
  130.                 xbc.FreeMemory(addy);
  131.             }
  132.      
  133.             public uint SV_GetClientStatEntry(uint clientIndex)
  134.             {
  135.                 return xbc.Call<uint>(0x824D3548, clientIndex);
  136.             }
  137.      
  138.             private void SetStat(uint index, byte[] value)
  139.             {
  140.                 msg_t msg = new msg_t();
  141.                 msg.Append<byte>(0x5A);
  142.                 msg.Append<byte>(0x00);
  143.                 msg.Append<ushort>((ushort)(value.Length + 6));
  144.                 msg.Append<byte>(0x47);
  145.                 msg.Append<uint>(index);
  146.                 msg.Append<byte>((byte)value.Length);
  147.                 msg.Append<byte[]>(value);
  148.      
  149.                 SV_SendClientStatMessage(clientIndex, msg);
  150.             }
  151.      
  152.             private bool IsValidType(Type t)
  153.             {
  154.                 if (t == typeof(bool) || t == typeof(byte) || t == typeof(short) || t == typeof(int) ||
  155.                     t == typeof(long) || t == typeof(ushort) || t == typeof(uint) || t == typeof(ulong) ||
  156.                     t == typeof(float) || t == typeof(double) || t == typeof(string) || t == typeof(byte[]))
  157.                 {
  158.                     return true;
  159.                 }
  160.                 return false;
  161.             }
  162.      
  163.             public void SetStat<T>(uint index, T value, bool littleEndian = true)
  164.             {
  165.                 Type t = typeof(T);
  166.      
  167.                 if (!IsValidType(t))
  168.                 {
  169.                     throw new Exception("Client.SetStat: Invalid type!");
  170.                 }
  171.      
  172.                 if (t == typeof(string))
  173.                 {
  174.                     string str = (string)(object)value;
  175.                     SetStat(index, Encoding.UTF8.GetBytes(str));
  176.                     return;
  177.                 }
  178.                 else if (t == typeof(byte[]))
  179.                 {
  180.                     SetStat(index, (byte[])(object)value);
  181.                     return;
  182.                 }
  183.                 else if (t == typeof(byte))
  184.                 {
  185.                     SetStat(index, new byte[] { (byte)(object)value });
  186.                     return;
  187.                 }
  188.      
  189.                 var bytes = typeof(BitConverter)
  190.                     .GetMethod("GetBytes", new Type[] { value.GetType() })
  191.                     .Invoke(null, new object[] { value });
  192.      
  193.                 if (!littleEndian) Array.Reverse((byte[])bytes);
  194.                 SetStat(index, (byte[])bytes);
  195.             }
  196.      
  197.             public byte[] GetStat(uint index, uint length)
  198.             {
  199.                 return xbc.GetMemory(SV_GetClientStatEntry(clientIndex) + index, length);
  200.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement