feat(glue): add realm and character handling (#7)

* fix(build): make project compilable

* feat(glue): update Character Selection screen to support switching

* fix(ui): fix CSimpleFontString::GetHeight() to use proper method

* feat(db): add static database classes from whoa-autocode

* feat(ui): use class and area IDs for Character Selection

* chore(db): update ItemRandomPropertiesRec

* feat(glue): update CCharacterSelection methods

* chore(db): uncomment DB records

* feat(glue): implement character deletion

* feat(gx): update supported text tags in GxuDetermineQuotedCode

* fix(ui): fix CSimpleFontString to use the FixedColor flag only if the string does not contain color tags

* feat(net): implement GrunLogin::LogOff

* feat(net): implement NetClient::Disconnect

* feat(login): implement trimming of realm name in LoginResponse::HandleRealmData

* feat(net): implement proper disconnection from login and realm servers

* feat(net): implement PING/PONG messages

* feat(net): add NetClient::Destroy method

* feat(net): implement ClientServices::GetRealmList (second request of Realm List)

* feat(glue): implement CGlueMgr::PollRealmList

* feat(glue): implement CGlueMgr::PollCreateCharacter

* chore(glue): add skeleton of CCharacterComponent class

* fix(build): fix build using latest features

* fix(glue): kill gotos in CGlueMgr::NetDisconnectHandler

* fix(build): include SDL3

---------

Co-authored-by: superp00t <superp00t@tutanota.com>
This commit is contained in:
VDm 2025-04-17 01:32:37 +04:00 committed by GitHub
parent 50e37d16bc
commit 957a4c7e2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
633 changed files with 1729 additions and 227 deletions

View file

@ -0,0 +1 @@
#include "glue/CCharacterComponent.hpp"

View file

@ -0,0 +1,17 @@
#ifndef GLUE_C_CHARACTER_COMPONENT_HPP
#define GLUE_C_CHARACTER_COMPONENT_HPP
#include "net/Types.hpp"
#include <storm/Array.hpp>
class CSimpleModelFFX;
class CM2Model;
class CCharacterComponent {
public:
// Static variables
// Static functions
};
#endif // GLUE_C_CHARACTER_COMPONENT_HPP

View file

@ -0,0 +1,8 @@
#include "glue/CCharacterCreation.hpp"
float CCharacterCreation::m_charFacing = 0.0;
CharacterCreationDisplay CCharacterCreation::m_character = {};
void CCharacterCreation::Initialize() {
CCharacterCreation::m_charFacing = 0.0;
}

View file

@ -0,0 +1,25 @@
#ifndef GLUE_C_CHARACTER_CREATION_HPP
#define GLUE_C_CHARACTER_CREATION_HPP
#include "net/Types.hpp"
#include <storm/Array.hpp>
class CSimpleModelFFX;
class CM2Model;
struct CharacterCreationDisplay {
CHARACTER_CREATE_INFO m_characterInfo;
CM2Model* m_characterModel;
};
class CCharacterCreation {
public:
// Static variables
static float m_charFacing;
static CharacterCreationDisplay m_character;
// Static functions
static void Initialize();
};
#endif // GLUE_C_CHARACTER_CREATION_HPP

View file

@ -1,34 +1,61 @@
#include "glue/CCharacterSelection.hpp"
#include "model/CM2Model.hpp"
#include "model/CM2Shared.hpp"
#include "ui/CSimpleModelFFX.hpp"
#include "client/ClientServices.hpp"
#include "client/Client.hpp"
#include "console/CVar.hpp"
#include "net/Connection.hpp"
#include "clientobject/Player_C.hpp"
#include "db/Db.hpp"
CSimpleModelFFX* CCharacterSelection::m_modelFrame = nullptr;
uint32_t CCharacterSelection::m_characterCount = 0;
float CCharacterSelection::m_charFacing = 0.0f;
uint32_t CCharacterSelection::m_restrictHuman = 0;
uint32_t CCharacterSelection::m_restrictDwarf = 0;
uint32_t CCharacterSelection::m_restrictGnome = 0;
uint32_t CCharacterSelection::m_restrictNightElf = 0;
uint32_t CCharacterSelection::m_restrictDraenei = 0;
uint32_t CCharacterSelection::m_restrictOrc = 0;
uint32_t CCharacterSelection::m_restrictTroll = 0;
uint32_t CCharacterSelection::m_restrictTauren = 0;
uint32_t CCharacterSelection::m_restrictUndead = 0;
uint32_t CCharacterSelection::m_restrictBloodElf = 0;
TSGrowableArray<CharacterSelectionDisplay> CCharacterSelection::s_characterList;
CSimpleModelFFX* CCharacterSelection::s_modelFrame;
float CCharacterSelection::s_charFacing = 0.0f;
int32_t CCharacterSelection::m_selectionIndex = 0;
CharacterSelectionDisplay::CharacterSelectionDisplay()
: m_characterModel(nullptr) {
}
void CCharacterSelection::Initialize() {
// Empty method
}
void CCharacterSelection::RenderPrep() {
// TODO
}
void CCharacterSelection::SetBackgroundModel(const char* modelPath) {
if (!CCharacterSelection::s_modelFrame || !modelPath || !*modelPath) {
if (!CCharacterSelection::m_modelFrame || !modelPath || !*modelPath) {
return;
}
auto model = CCharacterSelection::s_modelFrame->m_model;
auto model = CCharacterSelection::m_modelFrame->m_model;
// Check if already set
if (model && !SStrCmpI(modelPath, model->m_shared->m_filePath, STORM_MAX_STR)) {
return;
}
CCharacterSelection::s_modelFrame->SetModel(modelPath);
CCharacterSelection::m_modelFrame->SetModel(modelPath);
// TODO BYTE1(CCharacterSelection::m_modelFrame->simplemodelffx_dword510[3]) = 1;
model = CCharacterSelection::s_modelFrame->m_model;
model = CCharacterSelection::m_modelFrame->m_model;
if (model) {
// TODO lighting callback + arg
@ -37,8 +64,48 @@ void CCharacterSelection::SetBackgroundModel(const char* modelPath) {
}
}
void CCharacterSelection::EnumerateCharactersCallback(CHARACTER_INFO& info, void* param) {
auto character = CCharacterSelection::s_characterList.New();
character->m_characterInfo = info;
// TODO: LoadAddOnEnableState(a1 + 8);
}
void CCharacterSelection::ShowCharacter() {
auto index = CCharacterSelection::m_selectionIndex;
if (index < 0 || index >= CCharacterSelection::GetNumCharacters()) {
return;
}
// TODO
CCharacterSelection::m_charFacing = 0.0;
auto& character = CCharacterSelection::s_characterList[index];
if (character.m_characterModel) {
// TODO
return;
}
auto rec = Player_C_GetModelName(character.m_characterInfo.raceID, character.m_characterInfo.sexID);
STORM_ASSERT(rec);
if (!rec->m_modelName) {
// TODO
return;
}
auto scene = CCharacterSelection::m_modelFrame->GetScene();
character.m_characterModel = scene->CreateModel(rec->m_modelName, 0);
}
void CCharacterSelection::SetCharFacing(float facing) {
// TODO:
if (!CCharacterSelection::m_characterCount || !CCharacterSelection::GetNumCharacters()) {
return;
}
auto character = CCharacterSelection::s_characterList[CCharacterSelection::m_selectionIndex];
if (character.m_characterModel) {
character.m_characterModel->SetWorldTransform(C3Vector(), facing, 1.0);
}
}
void CCharacterSelection::ClearCharacterList() {
@ -46,24 +113,46 @@ void CCharacterSelection::ClearCharacterList() {
void CCharacterSelection::UpdateCharacterList() {
// TODO: ClearAddOnEnableState(0);
// TODO: Proper implementation
auto& received = ClientServices::Connection()->m_characterList;
CCharacterSelection::s_characterList.SetCount(received.Count());
for (uint32_t i = 0; i < received.Count(); ++i) {
CCharacterSelection::s_characterList[i].m_characterInfo = received[i];
}
CCharacterSelection::s_characterList.SetCount(0);
if (CCharacterSelection::GetNumCharacters()) {
int32_t currentIndex = 0;
FrameScript_SignalEvent(8, "%d", currentIndex + 1);
CCharacterSelection::m_restrictHuman = 0;
CCharacterSelection::m_restrictDwarf = 0;
CCharacterSelection::m_restrictGnome = 0;
CCharacterSelection::m_restrictNightElf = 0;
CCharacterSelection::m_restrictDraenei = 0;
CCharacterSelection::m_restrictOrc = 0;
CCharacterSelection::m_restrictTroll = 0;
CCharacterSelection::m_restrictTauren = 0;
CCharacterSelection::m_restrictUndead = 0;
CCharacterSelection::m_restrictBloodElf = 0;
ClientServices::EnumerateCharacters(&CCharacterSelection::EnumerateCharactersCallback, nullptr);
if (CCharacterSelection::s_characterList.Count()) {
// TODO: Apply restrictions (m_restrictHuman, etc)
// TODO: CRealmList::m_preferredCategory = 0;
int32_t selectionIndex = Client::g_lastCharacterIndex->GetInt();
if (selectionIndex < 0 || selectionIndex >= CCharacterSelection::s_characterList.Count()) {
selectionIndex = 0;
}
CCharacterSelection::m_selectionIndex = selectionIndex;
CCharacterSelection::ShowCharacter();
FrameScript_SignalEvent(8, "%d", CCharacterSelection::m_selectionIndex + 1);
} else {
int32_t currentIndex = 0;
FrameScript_SignalEvent(8, "%d", currentIndex + 1);
CCharacterSelection::m_selectionIndex = 0;
CCharacterSelection::ShowCharacter();
FrameScript_SignalEvent(8, "%d", CCharacterSelection::m_selectionIndex + 1);
if (CCharacterSelection::m_modelFrame) {
// TODO
}
}
FrameScript_SignalEvent(7, nullptr);
}
uint32_t CCharacterSelection::GetNumCharacters() {
return s_characterList.Count();
return CCharacterSelection::s_characterList.Count();
}

View file

@ -5,21 +5,40 @@
#include "net/Types.hpp"
class CSimpleModelFFX;
class CM2Model;
struct CharacterSelectionDisplay {
CharacterSelectionDisplay();
CHARACTER_INFO m_characterInfo;
CM2Model* m_characterModel;
};
class CCharacterSelection {
public:
// Static variables
static CSimpleModelFFX* m_modelFrame;
static uint32_t m_characterCount;
static float m_charFacing;
static uint32_t m_restrictHuman;
static uint32_t m_restrictDwarf;
static uint32_t m_restrictGnome;
static uint32_t m_restrictNightElf;
static uint32_t m_restrictDraenei;
static uint32_t m_restrictOrc;
static uint32_t m_restrictTroll;
static uint32_t m_restrictTauren;
static uint32_t m_restrictUndead;
static uint32_t m_restrictBloodElf;
static TSGrowableArray<CharacterSelectionDisplay> s_characterList;
static CSimpleModelFFX* s_modelFrame;
static float s_charFacing;
static int32_t m_selectionIndex;
// Static functions
static void Initialize();
static void RenderPrep();
static void SetBackgroundModel(const char* modelPath);
static void EnumerateCharactersCallback(CHARACTER_INFO& info, void* param);
static void ShowCharacter();
static void SetCharFacing(float facing);
static void ClearCharacterList();
static void UpdateCharacterList();

View file

@ -1,6 +1,8 @@
#include "glue/CGlueMgr.hpp"
#include "glue/CRealmList.hpp"
#include "glue/CCharacterSelection.hpp"
#include "glue/CCharacterCreation.hpp"
#include "console/Console.hpp"
#include "client/Client.hpp"
#include "client/ClientServices.hpp"
#include "gx/Coordinate.hpp"
@ -67,6 +69,7 @@ int32_t CGlueMgr::m_reload;
int32_t CGlueMgr::m_scandllOkayToLogIn = 1; // TODO
float CGlueMgr::m_screenHeight;
float CGlueMgr::m_screenWidth;
int32_t CGlueMgr::m_clientKickReason;
int32_t CGlueMgr::m_showedDisconnect;
CSimpleTop* CGlueMgr::m_simpleTop;
int32_t CGlueMgr::m_suspended;
@ -229,6 +232,61 @@ void CGlueMgr::GetCharacterList() {
}
}
int32_t CGlueMgr::NetDisconnectHandler(const void* eventData, void*) {
bool v11 = CGlueMgr::m_idleState != IDLE_ACCOUNT_LOGIN;
CGlueMgr::m_idleState = IDLE_NONE;
CGlueMgr::m_showedDisconnect = 0;
if (CGlueMgr::m_disconnectPending) {
ConsolePrintf("CGlueMgr::NetDisconnectHandler: Disconnect pending");
CGlueMgr::m_disconnectPending = 0;
if (CGlueMgr::m_reconnect) {
CGlueMgr::m_reconnect = 0;
CGlueMgr::m_idleState = IDLE_ACCOUNT_LOGIN;
CGlueMgr::m_showedDisconnect = 0;
auto text = FrameScript_GetText("GAME_SERVER_LOGIN", -1, GENDER_NOT_APPLICABLE);
FrameScript_SignalEvent(3u, "%s%s", "CANCEL", text);
ClientServices::Connection()->Connect();
return 1;
}
return 1;
}
if (!ClientServices::ValidDisconnect(eventData)) {
ConsolePrintf("CGlueMgr::NetDisconnectHandler: Invalid disconnect");
return 1;
}
// TODO: ClientDestroyGame(0, 1, 0);
// TODO: EventSetMouseMode(0, 0);
if (CGlueMgr::m_suspended) {
CGlueMgr::Resume();
}
if (v11) {
ConsolePrintf("CGlueMgr::NetDisconnectHandler: Displaying script");
FrameScript_SignalEvent(2u, "%d", CGlueMgr::m_clientKickReason);
} else {
ConsolePrintf("CGlueMgr::NetDisconnectHandler: NOT displaying script");
WOWCS_OPS op;
const char* msg;
int32_t result;
int32_t errorCode;
int32_t complete = ClientServices::Connection()->PollStatus(op, &msg, result, errorCode);
if (!complete || result) {
ClientServices::SelectRealm("");
FrameScript_SignalEvent(2u, "%d", CGlueMgr::m_clientKickReason);
} else {
FrameScript_SignalEvent(3u, "%s%s", "OKAY", msg);
}
}
ClientServices::LoginConnection()->Logoff();
return 1;
}
// TODO a1: const EVENT_DATA_IDLE*
int32_t CGlueMgr::Idle(const void* a1, void* a2) {
// TODO:
@ -287,44 +345,64 @@ int32_t CGlueMgr::Idle(const void* a1, void* a2) {
int32_t complete = ClientServices::Connection()->PollStatus(op, &msg, result, errorCode);
switch (CGlueMgr::m_idleState) {
case IDLE_LOGIN_SERVER_LOGIN: {
CGlueMgr::PollLoginServerLogin();
break;
}
case IDLE_ACCOUNT_LOGIN: {
CGlueMgr::PollAccountLogin(errorCode, msg, complete, result, op);
break;
}
case IDLE_CHARACTER_LIST: {
CGlueMgr::PollCharacterList(errorCode, msg, complete, result, op);
break;
}
case IDLE_ENTER_WORLD: {
CGlueMgr::PollEnterWorld();
break;
}
case IDLE_12: {
if (CGlueMgr::m_patchDownload) {
CGlueMgr::PatchDownloadIdle();
} else if (CGlueMgr::m_surveyDownload) {
CGlueMgr::SurveyDownloadIdle();
case IDLE_LOGIN_SERVER_LOGIN: {
CGlueMgr::PollLoginServerLogin();
break;
}
break;
}
case IDLE_13: {
CGlueMgr::PollUserSurvey();
break;
}
case IDLE_ACCOUNT_LOGIN: {
CGlueMgr::PollAccountLogin(errorCode, msg, complete, result, op);
break;
}
// TODO other idle states
case IDLE_CHARACTER_LIST: {
CGlueMgr::PollCharacterList(errorCode, msg, complete, result, op);
break;
}
default:
break;
case IDLE_REALM_LIST: {
CGlueMgr::PollRealmList(errorCode, msg, complete, result, op);
break;
}
case IDLE_CREATE_CHARACTER: {
CGlueMgr::PollCreateCharacter(errorCode, msg, complete, result, op);
break;
}
case IDLE_DELETE_CHARACTER: {
CGlueMgr::PollDeleteCharacter(errorCode, msg, complete, result, op);
break;
}
case IDLE_ENTER_WORLD: {
CGlueMgr::PollEnterWorld();
break;
}
case IDLE_WORLD_LOGIN: {
FrameScript_SignalEvent(3u, "%s%s", "OKAY", msg);
break;
}
case IDLE_12: {
if (CGlueMgr::m_patchDownload) {
CGlueMgr::PatchDownloadIdle();
} else if (CGlueMgr::m_surveyDownload) {
CGlueMgr::SurveyDownloadIdle();
}
break;
}
case IDLE_13: {
CGlueMgr::PollUserSurvey();
break;
}
// TODO other idle states
default:
break;
}
return 1;
@ -624,6 +702,80 @@ void CGlueMgr::PollCharacterList(int32_t errorCode, const char* msg, int32_t com
CGlueMgr::m_accountMsgAvailable = 0;
}
void CGlueMgr::PollRealmList(int32_t errorCode, const char* msg, int32_t complete, int32_t result, WOWCS_OPS op) {
FrameScript_SignalEvent(4u, "%s", msg);
if (CGlueMgr::HandleBattlenetDisconnect()) {
CGlueMgr::m_idleState = IDLE_NONE;
CGlueMgr::m_showedDisconnect = 0;
}
if (!complete) {
return;
}
if (result) {
CGlueMgr::m_idleState = IDLE_NONE;
CGlueMgr::m_showedDisconnect = 0;
FrameScript_SignalEvent(5u, nullptr);
CRealmList::UpdateList();
if (!CGlueMgr::m_accountMsgAvailable)
return;
FrameScript_SignalEvent(34u, nullptr);
CGlueMgr::m_accountMsgAvailable = 0;
} else {
FrameScript_SignalEvent(3u, "%s%s", "OKAY", msg);
CGlueMgr::m_idleState = IDLE_NONE;
CGlueMgr::m_showedDisconnect = 0;
}
}
void CGlueMgr::PollCreateCharacter(int32_t errorCode, const char* msg, int32_t complete, int32_t result, WOWCS_OPS op) {
FrameScript_SignalEvent(4u, "%s", msg);
if (CGlueMgr::HandleBattlenetDisconnect()) {
CGlueMgr::m_idleState = IDLE_NONE;
CGlueMgr::m_showedDisconnect = 0;
}
if (!complete) {
return;
}
if (result) {
CGlueMgr::m_idleState = IDLE_NONE;
CGlueMgr::m_showedDisconnect = 0;
FrameScript_SignalEvent(5u, 0);
FrameScript_SignalEvent(0xCu, 0);
CGlueMgr::SetScreen("charselect");
} else {
FrameScript_SignalEvent(3u, "%s%s", "OKAY", msg);
CGlueMgr::m_idleState = IDLE_NONE;
CGlueMgr::m_showedDisconnect = 0;
}
}
void CGlueMgr::PollDeleteCharacter(int32_t errorCode, const char* msg, int32_t complete, int32_t result, WOWCS_OPS op) {
FrameScript_SignalEvent(4, "%s", msg);
if (CGlueMgr::HandleBattlenetDisconnect()) {
CGlueMgr::m_idleState = IDLE_NONE;
CGlueMgr::m_showedDisconnect = 0;
}
if (!complete) {
return;
}
if (result) {
FrameScript_SignalEvent(13, 0);
CGlueMgr::GetCharacterList();
return;
}
FrameScript_SignalEvent(3, "%s%s", "OKAY", msg);
CGlueMgr::m_idleState = IDLE_NONE;
CGlueMgr::m_showedDisconnect = 0;
}
void CGlueMgr::PollUserSurvey() {
if (CGlueMgr::m_surveyDownload && false /* virtual call */) {
if (CGlueMgr::m_executedSurvey) {
@ -640,6 +792,12 @@ void CGlueMgr::PollUserSurvey() {
}
}
void CGlueMgr::CancelLogin() {
if (CGlueMgr::m_idleState == IDLE_LOGIN_SERVER_LOGIN) {
CGlueMgr::StatusDialogClick();
}
}
void CGlueMgr::InitCursor() {
uint32_t width;
uint32_t height;
@ -709,6 +867,9 @@ void CGlueMgr::Resume() {
OsCreateDirectory("Logs", 0);
CCharacterSelection::Initialize();
CCharacterCreation::Initialize();
CWOWClientStatus status;
if (!SLogCreate("Logs\\GlueXML.log", 0, &status.m_logFile)) {
@ -920,6 +1081,20 @@ bool CGlueMgr::HandleBattlenetDisconnect() {
return false;
}
void CGlueMgr::DeleteCharacter(uint64_t guid) {
if (!guid) {
return;
}
CGlueMgr::m_idleState = IDLE_DELETE_CHARACTER;
CGlueMgr::m_showedDisconnect = 0;
auto errorText = ClientServices::GetErrorToken(70);
auto text = FrameScript_GetText(errorText, -1, GENDER_NOT_APPLICABLE);
FrameScript_SignalEvent(3u, "%s%s", "CANCEL", text);
ClientServices::CharacterDelete(guid);
}
void CGlueMgr::PollEnterWorld() {
//if (!LoadingScreenDrawing())
// return;

View file

@ -59,6 +59,7 @@ class CGlueMgr {
static int32_t m_scandllOkayToLogIn;
static float m_screenHeight;
static float m_screenWidth;
static int32_t m_clientKickReason;
static int32_t m_showedDisconnect;
static CSimpleTop* m_simpleTop;
static int32_t m_suspended;
@ -78,6 +79,7 @@ class CGlueMgr {
static int32_t HandleDisplaySizeChanged(const CSizeEvent& event);
static void GetRealmList(bool showProgress);
static void GetCharacterList();
static int32_t NetDisconnectHandler(const void* eventData, void*);
static int32_t Idle(const void* a1, void* a2);
static void Initialize();
static void InitCursor();
@ -87,7 +89,11 @@ class CGlueMgr {
static void PollAccountLogin(int32_t errorCode, const char* msg, int32_t complete, int32_t result, WOWCS_OPS op);
static void PollLoginServerLogin();
static void PollCharacterList(int32_t errorCode, const char* msg, int32_t complete, int32_t result, WOWCS_OPS op);
static void PollRealmList(int32_t errorCode, const char* msg, int32_t complete, int32_t result, WOWCS_OPS op);
static void PollCreateCharacter(int32_t errorCode, const char* msg, int32_t complete, int32_t result, WOWCS_OPS op);
static void PollDeleteCharacter(int32_t errorCode, const char* msg, int32_t complete, int32_t result, WOWCS_OPS op);
static void PollUserSurvey();
static void CancelLogin();
static void Resume();
static void SetCurrentAccount(const char* accountName);
static void SetLoginStateAndResult(LOGIN_STATE state, LOGIN_RESULT result, char const* addrStr, char const* stateStr, char const* resultStr, uint8_t flags);
@ -97,6 +103,7 @@ class CGlueMgr {
static void Suspend();
static void UpdateCurrentScreen(const char* screen);
static bool HandleBattlenetDisconnect();
static void DeleteCharacter(uint64_t guid);
static void PollEnterWorld();