diff --git a/Source/Client/Session.h b/Source/Client/Session.h index 1025757..1a1c074 100644 --- a/Source/Client/Session.h +++ b/Source/Client/Session.h @@ -233,6 +233,7 @@ public: const char* GetPetString(int id); const char* GetPetTalkName(int job); const char* GetPetTalkActionName(int action); + void GetPetTalkText(int job, int hungerState, int action, char* text); const char* GetMonsterTalkEventName(int event); bool UpdateHomunSkill(const CSkillInfo& value, unsigned char notify); bool UpdateMercSkill(const CSkillInfo& value, unsigned char notify); diff --git a/Source/Contents/PetTalk.cpp b/Source/Contents/PetTalk.cpp index d3c6492..81baa4f 100644 --- a/Source/Contents/PetTalk.cpp +++ b/Source/Contents/PetTalk.cpp @@ -1,4 +1,9 @@ #include "Client/Session.h" +#include "Contents/MessageTable.h" + +#include +#include +#include // OFFSET: 0x00E0AD10 // FUNCTION: fn_23805 @@ -30,3 +35,65 @@ const char* CSession::GetPetTalkActionName(int action) { return "normal"; } } + +// OFFSET: 0x00E12470 +// FUNCTION: fn_23815 +void CSession::GetPetTalkText(int job, int hungerState, int action, char* text) { + *text = '\0'; + char name[256]; + std::strcpy(name, "monster_talk_table"); + XmlNode* node = this->m_petTalkTable.FindChild(DecodeMessageRot(name)); + if (node == nullptr) { + return; + } + + std::strcpy(name, g_session.GetPetTalkName(job)); + node = node->FindChild(DecodeMessageRot(name)); + if (node == nullptr) { + return; + } + + const char* hunger; + switch (hungerState) { + case 1: + hunger = "bit_hungry"; + break; + case 2: + hunger = "noting"; + break; + case 3: + hunger = "full"; + break; + case 4: + hunger = "so_full"; + break; + default: + hunger = "hungry"; + break; + } + std::strcpy(name, hunger); + node = node->FindChild(DecodeMessageRot(name)); + if (node == nullptr) { + return; + } + + const char* actionName = g_session.GetPetTalkActionName(action); + std::strcpy(name, actionName); + XmlNode* entry = node->FindChild(DecodeMessageRot(name)); + if (entry == nullptr) { + return; + } + + std::vector talks; + do { + talks.push_back(entry->Text().c_str()); + std::strcpy(name, actionName); + entry = entry->FindSibling(DecodeMessageRot(name)); + } while (entry != nullptr); + + const int count = static_cast(talks.size()); + if (count != 0) { + std::strcpy(text, talks[std::rand() % count]); + DecodeMessageRot(text); + } +}