Skip to content

Commit

Permalink
Merge branch 'master' into pd-upscaler
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Nov 2, 2024
2 parents 83fd33c + 21c3c02 commit 06c3607
Show file tree
Hide file tree
Showing 30 changed files with 5,728 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
target: [RE2, RE2_TDB66, RE3, RE3_TDB67, RE4, RE7, RE7_TDB49, RE8, DMC5, MHRISE, SF6, DD2]
target: [RE2, RE2_TDB66, RE3, RE3_TDB67, RE4, RE7, RE7_TDB49, RE8, DMC5, MHRISE, SF6, DD2, MHWILDS]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dev-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
target: [RE2, RE2_TDB66, RE3, RE3_TDB67, RE4, RE7, RE7_TDB49, RE8, DMC5, MHRISE, SF6, DD2]
target: [RE2, RE2_TDB66, RE3, RE3_TDB67, RE4, RE7, RE7_TDB49, RE8, DMC5, MHRISE, SF6, DD2, MHWILDS]
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
Expand Down
1,058 changes: 1,056 additions & 2 deletions CMakeLists.txt

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ REF_BUILD_DMC5_SDK = false
REF_BUILD_MHRISE_SDK = false
REF_BUILD_SF6_SDK = false
REF_BUILD_DD2_SDK = false
REF_BUILD_MHWILDS_SDK = false
REF_BUILD_FRAMEWORK = { value = true, comment = "Enable building the full REFramework" }
REF_BUILD_DEPENDENCIES = { value = true, comment = "Enable building dependencies" }

Expand All @@ -64,6 +65,7 @@ build-dmc5-sdk = "REF_BUILD_DMC5_SDK OR REF_BUILD_FRAMEWORK"
build-mhrise-sdk = "REF_BUILD_MHRISE_SDK OR REF_BUILD_FRAMEWORK"
build-sf6-sdk = "REF_BUILD_SF6_SDK OR REF_BUILD_FRAMEWORK"
build-dd2-sdk = "REF_BUILD_DD2_SDK OR REF_BUILD_FRAMEWORK"
build-mhwilds-sdk = "REF_BUILD_MHWILDS_SDK OR REF_BUILD_FRAMEWORK"
build-framework-dependencies = "REF_BUILD_DEPENDENCIES AND CMAKE_SIZEOF_VOID_P EQUAL 8"

[fetch-content.asmjit]
Expand Down Expand Up @@ -184,7 +186,7 @@ tag = "v1.34.10"

[fetch-content.kananlib]
git = "https://github.com/cursey/kananlib"
tag = "cca66766b139994f478ea48befd67a179b7310ab"
tag = "128900b23d02235975ad48388e94f64af3484ec0"

[target.utility]
type = "static"
Expand Down Expand Up @@ -361,6 +363,14 @@ condition = "build-dd2-sdk"
[target.DD2]
type = "game"

[target.MHWILDSSDK]
type = "sdk"
compile-definitions = ["MHWILDS", "REENGINE_PACKED", "REENGINE_AT"]
condition = "build-mhwilds-sdk"

[target.MHWILDS]
type = "game"

