2022-05-22 15:55:26 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-05-30 14:32:38 +08:00
|
|
|
|
using GTA.Math;
|
2022-06-03 16:28:02 +08:00
|
|
|
|
using System.Net;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
namespace RageCoop.Core
|
|
|
|
|
{
|
|
|
|
|
public class CoreUtils
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public static (byte, byte[]) GetBytesFromObject(object obj)
|
|
|
|
|
{
|
|
|
|
|
switch (obj)
|
|
|
|
|
{
|
|
|
|
|
case byte _:
|
|
|
|
|
return (0x01, BitConverter.GetBytes((byte)obj));
|
|
|
|
|
case short _:
|
|
|
|
|
return (0x02, BitConverter.GetBytes((short)obj));
|
|
|
|
|
case ushort _:
|
|
|
|
|
return (0x03, BitConverter.GetBytes((ushort)obj));
|
|
|
|
|
case int _:
|
|
|
|
|
return (0x04, BitConverter.GetBytes((int)obj));
|
|
|
|
|
case uint _:
|
|
|
|
|
return (0x05, BitConverter.GetBytes((uint)obj));
|
|
|
|
|
case long _:
|
|
|
|
|
return (0x06, BitConverter.GetBytes((long)obj));
|
|
|
|
|
case ulong _:
|
|
|
|
|
return (0x07, BitConverter.GetBytes((ulong)obj));
|
|
|
|
|
case float _:
|
|
|
|
|
return (0x08, BitConverter.GetBytes((float)obj));
|
|
|
|
|
case bool _:
|
|
|
|
|
return (0x09, BitConverter.GetBytes((bool)obj));
|
|
|
|
|
default:
|
|
|
|
|
return (0x0, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-03 16:28:02 +08:00
|
|
|
|
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
|
|
|
|
public static class Extensions
|
|
|
|
|
{
|
2022-05-30 14:32:38 +08:00
|
|
|
|
public static void AddVector3(this List<byte> bytes, Vector3 vec3)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(vec3.X));
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(vec3.Y));
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(vec3.Z));
|
|
|
|
|
}
|
2022-05-30 14:32:38 +08:00
|
|
|
|
public static void AddQuaternion(this List<byte> bytes, Quaternion quat)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(quat.X));
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(quat.Y));
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(quat.Z));
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(quat.W));
|
|
|
|
|
}
|
|
|
|
|
public static void AddInt(this List<byte> bytes,int i)
|
|
|
|
|
{
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(i));
|
|
|
|
|
}
|
|
|
|
|
public static void AddUint(this List<byte> bytes, uint i)
|
|
|
|
|
{
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(i));
|
|
|
|
|
}
|
|
|
|
|
public static void AddLong(this List<byte> bytes, long i)
|
|
|
|
|
{
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(i));
|
|
|
|
|
}
|
|
|
|
|
public static void AddUlong(this List<byte> bytes, ulong i)
|
|
|
|
|
{
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(i));
|
|
|
|
|
}
|
|
|
|
|
public static void AddFloat(this List<byte> bytes, float i)
|
|
|
|
|
{
|
|
|
|
|
bytes.AddRange(BitConverter.GetBytes(i));
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-11 18:41:10 +08:00
|
|
|
|
public static byte[] GetBytes(this string s)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-06-11 18:41:10 +08:00
|
|
|
|
return Encoding.UTF8.GetBytes(s);
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
2022-06-11 18:41:10 +08:00
|
|
|
|
public static string GetString(this byte[] data)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-06-11 18:41:10 +08:00
|
|
|
|
return Encoding.UTF8.GetString(data);
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
2022-06-11 18:41:10 +08:00
|
|
|
|
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|