Skip to content

Commit b695c41

Browse files
authored
Merge pull request #56 from apple1417/master
prevent setting struct/arrays to themselves, don't consider `Undefine` a pre-existing console key
2 parents ef8e0cb + 9d7e378 commit b695c41

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
lines changed

changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@
3939
[bebaeab4](https://github.com/bl-sdk/unrealsdk/commit/bebaeab4)
4040

4141

42+
- Trying to set a struct, array, or multicast delegate to itself is now a no-op, and prints a
43+
warning.
44+
45+
[8a98db1f](https://github.com/bl-sdk/unrealsdk/commit/8a98db1f)
46+
47+
- The console key will now also be overwritten if it was previously set to `Undefine`.
48+
49+
[631fa41e](https://github.com/bl-sdk/unrealsdk/commit/631fa41e)
50+
4251
## v1.4.0
4352
- Fixed that UE3 `WeakPointer`s would always return null, due to an incorrect offset in the
4453
`UObject` header layout.

src/unrealsdk/game/bl2/console.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ bool inject_console_hook(hook_manager::Details& hook) {
271271
console_output_text = console->get<UFunction, BoundFunction>(L"OutputTextLine"_fn);
272272

273273
auto existing_console_key = console->get<UNameProperty>(L"ConsoleKey"_fn);
274-
if (existing_console_key != L"None"_fn || existing_console_key == L"Undefine"_fn) {
274+
if (existing_console_key != L"None"_fn && existing_console_key != L"Undefine"_fn) {
275275
LOG(MISC, "Console key is already set to '{}'", existing_console_key);
276276
} else {
277277
std::string wanted_console_key{config::get_str("unrealsdk.console_key").value_or("Tilde")};

src/unrealsdk/game/bl3/console.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ bool inject_console_hook(hook_manager::Details& hook) {
195195
inner_obj->get<UStructProperty>(L"ConsoleKey"_fn).get<UNameProperty>(L"KeyName"_fn);
196196
FName console_key{0, 0};
197197

198-
if (existing_console_key != L"None"_fn || existing_console_key == L"Undefine"_fn) {
198+
if (existing_console_key != L"None"_fn && existing_console_key != L"Undefine"_fn) {
199199
LOG(MISC, "Console key is already set to {}", existing_console_key);
200200

201201
console_key = existing_console_key;

src/unrealsdk/unreal/classes/properties/uarrayproperty.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ void PropTraits<UArrayProperty>::set(const UArrayProperty* prop,
4141
+ (std::string)inner->Name);
4242
}
4343

44-
cast(inner, [prop, addr, &value]<typename T>(const T* inner) {
45-
auto arr = reinterpret_cast<TArray<void>*>(addr);
44+
auto arr = reinterpret_cast<TArray<void>*>(addr);
45+
if (arr->data != nullptr && arr->data == value.base.get()->data) {
46+
LOG(DEV_WARNING, L"Refusing to set array property {} to itself, at address {:p}",
47+
prop->get_path_name(), reinterpret_cast<void*>(addr));
48+
return;
49+
}
4650

51+
cast(inner, [prop, &arr, &value]<typename T>(const T* inner) {
4752
auto new_size = value.size();
4853
arr->resize(new_size, prop->ElementSize);
4954

src/unrealsdk/unreal/classes/properties/umulticastdelegateproperty.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ void PropTraits<UMulticastDelegateProperty>::set(const UMulticastDelegatePropert
2828
+ (std::string)prop->get_signature()->Name);
2929
}
3030

31+
auto arr = reinterpret_cast<TArray<FScriptDelegate>*>(addr);
32+
if (arr->data != nullptr && arr->data == value.base.get()->data) {
33+
LOG(DEV_WARNING,
34+
L"Refusing to set multicast delegate property {} to itself, at address {:p}",
35+
prop->get_path_name(), reinterpret_cast<void*>(addr));
36+
return;
37+
}
38+
3139
// Can just memcpy the array contents
3240
static_assert(std::is_trivially_copyable_v<FScriptDelegate>);
3341

34-
auto arr = reinterpret_cast<TArray<FScriptDelegate>*>(addr);
3542
arr->resize(value.base->size());
3643
memcpy(arr->data, value.base->data, value.base->size() * sizeof(*arr->data));
3744
}

src/unrealsdk/unreal/wrappers/wrapped_struct.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
namespace unrealsdk::unreal {
1212

1313
void copy_struct(uintptr_t dest, const WrappedStruct& src) {
14+
if (dest == reinterpret_cast<uintptr_t>(src.base.get())) {
15+
LOG(DEV_WARNING, "Refusing to copy struct of type {} to itself, at address {:p}",
16+
src.type->Name, src.base.get());
17+
return;
18+
}
19+
1420
for (const auto& prop : src.type->properties()) {
1521
cast(prop, [dest, &src]<typename T>(const T* prop) {
1622
for (size_t i = 0; i < (size_t)prop->ArrayDim; i++) {

0 commit comments

Comments
 (0)