Skip to content

Commit

Permalink
Merge branch 'feat/cheats'
Browse files Browse the repository at this point in the history
  • Loading branch information
keton committed Mar 18, 2024
2 parents d3979d9 + b21faaa commit 8037f24
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 31 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

[fetch-content.uevr]
git = "https://github.com/praydog/UEVR"
tag = "067279517877c0b3dd8a1bb46a7124c1e1aac113"
tag = "8b2fc9f2a8c50b01c0b48a98d94f03df434f0caf"

[target.ace_combat_plugin]
type = "shared"
Expand Down
64 changes: 60 additions & 4 deletions include/acesdk/Mission.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ class Mission : public API::UObject
public:
using API::UObject::get_full_name;

static API::UClass *static_class(bool force_search = false)
static API::UClass *static_class()
{
static API::UClass *result = nullptr;
if(!result || force_search) {
if(!result) {
result = API::get()->find_uobject<API::UClass>(L"Class /Script/Nimbus.Mission");
}
return result;
}

static Mission *get_instance(bool force_search = false)
static Mission *get_instance()
{
auto klass = static_class(force_search);
auto klass = Mission::static_class();
if(klass) {
return klass->get_first_object_matching<Mission>();
}
Expand All @@ -44,4 +44,60 @@ class Mission : public API::UObject

return params.res;
}

void complete()
{
static const auto func = Mission::static_class()->find_function(L"Complete");
if(!func) {
API::get()->log_error("Mission::Complete not found");
return;
}

struct
{
int dummy;
} params{0};

process_event(func, &params);
}

void complete_cooldown_override(float new_cooldown_fading_duration, float new_cooldown_duration)
{
static const auto func =
Mission::static_class()->find_function(L"CompleteCoolDownOverride");
if(!func) {
API::get()->log_error("Mission::CompleteCoolDownOverride not found");
return;
}

struct
{
float new_cooldown_fading_duration;
float new_cooldown_duration;
} params{
.new_cooldown_fading_duration = new_cooldown_fading_duration,
.new_cooldown_duration = new_cooldown_duration,
};

process_event(func, &params);
}

void force_pause_mission_timer(bool paused)
{
static const auto func =
Mission::static_class()->find_function(L"ForcePauseMissionTimer_S");
if(!func) {
API::get()->log_error("Mission::ForcePauseMissionTimer_S not found");
return;
}

struct
{
bool paused;
} params{
.paused = paused,
};

process_event(func, &params);
}
};
24 changes: 24 additions & 0 deletions include/acesdk/NimbusCheatManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "uevr/API.hpp"

#include "uesdk/CheatManager.hpp"

using namespace uevr;

class NimbusCheatManager : public CheatManager
{
public:
static API::UClass *static_class()
{
static auto result =
API::get()->find_uobject<API::UClass>(L"Class /Script/Nimbus.NimbusCheatManager");
return result;
}

static NimbusCheatManager *get_instance()
{
auto instance = static_class()->get_first_object_matching<NimbusCheatManager>();
return instance;
}
};
8 changes: 4 additions & 4 deletions include/acesdk/NimbusPlayerCameraManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class NimbusPlayerCameraManager : public API::UObject
public:
using API::UObject::get_full_name;

static API::UClass *static_class(bool force_search = false)
static API::UClass *static_class()
{
static API::UClass *result = nullptr;
if(!result || force_search) {
if(!result) {
result = API::get()->find_uobject<API::UClass>(
L"BlueprintGeneratedClass "
L"/Game/Blueprint/GameModes/"
Expand All @@ -21,9 +21,9 @@ class NimbusPlayerCameraManager : public API::UObject
return result;
}

static NimbusPlayerCameraManager *get_instance(bool force_search = false)
static NimbusPlayerCameraManager *get_instance()
{
auto klass = static_class(force_search);
auto klass = NimbusPlayerCameraManager::static_class();
if(klass) {
return klass->get_first_object_matching<NimbusPlayerCameraManager>();
}
Expand Down
32 changes: 32 additions & 0 deletions include/uesdk/CheatManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "uevr/API.hpp"

using namespace uevr;

class CheatManager : public API::UObject
{
public:
static API::UClass *static_class()
{
static auto result =
API::get()->find_uobject<API::UClass>(L"Class /Script/Engine.CheatManager");
return result;
}

void god()
{
static const auto func = CheatManager::static_class()->find_function(L"God");
if(!func) {
API::get()->log_error("CheatManager::God not found");
return;
}

struct
{
int dummy;
} params{0};

process_event(func, &params);
}
};
86 changes: 66 additions & 20 deletions src/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "acesdk/AcePlayerPawn.hpp"
#include "acesdk/Mission.hpp"
#include "acesdk/NimbusCheatManager.hpp"
#include "acesdk/NimbusPlayerCameraManager.hpp"
#include "acesdk/NimbusPlayerController.hpp"

Expand Down Expand Up @@ -368,6 +369,37 @@ class AceCombatPlugin : public uevr::Plugin
m_last_root_rotation.roll);
ImGui::Text("m_last_root_location: X: %f, Y: %f, Z: %f", m_last_root_location.x,
m_last_root_location.y, m_last_root_location.z);

ImGui::Checkbox("Automatically complete mission once it starts",
&m_mission_autocomplete_cheat_enabled);

if(m_should_show_cheat_ui) {
const auto mission = Mission::get_instance();
const auto cheat_manager = NimbusCheatManager::get_instance();

if(mission) {
ImGui::Text("Mission: %ls", mission->get_full_name().c_str());
if(ImGui::Button("Complete mission")) {
mission->complete();
}

if(ImGui::Button("Pause mission timer")) {
mission->force_pause_mission_timer(true);
}

if(ImGui::Button("Unpause mission timer")) {
mission->force_pause_mission_timer(false);
}
}

if(cheat_manager) {
ImGui::Text("CheatManager: %ls", cheat_manager->get_full_name().c_str());

if(ImGui::Button("Toggle God mode")) {
cheat_manager->god();
}
}
}
}
ImGui::End();
}
Expand All @@ -391,29 +423,15 @@ class AceCombatPlugin : public uevr::Plugin
m_last_is_in_igc = false;
m_last_camera_type = CameraType::NO_CAMERA;

m_mission_autocomplete_cheat_applied = false;

stop_camera_setup();

} else {
API::get()->log_info("pawn class NULL");

m_last_player_pawn = nullptr;
}

