mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-21 20:29:29 +08:00
fix: handle battle verify for global speedup of hook
This commit is contained in:
@@ -246,19 +246,45 @@ void Cracker::disable_all() {
|
||||
disable_global_speedup();
|
||||
}
|
||||
|
||||
void Cracker::enable_global_speedup(float rate) {
|
||||
// IS_ENABLED(GLOBAL_SPEEDUP)
|
||||
void Cracker::enable_global_speedup() {
|
||||
IS_ENABLED(GLOBAL_SPEEDUP)
|
||||
m_global_speedup_timer.stop();
|
||||
m_global_speedup_timer.setInterval([rate]() {
|
||||
get_Time_set_timeScale()(rate);
|
||||
m_global_speedup_timer.setInterval([this]() {
|
||||
get_Time_set_timeScale()(m_global_speedup_rate);
|
||||
}, 500);
|
||||
|
||||
auto gen_new_total_time = [this](double total_time) -> double {
|
||||
return total_time / m_global_speedup_rate;
|
||||
};
|
||||
|
||||
m_original.GetBattleCheckResult = m_state["GetBattleCheckResult"];
|
||||
m_state["GetBattleCheckResult"] = [this, gen_new_total_time](sol::this_state L, Lua::VariadicArgs args) {
|
||||
double total_time = args[2];
|
||||
std::vector<Lua::Object> new_args(args.begin(), args.end());
|
||||
new_args[2] = sol::make_object(L, gen_new_total_time(total_time));
|
||||
return m_original.GetBattleCheckResult(sol::as_args(new_args));
|
||||
};
|
||||
|
||||
m_original.FinishStageCommand_GeneralPackage = m_state["FinishStageCommand"]["GeneralPackage"];
|
||||
m_state["FinishStageCommand"]["GeneralPackage"] = [this, gen_new_total_time](sol::this_state L, Lua::VariadicArgs args) -> Lua::Table {
|
||||
Lua::Table ret = m_original.FinishStageCommand_GeneralPackage(args);
|
||||
double total_time = ret["total_time"];
|
||||
ret["total_time"] = gen_new_total_time(total_time);
|
||||
return ret;
|
||||
};
|
||||
ENABLE(GLOBAL_SPEEDUP)
|
||||
}
|
||||
|
||||
void Cracker::update_global_speedup_rate(float rate) {
|
||||
m_global_speedup_rate = rate;
|
||||
}
|
||||
|
||||
void Cracker::disable_global_speedup() {
|
||||
// IS_DISABLED(GLOBAL_SPEEDUP)
|
||||
IS_DISABLED(GLOBAL_SPEEDUP)
|
||||
m_global_speedup_timer.stop();
|
||||
get_Time_set_timeScale()(1.0);
|
||||
m_state["GetBattleCheckResult"] = m_original.GetBattleCheckResult;
|
||||
m_state["FinishStageCommand"]["GeneralPackage"] = m_original.FinishStageCommand_GeneralPackage;
|
||||
DISABLE(GLOBAL_SPEEDUP)
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,8 @@ public:
|
||||
|
||||
void disable_all();
|
||||
|
||||
void enable_global_speedup(float rate);
|
||||
void enable_global_speedup();
|
||||
void update_global_speedup_rate(float rate);
|
||||
void disable_global_speedup();
|
||||
|
||||
void enable_gg_factor();
|
||||
@@ -164,6 +165,8 @@ private:
|
||||
Lua::Function Ship_cosumeEnergy;
|
||||
Lua::Function Ship_getEnergy;
|
||||
Lua::Function Ship_intimacyAdditions;
|
||||
Lua::Function GetBattleCheckResult;
|
||||
Lua::Function FinishStageCommand_GeneralPackage;
|
||||
} m_original;
|
||||
struct {
|
||||
Lua::Function Ship_getIntimacyLevel;
|
||||
@@ -184,6 +187,7 @@ private:
|
||||
ShipProperties m_globle_ship_properties;
|
||||
std::map<ShipId, ShipProperties> m_specific_ship_properties;
|
||||
Timer m_global_speedup_timer;
|
||||
float m_global_speedup_rate = 1.0;
|
||||
};
|
||||
|
||||
#endif //CRACKER_HPP
|
||||
|
||||
@@ -604,11 +604,22 @@ CrackerServer::CrackerServer() {
|
||||
});
|
||||
|
||||
Post("/enable_global_speedup", [](const httplib::Request& req, httplib::Response& res) {
|
||||
try {
|
||||
Cracker::Instance().enable_global_speedup();
|
||||
} catch (std::exception& e) {
|
||||
SPDLOG_ERROR("Enable global speedup failed: {}", e.what());
|
||||
res.status = 500;
|
||||
return;
|
||||
}
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Post("/update_global_speedup_rate", [](const httplib::Request& req, httplib::Response& res) {
|
||||
try {
|
||||
Json::Reader reader;
|
||||
Json::Value j;
|
||||
reader.parse(req.body, j);
|
||||
Cracker::Instance().enable_global_speedup(j["rate"].asFloat());
|
||||
Cracker::Instance().update_global_speedup_rate(j["rate"].asFloat());
|
||||
} catch (std::exception& e) {
|
||||
SPDLOG_ERROR("Enable global speedup failed: {}", e.what());
|
||||
res.status = 500;
|
||||
|
||||
@@ -92,6 +92,9 @@ POST http://127.0.0.1:23897/disable_opsi_fast_move
|
||||
###
|
||||
POST http://127.0.0.1:23897/enable_global_speedup
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:23897/update_global_speedup_rate
|
||||
|
||||
{
|
||||
"rate": 10.0
|
||||
}
|
||||
|
||||
@@ -234,8 +234,11 @@ class CrackApi:
|
||||
def disable_opsi_fast_move(self):
|
||||
self.post("disable_opsi_fast_move")
|
||||
|
||||
def enable_global_speedup(self, rate: GlobalSpeedupRate):
|
||||
self.post("enable_global_speedup", data=rate.json())
|
||||
def enable_global_speedup(self):
|
||||
self.post("enable_global_speedup")
|
||||
|
||||
def update_global_speedup_rate(self, rate: GlobalSpeedupRate):
|
||||
self.post("update_global_speedup_rate", data=rate.json())
|
||||
|
||||
def disable_global_speedup(self):
|
||||
self.post("disable_global_speedup")
|
||||
|
||||
@@ -161,7 +161,8 @@ def do_crack_op(config: AzurLaneConfig, device: Device, ops: Union[Type[CrackOp.
|
||||
rate = float(deep_get(config.data, "Hook.Misc.GlobalSpeedup", 1.0))
|
||||
if rate == 1.0:
|
||||
continue
|
||||
api.enable_global_speedup(CrackApi.GlobalSpeedupRate(rate=rate))
|
||||
api.update_global_speedup_rate(CrackApi.GlobalSpeedupRate(rate=rate))
|
||||
api.enable_global_speedup()
|
||||
elif op == CrackOp.DisableGlobalSpeedup:
|
||||
api.disable_global_speedup()
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user