From e1ac36057a6a9545f0986b9bdc5ad6bc085c95ee Mon Sep 17 00:00:00 2001 From: praydog Date: Tue, 12 Dec 2023 15:36:27 -0800 Subject: [PATCH] Add "Spawn Native Console" button under CVars --- src/mods/vr/CVarManager.cpp | 30 ++++++++++++++++++++++++++++++ src/mods/vr/CVarManager.hpp | 2 ++ 2 files changed, 32 insertions(+) diff --git a/src/mods/vr/CVarManager.cpp b/src/mods/vr/CVarManager.cpp index 05d0f62a..e3801890 100644 --- a/src/mods/vr/CVarManager.cpp +++ b/src/mods/vr/CVarManager.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "Framework.hpp" @@ -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(L"ConsoleClass"); + auto game_viewport = engine->get_property(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(L"ViewportConsole") = console; + m_native_console_spawned = true; + } + } + } +} + void CVarManager::on_pre_engine_tick(sdk::UGameEngine* engine, float delta) { ZoneScopedN(__FUNCTION__); @@ -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]() { diff --git a/src/mods/vr/CVarManager.hpp b/src/mods/vr/CVarManager.hpp index cc8dc842..37e95d15 100644 --- a/src/mods/vr/CVarManager.hpp +++ b/src/mods/vr/CVarManager.hpp @@ -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 { @@ -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> s_default_standard_cvars { // Bools