1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-20 05:49:30 +08:00

add: add the function of obtaining player resources and scanning warehouses

This commit is contained in:
LA_DI_DA
2025-03-25 18:39:21 +08:00
parent 22e15b7641
commit d1f2c2a22e
3 changed files with 337 additions and 1 deletions

View File

@@ -3,17 +3,167 @@
#include <lua/lua.hpp>
#include <spdlog/spdlog.h>
#include <sol/as_args.hpp>
#include <sol/sol.hpp>
#include "utils.hpp"
Cracker::Cracker()
: m_state(lua_newthread(Utils::get_lua_state())) {}
: m_state(lua_newthread(Utils::get_lua_state())) {
Lua::Table proxies = m_state["pg"]["proxyRegister"]["data"];
for (int i = 1; i <= proxies.size(); ++i) {
Lua::Table proxy = proxies[i];
std::string proxy_name = proxy["proxyName"];
if (proxy_name == "PlayerProxy") {
Lua::Table proxy_map = proxy["facade"]["model"]["proxyMap"];
m_data_proxy.player = proxy_map["PlayerProxy"];
m_data_proxy.dock = proxy_map["BayProxy"];
m_data_proxy.storage = proxy_map["BagProxy"];
} else if (proxy_name == "WorldProxy") {
m_data_proxy.world = proxy["facade"]["model"]["proxyMap"]["WorldProxy"];
}
}
}
Cracker& Cracker::Instance() {
static auto* instance = new Cracker;
return *instance;
}
int Cracker::get_coin() {
double coin = m_data_proxy.player["data"]["gold"];
return static_cast<int>(coin);
}
int Cracker::get_oil() {
double oil = m_data_proxy.player["data"]["oil"];
return static_cast<int>(oil);
}
int Cracker::get_gems() {
double gems = m_data_proxy.player["data"]["awardGem"];
return static_cast<int>(gems);
}
int Cracker::get_level() {
double level = m_data_proxy.player["data"]["level"];
return static_cast<int>(level);
}
int Cracker::get_exp() {
double exp = m_data_proxy.player["data"]["exp"];
return static_cast<int>(exp);
}
int Cracker::get_merit() {
double merit = m_data_proxy.player["data"]["exploit"];
return static_cast<int>(merit);
}
int Cracker::get_guild_coin() {
double guild_coin = m_data_proxy.player["data"]["guildCoin"];
return static_cast<int>(guild_coin);
}
int Cracker::get_design_prt() {
double design_prt = m_data_proxy.player["data"]["design_prt"];
return static_cast<int>(design_prt);
}
#define CORE_DATA_ITEM_ID 59900
int Cracker::get_core_data() {
Lua::Table storage = m_data_proxy.storage["data"];
double core_data = storage.get<Lua::Table>(CORE_DATA_ITEM_ID)["count"];
return static_cast<int>(core_data);
}
#define MEDAL_ITEM_ID 15001
int Cracker::get_medal() {
Lua::Table storage = m_data_proxy.storage["data"];
double medal = storage.get<Lua::Table>(MEDAL_ITEM_ID)["count"];
return static_cast<int>(medal);
}
int Cracker::get_pt() {
double pt = m_data_proxy.player["data"]["pt"];
return static_cast<int>(pt);
}
#define SPECIALIZED_CORE_ITEM_ID 59010
int Cracker::get_specialized_core() {
Lua::Table storage = m_data_proxy.storage["data"];
double specialized_core = storage.get<Lua::Table>(SPECIALIZED_CORE_ITEM_ID)["count"];
return static_cast<int>(specialized_core);
}
int Cracker::get_curr_action_point() {
double curr_action_point = m_data_proxy.world["world"]["fields"]["staminaMgr"]["fields"]["stamina"];
return static_cast<int>(curr_action_point);
}
std::map<Cracker::ShipId, Cracker::ShipInfo> Cracker::scan_dock() {
std::map<ShipId, ShipInfo> ships;
Lua::Table dock = m_data_proxy.dock["data"];
for (auto& [ship_id, ship_info] : dock) {
Lua::Table ship_data = ship_info.as<Lua::Table>();
double id = ship_data["id"];
ships[static_cast<ShipId>(id)] = {
.config_id = static_cast<int>(ship_data.get<double>("configId")),
.emotion = static_cast<int>(ship_data.get<double>("energy")),
.rarity = static_cast<int>(ship_data.get<double>("star")),
.level = static_cast<int>(ship_data.get<double>("level")),
.exp = static_cast<int>(ship_data.get<double>("exp")),
.curr_star = static_cast<int>(ship_data.get<double>("state")),
};
}
return ships;
}
std::map<Cracker::StorageItemId, Cracker::StorageItemCount> Cracker::scan_storage() {
std::map<StorageItemId, StorageItemCount> items;
Lua::Table storage = m_data_proxy.storage["data"];
for (auto& [item_id, item_info] : storage) {
Lua::Table item_data = item_info.as<Lua::Table>();
double config_id = item_data["configId"];
double count = item_data["count"];
items[static_cast<StorageItemId>(config_id)] = static_cast<StorageItemCount>(count);
}
return items;
}
std::optional<Cracker::ShipInfo> Cracker::get_ship_info(ShipId ship_id) {
double id = static_cast<double>(ship_id);
Lua::Table dock = m_data_proxy.dock["data"];
try {
Lua::Table ship_data = dock.get<Lua::Table>(id);
return ShipInfo{
.config_id = static_cast<int>(ship_data.get<double>("configId")),
.emotion = static_cast<int>(ship_data.get<double>("energy")),
.rarity = static_cast<int>(ship_data.get<double>("star")),
.level = static_cast<int>(ship_data.get<double>("level")),
.exp = static_cast<int>(ship_data.get<double>("exp")),
.curr_star = static_cast<int>(ship_data.get<double>("state")),
};
} catch (const std::exception& e) {
return std::nullopt;
}
return std::nullopt;
}
std::optional<Cracker::StorageItemCount> Cracker::get_storage_item_count(StorageItemId item_id) {
double id = static_cast<double>(item_id);
Lua::Table storage = m_data_proxy.storage["data"];
try {
Lua::Table item_data = storage.get<Lua::Table>(id);
return static_cast<StorageItemCount>(item_data.get<double>("count"));
} catch (const std::exception& e) {
return std::nullopt;
}
return std::nullopt;
}
void Cracker::disable_all() {
disable_global_ship_properties_crack();
disable_fast_stage_move();