Skip to content

Commit

Permalink
SDK: Add UEngine::get_world
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jul 9, 2023
1 parent dd89684 commit 0aa8c34
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
28 changes: 28 additions & 0 deletions shared/sdk/UEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,34 @@ UEngine* UEngine::get() {
return *engine;
}

UWorld* UEngine::get_world() {
const auto& game_instance = get_property<sdk::UObject*>(L"GameInstance");

if (game_instance == nullptr) {
return nullptr;
}

const auto& localplayers = game_instance->get_property<sdk::TArray<sdk::UObject*>>(L"LocalPlayers");

if (localplayers.count == 0) {
return nullptr;
}

const auto localplayer = localplayers.data[0];

if (localplayer == nullptr) {
return nullptr;
}

const auto viewport_client = localplayer->get_property<sdk::UObject*>(L"ViewportClient");

if (viewport_client == nullptr) {
return nullptr;
}

return viewport_client->get_property<sdk::UWorld*>(L"World");
}

std::optional<uintptr_t> UEngine::get_emulatestereo_string_ref_address() {
static const auto addr = []() -> std::optional<uintptr_t> {
SPDLOG_INFO("Searching for correct string reference to \"emulatestereo\"...");
Expand Down
8 changes: 7 additions & 1 deletion shared/sdk/UEngine.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#pragma once

#include "UObject.hpp"

namespace sdk {
class UEngine {
class UWorld;

class UEngine : public sdk::UObject {
public:
static UEngine** get_lvalue();
static UEngine* get();

UWorld* get_world();

public:
void initialize_hmd_device();
static std::optional<uintptr_t> get_initialize_hmd_device_address();
Expand Down

0 comments on commit 0aa8c34

Please sign in to comment.