rodecomp/Source/Contents/Map/TownInfoMgr.cpp
ragnarok-clanker d7c1911fa6 Maintenance: Move explicit-template linkage declarations out of the game source. 105 units' extern template lines (and the std tree a
Batch #17237 by ragnarok-clanker: no function's compiled code changes; checked with 105 compiled unit(s), including every includer of Source/Linkage/Source/Client/Mode/LoginMode.cpp.h, Source/Linkage/Source/Client/Session/SessionAchievements.cpp.h, Source/Linkage/Source/Client/Session/SessionPredicates.cpp.h, Source/Linkage/Source/Client/Session/SessionState.cpp.h, Source/Linkage/Source/Contents/Achievement/AchievementMgr.cpp.h, Source/Linkage/Source/Contents/Actors/ActorPickNode.cpp.h, Source/Linkage/Source/Contents/Actors/MercenaryAI.cpp.h, Source/Linkage/Source/Contents/Actors/Resources/RobeResources.cpp.h, Source/Linkage/Source/Contents/CashEmotion/CashEmotionMgr.cpp.h, Source/Linkage/Source/Contents/Effects/EffectResourceSwitcher.cpp.h, Source/Linkage/Source/Contents/Effects/Particles/AnimatedEmitterEffect.cpp.h, Source/Linkage/Source/Contents/Effects/Particles/Particle.cpp.h, Source/Linkage/Source/Contents/Effects/Skills/MonsterSkillEffects.cpp.h, Source/Linkage/Source/Contents/Emblems/EmblemCache.cpp.h, Source/Linkage/Source/Contents/Emblems/EmblemDataDownloadAsyncWork.cpp.h, Source/Linkage/Source/Contents/Emblems/EmblemDataMgr.cpp.h, Source/Linkage/Source/Contents/Emblems/EmblemDataUploadAsyncWork.cpp.h, Source/Linkage/Source/Contents/Emblems/GuildEmblemLookup.cpp.h, Source/Linkage/Source/Contents/Hotkeys/EmotionHotkeys.cpp.h, Source/Linkage/Source/Contents/Items/ItemInfo.cpp.h, Source/Linkage/Source/Contents/Items/ItemNaming.cpp.h, Source/Linkage/Source/Contents/Map/PrivateAirplaneMgr.cpp.h, Source/Linkage/Source/Contents/Map/TownInfoMgr.cpp.h, Source/Linkage/Source/Contents/Messenger/MessengerMember.cpp.h, Source/Linkage/Source/Contents/Messenger/WhisperBlockMgr.cpp.h, Source/Linkage/Source/Contents/Models/ModelLighting.cpp.h, Source/Linkage/Source/Contents/Movies/BinkMovies.cpp.h, Source/Linkage/Source/Contents/Navigation/NavigationDestinations.cpp.h, Source/Linkage/Source/Contents/Navigation/NavigationRequest.cpp.h, Source/Linkage/Source/Contents/Navigation/NavigationRoute.cpp.h, Source/Linkage/Source/Contents/Party/AgencyRequests.cpp.h, Source/Linkage/Source/Contents/Party/LoadPartyInfoAsyncWork.cpp.h, Source/Linkage/Source/Contents/Party/LoadPartyListAsyncWork.cpp.h, Source/Linkage/Source/Contents/Party/RegisterPartyAsyncWork.cpp.h, Source/Linkage/Source/Contents/Repute/ReputeMgr.cpp.h, Source/Linkage/Source/Contents/Sound/SoundMgr.cpp.h, Source/Linkage/Source/Contents/Store/MCStoreInfoBackup.cpp.h, Source/Linkage/Source/Contents/Store/MCStoreInfoBackupAsyncWork.cpp.h, Source/Linkage/Source/Contents/Time/ClientTiming.cpp.h, Source/Linkage/Source/Contents/UserData/AccountLinkedUserDataLoadAsyncWork.cpp.h, Source/Linkage/Source/Contents/UserData/AccountLinkedUserDataMgr.cpp.h, Source/Linkage/Source/Contents/UserData/AccountLinkedUserDataSaveAsyncWork.cpp.h, Source/Linkage/Source/Contents/UserData/CharacterConfigSave.cpp.h, Source/Linkage/Source/Contents/UserData/CharacterLinkedUserDataLoadAsyncWork.cpp.h, Source/Linkage/Source/Contents/UserData/CharacterLinkedUserDataSaveAsyncWork.cpp.h, Source/Linkage/Source/File/DirectoryRemoval.cpp.h, Source/Linkage/Source/Network/NIPAddr.cpp.h, Source/Linkage/Source/Network/Packets/ActorNamePacket.cpp.h, Source/Linkage/Source/Render/Device/RenderBackends.cpp.h, Source/Linkage/Source/Render/Primitives/ScreenLine.cpp.h, Source/Linkage/Source/Render/Text/EmbedFont.cpp.h, Source/Linkage/Source/Resource/Models/RmaResource.cpp.h, Source/Linkage/Source/Resource/ResourceFailures.cpp.h, Source/Linkage/Source/Script/LuaScript.cpp.h, Source/Linkage/Source/Security/NProtectGameGuardMgr.cpp.h, Source/Linkage/Source/UI/Acceptance/UIExchangeAcceptWnd.cpp.h, Source/Linkage/Source/UI/Achievement/UIAchWnd.cpp.h, Source/Linkage/Source/UI/Buttons/UINaviLinkButton.cpp.h, Source/Linkage/Source/UI/CashShop/UICashShopWnd.cpp.h, Source/Linkage/Source/UI/Chat/UIChatRoomTitle.cpp.h, Source/Linkage/Source/UI/Dialogs/UIMessageBox.cpp.h, Source/Linkage/Source/UI/Dialogs/UINoteWnd.cpp.h, Source/Linkage/Source/UI/Edit/UIEditCtrl3.cpp.h, Source/Linkage/Source/UI/Enchant/UIEnchantUI.cpp.h, Source/Linkage/Source/UI/EntryQueue/UIEntryQueueWnd.cpp.h, Source/Linkage/Source/UI/Events/UICheckAttendanceWnd.cpp.h, Source/Linkage/Source/UI/GameSettings/GameSettingsUI.cpp.h, Source/Linkage/Source/UI/GameSettings/UIHotkeyGuideWnd.cpp.h, Source/Linkage/Source/UI/Gauges/UIBarGraph.cpp.h, Source/Linkage/Source/UI/Guild/UIGuildHelperWnd.cpp.h, Source/Linkage/Source/UI/Items/UIEquipmentPropertiesWnd.cpp.h, Source/Linkage/Source/UI/Items/UIItemReformWnd.cpp.h, Source/Linkage/Source/UI/Items/UIItemStoreComboBox.cpp.h, Source/Linkage/Source/UI/Items/UILapineBoxWnd.cpp.h, Source/Linkage/Source/UI/Items/UIMakeTargetProcessWnd.cpp.h, Source/Linkage/Source/UI/Items/UIMerchantItemLogWnd.cpp.h, Source/Linkage/Source/UI/Items/UISwapEquipmentWnd.cpp.h, Source/Linkage/Source/UI/Lists/UIChatHisBox.cpp.h, Source/Linkage/Source/UI/Lists/UIComboBoxDefWnd.cpp.h, Source/Linkage/Source/UI/Login/UIPasswordWnd.cpp.h, Source/Linkage/Source/UI/Macro/UIMacroDetectorWnd.cpp.h, Source/Linkage/Source/UI/Navigation/NavigationLink.cpp.h, Source/Linkage/Source/UI/Party/UIApplyForPartyWnd.cpp.h, Source/Linkage/Source/UI/Party/UIRegisterPartyWnd.cpp.h, Source/Linkage/Source/UI/Party/UISeekPartyMBWnd.cpp.h, Source/Linkage/Source/UI/Quest/UIRecommendedQuestInfo.cpp.h, Source/Linkage/Source/UI/Repute/UIReputeWnd.cpp.h, Source/Linkage/Source/UI/Rodex/UIRodexComposeWnd.cpp.h, Source/Linkage/Source/UI/RuneSystem/UIRuneSystemWnd.cpp.h, Source/Linkage/Source/UI/Shop/UIMerchantShopTitle.cpp.h, Source/Linkage/Source/UI/Shortcuts/UIShortCutWnd.cpp.h, Source/Linkage/Source/UI/Skill/UIGraffiStrboxWnd.cpp.h, Source/Linkage/Source/UI/SkillDelayInfo/UISkillDelayInfo.cpp.h, Source/Linkage/Source/UI/Status/UIBasicInfoWnd.cpp.h, Source/Linkage/Source/UI/Text/ColoredText.cpp.h, Source/Linkage/Source/UI/Text/ItemLinkDisplay.cpp.h, Source/Linkage/Source/UI/Text/TextMarkup.cpp.h, Source/Linkage/Source/UI/Text/UITagTextViewer.cpp.h, Source/Linkage/Source/UI/Text/UITextViewer.cpp.h, Source/Linkage/Source/UI/Window/UIFrameWnd.cpp.h, Source/Linkage/Source/UI/Window/UIWindow.cpp.h, Source/Linkage/Source/UI/Window/UIWindowFactory.cpp.h, Source/Linkage/Source/UI/Window/WindowRegistration.cpp.h, Source/Linkage/Source/UI/Window/WindowRetirement.cpp.h, Source/Linkage/Source/Utility/Threading/NThread.cpp.h.
2026-11-11 16:21:46 +00:00

