mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 13:39:25 +08:00
add: chapter auto ambush
This commit is contained in:
@@ -249,6 +249,7 @@ void Cracker::disable_all() {
|
||||
disable_chapter_force_enable_auto_fight();
|
||||
disable_chapter_skip_precombat();
|
||||
disable_chapter_auto_next_battle();
|
||||
disable_chapter_auto_ambush();
|
||||
}
|
||||
|
||||
void Cracker::enable_hooked_lua_function_trace() {
|
||||
@@ -283,6 +284,14 @@ void Cracker::disable_chapter_force_enable_auto_fight() {
|
||||
DISABLE(CHAPTER_FORCE_ENABLE_AUTO_FIGHT);
|
||||
}
|
||||
|
||||
void Cracker::enable_chapter_auto_ambush() {
|
||||
ENABLE(CHAPTER_AUTO_AMBUSH);
|
||||
}
|
||||
|
||||
void Cracker::disable_chapter_auto_ambush() {
|
||||
DISABLE(CHAPTER_AUTO_AMBUSH);
|
||||
}
|
||||
|
||||
void Cracker::enable_skip_ship_gain_show() {
|
||||
ENABLE(SKIP_SHIP_GAIN_SHOW);
|
||||
}
|
||||
@@ -564,6 +573,8 @@ void Cracker::load_lua_resources() {
|
||||
m_lua_res.ChapterProxy = m_state["ChapterProxy"];
|
||||
m_lua_res.ChapterProxy_GetChapterAutoFlag = m_state["ChapterProxy"]["GetChapterAutoFlag"];
|
||||
m_lua_res.ChapterProxy_SetChapterAutoFlag = m_state["ChapterProxy"]["SetChapterAutoFlag"];
|
||||
m_lua_res.Chapter_getChapterCell = m_state["Chapter"]["getChapterCell"];
|
||||
m_lua_res.LevelStageView_emit = m_state["LevelStageView"]["emit"];
|
||||
|
||||
SPDLOG_INFO("Load lua functions");
|
||||
m_original.GetBattleCheckResult = m_state["GetBattleCheckResult"];
|
||||
@@ -599,11 +610,49 @@ void Cracker::load_lua_resources() {
|
||||
m_original.Chapter_IsAutoFight = m_state["Chapter"]["IsAutoFight"];
|
||||
m_original.Chapter_IsSkipPrecombat = m_state["Chapter"]["IsSkipPrecombat"];
|
||||
m_original.Chapter_writeBack = m_state["Chapter"]["writeBack"];
|
||||
m_original.LevelStageView_tryAutoTrigger = m_state["LevelStageView"]["tryAutoTrigger"];
|
||||
}
|
||||
|
||||
void Cracker::hook_all_lua_functions() {
|
||||
SPDLOG_INFO("Hook lua functions");
|
||||
|
||||
// chapter_auto_ambush
|
||||
m_state["LevelStageView"]["tryAutoTrigger"] = [this](sol::this_state L, Lua::VariadicArgs args) -> Lua::Object {
|
||||
CALLED(LevelStageView.tryAutoTrigger);
|
||||
if (!IS_ENABLED(CHAPTER_AUTO_AMBUSH)) {
|
||||
return m_original.LevelStageView_tryAutoTrigger(L, args);
|
||||
}
|
||||
|
||||
Lua::Table self = args[0];
|
||||
std::optional<Lua::Table> chapterVO = self["contextData"]["chapterVO"];
|
||||
|
||||
if (chapterVO.has_value()) {
|
||||
auto& vo = chapterVO.value();
|
||||
Lua::Object row = vo["fleet"]["line"]["row"];
|
||||
Lua::Object column = vo["fleet"]["line"]["column"];
|
||||
|
||||
std::optional<Lua::Table> cell = m_lua_res.Chapter_getChapterCell(L, vo, row, column);
|
||||
if (cell.has_value()) {
|
||||
auto& cell_v = cell.value();
|
||||
int attachment = cell_v["attachment"];
|
||||
int flag = cell_v["flag"];
|
||||
|
||||
if (attachment == 5 && flag == 2) {
|
||||
Lua::Table trigger_arg = m_state.create_table();
|
||||
|
||||
int fleet_id = vo["fleet"]["id"];
|
||||
trigger_arg["type"] = 4;
|
||||
trigger_arg["id"] = fleet_id;
|
||||
trigger_arg["arg1"] = 1;
|
||||
|
||||
m_lua_res.LevelStageView_emit(L, self, sol::make_object(L, "LevelMediator2:ON_OP"), trigger_arg);
|
||||
return sol::make_object(L, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_original.LevelStageView_tryAutoTrigger(L, args);
|
||||
};
|
||||
|
||||
// chapter_auto_next_battle
|
||||
m_state["Chapter"]["writeBack"] = [this](sol::this_state L, Lua::VariadicArgs args) {
|
||||
CALLED(Chapter.writeBack);
|
||||
@@ -1289,6 +1338,7 @@ Cracker::Config Cracker::get_config() {
|
||||
SET_CONFIG_FLAG(CHAPTER_FORCE_ENABLE_AUTO_FIGHT),
|
||||
SET_CONFIG_FLAG(CHAPTER_SKIP_PRECOMBAT),
|
||||
SET_CONFIG_FLAG(CHAPTER_AUTO_NEXT_BATTLE),
|
||||
SET_CONFIG_FLAG(CHAPTER_AUTO_AMBUSH),
|
||||
},
|
||||
.globle_ship_properties = m_globle_ship_properties,
|
||||
.global_speedup_rate = static_cast<int>(m_global_speedup_rate),
|
||||
@@ -1308,6 +1358,12 @@ void Cracker::apply_config(Config& config) {
|
||||
disable_hooked_lua_function_trace();
|
||||
}
|
||||
|
||||
if(IS_CONFIG_ENABLED(CHAPTER_AUTO_AMBUSH)) {
|
||||
enable_chapter_auto_ambush();
|
||||
} else {
|
||||
disable_chapter_auto_ambush();
|
||||
}
|
||||
|
||||
if(IS_CONFIG_ENABLED(CHAPTER_SKIP_PRECOMBAT)) {
|
||||
enable_chapter_skip_precombat();
|
||||
} else {
|
||||
|
||||
@@ -94,6 +94,7 @@ public:
|
||||
bool CHAPTER_FORCE_ENABLE_AUTO_FIGHT = false;
|
||||
bool CHAPTER_SKIP_PRECOMBAT = false;
|
||||
bool CHAPTER_AUTO_NEXT_BATTLE = false;
|
||||
bool CHAPTER_AUTO_AMBUSH = false;
|
||||
} flag;
|
||||
ShipProperties globle_ship_properties;
|
||||
int global_speedup_rate = 1;
|
||||
@@ -141,6 +142,9 @@ public:
|
||||
void enable_chapter_force_enable_auto_fight();
|
||||
void disable_chapter_force_enable_auto_fight();
|
||||
|
||||
void enable_chapter_auto_ambush();
|
||||
void disable_chapter_auto_ambush();
|
||||
|
||||
void enable_skip_ship_gain_show();
|
||||
void disable_skip_ship_gain_show();
|
||||
|
||||
@@ -251,6 +255,7 @@ private:
|
||||
std::atomic<bool> CHAPTER_FORCE_ENABLE_AUTO_FIGHT = false;
|
||||
std::atomic<bool> CHAPTER_SKIP_PRECOMBAT = false;
|
||||
std::atomic<bool> CHAPTER_AUTO_NEXT_BATTLE = false;
|
||||
std::atomic<bool> CHAPTER_AUTO_AMBUSH = false;
|
||||
} m_flag;
|
||||
|
||||
struct {
|
||||
@@ -295,6 +300,7 @@ private:
|
||||
Lua::Function Chapter_IsAutoFight;
|
||||
Lua::Function Chapter_IsSkipPrecombat;
|
||||
Lua::Function Chapter_writeBack;
|
||||
Lua::Function LevelStageView_tryAutoTrigger;
|
||||
} m_original;
|
||||
struct {
|
||||
Lua::Function Clone;
|
||||
@@ -317,6 +323,8 @@ private:
|
||||
Lua::Table ChapterProxy;
|
||||
Lua::Function ChapterProxy_GetChapterAutoFlag;
|
||||
Lua::Function ChapterProxy_SetChapterAutoFlag;
|
||||
Lua::Function Chapter_getChapterCell;
|
||||
Lua::Function LevelStageView_emit;
|
||||
} m_lua_res;
|
||||
std::atomic<double> m_exercise_more_power_rate = 0.03;
|
||||
FakePlayerInfo m_fake_player_info;
|
||||
|
||||
@@ -982,6 +982,28 @@ CrackerServer::CrackerServer() {
|
||||
CRACK_OK();
|
||||
});
|
||||
|
||||
Post("/enable_chapter_auto_ambush", [](const httplib::Request& req, httplib::Response& res) {
|
||||
try {
|
||||
Cracker::Instance().enable_chapter_auto_ambush();
|
||||
} catch (std::exception& e) {
|
||||
SPDLOG_ERROR("Enable chapter auto ambush failed: {}", e.what());
|
||||
res.status = 500;
|
||||
return;
|
||||
}
|
||||
CRACK_OK();
|
||||
});
|
||||
|
||||
Post("/disable_chapter_auto_ambush", [](const httplib::Request& req, httplib::Response& res) {
|
||||
try {
|
||||
Cracker::Instance().disable_chapter_auto_ambush();
|
||||
} catch (std::exception& e) {
|
||||
SPDLOG_ERROR("Disable chapter auto ambush failed: {}", e.what());
|
||||
res.status = 500;
|
||||
return;
|
||||
}
|
||||
CRACK_OK();
|
||||
});
|
||||
|
||||
Post("/init", [](const httplib::Request& req, httplib::Response& res) {
|
||||
try {
|
||||
Cracker::Instance();
|
||||
|
||||
@@ -105,6 +105,7 @@ void CrackerUI::draw_menu() {
|
||||
ImGui::Checkbox("章节图强制开启自动战斗", &CONFIG_FLAG(CHAPTER_FORCE_ENABLE_AUTO_FIGHT));
|
||||
ImGui::Checkbox("章节图跳过战前准备", &CONFIG_FLAG(CHAPTER_SKIP_PRECOMBAT));
|
||||
ImGui::Checkbox("演习锁血", &CONFIG_FLAG(EXERCISE_GOD_MOD));
|
||||
ImGui::Checkbox("自动规避伏击", &CONFIG_FLAG(CHAPTER_AUTO_AMBUSH));
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Checkbox("移除困难图属性限制", &CONFIG_FLAG(REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT));
|
||||
|
||||
@@ -203,6 +203,12 @@ POST http://{{Host}}:{{Port}}/enable_chapter_auto_next_battle
|
||||
###
|
||||
POST http://{{Host}}:{{Port}}/disable_chapter_auto_next_battle
|
||||
|
||||
###
|
||||
POST http://{{Host}}:{{Port}}/enable_chapter_auto_ambush
|
||||
|
||||
###
|
||||
POST http://{{Host}}:{{Port}}/disable_chapter_auto_ambush
|
||||
|
||||
###
|
||||
POST http://{{Host}}:{{Port}}/is_alive
|
||||
|
||||
|
||||
Reference in New Issue
Block a user