Skip to content

Commit

Permalink
SDK: Migrate find to ShaderResource because it makes more sense
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed May 9, 2024
1 parent d8a0e45 commit 590a222
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 78 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ if(REF_BUILD_RE2_SDK OR REF_BUILD_FRAMEWORK) # build-re2-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down Expand Up @@ -1401,6 +1402,7 @@ if(REF_BUILD_RE2_TDB66SDK OR REF_BUILD_FRAMEWORK) # build-re2tdb66-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down Expand Up @@ -2644,6 +2646,7 @@ if(REF_BUILD_RE3_SDK OR REF_BUILD_FRAMEWORK) # build-re3-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down Expand Up @@ -3472,6 +3475,7 @@ if(REF_BUILD_RE3_TDB67SDK OR REF_BUILD_FRAMEWORK) # build-re3tdb67-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down Expand Up @@ -4922,6 +4926,7 @@ if(REF_BUILD_RE4_SDK OR REF_BUILD_FRAMEWORK) # build-re4-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down Expand Up @@ -5752,6 +5757,7 @@ if(REF_BUILD_RE7_SDK OR REF_BUILD_FRAMEWORK) # build-re7-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down Expand Up @@ -6580,6 +6586,7 @@ if(REF_BUILD_RE7_TDB49SDK OR REF_BUILD_FRAMEWORK) # build-re7tdb49-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down Expand Up @@ -7823,6 +7830,7 @@ if(REF_BUILD_RE8_SDK OR REF_BUILD_FRAMEWORK) # build-re8-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down Expand Up @@ -8860,6 +8868,7 @@ if(REF_BUILD_DMC5_SDK OR REF_BUILD_FRAMEWORK) # build-dmc5-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down Expand Up @@ -9895,6 +9904,7 @@ if(REF_BUILD_MHRISE_SDK OR REF_BUILD_FRAMEWORK) # build-mhrise-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down Expand Up @@ -10932,6 +10942,7 @@ if(REF_BUILD_SF6_SDK OR REF_BUILD_FRAMEWORK) # build-sf6-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down Expand Up @@ -11969,6 +11980,7 @@ if(REF_BUILD_DD2_SDK OR REF_BUILD_FRAMEWORK) # build-dd2-sdk
"shared/sdk/helpers/NativeObject.cpp"
"shared/sdk/renderer/RenderResource.cpp"
"shared/sdk/resources/MasterMaterialResource.cpp"
"shared/sdk/resources/ShaderResource.cpp"
"shared/sdk/Application.hpp"
"shared/sdk/Enums_Internal.hpp"
"shared/sdk/GUIPrimitiveSystem.hpp"
Expand Down
74 changes: 1 addition & 73 deletions shared/sdk/resources/MasterMaterialResource.cpp
Original file line number Diff line number Diff line change
@@ -1,73 +1 @@
#include <spdlog/spdlog.h>
#include <utility/Scan.hpp>
#include <utility/Module.hpp>

#include "../MurmurHash.hpp"

#include "MasterMaterialResource.hpp"

