/// <summary> /// Deserialize controller inputs from a simple byte[] array which was transmitted by another client. /// </summary> /// <param name="Controller_Inputs"></param> /// <returns></returns> public static SonicHeroes.Controller.Sonic_Heroes_Joystick.Controller_Inputs_Generic Deserialize_Controller_Inputs_Manual(byte[] Controller_Inputs_Serialized) { SonicHeroes.Controller.Sonic_Heroes_Joystick.Controller_Inputs_Generic Controller_Inputs = new SonicHeroes.Controller.Sonic_Heroes_Joystick.Controller_Inputs_Generic(); Controller_Inputs.LeftStick.X = BitConverter.ToInt16(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 2, 0), 0); Controller_Inputs.LeftStick.Y = BitConverter.ToInt16(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 2, 2), 0); Controller_Inputs.RightStick.X = BitConverter.ToInt16(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 2, 4), 0); Controller_Inputs.RightStick.Y = BitConverter.ToInt16(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 2, 6), 0); Controller_Inputs.LeftTriggerPressure = BitConverter.ToInt16(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 2, 8), 0); Controller_Inputs.RightTriggerPressure = BitConverter.ToInt16(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 2, 10), 0); // Buttons | Start Offset = 0x12 Controller_Inputs.ControllerButtons.Button_A = BitConverter.ToBoolean(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 1, 12), 0); Controller_Inputs.ControllerButtons.Button_B = BitConverter.ToBoolean(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 1, 13), 0); Controller_Inputs.ControllerButtons.Button_Back = BitConverter.ToBoolean(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 1, 14), 0); Controller_Inputs.ControllerButtons.Button_L1 = BitConverter.ToBoolean(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 1, 15), 0); Controller_Inputs.ControllerButtons.Button_L3 = BitConverter.ToBoolean(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 1, 16), 0); Controller_Inputs.ControllerButtons.Button_R1 = BitConverter.ToBoolean(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 1, 17), 0); Controller_Inputs.ControllerButtons.Button_R3 = BitConverter.ToBoolean(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 1, 18), 0); Controller_Inputs.ControllerButtons.Button_Start = BitConverter.ToBoolean(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 1, 19), 0); Controller_Inputs.ControllerButtons.Button_X = BitConverter.ToBoolean(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 1, 20), 0); Controller_Inputs.ControllerButtons.Button_Y = BitConverter.ToBoolean(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 1, 21), 0); Controller_Inputs.ControllerButtons.Optional_Button_Guide = BitConverter.ToBoolean(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 1, 22), 0); // DPAD Controller_Inputs.ControllerDPad = BitConverter.ToUInt16(SonicHeroes.Misc.SonicHeroes_Miscallenous.Get_Byte_Range_From_Array(Controller_Inputs_Serialized, 2, 23), 0); return(Controller_Inputs); }
/// <summary> /// Serialize controller inputs into a simple byte[] array such that they can be sent from client to server and vice versa. /// </summary> /// <param name="Controller_Inputs"></param> /// <returns></returns> public static byte[] Serialize_Controller_Inputs_Manual(SonicHeroes.Controller.Sonic_Heroes_Joystick.Controller_Inputs_Generic Controller_Inputs) { byte[] Controller_Inputs_New = new byte[25]; // Sticks Array.Copy(BitConverter.GetBytes(Controller_Inputs.LeftStick.X), 0, Controller_Inputs_New, 0, sizeof(short)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.LeftStick.Y), 0, Controller_Inputs_New, 2, sizeof(short)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.RightStick.X), 0, Controller_Inputs_New, 4, sizeof(short)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.RightStick.Y), 0, Controller_Inputs_New, 6, sizeof(short)); // Triggers Array.Copy(BitConverter.GetBytes(Controller_Inputs.LeftTriggerPressure), 0, Controller_Inputs_New, 8, sizeof(short)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.RightTriggerPressure), 0, Controller_Inputs_New, 10, sizeof(short)); // Axis Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerButtons.Button_A), 0, Controller_Inputs_New, 12, sizeof(bool)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerButtons.Button_B), 0, Controller_Inputs_New, 13, sizeof(bool)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerButtons.Button_Back), 0, Controller_Inputs_New, 14, sizeof(bool)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerButtons.Button_L1), 0, Controller_Inputs_New, 15, sizeof(bool)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerButtons.Button_L3), 0, Controller_Inputs_New, 16, sizeof(bool)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerButtons.Button_R1), 0, Controller_Inputs_New, 17, sizeof(bool)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerButtons.Button_R3), 0, Controller_Inputs_New, 18, sizeof(bool)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerButtons.Button_Start), 0, Controller_Inputs_New, 19, sizeof(bool)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerButtons.Button_X), 0, Controller_Inputs_New, 20, sizeof(bool)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerButtons.Button_Y), 0, Controller_Inputs_New, 21, sizeof(bool)); Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerButtons.Optional_Button_Guide), 0, Controller_Inputs_New, 22, sizeof(bool)); // DPAD Array.Copy(BitConverter.GetBytes(Controller_Inputs.ControllerDPad), 0, Controller_Inputs_New, 23, sizeof(short)); return(Controller_Inputs_New); }