-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK: Add MasterMaterialResource::find (for PipelineStates)
- Loading branch information
Showing
5 changed files
with
158 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
namespace sdk::renderer { | ||
struct PipelineState { | ||
// Opaque data (for now) | ||
}; | ||
} |
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 "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); | ||
} | ||
} |
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,19 @@ | ||
#pragma once | ||
|
||
#include <string_view> | ||
|
||
#include "ShaderResource.hpp" | ||
#include "../renderer/PipelineState.hpp" | ||
|
||
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: | ||
}; | ||
} |
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,11 @@ | ||
#pragma once | ||
|
||
#include "../ResourceManager.hpp" | ||
|
||
namespace sdk::renderer { | ||
class ShaderResource : public sdk::Resource { | ||
public: | ||
|
||
private: | ||
}; | ||
} |