-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK: Migrate find to ShaderResource because it makes more sense
- Loading branch information
Showing
5 changed files
with
92 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters