-
Notifications
You must be signed in to change notification settings - Fork 379
Expand file tree
/
Copy pathNpcHandler.cs
More file actions
342 lines (272 loc) · 12.7 KB
/
NpcHandler.cs
File metadata and controls
342 lines (272 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
using System;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System.Globalization;
using WowPacketParser.Enums;
using WowPacketParser.Misc;
using WowPacketParser.Parsing;
using WowPacketParser.Store;
using WowPacketParser.Store.Objects;
using CoreParsers = WowPacketParser.Parsing.Parsers;
namespace WowPacketParserModule.V5_4_1_17538.Parsers
{
[SuppressMessage("ReSharper", "UseObjectOrCollectionInitializer")]
public static class NpcHandler
{
[HasSniffData]
[Parser(Opcode.SMSG_GOSSIP_MESSAGE)]
public static void HandleNpcGossip(Packet packet)
{
var guidBytes = new byte[8];
uint amountOfOptions = packet.ReadBits(20);
packet.StartBitStream(guidBytes, 5, 1, 7, 2);
uint questgossips = packet.ReadBits(19);
packet.StartBitStream(guidBytes, 6, 4, 0);
var titleLen = new uint[questgossips];
for (int i = 0; i < questgossips; ++i)
{
packet.ReadBit("Change Icon", i);
titleLen[i] = packet.ReadBits(9);
}
var optionTextLen = new uint[amountOfOptions];
var boxTextLen = new uint[amountOfOptions];
for (int i = 0; i < amountOfOptions; ++i)
{
boxTextLen[i] = packet.ReadBits(12);
optionTextLen[i] = packet.ReadBits(12);
}
guidBytes[3] = packet.ReadBit();
for (int i = 0; i < questgossips; i++)
{
packet.ReadUInt32E<QuestFlags>("Flags", i);
packet.ReadUInt32("Icon", i);
packet.ReadInt32("Level", i);
packet.ReadWoWString("Title", titleLen[i], i);
packet.ReadUInt32<QuestId>("Quest ID", i);
packet.ReadUInt32E<QuestFlags2>("Flags 2", i);
}
packet.ReadXORByte(guidBytes, 2);
packet.ReadXORByte(guidBytes, 1);
uint menuId = packet.ReadUInt32("Menu Id");
for (int i = 0; i < amountOfOptions; ++i)
{
GossipMenuOption gossipOption = new GossipMenuOption
{
MenuId = menuId
};
GossipMenuOptionBox gossipMenuOptionBox = new GossipMenuOptionBox
{
MenuId = menuId
};
gossipOption.OptionText = packet.ReadWoWString("Text", optionTextLen[i], i);
gossipMenuOptionBox.BoxCoded = packet.ReadBool("Box", i);
gossipOption.OptionIcon = packet.ReadByteE<GossipOptionIcon>("Icon", i);
gossipMenuOptionBox.BoxMoney = packet.ReadUInt32("Required money", i);
gossipMenuOptionBox.BoxText = packet.ReadWoWString("Box Text", boxTextLen[i], i);
gossipOption.OptionIndex = gossipMenuOptionBox.OptionIndex = packet.ReadUInt32("Index", i);
Storage.GossipMenuOptions.Add(gossipOption, packet.TimeSpan);
if (!gossipMenuOptionBox.IsEmpty)
Storage.GossipMenuOptionBoxes.Add(gossipMenuOptionBox, packet.TimeSpan);
}
packet.ReadXORByte(guidBytes, 7);
packet.ReadXORByte(guidBytes, 4);
packet.ReadXORByte(guidBytes, 6);
packet.ReadUInt32("Friendship Faction");
packet.ReadXORByte(guidBytes, 0);
packet.ReadXORByte(guidBytes, 5);
uint textId = packet.ReadUInt32("Text Id");
packet.ReadXORByte(guidBytes, 3);
GossipMenu gossip = new GossipMenu
{
Entry = menuId,
TextID = textId
};
WowGuid guid = packet.WriteGuid("Guid", guidBytes);
gossip.ObjectType = guid.GetObjectType();
gossip.ObjectEntry = guid.GetEntry();
if (guid.GetObjectType() == ObjectType.Unit)
if (Storage.Objects.ContainsKey(guid))
((Unit)Storage.Objects[guid].Item1).GossipId = menuId;
Storage.Gossips.Add(gossip, packet.TimeSpan);
var lastGossipOption = CoreParsers.NpcHandler.LastGossipOption;
if (lastGossipOption.HasSelection)
Storage.GossipMenuOptionActions.Add(new GossipMenuOptionAction { MenuId = lastGossipOption.MenuId, OptionIndex = lastGossipOption.OptionIndex, ActionMenuId = gossip.Entry }, packet.TimeSpan);
packet.AddSniffData(StoreNameType.Gossip, (int)menuId, guid.GetEntry().ToString(CultureInfo.InvariantCulture));
}
[HasSniffData]
[Parser(Opcode.SMSG_QUERY_NPC_TEXT_RESPONSE)]
public static void HandleNpcTextUpdate(Packet packet)
{
var entry = packet.ReadEntry("Entry");
if (entry.Value) // Can be masked
return;
int size = packet.ReadInt32("Size");
var data = packet.ReadBytes(size);
Bit hasData = packet.ReadBit();
if (!hasData)
return; // nothing to do
NpcTextMop npcText = new NpcTextMop
{
ID = (uint)entry.Key
};
Packet pkt = new Packet(data, packet.Opcode, packet.Time, packet.Direction, packet.Number, packet.Writer, packet.FileName);
npcText.Probabilities = new float[8];
npcText.BroadcastTextId = new uint[8];
for (int i = 0; i < 8; ++i)
npcText.Probabilities[i] = pkt.ReadSingle("Probability", i);
for (int i = 0; i < 8; ++i)
npcText.BroadcastTextId[i] = pkt.ReadUInt32("Broadcast Text Id", i);
pkt.ClosePacket(false);
packet.AddSniffData(StoreNameType.NpcText, entry.Key, "QUERY_RESPONSE");
Storage.NpcTextsMop.Add(npcText, packet.TimeSpan);
}
[Parser(Opcode.CMSG_GOSSIP_HELLO)]
public static void HandleGossipHello(Packet packet)
{
var guid = new byte[8];
packet.StartBitStream(guid, 2, 0, 1, 5, 7, 6, 4, 3);
packet.ParseBitStream(guid, 6, 3, 2, 0, 5, 1, 7, 4);
CoreParsers.NpcHandler.LastGossipOption.Guid = packet.WriteGuid("Guid", guid);
}
[Parser(Opcode.CMSG_QUERY_NPC_TEXT)]
public static void HandleNpcTextQuery(Packet packet)
{
packet.ReadInt32("Entry");
var guid = new byte[8];
packet.StartBitStream(guid, 4, 7, 2, 5, 3, 0, 1, 6);
packet.ParseBitStream(guid, 6, 4, 1, 3, 2, 5, 7, 0);
packet.WriteGuid("GUID", guid);
}
[Parser(Opcode.CMSG_GOSSIP_SELECT_OPTION)]
public static void HandleNpcGossipSelectOption(Packet packet)
{
var guid = new byte[8];
var gossipId = packet.ReadUInt32("GossipMenu Id");
var menuEntry = packet.ReadUInt32("Menu Id");
packet.StartBitStream(guid, 4, 0, 6, 3, 2, 7, 1);
var bits8 = packet.ReadBits(8);
guid[5] = packet.ReadBit();
packet.ReadXORByte(guid, 5);
packet.ReadXORByte(guid, 6);
packet.ReadXORByte(guid, 3);
packet.ReadXORByte(guid, 0);
packet.ReadXORByte(guid, 1);
packet.ReadWoWString("Box Text", bits8);
packet.ReadXORByte(guid, 2);
packet.ReadXORByte(guid, 7);
packet.ReadXORByte(guid, 4);
Storage.GossipSelects.Add(Tuple.Create(menuEntry, gossipId), null, packet.TimeSpan);
packet.WriteGuid("GUID", guid);
}
[Parser(Opcode.SMSG_VENDOR_INVENTORY)]
public static void HandleVendorInventoryList(Packet packet)
{
var guid = new byte[8];
packet.ReadByte("Byte18");
guid[1] = packet.ReadBit();
guid[5] = packet.ReadBit();
guid[0] = packet.ReadBit();
guid[2] = packet.ReadBit();
uint count = packet.ReadBits("itemCount", 18);
guid[4] = packet.ReadBit();
var hasExtendedCost = new bool[count];
var hasCondition = new bool[count];
for (int i = 0; i < count; ++i)
{
hasExtendedCost[i] = !packet.ReadBit();
hasCondition[i] = !packet.ReadBit();
packet.ReadBit("Unk bit", i);
}
guid[3] = packet.ReadBit();
guid[6] = packet.ReadBit();
guid[7] = packet.ReadBit();
var tempArray = new NpcVendor[count];
for (int i = 0; i < count; ++i)
{
var vendor = new NpcVendor();
vendor.Item = packet.ReadInt32<ItemId>("Item ID", i);
if (hasCondition[i])
vendor.PlayerConditionID = packet.ReadUInt32("Condition ID", i);
packet.ReadInt32("Price", i);
if (hasExtendedCost[i])
vendor.ExtendedCost = packet.ReadUInt32("Extended Cost", i);
packet.ReadInt32("Display ID", i);
uint buyCount = packet.ReadUInt32("Buy Count", i);
vendor.Slot = packet.ReadInt32("Item Position", i);
int maxCount = packet.ReadInt32("Max Count", i);
vendor.MaxCount = maxCount == -1 ? 0 : (uint)maxCount; // TDB
if (vendor.Type == 2)
vendor.MaxCount = buyCount;
vendor.Type = packet.ReadUInt32("Type", i); // 1 - item, 2 - currency
packet.ReadInt32("Item Upgrade ID", i);
packet.ReadInt32("Max Durability", i);
tempArray[i] = vendor;
}
packet.ParseBitStream(guid, 0, 2, 1, 3, 5, 7, 4, 6);
uint entry = packet.WriteGuid("GUID", guid).GetEntry();
for(int i = 0; i < count; ++i)
{
tempArray[i].Entry = entry;
Storage.NpcVendors.Add(tempArray[i], packet.TimeSpan);
}
}
[Parser(Opcode.SMSG_TRAINER_LIST)]
public static void HandleServerTrainerList(Packet packet)
{
var guid = new byte[8];
guid[4] = packet.ReadBit();
guid[0] = packet.ReadBit();
uint count = packet.ReadBits("Spells", 19);
guid[3] = packet.ReadBit();
guid[7] = packet.ReadBit();
uint titleLen = packet.ReadBits(11);
guid[5] = packet.ReadBit();
guid[6] = packet.ReadBit();
guid[2] = packet.ReadBit();
guid[1] = packet.ReadBit();
var tempArray = new TrainerSpell[count];
for (int i = 0; i < count; ++i)
{
TrainerSpell trainerSpell = new TrainerSpell
{
SpellId = packet.ReadUInt32<SpellId>("SpellID", i),
ReqAbility = new uint[3]
};
for (var j = 0; j < 3; ++j)
trainerSpell.ReqAbility[j] = packet.ReadUInt32<SpellId>("ReqAbility", i, j);
packet.ReadByteE<TrainerSpellState>("Usable", i);
trainerSpell.ReqLevel = packet.ReadByte("ReqLevel", i);
trainerSpell.ReqSkillRank = packet.ReadUInt32("ReqSkillRank", i);
trainerSpell.MoneyCost = packet.ReadUInt32("MoneyCost", i);
trainerSpell.ReqSkillLine = packet.ReadUInt32("ReqSkillLine", i);
tempArray[i] = trainerSpell;
}
packet.ReadXORByte(guid, 4);
packet.ReadXORByte(guid, 3);
packet.ReadXORByte(guid, 2);
packet.ReadXORByte(guid, 5);
packet.ReadXORByte(guid, 1);
packet.ReadXORByte(guid, 6);
Trainer trainer = new Trainer
{
Type = packet.ReadInt32E<TrainerType>("Type"),
Greeting = packet.ReadWoWString("Title", titleLen),
Id = packet.ReadUInt32("TrainerID")
};
packet.ReadXORByte(guid, 7);
packet.ReadXORByte(guid, 0);
packet.WriteGuid("TrainerGUID", guid);
Storage.Trainers.Add(trainer, packet.TimeSpan);
for(int i = 0; i < count; ++i)
{
tempArray[i].TrainerId = trainer.Id;
Storage.TrainerSpells.Add(tempArray[i], packet.TimeSpan);
}
var lastGossipOption = CoreParsers.NpcHandler.LastGossipOption;
if (lastGossipOption.HasSelection)
Storage.GossipMenuOptionTrainers.Add(new GossipMenuOptionTrainer { MenuId = lastGossipOption.MenuId, OptionIndex = lastGossipOption.OptionIndex, TrainerId = trainer.Id }, packet.TimeSpan);
else
Storage.CreatureDefaultTrainers.Add(new CreatureDefaultTrainer { CreatureId = lastGossipOption.Guid.GetEntry(), TrainerId = trainer.Id }, packet.TimeSpan);
}
}
}