Skip to content

Commit

Permalink
Merge pull request #40 from apple1417/master
Browse files Browse the repository at this point in the history
weak, soft, and lazy pointers
  • Loading branch information
apple1417 authored Aug 21, 2024
2 parents 3a5a40f + 9319c5d commit 512985d
Show file tree
Hide file tree
Showing 44 changed files with 1,128 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "[email protected]:bl-sdk/common_dotfiles.git",
"commit": "5404cb2bf2c71c7572667468d58f7518d6e340ef",
"commit": "6b31480199099e9957b18918373a75d979951919",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down
6 changes: 6 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ extend-exclude = [
".typos.toml"
]

[default]
extend-ignore-re = [
# Ignore markdown links to github commits/trees
"\\[[0-9a-fA-F]+?\\]\\(https://github.com/.+?/.+?/(commit|tree)/.+?\\)",
]

[default.extend-identifiers]
llibgcc_s_seh = "llibgcc_s_seh"

Expand Down
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.25)

project(unrealsdk VERSION 1.2.0)

Expand All @@ -14,6 +14,14 @@ set_target_properties(_unrealsdk_interface PROPERTIES
INTERPROCEDURAL_OPTIMIZATION True
)

if(MSVC)
# Under MSVC, enable edit and continue in debug - which conflicts with LTO
set_target_properties(${target_name} PROPERTIES
MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug>:EditAndContinue>"
INTERPROCEDURAL_OPTIMIZATION $<CONFIG:Release>
)
endif()

if(MSVC)
target_compile_options(_unrealsdk_interface INTERFACE /W4)
else()
Expand Down
38 changes: 38 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
# Changelog

## v1.3.0
- Added a `WeakPointer` wrapper class with better ergonomics, including an emulated implementation
when built under UE3.

