diff --git a/WoW/Source/Game/GameTime.cpp b/WoW/Source/Game/GameTime.cpp index a34c108..ec7171f 100644 --- a/WoW/Source/Game/GameTime.cpp +++ b/WoW/Source/Game/GameTime.cpp @@ -1,5 +1,6 @@ #include "GameTime.h" #include "Engine/Source/Os/TimeManager.h" +#include "Engine/Source/Storm/H/storm.h" // STATIC: 0x00D37F98 CGameTime g_clientGameTime; @@ -173,3 +174,37 @@ void CGameTime::GameTimeUpdate(float elapsed) { this->TickMinute(); } } + +// VERIFY: 580cfeb5 manual +// OFFSET: 0x0076D1D0 +void __stdcall CGameTime::GameTimeUnregisterCallback(TIMESTAMPCALLBACK* callback) { + callback->m_link.Unlink(); + delete callback; +} + +// VERIFY: d53477cf manual +// OFFSET: 0x0076DB30 +TIMESTAMPCALLBACK* CGameTime::GameTimeRegisterCallback(const WowTime* time, void (__stdcall* callback)(CGameTime* time, void* param), void* param) { + if (!callback) { + DebugValidate("callback"); + SErrSetLastError(STORM_ERROR_INVALID_PARAMETER); + return nullptr; + } + + if (time->m_hour < 0 || time->m_minute < 0) { + return nullptr; + } + + int32_t minutes = time->GetHourAndMinutes(); + HASHKEY_NONE key; + TIMESTAMPSTRUCT* stamp = this->m_timeStamps.Ptr(minutes, key); + + if (!stamp) { + stamp = this->m_timeStamps.New(minutes, key, 0, 0); + } + + TIMESTAMPCALLBACK* node = stamp->m_callbacks.NewNode(2, 0, 0); + node->m_param = param; + node->m_callback = callback; + return node; +} diff --git a/WoW/Source/Game/GameTime.h b/WoW/Source/Game/GameTime.h index 69e7c4f..fcf4826 100644 --- a/WoW/Source/Game/GameTime.h +++ b/WoW/Source/Game/GameTime.h @@ -24,8 +24,11 @@ class CGameTime : public WowTime { /* 004C */ float unk_004C; /* 0050 */ TSHashTable m_timeStamps; + static void __stdcall GameTimeUnregisterCallback(TIMESTAMPCALLBACK* callback); + CGameTime(); float GameTimeGetDayProgression(); + TIMESTAMPCALLBACK* GameTimeRegisterCallback(const WowTime* time, void (__stdcall* callback)(CGameTime* time, void* param), void* param); float GameTimeSetMinutesPerSecond(float minutesPerSecond); void GameTimeSetTime(const WowTime& time, bool tick); void GameTimeSync(const WowTime& time, bool a2); diff --git a/WoW/Source/Game/ValidateName.cpp b/WoW/Source/Game/ValidateName.cpp index 0c5ae11..1aa63d3 100644 --- a/WoW/Source/Game/ValidateName.cpp +++ b/WoW/Source/Game/ValidateName.cpp @@ -910,3 +910,45 @@ bool ScrubString(const char* source, char* dest, int32_t maxChars, uint32_t dest return valid; } + +// VERIFY: 62097c42 manual +// OFFSET: 0x007E2040 +bool FixCharacterNameCase(char* dest, const char* source, uint32_t size) { + if (!dest || !size) { + return false; + } + + uint16_t buffer[1024]; + SUniConvertUTF8to16(buffer, 1024, source, STORM_MAX_STR, nullptr, nullptr); + + for (uint32_t i = 0; buffer[i]; i++) { + uint16_t c = buffer[i]; + + if (i) { + if (static_cast(c - 'A') <= 25 || static_cast(c - 0xC0) <= 30) { + c += 32; + } else if (c == 0x152) { + c = 0x153; + } else if (static_cast(c - 0x410) <= 31) { + c += 32; + } else if (c == 0x401) { + c = 0x451; + } + } else if (c >= 'a' && c <= 'z') { + c -= 32; + } else if (c >= 0xE0 && c <= 0xFE) { + c -= 32; + } else if (c == 0x153) { + c = 0x152; + } else if (c >= 0x430 && c <= 0x44F) { + c -= 32; + } else if (c == 0x451) { + c = 0x401; + } + + buffer[i] = c; + } + + SUniConvertUTF16to8(dest, size, buffer, STORM_MAX_STR, nullptr, nullptr); + return true; +} diff --git a/WoW/Source/Game/ValidateName.h b/WoW/Source/Game/ValidateName.h index c652a74..ca27bb1 100644 --- a/WoW/Source/Game/ValidateName.h +++ b/WoW/Source/Game/ValidateName.h @@ -37,6 +37,7 @@ uint16_t ToLower(uint16_t c); bool StripHyperlinks(const char* text, char* buffer, uint32_t size); bool ScrubString(const char* source, char* dest, int32_t maxChars, uint32_t destSize, int32_t flags); +bool FixCharacterNameCase(char* dest, const char* source, uint32_t size); int32_t GetNumRussianNameDeclensionSets(const char* name, int32_t sex); int32_t GetRussianNameDeclensions(char* declensions, const char* name, int32_t sex, uint32_t set); diff --git a/WoW/Source/Ui/Calendar.cpp b/WoW/Source/Ui/Calendar.cpp index db6c932..f36e9cb 100644 --- a/WoW/Source/Ui/Calendar.cpp +++ b/WoW/Source/Ui/Calendar.cpp @@ -24,12 +24,21 @@ #include "WoW/Source/Client.h" #include "WoW/Source/Object/ObjectClient/Player_C.h" #include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Ui/GuildInfo.h" +#include "WoW/Source/Ui/ChatFrame.h" +#include "WoW/Source/Ui/MailInfo.h" +#include "WoW/Source/DB/Rec/HolidayDescriptionsRec.h" +#include "WoW/Source/DB/DBClient/DBCacheInstances.h" +#include "WoW/Source/Object/Object.h" +#include "WoW/Source/Object/Player.h" +#include "Engine/Source/Os/TimeManager.h" +#include // STATIC: 0x00AD0340 static TSList > s_pendingInvites; // STATIC: 0x00AD0350 -static CalendarEventClipboard s_eventClipboard; +CalendarEventData s_eventClipboard; // STATIC: 0x00AD0328 static TSList > s_holidays; @@ -44,10 +53,10 @@ static TSGrowableArray s_days[3][31]; static CalendarEventTables s_eventTables; // STATIC: 0x00C20F38 -static TSHashTable s_dynamicHolidays; +TSHashTable s_dynamicHolidays; // STATIC: 0x00C20F60 -static TSFixedArray s_eventTextures[2]; +TSFixedArray s_eventTextures[2]; // STATIC: 0x00C207EC CGCalendarEvent* CGCalendar::m_curEvent; @@ -59,7 +68,13 @@ uint8_t CGCalendar::m_initialize; uint8_t CGCalendar::m_openedCalendar; // STATIC: 0x00C207F2 -uint8_t CGCalendar::unk_C207F2; +uint8_t CGCalendar::m_calendarReceived; + +// STATIC: 0x00C207E8 +CalendarDayEvent* CGCalendar::m_contextEventInfo; + +// STATIC: 0x00C207FC +uint32_t CGCalendar::m_lastEventTime; // STATIC: 0x00C207F4 int32_t CGCalendar::m_numInitialPending; @@ -67,13 +82,13 @@ int32_t CGCalendar::m_numInitialPending; // STATIC: 0x00C207F3 uint8_t CGCalendar::m_actionPending; -// VERIFY: 6a081deb auto +// VERIFY: 339c2c98 auto // OFFSET: 0x005C4240 void CGCalendar::InitializeGame() { CGCalendar::m_curEvent = nullptr; CGCalendar::m_initialize = 1; CGCalendar::m_openedCalendar = 0; - CGCalendar::unk_C207F2 = 0; + CGCalendar::m_calendarReceived = 0; CGCalendar::m_numInitialPending = 0; ClientServices::SetMessageHandler(SMSG_CALENDAR_SEND_CALENDAR, PH_CALENDAR_GROUP, nullptr); @@ -671,23 +686,22 @@ bool GameCalendarGetMaxCreateDate(WowTime* date) { // STATIC: 0x00ACFF94 static CVar** s_eventFilters[8] = { nullptr, nullptr, &s_cvCalendarShowLockouts, &s_cvCalendarShowResets, nullptr, &s_cvCalendarShowWeeklyHolidays, &s_cvCalendarShowDarkmoon, &s_cvCalendarShowBattlegrounds }; -// VERIFY: 05349707 auto +// VERIFY: f0f4c3be auto // OFFSET: 0x005B7820 CalendarDayEvent::CalendarDayEvent() { this->m_eventID = 0; this->m_startTime = 0; - this->unk_008C = 0; + this->m_alarmTime = 0; this->m_endTime = 0; this->m_holidayID = 0; this->m_type = 0; this->m_flags = 0; - this->unk_00A0 = -1; - this->unk_00A4 = 0; - this->unk_00A8 = 0; - this->unk_00B0 = 0; - this->unk_00B4 = 0; + this->m_eventType = -1; + this->m_textureID = 0; + this->m_inviteStatus = 0; + this->m_inviteID = 0; this->m_creatorGUID = WOWGUID(); - this->unk_00C0 = 0; + this->m_alarmCallback = nullptr; this->m_sequenceIndex = 0; this->m_sequenceLength = 0; } @@ -1524,3 +1538,2152 @@ int32_t CGCalendar::GetFirstPendingInviteIndex(uint32_t offset, uint32_t day) { return -1; } + +// VERIFY: b580c245 auto +// OFFSET: 0x005B7910 +static void __stdcall FireEventAlarm(CGameTime* time, void* param) { + CalendarDayEvent* event = static_cast(param); + WowTime alarm; + WowTime::WowDecodeTime(event->m_alarmTime, &alarm); + alarm.m_tzHours = 0; + + if (*time == alarm && (event->m_inviteStatus == 3 || event->m_inviteStatus == 1)) { + WowTime start; + WowTime::WowDecodeTime(event->m_startTime, &start); + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_EVENT_ALARM, "%s%d%d", event->m_title, start.m_hour, start.m_minute); + CGameTime::GameTimeUnregisterCallback(event->m_alarmCallback); + event->m_alarmCallback = nullptr; + } +} + +// VERIFY: fecc7261 auto +// OFFSET: 0x005B79B0 +void CalendarDayEvent::ScheduleAlarm() { + WowTime alarm; + WowTime::WowDecodeTime(this->m_startTime, &alarm); + alarm.m_tzHours = 0; + alarm.AddMinutes(-15); + WowTime::WowEncodeTime(this->m_alarmTime, &alarm); + this->m_alarmCallback = g_clientGameTime.GameTimeRegisterCallback(&alarm, FireEventAlarm, this); +} + +// VERIFY: 4db791b6 manual +// OFFSET: 0x005B8D10 +CalendarDayEvent::~CalendarDayEvent() { + if (this->m_alarmCallback) { + CGameTime::GameTimeUnregisterCallback(this->m_alarmCallback); + this->m_alarmCallback = nullptr; + } +} + +// VERIFY: f6c769b5 auto +// OFFSET: 0x005B7AF0 +static uint32_t EncodeDate(int32_t month, int32_t monthDay, int32_t year) { + WowTime date; + date.m_month = month; + date.m_monthDay = monthDay; + date.m_year = year; + uint32_t value; + WowTime::WowEncodeTime(value, &date); + return value; +} + +// VERIFY: 5341ec83 manual +// OFFSET: 0x005B7C00 +bool CGCalendar::ValidateCreateDate(const WowTime* date) { + if (!CGCalendar::ValidateDate(date)) { + return false; + } + + WowTime check = *date; + check.m_tzHours = date->m_tzHours; + WowTime limit; + limit = g_clientGameTime; + check.SetHourAndMinutes(limit.m_hour, limit.m_minute); + + if (check < limit) { + return false; + } + + GameCalendarGetMaxCreateDate(&limit); + check.SetHourAndMinutes(limit.m_hour, limit.m_minute); + return !(check > limit); +} + +// VERIFY: 5f5b9bac auto +// OFFSET: 0x005B7CC0 +void CGCalendar::ProcessInitialInviteList(CDataStore* msg) { + CGCalendar::m_curEvent->ProcessInitialInviteList(msg); +} + +// VERIFY: ce5df57d manual +// OFFSET: 0x005B7D20 +bool CGCalendar::CanEditCurrentEvent() { + if (!CGCalendar::m_curEvent) { + return false; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + return CGGuildInfo::CanEditGuildEvent(); + } + + return CGCalendar::m_curEvent->IsModerator(); +} + +// VERIFY: 784b0912 manual +// OFFSET: 0x005B7D60 +void CGCalendar::SetInviteStatus(uint32_t index, uint32_t status) { + if (!CGCalendar::m_curEvent) { + return; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return; + } + + if (CGCalendar::m_curEvent->m_new || !CGCalendar::m_actionPending) { + CGCalendar::m_curEvent->SetInviteStatus(index, status); + } +} + +// VERIFY: 60d9ba2b manual +// OFFSET: 0x005B7DC0 +void CGCalendar::SetModeratorStatus(uint32_t index, uint32_t status) { + if (!CGCalendar::m_curEvent) { + return; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return; + } + + if (CGCalendar::m_curEvent->m_new || !CGCalendar::m_actionPending) { + CGCalendar::m_curEvent->SetModeratorStatus(index, status); + } +} + +// VERIFY: 4354a74f auto +// OFFSET: 0x005B7E20 +void CGCalendar::SetActionPending(uint8_t pending) { + CGCalendar::m_actionPending = pending; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_ACTION_PENDING, "%b", pending); +} + +// VERIFY: 7820a65b auto +// OFFSET: 0x005B7FD0 +const char* CGCalendar::GetCalendarTypeString(uint32_t flags) { + if (flags & 0x1) { + return "PLAYER"; + } + + if (flags & 0x40) { + return "GUILD_ANNOUNCEMENT"; + } + + if (flags & 0x400) { + return "GUILD_EVENT"; + } + + if (flags & 0x4) { + return "SYSTEM"; + } + + if (flags & 0x8) { + return "HOLIDAY"; + } + + if (flags & 0x80) { + return "RAID_LOCKOUT"; + } + + if (flags & 0x200) { + return "RAID_RESET"; + } + + if (flags & 0x2) { + return "PLAYER"; + } + + if (flags & 0x100) { + return "PLAYER"; + } + + return ""; +} + +// VERIFY: ab94a6ff auto +// OFFSET: 0x005B9140 +uint32_t CGCalendar::GetDateKey(uint32_t time) { + WowTime date; + WowTime::WowDecodeTime(time, &date); + WowTime key; + key.m_month = date.m_month; + key.m_monthDay = date.m_monthDay; + key.m_year = date.m_year; + uint32_t value; + WowTime::WowEncodeTime(value, &key); + return value; +} + +// VERIFY: 9cf4e561 auto +// OFFSET: 0x005B9260 +CalendarDayEvent* CGCalendar::GetDayEvent(uint32_t offset, uint32_t day, uint32_t index) { + if (CGCalendar::GetDayEvent(offset, day) && index < s_days[offset + 1][day].Count()) { + return s_days[offset + 1][day].m_data[index]; + } + + return nullptr; +} + +// VERIFY: 9bc3f579 auto +// OFFSET: 0x005B9310 +void CGCalendar::GetEvent(uint32_t offset, uint32_t day, uint32_t index) { + if (CGCalendar::m_actionPending || offset + 1 > 2 || day >= 31 || index >= s_days[offset + 1][day].Count()) { + return; + } + + CalendarDayEvent* event = CGCalendar::GetDayEvent(offset, day, index); + + if (event && (event->m_type & 0x543)) { + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_GET_EVENT)); + msg.Put(event->m_eventID); + msg.Finalize(); + ClientServices::Send2(&msg); + CGCalendar::SetActionPending(1); + return; + } + + CGCalendar::m_selectedEvent.m_eventID = event->m_eventID; + CGCalendar::m_selectedEvent.m_startTime = event->m_startTime; + CGCalendar::m_selectedEvent.m_endTime = event->m_endTime; + CGCalendar::m_selectedEvent.m_holidayID = event->m_holidayID; + CGCalendar::m_selectedEvent.unk_0014 = event->m_type; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_OPEN_EVENT, "%s", CGCalendar::GetCalendarTypeString(event->m_type)); +} + +// VERIFY: b3fb02e5 auto +// OFFSET: 0x005B9490 +const char* GetHolidayDescription(int32_t holidayId) { + HolidaysRec* holiday = g_holidaysDB.GetRecord(holidayId); + + if (!holiday) { + return nullptr; + } + + HolidayDescriptionsRec* description = g_holidayDescriptionsDB.GetRecord(holiday->m_holidayDescriptionID); + return description ? description->m_description : nullptr; +} + +// VERIFY: 820bfaa2 manual +// OFFSET: 0x005B94F0 +bool CGCalendar::SetEventDate(uint32_t month, uint32_t monthDay, uint32_t year) { + if (!CGCalendar::m_curEvent) { + return false; + } + + bool canEdit = (CGCalendar::m_curEvent->m_flags & 0x40) ? CGGuildInfo::CanEditGuildEvent() : CGCalendar::m_curEvent->IsModerator(); + + if (!canEdit) { + return false; + } + + return CGCalendar::m_curEvent->SetDate(month, monthDay, year); +} + +// VERIFY: 613d12ff manual +// OFFSET: 0x005B9540 +bool CGCalendar::SetEventTime(uint32_t hour, uint32_t minute) { + if (!CGCalendar::m_curEvent) { + return false; + } + + bool canEdit = (CGCalendar::m_curEvent->m_flags & 0x40) ? CGGuildInfo::CanEditGuildEvent() : CGCalendar::m_curEvent->IsModerator(); + + if (!canEdit) { + return false; + } + + return CGCalendar::m_curEvent->SetTime(hour, minute); +} + +// VERIFY: 8d81e954 manual +// OFFSET: 0x005B9590 +bool CGCalendar::SetEventLockoutDate(uint32_t month, uint32_t monthDay, uint32_t year) { + if (!CGCalendar::m_curEvent) { + return false; + } + + bool canEdit = (CGCalendar::m_curEvent->m_flags & 0x40) ? CGGuildInfo::CanEditGuildEvent() : CGCalendar::m_curEvent->IsModerator(); + + if (!canEdit) { + return false; + } + + return CGCalendar::m_curEvent->SetLockoutDate(month, monthDay, year); +} + +// VERIFY: 0685eff6 manual +// OFFSET: 0x005B95E0 +bool CGCalendar::SetEventLockoutTime(uint32_t hour, uint32_t minute) { + if (!CGCalendar::m_curEvent) { + return false; + } + + bool canEdit = (CGCalendar::m_curEvent->m_flags & 0x40) ? CGGuildInfo::CanEditGuildEvent() : CGCalendar::m_curEvent->IsModerator(); + + if (!canEdit) { + return false; + } + + return CGCalendar::m_curEvent->SetLockoutTime(hour, minute); +} + +// VERIFY: a4ee2027 manual +// OFFSET: 0x005B9630 +void CGCalendar::SetEventTextureID(uint32_t index) { + if (!CGCalendar::m_curEvent) { + return; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return; + } + + uint32_t list; + + if (CGCalendar::m_curEvent->m_type == 1) { + list = 0; + } else if (CGCalendar::m_curEvent->m_type == 0) { + list = 1; + } else { + return; + } + + if (index < s_eventTextures[list].Count()) { + CGCalendar::m_curEvent->SetTextureID(s_eventTextures[list].m_data[index]); + } +} + +// VERIFY: 51286ab1 auto +// OFFSET: 0x005B96A0 +void CGCalendar::RemoveEvent() { + if (CGCalendar::m_actionPending || !CGCalendar::m_curEvent || CGCalendar::m_curEvent->m_new) { + return; + } + + if (CGCalendar::CanEditCurrentEvent()) { + if (!CGCalendar::m_curEvent->RemoveEvent()) { + return; + } + } else if (!CGCalendar::m_curEvent->RemoveInviteByGUID(ClntObjMgrGetActivePlayer())) { + return; + } + + CGCalendar::SetActionPending(1); +} + +// VERIFY: efc33489 auto +// OFFSET: 0x005B9700 +int32_t CGCalendar::GetTextureIndex(uint32_t type, int32_t textureID) { + uint32_t list; + + if (type == 1) { + list = 0; + } else if (type == 0) { + list = 1; + } else { + return -1; + } + + for (uint32_t i = 0; i < s_eventTextures[list].Count(); i++) { + if (s_eventTextures[list].m_data[i] == textureID) { + return i; + } + } + + return -1; +} + +// VERIFY: eee7ac59 manual +// OFFSET: 0x005B9760 +EventInviteInfo* CGCalendar::GetCurrentEventInvite(WOWGUID guid) { + return CGCalendar::m_curEvent ? CGCalendar::m_curEvent->GetInvite(guid) : nullptr; +} + +// VERIFY: 2ca20a00 auto +// OFFSET: 0x005B9780 +void CGCalendar::RemoveInvite(uint32_t index) { + if (CGCalendar::m_actionPending || !CGCalendar::m_curEvent || !CGCalendar::m_curEvent->RemoveInvite(index)) { + return; + } + + if (CGCalendar::m_curEvent->m_new) { + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, nullptr); + } else { + CGCalendar::SetActionPending(1); + } +} + +// VERIFY: 783bd655 auto +// OFFSET: 0x005B97D0 +void CGCalendar::SelectContextEvent(uint32_t offset, uint32_t day, uint32_t index) { + if (!CGCalendar::GetDayEvent(offset, day) || index >= s_days[offset + 1][day].Count()) { + return; + } + + CalendarDayEvent* event = s_days[offset + 1][day].m_data[index]; + + if (!event) { + return; + } + + CGCalendar::m_contextEvent.m_eventID = event->m_eventID; + CGCalendar::m_contextEvent.m_startTime = event->m_startTime; + CGCalendar::m_contextEvent.m_endTime = event->m_endTime; + CGCalendar::m_contextEvent.m_holidayID = event->m_holidayID; + CGCalendar::m_contextEvent.unk_0014 = event->m_type; + CGCalendar::m_contextEventInfo = event; +} + +// VERIFY: 11d7b720 manual +// OFFSET: 0x005B9860 +void CGCalendar::ContextMenuInviteRSVP(CalendarDayEvent* event, uint32_t status) { + if (!event || CGCalendar::m_actionPending) { + return; + } + + if ((event->m_type & 0x400) && (event->m_flags & 0x8)) { + return; + } + + if (status != 1 && status != 2 && status != 8) { + return; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_RSVP)); + msg.Put(event->m_eventID); + msg.Put(event->m_inviteID); + msg.Put(status); + msg.Finalize(); + ClientServices::Send2(&msg); + CGCalendar::m_actionPending = 1; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_ACTION_PENDING, "%b", 1); +} + +// VERIFY: 148806d4 manual +// OFFSET: 0x005BBB40 +void CGCalendar::GetCalendar() { + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_GET_CALENDAR)); + msg.Finalize(); + ClientServices::Send2(&msg); + CGCalendar::m_openedCalendar = 1; +} + +// VERIFY: 18bd4700 manual +// OFFSET: 0x005BBC20 +void CGCalendar::ProcessInviteNotes(CDataStore* msg, uint8_t* clearPending) { + if (!ClntObjMgrGetActivePlayerObj()) { + msg->m_read = msg->m_size; + return; + } + + SmartGUID guid; + *msg >> guid; + uint64_t eventID; + msg->Get(eventID); + char notes[128]; + msg->GetString(notes, STORM_MAX_STR); + uint8_t clear; + msg->Get(clear); + + if (!clear) { + *clearPending = 0; + } + + if (CGCalendar::m_curEvent && eventID == CGCalendar::m_curEvent->m_eventID) { + CGCalendar::m_curEvent->UpdateInviteNotes(guid, notes); + } +} + +// VERIFY: 6d3709b0 manual +// OFFSET: 0x005BBCD0 +void CGCalendar::ProcessInviteNotesAlert(CDataStore* msg) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + msg->m_read = msg->m_size; + return; + } + + uint64_t eventID; + msg->Get(eventID); + char notes[128]; + msg->GetString(notes, STORM_MAX_STR); + + if (CGCalendar::m_curEvent && eventID == CGCalendar::m_curEvent->m_eventID) { + CGCalendar::m_curEvent->UpdateInviteNotes(player->m_obj->m_guid, notes); + } +} + +// VERIFY: eae011c1 auto +// OFFSET: 0x005BBD60 +void CGCalendar::AddEvent() { + if (CGCalendar::m_actionPending) { + return; + } + + if (!CGCalendar::m_curEvent) { + CGCalendar::CalendarError("CALENDAR_ERROR_INTERNAL", 0); + return; + } + + uint32_t now; + + if ((unk_BD09AC && unk_BD09AC->m_intValue) || (now = OsGetAsyncTimeMs(), !CGCalendar::m_lastEventTime) || now - CGCalendar::m_lastEventTime >= 5000) { + if (CGCalendar::ValidateCreateDate(&CGCalendar::m_curEvent->m_date) && CGCalendar::m_curEvent->AddEvent()) { + CGCalendar::m_lastEventTime = OsGetAsyncTimeMs(); + CGCalendar::SetActionPending(1); + } + } else { + CGCalendar::CalendarError("CALENDAR_ERROR_EVENT_THROTTLED", 0); + } +} + +// VERIFY: e5b81e7f manual +// OFFSET: 0x005BBE50 +void CGCalendar::CreatePlayerEvent() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + if (CGCalendar::m_curEvent) { + delete CGCalendar::m_curEvent; + } + + void* mem = SMemAlloc(sizeof(CGCalendarEvent), __FILE__, __LINE__, 0); + CGCalendar::m_curEvent = mem ? new (mem) CGCalendarEvent(player->m_obj->m_guid, player->m_unit->m_unitFieldLevel, 0) : nullptr; + CGCalendar::m_selectedEvent.m_eventID = 0; + CGCalendar::m_selectedEvent.m_startTime = 0; + CGCalendar::m_selectedEvent.m_endTime = 0; + CGCalendar::m_selectedEvent.m_holidayID = 0; + CGCalendar::m_selectedEvent.unk_0014 = 0; + + if (CGCalendar::m_curEvent) { + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, "%b", 1); + } +} + +// VERIFY: 4fb18508 manual +// OFFSET: 0x005BBF20 +void CGCalendar::CreateGuildAnnouncement() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + if (!player->m_player->m_playerGuildid) { + CGCalendar::CalendarError("ERR_GUILD_PLAYER_NOT_IN_GUILD", 0); + return; + } + + if (CGCalendar::m_curEvent) { + delete CGCalendar::m_curEvent; + } + + void* mem = SMemAlloc(sizeof(CGCalendarEvent), __FILE__, __LINE__, 0); + CGCalendar::m_curEvent = mem ? new (mem) CGCalendarEvent(WOWGUID(), 0, 1) : nullptr; + CGCalendar::m_selectedEvent.m_eventID = 0; + CGCalendar::m_selectedEvent.m_startTime = 0; + CGCalendar::m_selectedEvent.m_endTime = 0; + CGCalendar::m_selectedEvent.m_holidayID = 0; + CGCalendar::m_selectedEvent.unk_0014 = 0; +} + +// VERIFY: 8c223278 manual +// OFFSET: 0x005BC030 +void CGCalendar::CreateGuildEvent() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + if (!player->m_player->m_playerGuildid) { + CGCalendar::CalendarError("ERR_GUILD_PLAYER_NOT_IN_GUILD", 0); + return; + } + + if (CGCalendar::m_curEvent) { + delete CGCalendar::m_curEvent; + } + + void* mem = SMemAlloc(sizeof(CGCalendarEvent), __FILE__, __LINE__, 0); + CGCalendar::m_curEvent = mem ? new (mem) CGCalendarEvent(player->m_obj->m_guid, player->m_unit->m_unitFieldLevel, 2) : nullptr; + CGCalendar::m_selectedEvent.m_eventID = 0; + CGCalendar::m_selectedEvent.m_startTime = 0; + CGCalendar::m_selectedEvent.m_endTime = 0; + CGCalendar::m_selectedEvent.m_holidayID = 0; + CGCalendar::m_selectedEvent.unk_0014 = 0; +} + +// VERIFY: f0dee297 manual +// OFFSET: 0x005BC160 +void CGCalendar::GuildFilter(uint32_t minLevel, uint32_t maxLevel, uint32_t minRank) { + if (CGCalendar::m_actionPending) { + return; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + if (!player->m_player->m_playerGuildid) { + CGCalendar::CalendarError("ERR_GUILD_PLAYER_NOT_IN_GUILD", 0); + return; + } + + if (!CGCalendar::m_curEvent || !CGCalendar::m_curEvent->m_new || (CGCalendar::m_curEvent->m_flags & 0x440)) { + return; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_GUILD_FILTER)); + msg.Put(minLevel); + msg.Put(maxLevel); + msg.Put(minRank); + msg.Finalize(); + ClientServices::Send2(&msg); + CGCalendar::SetActionPending(1); +} + +// VERIFY: bb90e389 manual +// OFFSET: 0x005BC240 +void CGCalendar::ArenaTeam(uint32_t index) { + if (CGCalendar::m_actionPending) { + return; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player || index >= 3) { + return; + } + + uint32_t* info = &player->m_player->m_playerFieldArenaTeamInfo11[index * 7]; + + if (!info || !*info || !CGCalendar::m_curEvent || !CGCalendar::m_curEvent->m_new || (CGCalendar::m_curEvent->m_flags & 0x440)) { + return; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_ARENA_TEAM)); + msg.Put(*info); + msg.Finalize(); + ClientServices::Send2(&msg); + CGCalendar::SetActionPending(1); +} + +// VERIFY: acb138ea auto +// OFFSET: 0x005BC310 +void CGCalendar::UpdateEvent() { + if (CGCalendar::m_actionPending || !CGCalendar::m_curEvent || CGCalendar::m_curEvent->m_new) { + return; + } + + if (!CGCalendar::CanEditCurrentEvent()) { + CGCalendar::CalendarError("CALENDAR_ERROR_PERMISSIONS", 0); + return; + } + + if (CGCalendar::m_curEvent->Update()) { + CGCalendar::SetActionPending(1); + } +} + +// VERIFY: 0cd94ee0 auto +// OFFSET: 0x005BC360 +void CGCalendar::Invite(const char* name) { + if (CGCalendar::m_actionPending || !CGCalendar::m_curEvent || !CGCalendar::m_curEvent->IsModerator()) { + return; + } + + uint32_t now; + + if ((unk_BD09AC && unk_BD09AC->m_intValue) || (now = OsGetAsyncTimeMs(), !CGCalendar::m_lastInviteTime) || now - CGCalendar::m_lastInviteTime >= 2000) { + if (CGCalendar::m_curEvent->Invite(name)) { + CGCalendar::m_lastInviteTime = OsGetAsyncTimeMs(); + CGCalendar::SetActionPending(1); + } + } else { + CGCalendar::CalendarError("CALENDAR_ERROR_INVITE_THROTTLED", 0); + } +} + +// VERIFY: 535dc77b manual +// OFFSET: 0x005BC3E0 +void CGCalendar::InviteRSVP(uint32_t status) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player || CGCalendar::m_actionPending || !CGCalendar::m_curEvent) { + return; + } + + bool sent; + + if ((CGCalendar::m_curEvent->m_flags & 0x400) && CGCalendar::m_curEvent->m_guildID == player->m_player->m_playerGuildid) { + if (status != 8) { + return; + } + + sent = CGCalendar::m_curEvent->SignUp(1); + } else { + sent = CGCalendar::m_curEvent->InviteRSVP(status); + } + + if (sent) { + CGCalendar::SetActionPending(1); + } +} + +// VERIFY: 22c17537 manual +// OFFSET: 0x005BC460 +void CGCalendar::EventSignUp() { + if (CGCalendar::m_actionPending || !CGCalendar::m_curEvent || !(CGCalendar::m_curEvent->m_flags & 0x400)) { + return; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if ((!player || !CGCalendar::GetCurrentEventInvite(player->m_obj->m_guid)) && CGCalendar::m_curEvent->SignUp(0)) { + CGCalendar::SetActionPending(1); + } +} + +// VERIFY: be3b8c9d manual +// OFFSET: 0x005BC4D0 +void CGCalendar::ContextMenuInviteRemove(CalendarDayEvent* event) { + if (!event || CGCalendar::m_actionPending) { + return; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + SmartGUID guid; + guid.m_guid = player->m_obj->m_guid.m_guid; + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_REMOVE_INVITE)); + msg << guid; + msg.Put(event->m_inviteID); + msg.Put(static_cast(0)); + msg.Put(event->m_eventID); + msg.Finalize(); + ClientServices::Send2(&msg); + CGCalendar::m_actionPending = 1; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_ACTION_PENDING, "%b", 1); +} + +// VERIFY: 3bea9afb manual +// OFFSET: 0x005BC5E0 +void CGCalendar::ContextMenuEventSignUp(CalendarDayEvent* event, uint8_t tentative) { + if (!event || CGCalendar::m_actionPending || ((event->m_type & 0x400) && event->m_inviteStatus != 7)) { + return; + } + + if (!ClntObjMgrGetActivePlayerObj()) { + return; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_SIGN_UP)); + msg.Put(event->m_eventID); + msg.Put(tentative); + msg.Finalize(); + ClientServices::Send2(&msg); + CGCalendar::m_actionPending = 1; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_ACTION_PENDING, "%b", 1); +} + +// VERIFY: 4ead8e12 manual +// OFFSET: 0x005BC6D0 +void CGCalendar::ContextMenuEventRemove(CalendarDayEvent* event) { + if (!event || CGCalendar::m_actionPending) { + return; + } + + if (!ClntObjMgrGetActivePlayerObj()) { + return; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_REMOVE_EVENT)); + msg.Put(event->m_eventID); + msg.Put(event->m_inviteID); + msg.Put(event->m_type); + msg.Finalize(); + ClientServices::Send2(&msg); + CGCalendar::m_actionPending = 1; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_ACTION_PENDING, "%b", 1); +} + +// VERIFY: aab52edd auto +// OFFSET: 0x005BC7C0 +void CGCalendar::ContextMenuEventCopy(CalendarDayEvent* event) { + if (!event) { + return; + } + + bool allowed = (event->m_type & 0x440) ? CGGuildInfo::CanEditGuildEvent() : (event->m_flags & 0x6) != 0; + + if (!allowed) { + memset(&s_eventClipboard, 0, sizeof(s_eventClipboard)); + CGCalendar::CalendarError("CALENDAR_ERROR_PERMISSIONS", 0); + return; + } + + s_eventClipboard = *event; +} + +// VERIFY: 5a5ef0de auto +// OFFSET: 0x005BC870 +void CGCalendar::ContextMenuEventPaste(int32_t offset, uint32_t day) { + if (CGCalendar::m_actionPending || !s_eventClipboard.m_eventID) { + return; + } + + int32_t month = 0; + int32_t year = 0; + int32_t days = 0; + uint32_t now; + + if ((unk_BD09AC && unk_BD09AC->m_intValue) || (now = OsGetAsyncTimeMs(), !CGCalendar::m_lastEventTime) || now - CGCalendar::m_lastEventTime >= 5000) { + int32_t weekDay; + CGCalendar::GetMonth(offset, &month, &year, &days, &weekDay); + + if (day >= static_cast(days)) { + return; + } + + WowTime date; + WowTime::WowDecodeTime(s_eventClipboard.m_startTime, &date); + date.m_tzHours = 0; + date.m_month = month; + date.m_monthDay = day; + date.m_year = year; + date.AddDays(0, false); + + if (!CGCalendar::ValidateCreateDate(&date)) { + return; + } + + uint32_t time; + WowTime::WowEncodeTime(time, &date); + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_COPY_EVENT)); + msg.Put(s_eventClipboard.m_eventID); + msg.Put(s_eventClipboard.m_inviteID); + msg.Put(time); + msg.Finalize(); + ClientServices::Send2(&msg); + CGCalendar::m_lastEventTime = OsGetAsyncTimeMs(); + CGCalendar::SetActionPending(1); + } else { + CGCalendar::CalendarError("CALENDAR_ERROR_EVENT_THROTTLED", 0); + } +} + +// VERIFY: 38ca5713 manual +// OFFSET: 0x005BC9D0 +bool CGCalendar::CanComplainAboutEvent(CalendarDayEvent* event) { + if (!event) { + return false; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + return player && CGChat::m_complaintsSystemStatus && !(event->m_type & 0x6CC) && event->m_creatorGUID != player->m_obj->m_guid && !FriendList::s_friendList->IsFriend(event->m_creatorGUID); +} + +// VERIFY: 9cab6517 manual +// OFFSET: 0x005BCA50 +void CGCalendar::Complain(CalendarDayEvent* event) { + if (CGCalendar::m_actionPending || !CGCalendar::CanComplainAboutEvent(event)) { + return; + } + + { + CDataStore msg; + + if (FriendList::s_friendList->IsComplained(event->m_creatorGUID)) { + CGCalendar::CalendarError("COMPLAINT_ADDED", 0); + SmartGUID guid; + guid.m_guid = ClntObjMgrGetActivePlayerObj()->m_obj->m_guid.m_guid; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_REMOVE_INVITE)); + msg << guid; + msg.Put(event->m_inviteID); + msg.Put(static_cast(0)); + msg.Put(event->m_eventID); + } else { + FriendList::s_friendList->AddComplained(event->m_creatorGUID); + msg.Put(static_cast(CMSG_CALENDAR_COMPLAIN)); + msg.Put(event->m_creatorGUID.m_guid); + msg.Put(event->m_eventID); + msg.Put(event->m_inviteID); + } + + msg.Finalize(); + ClientServices::Send2(&msg); + } + + CGCalendar::m_actionPending = 1; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_ACTION_PENDING, "%b", 1); +} + +// VERIFY: 46672b96 manual +// OFFSET: 0x005BD850 +bool CGCalendar::HasPendingInvite(uint64_t eventID) { + for (CalendarPendingInvite* invite = s_pendingInvites.Head(); invite; invite = s_pendingInvites.Next(invite)) { + if (invite->m_eventID == eventID) { + return true; + } + } + + return false; +} + +// VERIFY: 5f0f7f59 manual +// OFFSET: 0x005BDDE0 +CALENDAREVENTHASH::~CALENDAREVENTHASH() { + uint32_t count = this->m_events.Count(); + + for (uint32_t i = 0; i < count; i++) { + delete this->m_events.m_data[i]; + } +} + +// VERIFY: ec6c6961 manual +// OFFSET: 0x005BDE60 +void CGCalendar::InvalidatePlayer(WOWGUID guid) { + if (!ClntObjMgrGetActivePlayerObj()) { + return; + } + + for (CALENDAREVENTHASH* entry = s_eventTables.m_tables[0].m_fulllist.Head(); entry; entry = s_eventTables.m_tables[0].Next(entry)) { + for (uint32_t i = 0; i < entry->m_events.Count(); i++) { + if (entry->m_events.m_data[i]->m_creatorGUID == guid) { + CGCalendar::GetCalendar(); + return; + } + } + } +} + +// VERIFY: eded04a1 manual +// OFFSET: 0x005BE590 +void CGCalendar::AddPendingInvite(CalendarDayEvent* event) { + CalendarPendingInvite* invite = s_pendingInvites.NewNode(2, 0, 0); + + if (!invite) { + return; + } + + event->m_flags |= 0x1; + invite->m_eventID = event->m_eventID; + invite->m_inviteID = event->m_inviteID; + invite->m_inviterGuid = event->m_creatorGUID; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_PENDING_INVITES, nullptr); +} + +// VERIFY: 2878db21 manual +// OFFSET: 0x005BE950 +bool CalendarEventTables::Delete(int32_t table, uint32_t date, uint64_t eventID) { + CALENDAREVENTHASH* entry = this->m_tables[table].Ptr(date, HASHKEY_NONE()); + + if (!entry) { + return false; + } + + uint32_t count = entry->m_events.Count(); + + if (!count) { + return false; + } + + uint32_t index = 0; + + while (entry->m_events.m_data[index]->m_eventID != eventID) { + if (++index >= count) { + return false; + } + } + + delete entry->m_events.m_data[index]; + + for (uint32_t i = index; i < count - 1; i++) { + entry->m_events.m_data[i] = entry->m_events.m_data[i + 1]; + } + + entry->m_events.SetCount(count - 1); + return true; +} + +// VERIFY: 7034ef82 manual +// OFFSET: 0x005BEA50 +CalendarDayEvent* CalendarEventTables::GetEvent(int32_t table, uint32_t date, uint64_t eventID) { + CALENDAREVENTHASH* entry = this->m_tables[table].Ptr(date, HASHKEY_NONE()); + + if (!entry) { + return nullptr; + } + + for (uint32_t i = 0; i < entry->m_events.Count(); i++) { + if (entry->m_events.m_data[i]->m_eventID == eventID) { + return entry->m_events.m_data[i]; + } + } + + return nullptr; +} + +// VERIFY: c611b0b3 manual +// OFFSET: 0x005BECD0 +bool CGCalendar::DeletePendingInvite(uint64_t eventID) { + for (CalendarPendingInvite* invite = s_pendingInvites.Head(); invite; invite = s_pendingInvites.Next(invite)) { + if (invite->m_eventID == eventID) { + s_pendingInvites.DeleteNode(invite); + return true; + } + } + + return false; +} + +// VERIFY: daa3164f manual +// OFFSET: 0x005BED20 +void CGCalendar::ProcessGetEvent(CDataStore* msg) { + if (!ClntObjMgrGetActivePlayerObj()) { + return; + } + + if (CGCalendar::m_curEvent) { + delete CGCalendar::m_curEvent; + } + + void* mem = SMemAlloc(sizeof(CGCalendarEvent), __FILE__, __LINE__, 0); + CGCalendar::m_curEvent = mem ? new (mem) CGCalendarEvent() : nullptr; + + if (!CGCalendar::m_curEvent) { + return; + } + + uint8_t sendType; + msg->Get(sendType); + int32_t status = -1; + + if (!CGCalendar::m_curEvent->ProcessGetEvent(msg, &status)) { + return; + } + + uint64_t eventID = CGCalendar::m_curEvent->m_eventID; + + if (!status && CGCalendar::m_curEvent->m_date > g_clientGameTime && !CGCalendar::HasPendingInvite(eventID)) { + CalendarPendingInvite* invite = s_pendingInvites.NewNode(2, 0, 0); + + if (invite) { + invite->m_eventID = eventID; + CalendarDayEvent* event = s_eventTables.GetEvent((CGCalendar::m_curEvent->m_flags & 0x440) != 0, EncodeDate(CGCalendar::m_curEvent->m_date.m_month, CGCalendar::m_curEvent->m_date.m_monthDay, CGCalendar::m_curEvent->m_date.m_year), eventID); + + if (event) { + event->m_flags |= 0x1; + invite->m_inviterGuid = event->m_creatorGUID; + } + + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_PENDING_INVITES, nullptr); + } + } + + if (sendType == 1 || sendType == 2) { + if (CGCalendar::m_curEvent->m_pendingNames) { + CGCalendar::m_curEvent->SetSignalType(sendType == 1 ? 2 : 3); + } else { + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_NEW_EVENT, "%b", sendType == 2); + } + + return; + } + + CGCalendar::m_selectedEvent.m_startTime = 0; + CGCalendar::m_selectedEvent.m_endTime = 0; + CGCalendar::m_selectedEvent.m_holidayID = 0; + CGCalendar::m_selectedEvent.unk_0014 = 0; + CGCalendar::m_selectedEvent.m_eventID = eventID; + WowTime::WowEncodeTime(CGCalendar::m_selectedEvent.m_startTime, &CGCalendar::m_curEvent->m_date); + + if (CGCalendar::m_curEvent->m_pendingNames) { + CGCalendar::m_curEvent->SetSignalType(4); + } else { + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_OPEN_EVENT, "%s", CGCalendar::GetCalendarTypeString(CGCalendar::m_curEvent->m_flags)); + } +} + +// VERIFY: aa310072 manual +// OFFSET: 0x005BF030 +void CGCalendar::ProcessInvite(CDataStore* msg, uint8_t* clearPending) { + uint32_t responseTime = 0; + SmartGUID guid; + *msg >> guid; + uint64_t eventID; + msg->Get(eventID); + uint64_t inviteID; + msg->Get(inviteID); + uint8_t level; + msg->Get(level); + uint8_t status; + msg->Get(status); + uint8_t inviteType; + msg->Get(inviteType); + + if (inviteType == 1) { + msg->Get(responseTime); + } + + uint8_t clear; + msg->Get(clear); + + if (!clear) { + *clearPending = 0; + } + + if (inviteType == 1) { + if (CGCalendar::m_curEvent && eventID == CGCalendar::m_curEvent->m_eventID) { + CalendarDayEvent* event = s_eventTables.GetEvent((CGCalendar::m_curEvent->m_flags & 0x440) != 0, EncodeDate(CGCalendar::m_curEvent->m_date.m_month, CGCalendar::m_curEvent->m_date.m_monthDay, CGCalendar::m_curEvent->m_date.m_year), eventID); + + if (event) { + event->m_inviteID = inviteID; + event->m_inviteStatus = status; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_EVENT_LIST, nullptr); + } + } else { + for (CALENDAREVENTHASH* entry = s_eventTables.m_tables[1].m_fulllist.Head(); entry; entry = s_eventTables.m_tables[1].Next(entry)) { + for (uint32_t i = 0; i < entry->m_events.Count(); i++) { + if (entry->m_events.m_data[i]->m_eventID == eventID) { + entry->m_events.m_data[i]->m_inviteID = inviteID; + entry->m_events.m_data[i]->m_inviteStatus = status; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_EVENT_LIST, nullptr); + return; + } + } + } + } + } + + if (CGCalendar::m_curEvent && eventID == CGCalendar::m_curEvent->m_eventID) { + CGCalendar::m_curEvent->AddInvite(inviteID, guid, level, status, inviteType, responseTime); + } +} + +// VERIFY: fd09c36e manual +// OFFSET: 0x005BF250 +void CGCalendar::ProcessInviteRemoved(CDataStore* msg, uint8_t* clearPending) { + SmartGUID guid; + *msg >> guid; + uint64_t eventID; + msg->Get(eventID); + uint32_t flags; + msg->Get(flags); + uint8_t clear; + msg->Get(clear); + + if (!clear) { + *clearPending = 0; + } + + if (flags & 0x400) { + if (CGCalendar::m_curEvent && eventID == CGCalendar::m_curEvent->m_eventID) { + CalendarDayEvent* event = s_eventTables.GetEvent((CGCalendar::m_curEvent->m_flags & 0x440) != 0, EncodeDate(CGCalendar::m_curEvent->m_date.m_month, CGCalendar::m_curEvent->m_date.m_monthDay, CGCalendar::m_curEvent->m_date.m_year), eventID); + + if (event) { + event->m_inviteID = 0; + event->m_inviteStatus = 7; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_EVENT_LIST, nullptr); + } + } else { + for (CALENDAREVENTHASH* entry = s_eventTables.m_tables[1].m_fulllist.Head(); entry; entry = s_eventTables.m_tables[1].Next(entry)) { + for (uint32_t i = 0; i < entry->m_events.Count(); i++) { + if (entry->m_events.m_data[i]->m_eventID == eventID) { + entry->m_events.m_data[i]->m_inviteID = 0; + entry->m_events.m_data[i]->m_inviteStatus = 7; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_EVENT_LIST, nullptr); + return; + } + } + } + } + } + + if (CGCalendar::m_curEvent && CGCalendar::m_curEvent->m_eventID == eventID) { + CGCalendar::m_curEvent->InviteRemoved(guid); + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, nullptr); + } +} + +// VERIFY: d7b01422 manual +// OFFSET: 0x005BF420 +void CGCalendar::ProcessInviteStatus(CDataStore* msg, uint8_t* clearPending) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + msg->m_read = msg->m_size; + return; + } + + SmartGUID guid; + *msg >> guid; + uint64_t eventID; + msg->Get(eventID); + uint32_t date; + msg->Get(date); + uint32_t flags; + msg->Get(flags); + uint8_t status; + msg->Get(status); + uint8_t clear; + msg->Get(clear); + uint32_t responseTime; + msg->Get(responseTime); + + if (!clear) { + *clearPending = 0; + } + + CalendarDayEvent* event = s_eventTables.GetEvent((flags & 0x440) != 0, CGCalendar::GetDateKey(date), eventID); + + if (!event) { + return; + } + + if (guid == player->m_obj->m_guid) { + event->m_inviteStatus = status; + + if (status) { + if (CGCalendar::DeletePendingInvite(eventID)) { + event->m_flags &= ~0x1; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_PENDING_INVITES, nullptr); + } + } else { + CGCalendar::AddPendingInvite(event); + } + + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_EVENT_LIST, nullptr); + } + + if (CGCalendar::m_curEvent && eventID == CGCalendar::m_curEvent->m_eventID) { + CGCalendar::m_curEvent->UpdateInviteStatus(guid, status, responseTime); + } +} + +// VERIFY: dd6e1abd manual +// OFFSET: 0x005BF590 +void CGCalendar::ProcessInviteStatusAlert(CDataStore* msg) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + msg->m_read = msg->m_size; + return; + } + + uint64_t eventID; + msg->Get(eventID); + uint32_t date; + msg->Get(date); + uint32_t flags; + msg->Get(flags); + uint8_t status; + msg->Get(status); + + CalendarDayEvent* event = s_eventTables.GetEvent((flags & 0x440) != 0, CGCalendar::GetDateKey(date), eventID); + + if (!event) { + if (!CGCalendar::m_calendarReceived) { + CGCalendar::QueryPendingInvites(); + } + + return; + } + + event->m_inviteStatus = status; + + if (!(event->m_type & 0x10)) { + if (status) { + if (CGCalendar::DeletePendingInvite(eventID)) { + event->m_flags &= ~0x1; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_PENDING_INVITES, nullptr); + } + } else if (s_pendingInvites.NewNode(2, 0, 0)) { + CGCalendar::AddPendingInvite(event); + } + } + + if (CGCalendar::m_curEvent && CGCalendar::m_curEvent->m_eventID == eventID) { + CGCalendar::m_curEvent->UpdateInviteStatus(player->m_obj->m_guid, status, 0); + } + + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_EVENT_LIST, nullptr); +} + +// VERIFY: 10b40153 manual +// OFFSET: 0x005BF6F0 +void CGCalendar::SetInviteFlag(uint64_t eventID, uint32_t flag, bool set) { + CalendarDayEvent* event = nullptr; + + if (CGCalendar::m_curEvent && eventID == CGCalendar::m_curEvent->m_eventID) { + uint32_t flags = CGCalendar::m_curEvent->m_flags; + WowTime date; + date.m_month = CGCalendar::m_curEvent->m_date.m_month; + date.m_monthDay = CGCalendar::m_curEvent->m_date.m_monthDay; + date.m_year = CGCalendar::m_curEvent->m_date.m_year; + uint32_t key; + WowTime::WowEncodeTime(key, &date); + event = s_eventTables.GetEvent((flags & 0x440) != 0, key, eventID); + } else { + for (CALENDAREVENTHASH* entry = s_eventTables.m_tables[0].m_fulllist.Head(); entry && !event; entry = s_eventTables.m_tables[0].Next(entry)) { + for (uint32_t i = 0; i < entry->m_events.Count(); i++) { + if (entry->m_events.m_data[i]->m_eventID == eventID) { + event = entry->m_events.m_data[i]; + break; + } + } + } + } + + if (!event) { + return; + } + + if (set) { + event->m_flags |= flag; + } else { + event->m_flags &= ~flag; + } +} + +// VERIFY: f9d8441a auto +// OFFSET: 0x005BFA90 +DYNAMICHOLIDAYHASH* CalendarGetHolidayInfo(int32_t holidayId) { + return s_dynamicHolidays.Ptr(holidayId, HASHKEY_NONE()); +} + +// VERIFY: ebd51fc1 manual +// OFFSET: 0x005C07E0 +void CGCalendar::ProcessLockoutRemoved(CDataStore* msg) { + int32_t mapID = -1; + int32_t difficulty = 0; + int32_t resetTime = 0; + uint64_t instanceID = 0; + msg->Get(reinterpret_cast(mapID)); + + if (mapID < 0) { + for (CALENDAREVENTHASH* entry = s_eventTables.m_tables[2].m_fulllist.Head(); entry; entry = s_eventTables.m_tables[2].Next(entry)) { + uint32_t count = entry->m_events.Count(); + + if (!count) { + continue; + } + + CalendarDayEvent** keep = static_cast(alloca(count * sizeof(CalendarDayEvent*))); + uint32_t kept = 0; + + for (uint32_t i = 0; i < count; i++) { + CalendarDayEvent* event = entry->m_events.m_data[i]; + + if (event->m_type & 0x80) { + delete event; + } else { + keep[kept++] = event; + } + } + + if (kept < count) { + for (uint32_t i = 0; i < kept; i++) { + entry->m_events.m_data[i] = keep[i]; + } + + entry->m_events.SetCount(kept); + } + } + } else { + msg->Get(reinterpret_cast(difficulty)); + msg->Get(reinterpret_cast(resetTime)); + msg->Get(instanceID); + WowTime reset = g_clientGameTime; + reset.m_tzHours = g_clientGameTime.m_tzHours; + reset.AddMinutes(resetTime / 60); + WowTime key; + key.m_month = reset.m_month; + key.m_monthDay = reset.m_monthDay; + key.m_year = reset.m_year; + uint32_t hash; + WowTime::WowEncodeTime(hash, &key); + CALENDAREVENTHASH* entry = s_eventTables.m_tables[2].Ptr(hash, HASHKEY_NONE()); + + if (entry) { + uint32_t count = entry->m_events.Count(); + + if (count) { + CalendarDayEvent** keep = static_cast(alloca(count * sizeof(CalendarDayEvent*))); + uint32_t kept = 0; + + for (uint32_t i = 0; i < count; i++) { + CalendarDayEvent* event = entry->m_events.m_data[i]; + + if ((event->m_type & 0x80) && event->m_holidayID == static_cast(mapID) && (difficulty == -1 || event->m_endTime == static_cast(difficulty)) && (instanceID == ~0ull || event->m_eventID == instanceID)) { + delete event; + } else { + keep[kept++] = event; + } + } + + if (kept < count) { + for (uint32_t i = 0; i < kept; i++) { + entry->m_events.m_data[i] = keep[i]; + } + + entry->m_events.SetCount(kept); + } + } + } + } + + CGCalendar::UpdateDisplayList(true); +} + +// VERIFY: 5cf06944 manual +// OFFSET: 0x005C0AE0 +void CGCalendar::ProcessInviteRemovedAlert(CDataStore* msg) { + uint64_t eventID; + msg->Get(eventID); + uint32_t date; + msg->Get(date); + uint32_t flags; + msg->Get(flags); + uint8_t status; + msg->Get(status); + + bool remove = true; + uint32_t key = CGCalendar::GetDateKey(date); + CalendarDayEvent* event = s_eventTables.GetEvent((flags & 0x440) != 0, key, eventID); + + if (event && (event->m_type & 0x400) && (event->m_flags & 0x8)) { + event->m_inviteStatus = 7; + + if (CGCalendar::m_curEvent && CGCalendar::m_curEvent->m_eventID == eventID) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player) { + CGCalendar::m_curEvent->InviteRemoved(player->m_obj->m_guid); + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, nullptr); + } + } + + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_EVENT_LIST, nullptr); + remove = false; + } else { + if (CGCalendar::m_selectedEvent.m_eventID == eventID) { + CGCalendar::m_selectedEvent.m_eventID = 0; + CGCalendar::m_selectedEvent.m_startTime = 0; + CGCalendar::m_selectedEvent.m_endTime = 0; + CGCalendar::m_selectedEvent.m_holidayID = 0; + CGCalendar::m_selectedEvent.unk_0014 = 0; + } + + if (CGCalendar::m_curEvent && CGCalendar::m_curEvent->m_eventID == eventID) { + delete CGCalendar::m_curEvent; + CGCalendar::m_curEvent = nullptr; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_CLOSE_EVENT, nullptr); + } + + if (CGCalendar::m_contextEvent.m_eventID == eventID) { + CGCalendar::m_contextEvent.m_eventID = 0; + CGCalendar::m_contextEvent.m_startTime = 0; + CGCalendar::m_contextEvent.m_endTime = 0; + CGCalendar::m_contextEvent.m_holidayID = 0; + CGCalendar::m_contextEvent.unk_0014 = 0; + CGCalendar::m_contextEventInfo = nullptr; + } + } + + if (status && status != 9) { + CGMailInfo::ReceivedMail(0.0f); + } + + CGCalendar::DeletePendingInvite(eventID); + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_PENDING_INVITES, nullptr); + + if (remove && s_eventTables.Delete((flags & 0x440) != 0, key, eventID)) { + CGCalendar::UpdateDisplayList(true); + } +} + +// VERIFY: 6eb2e64f manual +// OFFSET: 0x005C0CF0 +void CGCalendar::ProcessEventRemovedAlert(CDataStore* msg, uint8_t* clearPending) { + uint8_t clear; + msg->Get(clear); + + if (!clear) { + *clearPending = 0; + } + + uint64_t eventID; + msg->Get(eventID); + uint32_t date; + msg->Get(date); + + if (CGCalendar::m_selectedEvent.m_eventID == eventID) { + CGCalendar::m_selectedEvent.m_eventID = 0; + CGCalendar::m_selectedEvent.m_startTime = 0; + CGCalendar::m_selectedEvent.m_endTime = 0; + CGCalendar::m_selectedEvent.m_holidayID = 0; + CGCalendar::m_selectedEvent.unk_0014 = 0; + } + + if (CGCalendar::m_curEvent && eventID == CGCalendar::m_curEvent->m_eventID) { + delete CGCalendar::m_curEvent; + CGCalendar::m_curEvent = nullptr; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_CLOSE_EVENT, nullptr); + } + + if (CGCalendar::m_contextEvent.m_eventID == eventID) { + CGCalendar::m_contextEvent.m_eventID = 0; + CGCalendar::m_contextEvent.m_startTime = 0; + CGCalendar::m_contextEvent.m_endTime = 0; + CGCalendar::m_contextEvent.m_holidayID = 0; + CGCalendar::m_contextEvent.unk_0014 = 0; + CGCalendar::m_contextEventInfo = nullptr; + } + + if (s_eventClipboard.m_eventID == eventID) { + memset(&s_eventClipboard, 0, sizeof(s_eventClipboard)); + } + + uint32_t key = CGCalendar::GetDateKey(date); + int32_t table = 0; + + while (!s_eventTables.Delete(table, key, eventID)) { + if (++table > 1) { + return; + } + } + + CGCalendar::DeletePendingInvite(eventID); + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_PENDING_INVITES, nullptr); + CGCalendar::UpdateDisplayList(true); +} + +// VERIFY: 4f00ed9f manual +// OFFSET: 0x005C0E70 +void CGCalendar::ProcessInviteModeratorStatusAlert(CDataStore* msg, uint8_t* clearPending) { + SmartGUID guid; + *msg >> guid; + uint64_t eventID; + msg->Get(eventID); + uint8_t status; + msg->Get(status); + uint8_t clear; + msg->Get(clear); + + if (!clear) { + *clearPending = 0; + } + + if (CGCalendar::m_curEvent && eventID == CGCalendar::m_curEvent->m_eventID) { + CGCalendar::m_curEvent->UpdateInviteModeratorStatus(guid, status); + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && player->m_obj->m_guid == guid) { + CGCalendar::SetInviteFlag(eventID, 0x2, status == 1); + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_EVENT_LIST, nullptr); + } +} + +// VERIFY: b5246e45 manual +// OFFSET: 0x005C0F40 +void CGCalendar::GuildChanged() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + if (player->m_player->m_playerGuildid) { + CGCalendar::GetCalendar(); + return; + } + + s_eventTables.m_counts[1] = 0; + s_eventTables.m_tables[1].InternalClear(0); + + if (s_eventClipboard.m_type & 0x440) { + memset(&s_eventClipboard, 0, sizeof(s_eventClipboard)); + } + + CGCalendar::UpdateDisplayList(true); +} + +// VERIFY: cdc89b97 manual +// OFFSET: 0x005C2350 +void CGCalendar::InsertLockoutEvent(int32_t mapID, int32_t difficulty, uint64_t instanceID, uint32_t time) { + void* mem = SMemAlloc(sizeof(CalendarDayEvent), __FILE__, __LINE__, 0); + CalendarDayEvent* event = mem ? new (mem) CalendarDayEvent() : nullptr; + event->m_holidayID = mapID; + event->m_endTime = difficulty; + event->m_eventID = instanceID; + event->m_title[0] = '\0'; + event->m_startTime = time; + event->m_type = 0x80; + CGCalendar::InsertEvent(event, 2); +} + +// VERIFY: c522fef8 manual +// OFFSET: 0x005C29C0 +void PH_SMSG_CALENDAR_SEND_CALENDAR(CDataStore* msg) { + CGCalendar::m_numInitialPending = 0; + s_pendingInvites.Clear(); + + uint32_t numInvites; + msg->Get(numInvites); + + for (uint32_t i = 0; i < numInvites; i++) { + uint64_t eventID; + msg->Get(eventID); + uint64_t inviteID; + msg->Get(inviteID); + uint8_t status; + msg->Get(status); + uint8_t rank; + msg->Get(rank); + uint8_t inviteType; + msg->Get(inviteType); + SmartGUID inviter; + *msg >> inviter; + + CalendarPendingInvite* invite = s_pendingInvites.NewNode(2, 0, 0); + + if (invite) { + invite->m_eventID = eventID; + invite->m_inviteID = inviteID; + invite->m_inviterGuid = inviter; + invite->m_status = status; + invite->m_rank = rank; + invite->m_inviteType = inviteType; + invite->m_valid = 0; + } + } + + s_eventTables.m_counts[0] = 0; + s_eventTables.m_tables[0].InternalClear(0); + s_eventTables.m_counts[1] = 0; + s_eventTables.m_tables[1].InternalClear(0); + + WOWGUID activePlayer = ClntObjMgrGetActivePlayer(); + uint32_t numEvents; + msg->Get(numEvents); + + for (uint32_t i = 0; i < numEvents; i++) { + CalendarDayEvent event; + msg->Get(event.m_eventID); + msg->GetString(event.m_title, sizeof(event.m_title)); + msg->Get(reinterpret_cast(event.m_eventType)); + msg->Get(event.m_startTime); + event.m_endTime = 0; + msg->Get(event.m_type); + msg->Get(reinterpret_cast(event.m_textureID)); + SmartGUID creator; + *msg >> creator; + event.m_flags = (activePlayer && creator == activePlayer) ? 0x4 : 0; + event.m_inviteID = 0; + event.m_creatorGUID = WOWGUID(); + + if (event.m_type & 0x40) { + void* mem = SMemAlloc(sizeof(CalendarDayEvent), __FILE__, __LINE__, 0); + CalendarDayEvent* copy = mem ? new (mem) CalendarDayEvent() : nullptr; + static_cast(*copy) = event; + WowTime alarm; + WowTime::WowDecodeTime(copy->m_startTime, &alarm); + alarm.m_tzHours = 0; + alarm.AddMinutes(-15); + WowTime::WowEncodeTime(copy->m_alarmTime, &alarm); + copy->m_alarmCallback = g_clientGameTime.GameTimeRegisterCallback(&alarm, FireEventAlarm, copy); + copy->m_creatorGUID = creator; + CGCalendar::InsertEvent(copy, (event.m_type & 0x440) != 0); + continue; + } + + CalendarPendingInvite* invite = s_pendingInvites.Head(); + + while (invite && invite->m_eventID != event.m_eventID) { + invite = s_pendingInvites.Next(invite); + } + + if (invite) { + event.m_inviteStatus = invite->m_status; + event.m_inviteID = invite->m_inviteID; + + if (invite->m_rank) { + event.m_flags |= 0x2; + + if (invite->m_rank == 2) { + event.m_flags |= 0x4; + } + } + + if (invite->m_inviteType == 1) { + event.m_flags |= 0x8; + event.m_creatorGUID = creator; + } else { + event.m_creatorGUID = invite->m_inviterGuid; + } + + WowTime start; + WowTime::WowDecodeTime(event.m_startTime, &start); + start.m_tzHours = 0; + + if (!invite->m_status && start > g_clientGameTime && !(event.m_type & 0x10)) { + event.m_flags |= 0x1; + invite->m_valid = 1; + } else { + s_pendingInvites.DeleteNode(invite); + numInvites--; + } + } else { + if (!(event.m_type & 0x400)) { + continue; + } + + event.m_flags |= 0x8; + event.m_creatorGUID = creator; + event.m_inviteStatus = 7; + } + + void* mem = SMemAlloc(sizeof(CalendarDayEvent), __FILE__, __LINE__, 0); + CalendarDayEvent* copy = mem ? new (mem) CalendarDayEvent() : nullptr; + static_cast(*copy) = event; + WowTime alarm; + WowTime::WowDecodeTime(copy->m_startTime, &alarm); + alarm.m_tzHours = 0; + alarm.AddMinutes(-15); + WowTime::WowEncodeTime(copy->m_alarmTime, &alarm); + copy->m_alarmCallback = g_clientGameTime.GameTimeRegisterCallback(&alarm, FireEventAlarm, copy); + CGCalendar::InsertEvent(copy, (event.m_type & 0x440) != 0); + WOWGUID none = WOWGUID(); + g_nameDBCache.GetRecord(event.m_creatorGUID.m_guid, none, nullptr, nullptr, false); + } + + CalendarPendingInvite* invite = s_pendingInvites.Head(); + + while (invite) { + CalendarPendingInvite* next = s_pendingInvites.Next(invite); + + if (!invite->m_valid || !invite->m_inviterGuid) { + s_pendingInvites.DeleteNode(invite); + numInvites--; + } else if (FriendList::s_friendList->IsIgnored(invite->m_inviterGuid, false)) { + numInvites--; + } + + invite = next; + } + + WowTime serverTime; + uint32_t serverNow = 0; + msg->Get(serverNow); + uint32_t serverDate; + msg->Get(serverDate); + WowTime::WowDecodeTime(serverDate, &serverTime); + + s_eventTables.m_counts[2] = 0; + s_eventTables.m_tables[2].InternalClear(0); + + uint32_t numLockouts; + msg->Get(numLockouts); + + for (uint32_t i = 0; i < numLockouts; i++) { + int32_t mapID; + msg->Get(reinterpret_cast(mapID)); + int32_t difficulty; + msg->Get(reinterpret_cast(difficulty)); + int32_t resetTime; + msg->Get(reinterpret_cast(resetTime)); + uint64_t instanceID; + msg->Get(instanceID); + WowTime reset = serverTime; + reset.m_tzHours = serverTime.m_tzHours; + reset.AddMinutes(resetTime / 60); + uint32_t time; + WowTime::WowEncodeTime(time, &reset); + CGCalendar::InsertLockoutEvent(mapID, difficulty, instanceID, time); + } + + uint32_t baseTime = 0; + msg->Get(baseTime); + s_raidResets.Clear(); + uint32_t numResets; + msg->Get(numResets); + + for (uint32_t i = 0; i < numResets; i++) { + int32_t mapID; + msg->Get(reinterpret_cast(mapID)); + uint32_t period; + msg->Get(period); + uint32_t offset; + msg->Get(offset); + + CALENDARRAIDRESETNODE* node = s_raidResets.NewNode(2, 0, 0); + + if (node) { + WowTime reset = serverTime; + reset.m_tzHours = serverTime.m_tzHours; + uint32_t start = baseTime + offset; + uint32_t periods = static_cast(static_cast(serverNow - start) / static_cast(period)); + reset.AddMinutes(static_cast(start + periods * period - serverNow) / 60); + uint32_t time; + WowTime::WowEncodeTime(time, &reset); + node->m_mapID = mapID; + node->m_interval = period / 60; + node->m_startTime = time; + } + } + + uint32_t numHolidays; + msg->Get(numHolidays); + + if (numHolidays) { + s_dynamicHolidays.InternalClear(0); + s_holidays.Clear(); + + for (uint32_t i = 0; i < numHolidays; i++) { + uint32_t id; + msg->Get(id); + int32_t region; + msg->Get(reinterpret_cast(region)); + int32_t looping; + msg->Get(reinterpret_cast(looping)); + int32_t priority; + msg->Get(reinterpret_cast(priority)); + int32_t filterType; + msg->Get(reinterpret_cast(filterType)); + + int32_t dates[26]; + + for (uint32_t j = 0; j < 26; j++) { + msg->Get(reinterpret_cast(dates[j])); + } + + int32_t durations[10]; + + for (uint32_t j = 0; j < 10; j++) { + msg->Get(reinterpret_cast(durations[j])); + } + + int32_t flags[10]; + + for (uint32_t j = 0; j < 10; j++) { + msg->Get(reinterpret_cast(flags[j])); + } + + char textureFileName[64]; + msg->GetString(textureFileName, sizeof(textureFileName)); + + DYNAMICHOLIDAYHASH* holiday = s_dynamicHolidays.New(id, HASHKEY_NONE(), 0, 0); + holiday->m_region = region; + holiday->m_looping = looping; + holiday->m_priority = priority; + holiday->m_calendarFilterType = filterType; + + for (uint32_t j = 0; j < 26; j++) { + holiday->m_date[j] = dates[j]; + } + + for (uint32_t j = 0; j < 10; j++) { + holiday->m_duration[j] = durations[j]; + } + + for (uint32_t j = 0; j < 10; j++) { + holiday->m_calendarFlags[j] = flags[j]; + } + + SStrCopy(holiday->m_textureFileName, textureFileName, sizeof(holiday->m_textureFileName)); + } + } + + CGCalendar::CalculateEvents(true); + + if (numInvites) { + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_PENDING_INVITES, nullptr); + } + + CGCalendar::m_calendarReceived = 1; +} + +// VERIFY: b0bed908 auto +// OFFSET: 0x005C37D0 +void CGCalendar::ProcessLockoutAdded(CDataStore* msg) { + WowTime date; + uint32_t time; + msg->Get(time); + WowTime::WowDecodeTime(time, &date); + int32_t mapID; + msg->Get(reinterpret_cast(mapID)); + int32_t difficulty; + msg->Get(reinterpret_cast(difficulty)); + int32_t resetTime; + msg->Get(reinterpret_cast(resetTime)); + uint64_t instanceID; + msg->Get(instanceID); + date.AddMinutes(resetTime / 60); + WowTime::WowEncodeTime(time, &date); + CGCalendar::InsertLockoutEvent(mapID, difficulty, instanceID, time); + CGCalendar::UpdateDisplayList(true); +} + +// VERIFY: fa479f46 manual +// OFFSET: 0x005C3880 +void CGCalendar::ProcessLockoutUpdated(CDataStore* msg) { + int32_t mapID = -1; + int32_t difficulty = 0; + int32_t oldReset = 0; + int32_t newReset = 0; + WowTime oldDate; + uint32_t time; + msg->Get(time); + WowTime::WowDecodeTime(time, &oldDate); + WowTime newDate = oldDate; + newDate.m_tzHours = oldDate.m_tzHours; + msg->Get(reinterpret_cast(mapID)); + msg->Get(reinterpret_cast(difficulty)); + msg->Get(reinterpret_cast(oldReset)); + msg->Get(reinterpret_cast(newReset)); + oldDate.AddMinutes(oldReset / 60); + newDate.AddMinutes(newReset / 60); + + WowTime key; + key.m_month = oldDate.m_month; + key.m_monthDay = oldDate.m_monthDay; + key.m_year = oldDate.m_year; + uint32_t hash; + WowTime::WowEncodeTime(hash, &key); + CALENDAREVENTHASH* entry = s_eventTables.m_tables[2].Ptr(hash, HASHKEY_NONE()); + + if (entry) { + uint32_t count = entry->m_events.Count(); + + if (count) { + CalendarDayEvent** keep = static_cast(alloca(count * sizeof(CalendarDayEvent*))); + uint32_t kept = 0; + + for (uint32_t i = 0; i < count; i++) { + CalendarDayEvent* event = entry->m_events.m_data[i]; + + if ((event->m_type & 0x80) && event->m_holidayID == static_cast(mapID) && event->m_endTime == static_cast(difficulty) && EncodeDate(newDate.m_month, newDate.m_monthDay, newDate.m_year) != hash) { + WowTime::WowEncodeTime(time, &newDate); + event->m_startTime = time; + CGCalendar::InsertEvent(event, 2); + } else { + keep[kept++] = event; + } + } + + if (kept < count) { + for (uint32_t i = 0; i < kept; i++) { + entry->m_events.m_data[i] = keep[i]; + } + + entry->m_events.SetCount(kept); + } + } + } + + CGCalendar::UpdateDisplayList(true); +} + +// VERIFY: 266adeae manual +// OFFSET: 0x005C3AB0 +void CGCalendar::ProcessInviteAlert(CDataStore* msg) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + void* mem = SMemAlloc(sizeof(CalendarDayEvent), __FILE__, __LINE__, 0); + CalendarDayEvent* event = mem ? new (mem) CalendarDayEvent() : nullptr; + event->m_flags = 0; + msg->Get(event->m_eventID); + msg->GetString(event->m_title, sizeof(event->m_title)); + msg->Get(event->m_startTime); + event->m_endTime = 0; + msg->Get(event->m_type); + msg->Get(reinterpret_cast(event->m_eventType)); + msg->Get(reinterpret_cast(event->m_textureID)); + msg->Get(event->m_inviteID); + msg->Get(event->m_inviteStatus); + uint8_t rank; + msg->Get(rank); + SmartGUID creator; + *msg >> creator; + SmartGUID inviter; + *msg >> inviter; + event->ScheduleAlarm(); + + bool pending = false; + + if (event->m_inviteStatus == 7 || event->m_inviteStatus == 6) { + event->m_creatorGUID = creator; + event->m_flags = 0x8; + } else { + event->m_creatorGUID = inviter; + + if (!event->m_inviteStatus && !(event->m_type & 0x40)) { + pending = true; + event->m_flags = 0x1; + } + } + + if (rank) { + event->m_flags |= 0x2; + } + + if (creator == player->m_obj->m_guid || rank == 2) { + event->m_flags |= 0x4; + } + + CGCalendar::InsertEvent(event, (event->m_type & 0x440) != 0); + + if (pending) { + CalendarPendingInvite* invite = s_pendingInvites.NewNode(2, 0, 0); + + if (invite) { + invite->m_eventID = event->m_eventID; + invite->m_inviterGuid = event->m_creatorGUID; + + if (!FriendList::s_friendList->IsIgnored(event->m_creatorGUID, false)) { + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_PENDING_INVITES, nullptr); + } + } + } + + CGCalendar::UpdateDisplayList(true); +} + +// VERIFY: 00a05b2b manual +// OFFSET: 0x005C3D30 +void CGCalendar::ProcessEventUpdatedAlert(CDataStore* msg, uint8_t* clearPending) { + uint8_t clear; + msg->Get(clear); + + if (!clear) { + *clearPending = 0; + } + + uint64_t eventID; + msg->Get(eventID); + uint32_t oldDate; + msg->Get(oldDate); + uint32_t read = msg->m_read; + uint32_t flags; + msg->Get(flags); + uint32_t newDate; + msg->Get(newDate); + uint8_t eventType; + msg->Get(eventType); + uint32_t textureID; + msg->Get(textureID); + char title[128]; + msg->GetString(title, sizeof(title)); + + int32_t table = (flags & 0x440) != 0; + uint32_t key = CGCalendar::GetDateKey(oldDate); + CalendarDayEvent* event = s_eventTables.GetEvent(table, key, eventID); + + if (event) { + bool locked = (event->m_type & 0x10) != 0; + + if (oldDate != newDate) { + void* mem = SMemAlloc(sizeof(CalendarDayEvent), __FILE__, __LINE__, 0); + CalendarDayEvent* moved = mem ? new (mem) CalendarDayEvent() : nullptr; + moved->m_eventID = eventID; + moved->m_startTime = newDate; + moved->m_endTime = 0; + moved->m_flags = event->m_flags; + moved->m_inviteStatus = event->m_inviteStatus; + moved->m_inviteID = event->m_inviteID; + moved->m_creatorGUID = event->m_creatorGUID; + moved->m_sequenceIndex = event->m_sequenceIndex; + moved->m_sequenceLength = event->m_sequenceLength; + moved->ScheduleAlarm(); + CGCalendar::InsertEvent(moved, table); + s_eventTables.Delete(table, key, eventID); + + if (CGCalendar::m_contextEventInfo == event) { + CGCalendar::m_contextEventInfo = moved; + } + + event = moved; + } + + SStrCopy(event->m_title, title, sizeof(event->m_title)); + event->m_type = flags; + event->m_eventType = eventType; + event->m_textureID = textureID; + + if (locked != ((flags & 0x10) != 0) && !event->m_inviteStatus) { + if (flags & 0x10) { + if (CGCalendar::DeletePendingInvite(eventID)) { + event->m_flags &= ~0x1; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_PENDING_INVITES, nullptr); + } + } else { + CGCalendar::AddPendingInvite(event); + } + } + + CGCalendar::UpdateDisplayList(true); + } else if (!CGCalendar::m_calendarReceived) { + CGCalendar::QueryPendingInvites(); + } + + if (CGCalendar::m_curEvent && eventID == CGCalendar::m_curEvent->m_eventID) { + msg->m_read = read; + + if (CGCalendar::m_curEvent->ProcessUpdateEvent(msg)) { + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_EVENT, nullptr); + } + } else { + msg->m_read = msg->m_size; + } +} diff --git a/WoW/Source/Ui/Calendar.h b/WoW/Source/Ui/Calendar.h index 13c3ed2..a01dbd4 100644 --- a/WoW/Source/Ui/Calendar.h +++ b/WoW/Source/Ui/Calendar.h @@ -8,15 +8,13 @@ class CDataStore; class CGCalendarEvent; +class CGameTime; class WowTime; +struct TIMESTAMPCALLBACK; struct CVar; +struct EventInviteInfo; struct lua_State; -struct CalendarEventClipboard { - /* 0000 */ uint64_t m_eventID; - /* 0008 */ uint8_t unk_0008[200]; -}; - int32_t PH_CALENDAR_GROUP(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); void PH_SMSG_CALENDAR_SEND_CALENDAR(CDataStore* msg); @@ -58,35 +56,39 @@ struct DYNAMICHOLIDAYHASH : public TSHashObject { /* 0018 */ TSGrowableArray m_events; + + ~CALENDAREVENTHASH(); }; -struct CalendarDayEvent { +struct CalendarEventData { /* 0000 */ uint64_t m_eventID; /* 0008 */ char m_title[128]; /* 0088 */ uint32_t m_startTime; - /* 008C */ uint32_t unk_008C; + /* 008C */ uint32_t m_alarmTime; /* 0090 */ uint32_t m_endTime; /* 0094 */ uint32_t m_holidayID; /* 0098 */ uint32_t m_type; /* 009C */ uint32_t m_flags; - /* 00A0 */ int32_t unk_00A0; - /* 00A4 */ uint32_t unk_00A4; - /* 00A8 */ uint8_t unk_00A8; - /* 00AC */ uint32_t unk_00AC; - /* 00B0 */ uint32_t unk_00B0; - /* 00B4 */ uint32_t unk_00B4; + /* 00A0 */ int32_t m_eventType; + /* 00A4 */ int32_t m_textureID; + /* 00A8 */ uint8_t m_inviteStatus; + /* 00B0 */ uint64_t m_inviteID; /* 00B8 */ WOWGUID m_creatorGUID; - /* 00C0 */ uint32_t unk_00C0; + /* 00C0 */ TIMESTAMPCALLBACK* m_alarmCallback; /* 00C4 */ uint32_t m_sequenceIndex; /* 00C8 */ uint32_t m_sequenceLength; - /* 00CC */ uint32_t unk_00CC; +}; +struct CalendarDayEvent : public CalendarEventData { CalendarDayEvent(); + ~CalendarDayEvent(); int32_t GetSequenceType() const; + void ScheduleAlarm(); }; struct CalendarEventSelection { @@ -103,13 +105,27 @@ class CalendarEventTables { /* 0140 */ int32_t m_counts[8]; void Clear(); + bool Delete(int32_t table, uint32_t date, uint64_t eventID); + CalendarDayEvent* GetEvent(int32_t table, uint32_t date, uint64_t eventID); }; struct CalendarPendingInvite : public TSLinkedNode { - /* 0008 */ uint8_t unk_0008[16]; + /* 0008 */ uint64_t m_eventID; + /* 0010 */ uint64_t m_inviteID; /* 0018 */ WOWGUID m_inviterGuid; + /* 0020 */ uint8_t m_status; + /* 0021 */ uint8_t m_rank; + /* 0022 */ uint8_t m_inviteType; + /* 0023 */ uint8_t m_valid; + + CalendarPendingInvite(); }; +// INLINED +inline CalendarPendingInvite::CalendarPendingInvite() { + this->m_eventID = 0; +} + class CGCalendar { public: static void GuildChanged(); @@ -121,7 +137,9 @@ class CGCalendar { static CGCalendarEvent* m_curEvent; static uint8_t m_initialize; static uint8_t m_openedCalendar; - static uint8_t unk_C207F2; + static uint8_t m_calendarReceived; + static CalendarDayEvent* m_contextEventInfo; + static uint32_t m_lastEventTime; static int32_t m_numInitialPending; static void EnterWorld(); @@ -163,91 +181,64 @@ class CGCalendar { static int32_t GetNumDayEvents(uint32_t offset, uint32_t day); static int32_t GetFirstPendingInviteIndex(uint32_t offset, uint32_t day); static void InsertEvent(CalendarDayEvent* event, int32_t table); + static bool ValidateCreateDate(const WowTime* date); + static bool CanEditCurrentEvent(); + static void SetInviteStatus(uint32_t index, uint32_t status); + static void SetModeratorStatus(uint32_t index, uint32_t status); + static void SetActionPending(uint8_t pending); + static const char* GetCalendarTypeString(uint32_t flags); + static uint32_t GetDateKey(uint32_t time); + static CalendarDayEvent* GetDayEvent(uint32_t offset, uint32_t day, uint32_t index); + static void GetEvent(uint32_t offset, uint32_t day, uint32_t index); + static bool SetEventDate(uint32_t month, uint32_t monthDay, uint32_t year); + static bool SetEventTime(uint32_t hour, uint32_t minute); + static bool SetEventLockoutDate(uint32_t month, uint32_t monthDay, uint32_t year); + static bool SetEventLockoutTime(uint32_t hour, uint32_t minute); + static void SetEventTextureID(uint32_t index); + static void RemoveEvent(); + static int32_t GetTextureIndex(uint32_t type, int32_t textureID); + static EventInviteInfo* GetCurrentEventInvite(WOWGUID guid); + static void RemoveInvite(uint32_t index); + static void SelectContextEvent(uint32_t offset, uint32_t day, uint32_t index); + static void ContextMenuInviteRSVP(CalendarDayEvent* event, uint32_t status); + static void GetCalendar(); + static void AddEvent(); + static void CreatePlayerEvent(); + static void CreateGuildAnnouncement(); + static void CreateGuildEvent(); + static void GuildFilter(uint32_t minLevel, uint32_t maxLevel, uint32_t minRank); + static void ArenaTeam(uint32_t index); + static void UpdateEvent(); + static void Invite(const char* name); + static void InviteRSVP(uint32_t status); + static void EventSignUp(); + static void ContextMenuInviteRemove(CalendarDayEvent* event); + static void ContextMenuEventSignUp(CalendarDayEvent* event, uint8_t tentative); + static void ContextMenuEventRemove(CalendarDayEvent* event); + static void ContextMenuEventCopy(CalendarDayEvent* event); + static void ContextMenuEventPaste(int32_t offset, uint32_t day); + static bool CanComplainAboutEvent(CalendarDayEvent* event); + static void Complain(CalendarDayEvent* event); + static bool HasPendingInvite(uint64_t eventID); + static void InvalidatePlayer(WOWGUID guid); + static void AddPendingInvite(CalendarDayEvent* event); + static bool DeletePendingInvite(uint64_t eventID); + static void SetInviteFlag(uint64_t eventID, uint32_t flag, bool set); + static void InsertLockoutEvent(int32_t mapID, int32_t difficulty, uint64_t instanceID, uint32_t time); }; -int32_t Script_CalendarGetMaxDate(lua_State* L); -int32_t Script_CalendarGetMinHistoryDate(lua_State* L); -int32_t Script_CalendarGetAbsMonth(lua_State* L); -int32_t Script_CalendarGetDayEvent(lua_State* L); -int32_t Script_CalendarGetDayEventSequenceInfo(lua_State* L); -int32_t Script_CalendarOpenEvent(lua_State* L); -int32_t Script_CalendarGetEventInfo(lua_State* L); -int32_t Script_CalendarGetHolidayInfo(lua_State* L); -int32_t Script_CalendarGetRaidInfo(lua_State* L); -int32_t Script_CalendarEventGetNumInvites(lua_State* L); -int32_t Script_CalendarEventGetInvite(lua_State* L); -int32_t Script_CalendarEventGetInviteResponseTime(lua_State* L); -int32_t Script_CalendarAddEvent(lua_State* L); -int32_t Script_CalendarNewEvent(lua_State* L); -int32_t Script_CalendarMassInviteGuild(lua_State* L); -int32_t Script_CalendarMassInviteArenaTeam(lua_State* L); -int32_t Script_CalendarNewGuildAnnouncement(lua_State* L); -int32_t Script_CalendarNewGuildEvent(lua_State* L); -int32_t Script_CalendarUpdateEvent(lua_State* L); -int32_t Script_CalendarRemoveEvent(lua_State* L); -int32_t Script_CalendarEventSelectInvite(lua_State* L); -int32_t Script_CalendarEventGetSelectedInvite(lua_State* L); -int32_t Script_CalendarContextSelectEvent(lua_State* L); -int32_t Script_CalendarContextDeselectEvent(lua_State* L); -int32_t Script_CalendarContextInviteIsPending(lua_State* L); -int32_t Script_CalendarContextInviteModeratorStatus(lua_State* L); -int32_t Script_CalendarContextInviteStatus(lua_State* L); -int32_t Script_CalendarContextInviteType(lua_State* L); -int32_t Script_CalendarContextInviteAvailable(lua_State* L); -int32_t Script_CalendarContextInviteTentative(lua_State* L); -int32_t Script_CalendarContextInviteDecline(lua_State* L); -int32_t Script_CalendarContextInviteRemove(lua_State* L); -int32_t Script_CalendarContextEventSignUp(lua_State* L); -int32_t Script_CalendarContextEventRemove(lua_State* L); -int32_t Script_CalendarContextEventCopy(lua_State* L); -int32_t Script_CalendarContextEventPaste(lua_State* L); -int32_t Script_CalendarContextEventClipboard(lua_State* L); -int32_t Script_CalendarContextEventCanComplain(lua_State* L); -int32_t Script_CalendarContextEventComplain(lua_State* L); -int32_t Script_CalendarContextEventCanEdit(lua_State* L); -int32_t Script_CalendarContextEventGetCalendarType(lua_State* L); -int32_t Script_CalendarEventInvite(lua_State* L); -int32_t Script_CalendarEventRemoveInvite(lua_State* L); -int32_t Script_CalendarEventAvailable(lua_State* L); -int32_t Script_CalendarEventTentative(lua_State* L); -int32_t Script_CalendarEventDecline(lua_State* L); -int32_t Script_CalendarEventSignUp(lua_State* L); -int32_t Script_CalendarEventSortInvites(lua_State* L); -int32_t Script_CalendarEventGetInviteSortCriterion(lua_State* L); -int32_t Script_CalendarEventGetStatusOptions(lua_State* L); -int32_t Script_CalendarEventSetStatus(lua_State* L); -int32_t Script_CalendarEventSetModerator(lua_State* L); -int32_t Script_CalendarEventClearModerator(lua_State* L); -int32_t Script_CalendarEventCanModerate(lua_State* L); -int32_t Script_CalendarEventIsModerator(lua_State* L); -int32_t Script_CalendarEventSetTitle(lua_State* L); -int32_t Script_CalendarEventSetDescription(lua_State* L); -int32_t Script_CalendarEventSetType(lua_State* L); -int32_t Script_CalendarEventSetRepeatOption(lua_State* L); -int32_t Script_CalendarEventSetSize(lua_State* L); -int32_t Script_CalendarEventSetDate(lua_State* L); -int32_t Script_CalendarEventSetTime(lua_State* L); -int32_t Script_CalendarEventSetLockoutDate(lua_State* L); -int32_t Script_CalendarEventSetLockoutTime(lua_State* L); -int32_t Script_CalendarEventSetTextureID(lua_State* L); -int32_t Script_CalendarEventSetLocked(lua_State* L); -int32_t Script_CalendarEventClearLocked(lua_State* L); -int32_t Script_CalendarEventSetAutoApprove(lua_State* L); -int32_t Script_CalendarEventClearAutoApprove(lua_State* L); -int32_t Script_CalendarEventGetTextures(lua_State* L); -int32_t Script_CalendarEventHasPendingInvite(lua_State* L); -int32_t Script_CalendarEventHaveSettingsChanged(lua_State* L); -int32_t Script_CalendarEventCanEdit(lua_State* L); -int32_t Script_CalendarEventGetCalendarType(lua_State* L); -int32_t Script_CalendarCanAddEvent(lua_State* L); -int32_t Script_OpenCalendar(lua_State* L); void CalendarRegisterScriptFunctions(); void CalendarUnregisterScriptFunctions(); const char* GetHolidayName(int32_t holidayId); const char* GetEventTypeString(uint32_t type); bool GameCalendarGetMaxCreateDate(WowTime* date); +const char* GetHolidayDescription(int32_t holidayId); +DYNAMICHOLIDAYHASH* CalendarGetHolidayInfo(int32_t holidayId); const char* GetEventRepeatString(uint32_t repeat); extern const char* s_weekdayNames[7]; +extern CalendarEventData s_eventClipboard; +extern TSHashTable s_dynamicHolidays; +extern TSFixedArray s_eventTextures[2]; #endif diff --git a/WoW/Source/Ui/CalendarEvent.cpp b/WoW/Source/Ui/CalendarEvent.cpp index bc75e55..beb5f4b 100644 --- a/WoW/Source/Ui/CalendarEvent.cpp +++ b/WoW/Source/Ui/CalendarEvent.cpp @@ -1,5 +1,24 @@ #include "CalendarEvent.h" +#include #include "WoW/Source/Ui/Calendar.h" +#include "Engine/Source/Base/CDataStore.h" +#include "Engine/Source/FrameScript/FrameScript.h" +#include "Engine/Source/Storm/H/storm.h" +#include "WoW/Source/DB/DBClient/DBCacheInstances.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/ChrClassesRec.h" +#include "WoW/Source/Game/GameClient/NameCache.h" +#include "WoW/Source/Game/GameTime.h" +#include "WoW/Source/Game/ValidateName.h" +#include "WoW/Source/Net/Types.h" +#include "WoW/Source/Object/Object.h" +#include "WoW/Source/Object/Player.h" +#include "WoW/Source/Object/Unit.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/Ui/RaidInfo.h" +#include "WoW/Source/Ui/Types.h" +#include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" // STATIC: 0x00AD1684 static const char* s_eventRepeatStrings[4] = { "CALENDAR_REPEAT_NEVER", "CALENDAR_REPEAT_WEEKLY", "CALENDAR_REPEAT_BIWEEKLY", "CALENDAR_REPEAT_MONTHLY" }; @@ -7,6 +26,28 @@ static const char* s_eventRepeatStrings[4] = { "CALENDAR_REPEAT_NEVER", "CALENDA // STATIC: 0x00AD1694 static const char* s_eventTypeStrings[5] = { "CALENDAR_TYPE_RAID", "CALENDAR_TYPE_DUNGEON", "CALENDAR_TYPE_PVP", "CALENDAR_TYPE_MEETING", "CALENDAR_TYPE_OTHER" }; +// STATIC: 0x00AD16A8 +static const char* s_eventStatusStrings[9] = { "CALENDAR_STATUS_INVITED", "CALENDAR_STATUS_ACCEPTED", "CALENDAR_STATUS_DECLINED", "CALENDAR_STATUS_CONFIRMED", "CALENDAR_STATUS_OUT", "CALENDAR_STATUS_STANDBY", "CALENDAR_STATUS_SIGNEDUP", "CALENDAR_STATUS_NOT_SIGNEDUP", "CALENDAR_STATUS_TENTATIVE" }; + +// STATIC: 0x00AD16CC +static const int32_t s_inviteStatusOrder[9] = { 9, 3, 6, 1, 7, 4, 2, 8, 5 }; + +// STATIC: 0x00AD16F0 +static uint32_t s_inviteSortType; + +// STATIC: 0x00C243B4 +static InviteSortCriterion s_inviteSortCriteria[6]; + +// VERIFY: 92e9c97a auto +// OFFSET: 0x005F1000 +const char* GetEventStatusString(uint32_t status) { + if (status == 7 || status >= 9) { + return nullptr; + } + + return s_eventStatusStrings[status]; +} + // VERIFY: 4baec31b manual // OFFSET: 0x005F1020 const char* GetEventTypeString(uint32_t type) { @@ -18,3 +59,1167 @@ const char* GetEventTypeString(uint32_t type) { const char* GetEventRepeatString(uint32_t repeat) { return repeat < 4 ? s_eventRepeatStrings[repeat] : nullptr; } + +// VERIFY: d2656ad2 manual +// OFFSET: 0x005F1060 +void CGCalendarEvent::Clear() { + this->m_eventID = 0; + this->m_numInvites = 0; + this->m_selectedInviteID = 0; + this->m_moderatorInviteID = 0; + this->m_title[0] = '\0'; + this->m_description[0] = '\0'; + this->m_type = 0; + this->m_repeatOption = 0; + this->m_maxSize = 100; + this->m_flags = 0; + this->m_new = 0; + this->m_changed = 0; + this->m_creatorGUID = WOWGUID(); + this->m_lockoutDate.m_minute = 0; + this->m_lockoutDate.m_hour = 0; + this->m_lockoutDate.m_weekDay = 0; + this->m_lockoutDate.m_monthDay = 0; + this->m_lockoutDate.m_month = 0; + this->m_lockoutDate.m_year = 0; + this->m_lockoutDate.m_flags = 0; + this->m_lockoutDate.m_tzHours = 0; + this->m_textureID = -1; + this->m_pendingNames = 0; + this->m_signalType = 1; + this->m_sortType = 3; + + for (uint32_t i = 0; i < 6; i++) { + this->m_sortCriteria[i].m_criterion = i; + this->m_sortCriteria[i].m_reverse = 0; + } +} + +// VERIFY: 29a5cc3a auto +// OFFSET: 0x005F1130 +void CGCalendarEvent::SetTitle(const char* title) { + if (title && SStrCmp(title, this->m_title, STORM_MAX_STR)) { + ScrubString(title, this->m_title, 32, sizeof(this->m_title), 1); + this->m_changed = 1; + } +} + +// VERIFY: e8f3857e auto +// OFFSET: 0x005F1180 +void CGCalendarEvent::SetDescription(const char* description) { + if (description && SStrCmp(description, this->m_description, STORM_MAX_STR)) { + ScrubString(description, this->m_description, 256, sizeof(this->m_description), 0); + this->m_changed = 1; + } +} + +// VERIFY: d2c0193e auto +// OFFSET: 0x005F11D0 +void CGCalendarEvent::SetType(uint32_t type) { + if (type < 5 && type != this->m_type) { + this->m_type = type; + this->m_changed = 1; + } +} + +// VERIFY: 36d2d1c6 auto +// OFFSET: 0x005F1200 +void CGCalendarEvent::SetRepeatOption(uint32_t repeatOption) { + if (repeatOption < 4 && repeatOption != this->m_repeatOption) { + this->m_repeatOption = repeatOption; + this->m_changed = 1; + } +} + +// VERIFY: 88a5717b auto +// OFFSET: 0x005F1230 +void CGCalendarEvent::SetSize(uint32_t size) { + if (!(this->m_flags & 0x440) && size > 1 && size != this->m_maxSize) { + this->m_maxSize = size; + this->m_changed = 1; + } +} + +// VERIFY: 6d782fef auto +// OFFSET: 0x005F1260 +bool CGCalendarEvent::SetDate(uint32_t month, uint32_t monthDay, uint32_t year) { + if (month != this->m_date.m_month || monthDay != this->m_date.m_monthDay || year != this->m_date.m_year) { + this->m_changed = 1; + } + + return this->m_date.SetDate(month, monthDay, year); +} + +// VERIFY: 0faa2884 auto +// OFFSET: 0x005F12A0 +bool CGCalendarEvent::SetTime(uint32_t hour, uint32_t minute) { + if (hour != this->m_date.m_hour || minute != this->m_date.m_minute) { + this->m_changed = 1; + } + + return this->m_date.SetHourAndMinutes(hour, minute); +} + +// VERIFY: 908baeb8 auto +// OFFSET: 0x005F12E0 +bool CGCalendarEvent::SetLockoutDate(uint32_t month, uint32_t monthDay, uint32_t year) { + if (this->m_flags & 0x440) { + return false; + } + + if (month != this->m_lockoutDate.m_month || monthDay != this->m_lockoutDate.m_monthDay || year != this->m_lockoutDate.m_year) { + this->m_changed = 1; + } + + return this->m_lockoutDate.SetDate(month, monthDay, year); +} + +// VERIFY: f9a4b158 auto +// OFFSET: 0x005F1340 +bool CGCalendarEvent::SetLockoutTime(uint32_t hour, uint32_t minute) { + if (this->m_flags & 0x440) { + return false; + } + + if (hour != this->m_lockoutDate.m_hour || minute != this->m_lockoutDate.m_minute) { + this->m_changed = 1; + } + + return this->m_lockoutDate.SetHourAndMinutes(hour, minute); +} + +// VERIFY: fe57aa62 auto +// OFFSET: 0x005F1390 +void CGCalendarEvent::SetTextureID(int32_t textureID) { + if (textureID != this->m_textureID) { + this->m_textureID = textureID; + this->m_changed = 1; + } +} + +// VERIFY: dd189781 auto +// OFFSET: 0x005F13B0 +void CGCalendarEvent::SetFlag(uint32_t flag) { + if (!(this->m_flags & flag)) { + this->m_flags |= flag; + this->m_changed = 1; + } +} + +// VERIFY: 86c68769 auto +// OFFSET: 0x005F13E0 +void CGCalendarEvent::ClearFlag(uint32_t flag) { + if (this->m_flags & flag) { + this->m_flags &= ~flag; + this->m_changed = 1; + } +} + +// VERIFY: eec371c3 auto +// OFFSET: 0x005F1410 +void CGCalendarEvent::SetSignalType(uint32_t signalType) { + this->m_signalType = signalType; +} + +// VERIFY: 6949882a auto +// OFFSET: 0x005F14B0 +bool CGCalendarEvent::ProcessUpdateEvent(CDataStore* msg) { + msg->Get(this->m_flags); + uint32_t date; + msg->Get(date); + uint8_t type; + msg->Get(type); + this->m_type = type; + msg->Get(reinterpret_cast(this->m_textureID)); + msg->GetString(this->m_title, sizeof(this->m_title)); + msg->GetString(this->m_description, sizeof(this->m_description)); + uint8_t repeatOption; + msg->Get(repeatOption); + this->m_repeatOption = repeatOption; + msg->Get(this->m_maxSize); + uint32_t lockoutDate; + msg->Get(lockoutDate); + WowTime::WowDecodeTime(date, &this->m_date); + WowTime::WowDecodeTime(lockoutDate, &this->m_lockoutDate); + return true; +} + +// VERIFY: 614ecd10 manual +// OFFSET: 0x005F1580 +void CGCalendarEvent::InviteRemoved(WOWGUID guid) { + uint32_t count = this->m_numInvites; + + if (!count) { + return; + } + + uint32_t index = 0; + EventInviteInfo* invite; + + for (;;) { + if (this->m_invites.m_data[index]->m_guid == guid) { + invite = this->m_invites.m_data[index]; + break; + } + + if (++index >= count) { + invite = nullptr; + break; + } + } + + if (index >= count) { + return; + } + + for (this->m_numInvites = count - 1; index < this->m_numInvites; index++) { + this->m_invites.m_data[index] = this->m_invites.m_data[index + 1]; + } + + this->m_invites.m_data[index] = invite; +} + +// VERIFY: 8174b978 manual +// OFFSET: 0x005F1600 +void CGCalendarEvent::UpdateInviteStatus(WOWGUID guid, uint8_t status, uint32_t responseTime) { + for (uint32_t i = 0; i < this->m_numInvites; i++) { + if (this->m_invites.m_data[i]->m_guid == guid) { + this->m_invites.m_data[i]->m_status = status; + + if (responseTime) { + this->m_invites.m_data[i]->m_responseTime = responseTime; + } + + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, nullptr); + return; + } + } +} + +// VERIFY: 81059cc6 manual +// OFFSET: 0x005F1670 +void CGCalendarEvent::UpdateInviteNotes(WOWGUID guid, const char* notes) { + for (uint32_t i = 0; i < this->m_numInvites; i++) { + if (this->m_invites.m_data[i]->m_guid == guid) { + SStrCopy(this->m_invites.m_data[i]->m_notes, notes, sizeof(this->m_invites.m_data[i]->m_notes)); + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, nullptr); + return; + } + } +} + +// VERIFY: 465fbdb7 manual +// OFFSET: 0x005F16E0 +bool CGCalendarEvent::CanModerate(uint32_t index) { + if (index >= this->m_numInvites) { + return false; + } + + if ((this->m_flags & 0x400) && !this->m_invites.m_data[index]->m_inviteType) { + CGCalendar::CalendarError("CALENDAR_ERROR_NO_MODERATOR", 0); + return false; + } + + return true; +} + +// VERIFY: 84687b6b manual +// OFFSET: 0x005F1720 +static int32_t QSortInvites(const void* a, const void* b) { + const EventInviteInfo* left = *static_cast(a); + const EventInviteInfo* right = *static_cast(b); + int32_t result = 0; + + switch (s_inviteSortType) { + case 0: { + WOWGUID leftKey = WOWGUID(); + NameCache* leftName = g_nameDBCache.GetRecord(left->m_guid.m_guid, leftKey, nullptr, nullptr, false); + WOWGUID rightKey = WOWGUID(); + NameCache* rightName = g_nameDBCache.GetRecord(right->m_guid.m_guid, rightKey, nullptr, nullptr, false); + + if (leftName && rightName) { + result = SStrCmpUTF8I(leftName->m_name, rightName->m_name, STORM_MAX_STR); + } + + break; + } + + case 1: + result = left->m_level - right->m_level; + break; + + case 2: { + WOWGUID leftKey = WOWGUID(); + NameCache* leftName = g_nameDBCache.GetRecord(left->m_guid.m_guid, leftKey, nullptr, nullptr, false); + WOWGUID rightKey = WOWGUID(); + NameCache* rightName = g_nameDBCache.GetRecord(right->m_guid.m_guid, rightKey, nullptr, nullptr, false); + + if (leftName && rightName) { + ChrClassesRec* leftClass = g_chrClassesDB.GetRecord(leftName->m_class); + ChrClassesRec* rightClass = g_chrClassesDB.GetRecord(rightName->m_class); + + if (leftClass && rightClass) { + result = SStrSortUTF8I(leftClass->m_name, rightClass->m_name, STORM_MAX_STR); + } + } + + break; + } + + case 3: + result = s_inviteStatusOrder[left->m_status] - s_inviteStatusOrder[right->m_status]; + break; + + case 4: + if (CGRaidInfo::FindMemberByGuid(left->m_guid)) { + if (!CGRaidInfo::FindMemberByGuid(right->m_guid)) { + result = -1; + } + } else if (CGRaidInfo::FindMemberByGuid(right->m_guid)) { + result = 1; + } + + break; + + case 5: + result = SStrSortUTF8I(left->m_notes, right->m_notes, STORM_MAX_STR); + break; + } + + if (s_inviteSortCriteria[s_inviteSortType].m_reverse) { + result = -result; + } + + if (s_inviteSortType && !result) { + WOWGUID leftKey = WOWGUID(); + NameCache* leftName = g_nameDBCache.GetRecord(left->m_guid.m_guid, leftKey, nullptr, nullptr, false); + WOWGUID rightKey = WOWGUID(); + NameCache* rightName = g_nameDBCache.GetRecord(right->m_guid.m_guid, rightKey, nullptr, nullptr, false); + + if (leftName && rightName) { + return SStrCmpUTF8I(leftName->m_name, rightName->m_name, STORM_MAX_STR); + } + + return 0; + } + + return result; +} + +// VERIFY: 90a7ac86 manual +// OFFSET: 0x005F1980 +bool CGCalendarEvent::SortInvites(uint32_t criterion, bool toggle) { + for (uint32_t i = 0; i < 6; i++) { + if (i == criterion) { + if (toggle) { + this->m_sortCriteria[i].m_reverse = !this->m_sortCriteria[i].m_reverse; + } + + this->m_sortType = i; + } else { + this->m_sortCriteria[i].m_reverse = 0; + } + + s_inviteSortCriteria[i].m_criterion = this->m_sortCriteria[i].m_criterion; + s_inviteSortCriteria[i].m_reverse = this->m_sortCriteria[i].m_reverse; + } + + s_inviteSortType = this->m_sortType; + qsort(this->m_invites.m_data, this->m_numInvites, sizeof(EventInviteInfo*), QSortInvites); + return true; +} + +// VERIFY: 73a7a685 auto +// OFFSET: 0x005F1A00 +void CGCalendarEvent::SelectInvite(uint32_t index) { + if (index > this->m_numInvites) { + return; + } + + for (uint32_t i = 0; i < this->m_numInvites; i++) { + if (i == index) { + this->m_selectedInviteID = this->m_invites.m_data[i]->m_inviteID; + return; + } + } +} + +// VERIFY: 23acd6ad auto +// OFFSET: 0x005F1B10 +static void InviteNameCacheCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { + CGCalendarEvent* event = static_cast(param); + + if (!event) { + return; + } + + if (event->m_pendingNames) { + event->m_pendingNames--; + } + + if (event->m_pendingNames) { + return; + } + + event->SortInvites(event->m_sortType, false); + + switch (event->m_signalType) { + case 0: + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, nullptr); + break; + + case 1: + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, "%b", 1); + break; + + case 2: + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_NEW_EVENT, "%b", 0); + break; + + case 3: + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_NEW_EVENT, "%b", 1); + break; + + case 4: + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_OPEN_EVENT, "%s", CGCalendar::GetCalendarTypeString(event->m_flags)); + break; + } +} + +// VERIFY: ee9836e6 manual +// OFFSET: 0x005F1B30 +bool CGCalendarEvent::IsModerator() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + WOWGUID guid = player ? player->m_obj->m_guid : WOWGUID(); + return this->m_moderatorInviteID || guid == this->m_creatorGUID; +} + +// VERIFY: f351fca2 manual +// OFFSET: 0x005F1B90 +bool CGCalendarEvent::AddEvent() { + if (!this->m_new) { + return false; + } + + if (!this->m_title[0]) { + CGCalendar::CalendarError("CALENDAR_ERROR_NEEDS_TITLE", 0); + return false; + } + + if (this->m_flags & 0x440) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && !player->m_player->m_playerGuildid) { + CGCalendar::CalendarError("ERR_GUILD_PLAYER_NOT_IN_GUILD", 0); + return false; + } + } else { + if (!this->m_maxSize) { + return false; + } + + if (this->m_maxSize > 100) { + CGCalendar::CalendarError("CALENDAR_ERROR_INVITES_EXCEEDED", 100); + return false; + } + } + + if (this->m_date.m_hour == -1 || this->m_date.m_minute == -1) { + CGCalendar::CalendarError("CALENDAR_ERROR_INVALID_TIME", 0); + return false; + } + + if (this->m_date.m_month == -1 || this->m_date.m_monthDay == -1 || this->m_date.m_year == -1) { + CGCalendar::CalendarError("CALENDAR_ERROR_INVALID_DATE", 0); + return false; + } + + if (this->m_date <= g_clientGameTime) { + CGCalendar::CalendarError("CALENDAR_ERROR_EVENT_TIME_PASSED", 0); + return false; + } + + uint32_t date; + WowTime::WowEncodeTime(date, &this->m_date); + uint32_t lockoutDate; + WowTime::WowEncodeTime(lockoutDate, &this->m_lockoutDate); + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_ADD_EVENT)); + msg.PutString(this->m_title); + msg.PutString(this->m_description); + msg.Put(static_cast(this->m_type)); + msg.Put(static_cast(this->m_repeatOption)); + msg.Put(this->m_maxSize); + msg.Put(static_cast(this->m_textureID)); + msg.Put(date); + msg.Put(lockoutDate); + msg.Put(this->m_flags); + + if (!(this->m_flags & 0x40)) { + msg.Put(this->m_numInvites); + + for (uint32_t i = 0; i < this->m_numInvites; i++) { + SmartGUID guid; + guid.m_guid = this->m_invites.m_data[i]->m_guid.m_guid; + msg << guid; + msg.Put(this->m_invites.m_data[i]->m_status); + msg.Put(this->m_invites.m_data[i]->m_moderatorStatus); + } + } + + msg.Finalize(); + ClientServices::Send2(&msg); + return true; +} + +// VERIFY: 8a244fb3 manual +// OFFSET: 0x005F1E30 +bool CGCalendarEvent::RemoveEvent() { + if (!this->IsModerator()) { + CGCalendar::CalendarError("CALENDAR_ERROR_PERMISSIONS", 0); + return false; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_REMOVE_EVENT)); + msg.Put(this->m_eventID); + msg.Put(this->m_moderatorInviteID); + msg.Put(static_cast((this->m_flags & 0x440) != 0)); + msg.Finalize(); + ClientServices::Send2(&msg); + return true; +} + +// VERIFY: e23e4de8 manual +// OFFSET: 0x005F1EF0 +bool CGCalendarEvent::Update() { + if (!this->m_changed) { + return false; + } + + this->m_changed = 0; + + if (this->m_date <= g_clientGameTime) { + CGCalendar::CalendarError("CALENDAR_ERROR_EVENT_PASSED", 0); + return false; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_UPDATE_EVENT)); + msg.Put(this->m_eventID); + msg.Put(this->m_moderatorInviteID); + msg.PutString(this->m_title); + msg.PutString(this->m_description); + msg.Put(static_cast(this->m_type)); + msg.Put(static_cast(this->m_repeatOption)); + msg.Put(this->m_maxSize); + msg.Put(static_cast(this->m_textureID)); + uint32_t date; + WowTime::WowEncodeTime(date, &this->m_date); + msg.Put(date); + WowTime::WowEncodeTime(date, &this->m_lockoutDate); + msg.Put(date); + msg.Put(this->m_flags); + msg.Finalize(); + ClientServices::Send2(&msg); + return true; +} + +// VERIFY: d6e6845f manual +// OFFSET: 0x005F2070 +bool CGCalendarEvent::Invite(const char* name) { + if (this->m_flags & 0x40) { + CGCalendar::CalendarError("CALENDAR_ERROR_INVITES_DISABLED", 0); + return false; + } + + if (this->m_numInvites >= 100) { + CGCalendar::CalendarError("CALENDAR_ERROR_INVITES_EXCEEDED", 100); + return false; + } + + char fixedName[48]; + FixCharacterNameCase(fixedName, name, sizeof(fixedName)); + + for (uint32_t i = 0; i < this->m_numInvites; i++) { + WOWGUID key = WOWGUID(); + NameCache* record = g_nameDBCache.GetRecord(this->m_invites.m_data[i]->m_guid.m_guid, key, nullptr, nullptr, false); + + if (record && !SStrCmp(fixedName, record->m_name, STORM_MAX_STR)) { + CGCalendar::CalendarError("CALENDAR_ERROR_ALREADY_INVITED_TO_EVENT_S", reinterpret_cast(fixedName)); + return false; + } + } + + if (!this->IsModerator()) { + CGCalendar::CalendarError("CALENDAR_ERROR_PERMISSIONS", 0); + return false; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_INVITE)); + msg.Put(this->m_eventID); + msg.Put(this->m_moderatorInviteID); + msg.PutString(fixedName); + msg.Put(this->m_new); + msg.Put(static_cast((this->m_flags & 0x400) != 0)); + msg.Finalize(); + ClientServices::Send2(&msg); + return true; +} + +// VERIFY: dd21d29e manual +// OFFSET: 0x005F2220 +bool CGCalendarEvent::RemoveInvite(uint32_t index) { + if (index >= this->m_numInvites) { + return false; + } + + if (this->m_invites.m_data[index]->m_moderatorStatus == 2) { + CGCalendar::CalendarError("CALENDAR_DELETE_CREATOR_FAILED", 0); + return false; + } + + SmartGUID guid; + guid.m_guid = this->m_invites.m_data[index]->m_guid.m_guid; + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && this->m_invites.m_data[index]->m_guid != player->m_obj->m_guid && !this->IsModerator()) { + CGCalendar::CalendarError("CALENDAR_ERROR_PERMISSIONS", 0); + return false; + } + + if (this->m_new) { + EventInviteInfo* invite = this->m_invites.m_data[index]; + this->m_numInvites--; + + for (uint32_t i = index; i < this->m_numInvites; i++) { + this->m_invites.m_data[i] = this->m_invites.m_data[i + 1]; + } + + this->m_invites.m_data[this->m_numInvites] = invite; + return true; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_REMOVE_INVITE)); + msg << guid; + msg.Put(this->m_invites.m_data[index]->m_inviteID); + msg.Put(this->m_moderatorInviteID); + msg.Put(this->m_eventID); + msg.Finalize(); + ClientServices::Send2(&msg); + return true; +} + +// VERIFY: 0ee03c7a manual +// OFFSET: 0x005F23B0 +bool CGCalendarEvent::RemoveInviteByGUID(WOWGUID guid) { + if (!guid) { + return false; + } + + int32_t index = this->GetInviteIndex(guid); + + if (index < 0) { + return false; + } + + return this->RemoveInvite(index); +} + +// VERIFY: 0c93d50a manual +// OFFSET: 0x005F23F0 +bool CGCalendarEvent::InviteRSVP(uint32_t status) { + if (this->m_new || (status != 1 && status != 2 && status != 8)) { + return false; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return false; + } + + uint32_t index = 0; + + if (!this->m_numInvites) { + return false; + } + + WOWGUID guid = player->m_obj->m_guid; + + while (this->m_invites.m_data[index]->m_guid != guid) { + if (++index >= this->m_numInvites) { + return false; + } + } + + if ((this->m_flags & 0x400) && this->m_invites.m_data[index]->m_inviteType == 1) { + return false; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_RSVP)); + msg.Put(this->m_eventID); + msg.Put(this->m_invites.m_data[index]->m_inviteID); + msg.Put(status); + msg.Finalize(); + ClientServices::Send2(&msg); + return true; +} + +// VERIFY: dbc2b3c0 manual +// OFFSET: 0x005F2530 +bool CGCalendarEvent::SignUp(uint8_t tentative) { + if (this->m_new) { + return false; + } + + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player) { + WOWGUID guid = player->m_obj->m_guid; + + for (uint32_t i = 0; i < this->m_numInvites; i++) { + if (this->m_invites.m_data[i]->m_guid == guid) { + return false; + } + } + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_SIGN_UP)); + msg.Put(this->m_eventID); + msg.Put(tentative); + msg.Finalize(); + ClientServices::Send2(&msg); + return true; +} + +// VERIFY: 62b551de manual +// OFFSET: 0x005F2640 +void CGCalendarEvent::UpdateInviteModeratorStatus(WOWGUID guid, uint8_t status) { + for (uint32_t i = 0; i < this->m_numInvites; i++) { + if (this->m_invites.m_data[i]->m_guid != guid) { + continue; + } + + this->m_invites.m_data[i]->m_moderatorStatus = status; + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && player->m_obj->m_guid == guid) { + if (status == 1) { + this->m_moderatorInviteID = this->m_invites.m_data[i]->m_inviteID; + } else { + this->m_moderatorInviteID = 0; + } + } + + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, nullptr); + return; + } +} + +// VERIFY: 1bbde5a8 manual +// OFFSET: 0x005F26F0 +bool CGCalendarEvent::CanSetInviteStatus(uint32_t index, uint32_t status) { + if (!this->IsModerator() || index >= this->m_numInvites || status >= 9 || !status || status == 6 || status == 7) { + return false; + } + + if ((this->m_flags & 0x400) && (status == 1 || status == 2)) { + return false; + } + + return status != this->m_invites.m_data[index]->m_status; +} + +// VERIFY: b4129b9f manual +// OFFSET: 0x005F2750 +void CGCalendarEvent::SetInviteStatus(uint32_t index, uint32_t status) { + if (!this->CanSetInviteStatus(index, status)) { + return; + } + + if (this->m_new) { + this->m_invites.m_data[index]->m_status = status; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, nullptr); + return; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_STATUS)); + SmartGUID guid; + guid.m_guid = this->m_invites.m_data[index]->m_guid.m_guid; + msg << guid; + msg.Put(this->m_eventID); + msg.Put(this->m_invites.m_data[index]->m_inviteID); + msg.Put(this->m_moderatorInviteID); + msg.Put(status); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: a301db27 auto +// OFFSET: 0x005F2860 +void CGCalendarEvent::SetModeratorStatus(uint32_t index, uint32_t status) { + if (!this->IsModerator()) { + CGCalendar::CalendarError("CALENDAR_ERROR_PERMISSIONS", 0); + return; + } + + if (index >= this->m_numInvites || status >= 2 || !this->CanModerate(index)) { + return; + } + + if (status == this->m_invites.m_data[index]->m_moderatorStatus) { + return; + } + + if (this->m_new) { + this->m_invites.m_data[index]->m_moderatorStatus = status; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, nullptr); + return; + } + + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_MODERATOR_STATUS)); + SmartGUID guid; + guid.m_guid = this->m_invites.m_data[index]->m_guid.m_guid; + msg << guid; + msg.Put(this->m_eventID); + msg.Put(this->m_invites.m_data[index]->m_inviteID); + msg.Put(this->m_moderatorInviteID); + msg.Put(status); + msg.Finalize(); + ClientServices::Send2(&msg); +} + +// VERIFY: 8f99c58f auto +// OFFSET: 0x005F29E0 +CGCalendarEvent::CGCalendarEvent() { + this->Clear(); +} + +// VERIFY: 4a90c632 manual +// OFFSET: 0x005F2A20 +CGCalendarEvent::CGCalendarEvent(WOWGUID guid, uint8_t level, int32_t calendarType) { + this->Clear(); + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player) { + return; + } + + this->m_creatorGUID = player->m_obj->m_guid; + uint8_t inviteType = 0; + + if (calendarType == 0) { + this->m_flags |= 0x1; + } else if (calendarType == 1) { + this->m_flags |= 0x40; + } else if (calendarType == 2) { + this->m_flags |= 0x400; + inviteType = 1; + } + + if (guid) { + this->m_numInvites = 1; + + if (!this->m_invites.Count()) { + void* mem = SMemAlloc(sizeof(EventInviteInfo), __FILE__, __LINE__, 0); + EventInviteInfo* invite = mem ? new (mem) EventInviteInfo() : nullptr; + this->m_invites.New(invite); + } + + EventInviteInfo* invite = this->m_invites.m_data[0]; + invite->m_inviteID = 0; + invite->m_guid = guid; + invite->m_level = level; + invite->m_status = 3; + invite->m_moderatorStatus = 2; + invite->m_inviteType = inviteType; + invite->m_responseTime = 0; + } + + this->m_moderatorInviteID = 1; + this->m_new = 1; +} + +// VERIFY: c5c54e9d manual +// OFFSET: 0x005F2B70 +CGCalendarEvent::~CGCalendarEvent() { + uint32_t count = this->m_invites.Count(); + + for (uint32_t i = 0; i < count; i++) { + g_nameDBCache.CancelCallback(this->m_invites.m_data[i]->m_guid.m_guid, InviteNameCacheCallback, this); + delete this->m_invites.m_data[i]; + } + + this->m_invites.Clear(); +} + +// VERIFY: 28fcc58f manual +// OFFSET: 0x005F2C00 +bool CGCalendarEvent::ProcessGetEvent(CDataStore* msg, int32_t* status) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + WOWGUID playerGuid = player ? player->m_obj->m_guid : WOWGUID(); + + SmartGUID creator; + *msg >> creator; + this->m_creatorGUID = creator; + msg->Get(this->m_eventID); + msg->GetString(this->m_title, sizeof(this->m_title)); + msg->GetString(this->m_description, sizeof(this->m_description)); + uint8_t type; + msg->Get(type); + this->m_type = type; + uint8_t repeatOption; + msg->Get(repeatOption); + this->m_repeatOption = repeatOption; + msg->Get(this->m_maxSize); + msg->Get(reinterpret_cast(this->m_textureID)); + msg->Get(this->m_flags); + uint32_t date; + msg->Get(date); + uint32_t lockoutDate; + msg->Get(lockoutDate); + WowTime::WowDecodeTime(date, &this->m_date); + WowTime::WowDecodeTime(lockoutDate, &this->m_lockoutDate); + msg->Get(this->m_guildID); + + uint32_t count = this->m_invites.Count(); + msg->Get(this->m_numInvites); + + for (uint32_t i = count; i < this->m_numInvites; i++) { + void* mem = SMemAlloc(sizeof(EventInviteInfo), __FILE__, __LINE__, 0); + EventInviteInfo* invite = mem ? new (mem) EventInviteInfo() : nullptr; + this->m_invites.New(invite); + } + + bool found = false; + + for (uint32_t i = 0; i < this->m_numInvites; i++) { + SmartGUID guid; + *msg >> guid; + WOWGUID key = guid; + + if (!g_nameDBCache.GetRecord(guid.m_guid, key, InviteNameCacheCallback, this, false)) { + this->m_pendingNames++; + } + + uint8_t level; + msg->Get(level); + uint8_t inviteStatus; + msg->Get(inviteStatus); + uint8_t moderatorStatus; + msg->Get(moderatorStatus); + uint8_t inviteType; + msg->Get(inviteType); + uint64_t inviteID; + msg->Get(inviteID); + uint32_t responseTime; + msg->Get(responseTime); + + if (this->m_new) { + inviteStatus = 0; + } + + if (guid == playerGuid) { + found = true; + *status = inviteStatus; + + if (moderatorStatus) { + this->m_moderatorInviteID = inviteID; + } + } + + EventInviteInfo* invite = this->m_invites.m_data[i]; + invite->m_inviteID = inviteID; + invite->m_guid = guid; + invite->m_level = level; + invite->m_status = inviteStatus; + invite->m_moderatorStatus = moderatorStatus; + invite->m_responseTime = responseTime; + invite->m_inviteType = inviteType; + msg->GetString(this->m_invites.m_data[i]->m_notes, STORM_MAX_STR); + } + + if (!found && (this->m_flags & 0x400)) { + *status = 7; + } + + this->m_new = 0; + this->m_changed = 0; + this->m_selectedInviteID = 0; + + if (!this->m_pendingNames) { + this->SortInvites(3, false); + } + + return true; +} + +// VERIFY: 5e4995f1 manual +// OFFSET: 0x005F2F90 +bool CGCalendarEvent::ProcessInitialInviteList(CDataStore* msg) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + WOWGUID playerGuid = player ? player->m_obj->m_guid : WOWGUID(); + + uint32_t count = this->m_invites.Count(); + msg->Get(this->m_numInvites); + + for (uint32_t i = count; i < this->m_numInvites; i++) { + void* mem = SMemAlloc(sizeof(EventInviteInfo), __FILE__, __LINE__, 0); + EventInviteInfo* invite = mem ? new (mem) EventInviteInfo() : nullptr; + this->m_invites.New(invite); + } + + bool found = false; + + for (uint32_t i = 0; i < this->m_numInvites; i++) { + SmartGUID guid; + *msg >> guid; + WOWGUID key = guid; + + if (!g_nameDBCache.GetRecord(guid.m_guid, key, InviteNameCacheCallback, this, false)) { + this->m_pendingNames++; + } + + uint8_t level; + msg->Get(level); + uint8_t moderatorStatus; + uint8_t inviteStatus; + + if (guid == playerGuid) { + moderatorStatus = 2; + inviteStatus = 3; + found = true; + } else { + moderatorStatus = 0; + inviteStatus = 0; + } + + EventInviteInfo* invite = this->m_invites.m_data[i]; + invite->m_inviteID = 0; + invite->m_guid = guid; + invite->m_level = level; + invite->m_status = inviteStatus; + invite->m_moderatorStatus = moderatorStatus; + invite->m_inviteType = 0; + invite->m_responseTime = 0; + } + + if (!found) { + uint32_t index = this->m_numInvites; + this->m_numInvites = index + 1; + + if (this->m_numInvites > this->m_invites.Count()) { + void* mem = SMemAlloc(sizeof(EventInviteInfo), __FILE__, __LINE__, 0); + EventInviteInfo* invite = mem ? new (mem) EventInviteInfo() : nullptr; + this->m_invites.New(invite); + } + + EventInviteInfo* invite = this->m_invites.m_data[index]; + invite->m_inviteID = 0; + invite->m_guid = playerGuid; + invite->m_level = player->m_unit->m_unitFieldLevel; + invite->m_status = 3; + invite->m_moderatorStatus = 2; + invite->m_inviteType = 0; + invite->m_responseTime = 0; + } + + this->m_moderatorInviteID = 1; + this->m_new = 1; + this->m_selectedInviteID = 0; + + if (this->m_pendingNames) { + this->m_signalType = 1; + return true; + } + + this->SortInvites(3, false); + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, "%b", 1); + return true; +} + +// VERIFY: c8c66049 manual +// OFFSET: 0x005F32B0 +void CGCalendarEvent::AddInvite(uint64_t inviteID, WOWGUID guid, uint8_t level, uint8_t status, uint8_t inviteType, uint32_t responseTime) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + WOWGUID playerGuid = player ? player->m_obj->m_guid : WOWGUID(); + + uint32_t index = this->m_numInvites; + uint8_t moderatorStatus = 0; + this->m_numInvites = index + 1; + + if (this->m_numInvites > this->m_invites.Count()) { + void* mem = SMemAlloc(sizeof(EventInviteInfo), __FILE__, __LINE__, 0); + EventInviteInfo* invite = mem ? new (mem) EventInviteInfo() : nullptr; + this->m_invites.New(invite); + } + + if (!g_nameDBCache.GetRecord(guid.m_guid, guid, InviteNameCacheCallback, this, false)) { + this->m_pendingNames++; + } + + if (guid == playerGuid && inviteType != 1) { + moderatorStatus = 2; + } + + EventInviteInfo* invite = this->m_invites.m_data[index]; + invite->m_inviteID = inviteID; + invite->m_guid = guid; + invite->m_level = level; + invite->m_status = status; + invite->m_moderatorStatus = moderatorStatus; + invite->m_inviteType = inviteType; + invite->m_responseTime = responseTime; + + if (this->m_pendingNames) { + this->m_signalType = 0; + return; + } + + this->SortInvites(this->m_sortType, false); + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, nullptr); +} + +// VERIFY: 2583e5f4 manual +// OFFSET: 0x005B8D60 +EventInviteInfo* CGCalendarEvent::GetInvite(WOWGUID guid) { + for (uint32_t i = 0; i < this->m_numInvites; i++) { + if (this->m_invites.m_data[i]->m_guid == guid) { + return this->m_invites.m_data[i]; + } + } + + return nullptr; +} + +// VERIFY: d87c9eac manual +// OFFSET: 0x005B8DC0 +int32_t CGCalendarEvent::GetInviteIndex(WOWGUID guid) { + for (uint32_t i = 0; i < this->m_numInvites; i++) { + if (this->m_invites.m_data[i]->m_guid == guid) { + return i; + } + } + + return -1; +} + +// VERIFY: db0dd3af manual +// OFFSET: 0x005B8E00 +int32_t CGCalendarEvent::GetSelectedInviteIndex() { + for (uint32_t i = 0; i < this->m_numInvites; i++) { + if (this->m_invites.m_data[i]->m_inviteID == this->m_selectedInviteID) { + return i; + } + } + + return -1; +} diff --git a/WoW/Source/Ui/CalendarEvent.h b/WoW/Source/Ui/CalendarEvent.h index bbff4e7..98686a3 100644 --- a/WoW/Source/Ui/CalendarEvent.h +++ b/WoW/Source/Ui/CalendarEvent.h @@ -3,58 +3,112 @@ #include #include +#include "Engine/Source/Storm/H/stpl.h" +#include "WoW/Common/WowTime.h" +#include "WoW/Source/Object/WGUID.h" + +class CDataStore; + +struct EventInviteInfo { + /* 0000 */ uint64_t m_inviteID; + /* 0008 */ WOWGUID m_guid; + /* 0010 */ uint32_t m_responseTime; + /* 0014 */ uint8_t m_level; + /* 0015 */ uint8_t m_status; + /* 0016 */ uint8_t m_moderatorStatus; + /* 0017 */ uint8_t m_inviteType; + /* 0018 */ char m_notes[128]; + + EventInviteInfo(); +}; + +// INLINED +inline EventInviteInfo::EventInviteInfo() { + this->m_inviteID = 0; + this->m_guid = WOWGUID(); + this->m_responseTime = 0; + this->m_level = 0; + this->m_status = 0; + this->m_moderatorStatus = 0; + this->m_inviteType = 0; + this->m_notes[0] = '\0'; +} + +struct InviteSortCriterion { + /* 0000 */ uint32_t m_criterion; + /* 0004 */ uint8_t m_reverse; +}; class CGCalendarEvent { public: - /* 0000 */ uint32_t unk_0000; - /* 0004 */ uint16_t unk_0004; - /* 0006 */ uint16_t unk_0006; - /* 0008 */ uint32_t unk_0008; - /* 000C */ uint32_t unk_000C; - /* 0010 */ uint32_t unk_0010; - /* 0014 */ uint32_t unk_0014; - /* 0018 */ uint32_t unk_0018; - /* 001C */ uint8_t unk_001C[4]; - /* 0020 */ uint32_t unk_0020; - /* 0024 */ uint32_t unk_0024; - /* 0028 */ uint32_t unk_0028; - /* 002C */ uint32_t unk_002C; - /* 0030 */ uint8_t unk_0030; - /* 0031 */ uint8_t unk_0031[288]; - /* 0151 */ uint8_t unk_0151[4]; - /* 0155 */ uint8_t unk_0155[859]; - /* 04B0 */ uint32_t unk_04B0; - /* 04B4 */ uint32_t unk_04B4; - /* 04B8 */ uint32_t unk_04B8; - /* 04BC */ uint32_t unk_04BC; - /* 04C0 */ uint32_t unk_04C0; - /* 04C4 */ uint8_t unk_04C4[4]; - /* 04C8 */ uint32_t unk_04C8; - /* 04CC */ uint32_t unk_04CC; - /* 04D0 */ uint32_t unk_04D0; - /* 04D4 */ uint8_t unk_04D4[8]; - /* 04DC */ uint32_t unk_04DC; - /* 04E0 */ uint32_t unk_04E0; - /* 04E4 */ uint8_t unk_04E4[4]; - /* 04E8 */ uint32_t unk_04E8; - /* 04EC */ uint32_t unk_04EC; - /* 04F0 */ uint32_t unk_04F0; - /* 04F4 */ uint8_t unk_04F4[8]; - /* 04FC */ uint32_t unk_04FC; - /* 0500 */ uint8_t unk_0500; - /* 0501 */ uint8_t unk_0501; - /* 0502 */ uint8_t unk_0502[6]; - /* 0508 */ uint32_t unk_0508; - /* 050C */ uint32_t unk_050C; - /* 0510 */ uint32_t unk_0510; - /* 0514 */ uint8_t unk_0514[48]; - /* 0544 */ uint32_t unk_0544; - /* 0548 */ uint32_t unk_0548; - /* 054C */ uint32_t unk_054C; - /* 0550 */ uint8_t unk_0550[3760]; - /* 1400 */ uint8_t unk_1400; + /* 0000 */ uint64_t m_eventID; + /* 0008 */ TSGrowableArray m_invites; + /* 0018 */ uint32_t m_numInvites; + /* 0020 */ uint64_t m_selectedInviteID; + /* 0028 */ uint64_t m_moderatorInviteID; + /* 0030 */ char m_title[128]; + /* 00B0 */ char m_description[1024]; + /* 04B0 */ uint32_t m_type; + /* 04B4 */ uint32_t m_repeatOption; + /* 04B8 */ uint32_t m_maxSize; + /* 04BC */ WowTime m_date; + /* 04DC */ WowTime m_lockoutDate; + /* 04FC */ uint32_t m_flags; + /* 0500 */ uint8_t m_new; + /* 0501 */ uint8_t m_changed; + /* 0508 */ WOWGUID m_creatorGUID; + /* 0510 */ int32_t m_textureID; + /* 0514 */ InviteSortCriterion m_sortCriteria[6]; + /* 0544 */ uint32_t m_sortType; + /* 0548 */ uint32_t m_pendingNames; + /* 054C */ uint32_t m_signalType; + /* 0550 */ uint32_t m_guildID; + CGCalendarEvent(); + CGCalendarEvent(WOWGUID guid, uint8_t level, int32_t calendarType); ~CGCalendarEvent(); + void Clear(); + void SetTitle(const char* title); + void SetDescription(const char* description); + void SetType(uint32_t type); + void SetRepeatOption(uint32_t repeatOption); + void SetSize(uint32_t size); + bool SetDate(uint32_t month, uint32_t monthDay, uint32_t year); + bool SetTime(uint32_t hour, uint32_t minute); + bool SetLockoutDate(uint32_t month, uint32_t monthDay, uint32_t year); + bool SetLockoutTime(uint32_t hour, uint32_t minute); + void SetTextureID(int32_t textureID); + void SetFlag(uint32_t flag); + void ClearFlag(uint32_t flag); + void SetSignalType(uint32_t signalType); + bool ProcessUpdateEvent(CDataStore* msg); + void InviteRemoved(WOWGUID guid); + void UpdateInviteStatus(WOWGUID guid, uint8_t status, uint32_t responseTime); + void UpdateInviteNotes(WOWGUID guid, const char* notes); + bool CanModerate(uint32_t index); + bool SortInvites(uint32_t criterion, bool toggle); + void SelectInvite(uint32_t index); + bool IsModerator(); + bool AddEvent(); + bool RemoveEvent(); + bool Update(); + bool Invite(const char* name); + bool RemoveInvite(uint32_t index); + bool RemoveInviteByGUID(WOWGUID guid); + bool InviteRSVP(uint32_t status); + bool SignUp(uint8_t tentative); + void UpdateInviteModeratorStatus(WOWGUID guid, uint8_t status); + bool CanSetInviteStatus(uint32_t index, uint32_t status); + void SetInviteStatus(uint32_t index, uint32_t status); + void SetModeratorStatus(uint32_t index, uint32_t status); + bool ProcessGetEvent(CDataStore* msg, int32_t* status); + bool ProcessInitialInviteList(CDataStore* msg); + void AddInvite(uint64_t inviteID, WOWGUID guid, uint8_t level, uint8_t status, uint8_t inviteType, uint32_t responseTime); + EventInviteInfo* GetInvite(WOWGUID guid); + int32_t GetInviteIndex(WOWGUID guid); + int32_t GetSelectedInviteIndex(); }; +const char* GetEventStatusString(uint32_t status); + #endif diff --git a/WoW/Source/Ui/Calendar_Scripts.cpp b/WoW/Source/Ui/Calendar_Scripts.cpp index f7d48a6..f31a431 100644 --- a/WoW/Source/Ui/Calendar_Scripts.cpp +++ b/WoW/Source/Ui/Calendar_Scripts.cpp @@ -13,6 +13,25 @@ #include "Engine/Source/Os/TimeManager.h" #include "Engine/Source/ConsoleBase/ConsoleVar.h" #include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Ui/CalendarEvent.h" +#include "WoW/Source/Ui/ChatFrame.h" +#include "WoW/Source/Ui/ScriptEvents.h" +#include "WoW/Source/Ui/Types.h" +#include "Engine/Source/Base/CDataStore.h" +#include "Engine/Source/FrameXML/LoadXML.h" +#include "Engine/Source/Storm/H/storm.h" +#include "WoW/Source/DB/DBClient/DBCacheInstances.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/ChrClassesRec.h" +#include "WoW/Source/DB/Rec/HolidaysRec.h" +#include "WoW/Source/DB/Rec/LfgDungeonsRec.h" +#include "WoW/Source/DB/Rec/MapDifficultyRec.h" +#include "WoW/Source/DB/Rec/MapRec.h" +#include "WoW/Source/Game/GameClient/NameCache.h" +#include "WoW/Source/Net/Types.h" +#include "WoW/Source/Object/Object.h" +#include "WoW/Source/Object/Player.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" // STATIC: 0x00ACFFB4 static const char* s_monthNames[12] = { "MONTH_JANUARY", "MONTH_FEBRUARY", "MONTH_MARCH", "MONTH_APRIL", "MONTH_MAY", "MONTH_JUNE", "MONTH_JULY", "MONTH_AUGUST", "MONTH_SEPTEMBER", "MONTH_OCTOBER", "MONTH_NOVEMBER", "MONTH_DECEMBER" }; @@ -296,6 +315,1759 @@ static int32_t Script_CalendarGetFirstPendingInvite(lua_State* L) { return 1; } +// VERIFY: 6931d0c9 auto +// OFFSET: 0x005B78D0 +static void NameCacheCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { + WOWGUID key = WOWGUID(); + + if (g_nameDBCache.GetRecord(guid.m_guid, key, nullptr, nullptr, false)) { + Script_SendUniqueSignal(SCRIPT_EVENT_CALENDAR_UPDATE_EVENT_LIST); + } +} + +// VERIFY: 38875a8f auto +// OFFSET: 0x005B8040 +static const char* GetSequenceLabel(uint32_t type, uint32_t index, uint32_t length) { + if (!(type & 0x8) || length <= 1) { + return ""; + } + + if (!index) { + return "START"; + } + + if (index == length - 1) { + return "END"; + } + + return "ONGOING"; +} + +// VERIFY: 876fe382 auto +// OFFSET: 0x005B8080 +static const char* GetInviteRoleLabel(uint32_t flags) { + if (flags & 0x4) { + return "CREATOR"; + } + + if (flags & 0x2) { + return "MODERATOR"; + } + + return ""; +} + +// VERIFY: 38d50b7e auto +// OFFSET: 0x005B80B0 +static bool IsSignUpInvite(const CalendarDayEvent* event) { + return (event->m_type & 0x400) && (event->m_flags & 0x8); +} + +// VERIFY: cba45807 auto +// OFFSET: 0x005B82A0 +static int32_t Script_CalendarGetMaxDate(lua_State* L) { + WowTime date; + date.m_month = 0; + date.m_monthDay = 0; + date.m_year = 31; + date.AddDays(-1, false); + date.SetHourAndMinutes(23u, 59u); + lua_pushnumber(L, date.m_weekDay + 1); + lua_pushnumber(L, date.m_month + 1); + lua_pushnumber(L, date.m_monthDay + 1); + lua_pushnumber(L, date.m_year + 2000); + return 4; +} + +// VERIFY: da43e929 auto +// OFFSET: 0x005B8350 +static int32_t Script_CalendarGetMinHistoryDate(lua_State* L) { + WowTime date; + date.m_weekDay = g_clientGameTime.m_weekDay; + date.m_month = g_clientGameTime.m_month; + date.m_monthDay = g_clientGameTime.m_monthDay; + date.m_year = g_clientGameTime.m_year; + date.AddDays(-14, false); + date.SetHourAndMinutes(0u, 0u); + lua_pushnumber(L, date.m_weekDay + 1); + lua_pushnumber(L, date.m_month + 1); + lua_pushnumber(L, date.m_monthDay + 1); + lua_pushnumber(L, date.m_year + 2000); + return 4; +} + +// VERIFY: e9039fb7 manual +// OFFSET: 0x005B84D0 +static int32_t Script_CalendarEventGetNumInvites(lua_State* L) { + lua_pushnumber(L, CGCalendar::m_curEvent ? CGCalendar::m_curEvent->m_numInvites : 0); + return 1; +} + +// VERIFY: ebc8d474 auto +// OFFSET: 0x005B8510 +static int32_t Script_CalendarContextDeselectEvent(lua_State* L) { + CGCalendar::m_contextEvent.m_eventID = 0; + CGCalendar::m_contextEvent.m_startTime = 0; + CGCalendar::m_contextEvent.m_endTime = 0; + CGCalendar::m_contextEvent.m_holidayID = 0; + CGCalendar::m_contextEvent.unk_0014 = 0; + CGCalendar::m_contextEventInfo = nullptr; + return 0; +} + +// VERIFY: 7a8c4b46 manual +// OFFSET: 0x005B8540 +static int32_t Script_CalendarContextEventClipboard(lua_State* L) { + lua_pushboolean(L, s_eventClipboard.m_eventID != 0); + return 1; +} + +// VERIFY: 90ff2325 auto +// OFFSET: 0x005B8570 +static int32_t Script_CalendarEventSortInvites(lua_State* L) { + if (!lua_isstring(L, 1)) { + luaL_error(L, "Usage: CalendarEventSortInvites(\"criteria\", reverse)"); + } + + uint32_t criterion = 3; + const char* name = lua_tolstring(L, 1, nullptr); + + if (!SStrCmpI(name, "name", STORM_MAX_STR)) { + criterion = 0; + } else if (!SStrCmpI(name, "level", STORM_MAX_STR)) { + criterion = 1; + } else if (!SStrCmpI(name, "class", STORM_MAX_STR)) { + criterion = 2; + } else if (!SStrCmpI(name, "status", STORM_MAX_STR)) { + criterion = 3; + } else if (!SStrCmpI(name, "party", STORM_MAX_STR)) { + criterion = 4; + } else if (!SStrCmpI(name, "notes", STORM_MAX_STR)) { + criterion = 5; + } + + int32_t reverse = StringToBOOL(L, 2, 1); + + if (CGCalendar::m_curEvent && CGCalendar::m_curEvent->SortInvites(criterion, reverse != 0)) { + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_UPDATE_INVITE_LIST, nullptr); + } + + return 0; +} + +// VERIFY: d50e8704 auto +// OFFSET: 0x005B8690 +static int32_t Script_CalendarEventGetInviteSortCriterion(lua_State* L) { + InviteSortCriterion* criterion = CGCalendar::m_curEvent ? &CGCalendar::m_curEvent->m_sortCriteria[CGCalendar::m_curEvent->m_sortType] : nullptr; + uint8_t reverse = 0; + const char* name = ""; + + if (criterion) { + switch (criterion->m_criterion) { + case 0: + name = "name"; + break; + + case 1: + name = "level"; + break; + + case 2: + name = "class"; + break; + + case 3: + name = "status"; + break; + + case 4: + name = "party"; + break; + + case 5: + name = "notes"; + break; + } + + reverse = criterion->m_reverse; + } + + lua_pushstring(L, name); + lua_pushboolean(L, reverse); + return 2; +} + +// VERIFY: e8c2c59f manual +// OFFSET: 0x005B8730 +static int32_t Script_CalendarEventSetStatus(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: CalendarEventSetStatus(index, status)"); + } + + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + uint32_t status = static_cast(lua_tonumber(L, 2)) - 1; + CGCalendar::SetInviteStatus(index, status); + return 0; +} + +// VERIFY: 38960e82 manual +// OFFSET: 0x005B87D0 +static int32_t Script_CalendarEventSetModerator(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarEventSetModerator(index)"); + } + + CGCalendar::SetModeratorStatus(static_cast(lua_tonumber(L, 1)) - 1, 1); + return 0; +} + +// VERIFY: d5897814 manual +// OFFSET: 0x005B8840 +static int32_t Script_CalendarEventClearModerator(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarEventClearModerator(index)"); + } + + CGCalendar::SetModeratorStatus(static_cast(lua_tonumber(L, 1)) - 1, 0); + return 0; +} + +// VERIFY: bbba4c0e auto +// OFFSET: 0x005B88B0 +static int32_t Script_CalendarEventIsModerator(lua_State* L) { + lua_pushboolean(L, CGCalendar::m_curEvent ? CGCalendar::m_curEvent->IsModerator() : false); + return 1; +} + +// VERIFY: a67e5434 manual +// OFFSET: 0x005B88E0 +static int32_t Script_CalendarEventCanModerate(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarEventCanModerate(index)"); + } + + double index = lua_tonumber(L, 1); + lua_pushboolean(L, CGCalendar::m_curEvent ? CGCalendar::m_curEvent->CanModerate(static_cast(index - 1)) : false); + return 1; +} + +// VERIFY: af140e99 auto +// OFFSET: 0x005B8A10 +static int32_t Script_CalendarEventHaveSettingsChanged(lua_State* L) { + if (CGCalendar::m_curEvent) { + lua_pushboolean(L, CGCalendar::m_curEvent->m_changed); + } else { + lua_pushboolean(L, 0); + } + + return 1; +} + +// VERIFY: d3312f5c manual +// OFFSET: 0x005B8A50 +static int32_t Script_CalendarEventCanEdit(lua_State* L) { + bool canEdit = false; + + if (CGCalendar::m_curEvent) { + canEdit = (CGCalendar::m_curEvent->m_flags & 0x40) ? CGGuildInfo::CanEditGuildEvent() : CGCalendar::m_curEvent->IsModerator(); + } + + lua_pushboolean(L, canEdit); + return 1; +} + +// VERIFY: c6dc5211 auto +// OFFSET: 0x005B8AA0 +static int32_t Script_CalendarEventGetCalendarType(lua_State* L) { + if (CGCalendar::m_curEvent) { + lua_pushstring(L, CGCalendar::GetCalendarTypeString(CGCalendar::m_curEvent->m_flags)); + } else { + lua_pushnil(L); + } + + return 1; +} + +// VERIFY: 744ac9ad auto +// OFFSET: 0x005B8AE0 +static int32_t Script_CalendarEventSelectInvite(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarEventSelectInvite(index)"); + } + + uint32_t index = lua_tointeger(L, 1) - 1; + + if (CGCalendar::m_curEvent) { + CGCalendar::m_curEvent->SelectInvite(index); + } + + return 0; +} + +// VERIFY: ce471ee3 auto +// OFFSET: 0x005B8BA0 +static int32_t Script_CalendarCanAddEvent(lua_State* L) { + uint32_t now; + + if (CGCalendar::m_actionPending || ((!unk_BD09AC || !unk_BD09AC->m_intValue) && (now = OsGetAsyncTimeMs(), CGCalendar::m_lastEventTime) && now - CGCalendar::m_lastEventTime < 5000)) { + lua_pushboolean(L, 0); + } else { + lua_pushboolean(L, 1); + } + + return 1; +} + +// VERIFY: 0fd74c9c manual +// OFFSET: 0x005B9AC0 +static int32_t Script_CalendarGetAbsMonth(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarGetAbsMonth(month[, year])"); + } + + int32_t month = static_cast(lua_tonumber(L, 1)) - 1; + int32_t year = CGCalendar::m_absYear; + + if (CGCalendar::m_absYear < 0) { + year = g_clientGameTime.m_year; + CGCalendar::m_absYear = year; + + if (year < 0) { + year = 4; + CGCalendar::m_absYear = 4; + } + } + + if (lua_isnumber(L, 2)) { + year = static_cast(lua_tonumber(L, 2)) - 2000; + } + + int32_t outMonth = 0; + int32_t outYear = 0; + int32_t days = 0; + int32_t weekDay = 0; + CGCalendar::ClampAbsMonthDay(month, year, &outMonth, &outYear, &days, &weekDay); + lua_pushnumber(L, ++outMonth); + outYear += 2000; + lua_pushnumber(L, outYear); + lua_pushnumber(L, static_cast(days)); + lua_pushnumber(L, weekDay + 1); + return 4; +} + +// VERIFY: 85a48470 manual +// OFFSET: 0x005B9CA0 +static int32_t Script_CalendarGetDayEventSequenceInfo(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + luaL_error(L, "Usage: CalendarGetDayEventSequenceInfo([-1.0.1], monthDay, index)"); + } + + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + CalendarDayEvent* event = CGCalendar::GetDayEvent(offset, day, index); + + if (event) { + lua_pushnumber(L, event->m_sequenceIndex); + lua_pushnumber(L, event->m_sequenceLength); + lua_pushstring(L, GetSequenceLabel(event->m_type, event->m_sequenceIndex, event->m_sequenceLength)); + } else { + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushstring(L, ""); + } + + return 3; +} + +// VERIFY: 3219cdf7 manual +// OFFSET: 0x005B9EB0 +static int32_t Script_CalendarOpenEvent(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + luaL_error(L, "Usage: CalendarOpenEvent([-1,0,1], monthDay, index)"); + } + + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + CGCalendar::GetEvent(offset, day, index); + return 0; +} + +// VERIFY: 1318acde manual +// OFFSET: 0x005BA000 +static int32_t Script_CalendarGetRaidInfo(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + luaL_error(L, "Usage: CalendarGetRaidInfo([-1,0,1], monthDay, index)"); + } + + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + CalendarDayEvent* event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + lua_pushnil(L); + lua_pushstring(L, ""); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushstring(L, ""); + return 7; + } + + MapRec* map = g_mapDB.GetRecord(event->m_holidayID); + lua_pushstring(L, map ? map->m_mapName : ""); + lua_pushstring(L, CGCalendar::GetCalendarTypeString(event->m_type)); + lua_pushnumber(L, static_cast(event->m_eventID)); + WowTime date; + WowTime::WowDecodeTime(event->m_startTime, &date); + lua_pushnumber(L, date.m_hour); + lua_pushnumber(L, date.m_minute); + lua_pushnumber(L, static_cast(event->m_endTime + 1)); + MapDifficultyRec* difficulty = GetMapDifficultyEntryByMapIdAndDifficulty(event->m_holidayID, event->m_endTime, nullptr); + + if (!difficulty) { + lua_pushstring(L, ""); + return 7; + } + + lua_pushstring(L, FrameScript_GetText(difficulty->m_difficultystring, -1, GENDER_NOT_APPLICABLE)); + return 7; +} + +// VERIFY: 2faead7e manual +// OFFSET: 0x005BA220 +static int32_t Script_CalendarEventGetInvite(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarEventGetInvite(index)"); + } + + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + CGCalendarEvent* event = CGCalendar::m_curEvent; + EventInviteInfo* invite; + + if (!event || index >= event->m_numInvites || !(invite = event->m_invites.m_data[index])) { + lua_pushnil(L); + lua_pushnumber(L, 0.0); + lua_pushnil(L); + lua_pushnil(L); + lua_pushnil(L); + lua_pushnil(L); + lua_pushboolean(L, 0); + lua_pushinteger(L, 0); + lua_pushnil(L); + return 9; + } + + WOWGUID key = WOWGUID(); + NameCache* name = g_nameDBCache.GetRecord(invite->m_guid.m_guid, key, nullptr, nullptr, false); + lua_pushstring(L, name ? name->m_name : ""); + lua_pushnumber(L, invite->m_level); + ChrClassesRec* classRec = name ? g_chrClassesDB.GetRecord(name->m_class) : nullptr; + + if (classRec) { + lua_pushstring(L, classRec->m_name); + lua_pushstring(L, classRec->m_filename); + } else { + lua_pushstring(L, ""); + lua_pushstring(L, ""); + } + + if (event) { + lua_pushinteger(L, invite->m_status + 1); + } else { + lua_pushinteger(L, 0); + } + + if (invite->m_moderatorStatus == 1) { + lua_pushstring(L, "MODERATOR"); + } else if (invite->m_moderatorStatus == 2) { + lua_pushstring(L, "CREATOR"); + } else { + lua_pushstring(L, ""); + } + + lua_pushboolean(L, ClntObjMgrGetActivePlayer() == invite->m_guid); + lua_pushinteger(L, invite->m_inviteType + 1); + lua_pushstring(L, invite->m_notes); + return 9; +} + +// VERIFY: 1fa94430 manual +// OFFSET: 0x005BA420 +static int32_t Script_CalendarEventGetInviteResponseTime(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarEventGetInviteResponseTime(index)"); + } + + uint32_t index = static_cast(lua_tonumber(L, 1)) - 1; + EventInviteInfo* invite; + + if (CGCalendar::m_curEvent && index < CGCalendar::m_curEvent->m_numInvites && (invite = CGCalendar::m_curEvent->m_invites.m_data[index]) && invite->m_responseTime) { + WowTime date; + WowTime::WowDecodeTime(invite->m_responseTime, &date); + lua_pushnumber(L, date.m_weekDay + 1); + lua_pushnumber(L, date.m_month + 1); + lua_pushnumber(L, date.m_monthDay + 1); + lua_pushnumber(L, date.m_year + 2000); + lua_pushnumber(L, date.m_hour); + lua_pushnumber(L, date.m_minute); + } else { + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + } + + return 6; +} + +// VERIFY: 7b0245c7 auto +// OFFSET: 0x005BA5A0 +static int32_t Script_CalendarRemoveEvent(lua_State* L) { + CGCalendar::RemoveEvent(); + return 0; +} + +// VERIFY: b9dbe177 manual +// OFFSET: 0x005BA5B0 +static int32_t Script_CalendarContextSelectEvent(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + luaL_error(L, "Usage: CalendarContextSelectEvent([-1.0.1], monthDay, index)"); + } + + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + CGCalendar::SelectContextEvent(offset, day, index); + return 0; +} + +// VERIFY: b16e6979 manual +// OFFSET: 0x005BA700 +static int32_t Script_CalendarContextInviteIsPending(lua_State* L) { + uint8_t pending = 0; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + CalendarDayEvent* event = CGCalendar::GetDayEvent(offset, day, index); + + if (event && (event->m_flags & 0x1)) { + pending = 1; + } + } else if (!CGCalendar::m_contextEventInfo) { + luaL_error(L, "Usage: CalendarContextInviteIsPending([-1.0.1], monthDay, index)"); + } + + lua_pushboolean(L, pending); + return 1; +} + +// VERIFY: 7095cce2 manual +// OFFSET: 0x005BA7F0 +static int32_t Script_CalendarContextInviteModeratorStatus(lua_State* L) { + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + CalendarDayEvent* event = CGCalendar::GetDayEvent(offset, day, index); + + if (event) { + if (event->m_flags & 0x4) { + lua_pushstring(L, "CREATOR"); + return 1; + } + + if (event->m_flags & 0x2) { + lua_pushstring(L, "MODERATOR"); + return 1; + } + } + } else if (!CGCalendar::m_contextEventInfo) { + luaL_error(L, "Usage: CalendarContextInviteModeratorStatus([-1.0.1], monthDay, index)"); + } + + lua_pushnil(L); + return 1; +} + +// VERIFY: 7a801c15 manual +// OFFSET: 0x005BA910 +static int32_t Script_CalendarContextInviteStatus(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + lua_pushinteger(L, 0); + return 1; + } + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: CalendarContextInviteStatus([-1.0.1], monthDay, index)"); + } + } + + lua_pushinteger(L, event->m_inviteStatus + 1); + return 1; +} + +// VERIFY: 7ae7f14c manual +// OFFSET: 0x005BAA20 +static int32_t Script_CalendarContextInviteType(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + lua_pushinteger(L, 0); + return 1; + } + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: CalendarContextInviteType([-1.0.1], monthDay, index)"); + } + } + + if ((event->m_type & 0x400) && (event->m_flags & 0x8)) { + lua_pushinteger(L, 2); + } else { + lua_pushinteger(L, 1); + } + + return 1; +} + +// VERIFY: db7fbfc9 manual +// OFFSET: 0x005BAB50 +static int32_t Script_CalendarContextInviteAvailable(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + return 0; + } + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: CalendarContextInviteAvailable([-1.0.1], monthDay, index)"); + } + } + + if (!CGCalendar::m_actionPending && (!(event->m_type & 0x400) || !(event->m_flags & 0x8))) { + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_RSVP)); + msg.Put(event->m_eventID); + msg.Put(event->m_inviteID); + msg.Put(static_cast(1)); + msg.Finalize(); + ClientServices::Send2(&msg); + CGCalendar::m_actionPending = 1; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_ACTION_PENDING, "%b", 1); + } + + return 0; +} + +// VERIFY: 2871e8fd manual +// OFFSET: 0x005BAD00 +static int32_t Script_CalendarContextInviteDecline(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + return 0; + } + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: CalendarContextInviteDecline([-1.0.1], monthDay, index)"); + } + } + + if (!CGCalendar::m_actionPending && (!(event->m_type & 0x400) || !(event->m_flags & 0x8))) { + CDataStore msg; + msg.Put(static_cast(CMSG_CALENDAR_EVENT_RSVP)); + msg.Put(event->m_eventID); + msg.Put(event->m_inviteID); + msg.Put(static_cast(2)); + msg.Finalize(); + ClientServices::Send2(&msg); + CGCalendar::m_actionPending = 1; + FrameScript_SignalEvent(SCRIPT_EVENT_CALENDAR_ACTION_PENDING, "%b", 1); + } + + return 0; +} + +// VERIFY: 519921f4 manual +// OFFSET: 0x005BAEB0 +static int32_t Script_CalendarContextEventCanEdit(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + lua_pushboolean(L, 0); + return 1; + } + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: CalendarContextEventCanEdit([-1.0.1], monthDay, index)"); + } + } + + bool canEdit = (event->m_type & 0x440) ? CGGuildInfo::CanEditGuildEvent() : (event->m_flags & 0x6) != 0; + lua_pushboolean(L, canEdit); + return 1; +} + +// VERIFY: 7a11a5c5 manual +// OFFSET: 0x005BAFC0 +static int32_t Script_CalendarContextEventGetCalendarType(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + lua_pushnil(L); + return 1; + } + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: CalendarContextEventGetCalendarType([-1.0.1], monthDay, index)"); + } + } + + lua_pushstring(L, CGCalendar::GetCalendarTypeString(event->m_type)); + return 1; +} + +// VERIFY: 3aacaae6 manual +// OFFSET: 0x005BB0C0 +static int32_t Script_CalendarEventRemoveInvite(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarEventRemoveInvite(index)"); + } + + CGCalendar::RemoveInvite(static_cast(lua_tonumber(L, 1)) - 1); + return 0; +} + +// VERIFY: 07c234f3 manual +// OFFSET: 0x005BB130 +static int32_t Script_CalendarEventGetStatusOptions(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarEventGetStatusOptions(index)"); + } + + double index = lua_tonumber(L, 1); + CGCalendarEvent* event = CGCalendar::m_curEvent; + + if (!event) { + return 0; + } + + if (!event->IsModerator()) { + CGCalendar::CalendarError("CALENDAR_ERROR_PERMISSIONS", 0); + return 0; + } + + int32_t count = 0; + + for (uint32_t i = 0; i < 9; i++) { + if (event->CanSetInviteStatus(static_cast(index - 1), i)) { + lua_pushinteger(L, i + 1); + lua_pushstring(L, FrameScript_GetText(GetEventStatusString(i), -1, GENDER_NOT_APPLICABLE)); + count += 2; + } + } + + return count; +} + +// VERIFY: cf28788c manual +// OFFSET: 0x005BB210 +static int32_t Script_CalendarEventSetTitle(lua_State* L) { + const char* title = nullptr; + + if (lua_isstring(L, 1)) { + title = lua_tolstring(L, 1, nullptr); + } + + if (!CGCalendar::m_curEvent) { + return 0; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return 0; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return 0; + } + + CGCalendar::m_curEvent->SetTitle(title); + return 0; +} + +// VERIFY: 25ceecec manual +// OFFSET: 0x005BB280 +static int32_t Script_CalendarEventSetDescription(lua_State* L) { + const char* description = nullptr; + + if (lua_isstring(L, 1)) { + description = lua_tolstring(L, 1, nullptr); + } + + if (!CGCalendar::m_curEvent) { + return 0; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return 0; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return 0; + } + + CGCalendar::m_curEvent->SetDescription(description); + return 0; +} + +// VERIFY: d21c122b manual +// OFFSET: 0x005BB2F0 +static int32_t Script_CalendarEventSetType(lua_State* L) { + if (!lua_isnumber(L, 1)) { + return 0; + } + + double type = lua_tonumber(L, 1); + + if (!CGCalendar::m_curEvent) { + return 0; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return 0; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return 0; + } + + CGCalendar::m_curEvent->SetType(static_cast(type - 1)); + return 0; +} + +// VERIFY: cca8fd6c manual +// OFFSET: 0x005BB380 +static int32_t Script_CalendarEventSetRepeatOption(lua_State* L) { + if (!lua_isnumber(L, 1)) { + return 0; + } + + double repeatOption = lua_tonumber(L, 1); + + if (!CGCalendar::m_curEvent) { + return 0; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return 0; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return 0; + } + + CGCalendar::m_curEvent->SetRepeatOption(static_cast(repeatOption - 1)); + return 0; +} + +// VERIFY: 8038ff09 manual +// OFFSET: 0x005BB410 +static int32_t Script_CalendarEventSetSize(lua_State* L) { + if (!lua_isnumber(L, 1)) { + return 0; + } + + double size = lua_tonumber(L, 1); + + if (!CGCalendar::m_curEvent) { + return 0; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return 0; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return 0; + } + + CGCalendar::m_curEvent->SetSize(static_cast(size)); + return 0; +} + +// VERIFY: 7fce121b manual +// OFFSET: 0x005BB4A0 +static int32_t Script_CalendarEventSetDate(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + luaL_error(L, "Usage: CalendarEventSetDate(month, day, year)"); + } + + uint32_t month = static_cast(lua_tonumber(L, 1)) - 1; + uint32_t monthDay = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t year = static_cast(lua_tonumber(L, 3)) - 2000; + + if (!CGCalendar::SetEventDate(month, monthDay, year)) { + CGCalendar::CalendarError("CALENDAR_ERROR_INVALID_DATE", 0); + } + + return 0; +} + +// VERIFY: 04c6caa7 manual +// OFFSET: 0x005BB5A0 +static int32_t Script_CalendarEventSetTime(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: CalendarEventSetTime(hour, minute)"); + } + + uint32_t hour = static_cast(lua_tonumber(L, 1)); + uint32_t minute = static_cast(lua_tonumber(L, 2)); + + if (!CGCalendar::SetEventTime(hour, minute)) { + CGCalendar::CalendarError("CALENDAR_ERROR_INVALID_TIME", 0); + } + + return 0; +} + +// VERIFY: d498f994 manual +// OFFSET: 0x005BB650 +static int32_t Script_CalendarEventSetLockoutDate(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + luaL_error(L, "Usage: CalendarEventSetLockoutDate(month, day, year)"); + } + + uint32_t month = static_cast(lua_tonumber(L, 1)) - 1; + uint32_t monthDay = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t year = static_cast(lua_tonumber(L, 3)) - 2000; + + if (!CGCalendar::SetEventLockoutDate(month, monthDay, year)) { + CGCalendar::CalendarError("CALENDAR_ERROR_INVALID_DATE", 0); + } + + return 0; +} + +// VERIFY: a04a738e manual +// OFFSET: 0x005BB750 +static int32_t Script_CalendarEventSetLockoutTime(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: CalendarEvenSettLockoutTime(hour, minute)"); + } + + uint32_t hour = static_cast(lua_tonumber(L, 1)); + uint32_t minute = static_cast(lua_tonumber(L, 2)); + + if (!CGCalendar::SetEventLockoutTime(hour, minute)) { + CGCalendar::CalendarError("CALENDAR_ERROR_INVALID_TIME", 0); + } + + return 0; +} + +// VERIFY: c559f66b manual +// OFFSET: 0x005BB800 +static int32_t Script_CalendarEventSetTextureID(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarEventSetTextureID(textureIndex)"); + } + + CGCalendar::SetEventTextureID(static_cast(lua_tonumber(L, 1)) - 1); + return 0; +} + +// VERIFY: 20d6b24e manual +// OFFSET: 0x005BB870 +static int32_t Script_CalendarEventSetLocked(lua_State* L) { + if (!CGCalendar::m_curEvent) { + return 0; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return 0; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return 0; + } + + CGCalendar::m_curEvent->SetFlag(0x10); + return 0; +} + +// VERIFY: 0d84b1df manual +// OFFSET: 0x005BB8B0 +static int32_t Script_CalendarEventClearLocked(lua_State* L) { + if (!CGCalendar::m_curEvent) { + return 0; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return 0; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return 0; + } + + CGCalendar::m_curEvent->ClearFlag(0x10); + return 0; +} + +// VERIFY: 3a4a63e9 manual +// OFFSET: 0x005BB8F0 +static int32_t Script_CalendarEventSetAutoApprove(lua_State* L) { + if (!CGCalendar::m_curEvent) { + return 0; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return 0; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return 0; + } + + CGCalendar::m_curEvent->SetFlag(0x20); + return 0; +} + +// VERIFY: b8e3ea42 manual +// OFFSET: 0x005BB930 +static int32_t Script_CalendarEventClearAutoApprove(lua_State* L) { + if (!CGCalendar::m_curEvent) { + return 0; + } + + if (CGCalendar::m_curEvent->m_flags & 0x40) { + if (!CGGuildInfo::CanEditGuildEvent()) { + return 0; + } + } else if (!CGCalendar::m_curEvent->IsModerator()) { + return 0; + } + + CGCalendar::m_curEvent->ClearFlag(0x20); + return 0; +} + +// VERIFY: fb18b910 manual +// OFFSET: 0x005BB970 +static int32_t Script_CalendarEventGetTextures(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarEventGetTextures(eventType)"); + } + + double type = lua_tonumber(L, 1); + uint32_t list; + + if (type == 2) { + list = 0; + } else if (type == 1) { + list = 1; + } else { + return 0; + } + + TSFixedArray* textures = &s_eventTextures[list]; + uint32_t count = textures->Count(); + + if (!count) { + return 0; + } + + lua_checkstack(L, 4 * count); + + for (uint32_t i = 0; i < count; i++) { + LfgDungeonsRec* dungeon = g_lfgDungeonsDB.GetRecord(textures->m_data[i]); + + if (dungeon) { + lua_pushstring(L, dungeon->m_name); + lua_pushstring(L, dungeon->m_textureFilename); + lua_pushinteger(L, dungeon->m_expansionLevel); + MapDifficultyRec* difficulty; + + if (type == 1 && (difficulty = GetMapDifficultyEntryByMapIdAndDifficulty(dungeon->m_mapID, dungeon->m_difficulty, nullptr))) { + lua_pushstring(L, FrameScript_GetText(difficulty->m_difficultystring, -1, GENDER_NOT_APPLICABLE)); + } else { + lua_pushstring(L, ""); + } + } else { + lua_pushstring(L, ""); + lua_pushstring(L, ""); + lua_pushinteger(L, -1); + lua_pushstring(L, ""); + } + } + + return 4 * count; +} + +// VERIFY: 38118389 auto +// OFFSET: 0x005BBB00 +static int32_t Script_CalendarEventGetSelectedInvite(lua_State* L) { + if (CGCalendar::m_curEvent) { + lua_pushinteger(L, CGCalendar::m_curEvent->GetSelectedInviteIndex() + 1); + } else { + lua_pushinteger(L, 0); + } + + return 1; +} + +// VERIFY: a3403abe auto +// OFFSET: 0x005BCC70 +static int32_t Script_CalendarAddEvent(lua_State* L) { + if ((unk_BD09AC && unk_BD09AC->m_intValue) || CGGameUI::CanPerformAction(19)) { + CGCalendar::AddEvent(); + } + + return 0; +} + +// VERIFY: c17b27f8 auto +// OFFSET: 0x005BCCA0 +static int32_t Script_CalendarNewEvent(lua_State* L) { + CGCalendar::CreatePlayerEvent(); + return 0; +} + +// VERIFY: fe8e8f86 manual +// OFFSET: 0x005BCCB0 +static int32_t Script_CalendarMassInviteGuild(lua_State* L) { + if (!lua_isnumber(L, 1) && !lua_isnumber(L, 2) && !lua_isnumber(L, 3)) { + luaL_error(L, "Usage: CalendarMassInviteGuild(minLevel, maxLevel, minRank)"); + } + + uint32_t minLevel = static_cast(lua_tonumber(L, 1)); + uint32_t maxLevel = static_cast(lua_tonumber(L, 2)); + uint32_t minRank = static_cast(lua_tonumber(L, 3)) - 1; + CGCalendar::GuildFilter(minLevel, maxLevel, minRank); + return 0; +} + +// VERIFY: d59cfbfe auto +// OFFSET: 0x005BCD80 +static int32_t Script_CalendarNewGuildAnnouncement(lua_State* L) { + CGCalendar::CreateGuildAnnouncement(); + return 0; +} + +// VERIFY: 0cbef7d1 auto +// OFFSET: 0x005BCD90 +static int32_t Script_CalendarNewGuildEvent(lua_State* L) { + CGCalendar::CreateGuildEvent(); + return 0; +} + +// VERIFY: 9b89693d manual +// OFFSET: 0x005BCE60 +static int32_t Script_CalendarMassInviteArenaTeam(lua_State* L) { + if (!lua_isnumber(L, 1)) { + luaL_error(L, "Usage: CalendarNewArenaTeamEvent(index)"); + } + + CGCalendar::ArenaTeam(static_cast(lua_tonumber(L, 1)) - 1); + return 0; +} + +// VERIFY: a049e522 auto +// OFFSET: 0x005BCED0 +static int32_t Script_CalendarUpdateEvent(lua_State* L) { + if ((unk_BD09AC && unk_BD09AC->m_intValue) || CGGameUI::CanPerformAction(19)) { + CGCalendar::UpdateEvent(); + } + + return 0; +} + +// VERIFY: 49208bb9 auto +// OFFSET: 0x005BCF00 +static int32_t Script_CalendarEventInvite(lua_State* L) { + const char* name = lua_tolstring(L, 1, nullptr); + + if (name) { + CGCalendar::Invite(name); + } + + return 0; +} + +// VERIFY: cdbacdde manual +// OFFSET: 0x005BCF30 +static int32_t Script_CalendarContextInviteTentative(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + return 0; + } + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: Script_CalendarContextInviteTentative([-1.0.1], monthDay, index)"); + } + } + + if ((event->m_type & 0x400) && (event->m_flags & 0x8)) { + CGCalendar::ContextMenuEventSignUp(event, 1); + } else { + CGCalendar::ContextMenuInviteRSVP(event, 8); + } + + return 0; +} + +// VERIFY: 38fb5e57 manual +// OFFSET: 0x005BD040 +static int32_t Script_CalendarContextInviteRemove(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + return 0; + } + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: CalendarContextInviteRemove([-1.0.1], monthDay, index)"); + } + } + + if (event->m_type & 0x401) { + CGCalendar::ContextMenuInviteRemove(event); + } + + return 0; +} + +// VERIFY: c079a593 manual +// OFFSET: 0x005BD130 +static int32_t Script_CalendarContextEventSignUp(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + return 0; + } + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: CalendarContextEventSignUp([-1.0.1], monthDay, index)"); + } + } + + if (event->m_type & 0x400) { + CGCalendar::ContextMenuEventSignUp(event, 0); + } + + return 0; +} + +// VERIFY: 7056c0b4 manual +// OFFSET: 0x005BD220 +static int32_t Script_CalendarContextEventRemove(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + return 0; + } + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: Script_CalendarContextEventRemove([-1.0.1], monthDay, index)"); + } + } + + bool allowed = (event->m_type & 0x440) ? CGGuildInfo::CanEditGuildEvent() : (event->m_flags & 0x6) != 0; + + if (!allowed) { + CGCalendar::CalendarError("CALENDAR_ERROR_PERMISSIONS", 0); + return 0; + } + + CGCalendar::ContextMenuEventRemove(event); + return 0; +} + +// VERIFY: 16d6ee8d manual +// OFFSET: 0x005BD340 +static int32_t Script_CalendarContextEventCopy(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + return 0; + } + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: Script_CalendarContextEventCopy([-1.0.1], monthDay, index)"); + } + } + + bool allowed = (event->m_type & 0x440) ? CGGuildInfo::CanEditGuildEvent() : (event->m_flags & 0x6) != 0; + + if (!allowed) { + CGCalendar::CalendarError("CALENDAR_ERROR_PERMISSIONS", 0); + return 0; + } + + CGCalendar::ContextMenuEventCopy(event); + return 0; +} + +// VERIFY: dd49574d manual +// OFFSET: 0x005BD460 +static int32_t Script_CalendarContextEventPaste(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) { + luaL_error(L, "Usage: Script_CalendarContextEventPaste([-1.0.1], monthDay)"); + } + + int32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + CGCalendar::ContextMenuEventPaste(offset, day); + return 0; +} + +// VERIFY: 5653bdb6 manual +// OFFSET: 0x005BD4F0 +static int32_t Script_CalendarContextEventCanComplain(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: CalendarContextEventCanComplain([-1.0.1], monthDay, index)"); + } + } + + if (CGCalendar::m_actionPending || !CGCalendar::CanComplainAboutEvent(event)) { + lua_pushboolean(L, 0); + } else { + lua_pushboolean(L, 1); + } + + return 1; +} + +// VERIFY: 5e617422 manual +// OFFSET: 0x005BD600 +static int32_t Script_CalendarContextEventComplain(lua_State* L) { + CalendarDayEvent* event; + + if (lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) { + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + event = CGCalendar::GetDayEvent(offset, day, index); + } else { + event = CGCalendar::m_contextEventInfo; + + if (!event) { + luaL_error(L, "Usage: CalendarContextEventComplain([-1.0.1], monthDay, index)"); + } + } + + CGCalendar::Complain(event); + return 0; +} + +// VERIFY: 0adb7ecc manual +// OFFSET: 0x005BD6E0 +static int32_t Script_CalendarEventAvailable(lua_State* L) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && !CGCalendar::m_actionPending && CGCalendar::m_curEvent && (!(CGCalendar::m_curEvent->m_flags & 0x400) || CGCalendar::m_curEvent->m_guildID != player->m_player->m_playerGuildid)) { + if (CGCalendar::m_curEvent->InviteRSVP(1)) { + CGCalendar::SetActionPending(1); + } + } + + return 0; +} + +// VERIFY: 2d764a19 auto +// OFFSET: 0x005BD750 +static int32_t Script_CalendarEventTentative(lua_State* L) { + CGCalendar::InviteRSVP(8); + return 0; +} + +// VERIFY: 5ef72a73 manual +// OFFSET: 0x005BD760 +static int32_t Script_CalendarEventDecline(lua_State* L) { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (player && !CGCalendar::m_actionPending && CGCalendar::m_curEvent && (!(CGCalendar::m_curEvent->m_flags & 0x400) || CGCalendar::m_curEvent->m_guildID != player->m_player->m_playerGuildid)) { + if (CGCalendar::m_curEvent->InviteRSVP(2)) { + CGCalendar::SetActionPending(1); + } + } + + return 0; +} + +// VERIFY: 3c288e81 auto +// OFFSET: 0x005BD7D0 +static int32_t Script_CalendarEventSignUp(lua_State* L) { + CGCalendar::EventSignUp(); + return 0; +} + +// VERIFY: 08db3b12 auto +// OFFSET: 0x005BD7E0 +static int32_t Script_OpenCalendar(lua_State* L) { + if (!CGCalendar::m_openedCalendar) { + CGCalendar::GetCalendar(); + } + + return 0; +} + +// VERIFY: df735662 manual +// OFFSET: 0x005BD8A0 +static int32_t Script_CalendarGetEventInfo(lua_State* L) { + CGCalendarEvent* event = CGCalendar::m_curEvent; + + if (!event) { + lua_pushnil(L); + lua_pushnil(L); + lua_pushstring(L, ""); + + for (uint32_t i = 0; i < 16; i++) { + lua_pushnumber(L, 0.0); + } + + lua_pushnil(L); + lua_pushnil(L); + lua_pushnil(L); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushstring(L, ""); + return 25; + } + + char title[128]; + SStrCopy(title, event->m_title, STORM_MAX_STR); + ProfanityFilter(title, false, false); + lua_pushstring(L, title); + char description[1024]; + SStrCopy(description, event->m_description, STORM_MAX_STR); + ProfanityFilter(description, false, false); + lua_pushstring(L, description); + WOWGUID key = WOWGUID(); + NameCache* creator = g_nameDBCache.GetRecord(event->m_creatorGUID.m_guid, key, NameCacheCallback, nullptr, false); + lua_pushstring(L, creator ? creator->m_name : ""); + lua_pushnumber(L, static_cast(event->m_type + 1)); + lua_pushnumber(L, static_cast(event->m_repeatOption + 1)); + lua_pushnumber(L, event->m_maxSize); + lua_pushnumber(L, CGCalendar::GetTextureIndex(event->m_type, event->m_textureID) + 1); + lua_pushnumber(L, event->m_date.m_weekDay + 1); + lua_pushnumber(L, event->m_date.m_month + 1); + lua_pushnumber(L, event->m_date.m_monthDay + 1); + lua_pushnumber(L, event->m_date.m_year + 2000); + lua_pushnumber(L, event->m_date.m_hour); + lua_pushnumber(L, event->m_date.m_minute); + lua_pushnumber(L, event->m_lockoutDate.m_weekDay + 1); + lua_pushnumber(L, event->m_lockoutDate.m_month + 1); + lua_pushnumber(L, event->m_lockoutDate.m_monthDay + 1); + lua_pushnumber(L, event->m_lockoutDate.m_year + 2000); + lua_pushnumber(L, event->m_lockoutDate.m_hour); + lua_pushnumber(L, event->m_lockoutDate.m_minute); + + if (event->m_flags & 0x10) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + if (event->m_flags & 0x20) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + if (CGCalendar::HasPendingInvite(event->m_eventID)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + EventInviteInfo* invite = event->GetInvite(ClntObjMgrGetActivePlayer()); + + if (invite) { + lua_pushnumber(L, invite->m_status + 1); + lua_pushnumber(L, invite->m_inviteType + 1); + } else if (event->m_flags & 0x400) { + lua_pushnumber(L, 8.0); + lua_pushnumber(L, 2.0); + } else { + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + } + + lua_pushstring(L, CGCalendar::GetCalendarTypeString(event->m_flags)); + return 25; +} + +// VERIFY: fed5193b auto +// OFFSET: 0x005BDD90 +static int32_t Script_CalendarEventHasPendingInvite(lua_State* L) { + if (CGCalendar::m_curEvent) { + lua_pushboolean(L, CGCalendar::HasPendingInvite(CGCalendar::m_curEvent->m_eventID)); + } else { + lua_pushboolean(L, 0); + } + + return 1; +} + +// VERIFY: a3de76cf manual +// OFFSET: 0x005C0FB0 +static void PushDayEventTexture(lua_State* L, CalendarDayEvent* event) { + const char* texture = ""; + + if (event) { + if (event->m_type & 0x8) { + DYNAMICHOLIDAYHASH* dynamic = s_dynamicHolidays.Ptr(static_cast(event->m_eventID), HASHKEY_NONE()); + + if (dynamic) { + lua_pushstring(L, dynamic->m_textureFileName); + return; + } + + HolidaysRec* holiday = g_holidaysDB.GetRecord(static_cast(event->m_eventID)); + + if (holiday) { + lua_pushstring(L, holiday->m_textureFileName); + return; + } + } else if ((event->m_type & 0x543) && event->m_textureID >= 0) { + LfgDungeonsRec* dungeon = g_lfgDungeonsDB.GetRecord(event->m_textureID); + + if (dungeon) { + texture = dungeon->m_textureFilename; + } + } + } + + lua_pushstring(L, texture); +} + +// VERIFY: 0e6d8df4 manual +// OFFSET: 0x005C1070 +static int32_t Script_CalendarGetDayEvent(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + luaL_error(L, "Usage: CalendarGetDayEvent([-1.0.1], monthDay, index)"); + } + + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + CalendarDayEvent* event = CGCalendar::GetDayEvent(offset, day, index); + + if (!event) { + lua_pushnil(L); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushstring(L, ""); + lua_pushstring(L, ""); + lua_pushnumber(L, 0.0); + lua_pushstring(L, ""); + lua_pushstring(L, ""); + lua_pushnumber(L, 0.0); + lua_pushstring(L, ""); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushnumber(L, 0.0); + lua_pushstring(L, ""); + return 15; + } + + WowTime start; + WowTime::WowDecodeTime(event->m_startTime, &start); + + if (event->m_type & 0x8) { + lua_pushstring(L, GetHolidayName(static_cast(event->m_eventID))); + } else if (event->m_type & 0x280) { + MapRec* map = g_mapDB.GetRecord(event->m_holidayID); + + if (map) { + lua_pushstring(L, map->m_mapName); + } else { + lua_pushstring(L, ""); + } + } else { + char title[128]; + SStrCopy(title, event->m_title, STORM_MAX_STR); + ProfanityFilter(title, false, false); + lua_pushstring(L, title); + } + + lua_pushnumber(L, start.m_hour); + lua_pushnumber(L, start.m_minute); + lua_pushstring(L, CGCalendar::GetCalendarTypeString(event->m_type)); + lua_pushstring(L, GetSequenceLabel(event->m_type, event->m_sequenceIndex, event->m_sequenceLength)); + lua_pushnumber(L, event->m_eventType + 1); + PushDayEventTexture(L, event); + lua_pushstring(L, GetInviteRoleLabel(event->m_flags)); + lua_pushnumber(L, event->m_inviteStatus + 1); + WOWGUID key = WOWGUID(); + NameCache* creator = g_nameDBCache.GetRecord(event->m_creatorGUID.m_guid, key, NameCacheCallback, nullptr, false); + lua_pushstring(L, creator ? creator->m_name : ""); + lua_pushnumber(L, (event->m_type & 0x280) ? static_cast(event->m_endTime + 1) : 0.0); + lua_pushnumber(L, IsSignUpInvite(event) + 1); + lua_pushnumber(L, event->m_sequenceIndex + 1); + lua_pushnumber(L, event->m_sequenceLength); + MapDifficultyRec* difficulty; + + if (!(event->m_type & 0x280) || !(difficulty = GetMapDifficultyEntryByMapIdAndDifficulty(event->m_holidayID, event->m_endTime, nullptr))) { + lua_pushstring(L, ""); + return 15; + } + + lua_pushstring(L, FrameScript_GetText(difficulty->m_difficultystring, -1, GENDER_NOT_APPLICABLE)); + return 15; +} + +// VERIFY: 2dbe6f35 manual +// OFFSET: 0x005C1480 +static int32_t Script_CalendarGetHolidayInfo(lua_State* L) { + if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + luaL_error(L, "Usage: CalendarGetHolidayInfo([-1,0,1], monthDay, index)"); + } + + uint32_t offset = static_cast(lua_tonumber(L, 1)); + uint32_t day = static_cast(lua_tonumber(L, 2)) - 1; + uint32_t index = static_cast(lua_tonumber(L, 3)) - 1; + CalendarDayEvent* event = CGCalendar::GetDayEvent(offset, day, index); + const char* name; + const char* description; + + if (!event || !(name = GetHolidayName(static_cast(event->m_eventID)), description = GetHolidayDescription(static_cast(event->m_eventID)), name) || !description) { + lua_pushnil(L); + lua_pushnil(L); + lua_pushnil(L); + return 3; + } + + lua_pushstring(L, name); + lua_pushstring(L, description); + const char* texture = ""; + DYNAMICHOLIDAYHASH* dynamic = CalendarGetHolidayInfo(static_cast(event->m_eventID)); + + if (dynamic) { + texture = dynamic->m_textureFileName; + } else { + HolidaysRec* holiday = g_holidaysDB.GetRecord(static_cast(event->m_eventID)); + + if (holiday) { + texture = holiday->m_textureFileName; + } + } + + lua_pushstring(L, texture); + return 3; +} + // STATIC: 0x00AD0030 static FrameScript_Method s_ScriptFunctions[] = { { "CalendarGetMonthNames", &Script_CalendarGetMonthNames }, diff --git a/WoW/Source/Ui/GuildInfo.cpp b/WoW/Source/Ui/GuildInfo.cpp index 03ba0d0..81af65b 100644 --- a/WoW/Source/Ui/GuildInfo.cpp +++ b/WoW/Source/Ui/GuildInfo.cpp @@ -7,6 +7,7 @@ #include "WoW/Source/Ui/Types.h" #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/Object/Player.h" #include "WoW/Source/Ui/GuildBankFrame.h" #include "WoW/Source/Game/ValidateName.h" #include "WoW/Source/Ui/CGAutoCompleteName.h" @@ -568,3 +569,15 @@ void GuildInfoCacheCallback(int32_t id, const WOWGUID& guid, void* param, bool s CGGuildInfo::SaveToFile(); } } + +// VERIFY: b420c257 manual +// OFFSET: 0x005CBCA0 +bool CGGuildInfo::CanEditGuildEvent() { + CGPlayer_C* player = ClntObjMgrGetActivePlayerObj(); + + if (!player || !player->m_player->m_playerGuildid) { + return false; + } + + return (CGGuildInfo::m_rankInfo[player->m_player->m_playerGuildrank].m_rights >> 20) & 1; +} diff --git a/WoW/Source/Ui/GuildInfo.h b/WoW/Source/Ui/GuildInfo.h index 75c3884..b78fe9f 100644 --- a/WoW/Source/Ui/GuildInfo.h +++ b/WoW/Source/Ui/GuildInfo.h @@ -81,6 +81,7 @@ class CGGuildInfo { static void QueryPermissions(); static void SetShowOffline(int32_t show); static int32_t GetSelectedMemberIndex(); + static bool CanEditGuildEvent(); }; extern int32_t s_guildControlRank; diff --git a/WoW/Source/WowSvcs/WowSvcsClient/FriendList.cpp b/WoW/Source/WowSvcs/WowSvcsClient/FriendList.cpp index 3360267..0f02c5a 100644 --- a/WoW/Source/WowSvcs/WowSvcsClient/FriendList.cpp +++ b/WoW/Source/WowSvcs/WowSvcsClient/FriendList.cpp @@ -1938,3 +1938,15 @@ int32_t Packet_SMSG_FRIEND_STATUS(void* param, NETMESSAGE msgId, uint32_t time, return 1; } + +// VERIFY: 762d6418 manual +// OFFSET: 0x006B3920 +bool FriendList::IsFriend(WOWGUID guid) { + for (uint32_t i = 0; i < 100; i++) { + if (this->m_friends[i].m_guid == guid) { + return true; + } + } + + return false; +}