public HMessage(byte[] data, HDestination destination) : this() { if (data == null) { throw new NullReferenceException(); } if (data.Length < 6) { throw new Exception("Insufficient data, minimum length is '6'(Six). [Length{4}][Header{2}]"); } Destination = destination; IsCorrupted = (BigEndian.DecypherInt(data) != data.Length - 4); if (!IsCorrupted) { Header = BigEndian.DecypherShort(data, 4); _body.AddRange(data); _body.RemoveRange(0, 6); Reconstruct(); } else { Length = data.Length; _toBytesCache = data; } }
private void FTRemoveBtn_Click(object sender, EventArgs e) { ListViewItem item = UI.FTFiltersVw.SelectedItem; var filter = (item.Tag as Tuple <HDestination, ushort>); if (filter == null) { return; } ushort header = filter.Item2; HDestination destination = filter.Item1; if (_blocked[destination].Contains(header)) { _blocked[destination].Remove(header); } if (_replacements[destination].ContainsKey(header)) { _replacements[destination].Remove(header); } if (_disabled[destination].Contains(header)) { _disabled[destination].Remove(header); } UI.FTFiltersVw.RemoveSelectedItem(); UpdateUI(); }
public Constructer() { _chunks = new List <object>(); SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.EnableNotifyMessage, true); var typeCol = new ColumnHeader { Name = "TypeCol", Text = "Type", Width = 60 }; var valueCol = new ColumnHeader { Name = "ValueCol", Text = "Value", Width = 194 }; var encodedCol = new ColumnHeader { Name = "EncodedCol", Text = "Encoded", Width = 104 }; Columns.AddRange(new[] { typeCol, valueCol, encodedCol }); FullRowSelect = true; GridLines = true; HeaderStyle = ColumnHeaderStyle.Nonclickable; MultiSelect = false; ShowItemToolTips = true; Size = new Size(386, 166); UseCompatibleStateImageBehavior = false; View = View.Details; LockColumns = true; _destination = HDestination.Server; _protocol = HProtocol.Modern; }
public DataToEventArgs(byte[] data, HDestination destination, int step, HFilters filters) : this(data, destination, step) { IsBlocked = (destination == HDestination.Client) ? filters.InProcessFilters(ref _replacement) : filters.OutProcessFilters(ref _replacement); }
public void Invoke(DataInterceptedEventArgs args) { object[] parameters = CreateValues(args); object result = Method?.Invoke(Target, parameters); switch (result) { case bool isBlocked: { args.IsBlocked = isBlocked; break; } case HMessage packet: { args.Packet = packet; break; } case object[] chunks: { HDestination destination = args.Packet.Destination; args.Packet = new HMessage(args.Packet.Header, chunks); args.Packet.Destination = destination; break; } } }
/// <summary> /// Initializes a new instance of the <see cref="DataInterceptedEventArgs"/> class. /// </summary> /// <param name="continuation">The <see cref="Func{TResult}"/> of type <see cref="Task"/> that will be invoked when <see cref="ContinueRead"/> is called.</param> /// <param name="step">The current count/step/order from which this data was intercepted.</param> /// <param name="packet">The intercepted data to read/write from.</param> public DataInterceptedEventArgs(HMessage packet, int step, Func <Task> continuation) : base(continuation) { _ogData = packet.ToBytes(); _ogString = packet.ToString(); _ogDestination = packet.Destination; Step = step; Packet = packet; Executions = new List <HMessage>(); }
public void SetItemDestination(HDestination destination) { if (SelectedItems.Count < 1) { return; } ListViewItem item = SelectedItems[0]; _schedules[item].Packet.Destination = destination; item.SubItems[1].Text = destination.ToString(); }
private void HandleMessage(byte[] data, HDestination destination) { var args = new InterceptedEventArgs(ReadMessageAsync, 0, new HMessage(data, destination)); Task readTask = ReadMessageAsync(); // Keep reading. if (destination == HDestination.Server) { _extension.Triggers.HandleOutgoing(args); OnDataOutgoing(args); } else { _extension.Triggers.HandleIncoming(args); OnDataIncoming(args); } }
public HMessage(byte[] data, HDestination destination) : this() { Destination = destination; IsCorrupted = (data.Length < 6 || (BigEndian.ToInt32(data, 0) != data.Length - 4)); if (!IsCorrupted) { Header = BigEndian.ToUInt16(data, 4); _bodyBuffer = new byte[data.Length - 6]; Buffer.BlockCopy(data, 6, _bodyBuffer, 0, data.Length - 6); } else _bodyBuffer = data; _body.AddRange(_bodyBuffer); }
public async Task <int> InjectInputAsync(HDestination destination) { HMessage packet = GetPacket(); if (!AuthorizeInjection(packet)) { return(0); } packet.Destination = destination; int length = await SendAsync(packet); if (length == (packet.Length + 4)) { AddAutocomplete(packet.ToString()); } return(length); }
private void HandleMessage(byte[] data, HDestination destination) { var args = new InterceptedEventArgs(ReadMessageAsync, 0, new HMessage(data, destination)); Task readTask = ReadMessageAsync(); // Keep reading. if (destination == HDestination.Server) { _extension.Triggers.HandleOutgoing(args); OnDataOutgoing(args); } else { _extension.Triggers.HandleIncoming(args); OnDataIncoming(args); } }
public HMessage(byte[] data, HDestination destination) : this() { Destination = destination; IsCorrupted = (data.Length < 6 || (BigEndian.ToInt32(data, 0) != data.Length - 4)); if (!IsCorrupted) { Header = BigEndian.ToUInt16(data, 4); _bodyBuffer = new byte[data.Length - 6]; Buffer.BlockCopy(data, 6, _bodyBuffer, 0, data.Length - 6); } else { _bodyBuffer = data; } _body.AddRange(_bodyBuffer); }
protected string ReadString(ref int index, HProtocol protocol, HDestination destination) { if (index >= Body.Length) { return(string.Empty); } if (destination == HDestination.Server || protocol == HProtocol.Modern) { ushort length = ReadShort(ref index, protocol); byte[] data = ByteUtils.CopyBlock(Body, (index += length) - length, length); return(Encoding.Default.GetString(data)); } else { string chunk = _rawBody.Substring(index).Split((char)2)[0]; index += chunk.Length + 1; return(chunk); } }
public static byte[] Construct(ushort header, HDestination destination, HProtocol protocol, params object[] chunks) { var buffer = new List <byte>(); bool isAncient = (protocol == HProtocol.Ancient); if (isAncient && destination == HDestination.Server) { buffer.Add(64); } buffer.AddRange(protocol == HProtocol.Ancient ? Ancient.CypherShort(header) : Modern.CypherShort(header)); buffer.AddRange(ConstructBody(destination, protocol, chunks)); if (!isAncient || destination == HDestination.Server) { buffer.InsertRange(isAncient ? 1 : 0, isAncient ? Ancient.CypherShort((ushort)(buffer.Count - 1)) : Modern.CypherInt(buffer.Count)); } else if (buffer[buffer.Count - 1] != 1) { buffer.Add(1); } return(buffer.ToArray()); }
public HMessage(byte[] data, HDestination destination) : this() { if (data == null) { throw new NullReferenceException(); } if (data.Length < 1) { throw new Exception("The minimum amount of bytes required to initialize an HMessage instance is 1(One). If the amount of bytes passed is < 3(Three), and >= 1(One), it will be immediately be identified as a corrupted packet. { IsCorrupted = true }"); } Destination = destination; bool hasByteZero = data.Contains(byte.MinValue); bool isAncientHeader = !hasByteZero && data.Length == 2 && data[1] != 1; if (!isAncientHeader && data.Length >= 6 && Modern.DecypherInt(data) == data.Length - 4) { Protocol = HProtocol.Modern; _header = Modern.DecypherShort(data, 4); Append(ByteUtils.CopyBlock(data, 4, data.Length - 4)); if (data.Length == 6) { _logWriting = true; } } else if ((destination == HDestination.Server && isAncientHeader) || (!hasByteZero && data.Length >= 5 && Ancient.DecypherShort(data, 1) == data.Length - 3)) { Destination = HDestination.Server; Protocol = HProtocol.Ancient; _header = Ancient.DecypherShort(data, isAncientHeader ? 0 : 3); Append(isAncientHeader ? data : ByteUtils.CopyBlock(data, 3, data.Length - 3)); if (data.Length == 5 || isAncientHeader) { _logWriting = true; } } else if (isAncientHeader || (!hasByteZero && data.Length >= 3 && data[data.Length - 1] == 1 && Destination != HDestination.Server)) { Destination = HDestination.Client; Protocol = HProtocol.Ancient; if (isAncientHeader) { data = new byte[] { data[0], data[1], 1 } } ; _header = Ancient.DecypherShort(data); Append(data); if (data.Length == 3 || isAncientHeader) { _logWriting = true; } } else { Body = data; _bufferCache = data; IsCorrupted = true; Length = data.Length; _buffer.AddRange(data); _stringCache = ToString(data); } }
public HMessage(string packet, HDestination destination) : this(ToBytes(packet), destination) { }
public static byte[] ConstructBody(HDestination destination, HProtocol protocol, params object[] chunks) { var buffer = new List <byte>(); bool isAncient = (protocol == HProtocol.Ancient); for (int i = 0; i < chunks.Length; i++) { object chunk = chunks[i]; if (chunk == null) { throw new NullReferenceException(string.Format("Unable to encode a null object. {{ Index = {0} }}", i)); } var data = chunk as byte[]; if (data != null) { buffer.AddRange(data); } else { switch (Type.GetTypeCode(chunk.GetType())) { case TypeCode.Int32: { var value = (int)chunk; buffer.AddRange(protocol == HProtocol.Ancient ? Ancient.CypherInt(value) : Modern.CypherInt(value)); break; } case TypeCode.Boolean: { var value = (bool)chunk; buffer.Add(isAncient ? (byte)(value ? 73 : 72) : Convert.ToByte(value)); break; } case TypeCode.Byte: { var value = (byte)chunk; buffer.Add(value); break; } default: { string value = chunk.ToString(); if (!isAncient || destination == HDestination.Server) { ushort valueLength = (ushort)value.Length; buffer.AddRange(protocol == HProtocol.Ancient ? Ancient.CypherShort(valueLength) : Modern.CypherShort(valueLength)); buffer.AddRange(Encoding.Default.GetBytes(value)); } else { buffer.AddRange(Encoding.Default.GetBytes(value)); buffer.Add(2); } break; } } } } return(buffer.ToArray()); }
/// <summary> /// Initializes a new instance of the <see cref="InterceptedEventArgs"/> class. /// </summary> /// <param name="continuation">The <see cref="Func{TResult}"/> of type <see cref="Task"/> that will be invoked when <see cref="ContinueRead"/> is called.</param> /// <param name="step">The current count/step/order from which this data was intercepted.</param> /// <param name="data">An array of type <see cref="byte"/> that contains the data to convert to an <see cref="HMessage"/>.</param> /// <param name="destination">The destination type that will help initialize the <see cref="HMessage"/>.</param> public InterceptedEventArgs(Func<Task> continuation, int step, byte[] data, HDestination destination) : this(continuation, step, new HMessage(data, destination)) { }
public void SetItemDestination(HDestination destination) { if (SelectedItems.Count < 1) return; ListViewItem item = SelectedItems[0]; _schedules[item].Packet.Destination = destination; item.SubItems[1].Text = destination.ToString(); }
public HostTradeEventArgs(int step, byte[] data, HDestination destination) : this(null, step, new HMessage(data, destination)) { }
public HostExitRoomEventArgs(int step, byte[] data, HDestination destination) : this(null, step, new HMessage(data, destination)) { }
/// <summary> /// Initializes a new instance of the <see cref="InterceptedEventArgs"/> class. /// </summary> /// <param name="continuation">The <see cref="Func{TResult}"/> of type <see cref="Task"/> that will be invoked when <see cref="ContinueRead"/> is called.</param> /// <param name="step">The current count/step/order from which this data was intercepted.</param> /// <param name="data">An array of type <see cref="byte"/> that contains the data to convert to an <see cref="HMessage"/>.</param> /// <param name="destination">The destination type that will help initialize the <see cref="HMessage"/>.</param> public InterceptedEventArgs(Func <Task> continuation, int step, byte[] data, HDestination destination) : this(continuation, step, new HMessage(data, destination)) { }
public HMessage(string data, HDestination destination) : this(ToBytes(data), destination) { }
public FurnitureLoadEventArgs(Func <Task> continuation, int step, byte[] data, HDestination destination) : this(continuation, step, new HMessage(data, destination)) { }
public FurnitureLoadEventArgs(int step, byte[] data, HDestination destination) : this(null, step, new HMessage(data, destination)) { }
/// <summary> /// Initializes a new instance of the <see cref="InterceptedEventArgs"/> class. /// </summary> /// <param name="step">The current count/step/order from which this data was intercepted.</param> /// <param name="data">An array of type <see cref="byte"/> that contains the data to convert to an <see cref="HMessage"/>.</param> /// <param name="destination">The destination type that will help initialize the <see cref="HMessage"/>.</param> public InterceptedEventArgs(int step, byte[] data, HDestination destination) : this(null, step, new HMessage(data, destination)) { }
public FurnitureDropEventArgs(int step, byte[] data, HDestination destination) : this(null, step, new HMessage(data, destination)) { }
public HostKickPlayerEventArgs(int step, byte[] data, HDestination destination) : this(null, step, new HMessage(data, destination)) { }
public FurnitureDropEventArgs(Func<Task> continuation, int step, byte[] data, HDestination destination) : this(continuation, step, new HMessage(data, destination)) { }
public PlayerDanceEventArgs(Func <Task> continuation, int step, byte[] data, HDestination destination) : this(continuation, step, new HMessage(data, destination)) { }
public HostExitRoomEventArgs(Func <Task> continuation, int step, byte[] data, HDestination destination) : this(continuation, step, new HMessage(data, destination)) { }
public HMessage(ushort header, HDestination destination, params object[] chunks) : this(Construct(header, chunks), destination) { _beganConstructing = true; AddToWritten(chunks); }
public PlayerDanceEventArgs(int step, byte[] data, HDestination destination) : this(null, step, new HMessage(data, destination)) { }
public HMessage(ushort header, HDestination destination, HProtocol protocol, params object[] chunks) : this(Construct(header, destination, protocol, chunks), destination) { _logWriting = true; _appended.AddRange(chunks); }
public PlayerGestureEventArgs(int step, byte[] data, HDestination destination) : this(null, step, new HMessage(data, destination)) { }
public HMessage(string data, HDestination destination) : this(ToBytes(data), destination) { }
/// <summary> /// Initializes a new instance of the <see cref="InterceptedEventArgs"/> class. /// </summary> /// <param name="step">The current count/step/order from which this data was intercepted.</param> /// <param name="data">An array of type <see cref="byte"/> that contains the data to convert to an <see cref="HMessage"/>.</param> /// <param name="destination">The destination type that will help initialize the <see cref="HMessage"/>.</param> public InterceptedEventArgs(int step, byte[] data, HDestination destination) : this(null, step, new HMessage(data, destination)) { }
public HostUpdateClothesEventArgs(int step, byte[] data, HDestination destination) : this(null, step, new HMessage(data, destination)) { }
public bool IsFilterAuthorized(ushort key, HDestination destination, FilterAction action) { return(!_blocked[destination].Contains(key) && !_replacements[destination].ContainsKey(key)); }
public HMessage(ushort header, HDestination destination) : this(header, destination, HProtocol.Modern) { }
public HostTradeEventArgs(Func<Task> continuation, int step, byte[] data, HDestination destination) : this(continuation, step, new HMessage(data, destination)) { }
public HostUpdateClothesEventArgs(int step, byte[] data, HDestination destination) : this(null, step, new HMessage(data, destination)) { }