194 lines
5.4 KiB
C++

#include "Contents/Map/TownInfoMgr.h"
#include "Script/NLuaState.h"
extern "C" {
#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
}
#include <windows.h>
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <new>
#include <utility>
// GLOBAL: gl_24817
CTownInfoMgr* g_townInfoMgr;
// OFFSET: 0x00AE1A60
// FUNCTION: fn_18003
TownInfo::TownInfo(int type, std::string name, int x, int y, std::string image)
: type(type), name(name), x(x), y(y), image(image) {
}
// OFFSET: 0x00AE1B00
// FUNCTION: fn_18004
TownInfo::TownInfo() : type(-1), name(""), x(-1), y(-1), image("") {
}
// OFFSET: 0x00AE1F70
// FUNCTION: fn_18007
void CTownInfoMgr::AddTownInfo(std::string mapName, std::string name, int x, int y, int type) {
// GLOBAL: gl_24866
static std::string icons[10] = {
"유저인터페이스\\Information\\Store.bmp",
"유저인터페이스\\Information\\Weaponshop.bmp",
"유저인터페이스\\Information\\ArmorShops.bmp",
"유저인터페이스\\Information\\Smithy.bmp",
"유저인터페이스\\Information\\Guide.bmp",
"유저인터페이스\\Information\\Inn.bmp",
"유저인터페이스\\Information\\kafra.bmp",
"유저인터페이스\\Information\\style.bmp",
"유저인터페이스\\Information\\warp.bmp",
"유저인터페이스\\minimap\\Quest.bmp",
};
std::map<std::string, std::vector<TownInfo>>::iterator it = this->m_towns.find(mapName);
if (it == this->m_towns.end()) {
TownInfo info(type, name, x, y, icons[type]);
std::vector<TownInfo> list;
list.push_back(info);
this->m_towns.insert(std::make_pair(mapName, list));
} else {
TownInfo info(type, name, x, y, icons[type]);
it->second.push_back(info);
}
}
// OFFSET: 0x00AE2740
// FUNCTION: fn_18008
bool CTownInfoMgr::Create() {
if (g_townInfoMgr == nullptr) {
g_townInfoMgr = new (std::nothrow) CTownInfoMgr();
if (g_townInfoMgr != nullptr) {
if (!g_townInfoMgr->m_isValid) {
delete g_townInfoMgr;
g_townInfoMgr = nullptr;
return false;
}
return true;
}
}
return false;
}
// OFFSET: 0x00AE2840
// FUNCTION: fn_18009
void CTownInfoMgr::Destroy() {
if (g_townInfoMgr != nullptr) {
delete g_townInfoMgr;
g_townInfoMgr = nullptr;
}
}
// OFFSET: 0x00AE2860
// FUNCTION: fn_18010
bool CTownInfoMgr::LoadScript() {
NLuaState lua;
if (lua.IsValid()) {
luaL_openlibs(lua.GetState());
lua_register(lua.GetState(), "AddTownInfo", CTownInfoMgr::L_AddTownInfo);
if (luaL_loadfile(lua.GetState(), "System\\Towninfo.lub") == 0 && lua_pcall(lua.GetState(), 0, 0, 0) == 0) {
lua_getglobal(lua.GetState(), "main");
if (lua_pcall(lua.GetState(), 0, 2, 0) == 0) {
if (!lua_isstring(lua.GetState(), -1)) {
MessageBoxA(nullptr, "second return value is not string...", "CTownInfoMgr", MB_OK);
return false;
}
if (lua_toboolean(lua.GetState(), -2)) {
return true;
}
const std::string message = std::string("error found :") + lua_tostring(lua.GetState(), -1);
MessageBoxA(nullptr, message.c_str(), "CTownInfoMgr", MB_OK);
return false;
}
}
MessageBoxA(nullptr, lua_tostring(lua.GetState(), -1), "CTownInfoMgr", MB_OK);
}
return false;
}
// OFFSET: 0x00AE2A90
// FUNCTION: fn_18011
std::string FormatTownInfoString(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: 0x00AE2F40
// FUNCTION: fn_18018
TownInfo CTownInfoMgr::GetTownInfo(std::string mapName, unsigned int index) {
std::string key = mapName;
const std::string::size_type dot = key.find_first_of(".");
if (dot != std::string::npos) {
key = key.substr(0, dot);
}
std::map<std::string, std::vector<TownInfo>>::iterator it = this->m_towns.find(key);
if (it == this->m_towns.end()) {
return TownInfo();
}
if (index >= it->second.size()) {
return TownInfo();
}
return it->second[index];
}
// OFFSET: 0x00AE33A0
// FUNCTION: fn_18020
int CTownInfoMgr::L_AddTownInfo(lua_State* state) {
if (!lua_isnumber(state, -1)) {
lua_pushboolean(state, 0);
lua_pushstring(state, FormatTownInfoString("5th argment is must number").c_str());
return 2;
}
if (!lua_isnumber(state, -2)) {
lua_pushboolean(state, 0);
lua_pushstring(state, FormatTownInfoString("4th argment is must number").c_str());
return 2;
}
if (!lua_isnumber(state, -3)) {
lua_pushboolean(state, 0);
lua_pushstring(state, FormatTownInfoString("3th argment is must number").c_str());
return 2;
}
if (!lua_isstring(state, -4)) {
lua_pushboolean(state, 0);
lua_pushstring(state, FormatTownInfoString("2nd argment is must string").c_str());
return 2;
}
if (!lua_isstring(state, -5)) {
lua_pushboolean(state, 0);
lua_pushstring(state, FormatTownInfoString("1st argment is must string").c_str());
return 2;
}
std::string mapName = lua_tostring(state, -5);
std::string name = lua_tostring(state, -4);
const int x = static_cast<int>(lua_tonumber(state, -3));
const int y = static_cast<int>(lua_tonumber(state, -2));
const int type = static_cast<int>(lua_tonumber(state, -1));
g_townInfoMgr->AddTownInfo(mapName, name, x, y, type);
lua_pushboolean(state, 1);
lua_pushstring(state, FormatTownInfoString("good").c_str());
return 2;
}