diff --git a/Source/Client/Mode/GameMode.cpp b/Source/Client/Mode/GameMode.cpp index 6d5ffccbb..50d004278 100644 --- a/Source/Client/Mode/GameMode.cpp +++ b/Source/Client/Mode/GameMode.cpp @@ -2059,7 +2059,7 @@ int CGameMode::SendMsg(int event, int argument1, int argument2, int argument3, i target = *reinterpret_cast(&g_session.spAndHomunculusStats[8]); } else { const bool mercenary = g_session.IsMercenarySkill(skill->id) != 0; - target = mercenary ? *reinterpret_cast(&g_session.companionTargetState[8]) : g_session.m_aid; + target = mercenary ? g_session.m_mercenaryAid : g_session.m_aid; } this->SendMsg(MM_USE_SKILL, skill->id, target, argument2, argument3); this->SendMsg(MM_HANG_USE_SKILL, 0, 0, 0, 0); @@ -3739,7 +3739,7 @@ int CGameMode::SendMsg(int event, int argument1, int argument2, int argument3, i } return 0; case MENUID_MER_FOLLOW: { - auto* actor = static_cast(this->scene->GetGameActorByAID(*reinterpret_cast(&g_session.companionTargetState[8]))); + auto* actor = static_cast(this->scene->GetGameActorByAID(g_session.m_mercenaryAid)); if (actor && actor->merAI && *reinterpret_cast(actor->merAI + 4)) { float value[6] = {}; const int type = 9; @@ -7426,7 +7426,7 @@ void CGameMode::InitializeState() { *reinterpret_cast(&g_session.spAndHomunculusStats[0x08]) = -1; g_session.homunAlive = 0; g_session.ClearHomunStatus(); - *reinterpret_cast(&g_session.companionTargetState[0x08]) = -1; + g_session.m_mercenaryAid = -1; g_session.mercenaryAlive = 0; g_session.ResetMercenaryStats(); g_windowMgr.FocusWindow01C8Edit(); @@ -8146,7 +8146,7 @@ void CGameMode::ProcessActorClick(int& handled, ActorPickInfo* pick, CGameActor* } const std::uint32_t& homunAid = *reinterpret_cast(&g_session.spAndHomunculusStats[8]); - const std::uint32_t& mercenaryAid = *reinterpret_cast(&g_session.companionTargetState[8]); + const std::uint32_t& mercenaryAid = g_session.m_mercenaryAid; if (g_session.homunAlive != 0) { if (g_mouse.buttons[1] == 1 && HIBYTE(GetAsyncKeyState(VK_MENU))) { if (HIBYTE(GetAsyncKeyState(VK_SHIFT))) { @@ -8492,7 +8492,7 @@ int CGameMode::ProcessGroundClick(int result) { } const std::uint32_t& homunAid = *reinterpret_cast(&g_session.spAndHomunculusStats[8]); - const std::uint32_t& mercenaryAid = *reinterpret_cast(&g_session.companionTargetState[8]); + const std::uint32_t& mercenaryAid = g_session.m_mercenaryAid; if (g_session.homunAlive != 0) { if (HIBYTE(GetAsyncKeyState(VK_MENU)) && g_mouse.buttons[1] == 1) { if (g_session.selectHomunEnemy != 0) { @@ -10188,7 +10188,7 @@ void CGameMode::ProcessActorPick(int& handled, ActorPickInfo* pick, CGameActor* } const std::uint32_t& homunAid = *reinterpret_cast(&g_session.spAndHomunculusStats[8]); - const std::uint32_t& mercenaryAid = *reinterpret_cast(&g_session.companionTargetState[8]); + const std::uint32_t& mercenaryAid = g_session.m_mercenaryAid; if ((attack || this->scene->isSiegeMode != 0) && actor->render.state != 3 && !skillMode && g_session.homunAlive != 0 && g_mouse.buttons[1] == 1 && HIBYTE(GetAsyncKeyState(VK_MENU))) { if (HIBYTE(GetAsyncKeyState(VK_SHIFT))) { CGameActor* homun = static_cast(this->scene->GetGameActorByAID(homunAid)); @@ -10490,7 +10490,7 @@ int CGameMode::HandleActorPick(ActorPickInfo* pick, int result) { const unsigned char forceOption = g_serviceOptions.Get(0x6D); const int& siegeMode = *reinterpret_cast(&g_session.interactionFlags[4]); const std::uint32_t& homunAid = *reinterpret_cast(&g_session.spAndHomunculusStats[8]); - const std::uint32_t& mercenaryAid = *reinterpret_cast(&g_session.companionTargetState[8]); + const std::uint32_t& mercenaryAid = g_session.m_mercenaryAid; GuildInfo* guildInfo = &g_guildInfo; if (pick->accountId != g_session.m_aid) { diff --git a/Source/Client/Mode/GameModeHandlers.cpp b/Source/Client/Mode/GameModeHandlers.cpp index c9e8b8b89..8984f8715 100644 --- a/Source/Client/Mode/GameModeHandlers.cpp +++ b/Source/Client/Mode/GameModeHandlers.cpp @@ -928,12 +928,12 @@ void CGameMode::ReceiveHomunculusInfo(const unsigned char* data) { g_session.RefreshHomunculusInfo(); *reinterpret_cast(g_session.companionSkillPoints) = packet->skillPoints; g_session.InvalidateWindowFrames(); - *reinterpret_cast(&g_session.companionTargetState[4]) = packet->attackRange; + g_session.m_homunAttackRange = packet->attackRange; if (g_windowMgr.homunculusSkillWnd) { g_windowMgr.homunculusSkillWnd->SendMsg(nullptr, UM_REFRESHITEM, 0, 0, 0, 0); } - int& notified = *reinterpret_cast(&g_session.companionTargetState[0]); + int& notified = g_session.m_homunHungerNotified; const std::int16_t state = packet->hunger; if ((state == 1 || state == 5 || state == 10) && notified != state) { g_windowMgr.SendNotice(UIM_PUSHINTOCHATHISTORY, reinterpret_cast(LookupMessage(MSI_HOMUN_HUNGRY)), 0xFF, 0, 0, 0); @@ -956,7 +956,7 @@ void CGameMode::ReceiveHomunculusInfo3(const unsigned char* data) { g_session.homunHunger = packet->hunger; g_session.RefreshHomunculusInfo(); - int& notified = *reinterpret_cast(&g_session.companionTargetState[0]); + int& notified = g_session.m_homunHungerNotified; const int state = packet->hunger; switch (state) { case 1: @@ -990,7 +990,7 @@ void CGameMode::ReceiveHomunculusInfo3(const unsigned char* data) { g_windowMgr.homunculusSkillWnd->SendMsg(nullptr, UM_REFRESHITEM, 0, 0, 0, 0); } - *reinterpret_cast(&g_session.companionTargetState[4]) = packet->attackRange; + g_session.m_homunAttackRange = packet->attackRange; if (UIHomunInfoWnd* window = static_cast(g_windowMgr.homunInfoWnd)) { window->expBar->FillBackground(0xFFFFFF); window->expBar->SetValues(g_session.m_homunExp, g_session.m_homunMaxExp); @@ -1032,12 +1032,12 @@ void CGameMode::ReceiveHomunculusInfo2(const unsigned char* data) { g_session.RefreshHomunculusInfo(); *reinterpret_cast(g_session.companionSkillPoints) = packet->skillPoints; g_session.InvalidateWindowFrames(); - *reinterpret_cast(&g_session.companionTargetState[4]) = packet->attackRange; + g_session.m_homunAttackRange = packet->attackRange; if (g_windowMgr.homunculusSkillWnd) { g_windowMgr.homunculusSkillWnd->SendMsg(nullptr, UM_REFRESHITEM, 0, 0, 0, 0); } - int& notified = *reinterpret_cast(&g_session.companionTargetState[0]); + int& notified = g_session.m_homunHungerNotified; const std::int16_t state = packet->hunger; if ((state == 1 || state == 5 || state == 10) && notified != state) { g_windowMgr.SendNotice(UIM_PUSHINTOCHATHISTORY, reinterpret_cast(LookupMessage(MSI_HOMUN_HUNGRY)), 0xFF, 0, 0, 0); diff --git a/Source/Client/Mode/GameModePackets.cpp b/Source/Client/Mode/GameModePackets.cpp index 0fbe6cd28..567b02215 100644 --- a/Source/Client/Mode/GameModePackets.cpp +++ b/Source/Client/Mode/GameModePackets.cpp @@ -25154,9 +25154,9 @@ void CGameMode::ProcessIncomingPackets() { case 1: case 5: case 10: - if (*reinterpret_cast(g_session.companionTargetState) != *reinterpret_cast(g_gameModePacketBuffer + 0x1D)) { + if (g_session.m_homunHungerNotified != *reinterpret_cast(g_gameModePacketBuffer + 0x1D)) { g_windowMgr.SendNotice(UIM_PUSHINTOCHATHISTORY, reinterpret_cast(LookupMessage(MSI_HOMUN_HUNGRY)), 0xFF, 0, 0, 0); - *reinterpret_cast(g_session.companionTargetState) = *reinterpret_cast(g_gameModePacketBuffer + 0x1D); + g_session.m_homunHungerNotified = *reinterpret_cast(g_gameModePacketBuffer + 0x1D); } break; } @@ -25186,7 +25186,7 @@ void CGameMode::ProcessIncomingPackets() { if (g_windowMgr.homunculusSkillWnd) { g_windowMgr.homunculusSkillWnd->SendMsg(nullptr, UM_REFRESHITEM, 0, 0, 0, 0); } - reinterpret_cast(g_session.companionTargetState)[1] = *reinterpret_cast(g_gameModePacketBuffer + 0x4B); + g_session.m_homunAttackRange = *reinterpret_cast(g_gameModePacketBuffer + 0x4B); break; case ID_ZC_NPC_BARTER_MARKET_ITEMINFO: { g_barterMarketItemMgr->Clear(); diff --git a/Source/Client/Replay/Replay.cpp b/Source/Client/Replay/Replay.cpp index d5a75f2b6..c9c0fa920 100644 --- a/Source/Client/Replay/Replay.cpp +++ b/Source/Client/Replay/Replay.cpp @@ -1091,9 +1091,9 @@ std::vector CSession::BuildCompanionReplayRecords() { AppendRecord(records, MakeReplayRecord(5130, &this->homunAlive, sizeof(this->homunAlive))); AppendRecord(records, MakeReplayRecord(5131, &this->m_traceAi, sizeof(this->m_traceAi))); AppendRecord(records, MakeReplayRecord(5132, &this->m_homunActionState, sizeof(this->m_homunActionState))); - AppendRecord(records, MakeReplayRecord(5133, &this->companionTargetState[0x0], 4)); - AppendRecord(records, MakeReplayRecord(5134, &this->companionTargetState[0x4], 4)); - AppendRecord(records, MakeReplayRecord(5201, &this->companionTargetState[0x8], 4)); + AppendRecord(records, MakeReplayRecord(5133, &this->m_homunHungerNotified, sizeof(this->m_homunHungerNotified))); + AppendRecord(records, MakeReplayRecord(5134, &this->m_homunAttackRange, sizeof(this->m_homunAttackRange))); + AppendRecord(records, MakeReplayRecord(5201, &this->m_mercenaryAid, sizeof(this->m_mercenaryAid))); AppendRecord(records, MakeReplayRecord(5202, this->m_mercenaryName, sizeof(this->m_mercenaryName))); AppendRecord(records, MakeReplayRecord(5203, &this->m_mercenaryStats[0], sizeof(this->m_mercenaryStats[0]))); AppendRecord(records, MakeReplayRecord(5204, &this->m_mercenaryStats[1], sizeof(this->m_mercenaryStats[1]))); diff --git a/Source/Client/Session/Session.cpp b/Source/Client/Session/Session.cpp index a33947d4c..04d2137f5 100644 --- a/Source/Client/Session/Session.cpp +++ b/Source/Client/Session/Session.cpp @@ -3005,8 +3005,8 @@ void CSession::Init() { this->homunAlive = 0; this->m_traceAi = 0; this->m_homunActionState = 0; - *reinterpret_cast(&this->companionTargetState[0x00]) = 0; - *reinterpret_cast(&this->companionTargetState[0x04]) = 0; + this->m_homunHungerNotified = 0; + this->m_homunAttackRange = 0; this->moveHomunEnemy = 0; this->selectHomunEnemy = 0; this->attackHomunEnemy = 0; @@ -3100,7 +3100,7 @@ void CSession::Init() { this->m_currentHotkey = 0; this->petGid = 0xFFFFFFFF; *reinterpret_cast(&this->spAndHomunculusStats[0x08]) = -1; - *reinterpret_cast(&this->companionTargetState[0x08]) = -1; + this->m_mercenaryAid = -1; this->m_guildMemberListSort = true; this->m_blockPrivateTab = false; this->swapEquipmentFlag[0] = 0; diff --git a/Source/Client/Session/Session.h b/Source/Client/Session/Session.h index 414a8f17f..5577a2398 100644 --- a/Source/Client/Session/Session.h +++ b/Source/Client/Session/Session.h @@ -458,7 +458,9 @@ public: /* 5614 */ int homunAlive; /* 5618 */ int m_traceAi; /* 561C */ int m_homunActionState; - /* 5620 */ unsigned char companionTargetState[0xC]; + /* 5620 */ int m_homunHungerNotified; + /* 5624 */ int m_homunAttackRange; + /* 5628 */ std::uint32_t m_mercenaryAid; /* 562C */ char m_mercenaryName[32]; /* 564C */ int m_mercenaryStats[8]; /* 566C */ int m_mercenaryHp; diff --git a/Source/Client/Session/SessionPredicates.cpp b/Source/Client/Session/SessionPredicates.cpp index 07592bc83..d0d1be38c 100644 --- a/Source/Client/Session/SessionPredicates.cpp +++ b/Source/Client/Session/SessionPredicates.cpp @@ -100,7 +100,7 @@ int CSession::IsMercenaryAid(std::uint32_t aid) const { if (aid == 0xFFFFFFFF) { return false; } - return aid == *reinterpret_cast(&this->companionTargetState[8]); + return aid == this->m_mercenaryAid; } // OFFSET: 0x00E1DE30 @@ -110,7 +110,7 @@ int CSession::IsCompanionAid(std::uint32_t aid) const { return 0; } if (aid == *reinterpret_cast(&this->spAndHomunculusStats[8]) || - aid == *reinterpret_cast(&this->companionTargetState[8]) || aid == this->petGid || + aid == this->m_mercenaryAid || aid == this->petGid || aid == static_cast(this->elementalGid)) { return 1; } diff --git a/Source/Contents/Actors/MercenaryAI.cpp b/Source/Contents/Actors/MercenaryAI.cpp index 3def77682..9124728b0 100644 --- a/Source/Contents/Actors/MercenaryAI.cpp +++ b/Source/Contents/Actors/MercenaryAI.cpp @@ -58,7 +58,7 @@ bool IsHomunAid(std::uint32_t aid) { // INLINED bool IsMercenaryAid(std::uint32_t aid) { - return aid != 0xFFFFFFFF && aid == *reinterpret_cast(&g_session.companionTargetState[8]); + return aid != 0xFFFFFFFF && aid == g_session.m_mercenaryAid; } // INLINED @@ -273,7 +273,7 @@ int AiHomunAttack(lua_State* state) { if (!g_session.IsHomunAid(aid)) { return 0; } - if (*reinterpret_cast(&g_session.companionTargetState[8]) != 0 && g_session.IsMercenaryAid(target)) { + if (g_session.m_mercenaryAid != 0 && g_session.IsMercenaryAid(target)) { return 0; } @@ -455,7 +455,7 @@ int AiHomunGetV(lua_State* state) { } case V_ATTACKRANGE: { - int range = *reinterpret_cast(&g_session.companionTargetState[4]); + int range = g_session.m_homunAttackRange; if (!actor || range == 0) { lua_pushnumber(state, -1.0); return 1; @@ -589,7 +589,7 @@ int AiMercenaryGetV(lua_State* state) { skillLevel = static_cast(luaL_checknumber(state, 4)); } - std::uint32_t mercAid = *reinterpret_cast(&g_session.companionTargetState[8]); + std::uint32_t mercAid = g_session.m_mercenaryAid; if (actor->render.accountId != g_session.m_aid && !g_session.IsCompanionAid(actor->render.accountId)) { CGameActor* targetActor = static_cast(static_cast(g_modeMgr.GetGameMode())->scene->GetGameActorByAID(mercAid)); if (targetActor) { @@ -676,7 +676,7 @@ int AiMercenaryGetV(lua_State* state) { int level = static_cast(luaL_checknumber(state, 4)); range = static_cast(g_modeMgr.GetGameMode())->GetSkillAttackRange(skillId, level); } - std::uint32_t mercAid = *reinterpret_cast(&g_session.companionTargetState[8]); + std::uint32_t mercAid = g_session.m_mercenaryAid; result = static_cast(ClampTargetAttackRange(mercAid, range)); } lua_pushnumber(state, result); diff --git a/Source/Contents/ClientState.cpp b/Source/Contents/ClientState.cpp index c1dbfb15e..081b7add2 100644 --- a/Source/Contents/ClientState.cpp +++ b/Source/Contents/ClientState.cpp @@ -674,15 +674,15 @@ std::uint32_t CSession::ReadReplayCompanions(const std::vector& d offset += header.bytes; break; case 5133: - std::memcpy(&this->companionTargetState[0], data.data() + offset, header.bytes); + std::memcpy(&this->m_homunHungerNotified, data.data() + offset, header.bytes); offset += header.bytes; break; case 5134: - std::memcpy(&this->companionTargetState[4], data.data() + offset, header.bytes); + std::memcpy(&this->m_homunAttackRange, data.data() + offset, header.bytes); offset += header.bytes; break; case 5201: - std::memcpy(&this->companionTargetState[8], data.data() + offset, header.bytes); + std::memcpy(&this->m_mercenaryAid, data.data() + offset, header.bytes); offset += header.bytes; break; case 5202: diff --git a/Source/Contents/Jobs/JobInheritance.cpp b/Source/Contents/Jobs/JobInheritance.cpp index bc6f85f2a..e88b600cb 100644 --- a/Source/Contents/Jobs/JobInheritance.cpp +++ b/Source/Contents/Jobs/JobInheritance.cpp @@ -1334,7 +1334,7 @@ int CSession::GetPetTargetAid() const { target = static_cast(actor)->hitTargetAid; } - aid = *reinterpret_cast(&this->companionTargetState[8]); + aid = this->m_mercenaryAid; if (aid != 0 && (mode = static_cast(g_modeMgr.GetGameMode())) != nullptr && (actor = mode->scene->GetGameActorByAID(aid)) != nullptr) { target = static_cast(actor)->hitTargetAid; diff --git a/Source/Contents/Messenger/ClientMessenger.cpp b/Source/Contents/Messenger/ClientMessenger.cpp index f86399bb4..44aa29f54 100644 --- a/Source/Contents/Messenger/ClientMessenger.cpp +++ b/Source/Contents/Messenger/ClientMessenger.cpp @@ -6237,7 +6237,7 @@ void CGameMode::Zc_Mer_Init(const unsigned char* data) { const MercenaryInitPacket* packet = reinterpret_cast(data); g_session.m_mercSkills.clear(); CRenderObject* actor = this->scene->GetGameActorByAID(packet->aid); - *reinterpret_cast(&g_session.companionTargetState[8]) = packet->aid; + g_session.m_mercenaryAid = packet->aid; g_session.mercenaryAlive = 1; if (actor != nullptr) { g_session.m_mercenaryClass = static_cast(actor)->GetEffectiveJob(-1); diff --git a/Source/UI/Window/UIWindowMgr.cpp b/Source/UI/Window/UIWindowMgr.cpp index 95f1faec1..c7331cfa4 100644 --- a/Source/UI/Window/UIWindowMgr.cpp +++ b/Source/UI/Window/UIWindowMgr.cpp @@ -4451,9 +4451,7 @@ bool UIWindowMgr::ProcessShortcutKey(int action) { if (g_session.mercenaryAlive != 0) { g_session.ResetMercenaryStats(); if (CMode* mode = g_modeMgr.GetGameMode()) { - std::uint32_t aid; - std::memcpy(&aid, &g_session.companionTargetState[8], sizeof(aid)); - CGameActor* actor = static_cast(static_cast(mode)->scene->GetGameActorByAID(aid)); + CGameActor* actor = static_cast(static_cast(mode)->scene->GetGameActorByAID(g_session.m_mercenaryAid)); if (actor && actor->HasActiveMercenaryAI()) { AiCommand command; command.type = 9;