Files
mtgodot-poc/extension/src/pack/pack_mount.cpp
T
shenandClaude Sonnet 5 47baf6c0c6 Metin2 game client (P0–P11) + mobile asset pipeline
Networked client on the existing Godot 4.7 + libgr2 renderer:
- net: m2dev wire protocol (libsodium KX + XChaCha20), auth/select/game
  phases, EntityStore world model, ~all GC/CG headers. char create/delete,
  private shop / mall / cube, SHOP_GC_START_EX, guild, party (+ CG_PARTY_SET_STATE),
  quests, dragon soul, refine, safebox, exchange.
- UI: in-game windows migrated 1:1 from the reference uiscript/root .py —
  char status (/stat), inventory+equipment, select-item ([SELECT_ITEM] quest
  token), system-option + game-option + ESC system menu, private-shop 39-grid,
  party info board, shop tabs, atlas, minimap, quickbar, chat, …
- EterGrnLib polish: GR2 material blend/two-sided, LOD crossfade, motion-event
  dispatch, contact shadow, ray-AABB picking, weapon grip pre-transform.

Portable asset IO (A1) — all extension/libgr2/formats/mtproto reads routed
through godot::FileAccess (res:// PCK works on iOS/Android); standalone-lib
*_path() kept for the non-Godot CTests. AssetResolver + PropertyRegistry
switched to a baked index (bake_asset_index.gd) instead of std::filesystem.

Mobile builds: build-{android,ios}.sh, export-android.sh, pack-assets.sh,
gen-debug-keystore.sh. Assets ship as a zip mounted at runtime by
project/asset_pack.gd (adb push now; HTTP download is a drop-in later).

ctest 10/10, 34 GDScript suites, macOS/iOS/Android all build.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013EJxkHiNKS4kybHS3XKyAJ
2026-08-31 20:02:12 +09:00

114 lines
2.7 KiB
C++

#include "pack_mount.h"
#include <algorithm>
#include <filesystem>
namespace fs = std::filesystem;
namespace mtpack {
std::string PackMount::norm(std::string s) {
std::replace(s.begin(), s.end(), '\\', '/');
// strip a leading "x:/" drive
if (s.size() > 2 && s[1] == ':') {
s = s.substr(2);
}
while (!s.empty() && s.front() == '/') {
s.erase(s.begin());
}
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
// fold "//"
std::string o;
o.reserve(s.size());
for (char c : s) {
if (c == '/' && !o.empty() && o.back() == '/') {
continue;
}
o.push_back(c);
}
return o;
}
bool PackMount::mount(const std::string &epk_path, std::string *err) {
auto pk = std::make_shared<EterPack>();
if (!pk->open(epk_path, err)) {
return false;
}
const size_t pi = m_packs.size();
m_packs.push_back(pk);
for (const std::string &name : pk->names()) {
std::string n = norm(name);
m_by_norm[n] = {pi, name}; // later pack wins
auto p = n.find("ymir work/");
if (p != std::string::npos) {
m_by_ymir[n.substr(p + 10)] = {pi, name};
}
}
return true;
}
int PackMount::scan_dir(const std::string &dir, const std::string &patch_prefix) {
std::error_code ec;
if (!fs::is_directory(dir, ec)) {
return 0;
}
std::vector<std::string> base, patch;
for (const auto &e : fs::directory_iterator(dir, ec)) {
if (!e.is_regular_file()) {
continue;
}
const auto &p = e.path();
if (p.extension() != ".epk") {
continue;
}
if (!patch_prefix.empty() && p.filename().string().rfind(patch_prefix, 0) == 0) {
patch.push_back(p.string());
} else {
base.push_back(p.string());
}
}
std::sort(base.begin(), base.end());
std::sort(patch.begin(), patch.end());
int n = 0;
for (const auto &v : {&base, &patch}) {
for (const std::string &f : *v) {
if (mount(f)) {
++n;
}
}
}
return n;
}
bool PackMount::has(const std::string &vp) const {
std::string n = norm(vp);
if (m_by_norm.count(n)) {
return true;
}
auto p = n.find("ymir work/");
std::string suf = (p != std::string::npos) ? n.substr(p + 10) : n;
return m_by_ymir.count(suf) != 0;
}
bool PackMount::read(const std::string &vp, std::vector<uint8_t> &out, std::string *err) const {
std::string n = norm(vp);
const Ref *r = nullptr;
if (auto it = m_by_norm.find(n); it != m_by_norm.end()) {
r = &it->second;
} else {
auto p = n.find("ymir work/");
std::string suf = (p != std::string::npos) ? n.substr(p + 10) : n;
if (auto it2 = m_by_ymir.find(suf); it2 != m_by_ymir.end()) {
r = &it2->second;
}
}
if (!r) {
if (err) *err = "not mounted: " + vp;
return false;
}
return m_packs[r->pack]->read(r->name, out, err);
}
} // namespace mtpack