public void InPurchaseOk(DataInterceptedEventArgs e) { }
public override void In_RoomUsers(DataInterceptedEventArgs obj) { WriteRegistrationUsers(); }
private object[] CreateValues(DataInterceptedEventArgs args) { ParameterInfo[] parameters = Method.GetParameters(); var values = new object[parameters.Length]; int position = 0; for (int i = 0; i < values.Length; i++) { ParameterInfo parameter = parameters[i]; switch (Type.GetTypeCode(parameter.ParameterType)) { case TypeCode.UInt16: { if (parameter.Name.Equals("id", StringComparison.OrdinalIgnoreCase)) { values[i] = args.Packet.Id; } else { values[i] = args.Packet.ReadUInt16(ref position); } break; } case TypeCode.Int32: values[i] = args.Packet.ReadInt32(ref position); break; case TypeCode.Boolean: values[i] = args.Packet.ReadBoolean(ref position); break; case TypeCode.Byte: values[i] = args.Packet.ReadByte(ref position); break; case TypeCode.String: values[i] = args.Packet.ReadUTF8(ref position); break; case TypeCode.Double: values[i] = args.Packet.ReadDouble(ref position); break; case TypeCode.Object: { if (parameter.ParameterType == typeof(DataInterceptedEventArgs)) { values[i] = args; } else if (parameter.ParameterType == typeof(HPacket)) { values[i] = args.Packet; } else if (parameter.ParameterType == typeof(HPoint)) { values[i] = new HPoint(args.Packet.ReadInt32(ref position), args.Packet.ReadInt32(ref position)); } else if (parameter.ParameterType == typeof(byte[])) { int length = args.Packet.ReadInt32(ref position); values[i] = args.Packet.ReadBytes(length, ref position); } else if (typeof(IList <HEntity>).IsAssignableFrom(parameter.ParameterType)) { args.Packet.Position = 0; values[i] = HEntity.Parse(args.Packet); } else if (typeof(IList <HFloorObject>).IsAssignableFrom(parameter.ParameterType)) { args.Packet.Position = 0; values[i] = HFloorObject.Parse(args.Packet); } else if (typeof(IList <HWallItem>).IsAssignableFrom(parameter.ParameterType)) { args.Packet.Position = 0; values[i] = HWallItem.Parse(args.Packet); } break; } } } return(values); }
public override void HandleIncoming(DataInterceptedEventArgs e) { Connected = true; base.HandleIncoming(e); }
private static void DataIncoming(object sender, DataInterceptedEventArgs e) { //Console.WriteLine("Incoming[{0}]: {1}\r\n----------", e.Packet.Header, e.Packet); }
public void HandleOutgoing(DataInterceptedEventArgs e) { }
private void HandleData(DataInterceptedEventArgs e) { ModuleItem[] moduleItems = Contractor.GetModuleItems(); bool isOutgoing = (e.Packet.Destination == HDestination.Server); if (Contractor.RemoteModule != null) { string stamp = DateTime.Now.Ticks.ToString(); stamp += isOutgoing; stamp += e.Step; Contractor.DataAwaiters[stamp] = new TaskCompletionSource <DataInterceptedEventArgs>(); var interceptedData = new HMessage((ushort)(e.Packet.Destination + 4)); interceptedData.WriteString(stamp); interceptedData.WriteInteger(e.Step); interceptedData.WriteBoolean(e.IsBlocked); interceptedData.WriteInteger(e.Packet.Length + 4); interceptedData.WriteBytes(e.Packet.ToBytes()); Contractor.RemoteModule.SendAsync(interceptedData); DataInterceptedEventArgs args = Contractor .DataAwaiters[stamp].Task.Result; if (args != null) { e.Packet = args.Packet; e.IsBlocked = args.IsBlocked; } Contractor.DataAwaiters.Remove(stamp); } foreach (ModuleItem moduleItem in moduleItems) { if (!moduleItem.IsInitialized) { continue; } ITExtension extension = moduleItem.Extension; if (extension == null) { continue; } try { if (isOutgoing) { extension.HandleOutgoing(e); extension.Triggers?.HandleOutgoing(e); } else { extension.HandleIncoming(e); extension.Triggers?.HandleIncoming(e); } } catch (Exception ex) { if (!e.HasContinued) { e.Continue(); } WriteLog(ex); DisplayModuleException(moduleItem, e, ex); } } }
public override void HandleOutgoing(DataInterceptedEventArgs e) { Window?.HandleOutgoing(e); base.HandleOutgoing(e); }
public void PacketIncoming(object sender, DataInterceptedEventArgs e) { SendMessage("incoming", $"Incoming: [{e.Packet.Header}]: {e.Packet.ToString()}").Wait(); }
/// <summary> /// Will log the packet that sends all the floor item furniture and then finally saves it /// to JSON format using the room data logged in the packet above. /// </summary> /// <param name="obj"></param> private void HandleObjectsMessageEvent(DataInterceptedEventArgs obj) { dynamic itemData = new ExpandoObject(); Log("Got room objects packet"); int owners = obj.Packet.ReadInteger(); Log("Owners: " + owners); itemData.owners = new List <dynamic>(); for (int i = 0; i < owners; i++) //in a group room, group admins count as "room owners" here { dynamic owner = new ExpandoObject(); Log("Owner #" + i); int ownerId = obj.Packet.ReadInteger(); Log("Owner #" + i + ".id=" + ownerId); owner.ownerId = ownerId; string ownerName = obj.Packet.ReadString(); Log("Owner #" + i + ".name=" + ownerName); owner.ownerName = ownerName; itemData.owners.Add(owner); } int items = obj.Packet.ReadInteger(); Log("Items: " + items); itemData.items = new List <dynamic>(); for (int i = 0; i < items; i++) { dynamic item = new ExpandoObject(); item.id = obj.Packet.ReadInteger(); item.spriteId = obj.Packet.ReadInteger(); item.x = obj.Packet.ReadInteger(); item.y = obj.Packet.ReadInteger(); item.dir = obj.Packet.ReadInteger(); item.z = obj.Packet.ReadString(); //z position = furniture placement height item.sizeZ = obj.Packet.ReadString(); //z dimensions = furniture height item.extra = obj.Packet.ReadInteger(); item.data = obj.Packet.ReadInteger(); //4 hex nibbles store 2 values: //hex nibbles 1-2 for item.data //https://github.com/xnumad/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/room/object/data/StuffDataFactory.as#L10 //hex nibbles 3-4 for LTD // //Example: // LTD extraDataType //0x 01 03 bool LTD = false; if (item.data > 0xFF) //LTD indication { LTD = true; item.data &= 0xFF; //trim value for item.data } //https://github.com/JasonWibbo/HabboSwfOpenSource/tree/master/src/com/sulake/habbo/room/object/data //https://github.com/JasonWibbo/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/room/object/data/StuffDataFactory.as //https://github.com/JasonWibbo/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/room/IStuffData.as switch (item.data) { case 0: // String //Legacy //https://github.com/JasonWibbo/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/room/object/data/LegacyStuffData.as#L15 item.state = obj.Packet.ReadString(); break; case 1: // Key value //Map //https://github.com/JasonWibbo/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/room/object/data/MapStuffData.as#L28 int pairs = obj.Packet.ReadInteger(); item.keyValue = new Dictionary <string, string>(); for (int j = 0; j < pairs; j++) { item.keyValue.Add(obj.Packet.ReadString(), obj.Packet.ReadString()); } break; case 2: // String array //https://github.com/JasonWibbo/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/room/object/data/StringArrayStuffData.as int strings = obj.Packet.ReadInteger(); item.strings = new List <String>(); for (int j = 0; j < strings; j++) { item.strings.Add(obj.Packet.ReadString()); } break; case 3: //VoteResult //https://github.com/JasonWibbo/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/room/object/data/VoteResultStuffData.as#L20 item.state = obj.Packet.ReadString(); item.result = obj.Packet.ReadInteger(); break; case 4: //Empty //https://github.com/JasonWibbo/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/room/object/data/EmptyStuffData.as#L10 break; case 5: // Integer array //https://github.com/JasonWibbo/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/room/object/data/IntArrayStuffData.as#L22 int integers = obj.Packet.ReadInteger(); item.ints = new List <int>(); for (int j = 0; j < integers; j++) { item.ints.Add(obj.Packet.ReadInteger()); } break; case 6: //high score //https://github.com/JasonWibbo/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/room/object/data/HighScoreStuffData.as item.state = obj.Packet.ReadString(); item.scoretype = obj.Packet.ReadInteger(); item.clearType = obj.Packet.ReadInteger(); int amountScores = obj.Packet.ReadInteger(); item.scores = new List <dynamic>(); for (int k = 0; k < amountScores; k++) { dynamic scoreData = new ExpandoObject(); scoreData.score = obj.Packet.ReadInteger(); int amountUsers = obj.Packet.ReadInteger(); scoreData.users = new List <String>(); for (int l = 0; l < amountUsers; l++) { scoreData.users.Add(obj.Packet.ReadString()); } itemData.scores.Add(scoreData); } break; case 7: //crackable item.state = obj.Packet.ReadString(); item.hits = obj.Packet.ReadInteger(); item.target = obj.Packet.ReadInteger(); break; default: throw new NotImplementedException("item.data of item " + item.id + " is " + item.data + " and its interpretation is undefined and the packet can't be read any further from here on."); } if (LTD) { item.uniqueSerialNumber = obj.Packet.ReadInteger(); item.uniqueSeriesSize = obj.Packet.ReadInteger(); } item.rentTimeSecondsLeft = obj.Packet.ReadInteger(); //rent time in seconds, or -1 //https://github.com/JasonWibbo/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/ui/widget/infostand/InfoStandFurniView.as#L506 //int infostand text opens on click //<0 infostand.button.buy, catalog page //>=0 infostand.button.buyout buy window directly item.usagePolicy = obj.Packet.ReadInteger(); //https://github.com/JasonWibbo/HabboSwfOpenSource/blob/master/src/com/sulake/habbo/ui/widget/enums/RoomWidgetFurniInfoUsagePolicyEnum.as item.ownerId = obj.Packet.ReadInteger(); //Furniture owner ID itemData.items.Add(item); } Log("Finished with all items"); var json = JsonConvert.SerializeObject(itemData); Log("Finished converting data to JSON"); File.WriteAllText(/*Hotel.ToDomain() + */ this.CurrentRoomId + "-" + this.CurrentRoomName + ".json", json); //fails if Tanji doesn't know the current hotel Log("Finished writing JSON file"); }
private void DataIncoming(object sender, DataInterceptedEventArgs e) => HandleData(e);
public void OnUsername(DataInterceptedEventArgs e) { }
public void OnLatencyTest(DataInterceptedEventArgs e) { }
public void OnOutDiceTrigger(DataInterceptedEventArgs e) { }
private Task <int> ServerRelayer(DataInterceptedEventArgs relayedFrom) { return(SendToServerAsync(relayedFrom.Packet)); }
private void AddEntry(List <Tuple <string, Color> > entries) { DataInterceptedEventArgs args = _intercepted.Dequeue(); if (!IsLoggingAuthorized(args)) { return; } if (args.IsBlocked) { entries.Add(Tuple.Create("[Blocked]\r\n", FilterHighlight)); } if (!args.IsOriginal) { entries.Add(Tuple.Create("[Replaced]\r\n", FilterHighlight)); } if (IsDisplayingTimestamp) { entries.Add(Tuple.Create($"[{args.Timestamp:M/d H:mm:ss}]\r\n", DetailHighlight)); } MessageItem message = GetMessage(args); if (IsDisplayingHash && message != null && !string.IsNullOrWhiteSpace(message.Hash)) { entries.Add(Tuple.Create($"[{message.Hash}]\r\n", DetailHighlight)); } if (IsDisplayingHexadecimal) { string hex = BitConverter.ToString(args.Packet.ToBytes()); entries.Add(Tuple.Create($"[{hex.Replace("-", string.Empty)}]\r\n", DetailHighlight)); } string arrow = "->"; string title = "Outgoing"; Color entryHighlight = OutgoingHighlight; if (!args.IsOutgoing) { arrow = "<-"; title = "Incoming"; entryHighlight = IncomingHighlight; } entries.Add(Tuple.Create(title + "[", entryHighlight)); entries.Add(Tuple.Create(args.Packet.Id.ToString(), DetailHighlight)); if (message != null) { if (IsDisplayingMessageName) { entries.Add(Tuple.Create(", ", entryHighlight)); entries.Add(Tuple.Create(message.Class.QName.Name, DetailHighlight)); } if (IsDisplayingParserName && message.Parser != null) { entries.Add(Tuple.Create(", ", entryHighlight)); entries.Add(Tuple.Create(message.Parser.QName.Name, DetailHighlight)); } } entries.Add(Tuple.Create("]", entryHighlight)); entries.Add(Tuple.Create($" {arrow} ", DetailHighlight)); entries.Add(Tuple.Create($"{args.Packet}\r\n", entryHighlight)); if (IsDisplayingStructure && message?.Structure?.Length >= 0) { int position = 0; HPacket packet = args.Packet; string structure = ("{id:" + packet.Id + "}"); foreach (string valueType in message.Structure) { switch (valueType.ToLower()) { case "int": structure += ("{i:" + packet.ReadInt32(ref position) + "}"); break; case "string": structure += ("{s:" + packet.ReadUTF8(ref position) + "}"); break; case "double": structure += ("{d:" + packet.ReadDouble(ref position) + "}"); break; case "byte": structure += ("{b:" + packet.ReadByte(ref position) + "}"); break; case "boolean": structure += ("{b:" + packet.ReadBoolean(ref position) + "}"); break; } } if (packet.GetReadableBytes(position) == 0) { entries.Add(Tuple.Create(structure + "\r\n", StructureHighlight)); } } entries.Add(Tuple.Create("--------------------\r\n", DetailHighlight)); }
protected virtual void OnDataIncoming(DataInterceptedEventArgs e) { DataIncoming?.Invoke(this, e); }
protected internal virtual void HandleOutgoing(DataInterceptedEventArgs e) { }
public void HandleIncoming(DataInterceptedEventArgs e) => HandleData(e);
internal dynamic ReadEventArgs(DataInterceptedEventArgs obj) { var packet = obj.Packet; dynamic itemData = new ExpandoObject(); int itemId = packet.ReadInteger(); itemData.itemId = itemId; string displayName = packet.ReadString(); itemData.displayName = displayName; packet.ReadBoolean(); // ?? int costCredits = packet.ReadInteger(); itemData.costCredits = costCredits; int otherCurrencyCost = packet.ReadInteger(); int otherCurrencyType = packet.ReadInteger(); if (otherCurrencyCost > 0) { itemData.otherCurrencyType = otherCurrencyType; itemData.otherCurrencyCost = otherCurrencyCost; } bool allowGift = packet.ReadBoolean(); itemData.allowGift = allowGift; bool hasBadge = (packet.ReadInteger() == 2); if (hasBadge) { string badgeType = packet.ReadString(); itemData.badgeType = badgeType; string badgeCode = packet.ReadString(); itemData.badgeCode = badgeCode; } string itemType = packet.ReadString(); itemData.itemType = itemType; if (hasBadge) { string itemName = packet.ReadString(); itemData.itemName = itemName; } else { int spriteId = packet.ReadInteger(); itemData.spriteId = spriteId; string extraData = packet.ReadString(); itemData.extraData = extraData; int amount = packet.ReadInteger(); itemData.amount = amount; bool isLimited = packet.ReadBoolean(); if (isLimited) { int limitedTotal = packet.ReadInteger(); itemData.limitedTotal = limitedTotal; int limitedRemaining = packet.ReadInteger(); itemData.limitedRemaining = limitedRemaining; } } int subscriptionStatus = packet.ReadInteger(); itemData.subscriptionStatus = subscriptionStatus; bool purchaseMulitiple = packet.ReadBoolean(); itemData.purchaseMultiple = purchaseMulitiple; packet.ReadBoolean(); // dunno m8 packet.ReadString(); // this is important but forgot return(itemData); }
public void Invoke(DataInterceptedEventArgs e) => Attribute.Invoke(e);
public void HandleIncoming(DataInterceptedEventArgs e) => PushToQueue(e);
private async Task ReceiveRemoteModuleDataAsync() { try { HMessage packet = await RemoteModule.ReceivePacketAsync().ConfigureAwait(false); if (packet == null) { DataAwaiters.Values.ToList().ForEach(awaiter => { if (awaiter != null) { awaiter.SetResult(null); } }); RemoteModule = null; Task grabRemoteModuleTask = GrabRemoteModuleAsync(); return; } var response = new HMessage(packet.Header); #region Switch: packet.Header switch (packet.Header) { default: response = null; break; case 0: { response.WriteShort((ushort)Hotel); break; } case 1: { response.WriteString(Game?.Location); if (!string.IsNullOrWhiteSpace(Game?.Location)) { response.WriteString(Path.GetFullPath("Hashes.ini")); } break; } case 2: { response.WriteString(GameData.Source); break; } case 3: { response.WriteShort(Connection.Port); response.WriteString(Connection.Host); response.WriteString(Connection.Address); break; } case 4: { if (Connection != null) { int dataLength = packet.ReadInteger(); byte[] data = packet.ReadBytes(dataLength); await Connection.SendToClientAsync( data).ConfigureAwait(false); response = null; } break; } case 5: { if (Connection != null) { int dataLength = packet.ReadInteger(); byte[] data = packet.ReadBytes(dataLength); await Connection.SendToServerAsync( data).ConfigureAwait(false); response = null; } break; } case 6: case 7: { string stamp = packet.ReadString(); if (DataAwaiters.ContainsKey(stamp)) { var destination = (HDestination)(packet.Header - 6); int step = packet.ReadInteger(); bool isBlocked = packet.ReadBoolean(); int dataLength = packet.ReadInteger(); byte[] data = packet.ReadBytes(dataLength); var interPacket = new HMessage(data, destination); var args = new DataInterceptedEventArgs(interPacket, step, (destination == HDestination.Server)); args.IsBlocked = isBlocked; DataAwaiters[stamp].SetResult(args); response = null; } break; } } #endregion if (response != null) { await RemoteModule.SendPacketAsync(response).ConfigureAwait(false); } } finally { if (RemoteModule != null) { Task receiveRemModuDataTask = ReceiveRemoteModuleDataAsync(); } } }
public void WritePacketLog(DataInterceptedEventArgs args) { HMessage packet = args.Packet; bool isOutgoing = (args.Packet.Destination == HDestination.Server); ReadOnlyDictionary <ushort, ASClass> msgClasses = (isOutgoing ? MainUI.Game.OutgoingMessages : MainUI.Game.IncomingMessages); ASClass msgClass = null; msgClasses.TryGetValue(packet.Header, out msgClass); Color highlight = (isOutgoing ? OutgoingHighlight : IncomingHighlight); if (IsDisplayingTimestamp) { WriteHighlight($"[{DateTime.Now.ToLongTimeString()}]\r\n", SpecialHighlight); } if (IsDisplayingHash) { string hash = MainUI.Game.GetMessageHash(msgClass); WriteHighlight($"[{hash}]\r\n", SpecialHighlight); } WriteHighlight((isOutgoing ? "Outgoing" : "Incoming"), highlight); if (args.IsBlocked && IsDisplayingBlocked) { WriteHighlight("[Blocked]", SpecialHighlight); } else if (!args.IsOriginal) { WriteHighlight("[Replaced]", SpecialHighlight); } string arrow = (isOutgoing ? "->" : "<-"); WriteHighlight($"({packet.Header}, {packet.Length}", highlight); if (IsDisplayingMessageName && msgClass != null) { WriteHighlight(", ", highlight); WriteHighlight((msgClass?.Instance.Name.Name) ?? "???", SpecialHighlight); } if (!isOutgoing && IsDisplayingParserName && msgClass != null && !_invalidParsers.Contains(packet.Header)) { ASClass parserClass = MainUI.Game .GetIncomingMessageParser(msgClass); if (parserClass != null) { WriteHighlight($", ", highlight); WriteHighlight(parserClass.Instance.Name.Name, SpecialHighlight); } else { _invalidParsers.Add(packet.Header); } } WriteHighlight($") {arrow} {packet}\r\n", highlight); if (IsDisplayingStructure && isOutgoing) { WriteStructureLog(packet, msgClass); } }
public override void HandleOutgoing(DataInterceptedEventArgs e) => HandleData(e);
public override void HandleIncoming(DataInterceptedEventArgs e) { base.HandleIncoming(e); }
internal dynamic ReadEventArgs(DataInterceptedEventArgs obj) { dynamic tab = this.ReadTabData(obj); return(tab); }
private Task <int> ClientRelayer(DataInterceptedEventArgs relayedFrom) { return(SendToClientAsync(relayedFrom.Packet)); }
private void ParseRoomModel(DataInterceptedEventArgs e) { room.Heightmap.Model = e.Packet.ReadString(); }
public void OnRequestRoomLoad(DataInterceptedEventArgs obj) { users.Clear(); WriteRegistrationUsers(users.Count); }