diff --git a/src/glue/CCharacterSelection.cpp b/src/glue/CCharacterSelection.cpp index 546609e..d1b6124 100644 --- a/src/glue/CCharacterSelection.cpp +++ b/src/glue/CCharacterSelection.cpp @@ -1,10 +1,24 @@ #include "glue/CCharacterSelection.hpp" +#include "client/ClientServices.hpp" #include "glue/CGlueMgr.hpp" +#include "glue/CRealmList.hpp" #include "model/CM2Shared.hpp" +#include "net/Connection.hpp" #include "ui/CSimpleModelFFX.hpp" TSGrowableArray CCharacterSelection::s_characterList; CSimpleModelFFX* CCharacterSelection::s_modelFrame; +uint32_t CCharacterSelection::s_restrictHuman; +uint32_t CCharacterSelection::s_restrictDwarf; +uint32_t CCharacterSelection::s_restrictGnome; +uint32_t CCharacterSelection::s_restrictNightElf; +uint32_t CCharacterSelection::s_restrictDraenei; +uint32_t CCharacterSelection::s_restrictOrc; +uint32_t CCharacterSelection::s_restrictTroll; +uint32_t CCharacterSelection::s_restrictTauren; +uint32_t CCharacterSelection::s_restrictUndead; +uint32_t CCharacterSelection::s_restrictBloodElf; +int32_t CCharacterSelection::s_selectionIndex; void CCharacterSelection::ClearCharacterList() { // TODO @@ -14,6 +28,13 @@ void CCharacterSelection::ClearCharacterModel() { // TODO } +void CCharacterSelection::EnumerateCharactersCallback(const CHARACTER_INFO& info, void* param) { + auto display = CCharacterSelection::s_characterList.New(); + display->info = info; + + // TODO +} + void CCharacterSelection::OnGetCharacterList() { CCharacterSelection::s_characterList.SetCount(0); @@ -53,4 +74,61 @@ void CCharacterSelection::SetBackgroundModel(const char* modelPath) { void CCharacterSelection::UpdateCharacterList() { // TODO + + CCharacterSelection::s_characterList.SetCount(0); + + CCharacterSelection::s_restrictHuman = 0; + CCharacterSelection::s_restrictDwarf = 0; + CCharacterSelection::s_restrictGnome = 0; + CCharacterSelection::s_restrictNightElf = 0; + CCharacterSelection::s_restrictDraenei = 0; + CCharacterSelection::s_restrictOrc = 0; + CCharacterSelection::s_restrictTroll = 0; + CCharacterSelection::s_restrictTauren = 0; + CCharacterSelection::s_restrictUndead = 0; + CCharacterSelection::s_restrictBloodElf = 0; + + // Enumerate characters + + ClientServices::Connection()->EnumerateCharacters(CCharacterSelection::EnumerateCharactersCallback, nullptr); + + // No characters + + if (CCharacterSelection::s_characterList.Count() == 0) { + CCharacterSelection::s_selectionIndex = 0; + + // TODO Sub4E3CD0(); + + FrameScript_SignalEvent(8, "%d", CCharacterSelection::s_selectionIndex + 1); + + CCharacterSelection::ClearCharacterModel(); + + FrameScript_SignalEvent(7, nullptr); + + return; + } + + // At least one character + + CCharacterSelection::s_restrictHuman = ClientServices::Connection()->m_restrictHuman; + CCharacterSelection::s_restrictDwarf = ClientServices::Connection()->m_restrictDwarf; + CCharacterSelection::s_restrictGnome = ClientServices::Connection()->m_restrictGnome; + CCharacterSelection::s_restrictNightElf = ClientServices::Connection()->m_restrictNightElf; + CCharacterSelection::s_restrictDraenei = ClientServices::Connection()->m_restrictDraenei; + CCharacterSelection::s_restrictOrc = ClientServices::Connection()->m_restrictOrc; + CCharacterSelection::s_restrictTroll = ClientServices::Connection()->m_restrictTroll; + CCharacterSelection::s_restrictTauren = ClientServices::Connection()->m_restrictTauren; + CCharacterSelection::s_restrictUndead = ClientServices::Connection()->m_restrictUndead; + CCharacterSelection::s_restrictBloodElf = ClientServices::Connection()->m_restrictBloodElf; + + CRealmList::s_preferredCategory = 0; + + // TODO g_lastCharacterIndex stuff + int32_t selectionIndex = 0; + + CCharacterSelection::s_selectionIndex = selectionIndex; + + // TODO Sub4E3CD0(); + + FrameScript_SignalEvent(8, "%d", CCharacterSelection::s_selectionIndex + 1); } diff --git a/src/glue/CCharacterSelection.hpp b/src/glue/CCharacterSelection.hpp index bcb0d7c..fd1896f 100644 --- a/src/glue/CCharacterSelection.hpp +++ b/src/glue/CCharacterSelection.hpp @@ -1,11 +1,13 @@ #ifndef GLUE_C_CHARACTER_SELECTION_HPP #define GLUE_C_CHARACTER_SELECTION_HPP +#include "net/Types.hpp" #include class CSimpleModelFFX; struct CharacterSelectionDisplay { + CHARACTER_INFO info; // TODO }; @@ -14,10 +16,22 @@ class CCharacterSelection { // Static variables static TSGrowableArray s_characterList; static CSimpleModelFFX* s_modelFrame; + static uint32_t s_restrictHuman; + static uint32_t s_restrictDwarf; + static uint32_t s_restrictGnome; + static uint32_t s_restrictNightElf; + static uint32_t s_restrictDraenei; + static uint32_t s_restrictOrc; + static uint32_t s_restrictTroll; + static uint32_t s_restrictTauren; + static uint32_t s_restrictUndead; + static uint32_t s_restrictBloodElf; + static int32_t s_selectionIndex; // Static functions static void ClearCharacterList(); static void ClearCharacterModel(); + static void EnumerateCharactersCallback(const CHARACTER_INFO& info, void* param); static void OnGetCharacterList(); static void RenderPrep(); static void SetBackgroundModel(const char* modelPath); diff --git a/src/net/connection/ClientConnection.cpp b/src/net/connection/ClientConnection.cpp index c21864a..c1d2f48 100644 --- a/src/net/connection/ClientConnection.cpp +++ b/src/net/connection/ClientConnection.cpp @@ -170,6 +170,14 @@ int32_t ClientConnection::Disconnect() { return 1; } +void ClientConnection::EnumerateCharacters(ENUMERATE_CHARACTERS_CALLBACK callback, void* param) { + // TODO Assertion-like thing + + for (uint32_t i = 0; i < this->m_characterList.Count(); i++) { + callback(this->m_characterList[i], param); + } +} + void ClientConnection::GetCharacterList() { this->Initiate(COP_GET_CHARACTERS, 43, nullptr); diff --git a/src/net/connection/ClientConnection.hpp b/src/net/connection/ClientConnection.hpp index ec28c3e..4b49b9b 100644 --- a/src/net/connection/ClientConnection.hpp +++ b/src/net/connection/ClientConnection.hpp @@ -7,6 +7,8 @@ class RealmResponse; +typedef void (*ENUMERATE_CHARACTERS_CALLBACK)(const CHARACTER_INFO&, void*); + class ClientConnection : public RealmConnection { public: // Member variables @@ -32,6 +34,7 @@ class ClientConnection : public RealmConnection { void Complete(int32_t result, int32_t errorCode); void Connect(); int32_t Disconnect(); + void EnumerateCharacters(ENUMERATE_CHARACTERS_CALLBACK callback, void* param); void GetCharacterList(); void Initiate(WOWCS_OPS op, int32_t errorCode, void (*cleanup)()); int32_t IsConnected();