[template.plugin]
type = "shared"
include-directories = ["include/"]
Expand Down
9 changes: 8 additions & 1 deletion shared/sdk/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ Application::Function* Application::get_functions() {

const auto module_entry_enum = sdk::find_type_definition("via.ModuleEntry");

if (module_entry_enum == nullptr) {
spdlog::error("Cannot find via.ModuleEntry");
}

// screw that lets just bruteforce through the Application object looking for huge
// list of valid pointers within the current module
for (auto i = 0x100; i < 0x1000; i += sizeof(void*)) try {
Expand All @@ -131,14 +135,17 @@ Application::Function* Application::get_functions() {
if (j == 0 && func.entry == nullptr || IsBadReadPtr(func.entry, sizeof(void*))) {
break; // the first one should always be valid.
}

const auto name = std::string_view{func.description};

if (j == 0) {
if (module_entry_enum != nullptr) {
if (auto f = sdk::get_native_field<uint16_t>(nullptr, module_entry_enum, name, true); f != nullptr) {
if (*f != func.priority) {
spdlog::error("{} priority mismatch: {} != {}", name.data(), *f, func.priority);
break; // the first one should always be valid.
} else{
spdlog::info("{} priority match: {} == {}", name.data(), *f, func.priority);
}
}
} else if (func.priority != 1) {
Expand Down
17 changes: 17 additions & 0 deletions shared/sdk/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,37 @@
#include <cstdint>
#include <string_view>

#include "TDBVer.hpp"

namespace sdk {
struct RETypeDefinition;

struct Application {
struct Function {
void* entry; // 0
void (*func)(void* entry); // 0x8

#if TDB_VER < 74
void* unk; // 0x10
#endif

const char* description; // 0x18
uint16_t priority; // 0x20 (via.ModuleEntry enum)
uint16_t type; // 0x22

#if TDB_VER >= 74
uint8_t pad[0xC8 - 0x1C];
#else
uint8_t pad[0xD0 - 0x24];
#endif
};

#if TDB_VER >= 74
static_assert(sizeof(Function) == 0xC8, "Function has wrong size");
#elif TDB_VER < 74
static_assert(sizeof(Function) == 0xD0, "Function has wrong size");
#endif

static RETypeDefinition* get_type();
static Application* get();

Expand Down
10 changes: 5 additions & 5 deletions shared/sdk/REGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ REGlobals::REGlobals() {
}

m_objects.insert(obj_ptr);
m_object_list.push_back(obj_ptr);
m_object_list.insert(obj_ptr);
} catch(...) {

}
Expand Down Expand Up @@ -111,21 +111,21 @@ REGlobals::REGlobals() {
spdlog::info("Finished REGlobals initialization");
}

std::vector<REManagedObject*> REGlobals::get_objects() {
std::vector<REManagedObject*> out{};
std::unordered_set<REManagedObject*> REGlobals::get_objects() {
std::unordered_set<REManagedObject*> out{};

if (!m_object_list.empty()) {
for (auto obj_ptr : m_object_list) {
if (*obj_ptr != nullptr && !IsBadReadPtr(*obj_ptr, sizeof(void*))) {
out.push_back(*obj_ptr);
out.insert(*obj_ptr);
}
}
} else {
for (auto getter : m_getters) {
auto result = getter.second();

if (result != nullptr) {
out.push_back(result);
out.insert(result);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions shared/sdk/REGlobals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class REGlobals {
return m_objects;
}

std::vector<REManagedObject*> get_objects();
std::unordered_set<REManagedObject*> get_objects();

REType* get_native(std::string_view name);
std::vector<::REType*>& get_native_singleton_types();
Expand All @@ -45,7 +45,7 @@ class REGlobals {

// Raw list of objects (for if the type hasn't been fully initialized, we need to refresh the map)
std::unordered_set<REManagedObject**> m_objects;
std::vector<REManagedObject**> m_object_list;
std::unordered_set<REManagedObject**> m_object_list;
std::unordered_map<std::string, std::function<REManagedObject* ()>> m_getters;

// List of objects we've already logged
Expand Down
10 changes: 6 additions & 4 deletions shared/sdk/REManagedObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ void resolve_add_ref() {
return;
}

constexpr std::array<std::string_view, 3> possible_patterns{
constexpr std::array<std::string_view, 4> possible_patterns{
"40 ? 48 83 EC ? 8B 41 ? 48 8B ? 85 C0 0F ? ? ? ? ? 0F ? ? 0E", // RE2+
"40 ? 48 83 EC ? 8B 41 ? 48 8B ? 85 C0 0F ? ? ? ? ? 80 ? 0E 00", // TDB73+/DD2+
"48 89 ? ? ? 57 48 83 EC ? 0F ? ? 0E" // RE7 TDB49
"48 89 ? ? ? 57 48 83 EC ? 0F ? ? 0E", // RE7 TDB49
"41 57 41 56 41 55 41 54 56 57 55 53 48 83 EC ? 48 89 CE 8B 41 08 85 C0", // MHWILDS+ (or unoptimized compiler builds?)
};

spdlog::info("[REManagedObject] Finding add_ref function...");
Expand All @@ -53,9 +54,10 @@ void resolve_release() {
// because we need to make sure we don't resolve release to the same function.
resolve_add_ref();

constexpr std::array<std::string_view, 2> possible_patterns{
constexpr std::array<std::string_view, 3> possible_patterns{
"40 53 48 83 EC ? 8B 41 08 48 8B D9 85 C0 0F", // RE2+
"40 53 48 83 EC ? 8B 41 08 48 8B D9 48 83 C1 08 85 C0 78" // RE7
"40 53 48 83 EC ? 8B 41 08 48 8B D9 48 83 C1 08 85 C0 78", // RE7
"41 57 41 56 41 55 41 54 56 57 55 53 48 83 EC ? 48 8B 05 ? ? ? ? 48 31 E0 48 89 44 24 30 8B 41 08", // MHWILDS+ (or unoptimized compiler builds?)
};

spdlog::info("[REManagedObject] Finding release function...");
Expand Down
38 changes: 22 additions & 16 deletions shared/sdk/RETransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace sdk {
Vector4f sdk::get_transform_position(RETransform* transform) {
static auto get_position_method = sdk::find_type_definition("via.Transform")->get_method("get_Position");

Vector4f out{};
__declspec(align(16)) Vector4f out{};
get_position_method->call<Vector4f*>(&out, sdk::get_thread_context(), transform);

return out;
Expand All @@ -18,7 +18,7 @@ Vector4f sdk::get_transform_position(RETransform* transform) {
glm::quat sdk::get_transform_rotation(RETransform* transform) {
static auto get_rotation_method = sdk::find_type_definition("via.Transform")->get_method("get_Rotation");

glm::quat out{};
__declspec(align(16)) glm::quat out{};
get_rotation_method->call<glm::quat*>(&out, sdk::get_thread_context(), transform);

return out;
Expand Down Expand Up @@ -46,7 +46,8 @@ void set_transform_position(RETransform* transform, const Vector4f& pos, bool no
if (!no_dirty) {
static auto set_position_method = sdk::find_type_definition("via.Transform")->get_method("set_Position");

set_position_method->call<void*>(sdk::get_thread_context(), transform, &pos);
__declspec(align(16)) Vector4f p = pos;
set_position_method->call<void*>(sdk::get_thread_context(), transform, &p);
} else {
static auto get_parent_method = sdk::find_type_definition("via.Transform")->get_method("get_Parent");
const auto parent_transform = get_parent_method->call<RETransform*>(sdk::get_thread_context(), transform);
Expand All @@ -69,7 +70,8 @@ void set_transform_position(RETransform* transform, const Vector4f& pos, bool no
void set_transform_rotation(RETransform* transform, const glm::quat& rot) {
static auto set_rotation_method = sdk::find_type_definition("via.Transform")->get_method("set_Rotation");

set_rotation_method->call<void*>(sdk::get_thread_context(), transform, &rot);
__declspec(align(16)) glm::quat q = rot;
set_rotation_method->call<void*>(sdk::get_thread_context(), transform, &q);
}

REJoint* sdk::get_joint_parent(REJoint* joint) {
Expand Down Expand Up @@ -106,19 +108,21 @@ uint32_t get_joint_hash(REJoint* joint) {
void sdk::set_joint_position(REJoint* joint, const Vector4f& position) {
static auto set_position_method = sdk::find_type_definition("via.Joint")->get_method("set_Position");

set_position_method->call<void*>(sdk::get_thread_context(), joint, &position);
__declspec(align(16)) Vector4f pos = position;
set_position_method->call<void*>(sdk::get_thread_context(), joint, &pos);
};

void sdk::set_joint_rotation(REJoint* joint, const glm::quat& rotation) {
static auto set_rotation_method = sdk::find_type_definition("via.Joint")->get_method("set_Rotation");

set_rotation_method->call<void*>(sdk::get_thread_context(), joint, &rotation);
__declspec(align(16)) glm::quat rot = rotation;
set_rotation_method->call<void*>(sdk::get_thread_context(), joint, &rot);
};

glm::quat sdk::get_joint_rotation(REJoint* joint) {
static auto get_rotation_method = sdk::find_type_definition("via.Joint")->get_method("get_Rotation");

glm::quat rotation{};
__declspec(align(16)) glm::quat rotation{};
get_rotation_method->call<glm::quat*>(&rotation, sdk::get_thread_context(), joint);

return rotation;
Expand All @@ -127,7 +131,7 @@ glm::quat sdk::get_joint_rotation(REJoint* joint) {
Vector4f sdk::get_joint_position(REJoint* joint) {
static auto get_position_method = sdk::find_type_definition("via.Joint")->get_method("get_Position");

Vector4f position{};
__declspec(align(16)) Vector4f position{};
get_position_method->call<Vector4f*>(&position, sdk::get_thread_context(), joint);

return position;
Expand All @@ -136,7 +140,7 @@ Vector4f sdk::get_joint_position(REJoint* joint) {
glm::quat sdk::get_joint_local_rotation(REJoint* joint) {
static auto get_local_rotation_method = sdk::find_type_definition("via.Joint")->get_method("get_LocalRotation");

glm::quat rotation{};
__declspec(align(16)) glm::quat rotation{};
get_local_rotation_method->call<glm::quat*>(&rotation, sdk::get_thread_context(), joint);

return rotation;
Expand All @@ -145,7 +149,7 @@ glm::quat sdk::get_joint_local_rotation(REJoint* joint) {
Vector4f sdk::get_joint_local_position(REJoint* joint) {
static auto get_local_position_method = sdk::find_type_definition("via.Joint")->get_method("get_LocalPosition");

Vector4f position{};
__declspec(align(16)) Vector4f position{};
get_local_position_method->call<Vector4f*>(&position, sdk::get_thread_context(), joint);

return position;
Expand All @@ -154,13 +158,15 @@ Vector4f sdk::get_joint_local_position(REJoint* joint) {
void sdk::set_joint_local_rotation(REJoint* joint, const glm::quat& rotation) {
static auto set_local_rotation_method = sdk::find_type_definition("via.Joint")->get_method("set_LocalRotation");

set_local_rotation_method->call<void*>(sdk::get_thread_context(), joint, &rotation);
__declspec(align(16)) glm::quat rot = rotation;
set_local_rotation_method->call<void*>(sdk::get_thread_context(), joint, &rot);
};

void sdk::set_joint_local_position(REJoint* joint, const Vector4f& position) {
static auto set_local_position_method = sdk::find_type_definition("via.Joint")->get_method("set_LocalPosition");

set_local_position_method->call<void*>(sdk::get_thread_context(), joint, &position);
__declspec(align(16)) Vector4f pos = position;
set_local_position_method->call<void*>(sdk::get_thread_context(), joint, &pos);
};

std::string sdk::get_joint_name(REJoint* joint) {
Expand Down Expand Up @@ -231,10 +237,10 @@ glm::mat4 calculate_base_transform(const ::RETransform& transform, REJoint* targ

auto parent_transform = calculate_base_transform(transform, parent_joint);

glm::quat base_rotation{};
__declspec(align(16)) glm::quat base_rotation{};
get_base_local_rotation_method->call<glm::quat*>(&base_rotation, sdk::get_thread_context(), target);

Vector4f base_position{};
__declspec(align(16)) Vector4f base_position{};
get_base_local_position_method->call<Vector4f*>(&base_position, sdk::get_thread_context(), target);

// Convert to matrix
Expand Down Expand Up @@ -281,10 +287,10 @@ void calculate_base_transforms(const ::RETransform& transform, REJoint* target,

const auto& parent_transform = it->second;

glm::quat base_rotation{};
__declspec(align(16)) glm::quat base_rotation{};
get_base_local_rotation_method->call<glm::quat*>(&base_rotation, sdk::get_thread_context(), target);

Vector4f base_position{};
__declspec(align(16)) Vector4f base_position{};
get_base_local_position_method->call<Vector4f*>(&base_position, sdk::get_thread_context(), target);

// Convert to matrix
Expand Down
Loading

0 comments on commit 06c3607

Please sign in to comment.