TrinityCore
Loading...
Searching...
No Matches
ObjectGuid.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "ObjectGuid.h"
19#include "ByteBuffer.h"
20#include "Errors.h"
21#include "RealmList.h"
22#include "StringFormat.h"
23#include "Util.h"
24#include <bit>
25#include <charconv>
26
27static_assert(sizeof(ObjectGuid) == sizeof(uint64) * 2, "ObjectGuid must be exactly 16 bytes");
28
29namespace
30{
31 struct ObjectGuidInfo
32 {
33 using FormatFunction = fmt::appender(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid);
34 using ParseFunction = ObjectGuid(HighGuid type, std::string_view guidString);
35
36 std::string_view Names[AsUnderlyingType(HighGuid::Count)];
37 std::array<FormatFunction*, AsUnderlyingType(HighGuid::Count)> ClientFormatFunction;
38 std::array<ParseFunction*, AsUnderlyingType(HighGuid::Count)> ClientParseFunction;
39
40 static std::string Format(ObjectGuid const& guid)
41 {
42 return Trinity::StringFormat("{}", guid);
43 }
44
45 ObjectGuid Parse(std::string_view guidString) const
46 {
47 std::size_t typeEnd = guidString.find('-');
48 if (typeEnd == std::string::npos)
49 {
50 if (guidString == "0000000000000000")
51 return ObjectGuid::Empty;
53 }
54
55 std::string_view typeStr = guidString.substr(0, typeEnd);
56 guidString.remove_prefix(typeEnd + 1);
57
58 // find correct parser for type name
59 for (int32 type = 0; type < AsUnderlyingType(HighGuid::Count); ++type)
60 if (typeStr == Names[type])
61 return ClientParseFunction[type](HighGuid(type), guidString);
62
64 }
65
66 struct FormatPadding { std::ptrdiff_t Value; constexpr operator std::ptrdiff_t() const { return Value; } };
67
68 template <std::ptrdiff_t Width>
69 static constexpr inline FormatPadding padding{ .Value = Width };
70 static constexpr inline FormatPadding no_padding{ .Value = 0 };
71
72 struct FormatBase { int32 Value; constexpr operator int32() const { return Value; } };
73
74 static constexpr inline FormatBase dec{ 10 };
75 static constexpr inline FormatBase hex{ 16 };
76
77 static fmt::appender AppendTypeName(fmt::format_context& ctx, std::string_view type)
78 {
79 return std::ranges::copy(type, ctx.out()).out;
80 }
81
82 template <FormatPadding Width, FormatBase Base>
83 static fmt::appender AppendComponent(fmt::format_context& ctx, uint64 component)
84 {
85 *ctx.out() = '-';
86
87 std::array<char, 20> buf;
88 auto [end, err] = std::to_chars(buf.data(), buf.data() + buf.size(), component, Base);
89
90 ASSERT(err == std::errc(), "Failed to convert guid part to string");
91
92 if constexpr (Width != 0)
93 {
94 if (std::ptrdiff_t written = std::distance(buf.data(), end); written < Width)
95 std::ranges::fill_n(ctx.out(), Width - written, '0');
96 }
97
98 if constexpr (Base > 10)
99 return std::ranges::transform(buf.data(), end, ctx.out(), charToUpper).out;
100 else
101 return std::ranges::copy(buf.data(), end, ctx.out()).out;
102 }
103
104 static fmt::appender AppendComponent(fmt::format_context& ctx, std::string_view component)
105 {
106 *ctx.out() = '-';
107 return std::ranges::copy(component, ctx.out()).out;
108 }
109
110 template <FormatBase Base, typename T>
111 static bool ParseComponent(std::string_view& input, T* component)
112 {
113 auto [end, err] = std::from_chars(input.data(), input.data() + input.length(), *component, Base);
114 if (err != std::errc())
115 return false;
116
117 input.remove_prefix(end - input.data());
118 if (!input.empty())
119 {
120 if (input[0] != '-')
121 return false;
122
123 input.remove_prefix(1);
124 }
125
126 return true;
127 }
128
129 static bool ParseDone(std::string_view const& sv) { return sv.empty(); }
130
131 static fmt::appender FormatNull(fmt::format_context& ctx, std::string_view /*typeName*/, ObjectGuid const& /*guid*/)
132 {
133 return std::ranges::fill_n(ctx.out(), 16, '0');
134 }
135
136 static ObjectGuid ParseNull(HighGuid, std::string_view)
137 {
138 return ObjectGuid::Empty;
139 }
140
141 static constexpr std::array<std::string_view, 20> UniqNames =
142 {
143 "",
144 "WOWGUID_UNIQUE_PROBED_DELETE",
145 "WOWGUID_UNIQUE_JAM_TEMP",
146 "WOWGUID_TO_STRING_FAILED",
147 "WOWGUID_FROM_STRING_FAILED",
148 "WOWGUID_UNIQUE_SERVER_SELF",
149 "WOWGUID_UNIQUE_MAGIC_SELF",
150 "WOWGUID_UNIQUE_MAGIC_PET",
151 "WOWGUID_UNIQUE_INVALID_TRANSPORT",
152 "WOWGUID_UNIQUE_AMMO_ID",
153 "WOWGUID_SPELL_TARGET_TRADE_ITEM",
154 "WOWGUID_SCRIPT_TARGET_INVALID",
155 "WOWGUID_SCRIPT_TARGET_NONE",
156 "",
157 "WOWGUID_FAKE_MODERATOR",
158 "",
159 "",
160 "WOWGUID_UNIQUE_ACCOUNT_OBJ_INITIALIZATION",
161 "",
162 "WOWGUID_PENDING_PERMANENT_CHARACTER_ASSIGNMENT"
163 };
164
165 static fmt::appender FormatUniq(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
166 {
168 if (id >= UniqNames.size() || UniqNames[id].empty())
169 id = 3;
170
171 ctx.advance_to(AppendTypeName(ctx, typeName));
172 ctx.advance_to(AppendComponent(ctx, UniqNames[id]));
173 return ctx.out();
174 }
175
176 static ObjectGuid ParseUniq(HighGuid /*type*/, std::string_view guidString)
177 {
178 for (std::size_t id = 0; id < UniqNames.size(); ++id)
179 {
180 if (UniqNames[id].empty())
181 continue;
182
183 if (guidString == UniqNames[id])
185 }
186
188 }
189
190 static fmt::appender FormatPlayer(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
191 {
192 ctx.advance_to(AppendTypeName(ctx, typeName));
193 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRealmId()));
194 switch (uint8 subType = (guid.GetRawValue(1) >> 40) & 0x3)
195 {
196 case 0:
197 // no subType
198 ctx.advance_to(AppendComponent<padding<8>, hex>(ctx, guid.GetRawValue(0)));
199 break;
200 case 1: // characterless (plunderstorm)
201 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, subType));
202 ctx.advance_to(AppendComponent<padding<16>, hex>(ctx, guid.GetRawValue(0)));
203 break;
204 case 2: // npc-as-player
205 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, subType));
206 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 16 & 0xFFFFFF)); // creature id?
207 ctx.advance_to(AppendComponent<padding<16>, hex>(ctx, guid.GetRawValue(0)));
208 break;
209 default:
210 break;
211 }
212
213 return ctx.out();
214 }
215
216 static ObjectGuid ParsePlayer(HighGuid /*type*/, std::string_view guidString)
217 {
218 uint32 realmId = 0;
219 uint8 subType = 0;
220 uint32 arg1 = 0;
221 uint64 dbId = UI64LIT(0);
222
223 if (!ParseComponent<dec>(guidString, &realmId)
224 || !ParseComponent<hex>(guidString, &dbId))
226
227 if (!ParseDone(guidString))
228 {
229 // dbId holds playerType at this point
230 switch (dbId)
231 {
232 case 1: // characterless (plunderstorm)
233 break;
234 case 2: // npc-as-player
235 if (!ParseComponent<dec>(guidString, &arg1)) // creature id?
237 break;
238 default:
240 }
241
242 subType = dbId;
243 if (!ParseComponent<hex>(guidString, &dbId)
244 || !ParseDone(guidString))
246 }
247
248 return ObjectGuidFactory::CreatePlayer(realmId, subType, arg1, dbId);
249 }
250
251 static fmt::appender FormatItem(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
252 {
253 ctx.advance_to(AppendTypeName(ctx, typeName));
254 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRealmId()));
255 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 18 & 0xFFFFFF));
256 ctx.advance_to(AppendComponent<padding<16>, hex>(ctx, guid.GetRawValue(0)));
257 return ctx.out();
258 }
259
260 static ObjectGuid ParseItem(HighGuid /*type*/, std::string_view guidString)
261 {
262 uint32 realmId = 0;
263 uint32 arg1 = 0;
264 uint64 dbId = UI64LIT(0);
265
266 if (!ParseComponent<dec>(guidString, &realmId)
267 || !ParseComponent<dec>(guidString, &arg1)
268 || !ParseComponent<hex>(guidString, &dbId)
269 || !ParseDone(guidString))
271
272 return ObjectGuidFactory::CreateItem(realmId, dbId);
273 }
274
275 static fmt::appender FormatWorldObject(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
276 {
277 ctx.advance_to(AppendTypeName(ctx, typeName));
278 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetSubType()));
279 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRealmId()));
280 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetMapId()));
281 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(0) >> 40 & 0xFFFFFF));
282 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetEntry()));
283 ctx.advance_to(AppendComponent<padding<10>, hex>(ctx, guid.GetCounter()));
284 return ctx.out();
285 }
286
287 static ObjectGuid ParseWorldObject(HighGuid type, std::string_view guidString)
288 {
289 uint8 subType = 0;
290 uint32 realmId = 0;
291 uint16 mapId = 0;
292 uint32 serverId = 0;
293 uint32 id = 0;
294 uint64 counter = UI64LIT(0);
295
296 if (!ParseComponent<dec>(guidString, &subType)
297 || !ParseComponent<dec>(guidString, &realmId)
298 || !ParseComponent<dec>(guidString, &mapId)
299 || !ParseComponent<dec>(guidString, &serverId)
300 || !ParseComponent<dec>(guidString, &id)
301 || !ParseComponent<hex>(guidString, &counter)
302 || !ParseDone(guidString))
304
305 return ObjectGuidFactory::CreateWorldObject(type, subType, realmId, mapId, serverId, id, counter);
306 }
307
308 static fmt::appender FormatTransport(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
309 {
310 ctx.advance_to(AppendTypeName(ctx, typeName));
311 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetEntry()));
312 ctx.advance_to(AppendComponent<padding<16>, hex>(ctx, guid.GetRawValue(0)));
313 return ctx.out();
314 }
315
316 static ObjectGuid ParseTransport(HighGuid type, std::string_view guidString)
317 {
318 uint32 id = 0;
319 uint32 counter = 0;
320
321 if (!ParseComponent<dec>(guidString, &id)
322 || !ParseComponent<hex>(guidString, &counter)
323 || !ParseDone(guidString))
325
326 return ObjectGuidFactory::CreateTransport(type, counter);
327 }
328
329 static fmt::appender FormatClientActor(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
330 {
331 ctx.advance_to(AppendTypeName(ctx, typeName));
332 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRealmId()));
333 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 26 & 0xFFFFFF));
334 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(0) & 0xFFFFFFFF));
335 return ctx.out();
336 }
337
338 static ObjectGuid ParseClientActor(HighGuid /*type*/, std::string_view guidString)
339 {
340 uint16 ownerType = 0;
341 uint16 ownerId = 0;
342 uint32 counter = 0;
343
344 if (!ParseComponent<dec>(guidString, &ownerType)
345 || !ParseComponent<dec>(guidString, &ownerId)
346 || !ParseComponent<dec>(guidString, &counter)
347 || !ParseDone(guidString))
349
350 return ObjectGuidFactory::CreateClientActor(ownerType, ownerId, counter);
351 }
352
353 static fmt::appender FormatChatChannel(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
354 {
355 uint32 builtIn = (guid.GetRawValue(1) >> 25) & 0x1;
356 uint32 trade = (guid.GetRawValue(1) >> 24) & 0x1;
357 uint32 zoneId = (guid.GetRawValue(1) >> 10) & 0x3FFF;
358 uint32 factionGroupMask = (guid.GetRawValue(1) >> 4) & 0x3F;
359
360 ctx.advance_to(AppendTypeName(ctx, typeName));
361 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRealmId()));
362 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, builtIn));
363 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, trade));
364 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, zoneId));
365 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, factionGroupMask));
366 ctx.advance_to(AppendComponent<padding<8>, hex>(ctx, guid.GetRawValue(0)));
367 return ctx.out();
368 }
369
370 static ObjectGuid ParseChatChannel(HighGuid /*type*/, std::string_view guidString)
371 {
372 uint32 realmId = 0;
373 uint32 builtIn = 0;
374 uint32 trade = 0;
375 uint16 zoneId = 0;
376 uint8 factionGroupMask = 0;
377 uint64 id = UI64LIT(0);
378
379 if (!ParseComponent<dec>(guidString, &realmId)
380 || !ParseComponent<dec>(guidString, &builtIn)
381 || !ParseComponent<dec>(guidString, &trade)
382 || !ParseComponent<dec>(guidString, &zoneId)
383 || !ParseComponent<dec>(guidString, &factionGroupMask)
384 || !ParseComponent<hex>(guidString, &id)
385 || !ParseDone(guidString))
387
388 return ObjectGuidFactory::CreateChatChannel(realmId, builtIn != 0, trade != 0, zoneId, factionGroupMask, id);
389 }
390
391 static fmt::appender FormatGlobal(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
392 {
393 ctx.advance_to(AppendTypeName(ctx, typeName));
394 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) & 0x3FFFFFFFFFFFFFF));
395 ctx.advance_to(AppendComponent<padding<12>, hex>(ctx, guid.GetRawValue(0)));
396 return ctx.out();
397 }
398
399 static ObjectGuid ParseGlobal(HighGuid type, std::string_view guidString)
400 {
401 uint64 dbIdHigh = UI64LIT(0);
402 uint64 dbIdLow = UI64LIT(0);
403
404 if (!ParseComponent<dec>(guidString, &dbIdHigh)
405 || !ParseComponent<hex>(guidString, &dbIdLow)
406 || !ParseDone(guidString))
408
409 return ObjectGuidFactory::CreateGlobal(type, dbIdHigh, dbIdLow);
410 }
411
412 static fmt::appender FormatGuild(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
413 {
414 ctx.advance_to(AppendTypeName(ctx, typeName));
415 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRealmId()));
416 ctx.advance_to(AppendComponent<padding<12>, hex>(ctx, guid.GetRawValue(0)));
417 return ctx.out();
418 }
419
420 static ObjectGuid ParseGuild(HighGuid type, std::string_view guidString)
421 {
422 uint32 realmId = 0;
423 uint64 dbId = UI64LIT(0);
424
425 if (!ParseComponent<dec>(guidString, &realmId)
426 || !ParseComponent<hex>(guidString, &dbId)
427 || !ParseDone(guidString))
429
430 return ObjectGuidFactory::CreateGuild(type, realmId, dbId);
431 }
432
433 static fmt::appender FormatMobileSession(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
434 {
435 ctx.advance_to(AppendTypeName(ctx, typeName));
436 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRealmId()));
437 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 33 & 0x1FF));
438 ctx.advance_to(AppendComponent<padding<8>, hex>(ctx, guid.GetRawValue(0)));
439 return ctx.out();
440 }
441
442 static ObjectGuid ParseMobileSession(HighGuid /*type*/, std::string_view guidString)
443 {
444 uint32 realmId = 0;
445 uint16 arg1 = 0;
446 uint64 counter = UI64LIT(0);
447
448 if (!ParseComponent<dec>(guidString, &realmId)
449 || !ParseComponent<dec>(guidString, &arg1)
450 || !ParseComponent<hex>(guidString, &counter)
451 || !ParseDone(guidString))
453
454 return ObjectGuidFactory::CreateMobileSession(realmId, arg1, counter);
455 }
456
457 static fmt::appender FormatWebObj(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
458 {
459 ctx.advance_to(AppendTypeName(ctx, typeName));
460 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRealmId()));
461 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 37 & 0x1F));
462 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 35 & 0x3));
463 ctx.advance_to(AppendComponent<padding<12>, hex>(ctx, guid.GetRawValue(0)));
464 return ctx.out();
465 }
466
467 static ObjectGuid ParseWebObj(HighGuid /*type*/, std::string_view guidString)
468 {
469 uint32 realmId = 0;
470 uint8 arg1 = 0;
471 uint8 arg2 = 0;
472 uint64 counter = UI64LIT(0);
473
474 if (!ParseComponent<dec>(guidString, &realmId)
475 || !ParseComponent<dec>(guidString, &arg1)
476 || !ParseComponent<dec>(guidString, &arg2)
477 || !ParseComponent<hex>(guidString, &counter)
478 || !ParseDone(guidString))
480
481 return ObjectGuidFactory::CreateWebObj(realmId, arg1, arg2, counter);
482 }
483
484 static fmt::appender FormatLFGObject(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
485 {
486 ctx.advance_to(AppendTypeName(ctx, typeName));
487 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 54 & 0xF));
488 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 50 & 0xF));
489 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 46 & 0xF));
490 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 38 & 0xFF));
491 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 37 & 0x1));
492 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 35 & 0x3));
493 ctx.advance_to(AppendComponent<padding<6>, hex>(ctx, guid.GetRawValue(0)));
494 return ctx.out();
495 }
496
497 static ObjectGuid ParseLFGObject(HighGuid /*type*/, std::string_view guidString)
498 {
499 uint8 arg1 = 0;
500 uint8 arg2 = 0;
501 uint8 arg3 = 0;
502 uint8 arg4 = 0;
503 uint8 arg5 = 0;
504 uint8 arg6 = 0;
505 uint64 counter = UI64LIT(0);
506
507 if (!ParseComponent<dec>(guidString, &arg1)
508 || !ParseComponent<dec>(guidString, &arg2)
509 || !ParseComponent<dec>(guidString, &arg3)
510 || !ParseComponent<dec>(guidString, &arg4)
511 || !ParseComponent<dec>(guidString, &arg5)
512 || !ParseComponent<dec>(guidString, &arg6)
513 || !ParseComponent<hex>(guidString, &counter)
514 || !ParseDone(guidString))
516
517 return ObjectGuidFactory::CreateLFGObject(arg1, arg2, arg3, arg4, arg5 != 0, arg6, counter);
518 }
519
520 static fmt::appender FormatLFGList(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
521 {
522 ctx.advance_to(AppendTypeName(ctx, typeName));
523 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 54 & 0xF));
524 ctx.advance_to(AppendComponent<padding<6>, hex>(ctx, guid.GetRawValue(0)));
525 return ctx.out();
526 }
527
528 static ObjectGuid ParseLFGList(HighGuid /*type*/, std::string_view guidString)
529 {
530 uint8 arg1 = 0;
531 uint64 counter = UI64LIT(0);
532
533 if (!ParseComponent<dec>(guidString, &arg1)
534 || !ParseComponent<hex>(guidString, &counter)
535 || !ParseDone(guidString))
537
538 return ObjectGuidFactory::CreateLFGList(arg1, counter);
539 }
540
541 static fmt::appender FormatClient(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
542 {
543 ctx.advance_to(AppendTypeName(ctx, typeName));
544 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRealmId()));
545 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) >> 10 & 0xFFFFFFFF));
546 ctx.advance_to(AppendComponent<padding<12>, hex>(ctx, guid.GetRawValue(0)));
547 return ctx.out();
548 }
549
550 static ObjectGuid ParseClient(HighGuid type, std::string_view guidString)
551 {
552 uint32 realmId = 0;
553 uint32 arg1 = 0;
554 uint64 counter = UI64LIT(0);
555
556 if (!ParseComponent<dec>(guidString, &realmId)
557 || !ParseComponent<dec>(guidString, &arg1)
558 || !ParseComponent<hex>(guidString, &counter)
559 || !ParseDone(guidString))
561
562 return ObjectGuidFactory::CreateClient(type, realmId, arg1, counter);
563 }
564
565 static fmt::appender FormatClubFinder(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
566 {
567 uint32 type = uint32(guid.GetRawValue(1) >> 33) & 0xFF;
568 uint32 clubFinderId = uint32(guid.GetRawValue(1)) & 0xFFFFFFFF;
569
570 ctx.advance_to(AppendTypeName(ctx, typeName));
571 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, type));
572 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, clubFinderId));
573 switch (type)
574 {
575 case 0: // club
576 ctx.advance_to(AppendComponent<padding<16>, hex>(ctx, guid.GetRawValue(0))); // clubId
577 break;
578 case 1: // guild
579 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRealmId()));
580 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(0))); // guildId
581 break;
582 default:
583 break;
584 }
585
586 return ctx.out();
587 }
588
589 static ObjectGuid ParseClubFinder(HighGuid /*type*/, std::string_view guidString)
590 {
591 uint8 type = 0;
592 uint32 clubFinderId = 0;
593 uint32 realmId = 0;
594 uint64 dbId = UI64LIT(0);
595
596 if (!ParseComponent<dec>(guidString, &type)
597 || !ParseComponent<dec>(guidString, &clubFinderId))
599
600 switch (type)
601 {
602 case 0: // club
603 if (!ParseComponent<hex>(guidString, &dbId))
605 break;
606 case 1: // guild
607 if (!ParseComponent<dec>(guidString, &realmId)
608 || !ParseComponent<dec>(guidString, &dbId))
610 break;
611 default:
613 }
614
615 if (!ParseDone(guidString))
617
618 return ObjectGuidFactory::CreateClubFinder(realmId, type, clubFinderId, dbId);
619 }
620
621 static fmt::appender FormatToolsClient(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
622 {
623 ctx.advance_to(AppendTypeName(ctx, typeName));
624 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetMapId()));
625 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(0) >> 40 & 0xFFFFFF));
626 ctx.advance_to(AppendComponent<padding<10>, hex>(ctx, guid.GetCounter()));
627 return ctx.out();
628 }
629
630 static ObjectGuid ParseToolsClient(HighGuid /*type*/, std::string_view guidString)
631 {
632 uint16 mapId = 0;
633 uint32 serverId = 0;
634 uint64 counter = UI64LIT(0);
635
636 if (!ParseComponent<dec>(guidString, &mapId)
637 || !ParseComponent<dec>(guidString, &serverId)
638 || !ParseComponent<hex>(guidString, &counter)
639 || !ParseDone(guidString))
641
642 return ObjectGuidFactory::CreateToolsClient(mapId, serverId, counter);
643 }
644
645 static fmt::appender FormatWorldLayer(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
646 {
647 ctx.advance_to(AppendTypeName(ctx, typeName));
648 ctx.advance_to(AppendComponent<padding<0>, hex>(ctx, guid.GetRawValue(1) >> 10 & 0xFFFFFFFF));
649 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(1) & 0x1FF));
650 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(0) >> 24 & 0xFF));
651 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(0) & 0x7FFFFF));
652 return ctx.out();
653 }
654
655 static ObjectGuid ParseWorldLayer(HighGuid /*type*/, std::string_view guidString)
656 {
657 uint32 arg1 = 0;
658 uint16 arg2 = 0;
659 uint8 arg3 = 0;
660 uint32 arg4 = 0;
661
662 if (!ParseComponent<hex>(guidString, &arg1)
663 || !ParseComponent<dec>(guidString, &arg2)
664 || !ParseComponent<dec>(guidString, &arg3)
665 || !ParseComponent<dec>(guidString, &arg4)
666 || !ParseDone(guidString))
668
669 return ObjectGuidFactory::CreateWorldLayer(arg1, arg2, arg3, arg4);
670 }
671
672 static fmt::appender FormatLMMLobby(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
673 {
674 ctx.advance_to(AppendTypeName(ctx, typeName));
675 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRealmId()));
676 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, uint32(guid.GetRawValue(1) >> 26) & 0xFFFFFF));
677 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, uint32(guid.GetRawValue(1) >> 18) & 0xFF));
678 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, uint32(guid.GetRawValue(1) >> 10) & 0xFF));
679 ctx.advance_to(AppendComponent<padding<0>, hex>(ctx, guid.GetRawValue(0)));
680 return ctx.out();
681 }
682
683 static ObjectGuid ParseLMMLobby(HighGuid /*type*/, std::string_view guidString)
684 {
685 uint32 realmId = 0;
686 uint32 arg2 = 0;
687 uint8 arg3 = 0;
688 uint8 arg4 = 0;
689 uint64 arg5 = 0;
690
691 if (!ParseComponent<dec>(guidString, &realmId)
692 || !ParseComponent<dec>(guidString, &arg2)
693 || !ParseComponent<dec>(guidString, &arg3)
694 || !ParseComponent<dec>(guidString, &arg4)
695 || !ParseComponent<hex>(guidString, &arg5)
696 || !ParseDone(guidString))
698
699 return ObjectGuidFactory::CreateLMMLobby(realmId, arg2, arg3, arg4, arg5);
700 }
701
702 static fmt::appender FormatHousing(fmt::format_context& ctx, std::string_view typeName, ObjectGuid const& guid)
703 {
704 ctx.advance_to(AppendTypeName(ctx, typeName));
705 switch (uint32 subType = (guid.GetRawValue(1) >> 53) & 0x1F)
706 {
707 case 1:
708 case 4:
709 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, subType));
710 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, uint32(guid.GetRawValue(1) >> 32) & 0xFFFF));
711 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, uint32(guid.GetRawValue(1)) & 0xFFFFFFFF));
712 ctx.advance_to(AppendComponent<no_padding, hex>(ctx, guid.GetRawValue(0)));
713 break;
714 case 2:
715 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, subType));
716 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, uint32(guid.GetRawValue(1)) & 0xFFFFFFFF));
717 ctx.advance_to(AppendComponent<no_padding, hex>(ctx, guid.GetRawValue(0)));
718 break;
719 case 3:
720 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, subType));
721 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, uint32(guid.GetRawValue(1)) & 0x7FFF));
722 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, guid.GetRawValue(0)));
723 ctx.advance_to(AppendComponent<no_padding, dec>(ctx, uint32(guid.GetRawValue(1) >> 15) & 0x3F));
724 break;
725 default:
726 break;
727 }
728 return ctx.out();
729 }
730
731 static ObjectGuid ParseHousing(HighGuid /*type*/, std::string_view guidString)
732 {
733 uint32 subType = 0;
734
735 if (!ParseComponent<dec>(guidString, &subType))
737
738 uint32 arg1 = 0;
739 uint32 arg2 = 0;
740 uint64 arg3 = UI64LIT(0);
741
742 switch (subType)
743 {
744 case 1:
745 case 4:
746 if (!ParseComponent<dec>(guidString, &arg1)
747 || !ParseComponent<dec>(guidString, &arg2)
748 || !ParseComponent<hex>(guidString, &arg3)
749 || !ParseDone(guidString))
751 break;
752 case 2:
753 if (!ParseComponent<dec>(guidString, &arg2)
754 || !ParseComponent<hex>(guidString, &arg3)
755 || !ParseDone(guidString))
757 break;
758 case 3:
759 if (!ParseComponent<dec>(guidString, &arg2)
760 || !ParseComponent<dec>(guidString, &arg3)
761 || !ParseComponent<dec>(guidString, &arg1)
762 || !ParseDone(guidString))
764 break;
765 }
766
767 return ObjectGuidFactory::CreateHousing(subType, arg1, arg2, arg3);
768 }
769
770 ObjectGuidInfo();
771 } Info;
772
773 ObjectGuidInfo::ObjectGuidInfo()
774 {
775#define SET_GUID_INFO(type, format, parse) \
776 Names[AsUnderlyingType(HighGuid::type)] = #type ## sv;\
777 ClientFormatFunction[AsUnderlyingType(HighGuid::type)] = &ObjectGuidInfo::format;\
778 ClientParseFunction[AsUnderlyingType(HighGuid::type)] = &ObjectGuidInfo::parse
779
780 SET_GUID_INFO(Null, FormatNull, ParseNull);
781 SET_GUID_INFO(Uniq, FormatUniq, ParseUniq);
782 SET_GUID_INFO(Player, FormatPlayer, ParsePlayer);
783 SET_GUID_INFO(Item, FormatItem, ParseItem);
784 SET_GUID_INFO(WorldTransaction, FormatWorldObject, ParseWorldObject);
785 SET_GUID_INFO(StaticDoor, FormatTransport, ParseTransport);
786 SET_GUID_INFO(Transport, FormatTransport, ParseTransport);
787 SET_GUID_INFO(Conversation, FormatWorldObject, ParseWorldObject);
788 SET_GUID_INFO(Creature, FormatWorldObject, ParseWorldObject);
789 SET_GUID_INFO(Vehicle, FormatWorldObject, ParseWorldObject);
790 SET_GUID_INFO(Pet, FormatWorldObject, ParseWorldObject);
791 SET_GUID_INFO(GameObject, FormatWorldObject, ParseWorldObject);
792 SET_GUID_INFO(DynamicObject, FormatWorldObject, ParseWorldObject);
793 SET_GUID_INFO(AreaTrigger, FormatWorldObject, ParseWorldObject);
794 SET_GUID_INFO(Corpse, FormatWorldObject, ParseWorldObject);
795 SET_GUID_INFO(LootObject, FormatWorldObject, ParseWorldObject);
796 SET_GUID_INFO(SceneObject, FormatWorldObject, ParseWorldObject);
797 SET_GUID_INFO(Scenario, FormatWorldObject, ParseWorldObject);
798 SET_GUID_INFO(AIGroup, FormatWorldObject, ParseWorldObject);
799 SET_GUID_INFO(DynamicDoor, FormatWorldObject, ParseWorldObject);
800 SET_GUID_INFO(ClientActor, FormatClientActor, ParseClientActor);
801 SET_GUID_INFO(Vignette, FormatWorldObject, ParseWorldObject);
802 SET_GUID_INFO(CallForHelp, FormatWorldObject, ParseWorldObject);
803 SET_GUID_INFO(AIResource, FormatWorldObject, ParseWorldObject);
804 SET_GUID_INFO(AILock, FormatWorldObject, ParseWorldObject);
805 SET_GUID_INFO(AILockTicket, FormatWorldObject, ParseWorldObject);
806 SET_GUID_INFO(ChatChannel, FormatChatChannel, ParseChatChannel);
807 SET_GUID_INFO(Party, FormatGlobal, ParseGlobal);
808 SET_GUID_INFO(Guild, FormatGuild, ParseGuild);
809 SET_GUID_INFO(WowAccount, FormatGlobal, ParseGlobal);
810 SET_GUID_INFO(BNetAccount, FormatGlobal, ParseGlobal);
811 SET_GUID_INFO(GMTask, FormatGlobal, ParseGlobal);
812 SET_GUID_INFO(MobileSession, FormatMobileSession, ParseMobileSession);
813 SET_GUID_INFO(RaidGroup, FormatGlobal, ParseGlobal);
814 SET_GUID_INFO(Spell, FormatGlobal, ParseGlobal);
815 SET_GUID_INFO(Mail, FormatGlobal, ParseGlobal);
816 SET_GUID_INFO(WebObj, FormatWebObj, ParseWebObj);
817 SET_GUID_INFO(LFGObject, FormatLFGObject, ParseLFGObject);
818 SET_GUID_INFO(LFGList, FormatLFGList, ParseLFGList);
819 SET_GUID_INFO(UserRouter, FormatGlobal, ParseGlobal);
820 SET_GUID_INFO(PVPQueueGroup, FormatGlobal, ParseGlobal);
821 SET_GUID_INFO(UserClient, FormatGlobal, ParseGlobal);
822 SET_GUID_INFO(PetBattle, FormatClient, ParseClient);
823 SET_GUID_INFO(UniqUserClient, FormatClient, ParseClient);
824 SET_GUID_INFO(BattlePet, FormatGlobal, ParseGlobal);
825 SET_GUID_INFO(CommerceObj, FormatGlobal, ParseGlobal);
826 SET_GUID_INFO(ClientSession, FormatClient, ParseClient);
827 SET_GUID_INFO(Cast, FormatWorldObject, ParseWorldObject);
828 SET_GUID_INFO(ClientConnection, FormatClient, ParseClient);
829 SET_GUID_INFO(ClubFinder, FormatClubFinder, ParseClubFinder);
830 SET_GUID_INFO(ToolsClient, FormatToolsClient, ParseToolsClient);
831 SET_GUID_INFO(WorldLayer, FormatWorldLayer, ParseWorldLayer);
832 SET_GUID_INFO(ArenaTeam, FormatGuild, ParseGuild);
833 SET_GUID_INFO(LMMParty, FormatClient, ParseClient);
834 SET_GUID_INFO(LMMLobby, FormatLMMLobby, ParseLMMLobby);
835 SET_GUID_INFO(Housing, FormatHousing, ParseHousing);
836 SET_GUID_INFO(MeshObject, FormatWorldObject, ParseWorldObject);
837 SET_GUID_INFO(Entity, FormatWorldObject, ParseWorldObject);
838
839#undef SET_GUID_INFO
840 }
841}
842
843template <typename FormatContext>
844auto fmt::formatter<ObjectGuid>::format(ObjectGuid const& guid, FormatContext& ctx) const -> decltype(ctx.out())
845{
846 if (guid.GetHigh() >= HighGuid::Count)
847 return this->format(ObjectGuid::ToStringFailed, ctx);
848
849 int32 type = AsUnderlyingType(guid.GetHigh());
850 if (!Info.ClientFormatFunction[type])
851 return this->format(ObjectGuid::ToStringFailed, ctx);
852
853 return Info.ClientFormatFunction[type](ctx, Info.Names[type], guid);
854}
855
856template TC_GAME_API fmt::appender fmt::formatter<ObjectGuid>::format<fmt::format_context>(ObjectGuid const&, format_context&) const;
857
858std::string_view ObjectGuid::GetTypeName(HighGuid high)
859{
860 if (high >= HighGuid::Count)
861 return "<unknown>";
862
863 return Info.Names[uint32(high)];
864}
865
866std::string ObjectGuid::ToString() const
867{
868 return ObjectGuidInfo::Format(*this);
869}
870
871std::string ObjectGuid::ToHexString() const
872{
873 return Trinity::StringFormat("0x{:016X}{:016X}", _data[1], _data[0]);
874}
875
876ObjectGuid ObjectGuid::FromString(std::string_view guidString)
877{
878 return Info.Parse(guidString);
879}
880
881void ObjectGuid::SetRawValue(std::span<uint8 const> rawBytes)
882{
883 ASSERT(rawBytes.size() == BytesSize, SZFMTD " == " SZFMTD, rawBytes.size(), BytesSize);
884 memcpy(_data.data(), rawBytes.data(), BytesSize);
885}
886
888{
889 if (realmId)
890 return realmId;
891
892 return sRealmList->GetCurrentRealmId().Realm;
893}
894
896{
897 return ObjectGuid();
898}
899
905
907{
909 | (uint64(GetRealmIdForObjectGuid(realmId)) << 42)
910 | (uint64(subType & 0x3) << 40)
911 | (uint64(arg1 & 0xFFFFFF) << 16)),
912 dbId);
913}
914
916{
917 return ObjectGuid(uint64((uint64(HighGuid::Item) << 58)
918 | (uint64(GetRealmIdForObjectGuid(realmId)) << 42)),
919 dbId);
920}
921
923{
924 return ObjectGuid(uint64((uint64(type) << 58)
925 | (uint64(GetRealmIdForObjectGuid(realmId) & 0x1FFF) << 42)
926 | (uint64(mapId & 0x1FFF) << 29)
927 | (uint64(entry & 0x7FFFFF) << 6)
928 | (uint64(subType) & 0x3F)),
929 uint64((uint64(serverId & 0xFFFFFF) << 40)
930 | (counter & UI64LIT(0xFFFFFFFFFF))));
931}
932
934{
935 return ObjectGuid(uint64((uint64(type) << 58)
936 | (uint64(counter) << 38)),
937 UI64LIT(0));
938}
939
941{
943 | (uint64(ownerType & 0x1FFF) << 42)
944 | (uint64(ownerId & 0xFFFFFF) << 26)),
945 uint64(counter));
946}
947
948ObjectGuid ObjectGuidFactory::CreateChatChannel(uint32 realmId, bool builtIn, bool trade, uint16 zoneId, uint8 factionGroupMask, ObjectGuid::LowType counter)
949{
951 | (uint64(GetRealmIdForObjectGuid(realmId) & 0x1FFF) << 42)
952 | (uint64(builtIn) << 25)
953 | (uint64(trade) << 24)
954 | (uint64(zoneId & 0x3FFF) << 10)
955 | (uint64(factionGroupMask & 0x3F) << 4)),
956 counter);
957}
958
960{
961 return ObjectGuid(uint64((uint64(type) << 58)
962 | (uint64(dbIdHigh & UI64LIT(0x3FFFFFFFFFFFFFF)))),
963 dbId);
964}
965
967{
968 return ObjectGuid(uint64((uint64(type) << 58)
969 | (uint64(GetRealmIdForObjectGuid(realmId)) << 42)),
970 dbId);
971}
972
974{
976 | (uint64(GetRealmIdForObjectGuid(realmId)) << 42)
977 | (uint64(arg1 & 0x1FF) << 33)),
978 counter);
979}
980
982{
984 | (uint64(GetRealmIdForObjectGuid(realmId) & 0x1FFF) << 42)
985 | (uint64(arg1 & 0x1F) << 37)
986 | (uint64(arg2 & 0x3) << 35)),
987 counter);
988}
989
991{
993 | (uint64(arg1 & 0xF) << 54)
994 | (uint64(arg2 & 0xF) << 50)
995 | (uint64(arg3 & 0xF) << 46)
996 | (uint64(arg4 & 0xFF) << 38)
997 | (uint64(arg5 ? 1 : 0) << 37)
998 | (uint64(arg6 & 0x3) << 35)),
999 counter);
1000}
1001
1003{
1005 | (uint64(arg1 & 0xF) << 54)),
1006 counter);
1007}
1008
1010{
1011 return ObjectGuid(uint64((uint64(type) << 58)
1012 | (uint64(GetRealmIdForObjectGuid(realmId) & 0x1FFF) << 42)
1013 | (uint64(arg1 & 0xFFFFFFFF) << 10)),
1014 counter);
1015}
1016
1018{
1020 | (type == 1 ? (uint64(GetRealmIdForObjectGuid(realmId) & 0x1FFF) << 42) : UI64LIT(0))
1021 | (uint64(type & 0xFF) << 33)
1022 | (uint64(clubFinderId & 0xFFFFFFFF))),
1023 dbId);
1024}
1025
1027{
1029 | uint64(mapId)),
1030 uint64((uint64(serverId & 0xFFFFFF) << 40)
1031 | (counter & UI64LIT(0xFFFFFFFFFF))));
1032}
1033
1035{
1037 | (uint64(arg1 & 0xFFFFFFFF) << 10)
1038 | (uint64(arg2 & 0x1FF))),
1039 uint64((uint64(arg3 & 0xFF) << 24)
1040 | uint64(arg4 & 0x7FFFFF)));
1041}
1042
1044{
1046 | (uint64(GetRealmIdForObjectGuid(realmId)) << 42)
1047 | (uint64(arg2 & 0xFFFFFFFF) << 26)
1048 | (uint64(arg3 & 0xFF) << 18)
1049 | (uint64(arg4 & 0xFF) << 10)),
1050 counter);
1051}
1052
1054{
1055 switch (subType)
1056 {
1057 case 1:
1058 case 4:
1060 | (uint64(subType & 0x1F) << 53)
1061 | (uint64(arg1 & 0xFFFF) << 32)
1062 | (uint64(arg2 & 0xFFFFFFFF))),
1063 arg3);
1064 case 2:
1066 | (uint64(subType & 0x1F) << 53)
1067 | (uint64(arg2 & 0xFFFFFFFF))),
1068 arg3);
1069 case 3:
1071 | (uint64(subType & 0x1F) << 53)
1072 | (uint64(arg1 & 0x3F) << 15)
1073 | (uint64(arg2 & 0x7FFF))),
1074 arg3);
1075 default:
1076 break;
1077 }
1078
1079 return ObjectGuid::Empty;
1080}
1081
1082ObjectGuid const ObjectGuid::Empty = ObjectGuid::Create<HighGuid::Null>();
1083ObjectGuid const ObjectGuid::ToStringFailed = ObjectGuid::Create<HighGuid::Uniq>(UI64LIT(3));
1084ObjectGuid const ObjectGuid::FromStringFailed = ObjectGuid::Create<HighGuid::Uniq>(UI64LIT(4));
1085ObjectGuid const ObjectGuid::TradeItem = ObjectGuid::Create<HighGuid::Uniq>(UI64LIT(10));
1086
1088{
1089 static constexpr std::ptrdiff_t NumUInt64s = std::tuple_size_v<decltype(ObjectGuid::_data)>;
1090
1091 std::array<uint8, NumUInt64s + ObjectGuid::BytesSize> bytes;
1092 int32 mask = 0;
1093 int32 outputByteIndex = NumUInt64s;
1094 std::span<uint8 const, ObjectGuid::BytesSize> guidBytes = std::span<uint8 const, ObjectGuid::BytesSize>(reinterpret_cast<uint8 const*>(guid._data.data()), ObjectGuid::BytesSize);
1095
1096 for (int32 inputByteIndex = 0; inputByteIndex < int32(ObjectGuid::BytesSize); ++inputByteIndex)
1097 {
1098 uint8 byte = guidBytes[inputByteIndex];
1099 bytes[outputByteIndex] = byte;
1100
1101 int32 hasByte = (byte != 0) ? 1 : 0;
1102 mask |= hasByte << inputByteIndex;
1103 outputByteIndex += hasByte;
1104 }
1105
1106 bytes[0] = mask & 0xFF;
1107 bytes[1] = (mask >> 8) & 0xFF;
1108 buf.append(bytes.data(), outputByteIndex);
1109
1110 return buf;
1111}
1112
1114{
1115 uint16 mask = buf.read<uint16>();
1116 std::span<uint8> bytes = buf.ReadBytes(std::popcount(mask));
1117
1118 // check highest byte holding guid type
1119 // if it's 0 then we consider it empty and discard all sent bytes
1120 // return early to prevent reading out of bounds data
1121 if (!(mask & 0x8000))
1122 {
1123 guid.Clear();
1124 return buf;
1125 }
1126
1127 std::span<uint8, ObjectGuid::BytesSize> guidBytes = std::span<uint8, ObjectGuid::BytesSize>(reinterpret_cast<uint8*>(guid._data.data()), ObjectGuid::BytesSize);
1128
1129 for (std::size_t outputByteIndex = 0, inputByteIndex = 0; outputByteIndex < ObjectGuid::BytesSize; ++outputByteIndex)
1130 {
1131 int32 hasByte = (mask >> outputByteIndex) & 1;
1132 guidBytes[outputByteIndex] = bytes[inputByteIndex] & -hasByte;
1133 inputByteIndex += hasByte;
1134 }
1135
1136 return buf;
1137}
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
int32_t int32
Definition Define.h:150
uint64_t uint64
Definition Define.h:153
#define UI64LIT(N)
Definition Define.h:139
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
#define SZFMTD
Definition Define.h:144
#define ASSERT
Definition Errors.h:72
ByteBuffer & operator<<(ByteBuffer &buf, ObjectGuid const &guid)
ByteBuffer & operator>>(ByteBuffer &buf, ObjectGuid &guid)
static uint32 GetRealmIdForObjectGuid(uint32 realmId)
#define SET_GUID_INFO(type, format, parse)
HighGuid
Definition ObjectGuid.h:109
@ UniqUserClient
@ WorldTransaction
@ ClientConnection
#define sRealmList
Definition RealmList.h:95
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition Util.h:565
struct CharToUpper charToUpper
std::span< uint8 > ReadBytes(size_t length)
Definition ByteBuffer.h:566
void append(T value)
Definition ByteBuffer.h:131
Definition Guild.h:329
Definition Item.h:185
static ObjectGuid CreateTransport(HighGuid type, uint32 counter)
static ObjectGuid CreateHousing(uint32 subType, uint32 arg1, uint32 arg2, uint64 arg3)
static ObjectGuid CreateGlobal(HighGuid type, uint64 dbIdHigh, uint64 dbId)
static ObjectGuid CreateItem(uint32 realmId, uint64 dbId)
static ObjectGuid CreateWorldLayer(uint32 arg1, uint16 arg2, uint8 arg3, uint32 arg4)
static ObjectGuid CreateLMMLobby(uint32 realmId, uint32 arg2, uint8 arg3, uint8 arg4, uint64 counter)
static ObjectGuid CreateMobileSession(uint32 realmId, uint16 arg1, uint64 counter)
static ObjectGuid CreateClubFinder(uint32 realmId, uint8 type, uint32 clubFinderId, uint64 dbId)
static ObjectGuid CreateClient(HighGuid type, uint32 realmId, uint32 arg1, uint64 counter)
static ObjectGuid CreateClientActor(uint16 ownerType, uint16 ownerId, uint32 counter)
static ObjectGuid CreateToolsClient(uint16 mapId, uint32 serverId, uint64 counter)
static ObjectGuid CreatePlayer(uint32 realmId, uint8 subType, uint32 arg1, uint64 dbId)
static ObjectGuid CreateGuild(HighGuid type, uint32 realmId, uint64 dbId)
static ObjectGuid CreateWorldObject(HighGuid type, uint8 subType, uint32 realmId, uint16 mapId, uint32 serverId, uint32 entry, uint64 counter)
static ObjectGuid CreateChatChannel(uint32 realmId, bool builtIn, bool trade, uint16 zoneId, uint8 factionGroupMask, uint64 counter)
static constexpr ObjectGuid CreateUniq(uint64 id)
static ObjectGuid CreateLFGList(uint8 arg1, uint64 counter)
static constexpr ObjectGuid CreateNull()
static ObjectGuid CreateLFGObject(uint8 arg1, uint8 arg2, uint8 arg3, uint8 arg4, bool arg5, uint8 arg6, uint64 counter)
static ObjectGuid CreateWebObj(uint32 realmId, uint8 arg1, uint8 arg2, uint64 counter)
uint32 GetMapId() const
Definition ObjectGuid.h:333
LowType GetCounter() const
Definition ObjectGuid.h:336
static ObjectGuid const Empty
Definition ObjectGuid.h:314
static ObjectGuid const ToStringFailed
Definition ObjectGuid.h:315
uint64 GetRawValue(std::size_t i) const
Definition ObjectGuid.h:325
static ObjectGuid const FromStringFailed
Definition ObjectGuid.h:316
std::string ToHexString() const
std::string ToString() const
std::string_view GetTypeName() const
Definition ObjectGuid.h:396
void SetRawValue(std::span< uint8 const > rawBytes)
static ObjectGuid FromString(std::string_view guidString)
static constexpr std::size_t BytesSize
Definition ObjectGuid.h:319
std::array< uint64, 2 > _data
Definition ObjectGuid.h:428
uint32 GetEntry() const
Definition ObjectGuid.h:334
static ObjectGuid const TradeItem
Definition ObjectGuid.h:317
uint32 GetSubType() const
Definition ObjectGuid.h:335
uint64 LowType
Definition ObjectGuid.h:321
uint32 GetRealmId() const
Definition ObjectGuid.h:332
HighGuid GetHigh() const
Definition ObjectGuid.h:331
void Clear()
Definition ObjectGuid.h:329
Definition Pet.h:40
Definition Spell.h:277
std::string StringFormat(FormatString< Args... > fmt, Args &&... args) noexcept
Default TC string format function.
Definition Mail.h:181