mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 07:39:25 +08:00
547 lines
18 KiB
C++
547 lines
18 KiB
C++
#ifndef CRACKER_HPP
|
|
#define CRACKER_HPP
|
|
|
|
#include <map>
|
|
#include <optional>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <sol/state_view.hpp>
|
|
#include <sol/variadic_args.hpp>
|
|
#include <vector>
|
|
#include <atomic>
|
|
#include <semaphore>
|
|
#include <json/json.h>
|
|
|
|
#include "timer.hpp"
|
|
|
|
namespace Lua {
|
|
using Table = sol::table;
|
|
using Object = sol::object;
|
|
using Function = sol::function;
|
|
using VariadicArgs = sol::variadic_args;
|
|
using StateView = sol::state_view;
|
|
}
|
|
|
|
class LuaStatePauser {
|
|
public:
|
|
LuaStatePauser(lua_State* L);
|
|
|
|
void do_when_paused(std::function<void()>&& func);
|
|
|
|
private:
|
|
void ensure_debug_hook();
|
|
void register_debug_hook();
|
|
|
|
static std::atomic<std::binary_semaphore*> g_pause_flag;
|
|
static std::atomic<const std::function<void()>*> g_lua_state_operation;
|
|
static void debug_hook(lua_State *L, lua_Debug *ar);
|
|
|
|
std::mutex m_atomic_pause;
|
|
lua_State* m_L;
|
|
};
|
|
|
|
class Cracker {
|
|
public:
|
|
using FunctionId = int;
|
|
using ShipId = int;
|
|
using StorageItemId = int;
|
|
using StorageItemCount = int;
|
|
|
|
// -1 means disabled
|
|
struct ShipProperties {
|
|
int armor = -1;
|
|
int speed = -1;
|
|
int antiaircraft = -1;
|
|
int oxy_recovery_bench = -1;
|
|
int torpedo = -1;
|
|
int hit = -1;
|
|
int sonarRange = -1;
|
|
int attack_duration = -1;
|
|
int raid_distance = -1;
|
|
int oxy_recovery_surface = -1;
|
|
int oxy_recovery = -1;
|
|
int dodge = -1;
|
|
int luck = -1;
|
|
int reload = -1;
|
|
int oxy_cost = -1;
|
|
int durability = -1;
|
|
int air = -1;
|
|
int oxy_max = -1;
|
|
int cannon = -1;
|
|
int antisub = -1;
|
|
};
|
|
|
|
struct FakePlayerInfo {
|
|
std::string name;
|
|
std::string id;
|
|
std::string level;
|
|
};
|
|
|
|
struct ShipInfo {
|
|
int config_id;
|
|
int emotion;
|
|
int rarity;
|
|
int level;
|
|
int exp;
|
|
int curr_star;
|
|
};
|
|
|
|
struct Config {
|
|
struct {
|
|
bool HOOKED_LUA_FUNCTION_TRACE = false;
|
|
bool GLOBAL_SHIP_PROPERTIES_CRACK = false;
|
|
bool FAST_STAGE_MOVE_CRACK = false;
|
|
bool REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT = false;
|
|
bool REMOVE_HARD_MODE_SHIP_TYPE_LIMIT = false;
|
|
bool FAKE_PLAYER_INFO = false;
|
|
bool NO_BB_ANIMATION = false;
|
|
bool NO_EMOTION_WARNING = false;
|
|
bool OPSI_FAST_MOVE = false;
|
|
bool GG_FACTOR = false;
|
|
bool GLOBAL_SPEEDUP = false;
|
|
bool EXERCISE_GOD_MOD = false;
|
|
bool EXERCISE_MORE_POWER = false;
|
|
bool FAST_WAVE = false;
|
|
bool MONSTER_KILL_SELF = false;
|
|
bool SKIP_BATTLE_CELEBRATE = false;
|
|
bool BETTER_GLOBAL_SPEEDUP = false;
|
|
bool NO_DAMAGE = false;
|
|
bool ALL_SKIN = false;
|
|
bool OPSI_FORCE_AUTO = false;
|
|
bool OPSI_NO_MAP_FOG = false;
|
|
bool SKIP_SHIP_GAIN_SHOW = false;
|
|
bool CHAPTER_FORCE_ENABLE_AUTO_FIGHT = false;
|
|
bool CHAPTER_SKIP_PRECOMBAT = false;
|
|
bool CHAPTER_AUTO_NEXT_BATTLE = false;
|
|
bool CHAPTER_AUTO_AMBUSH = false;
|
|
bool CHAPTER_AUTO_CLEAR = false;
|
|
bool SKIP_STORY = false;
|
|
bool INFINITE_BATTLE = false;
|
|
bool SKIP_AIR_STRIKE_ANIMATION = false;
|
|
bool AUTO_ONCE_AGAIN = false;
|
|
bool AUTO_RETIRE = false;
|
|
bool SKIP_ENEMY_SCAN = false;
|
|
bool SKIP_BATTLE_RESULT = false;
|
|
bool SKIP_ENTER_BATTLE = false;
|
|
} flag;
|
|
ShipProperties globle_ship_properties;
|
|
int global_speedup_rate = 1;
|
|
int gg_factor = 1;
|
|
int exercise_more_power_rate = 1;
|
|
int better_global_speedup_rate = 1;
|
|
double chapter_auto_clear_step_interval = 0.5;
|
|
int white_flagship_keep_count = 0;
|
|
};
|
|
|
|
public:
|
|
Cracker(bool need_pause);
|
|
|
|
static Cracker& Instance(bool need_pause = true);
|
|
|
|
int get_coin();
|
|
int get_oil();
|
|
int get_gems();
|
|
int get_level();
|
|
int get_exp();
|
|
int get_merit();
|
|
int get_guild_coin();
|
|
int get_design_prt();
|
|
int get_core_data();
|
|
int get_medal();
|
|
int get_pt();
|
|
int get_specialized_core();
|
|
int get_curr_action_point();
|
|
std::map<ShipId, ShipInfo> scan_dock();
|
|
std::map<StorageItemId, StorageItemCount> scan_storage();
|
|
|
|
std::optional<ShipInfo> get_ship_info(ShipId ship_id);
|
|
std::optional<StorageItemCount> get_storage_item_count(StorageItemId item_id);
|
|
|
|
|
|
void disable_all();
|
|
|
|
void enable_skip_enemy_scan();
|
|
void disable_skip_enemy_scan();
|
|
|
|
void enable_skip_battle_result();
|
|
void disable_skip_battle_result();
|
|
|
|
void skip_enter_battle_pause(bool need_pause);
|
|
void enable_skip_enter_battle();
|
|
void disable_skip_enter_battle();
|
|
|
|
void set_white_flagship_keep_count(int ships);
|
|
void enable_auto_retire();
|
|
void disable_auto_retire();
|
|
|
|
void enable_auto_once_again();
|
|
void disable_auto_once_again();
|
|
|
|
void enable_skip_air_strike_animation();
|
|
void disable_skip_air_strike_animation();
|
|
|
|
void enable_infinite_battle();
|
|
void disable_infinite_battle();
|
|
|
|
void enable_hooked_lua_function_trace();
|
|
void disable_hooked_lua_function_trace();
|
|
|
|
void enable_skip_story();
|
|
void disable_skip_story();
|
|
|
|
void set_chapter_auto_clear_step_interval(double interval);
|
|
void enable_chapter_auto_clear();
|
|
void disable_chapter_auto_clear();
|
|
|
|
void enable_chapter_skip_precombat();
|
|
void disable_chapter_skip_precombat();
|
|
|
|
void enable_chapter_auto_next_battle();
|
|
void disable_chapter_auto_next_battle();
|
|
|
|
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();
|
|
|
|
void enable_opsi_force_auto();
|
|
void disable_opsi_force_auto();
|
|
|
|
void enable_opsi_no_map_fog();
|
|
void disable_opsi_no_map_fog();
|
|
|
|
void enable_all_skin();
|
|
void disable_all_skin();
|
|
|
|
void enable_no_damage();
|
|
void disable_no_damage();
|
|
|
|
void enable_better_global_speedup();
|
|
void update_better_global_speedup_rate(double rate);
|
|
void disable_better_global_speedup();
|
|
|
|
void skip_battle_celebrate_pause(bool need_pause);
|
|
void enable_skip_battle_celebrate();
|
|
void disable_skip_battle_celebrate();
|
|
|
|
void enable_monster_kill_self();
|
|
void disable_monster_kill_self();
|
|
|
|
void enable_fast_wave();
|
|
void disable_fast_wave();
|
|
|
|
void enable_exercise_more_power();
|
|
void update_exercise_more_power_rate(double rate);
|
|
void disable_exercise_more_power();
|
|
|
|
void enable_exercise_god_mode();
|
|
void disable_exercise_god_mode();
|
|
|
|
void enable_global_speedup();
|
|
void update_global_speedup_rate(float rate);
|
|
void disable_global_speedup();
|
|
|
|
void enable_gg_factor();
|
|
void disable_gg_factor();
|
|
void update_gg_factor(double factor);
|
|
|
|
void enable_opsi_fast_move();
|
|
void disable_opsi_fast_move();
|
|
|
|
void no_emotion_warning_pause(bool need_pause);
|
|
void enable_no_emotion_warning();
|
|
void disable_no_emotion_warning();
|
|
|
|
void enable_no_bb_animation();
|
|
void disable_no_bb_animation();
|
|
|
|
void enable_fake_player();
|
|
void disable_fake_player();
|
|
void update_fake_player_info(const FakePlayerInfo& fake_info);
|
|
|
|
void enable_remove_hard_mode_ship_type_limit();
|
|
void disable_remove_hard_mode_ship_type_limit();
|
|
void enable_remove_hard_mode_ship_properties_limit();
|
|
void disable_remove_hard_mode_ship_properties_limit();
|
|
|
|
void fast_stage_move_pause(bool need_pause);
|
|
void enable_fast_stage_move();
|
|
void disable_fast_stage_move();
|
|
|
|
void update_global_ship_properties(const ShipProperties& properties);
|
|
void enable_global_ship_properties_crack();
|
|
void disable_global_ship_properties_crack();
|
|
|
|
void print_table_field(std::vector<std::string>& path);
|
|
void print_value(std::vector<std::string>& path);
|
|
|
|
void better_global_speedup_pause(bool need_pause);
|
|
|
|
Config get_config();
|
|
|
|
void apply_config(Config& config);
|
|
|
|
private:
|
|
void clear_combat_delay_active();
|
|
void clear_combat_delay_active_with_pause();
|
|
void clear_combat_delay_active_without_pause();
|
|
void restore_combat_delay_active();
|
|
void restore_combat_delay_active_with_pause();
|
|
void restore_combat_delay_active_without_pause();
|
|
|
|
void clear_emotion_threshold();
|
|
void clear_emotion_threshold_with_pause();
|
|
void clear_emotion_threshold_without_pause();
|
|
void restore_emotion_threshold();
|
|
void restore_emotion_threshold_with_pause();
|
|
void restore_emotion_threshold_without_pause();
|
|
|
|
void fast_stage_move_set_duration(double duration);
|
|
void fast_stage_move_set_duration_with_pause(double duration);
|
|
void fast_stage_move_set_duration_without_pause(double duration);
|
|
|
|
void skip_battle_celebrate_set_duration(double duration);
|
|
void skip_battle_celebrate_set_duration_with_pause(double duration);
|
|
void skip_battle_celebrate_set_duration_without_pause(double duration);
|
|
|
|
void better_global_speedup_set_rate_with_pause(double rate);
|
|
void better_global_speedup_set_rate_without_pause(double rate);
|
|
|
|
void load_cracker_with_pause();
|
|
void load_cracker_without_pause();
|
|
|
|
void load_real_lua_func();
|
|
|
|
void ensure_data_proxies();
|
|
|
|
void mover_stop(sol::this_state& L);
|
|
void mover_go(sol::this_state& L, Lua::Table& view, Lua::Table& path);
|
|
void mover_step(sol::this_state& L);
|
|
|
|
bool my_ChapterConst_IsBossCell(sol::this_state& L, Lua::Table& cell);
|
|
|
|
int CntNonBoss(sol::this_state& L, Lua::Table& chap);
|
|
|
|
struct Cell {
|
|
int row;
|
|
int column;
|
|
};
|
|
|
|
std::optional<Cell> NearestEnemy(sol::this_state& L, Lua::Table& chap, bool farming);
|
|
|
|
void my_LevelStageView_TryAutoFight(sol::this_state& L, Lua::VariadicArgs& args);
|
|
|
|
void load_lua_resources();
|
|
void hook_all_lua_functions();
|
|
|
|
void better_global_speedup_set_rate(double rate);
|
|
|
|
static bool is_valid_ship(const Lua::Object& obj);
|
|
Lua::Table filter_ship(sol::this_state& l, Lua::VariadicArgs& args);
|
|
void execute_retire_ship(sol::this_state& l, Lua::VariadicArgs& args);
|
|
|
|
static void modify_ship_properties(Lua::Table& properties, const ShipProperties& new_properties);
|
|
static void clear_hard_mode_ship_properties_limit(Lua::Table& t);
|
|
|
|
struct {
|
|
std::atomic<bool> HOOKED_LUA_FUNCTION_TRACE = false;
|
|
std::atomic<bool> GLOBAL_SHIP_PROPERTIES_CRACK = false;
|
|
std::atomic<bool> FAST_STAGE_MOVE_CRACK = false;
|
|
std::atomic<bool> REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT = false;
|
|
std::atomic<bool> REMOVE_HARD_MODE_SHIP_TYPE_LIMIT = false;
|
|
std::atomic<bool> FAKE_PLAYER_INFO = false;
|
|
std::atomic<bool> NO_BB_ANIMATION = false;
|
|
std::atomic<bool> NO_EMOTION_WARNING = false;
|
|
std::atomic<bool> OPSI_FAST_MOVE = false;
|
|
std::atomic<bool> GG_FACTOR = false;
|
|
std::atomic<bool> GLOBAL_SPEEDUP = false;
|
|
std::atomic<bool> EXERCISE_GOD_MOD = false;
|
|
std::atomic<bool> EXERCISE_MORE_POWER = false;
|
|
std::atomic<bool> FAST_WAVE = false;
|
|
std::atomic<bool> MONSTER_KILL_SELF = false;
|
|
std::atomic<bool> SKIP_BATTLE_CELEBRATE = false;
|
|
std::atomic<bool> BETTER_GLOBAL_SPEEDUP = false;
|
|
std::atomic<bool> NO_DAMAGE = false;
|
|
std::atomic<bool> ALL_SKIN = false;
|
|
std::atomic<bool> OPSI_FORCE_AUTO = false;
|
|
std::atomic<bool> OPSI_NO_MAP_FOG = false;
|
|
std::atomic<bool> SKIP_SHIP_GAIN_SHOW = false;
|
|
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;
|
|
std::atomic<bool> CHAPTER_AUTO_CLEAR = false;
|
|
std::atomic<bool> SKIP_STORY = false;
|
|
std::atomic<bool> INFINITE_BATTLE = false;
|
|
std::atomic<bool> SKIP_AIR_STRIKE_ANIMATION = false;
|
|
std::atomic<bool> AUTO_ONCE_AGAIN = false;
|
|
std::atomic<bool> AUTO_RETIRE = false;
|
|
std::atomic<bool> SKIP_ENEMY_SCAN = false;
|
|
std::atomic<bool> SKIP_BATTLE_RESULT = false;
|
|
std::atomic<bool> SKIP_ENTER_BATTLE = false;
|
|
} m_flag;
|
|
|
|
struct {
|
|
Lua::Table player;
|
|
Lua::Table world;
|
|
Lua::Table dock;
|
|
Lua::Table storage;
|
|
} m_data_proxy;
|
|
bool m_proxy_data_loaded = false;
|
|
int m_gg_factor = 1;
|
|
sol::state_view m_state;
|
|
struct {
|
|
Lua::Function Ship_getShipProperties;
|
|
Lua::Function WorldFleetSelectLayer_CheckValid;
|
|
Lua::Function BossSingleBattleFleetSelectSubPanel_CheckValid;
|
|
Lua::Function Chapter_IsEliteFleetLegal;
|
|
Lua::Function Chapter_getConfig;
|
|
Lua::Function PlayerVitaeDetailPage_UpdateInfo;
|
|
Lua::Function ys_Battle_BattleManualWeaponAutoBot_SetActive;
|
|
Lua::Function Ship_cosumeEnergy;
|
|
Lua::Function Ship_getEnergy;
|
|
Lua::Function Ship_intimacyAdditions;
|
|
Lua::Function GetBattleCheckResult;
|
|
Lua::Function FinishStageCommand_GeneralPackage;
|
|
Lua::Function ys_Battle_BattleGateGuild_GeneralPackage;
|
|
Lua::Function ys_Battle_BattleDataFunction_GetBuffTemplate;
|
|
Lua::Function WorldConst_GetTerrainMoveStepDuration;
|
|
Lua::Function ys_Battle_BattleDataFunction_GetDungeonTmpDataByID;
|
|
Lua::Function ys_Battle_BattleEnemyUnit_GetTemplate;
|
|
Lua::Function ys_Battle_BattleState_ExitBattle;
|
|
Lua::Function ys_Battle_BattleState_ScaleTimer;
|
|
Lua::Function ShipSkin_IsShareSkin;
|
|
Lua::Function ShipSkin_CanUseShareSkinForShip;
|
|
Lua::Function ShipSkinProxy_hasSkin;
|
|
Lua::Function ShipSkinProxy_hasNonLimitSkin;
|
|
Lua::Function pg_ConnectionMgr_Send;
|
|
Lua::Function Ship_getSkinId;
|
|
Lua::Function WorldMap_CanAutoFight;
|
|
Lua::Function WorldMap_UpdateVisionFlag;
|
|
Lua::Function NewBattleResultDisplayAwardPage_ShowShips;
|
|
Lua::Function BaseUI_emit;
|
|
Lua::Function Chapter_CanActivateAutoFight;
|
|
Lua::Function Chapter_IsAutoFight;
|
|
Lua::Function Chapter_IsSkipPrecombat;
|
|
Lua::Function Chapter_writeBack;
|
|
Lua::Function LevelStageView_tryAutoTrigger;
|
|
Lua::Function LevelStageView_TryAutoFight;
|
|
Lua::Function Story_Ctor;
|
|
Lua::Function ContinuousOperationRuntimeData_ConsumeBattleTime;
|
|
Lua::Function ActivityProxy_UseContinuousTime;
|
|
Lua::Function LevelScene_doPlayAirStrike;
|
|
Lua::Function LevelStageTotalRewardPanel_UpdateView;
|
|
Lua::Function NewBattleResultScene_SetUp;
|
|
Lua::Function ys_Battle_BattleUIMediator_SeaSurfaceShift;
|
|
Lua::Function LevelScene_doTracking;
|
|
} m_original;
|
|
struct {
|
|
Lua::Function Clone;
|
|
Lua::Function Ship_getIntimacyLevel;
|
|
Lua::Table pg_intimacy_template;
|
|
struct {
|
|
std::string Durability;
|
|
std::string Cannon;
|
|
std::string Torpedo;
|
|
std::string AntiAircraft;
|
|
std::string AntiSub;
|
|
std::string Air;
|
|
std::string Reload;
|
|
std::string Hit;
|
|
std::string Dodge;
|
|
} AttributeType;
|
|
std::string BattleResultMediator_GET_NEW_SHIP;
|
|
std::string NewBattleResultMediator_GET_NEW_SHIP;
|
|
Lua::Function getProxy;
|
|
Lua::Table ChapterProxy;
|
|
Lua::Function ChapterProxy_GetChapterAutoFlag;
|
|
Lua::Function ChapterProxy_SetChapterAutoFlag;
|
|
Lua::Function Chapter_getChapterCell;
|
|
Lua::Function LevelStageView_emit;
|
|
Lua::Function Chapter_emit;
|
|
int ChapterConst_OpMove;
|
|
int ChapterConst_CellFlagActive;
|
|
Lua::Function ChapterConst_IsEnemyAttach;
|
|
std::string LevelMediator2_ON_OP;
|
|
Lua::Function Timer_New;
|
|
Lua::Function Timer_Start;
|
|
Lua::Function ChapterConst_IsBossCell;
|
|
int ChapterConst_CellFlagDisabled;
|
|
Lua::Function Chapter_checkAnyInteractive;
|
|
Lua::Function Chapter_GetFleetOfDuty;
|
|
Lua::Function Chapter_findPath;
|
|
int ChapterConst_SubjectPlayer;
|
|
int Ship_ENERGY_LOW;
|
|
int Ship_ENERGY_MID;
|
|
Lua::Function BaseUI_closeView;
|
|
std::string LevelMediator2_ON_RETRACKING;
|
|
Lua::Object PlayerProxy;
|
|
Lua::Object BayProxy;
|
|
std::string GAME_DESTROY_SHIPS;
|
|
Lua::Function Proxy_getData;
|
|
Lua::Function Ship_calReturnRes;
|
|
Lua::Function Player_GoldMax;
|
|
Lua::Function Player_OilMax;
|
|
Lua::Object pg_m02;
|
|
Lua::Function pg_m02_sendNotification;
|
|
Lua::Function BayProxy_getShips;
|
|
Lua::Function Ship_isMaxStar;
|
|
Lua::Function Ship_getGroupId;
|
|
Lua::Function Ship_getMaxStar;
|
|
Lua::Function Ship_getStar;
|
|
int Ship_LOCK_STATE_UNLOCK;
|
|
int Ship_LOCK_STATE_LOCK;
|
|
Lua::Function Ship_GetLockState;
|
|
Lua::Function Ship_getRarity;
|
|
Lua::Function Ship_getFlag;
|
|
Lua::Function BayProxy_findShipsByGroup;
|
|
Lua::Function _map;
|
|
Lua::Function _select;
|
|
Lua::Function NewBattleResultScene_GoBack;
|
|
double ys_Battle_BattleConfig_COMBAT_DELAY_ACTIVE;
|
|
} m_lua_res;
|
|
|
|
struct {
|
|
Lua::Function Chapter_IsAutoFight;
|
|
Lua::Function LevelStageView_tryAutoTrigger;
|
|
} m_real_func;
|
|
|
|
struct {
|
|
std::optional<Lua::Table> path;
|
|
int idx = 1;
|
|
bool moving = false;
|
|
int stepSize = 3;
|
|
int currentStepSize = 3;
|
|
int lastTargetIdx = 0;
|
|
std::optional<Lua::Table> lastMoveStartP;
|
|
std::atomic<double> interval = 0.5;
|
|
std::optional<Lua::Table> view;
|
|
} m_mover;
|
|
|
|
std::atomic<double> m_exercise_more_power_rate = 0.03;
|
|
FakePlayerInfo m_fake_player_info;
|
|
ShipProperties m_globle_ship_properties;
|
|
std::map<ShipId, ShipProperties> m_specific_ship_properties;
|
|
Timer m_global_speedup_timer;
|
|
std::atomic<float> m_global_speedup_rate = 1.0;
|
|
std::atomic<double> m_better_global_speedup_rate = 1.0;
|
|
LuaStatePauser m_lua_state_pauser;
|
|
std::atomic<bool> m_better_global_speedup_need_pause = false;
|
|
std::atomic<bool> m_skip_battle_celebrate_need_pause = false;
|
|
std::atomic<bool> m_fast_stage_move_need_pause = false;
|
|
std::atomic<bool> m_no_emotion_warning_need_pause = false;
|
|
std::atomic<bool> m_skip_enter_battle_need_pause = false;
|
|
std::atomic<int> m_keep_white_flagship_number = 0;
|
|
|
|
static std::vector<std::string> s_shipStatus;
|
|
static std::vector<int> s_excludedShips;
|
|
static std::vector<int> s_shipRarityId;
|
|
static std::map<std::string_view, int> s_shipRarityNameToId;
|
|
};
|
|
|
|
#endif //CRACKER_HPP
|