Commit 67ffbd75 authored by nanahira's avatar nanahira

add YGOPRO_ENV_foo=bar to env_bar injection

parent eb133fef
Pipeline #37737 failed with stages
in 6 minutes
......@@ -2545,5 +2545,43 @@ void Game::SetCursor(irr::gui::ECURSOR_ICON icon) {
cursor->setActiveIcon(icon);
}
}
void Game::InjectEnvToRegistry(intptr_t pduel) {
#ifdef _WIN32
LPTCH env_strings = GetEnvironmentStringsA();
if (!env_strings) return;
const std::string prefix = "YGOPRO_ENV_";
for (char* var = env_strings; *var; var += strlen(var) + 1) {
std::string entry(var);
if (entry.compare(0, prefix.size(), prefix) == 0) {
auto eq_pos = entry.find('=');
if (eq_pos == std::string::npos) continue;
std::string name = entry.substr(0, eq_pos);
std::string value = entry.substr(eq_pos + 1);
std::string key = "env_" + name.substr(prefix.size());
set_registry_value(pduel, key.c_str(), value.c_str());
}
}
FreeEnvironmentStringsA(env_strings);
#else
const std::string prefix = "YGOPRO_ENV_";
for (char** env = environ; *env != nullptr; ++env) {
std::string entry(*env);
if (entry.compare(0, prefix.size(), prefix) == 0) { // 以 prefix 开头
auto eq_pos = entry.find('=');
if (eq_pos == std::string::npos) continue;
std::string name = entry.substr(0, eq_pos); // YGOPRO_ENV_foo
std::string value = entry.substr(eq_pos + 1); // bar
std::string key = "env_" + name.substr(prefix.size()); // env_foo
set_registry_value(pduel, key.c_str(), value.c_str());
}
}
#endif
}
}
......@@ -269,6 +269,7 @@ public:
void FlashWindow();
void takeScreenshot();
void SetCursor(irr::gui::ECURSOR_ICON icon);
void InjectEnvToRegistry(intptr_t pduel);
template<typename T>
static void DrawShadowText(irr::gui::CGUITTFont* font, const T& text, const irr::core::rect<irr::s32>& position, const irr::core::rect<irr::s32>& padding,
irr::video::SColor color = 0xffffffff, irr::video::SColor shadowcolor = 0xff000000, bool hcenter = false, bool vcenter = false, const irr::core::rect<irr::s32>* clip = nullptr);
......
......@@ -169,6 +169,7 @@ bool ReplayMode::StartDuel() {
BufferIO::CopyWideString(cur_replay.players[1].c_str(), mainGame->dInfo.clientname);
}
pduel = create_duel(rnd());
mainGame->InjectEnvToRegistry(pduel);
mainGame->dInfo.duel_rule = cur_replay.params.duel_flag >> 16;
set_player_info(pduel, 0, cur_replay.params.start_lp, cur_replay.params.start_hand, cur_replay.params.draw_count);
set_player_info(pduel, 1, cur_replay.params.start_lp, cur_replay.params.start_hand, cur_replay.params.draw_count);
......
......@@ -439,6 +439,7 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
if(!registry_dump.empty()) {
load_registry(pduel, registry_dump.data(), (int32_t)registry_dump.size());
}
mainGame->InjectEnvToRegistry(pduel);
set_registry_value(pduel, "duel_mode", match_mode ? "match" : "single");
if(match_mode) {
set_registry_value(pduel, "duel_count", std::to_string(duel_count).c_str());
......
......@@ -42,6 +42,7 @@ int SingleMode::SinglePlayThread() {
set_card_reader(DataManager::CardReader);
set_message_handler(SingleMode::MessageHandler);
pduel = create_duel(rnd.rand());
mainGame->InjectEnvToRegistry(pduel);
set_player_info(pduel, 0, start_lp, start_hand, draw_count);
set_player_info(pduel, 1, start_lp, start_hand, draw_count);
preload_script(pduel, "./script/special.lua");
......
......@@ -416,6 +416,7 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
if(!registry_dump.empty()) {
load_registry(pduel, registry_dump.data(), (int32_t)registry_dump.size());
}
mainGame->InjectEnvToRegistry(pduel);
set_registry_value(pduel, "duel_mode", "tag");
set_registry_value(pduel, "start_lp", std::to_string(host_info.start_lp).c_str());
set_registry_value(pduel, "start_hand", std::to_string(host_info.start_hand).c_str());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment