Skip to content

Commit

Permalink
Add "Spawn Native Console" button under CVars
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Dec 12, 2023
1 parent 7443f23 commit e1ac360
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/mods/vr/CVarManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <sdk/CVar.hpp>
#include <sdk/threading/GameThreadWorker.hpp>
#include <sdk/ConsoleManager.hpp>
#include <sdk/UGameplayStatics.hpp>

#include "Framework.hpp"

Expand Down Expand Up @@ -46,6 +47,29 @@ CVarManager::~CVarManager() {
}*/
}

void CVarManager::spawn_console() {
if (m_native_console_spawned) {
return;
}

// Find Engine object and add the Console
const auto engine = sdk::UGameEngine::get();

if (engine != nullptr) {
const auto console_class = engine->get_property<sdk::UClass*>(L"ConsoleClass");
auto game_viewport = engine->get_property<sdk::UObject*>(L"GameViewport");

if (console_class != nullptr && game_viewport != nullptr) {
const auto console = sdk::UGameplayStatics::get()->spawn_object(console_class, game_viewport);

if (console != nullptr) {
game_viewport->get_property<sdk::UObject*>(L"ViewportConsole") = console;
m_native_console_spawned = true;
}
}
}
}

void CVarManager::on_pre_engine_tick(sdk::UGameEngine* engine, float delta) {
ZoneScopedN(__FUNCTION__);

Expand Down Expand Up @@ -73,6 +97,12 @@ void CVarManager::on_draw_ui() {
ImGui::TextWrapped("Frozen CVars: %i", frozen_cvars);

ImGui::Checkbox("Display Console", &m_wants_display_console);

if (!m_native_console_spawned) {
if (ImGui::Button("Spawn Native Console")) {
spawn_console();
}
}

if (ImGui::Button("Dump All CVars")) {
GameThreadWorker::get().enqueue([this]() {
Expand Down
2 changes: 2 additions & 0 deletions src/mods/vr/CVarManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CVarManager final : public ModComponent {
void on_config_load(const utility::Config& cfg, bool set_defaults) override;

void dump_commands();
void spawn_console();

public:
class CVar : public std::enable_shared_from_this<CVar> {
Expand Down Expand Up @@ -173,6 +174,7 @@ class CVarManager final : public ModComponent {
} m_console;

bool m_wants_display_console{false};
bool m_native_console_spawned{false};

static inline std::vector<std::shared_ptr<CVarStandard>> s_default_standard_cvars {
// Bools
Expand Down

0 comments on commit e1ac360

Please sign in to comment.