Advertisement
IAmXeClutch

[Project] PhantomRTM NET 1.8.1

Apr 4th, 2014
2,141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 23.31 KB | None | 0 0
  1. // PhantomRTM.NET version 1.8.1
  2. // Copyright (c) 2016 Joshua Ozeri
  3. //
  4. // You are free to use this code in your software
  5. //  however you are not permitted to sell this
  6. //  code. Give credit where it's due.
  7.  
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.Drawing;
  12. using System.Globalization;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using System.Net;
  19. using System.Net.Sockets;
  20. using System.Windows;
  21. using System.Windows.Forms;
  22.  
  23. namespace XeClutch
  24. {
  25.     public class PhantomRTM
  26.     {
  27.         // Enumerations
  28.         public enum ConsoleColor
  29.         {
  30.             Black,
  31.             Blue,
  32.             BlueGray,
  33.             White,
  34.         };
  35.         public enum ExecutionState
  36.         {
  37.             Pending,
  38.             Reboot,
  39.             Start,
  40.             Stop,
  41.             TitlePending,
  42.             TitleReboot,
  43.             Unknown
  44.         };
  45.  
  46.         // Structures
  47.         public struct HardwareInfo
  48.         {
  49.             public uint Flags;
  50.             public byte NumberOfProcessors, PCIBridgeRevisionID;
  51.             public byte[] ReservedBytes;
  52.             public ushort BldrMagic, BldrFlags;
  53.         }
  54.         public struct Vector2
  55.         {
  56.             public float x, y;
  57.         }
  58.         public struct Vector3
  59.         {
  60.             public float x, y, z;
  61.         }
  62.  
  63.         // Variables
  64.         private TcpClient client;
  65.         public bool Connected;
  66.         private StreamReader sreader;
  67.  
  68.         // Methods
  69.         private string HexString2Ascii(string hexString)
  70.         {
  71.             StringBuilder sb = new StringBuilder();
  72.             for (int i = 0; i <= hexString.Length - 2; i += 2)
  73.                 sb.Append(Convert.ToString(Convert.ToChar(Int32.Parse(hexString.Substring(i, 2), System.Globalization.NumberStyles.HexNumber))));
  74.             return sb.ToString();
  75.         }
  76.         private byte[] StringToByteArray(string hex)
  77.         {
  78.             return Enumerable.Range(0, hex.Length)
  79.                           .Where(x => x % 2 == 0)
  80.                           .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
  81.                           .ToArray();
  82.         }
  83.         public void Command_Eject()
  84.         {
  85.             Command_SendText("dvdeject");
  86.         }
  87.         public void Command_Reboot()
  88.         {
  89.             Command_SendText("magicboot cold");
  90.             Connected = false;
  91.             client.Client.Close();
  92.         }
  93.         public string[] Command_SendText(string Text)
  94.         {
  95.             if (!Connected)
  96.                 return new string[] { "" };
  97.             new BinaryWriter(client.GetStream()).Write(Encoding.ASCII.GetBytes(Text + "\r\n"));
  98.             return sreader.ReadToEnd().Split("\n".ToCharArray());
  99.         }
  100.         public void Command_Shutdown()
  101.         {
  102.             Command_SendText("shutdown");
  103.             Connected = false;
  104.             client.Client.Close();
  105.         }
  106.         public bool Connect(string XboxIP)
  107.         {
  108.             try
  109.             {
  110.                 client = new TcpClient(XboxIP, 730);
  111.                 sreader = new StreamReader(client.GetStream());
  112.                 return Connected = (sreader.ReadLine().ToString().ToLower() == "201- connected");
  113.             }
  114.             catch
  115.             {
  116.                 return false;
  117.             }
  118.         }
  119.         public bool Disconnect()
  120.         {
  121.             try
  122.             {
  123.                 new BinaryWriter(client.GetStream()).Write(Encoding.ASCII.GetBytes("bye\r\n"));
  124.                 Connected = false;
  125.                 client.Client.Close();
  126.                 return true;
  127.             }
  128.             catch
  129.             {
  130.                 return false;
  131.             }
  132.         }
  133.         public void Debug_Freeze()
  134.         {
  135.             Command_SendText("stop");
  136.         }
  137.         public void Debug_UnFreeze()
  138.         {
  139.             Command_SendText("go");
  140.         }
  141.         public void File_Delete(string Path)
  142.         {
  143.             string[] lines = Path.Split("\\".ToCharArray());
  144.             string Directory = "";
  145.             for (int i = 0; i < (lines.Length - 1); i++)
  146.                 Directory += lines[i] + "\\";
  147.             Command_SendText("delete title=\"" + Path + "\" dir=\"" + Directory + "\"");
  148.         }
  149.         public void File_Launch(string Path)
  150.         {
  151.             string[] lines = Path.Split("\\".ToCharArray());
  152.             string Directory = "";
  153.             for (int i = 0; i < lines.Length - 1; i++)
  154.                 Directory += lines[i] + "\\";
  155.             Command_SendText("magicboot title=\"" + Path + "\" directory=\"" + Directory + "\"");
  156.         }
  157.         public string Get_ConsoleID()
  158.         {
  159.             return Command_SendText("getconsoleid")[0].Replace("200- consoleid=", "");
  160.         }
  161.         public string Get_CPUKey()
  162.         {
  163.             return Command_SendText("getcpukey")[0].Replace("200- ", "");
  164.         }
  165.         public string Get_DebugName()
  166.         {
  167.             return Command_SendText("dbgname")[0].Replace("200- ", "");
  168.         }
  169.         public ExecutionState Get_ExecutionState()
  170.         {
  171.             string str = Command_SendText("getexecstate")[0].Replace("200- ", "");
  172.             if (str == "pending")
  173.                 return ExecutionState.Pending;
  174.             else if (str == "reboot")
  175.                 return ExecutionState.Reboot;
  176.             else if (str == "start")
  177.                 return ExecutionState.Start;
  178.             else if (str == "stop")
  179.                 return ExecutionState.Stop;
  180.             else if (str == "pending_title")
  181.                 return ExecutionState.TitlePending;
  182.             else if (str == "reboot_title")
  183.                 return ExecutionState.TitleReboot;
  184.             return ExecutionState.Unknown;
  185.         }
  186.         public HardwareInfo Get_HardwareInfo()
  187.         {
  188.             string[] lines = Command_SendText("hwinfo");
  189.             HardwareInfo info;
  190.             info.Flags = uint.Parse(lines[1].Split(" : ".ToCharArray())[1].Replace("0x", ""), NumberStyles.HexNumber);
  191.             info.NumberOfProcessors = byte.Parse(lines[2].Split(" : ".ToCharArray())[1].Replace("0x", ""), NumberStyles.HexNumber);
  192.             info.PCIBridgeRevisionID = byte.Parse(lines[3].Split(" : ".ToCharArray())[1].Replace("0x", ""), NumberStyles.HexNumber);
  193.             info.ReservedBytes = new byte[6];
  194.             info.ReservedBytes[0] = byte.Parse(lines[4].Split(" : 0x ".ToCharArray())[1].Substring(0, 2), NumberStyles.HexNumber);
  195.             info.ReservedBytes[1] = byte.Parse(lines[4].Split(" : 0x ".ToCharArray())[1].Substring(3, 2), NumberStyles.HexNumber);
  196.             info.ReservedBytes[2] = byte.Parse(lines[4].Split(" : 0x ".ToCharArray())[1].Substring(6, 2), NumberStyles.HexNumber);
  197.             info.ReservedBytes[3] = byte.Parse(lines[4].Split(" : 0x ".ToCharArray())[1].Substring(9, 2), NumberStyles.HexNumber);
  198.             info.ReservedBytes[4] = byte.Parse(lines[4].Split(" : 0x ".ToCharArray())[1].Substring(12, 2), NumberStyles.HexNumber);
  199.             info.ReservedBytes[5] = byte.Parse(lines[4].Split(" : 0x ".ToCharArray())[1].Substring(15, 2), NumberStyles.HexNumber);
  200.             info.BldrMagic = ushort.Parse(lines[5].Split(" : ".ToCharArray())[1].Replace("0x", ""), NumberStyles.HexNumber);
  201.             info.BldrFlags = ushort.Parse(lines[6].Split(" : ".ToCharArray())[1].Replace("0x", ""), NumberStyles.HexNumber);
  202.             return info;
  203.         }
  204.         public uint Get_ProcessID()
  205.         {
  206.             return uint.Parse(Command_SendText("getpid")[0].Replace("200- pid=", "").Replace("0x", ""), NumberStyles.HexNumber);
  207.         }
  208.         public uint Get_TitleAddress()
  209.         {
  210.             return uint.Parse(Command_SendText("altaddr")[0].Replace("200- addr=", "").Replace("0x", ""), NumberStyles.HexNumber);
  211.         }
  212.         public bool Read_Bool(uint Offset)
  213.         {
  214.             return Convert.ToBoolean(Read_Byte(Offset, 1));
  215.         }
  216.         public byte Read_Byte(uint Offset)
  217.         {
  218.             return Read_Byte(Offset, 1)[0];
  219.         }
  220.         public byte[] Read_Byte(uint Offset, uint Length)
  221.         {
  222.             if (!Connected)
  223.             {
  224.                 byte[] ret = new byte[Length];
  225.                 return ret;
  226.             }
  227.             int size = (int)Length;
  228.             string buffer = "";
  229.             while (size > 0)
  230.             {
  231.                 if (size > 0x40)
  232.                 {
  233.                     new BinaryWriter(client.GetStream()).Write(Encoding.ASCII.GetBytes("getmem addr=" + (Offset + (Length - size)) + " length=64\r\n"));
  234.                     while (sreader.ReadLine() != "202- memory data follows") ;
  235.                     sreader.ReadLine();
  236.                     buffer += sreader.ReadLine();
  237.                     size -= 0x40;
  238.                 }
  239.                 else
  240.                 {
  241.                     new BinaryWriter(client.GetStream()).Write(Encoding.ASCII.GetBytes("getmem addr=" + (Offset + (Length - size)) + " length=" + size + "\r\n"));
  242.                     while (sreader.ReadLine() != "202- memory data follows") ;
  243.                     sreader.ReadLine();
  244.                     buffer += sreader.ReadLine();
  245.                     break;
  246.                 }
  247.             }
  248.             return StringToByteArray(buffer);
  249.         }
  250.         public char Read_Char(uint Offset)
  251.         {
  252.             return (char)Read_Byte(Offset);
  253.         }
  254.         public double Read_Double(uint Offset)
  255.         {
  256.             byte[] buffer = Read_Byte(Offset, 8);
  257.             Array.Reverse(buffer);
  258.             return BitConverter.ToDouble(buffer, 0);
  259.         }
  260.         public void Read_File(uint Offset, uint Length, string Path)
  261.         {
  262.             File.WriteAllBytes(Path, Read_Byte(Offset, Length));
  263.         }
  264.         public float Read_Float(uint Offset)
  265.         {
  266.             byte[] buffer = Read_Byte(Offset, 4);
  267.             Array.Reverse(buffer);
  268.             return BitConverter.ToSingle(buffer, 0);
  269.         }
  270.         public short Read_Int16(uint Offset)
  271.         {
  272.             byte[] buffer = Read_Byte(Offset, 2);
  273.             Array.Reverse(buffer);
  274.             return BitConverter.ToInt16(buffer, 0);
  275.         }
  276.         public int Read_Int32(uint Offset)
  277.         {
  278.             byte[] buffer = Read_Byte(Offset, 4);
  279.             Array.Reverse(buffer);
  280.             return BitConverter.ToInt32(buffer, 0);
  281.         }
  282.         public long Read_Int64(uint Offset)
  283.         {
  284.             byte[] buffer = Read_Byte(Offset, 8);
  285.             Array.Reverse(buffer);
  286.             return BitConverter.ToInt64(buffer, 0);
  287.         }
  288.         public sbyte Read_SByte(uint Offset)
  289.         {
  290.             return (sbyte)Read_Byte(Offset);
  291.         }
  292.         public string Read_String(uint Offset, uint Length)
  293.         {
  294.             byte[] buffer = Read_Byte(Offset, Length);
  295.             string str = "";
  296.             foreach (byte bit in buffer)
  297.                 str += bit.ToString("X2");
  298.             return HexString2Ascii(str);
  299.         }
  300.         public ushort Read_UInt16(uint Offset)
  301.         {
  302.             byte[] buffer = Read_Byte(Offset, 2);
  303.             Array.Reverse(buffer);
  304.             return BitConverter.ToUInt16(buffer, 0);
  305.         }
  306.         public uint Read_UInt32(uint Offset)
  307.         {
  308.             byte[] buffer = Read_Byte(Offset, 4);
  309.             Array.Reverse(buffer);
  310.             return BitConverter.ToUInt32(buffer, 0);
  311.         }
  312.         public ulong Read_UInt64(uint Offset)
  313.         {
  314.             byte[] buffer = Read_Byte(Offset, 8);
  315.             Array.Reverse(buffer);
  316.             return BitConverter.ToUInt64(buffer, 0);
  317.         }
  318.         public Vector2 Read_Vector2(uint Offset)
  319.         {
  320.             Vector2 vec;
  321.             vec.x = Read_Float(Offset);
  322.             vec.y = Read_Float(Offset + 4);
  323.             return vec;
  324.         }
  325.         public Vector3 Read_Vector3(uint Offset)
  326.         {
  327.             Vector3 vec;
  328.             vec.x = Read_Float(Offset);
  329.             vec.y = Read_Float(Offset + 4);
  330.             vec.z = Read_Float(Offset + 8);
  331.             return vec;
  332.         }
  333.         public uint Search_Bool(uint StartOffset, uint Length, bool Bool)
  334.         {
  335.             return Search_Byte(StartOffset, Length, (byte)(Bool ? 0x01 : 0x00));
  336.         }
  337.         public uint Search_Byte(uint StartOffset, uint Length, byte Byte)
  338.         {
  339.             return Search_Byte(StartOffset, Length, new byte[] { Byte });
  340.         }
  341.         public uint Search_Byte(uint StartOffset, uint Length, byte[] Bytes)
  342.         {
  343.             if (!Connected)
  344.                 return 0;
  345.             uint addr = StartOffset;
  346.             byte[] data = Read_Byte(StartOffset, Length);
  347.             for (uint i = 0; i < (Length - Bytes.Length); i++)
  348.             {
  349.                 byte[] buffer = new byte[Bytes.Length];
  350.                 Array.Copy(data, i, buffer, 0, Bytes.Length);
  351.                 if (buffer.SequenceEqual(Bytes))
  352.                 {
  353.                     addr += i;
  354.                     break;
  355.                 }
  356.             }
  357.             return addr;
  358.         }
  359.         public uint Search_Char(uint StartOffset, uint Length, char Char)
  360.         {
  361.             return Search_Byte(StartOffset, Length, (byte)Char);
  362.         }
  363.         public uint Search_Double(uint StartOffset, uint Length, double Double)
  364.         {
  365.             byte[] bytes = BitConverter.GetBytes(Double);
  366.             if (BitConverter.IsLittleEndian)
  367.                 Array.Reverse(bytes);
  368.             return Search_Byte(StartOffset, Length, bytes);
  369.         }
  370.         public uint Search_Float(uint StartOffset, uint Length, float Float)
  371.         {
  372.             byte[] bytes = BitConverter.GetBytes(Float);
  373.             if (BitConverter.IsLittleEndian)
  374.                 Array.Reverse(bytes);
  375.             return Search_Byte(StartOffset, Length, bytes);
  376.         }
  377.         public uint Search_Int16(uint StartOffset, uint Length, short Int16)
  378.         {
  379.             byte[] bytes = BitConverter.GetBytes(Int16);
  380.             if (BitConverter.IsLittleEndian)
  381.                 Array.Reverse(bytes);
  382.             return Search_Byte(StartOffset, Length, bytes);
  383.         }
  384.         public uint Search_Int32(uint StartOffset, uint Length, int Int32)
  385.         {
  386.             byte[] bytes = BitConverter.GetBytes(Int32);
  387.             if (BitConverter.IsLittleEndian)
  388.                 Array.Reverse(bytes);
  389.             return Search_Byte(StartOffset, Length, bytes);
  390.         }
  391.         public uint Search_Int64(uint StartOffset, uint Length, long Int64)
  392.         {
  393.             byte[] bytes = BitConverter.GetBytes(Int64);
  394.             if (BitConverter.IsLittleEndian)
  395.                 Array.Reverse(bytes);
  396.             return Search_Byte(StartOffset, Length, bytes);
  397.         }
  398.         public uint Search_String(uint StartOffset, uint Length, string String)
  399.         {
  400.             return Search_Byte(StartOffset, (uint)String.Length, Encoding.ASCII.GetBytes(String));
  401.         }
  402.         public uint Search_SByte(uint StartOffset, uint Length, sbyte SByte)
  403.         {
  404.             return Search_Byte(StartOffset, Length, (byte)SByte);
  405.         }
  406.         public uint Search_UInt16(uint StartOffset, uint Length, ushort UInt16)
  407.         {
  408.             byte[] bytes = BitConverter.GetBytes(UInt16);
  409.             if (BitConverter.IsLittleEndian)
  410.                 Array.Reverse(bytes);
  411.             return Search_Byte(StartOffset, Length, bytes);
  412.         }
  413.         public uint Search_UInt32(uint StartOffset, uint Length, uint UInt32)
  414.         {
  415.             byte[] bytes = BitConverter.GetBytes(UInt32);
  416.             if (BitConverter.IsLittleEndian)
  417.                 Array.Reverse(bytes);
  418.             return Search_Byte(StartOffset, Length, bytes);
  419.         }
  420.         public uint Search_UInt64(uint StartOffset, uint Length, ulong UInt64)
  421.         {
  422.             byte[] bytes = BitConverter.GetBytes(UInt64);
  423.             if (BitConverter.IsLittleEndian)
  424.                 Array.Reverse(bytes);
  425.             return Search_Byte(StartOffset, Length, bytes);
  426.         }
  427.         public uint Search_Vector2(uint StartOffset, uint Length, Vector2 Vector2)
  428.         {
  429.             byte[] bytes = new byte[8];
  430.             byte[] x = BitConverter.GetBytes(Vector2.x);
  431.             byte[] y = BitConverter.GetBytes(Vector2.y);
  432.             if (BitConverter.IsLittleEndian)
  433.             {
  434.                 Array.Reverse(x);
  435.                 Array.Reverse(y);
  436.             }
  437.             Array.Copy(x, 0, bytes, 0, 4);
  438.             Array.Copy(y, 0, bytes, 4, 4);
  439.             return Search_Byte(StartOffset, Length, bytes);
  440.         }
  441.         public uint Search_Vector3(uint StartOffset, uint Length, Vector3 Vector3)
  442.         {
  443.             byte[] bytes = new byte[12];
  444.             byte[] x = BitConverter.GetBytes(Vector3.x);
  445.             byte[] y = BitConverter.GetBytes(Vector3.y);
  446.             byte[] z = BitConverter.GetBytes(Vector3.z);
  447.             if (BitConverter.IsLittleEndian)
  448.             {
  449.                 Array.Reverse(x);
  450.                 Array.Reverse(y);
  451.                 Array.Reverse(z);
  452.             }
  453.             Array.Copy(x, 0, bytes, 0, 4);
  454.             Array.Copy(y, 0, bytes, 4, 4);
  455.             Array.Copy(z, 0, bytes, 8, 4);
  456.             return Search_Byte(StartOffset, Length, bytes);
  457.         }
  458.         public void Set_ConsoleColor(ConsoleColor Color)
  459.         {
  460.             Command_SendText("setcolor name=" + System.Enum.GetName(typeof(int), Color).ToLower());
  461.         }
  462.         public void Set_DebugName(string DebugName)
  463.         {
  464.             Command_SendText("dbgname name=" + DebugName);
  465.         }
  466.         public void Write_Bool(uint Offset, bool Bool)
  467.         {
  468.             Write_Byte(Offset, (byte)(Bool ? 0x01 : 0x00));
  469.         }
  470.         public void Write_Byte(uint Offset, byte Byte)
  471.         {
  472.             Write_Byte(Offset, new byte[] { Byte });
  473.         }
  474.         public void Write_Byte(uint Offset, byte[] Bytes)
  475.         {
  476.             if (!Connected)
  477.                 return;
  478.             string str = "setmem addr=0x" + Offset.ToString("X8") + " data=";
  479.             foreach (byte b in Bytes)
  480.                 str += b.ToString("X2");
  481.             str += "\r\n";
  482.             new BinaryWriter(client.GetStream()).Write(Encoding.ASCII.GetBytes(str));
  483.         }
  484.         public void Write_Char(uint Offset, char Char)
  485.         {
  486.             Write_Byte(Offset, (byte)Char);
  487.         }
  488.         public void Write_Double(uint Offset, double Double)
  489.         {
  490.             byte[] bytes = BitConverter.GetBytes(Double);
  491.             if (BitConverter.IsLittleEndian)
  492.                 Array.Reverse(bytes);
  493.             Write_Byte(Offset, bytes);
  494.         }
  495.         public void Write_File(uint Offset, string Path)
  496.         {
  497.             Write_Byte(Offset, File.ReadAllBytes(Path));
  498.         }
  499.         public void Write_Float(uint Offset, float Float)
  500.         {
  501.             byte[] bytes = BitConverter.GetBytes(Float);
  502.             if (BitConverter.IsLittleEndian)
  503.                 Array.Reverse(bytes);
  504.             Write_Byte(Offset, bytes);
  505.         }
  506.         public void Write_Hook(uint Offset, uint Destination, bool Linked)
  507.         {
  508.             uint[] Func = new uint[4];
  509.             if ((Destination & 0x8000) != 0)
  510.                 Func[0] = 0x3D600000 + (((Destination >> 16) & 0xFFFF) + 1);
  511.             else
  512.                 Func[0] = 0x3D600000 + ((Destination >> 16) & 0xFFFF);
  513.             Func[1] = 0x396B0000 + (Destination & 0xFFFF);
  514.             Func[2] = 0x7D6903A6;
  515.             Func[3] = 0x4E800420;
  516.             if (Linked)
  517.                 Func[3]++;
  518.             byte[] buffer = new byte[0x10];
  519.             byte[] f1 = BitConverter.GetBytes(Func[0]);
  520.             byte[] f2 = BitConverter.GetBytes(Func[1]);
  521.             byte[] f3 = BitConverter.GetBytes(Func[2]);
  522.             byte[] f4 = BitConverter.GetBytes(Func[3]);
  523.             if (BitConverter.IsLittleEndian)
  524.             {
  525.                 Array.Reverse(f1);
  526.                 Array.Reverse(f2);
  527.                 Array.Reverse(f3);
  528.                 Array.Reverse(f4);
  529.             }
  530.             for (int i = 0; i < 4; i++)
  531.                 buffer[i] = f1[i];
  532.             for (int i = 4; i < 8; i++)
  533.                 buffer[i] = f2[i - 4];
  534.             for (int i = 8; i < 0xC; i++)
  535.                 buffer[i] = f3[i - 8];
  536.             for (int i = 0xC; i < 0x10; i++)
  537.                 buffer[i] = f4[i - 0xC];
  538.             Write_Byte(Offset, buffer);
  539.         }
  540.         public void Write_Int16(uint Offset, short Int16)
  541.         {
  542.             byte[] bytes = BitConverter.GetBytes(Int16);
  543.             if (BitConverter.IsLittleEndian)
  544.                 Array.Reverse(bytes);
  545.             Write_Byte(Offset, bytes);
  546.         }
  547.         public void Write_Int32(uint Offset, int Int32)
  548.         {
  549.             byte[] bytes = BitConverter.GetBytes(Int32);
  550.             if (BitConverter.IsLittleEndian)
  551.                 Array.Reverse(bytes);
  552.             Write_Byte(Offset, bytes);
  553.         }
  554.         public void Write_Int64(uint Offset, long Int64)
  555.         {
  556.             byte[] bytes = BitConverter.GetBytes(Int64);
  557.             if (BitConverter.IsLittleEndian)
  558.                 Array.Reverse(bytes);
  559.             Write_Byte(Offset, bytes);
  560.         }
  561.         public void Write_NOP(uint Offset)
  562.         {
  563.             Write_Byte(Offset, new byte[] { 0x60, 0x00, 0x00, 0x00 });
  564.         }
  565.         public void Write_String(uint Offset, string String)
  566.         {
  567.             Write_Byte(Offset, Encoding.ASCII.GetBytes(String));
  568.         }
  569.         public void Write_SByte(uint Offset, sbyte SByte)
  570.         {
  571.             Write_Byte(Offset, BitConverter.GetBytes(SByte));
  572.         }
  573.         public void Write_UInt16(uint Offset, ushort UInt16)
  574.         {
  575.             byte[] bytes = BitConverter.GetBytes(UInt16);
  576.             if (BitConverter.IsLittleEndian)
  577.                 Array.Reverse(bytes);
  578.             Write_Byte(Offset, bytes);
  579.         }
  580.         public void Write_UInt32(uint Offset, uint UInt32)
  581.         {
  582.             byte[] bytes = BitConverter.GetBytes(UInt32);
  583.             if (BitConverter.IsLittleEndian)
  584.                 Array.Reverse(bytes);
  585.             Write_Byte(Offset, bytes);
  586.         }
  587.         public void Write_UInt64(uint Offset, ulong UInt64)
  588.         {
  589.             byte[] bytes = BitConverter.GetBytes(UInt64);
  590.             if (BitConverter.IsLittleEndian)
  591.                 Array.Reverse(bytes);
  592.             Write_Byte(Offset, bytes);
  593.         }
  594.         public void Write_Vector2(uint Offset, Vector2 Vector2)
  595.         {
  596.             byte[] bytes = new byte[8];
  597.             byte[] x = BitConverter.GetBytes(Vector2.x);
  598.             byte[] y = BitConverter.GetBytes(Vector2.y);
  599.             if (BitConverter.IsLittleEndian)
  600.             {
  601.                 Array.Reverse(x);
  602.                 Array.Reverse(y);
  603.             }
  604.             Array.Copy(x, 0, bytes, 0, 4);
  605.             Array.Copy(y, 0, bytes, 4, 4);
  606.             Write_Byte(Offset, bytes);
  607.         }
  608.         public void Write_Vector3(uint Offset, Vector3 Vector3)
  609.         {
  610.             byte[] bytes = new byte[12];
  611.             byte[] x = BitConverter.GetBytes(Vector3.x);
  612.             byte[] y = BitConverter.GetBytes(Vector3.y);
  613.             byte[] z = BitConverter.GetBytes(Vector3.z);
  614.             if (BitConverter.IsLittleEndian)
  615.             {
  616.                 Array.Reverse(x);
  617.                 Array.Reverse(y);
  618.                 Array.Reverse(z);
  619.             }
  620.             Array.Copy(x, 0, bytes, 0, 4);
  621.             Array.Copy(y, 0, bytes, 4, 4);
  622.             Array.Copy(z, 0, bytes, 8, 4);
  623.             Write_Byte(Offset, bytes);
  624.         }
  625.     }
  626. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement