2022-05-17 03:13:41 +03:00
|
|
|
#include "pch-il2cpp.h"
|
|
|
|
#include "AutoFish.h"
|
|
|
|
|
|
|
|
#include <helpers.h>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <cheat/events.h>
|
|
|
|
#include <cheat/game/util.h>
|
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
namespace cheat::feature
|
2022-05-17 03:13:41 +03:00
|
|
|
{
|
|
|
|
AutoFish::AutoFish() : Feature(),
|
|
|
|
NFEX(f_Enabled, "Auto Fish", "m_AutoFish", "AutoFish", false, false),
|
|
|
|
NF(f_DelayBeforeCatch, "Delay before catch", "AutoFish", 2000),
|
|
|
|
NF(f_AutoRecastRod, "Recast rod", "AutoFish", true),
|
|
|
|
NF(f_DelayBeforeRecast, "Delay before recast", "AutoFish", 500)
|
|
|
|
{
|
|
|
|
events::GameUpdateEvent += MY_METHOD_HANDLER(AutoFish::OnGameUpdate);
|
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
HookManager::install(app::FishingModule_RequestFishCastRod, FishingModule_RequestFishCastRod_Hook);
|
|
|
|
HookManager::install(app::FishingModule_onFishChosenNotify, FishingModule_onFishChosenNotify_Hook);
|
|
|
|
HookManager::install(app::FishingModule_OnFishBiteRsp, FishingModule_OnFishBiteRsp_Hook);
|
2022-05-17 03:13:41 +03:00
|
|
|
HookManager::install(app::FishingModule_OnFishBattleBeginRsp, FishingModule_OnFishBattleBeginRsp_Hook);
|
2022-05-28 04:21:08 -06:00
|
|
|
HookManager::install(app::FishingModule_OnFishBattleEndRsp, FishingModule_OnFishBattleEndRsp_Hook);
|
|
|
|
HookManager::install(app::FishingModule_OnExitFishingRsp, FishingModule_OnExitFishingRsp_Hook);
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const FeatureGUIInfo& AutoFish::GetGUIInfo() const
|
|
|
|
{
|
|
|
|
static const FeatureGUIInfo info{ "Fishing", "World", true };
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoFish::DrawMain()
|
|
|
|
{
|
|
|
|
ConfigWidget("Enabled", f_Enabled, "Automatically catch fish.");
|
|
|
|
ConfigWidget("Delay (ms)", f_DelayBeforeCatch, 100, 500, 4000, "Fish will be caught after this delay (in ms).");
|
|
|
|
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
|
|
|
ConfigWidget(f_AutoRecastRod, "If enabled, rod will recasted. Without visualization.");
|
|
|
|
ConfigWidget("Delay (ms)", f_DelayBeforeRecast, 10, 100, 4000, "Rod will be recast after this delay (in ms).");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AutoFish::NeedStatusDraw() const
|
2022-05-28 04:21:08 -06:00
|
|
|
{
|
2022-05-17 03:13:41 +03:00
|
|
|
return f_Enabled;
|
|
|
|
}
|
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
void AutoFish::DrawStatus()
|
2022-05-17 03:13:41 +03:00
|
|
|
{
|
|
|
|
ImGui::Text("Auto Fish");
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoFish& AutoFish::GetInstance()
|
|
|
|
{
|
|
|
|
static AutoFish instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
void AutoFish::FishingModule_onFishChosenNotify_Hook(void* __this, void* notify, MethodInfo* method)
|
|
|
|
{
|
2022-05-17 03:13:41 +03:00
|
|
|
CALL_ORIGIN(FishingModule_onFishChosenNotify_Hook, __this, notify, method);
|
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
auto& autoFish = GetInstance();
|
|
|
|
if (!autoFish.f_Enabled)
|
|
|
|
return;
|
2022-05-17 03:13:41 +03:00
|
|
|
|
|
|
|
app::FishingModule_RequestFishBite(__this, nullptr);
|
2022-05-28 04:21:08 -06:00
|
|
|
}
|
2022-05-17 03:13:41 +03:00
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
void AutoFish::FishingModule_OnFishBiteRsp_Hook(void* __this, app::FishBiteRsp* rsp, MethodInfo* method)
|
|
|
|
{
|
2022-05-17 03:13:41 +03:00
|
|
|
auto& autoFish = GetInstance();
|
|
|
|
if (!autoFish.f_Enabled)
|
|
|
|
{
|
|
|
|
CALL_ORIGIN(FishingModule_OnFishBiteRsp_Hook, __this, rsp, method);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
app::FishingModule_RequestFishBattleBegin(__this, nullptr);
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
void AutoFish::FishingModule_OnFishBattleBeginRsp_Hook(void* __this, app::FishBattleBeginRsp* rsp, MethodInfo* method)
|
|
|
|
{
|
|
|
|
auto& autoFish = GetInstance();
|
|
|
|
if (!autoFish.f_Enabled)
|
|
|
|
{
|
2022-05-17 03:13:41 +03:00
|
|
|
CALL_ORIGIN(FishingModule_OnFishBattleBeginRsp_Hook, __this, rsp, method);
|
2022-05-28 04:21:08 -06:00
|
|
|
return;
|
|
|
|
}
|
2022-05-17 03:13:41 +03:00
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
std::lock_guard<std::mutex> catchLock(autoFish.m_BattleFinishTimestampMutex);
|
|
|
|
autoFish.m_BattleFinishTimestamp = app::TimeUtil_get_NowTimeStamp(nullptr) + autoFish.f_DelayBeforeCatch;
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
void AutoFish::FishingModule_OnFishBattleEndRsp_Hook(void* __this, app::FishBattleEndRsp* rsp, MethodInfo* method)
|
|
|
|
{
|
2022-05-17 03:13:41 +03:00
|
|
|
CALL_ORIGIN(FishingModule_OnFishBattleEndRsp_Hook, __this, rsp, method);
|
|
|
|
|
|
|
|
auto& autoFish = GetInstance();
|
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
if (rsp->fields.battleResult_ == app::FishBattleResult__Enum::Cancel
|
|
|
|
|| rsp->fields.battleResult_ == app::FishBattleResult__Enum::Exit)
|
2022-05-17 03:13:41 +03:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> _lock2(autoFish.m_RecastTimestampMutex);
|
|
|
|
autoFish.m_RecastTimestamp = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!autoFish.f_Enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rsp->fields.retcode_ != 0)
|
|
|
|
{
|
|
|
|
LOG_WARNING("Failed to catch fish, retrying in %u ms", autoFish.f_DelayBeforeCatch);
|
2022-05-28 04:21:08 -06:00
|
|
|
std::lock_guard<std::mutex> catchLock(autoFish.m_BattleFinishTimestampMutex);
|
|
|
|
autoFish.m_BattleFinishTimestamp = app::TimeUtil_get_NowTimeStamp(nullptr) + autoFish.f_DelayBeforeCatch;
|
2022-05-17 03:13:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!autoFish.f_AutoRecastRod)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> _lock(autoFish.m_RecastTimestampMutex);
|
2022-05-28 04:21:08 -06:00
|
|
|
autoFish.m_RecastTimestamp = app::TimeUtil_get_NowTimeStamp(nullptr) + autoFish.f_DelayBeforeRecast;
|
|
|
|
}
|
2022-05-17 03:13:41 +03:00
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
void AutoFish::FishingModule_OnExitFishingRsp_Hook(void* __this, void* rsp, MethodInfo* method)
|
|
|
|
{
|
2022-05-17 03:13:41 +03:00
|
|
|
CALL_ORIGIN(FishingModule_OnExitFishingRsp_Hook, __this, rsp, method);
|
|
|
|
|
|
|
|
auto& autoFish = GetInstance();
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> _lock(autoFish.m_RecastTimestampMutex);
|
|
|
|
autoFish.m_LastCastData.exist = false;
|
2022-05-28 04:21:08 -06:00
|
|
|
}
|
2022-05-17 03:13:41 +03:00
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
void AutoFish::FishingModule_RequestFishCastRod_Hook(void* __this, uint32_t baitId, uint32_t rodId, app::Vector3 pos, uint32_t rodEntityId, MethodInfo* method)
|
|
|
|
{
|
2022-05-17 03:13:41 +03:00
|
|
|
CALL_ORIGIN(FishingModule_RequestFishCastRod_Hook, __this, baitId, rodId, pos, rodEntityId, method);
|
|
|
|
|
|
|
|
auto& autoFish = GetInstance();
|
|
|
|
|
|
|
|
autoFish.m_LastCastData.exist = true;
|
|
|
|
autoFish.m_LastCastData.fishingModule = __this;
|
|
|
|
autoFish.m_LastCastData.baitId = baitId;
|
|
|
|
autoFish.m_LastCastData.rodId = rodId;
|
|
|
|
autoFish.m_LastCastData.pos = pos;
|
|
|
|
autoFish.m_LastCastData.rodEntityId = rodEntityId;
|
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
autoFish.m_RecastTimestamp = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoFish::OnGameUpdate()
|
|
|
|
{
|
|
|
|
auto timestamp = app::TimeUtil_get_NowTimeStamp(nullptr);
|
2022-05-17 03:13:41 +03:00
|
|
|
|
|
|
|
std::lock_guard<std::mutex> _lock(m_BattleFinishTimestampMutex);
|
|
|
|
std::lock_guard<std::mutex> _lock2(m_RecastTimestampMutex);
|
2022-05-28 04:21:08 -06:00
|
|
|
|
2022-05-17 03:13:41 +03:00
|
|
|
if (!m_LastCastData.exist)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_BattleFinishTimestamp != 0 && timestamp > m_BattleFinishTimestamp)
|
|
|
|
{
|
|
|
|
m_BattleFinishTimestamp = 0;
|
|
|
|
|
|
|
|
app::FishingModule_RequestFishBattleEnd(m_LastCastData.fishingModule, app::FishBattleResult__Enum::Succ, f_DelayBeforeCatch == 4.0f,
|
|
|
|
static_cast<float>(f_DelayBeforeCatch / 1000), nullptr);
|
|
|
|
}
|
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
if (m_RecastTimestamp != 0 && timestamp > m_RecastTimestamp)
|
|
|
|
{
|
|
|
|
m_RecastTimestamp = 0;
|
2022-05-17 03:13:41 +03:00
|
|
|
|
2022-05-28 04:21:08 -06:00
|
|
|
app::FishingModule_RequestFishCastRod(m_LastCastData.fishingModule, m_LastCastData.baitId,
|
|
|
|
m_LastCastData.rodId, m_LastCastData.pos, m_LastCastData.rodEntityId, nullptr);
|
|
|
|
}
|
|
|
|
}
|
2022-05-17 03:13:41 +03:00
|
|
|
}
|
|
|
|
|