const auto camera_manager_class = NimbusPlayerCameraManager::static_class(true);
if(camera_manager_class) {
API::get()->log_info("New camera_manager_class: %ls",
camera_manager_class->get_full_name().c_str());
} else {
API::get()->log_info("camera_manager_class NULL");
}

const auto mission_class = NimbusPlayerCameraManager::get_instance(true);
if(mission_class) {
API::get()->log_info("New mission_class: %ls",
mission_class->get_full_name().c_str());
} else {
API::get()->log_info("mission_class NULL");
}
}
}

Expand All @@ -436,6 +454,22 @@ class AceCombatPlugin : public uevr::Plugin
m_camera_setup_start_location = m_last_root_location;
}

void do_mission_autocomplete_cheat()
{
if(m_mission_autocomplete_cheat_enabled && !m_mission_autocomplete_cheat_applied) {
const auto mission_inst = Mission::get_instance();
const auto cheat_manager = NimbusCheatManager::get_instance();

if(!mission_inst || !cheat_manager) {
return;
}

m_mission_autocomplete_cheat_applied = true;
mission_inst->complete_cooldown_override(0.5, 1.0);
cheat_manager->god();
}
}

void do_camera_setup_step(NimbusPlayerCameraManager *const camera_manager)
{
const auto now = std::chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -485,6 +519,8 @@ class AceCombatPlugin : public uevr::Plugin
camera_manager->test_loop_camera_shake_add_scale(-5000.0);
m_last_camera_setup_step = {};
m_last_camera_setup_state = CameraSetupState::None;

do_mission_autocomplete_cheat();
}
break;

Expand Down Expand Up @@ -576,7 +612,7 @@ class AceCombatPlugin : public uevr::Plugin
{
const bool is_drawing_ui = API::get()->param()->functions->is_drawing_ui();

if(is_drawing_ui == last_is_is_drawing_ui) {
if(is_drawing_ui == m_last_is_is_drawing_ui) {
return;
}

Expand All @@ -587,11 +623,13 @@ class AceCombatPlugin : public uevr::Plugin
ImGui::MarkIniSettingsDirty();
}

last_is_is_drawing_ui = is_drawing_ui;
m_last_is_is_drawing_ui = is_drawing_ui;
}

void plugin_on_pre_engine_tick(API::UGameEngine *engine, float delta)
{
m_should_show_cheat_ui = false;

// trigger regardless if player_pawn (the plane) exists
process_ui_enter_exit();

Expand All @@ -608,6 +646,9 @@ class AceCombatPlugin : public uevr::Plugin
process_level_load(player_controller, player_pawn);
process_root_component_data(player_controller, player_pawn);
process_camera_switch(player_controller, player_pawn);

// only show cheat options in ImGui when player plane exists
m_should_show_cheat_ui = true;
}

inline int32_t linear_scale(const int32_t val, const int32_t val_max, const int32_t target_max,
Expand All @@ -618,7 +659,7 @@ class AceCombatPlugin : public uevr::Plugin
}

inline ControlInputs remap_controls(const XINPUT_STATE *const starting_state,
const ControlScheme control_scheme)
const ControlScheme control_scheme)
{
switch(control_scheme) {
case ControlScheme::Mode1:
Expand Down Expand Up @@ -697,7 +738,12 @@ class AceCombatPlugin : public uevr::Plugin
UEVR_Rotatorf m_last_root_rotation{0};

static inline ControlScheme m_control_scheme = ControlScheme::DefaultControls;
bool last_is_is_drawing_ui = false;

bool m_last_is_is_drawing_ui = false;

bool m_should_show_cheat_ui = false;
bool m_mission_autocomplete_cheat_enabled = false;
bool m_mission_autocomplete_cheat_applied = false;
};

// Actually creates the plugin. Very important that this global is created.
Expand Down

0 comments on commit 8037f24

Please sign in to comment.