rodecomp/Source/Contents/SpecialPopupMgr.cpp
ragnarok-clanker fec919b88e Maintenance: Link-completeness fixes so the whole client links into one executable (all units in data/compile.json plus exe-only thir
Batch #13186 by ragnarok-clanker: forced by an admin (40 lower score(s), 206 changed function(s)); checked with 620 compiled unit(s), including every includer of Source/Archive/GPak.h, Source/Client/Mode/CGameMode.h, Source/Client/Mode/CLoginMode.h, Source/Client/Session.h, Source/Client/Stove/StoveMgr.h, Source/Client/Stove/StovePCSDK.h, Source/Client/Timer.h, Source/Contents/Actors/GameActor.h, Source/Contents/Actors/RenderObject.h, Source/Contents/CashEmotionMgr.h, Source/Contents/Configuration/ServiceOptions.h, Source/Contents/Skills/SkillTreeScript.h, Source/Render/DX9/D3DX9Runtime.h, Source/Resource/GifResource.h, Source/UI/AdventureGuide/UIAdventureGuide.h, Source/UI/Cooldowns/CooldownOwner.h, Source/UI/Edit/UIEditBoxEx.h, Source/UI/Lists/UIListBoxTemplate.h, Source/UI/Quest/UIRenewQuestUI.h, Source/UI/Rodex/UIRodexComposeWnd.h, Source/UI/Text/UITextViewerControl.h, Source/UI/UIBroadcastBalloon.h, Source/UI/UICaptchaRegisterWnd.h, Source/UI/UIMacroDetectorWnd.h, Source/UI/UIReputeWnd.h, Source/UI/Window/UIRegisterMgr.h, Source/UI/Window/UISecondCostumeWnd.h, Source/UI/Window/UISelCharForUServerWnd.h, Source/UI/Window/UIWindow.h, Source/UI/Window/UIWindowMgr.h, Source/Utility/EncryptedName.h.
2026-11-06 10:56:48 +00:00

167 lines
4.6 KiB
C++

#include "Contents/SpecialPopupMgr.h"
#include "Script/LuaFileOperations.h"
#include "Script/NLuaState.h"
extern "C" {
#include <lua.h>
#include <lualib.h>
}
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <new>
#include <windows.h>
// GLOBAL: gl_24839
CSpecialPopupMgr* g_specialPopupMgr = nullptr;
// OFFSET: 0x007A7930
// FUNCTION: fn_09052
bool CSpecialPopupMgr::Create() {
if (g_specialPopupMgr) {
return false;
}
g_specialPopupMgr = new (std::nothrow) CSpecialPopupMgr();
if (!g_specialPopupMgr) {
return false;
}
if (!g_specialPopupMgr->m_initialized) {
delete g_specialPopupMgr;
g_specialPopupMgr = nullptr;
return false;
}
return true;
}
// OFFSET: 0x007A7A20
// FUNCTION: fn_09053
void CSpecialPopupMgr::Destroy() {
if (g_specialPopupMgr) {
delete g_specialPopupMgr;
g_specialPopupMgr = nullptr;
}
}
// OFFSET: 0x007A7A40
// FUNCTION: fn_09054
PopupData* CSpecialPopupMgr::GetPopup(int id) {
std::map<int, PopupData>::iterator it = this->m_popups.find(id);
if (it != this->m_popups.end()) {
return &it->second;
}
return nullptr;
}
// OFFSET: 0x007A7A90
// FUNCTION: fn_09055
bool CSpecialPopupMgr::Init() {
NLuaState luaState;
if (!luaState.IsValid()) {
return false;
}
luaL_openlibs(luaState.GetState());
lua_pushcclosure(luaState.GetState(), CSpecialPopupMgr::LuaAddMsg, 0);
lua_setfield(luaState.GetState(), LUA_GLOBALSINDEX, "AddMsg");
lua_pushcclosure(luaState.GetState(), CSpecialPopupMgr::LuaAddDesc, 0);
lua_setfield(luaState.GetState(), LUA_GLOBALSINDEX, "AddDesc");
if (!LoadLuaResource(luaState.GetState(), "System\\spopup.lub", false)) {
MessageBoxA(NULL, lua_tostring(luaState.GetState(), -1), "CSpecialPopupMgr LuaLoadFile X", 0);
return false;
}
if (lua_pcall(luaState.GetState(), 0, 0, 0) != 0) {
MessageBoxA(NULL, lua_tostring(luaState.GetState(), -1), "CSpecialPopupMgr lua_pcall X", 0);
return false;
}
lua_getfield(luaState.GetState(), LUA_GLOBALSINDEX, "main");
if (lua_pcall(luaState.GetState(), 0, 2, 0) != 0) {
MessageBoxA(NULL, lua_tostring(luaState.GetState(), -1), "CSpecialPopupMgr main X", 0);
return false;
}
if (!lua_isstring(luaState.GetState(), -1)) {
MessageBoxA(NULL, "second return value is not string...", "CSpecialPopupMgr", 0);
return false;
}
if (lua_toboolean(luaState.GetState(), -2)) {
return true;
}
MessageBoxA(NULL, (std::string("error found :") + lua_tostring(luaState.GetState(), -1)).c_str(), "CSpecialPopupMgr", 0);
return false;
}
// OFFSET: 0x007A7DB0
// FUNCTION: fn_09056
std::string FormatPopupString(const char* format, ...) {
char buffer[2049];
std::memset(buffer, 0, sizeof(buffer));
va_list arguments;
va_start(arguments, format);
_vsnprintf(buffer, 2048, format, arguments);
return std::string(buffer);
}
// OFFSET: 0x007A80B0
// FUNCTION: fn_09058
int CSpecialPopupMgr::LuaAddDesc(lua_State* state) {
if (!lua_isstring(state, -1)) {
lua_pushboolean(state, 0);
lua_pushstring(state, FormatPopupString("2nd argment is must string").c_str());
return 2;
}
if (!lua_isnumber(state, -2)) {
lua_pushboolean(state, 0);
lua_pushstring(state, FormatPopupString("1st argment is must number").c_str());
return 2;
}
const int id = static_cast<int>(lua_tonumber(state, -2));
std::string description = lua_tostring(state, -1);
g_specialPopupMgr->AddDescription(id, description);
lua_pushboolean(state, 1);
lua_pushstring(state, FormatPopupString("good").c_str());
return 2;
}
// OFFSET: 0x007A82D0
// FUNCTION: fn_09059
int CSpecialPopupMgr::LuaAddMsg(lua_State* state) {
const int id = static_cast<int>(lua_tonumber(state, -3));
if (!lua_isnumber(state, -3)) {
lua_pushboolean(state, 0);
lua_pushstring(state, FormatPopupString("3th argment is must number [itemID:%d]", id).c_str());
return 2;
}
if (!lua_isnumber(state, -2)) {
lua_pushboolean(state, 0);
lua_pushstring(state, FormatPopupString("2nd argment is must number [itemID:%d]", id).c_str());
return 2;
}
if (!lua_isnumber(state, -1)) {
lua_pushboolean(state, 0);
lua_pushstring(state, FormatPopupString("1st argment is must number [itemID:%d]", id).c_str());
return 2;
}
const int messageId = static_cast<int>(lua_tonumber(state, -2));
const unsigned int color = static_cast<unsigned int>(lua_tonumber(state, -1));
g_specialPopupMgr->m_popups[id].m_messageId = messageId;
g_specialPopupMgr->m_popups[id].m_color = ((((color >> 8) & 0xFF) | ((color & 0xFF) << 8)) << 8) | ((color >> 16) & 0xFF);
lua_pushboolean(state, 1);
lua_pushstring(state, FormatPopupString("good").c_str());
return 2;
}