diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 8bf424e..21f4203 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -20,6 +20,7 @@ target_link_libraries(ui math model net + object util PUBLIC common diff --git a/src/ui/FrameScript.cpp b/src/ui/FrameScript.cpp index b812b2f..9afea77 100644 --- a/src/ui/FrameScript.cpp +++ b/src/ui/FrameScript.cpp @@ -14,6 +14,12 @@ const char* g_glueScriptEvents[41]; const char* g_scriptEvents[722]; +int32_t g_glueFrameScriptGenders[] = { + 2, // UNIT_SEX_MALE + 3, // UNIT_SEX_FEMALE + 1, // UNIT_SEX_NONE +}; + void* FrameScript::s_mempool; lua_State* FrameScript::s_context; int64_t FrameScript::s_scriptTimeUsed; diff --git a/src/ui/FrameScript.hpp b/src/ui/FrameScript.hpp index debf40f..0982934 100644 --- a/src/ui/FrameScript.hpp +++ b/src/ui/FrameScript.hpp @@ -1,13 +1,14 @@ #ifndef UI_FRAME_SCRIPT_HPP #define UI_FRAME_SCRIPT_HPP +#include "object/Types.hpp" #include "ui/Types.hpp" -#include -#include #include #include #include #include +#include +#include #define NUM_GLUE_SCRIPT_EVENTS 41 @@ -40,6 +41,7 @@ class FrameScript_EventObject : public TSHashObject(lua_tonumber(L, 1)) - 1; + + // Out of bounds + + if (index < 0 || index >= CCharacterSelection::s_characterList.Count()) { + // Name + lua_pushnil(L); + + // Race + lua_pushnil(L); + + // Class + lua_pushnil(L); + + // Level + lua_pushnumber(L, 0.0); + + // Zone (why isn't this nil?) + lua_pushnumber(L, 0.0); + + // Sex + lua_pushnil(L); + + // Ghost + lua_pushnil(L); + + // Paid class change + lua_pushnil(L); + + // Paid race change + lua_pushnil(L); + + // Paid faction change + lua_pushnil(L); + + return 10; + } + + // Character exists at index + + auto& display = CCharacterSelection::s_characterList[index]; + auto sex = static_cast(display.info.sexID); + + // Name + lua_pushstring(L, display.info.name); + + // Race + auto raceRec = g_chrRacesDB.GetRecord(display.info.raceID); + auto raceName = CGUnit_C::GetDisplayRaceNameFromRecord(raceRec, sex, nullptr); + lua_pushstring(L, raceName ? raceName : ""); + + // Class + auto classRec = g_chrClassesDB.GetRecord(display.info.classID); + auto className = CGUnit_C::GetDisplayClassNameFromRecord(classRec, sex, nullptr); + lua_pushstring(L, className ? className : ""); + + // Level + lua_pushnumber(L, display.info.experienceLevel); + + // Zone + auto areaRec = g_areaTableDB.GetRecord(display.info.zoneID); + if (areaRec) { + lua_pushstring(L, areaRec->m_areaName); + } else { + lua_pushnil(L); + } + + // Sex + lua_pushnumber(L, g_glueFrameScriptGenders[display.info.sexID]); + + // Ghost + lua_pushboolean(L, display.info.flags & 0x2000); + + // Paid class change + lua_pushboolean(L, display.info.customizeFlags & 0x1); + + // Paid race change + lua_pushboolean(L, display.info.customizeFlags & 0x100000); + + // Paid faction change + lua_pushboolean(L, display.info.customizeFlags & 0x10000); + + return 10; } int32_t Script_SelectCharacter(lua_State* L) {