Skip to content

Commit

Permalink
SDK: Add FField/UField default detection
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jul 7, 2023
1 parent 1cdc168 commit 83a840f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions shared/sdk/FField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class FField {
static inline uint32_t s_next_offset{0x20}; // not correct always, we bruteforce it later
static inline uint32_t s_name_offset{0x28}; // not correct always, we bruteforce it later

static inline bool s_uses_ufield_only{false};

friend class UStruct;
};
}
18 changes: 15 additions & 3 deletions shared/sdk/UClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ void UStruct::update_offsets() {
const auto possible_name_a1 = possible_fname_a1.to_string();

if (possible_name_a1 == L"X" || possible_name_a1 == L"Y" || possible_name_a1 == L"Z") {
SPDLOG_INFO("[UStruct] Found Children at offset 0x{:X}", i);
SPDLOG_INFO("[UStruct] Found ChildProperties at offset 0x{:X}", i);
SPDLOG_INFO("[UStruct] Found FField/UField Name at offset 0x{:X} ({})", j, utility::narrow(possible_name_a1));
s_children_offset = i;
s_child_properties_offset = i;
FField::s_name_offset = j;

// Now we need to locate the "Next" field of the UField struct.
Expand Down Expand Up @@ -147,6 +147,18 @@ void UStruct::update_offsets() {
SPDLOG_INFO("[UStruct] Found true UField Next at offset 0x{:X} ({})", k, utility::narrow(potential_next_field_name));
FField::s_next_offset = k;

try {
const auto uvalue = ((UObject*)value);

if (uvalue->is_a(sdk::UField::static_class())) {
UField::s_next_offset = k;
FField::s_uses_ufield_only = true; // for older versions of the engine
SPDLOG_INFO("[UStruct] UField detected, setting UField::s_next_offset to 0x{:X}", k);
}
} catch(...) {
// dont care
}

const auto next_next = potential_field->get_next();

if (next_next != nullptr) try {
Expand Down Expand Up @@ -212,7 +224,7 @@ void UStruct::update_offsets() {
}

if (!found) {
SPDLOG_ERROR("[UStruct] Failed to find Children and Name!");
SPDLOG_ERROR("[UStruct] Failed to find ChildProperties and Name!");
}
} else {
SPDLOG_ERROR("[UStruct] Failed to find Matrix/Vector!");
Expand Down
15 changes: 12 additions & 3 deletions shared/sdk/UClass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ class UField : public UObject {
static UClass* static_class();
static void update_offsets();

UField* get_next() const {
return *(UField**)((uintptr_t)this + s_next_offset);
}

protected:
static inline bool s_attempted_update_offsets{false};
static inline uint32_t s_next_offset{0x28}; // not correct always, we bruteforce it later

friend class UStruct;
};
Expand All @@ -28,8 +32,12 @@ class UStruct : public UField {
return *(UStruct**)((uintptr_t)this + s_super_struct_offset);
}

FField* get_children() const {
return *(FField**)((uintptr_t)this + s_children_offset);
UField* get_children() const {
return *(UField**)((uintptr_t)this + s_children_offset);
}

FField* get_child_properties() const {
return *(FField**)((uintptr_t)this + s_child_properties_offset);
}

bool is_a(UStruct* other) const {
Expand All @@ -45,7 +53,8 @@ class UStruct : public UField {
protected:
static inline bool s_attempted_update_offsets{false};
static inline uint32_t s_super_struct_offset{0x40}; // not correct always, we bruteforce it later
static inline uint32_t s_children_offset{0x48}; // not correct always, we bruteforce it later
static inline uint32_t s_children_offset{0x48}; // For UField variants
static inline uint32_t s_child_properties_offset{0x48}; // not correct always, we bruteforce it later // Children (old)/ChildProperties
static inline uint32_t s_properties_size_offset{0x50}; // not correct always, we bruteforce it later

friend class UField;
Expand Down

0 comments on commit 83a840f

Please sign in to comment.