namespace sdk::renderer {
MasterMaterialResource::FindFn MasterMaterialResource::get_find_fn() {
static FindFn fn = []() -> FindFn {
spdlog::info("[MasterMaterialResource::get_find_fn] Scanning for MasterMaterialResource::find");

const auto game = utility::get_executable();
const auto string_data = utility::scan_string(game, "UpdateDepthBlockerState");

if (!string_data) {
spdlog::error("[MasterMaterialResource::get_find_fn] Failed to find UpdateDepthBlockerState string");
return nullptr;
}

const auto string_ref = utility::scan_displacement_reference(game, *string_data);

if (!string_ref) {
spdlog::error("[MasterMaterialResource::get_find_fn] Failed to find UpdateDepthBlockerState reference");
return nullptr;
}

const auto next_fn_call = utility::scan_mnemonic(*string_ref + 4, 100, "CALL");

if (!next_fn_call) {
spdlog::error("[MasterMaterialResource::get_find_fn] Failed to find next CALL instruction");
return nullptr;
}

const auto next_next_fn_call = utility::scan_mnemonic(*next_fn_call + 5, 100, "CALL");

if (!next_next_fn_call) {
spdlog::error("[MasterMaterialResource::get_find_fn] Failed to find next next CALL instruction");
return nullptr;
}

const auto result = utility::resolve_displacement(*next_next_fn_call);

if (!result) {
spdlog::error("[MasterMaterialResource::get_find_fn] Failed to resolve displacement");
return nullptr;
}

spdlog::info("[MasterMaterialResource::get_find_fn] Found MasterMaterialResource::find at {0:x}", *result);

return (FindFn)*result;
}();

return fn;
}

sdk::renderer::PipelineState* MasterMaterialResource::find(uint32_t murmur_hash, uint8_t unk) {
auto fn = get_find_fn();

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

return fn(this, murmur_hash, unk);
}

sdk::renderer::PipelineState* MasterMaterialResource::find(std::string_view name, uint8_t unk) {
const auto murmur_hash = sdk::murmur_hash::calc32_as_utf8(name.data());

return find(murmur_hash, unk);
}
}
#include "MasterMaterialResource.hpp"
5 changes: 0 additions & 5 deletions shared/sdk/resources/MasterMaterialResource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
namespace sdk::renderer {
class MasterMaterialResource : public ShaderResource {
public:
using FindFn = PipelineState* (*)(MasterMaterialResource*, uint32_t, uint8_t);
static FindFn get_find_fn();

PipelineState* find(uint32_t murmur_hash, uint8_t unk);
PipelineState* find(std::string_view name, uint8_t unk);

private:
};
Expand Down
73 changes: 73 additions & 0 deletions shared/sdk/resources/ShaderResource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <spdlog/spdlog.h>
#include <utility/Scan.hpp>
#include <utility/Module.hpp>

#include "../MurmurHash.hpp"

#include "ShaderResource.hpp"

namespace sdk::renderer {
ShaderResource::FindFn ShaderResource::get_find_fn() {
static FindFn fn = []() -> FindFn {
spdlog::info("[ShaderResource::get_find_fn] Scanning for ShaderResource::find");

const auto game = utility::get_executable();
const auto string_data = utility::scan_string(game, "UpdateDepthBlockerState");

if (!string_data) {
spdlog::error("[ShaderResource::get_find_fn] Failed to find UpdateDepthBlockerState string");
return nullptr;
}

const auto string_ref = utility::scan_displacement_reference(game, *string_data);

if (!string_ref) {
spdlog::error("[ShaderResource::get_find_fn] Failed to find UpdateDepthBlockerState reference");
return nullptr;
}

const auto next_fn_call = utility::scan_mnemonic(*string_ref + 4, 100, "CALL");

if (!next_fn_call) {
spdlog::error("[ShaderResource::get_find_fn] Failed to find next CALL instruction");
return nullptr;
}

const auto next_next_fn_call = utility::scan_mnemonic(*next_fn_call + 5, 100, "CALL");

if (!next_next_fn_call) {
spdlog::error("[ShaderResource::get_find_fn] Failed to find next next CALL instruction");
return nullptr;
}

const auto result = utility::resolve_displacement(*next_next_fn_call);

if (!result) {
spdlog::error("[ShaderResource::get_find_fn] Failed to resolve displacement");
return nullptr;
}

spdlog::info("[ShaderResource::get_find_fn] Found ShaderResource::find at {0:x}", *result);

return (FindFn)*result;
}();

return fn;
}

sdk::renderer::PipelineState* ShaderResource::find(uint32_t murmur_hash, uint8_t unk) {
auto fn = get_find_fn();

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

return fn(this, murmur_hash, unk);
}

sdk::renderer::PipelineState* ShaderResource::find(std::string_view name, uint8_t unk) {
const auto murmur_hash = sdk::murmur_hash::calc32_as_utf8(name.data());

return find(murmur_hash, unk);
}
}
6 changes: 6 additions & 0 deletions shared/sdk/resources/ShaderResource.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#pragma once

#include "../ResourceManager.hpp"
#include "../renderer/PipelineState.hpp"

namespace sdk::renderer {
class ShaderResource : public sdk::Resource {
public:
using FindFn = PipelineState* (*)(ShaderResource*, uint32_t, uint8_t);
static FindFn get_find_fn();

PipelineState* find(uint32_t murmur_hash, uint8_t unk);
PipelineState* find(std::string_view name, uint8_t unk);

private:
};
Expand Down

0 comments on commit 590a222

Please sign in to comment.