mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-10-26 22:06:06 +03:00
feat(glue): handle GetRealmInfo script command
This commit is contained in:
parent
e0b6f361cc
commit
7359f741f1
@ -1,10 +1,13 @@
|
|||||||
#include "ui/ScriptFunctions.hpp"
|
#include "ui/ScriptFunctions.hpp"
|
||||||
|
#include "client/ClientServices.hpp"
|
||||||
|
#include "db/Db.hpp"
|
||||||
#include "glue/CRealmList.hpp"
|
#include "glue/CRealmList.hpp"
|
||||||
#include "util/StringTo.hpp"
|
#include "util/StringTo.hpp"
|
||||||
#include "ui/Types.hpp"
|
#include "ui/Types.hpp"
|
||||||
#include "util/Lua.hpp"
|
#include "util/Lua.hpp"
|
||||||
#include "util/Unimplemented.hpp"
|
#include "util/Unimplemented.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <storm/String.hpp>
|
||||||
|
|
||||||
int32_t Script_RequestRealmList(lua_State* L) {
|
int32_t Script_RequestRealmList(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED();
|
WHOA_UNIMPLEMENTED();
|
||||||
@ -23,7 +26,140 @@ int32_t Script_GetNumRealms(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t Script_GetRealmInfo(lua_State* L) {
|
int32_t Script_GetRealmInfo(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED();
|
if (!lua_isnumber(L, 1)) {
|
||||||
|
return luaL_error(L, "Usage: GetRealmInfo(category, index)");
|
||||||
|
}
|
||||||
|
|
||||||
|
REALM_INFO* realmInfo = nullptr;
|
||||||
|
|
||||||
|
if (lua_isnumber(L, 2)) {
|
||||||
|
int32_t categoryIndex = lua_tonumber(L, 1) - 1;
|
||||||
|
categoryIndex = CRealmList::Sub4DE910(categoryIndex);
|
||||||
|
|
||||||
|
auto realmCategory = categoryIndex < CRealmList::s_categories.Count()
|
||||||
|
? CRealmList::s_categories[categoryIndex]
|
||||||
|
: nullptr;
|
||||||
|
int32_t realmIndex = lua_tonumber(L, 2) - 1;
|
||||||
|
|
||||||
|
if (realmCategory && realmIndex > realmCategory->uint14) {
|
||||||
|
realmInfo = ClientServices::GetRealmInfoByIndex(realmCategory->m_realms[realmIndex]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int32_t realmIndex = lua_tonumber(L, 1) - 1;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < CRealmList::s_categories.Count(); i++) {
|
||||||
|
auto realmCategory = CRealmList::s_categories[i];
|
||||||
|
if (realmCategory) {
|
||||||
|
if (realmCategory->uint14 > realmIndex) {
|
||||||
|
realmInfo = ClientServices::GetRealmInfoByIndex(realmCategory->m_realms[realmIndex]);
|
||||||
|
} else {
|
||||||
|
realmIndex -= realmCategory->uint14;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!realmInfo) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnumber(L, 0.0);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnumber(L, 0.0);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
|
||||||
|
return 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
// name
|
||||||
|
lua_pushstring(L, realmInfo->name);
|
||||||
|
|
||||||
|
// numCharacters
|
||||||
|
lua_pushnumber(L, realmInfo->numChars);
|
||||||
|
|
||||||
|
// invalidRealm
|
||||||
|
if (/* TODO Sub422140() || */ !(realmInfo->flags & 0x1)) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
} else {
|
||||||
|
lua_pushnumber(L, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// realmDown
|
||||||
|
if (realmInfo->flags & 0x2) {
|
||||||
|
lua_pushnumber(L, 1.0);
|
||||||
|
} else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
// currentRealm
|
||||||
|
auto selectedRealmName = ClientServices::GetSelectedRealmName();
|
||||||
|
if (SStrCmpI(realmInfo->name, selectedRealmName, STORM_MAX_STR) /* TODO SStrCmpUTF8I */) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
} else {
|
||||||
|
lua_pushnumber(L, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t realmIsPvp = 0;
|
||||||
|
int32_t realmIsRp = 0;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < g_cfg_ConfigsDB.m_numRecords; i++) {
|
||||||
|
auto config = g_cfg_ConfigsDB.GetRecordByIndex(i);
|
||||||
|
|
||||||
|
if (config->m_realmType == realmInfo->type) {
|
||||||
|
realmIsPvp = config->m_playerKillingAllowed != 0;
|
||||||
|
realmIsRp = config->m_roleplaying != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pvp
|
||||||
|
if (realmIsPvp) {
|
||||||
|
lua_pushnumber(L, 1.0);
|
||||||
|
} else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
// rp
|
||||||
|
if (realmIsRp) {
|
||||||
|
lua_pushnumber(L, 1.0);
|
||||||
|
} else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
// load
|
||||||
|
// TODO auto v18 = CRealmList::Sub4DE5B0(realmInfo);
|
||||||
|
float v18 = 0.0f;
|
||||||
|
lua_pushnumber(L, v18);
|
||||||
|
|
||||||
|
// locked
|
||||||
|
if (realmInfo->locked & 0x1) {
|
||||||
|
lua_pushnumber(L, 1.0);
|
||||||
|
} else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
// major, minor, revision, build, type
|
||||||
|
if (realmInfo->flags & 0x4) {
|
||||||
|
lua_pushnumber(L, realmInfo->majorVersion);
|
||||||
|
lua_pushnumber(L, realmInfo->minorVersion);
|
||||||
|
lua_pushnumber(L, realmInfo->patchVersion);
|
||||||
|
lua_pushnumber(L, realmInfo->revision);
|
||||||
|
lua_pushnumber(L, realmInfo->type);
|
||||||
|
} else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 14;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Script_ChangeRealm(lua_State* L) {
|
int32_t Script_ChangeRealm(lua_State* L) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user