[fe3a9130](https://github.com/bl-sdk/unrealsdk/commit/fe3a9130)

- Added support for Soft Object, Soft Class, and Lazy Object Pointer properties.

When accessing these via the standard getters/setters, they return their object reference
directly. You can get the object identifier separately via `FSoftObjectPath::get_from` + related.

[8f6fd71d](https://github.com/bl-sdk/unrealsdk/commit/8f6fd71d)

- Console commands bound via the sdk now appear in the sdk log file.

[73ded7cb](https://github.com/bl-sdk/unrealsdk/commit/73ded7cb)

- Fixed that hooks could not always be removed after adding, or that they might not always fire.
This could be caused by constructing `FName`s with strings which were *not* null terminated. The
`FName` constructor no longer takes string views to avoid this, it needs explicitly strings.

[227a93d2](https://github.com/bl-sdk/unrealsdk/commit/227a93d2)

- Moved several functions in the base `unrealsdk` namespace into `unrealsdk::internal`. These were
all functions which relied on a game hook, but were primarily used to implement sdk internals, so
shouldn't really have had reason to be called from user code. For example, `fname_init` is used
to implement the `FName` constructor, so there's no reason for user code to call it directly.

[73ded7cb](https://github.com/bl-sdk/unrealsdk/commit/73ded7cb)

- Added a dedicated `TArray<T>::free()` helper function, and inserted it where appropriate.

[850763f9](https://github.com/bl-sdk/unrealsdk/commit/850763f9)

- Fixed an off by one in basically all array bounds checks.

[001a87be](https://github.com/bl-sdk/unrealsdk/commit/001a87be)

## v1.2.0
- When an exception occurs during a hook, now mention what function it was under, to make debugging
easier.
Expand Down
2 changes: 1 addition & 1 deletion common_cmake
Submodule common_cmake updated 1 files
+0 −12 msvc.cmake
30 changes: 19 additions & 11 deletions src/unrealsdk/game/abstract_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class GObjects;
class UClass;
class UFunction;
struct FFrame;
struct FLazyObjectPtr;
struct FSoftObjectPtr;
struct FText;
struct TemporaryFString;

Expand Down Expand Up @@ -47,32 +49,38 @@ struct AbstractHook {
*/
virtual void post_init(void) {};

// Inner methods accessed by the global wrappers in `unrealsdk.h`
// Inner methods accessed by the global wrappers in `unrealsdk.h` - see there for documentation
[[nodiscard]] virtual bool is_console_ready(void) const = 0;

[[nodiscard]] virtual const unreal::GObjects& gobjects(void) const = 0;
[[nodiscard]] virtual const unreal::GNames& gnames(void) const = 0;
virtual void fname_init(unreal::FName* name, const wchar_t* str, int32_t number) const = 0;
virtual void fframe_step(unreal::FFrame* frame, unreal::UObject* obj, void* param) const = 0;
[[nodiscard]] virtual void* u_malloc(size_t len) const = 0;
[[nodiscard]] virtual void* u_realloc(void* original, size_t len) const = 0;
virtual void u_free(void* data) const = 0;
virtual void process_event(unreal::UObject* object,
unreal::UFunction* func,
void* params) const = 0;
[[nodiscard]] virtual unreal::UObject* construct_object(
unreal::UClass* cls,
unreal::UObject* outer,
const unreal::FName& name,
decltype(unreal::UObject::ObjectFlags) flags,
unreal::UObject* template_obj) const = 0;
virtual void uconsole_output_text(const std::wstring& str) const = 0;
[[nodiscard]] virtual bool is_console_ready(void) const = 0;
[[nodiscard]] virtual std::wstring uobject_path_name(const unreal::UObject* obj) const = 0;
[[nodiscard]] virtual unreal::UObject* find_object(unreal::UClass* cls,
const std::wstring& name) const = 0;
virtual void ftext_as_culture_invariant(unreal::FText* text,
unreal::TemporaryFString&& str) const = 0;
[[nodiscard]] virtual unreal::UObject* load_package(const std::wstring& name,
uint32_t flags) const = 0;

virtual void fname_init(unreal::FName* name, const wchar_t* str, int32_t number) const = 0;
virtual void fframe_step(unreal::FFrame* frame, unreal::UObject* obj, void* param) const = 0;
virtual void process_event(unreal::UObject* object,
unreal::UFunction* func,
void* params) const = 0;
virtual void uconsole_output_text(const std::wstring& str) const = 0;
[[nodiscard]] virtual std::wstring uobject_path_name(const unreal::UObject* obj) const = 0;
virtual void ftext_as_culture_invariant(unreal::FText* text,
unreal::TemporaryFString&& str) const = 0;
virtual void fsoftobjectptr_assign(unreal::FSoftObjectPtr* ptr,
const unreal::UObject* obj) const = 0;
virtual void flazyobjectptr_assign(unreal::FLazyObjectPtr* ptr,
const unreal::UObject* obj) const = 0;
};

#pragma endregion
Expand Down
26 changes: 16 additions & 10 deletions src/unrealsdk/game/bl2/bl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,36 @@ class BL2Hook : public AbstractHook {
void hook(void) override;
void post_init(void) override;

[[nodiscard]] bool is_console_ready(void) const override;

[[nodiscard]] const unreal::GObjects& gobjects(void) const override;
[[nodiscard]] const unreal::GNames& gnames(void) const override;
void fname_init(unreal::FName* name, const wchar_t* str, int32_t number) const override;
void fframe_step(unreal::FFrame* frame, unreal::UObject* obj, void* param) const override;
[[nodiscard]] void* u_malloc(size_t len) const override;
[[nodiscard]] void* u_realloc(void* original, size_t len) const override;
void u_free(void* data) const override;
void process_event(unreal::UObject* object,
unreal::UFunction* func,
void* params) const override;
[[nodiscard]] unreal::UObject* construct_object(unreal::UClass* cls,
unreal::UObject* outer,
const unreal::FName& name,
decltype(unreal::UObject::ObjectFlags) flags,
unreal::UObject* template_obj) const override;
void uconsole_output_text(const std::wstring& str) const override;
[[nodiscard]] bool is_console_ready(void) const override;
[[nodiscard]] std::wstring uobject_path_name(const unreal::UObject* obj) const override;
[[nodiscard]] unreal::UObject* find_object(unreal::UClass* cls,
const std::wstring& name) const override;
void ftext_as_culture_invariant(unreal::FText* text,
unreal::TemporaryFString&& str) const override;
[[nodiscard]] unreal::UObject* load_package(const std::wstring& name,
uint32_t flags) const override;

void fname_init(unreal::FName* name, const wchar_t* str, int32_t number) const override;
void fframe_step(unreal::FFrame* frame, unreal::UObject* obj, void* param) const override;
void process_event(unreal::UObject* object,
unreal::UFunction* func,
void* params) const override;
void uconsole_output_text(const std::wstring& str) const override;
[[nodiscard]] std::wstring uobject_path_name(const unreal::UObject* obj) const override;
void ftext_as_culture_invariant(unreal::FText* text,
unreal::TemporaryFString&& str) const override;
void fsoftobjectptr_assign(unreal::FSoftObjectPtr* ptr,
const unreal::UObject* obj) const override;
void flazyobjectptr_assign(unreal::FLazyObjectPtr* ptr,
const unreal::UObject* obj) const override;
};

template <>
Expand Down
3 changes: 1 addition & 2 deletions src/unrealsdk/game/bl2/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ bool console_command_hook(hook_manager::Details& hook) {
hook.obj->get<UFunction, BoundFunction>(save_config_func).call<void>();
}

// Don't want to log this, just output to console by itself
unrealsdk::uconsole_output_text(unrealsdk::fmt::format(L">>> {} <<<", line));
LOG(INFO, L">>> {} <<<", line);

try {
callback->operator()(line.c_str(), line.size(), cmd_len);
Expand Down
21 changes: 21 additions & 0 deletions src/unrealsdk/game/bl2/persistentobjectptr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "unrealsdk/pch.h"
#include "unrealsdk/game/bl2/bl2.h"
#include "unrealsdk/version_error.h"

#if defined(UE3) && defined(ARCH_X86) && !defined(UNREALSDK_IMPORTING)

namespace unrealsdk::game {

void BL2Hook::fsoftobjectptr_assign(unreal::FSoftObjectPtr* /* ptr */,
const unreal::UObject* /* obj */) const {
throw_version_error("Soft object pointers are not implemented in UE3");
}

void BL2Hook::flazyobjectptr_assign(unreal::FLazyObjectPtr* /* ptr */,
const unreal::UObject* /* obj */) const {
throw_version_error("Lazy object pointers are not implemented in UE3");
}

} // namespace unrealsdk::game

#endif
1 change: 1 addition & 0 deletions src/unrealsdk/game/bl3/bl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void BL3Hook::hook(void) {
find_static_find_object();
find_ftext_as_culture_invariant();
find_load_package();
find_persistent_obj_ptrs();
}

void BL3Hook::post_init(void) {
Expand Down
32 changes: 22 additions & 10 deletions src/unrealsdk/game/bl3/bl3.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class BL3Hook : public AbstractHook {
*/
static void find_load_package(void);

/**
* @brief Finds the required pointers such that `fsoftobjectptr_assign` and
* `flazyobjectptr_assign` may be called.
*/
static void find_persistent_obj_ptrs(void);

/**
* @brief Creates a console and sets the bind (if required), and hooks logging onto it.
*/
Expand All @@ -82,30 +88,36 @@ class BL3Hook : public AbstractHook {
void hook(void) override;
void post_init(void) override;

[[nodiscard]] bool is_console_ready(void) const override;

[[nodiscard]] const unreal::GObjects& gobjects(void) const override;
[[nodiscard]] const unreal::GNames& gnames(void) const override;
void fname_init(unreal::FName* name, const wchar_t* str, int32_t number) const override;
void fframe_step(unreal::FFrame* frame, unreal::UObject* obj, void* param) const override;
[[nodiscard]] void* u_malloc(size_t len) const override;
[[nodiscard]] void* u_realloc(void* original, size_t len) const override;
void u_free(void* data) const override;
void process_event(unreal::UObject* object,
unreal::UFunction* func,
void* params) const override;
[[nodiscard]] unreal::UObject* construct_object(unreal::UClass* cls,
unreal::UObject* outer,
const unreal::FName& name,
decltype(unreal::UObject::ObjectFlags) flags,
unreal::UObject* template_obj) const override;
void uconsole_output_text(const std::wstring& str) const override;
[[nodiscard]] bool is_console_ready(void) const override;
[[nodiscard]] std::wstring uobject_path_name(const unreal::UObject* obj) const override;
[[nodiscard]] unreal::UObject* find_object(unreal::UClass* cls,
const std::wstring& name) const override;
void ftext_as_culture_invariant(unreal::FText* text,
unreal::TemporaryFString&& str) const override;
[[nodiscard]] unreal::UObject* load_package(const std::wstring& name,
uint32_t flags) const override;

void fname_init(unreal::FName* name, const wchar_t* str, int32_t number) const override;
void fframe_step(unreal::FFrame* frame, unreal::UObject* obj, void* param) const override;
void process_event(unreal::UObject* object,
unreal::UFunction* func,
void* params) const override;
void uconsole_output_text(const std::wstring& str) const override;
[[nodiscard]] std::wstring uobject_path_name(const unreal::UObject* obj) const override;
void ftext_as_culture_invariant(unreal::FText* text,
unreal::TemporaryFString&& str) const override;
void fsoftobjectptr_assign(unreal::FSoftObjectPtr* ptr,
const unreal::UObject* obj) const override;
void flazyobjectptr_assign(unreal::FLazyObjectPtr* ptr,
const unreal::UObject* obj) const override;
};

template <>
Expand Down
3 changes: 1 addition & 2 deletions src/unrealsdk/game/bl3/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ void console_command_hook(UObject* console_obj, UnmanagedFString* raw_line) {
// just this, and we'll see if people actually complain
}

// Don't want to log this, just output to console by itself
unrealsdk::uconsole_output_text(unrealsdk::fmt::format(L">>> {} <<<", line));
LOG(INFO, L">>> {} <<<", line);

try {
callback->operator()(line.c_str(), line.size(), cmd_len);
Expand Down
Loading

0 comments on commit 512985d

Please sign in to comment.