Skip to content

Commit

Permalink
Merge branch 'praydog:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyhodge authored Sep 21, 2024
2 parents 2eaaa7a + ddabc60 commit 2bcb379
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 17 deletions.
9 changes: 9 additions & 0 deletions src/Mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ class ModCombo : public ModValue<int32_t> {
ImGui::Text("%s: %s", name.data(), m_options[m_value]);
}

void recreate_options(const std::vector<std::string>& options) {
m_options_stdstr = options;
m_options.clear();

for (auto& o : m_options_stdstr) {
m_options.push_back(o.c_str());
}
}

const auto& options() const {
return m_options;
}
Expand Down
1 change: 1 addition & 0 deletions src/mods/APIProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class APIProxy : public Mod {
using REFOnDeviceResetCb = std::function<std::remove_pointer<::REFOnDeviceResetCb>::type>;
using REFOnMessageCb = std::function<std::remove_pointer<::REFOnMessageCb>::type>;
using REFOnImGuiFrameCb = std::function<std::remove_pointer<::REFOnImGuiFrameCb>::type>;
using REFOnImGuiDrawUICb = std::function<std::remove_pointer<::REFOnImGuiDrawUICb>::type>;

bool add_on_lua_state_created(REFLuaStateCreatedCb cb);
bool add_on_lua_state_destroyed(REFLuaStateDestroyedCb cb);
Expand Down
121 changes: 109 additions & 12 deletions src/mods/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,76 @@ std::shared_ptr<Graphics>& Graphics::get() {
return mod;
}

std::optional<std::string> Graphics::on_initialize() {
#if TDB_VER >= 69
const auto raytracing_enum = sdk::find_type_definition("via.render.ExperimentalRayTrace.Raytracing");

if (raytracing_enum == nullptr) {
return Mod::on_initialize(); // OK
}

s_ray_trace_type.clear();
s_ray_trace_type.push_back("Disabled");

s_ray_trace_type.resize(raytracing_enum->get_fields().size() + 1);

int32_t actual_size = 1;

for (auto f : raytracing_enum->get_fields()) {
const auto field_flags = f->get_flags();

if ((field_flags & (uint16_t)via::clr::FieldFlag::Static) != 0 && (field_flags & (uint16_t)via::clr::FieldFlag::Literal) != 0) {
auto raw_data = f->get_data_raw(nullptr, true);
int64_t enum_data = 0;

switch(raytracing_enum->get_valuetype_size()) {
case 1:
enum_data = (int64_t)*(int8_t*)raw_data;
break;
case 2:
enum_data = (int64_t)*(int16_t*)raw_data;
break;
case 4:
enum_data = (int64_t)*(int32_t*)raw_data;
break;
case 8:
enum_data = *(int64_t*)raw_data;
break;
default:
spdlog::error("Unknown enum size: {}", raytracing_enum->get_valuetype_size());
break;
}

if (enum_data < 0 || enum_data + 1 >= s_ray_trace_type.size()) {
spdlog::error("Invalid enum data: {} {}", f->get_name(), enum_data);
continue;
}

auto unfriendly_name = std::string{f->get_name()};

// Format into a friendly name (Spacing between words)
for (size_t i = 1; i < unfriendly_name.size(); ++i) {
if (unfriendly_name[i] >= 'A' && unfriendly_name[i] <= 'Z') {
unfriendly_name.insert(i, " ");
i++;
}
}

s_ray_trace_type[enum_data + 1] = unfriendly_name;
++actual_size;
}
}

s_ray_trace_type.resize(actual_size);
m_ray_trace_type->recreate_options(s_ray_trace_type);
m_ray_trace_clone_type_pre->recreate_options(s_ray_trace_type);
m_ray_trace_clone_type_post->recreate_options(s_ray_trace_type);
m_ray_trace_clone_type_true->recreate_options(s_ray_trace_type);
#endif

return Mod::on_initialize(); // OK
}

void Graphics::on_config_load(const utility::Config& cfg) {
for (IModValue& option : m_options) {
option.config_load(cfg);
Expand Down Expand Up @@ -126,6 +196,11 @@ void Graphics::on_draw_ui() {

if (m_ray_tracing_tweaks->value()) {
m_ray_trace_disable_raster_shadows->draw("Disable Raster Shadows (with PT)");
m_ray_trace_always_recreate_rt_component->draw("Always Recreate RT Component");
// Description of the above option
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Recreates the RT component. Useful if Ray Tracing Tweaks is not working.");
}
m_ray_trace_type->draw("Ray Trace Type");

const auto clone_tooltip =
Expand All @@ -152,9 +227,7 @@ void Graphics::on_draw_ui() {
}

// Hybrid/pure
if (m_ray_trace_type->value() == (int32_t)RayTraceType::Hybrid || m_ray_trace_type->value() == (int32_t)RayTraceType::Pure
|| m_ray_trace_clone_type_true->value() == (int32_t)RayTraceType::Hybrid || m_ray_trace_clone_type_true->value() == (int32_t)RayTraceType::Pure)
{
if (is_pt_type(m_ray_trace_type->value()) || is_pt_type(m_ray_trace_clone_type_true->value())) {
m_bounce_count->draw("Bounce Count");
m_samples_per_pixel->draw("Samples Per Pixel");
}
Expand Down Expand Up @@ -396,8 +469,20 @@ bool Graphics::on_pre_gui_draw_element(REComponent* gui_element, void* primitive
auto game_object = utility::re_component::get_game_object(gui_element);
static auto letter_box_behavior_t = sdk::find_type_definition("app.LetterBoxBehavior");
static auto letter_box_behavior_retype = letter_box_behavior_t != nullptr ? letter_box_behavior_t->get_type() : nullptr;
static auto csmaskui_t = sdk::find_type_definition("app.solid.gui.CSMaskUI");
static auto csmaskui_retype = csmaskui_t != nullptr ? csmaskui_t->get_type() : nullptr;

if (game_object != nullptr && game_object->transform != nullptr) {
// Ultrawide for Dead Rising Deluxe Remaster
if (csmaskui_retype != nullptr) {
auto csmaskui = utility::re_component::find<REComponent*>(game_object->transform, csmaskui_retype);

if (csmaskui != nullptr) {
game_object->shouldDraw = false;
return false;
}
}

const auto name = utility::re_string::get_string(game_object->name);
const auto name_hash = utility::hash(name);

Expand Down Expand Up @@ -917,11 +1002,16 @@ void Graphics::setup_rt_component() {
auto rt_component = utility::re_component::find<REComponent>(game_object->transform, rt_t->get_type());

// Attempt to create the component if it doesn't exist
if (rt_component == nullptr) {
if (rt_component == nullptr || (m_ray_trace_always_recreate_rt_component->value() && m_rt_recreated_component.get() != (sdk::ManagedObject*)rt_component)) {
if (rt_component != nullptr) {
sdk::call_object_func_easy<void*>(rt_component, "destroy", rt_component);
}

rt_component = sdk::call_object_func_easy<REComponent*>(game_object, "createComponent(System.Type)", rt_t->get_runtime_type());

if (rt_component != nullptr) {
spdlog::info("[Graphics] Successfully created new RT component @ {:x}", (uintptr_t)rt_component);
m_rt_recreated_component = (sdk::ManagedObject*)rt_component;
}
}

Expand All @@ -934,7 +1024,7 @@ void Graphics::setup_rt_component() {
m_rt_component = (sdk::ManagedObject*)rt_component;
}

if (m_rt_cloned_component.get() == nullptr && m_ray_trace_clone_type_true->value() > (int32_t)RayTraceType::Disabled) {
if (m_rt_cloned_component.get() == nullptr && m_ray_trace_clone_type_true->value() > 0) {
m_rt_cloned_component = (sdk::ManagedObject*)rt_t->create_instance_full(false);

if (m_rt_cloned_component.get() != nullptr) {
Expand All @@ -959,6 +1049,7 @@ void Graphics::apply_ray_tracing_tweaks() {
static const auto set_RaytracingMode = rt_t->get_method("set_RaytracingMode");
static const auto setBounce = rt_t->get_method("setBounce");
static const auto setSpp = rt_t->get_method("setSpp");
static const auto set_enabled = rt_t->get_method("set_Enabled");

bool any_pt = false;

Expand All @@ -974,11 +1065,17 @@ void Graphics::apply_ray_tracing_tweaks() {
return;
}

if (set_RaytracingMode != nullptr && rt_type > (int32_t)RayTraceType::Disabled) {
any_pt = any_pt || rt_type == (int32_t)RayTraceType::Pure;
if (set_enabled != nullptr) {
set_enabled->call<void>(context, target, true); // Some games have this disabled.
}

const auto is_pure_pt = is_pure_pt_type(rt_type);

if (set_RaytracingMode != nullptr && rt_type > 0) {
any_pt = any_pt || is_pure_pt;
set_RaytracingMode->call<void>(context, target, rt_type - 1);

if (rt_type == (int32_t)RayTraceType::Pure && m_ray_trace_disable_raster_shadows->value()) {
if (is_pure_pt && m_ray_trace_disable_raster_shadows->value()) {
if (get_DynamicShadowEnable != nullptr && set_DynamicShadowEnable != nullptr) {
const bool is_shadow_enabled = get_DynamicShadowEnable->call<bool>(context);

Expand All @@ -991,7 +1088,7 @@ void Graphics::apply_ray_tracing_tweaks() {
}
}

if (rt_type == (int32_t)RayTraceType::Hybrid || rt_type == (int32_t)RayTraceType::Pure) {
if (is_pt_type(rt_type)) { // hybrid or any pure
if (setBounce != nullptr) {
setBounce->call<void>(context, target, m_bounce_count->value());
}
Expand Down Expand Up @@ -1022,7 +1119,7 @@ void* Graphics::rt_draw_hook(REComponent* rt, void* draw_context, void* r8, void
return og(rt, draw_context, r8, r9);
}

if (graphics->m_ray_tracing_tweaks->value() && graphics->m_ray_trace_clone_type_true->value() > (int32_t)RayTraceType::Disabled) {
if (graphics->m_ray_tracing_tweaks->value() && graphics->m_ray_trace_clone_type_true->value() > 0) {
static std::recursive_mutex mtx{};
std::scoped_lock _{mtx};

Expand Down Expand Up @@ -1074,7 +1171,7 @@ void* Graphics::rt_draw_impl_hook(void* rt_impl, void* draw_context, void* r8, v
.unk = unk
};

if (graphics->m_ray_tracing_tweaks->value() && graphics->m_ray_trace_clone_type_pre->value() > (int32_t)RayTraceType::Disabled) {
if (graphics->m_ray_tracing_tweaks->value() && graphics->m_ray_trace_clone_type_pre->value() > 0) {
ray_tracing_mode = graphics->m_ray_trace_clone_type_pre->value() - 1;
og(rt_impl, draw_context, r8, r9, unk);
ray_tracing_mode = old_mode;
Expand All @@ -1085,7 +1182,7 @@ void* Graphics::rt_draw_impl_hook(void* rt_impl, void* draw_context, void* r8, v
result = og(rt_impl, draw_context, r8, r9, unk);
}*/

if (graphics->m_ray_tracing_tweaks->value() && graphics->m_ray_trace_clone_type_post->value() > (int32_t)RayTraceType::Disabled) {
if (graphics->m_ray_tracing_tweaks->value() && graphics->m_ray_trace_clone_type_post->value() > 0) {
ray_tracing_mode = graphics->m_ray_trace_clone_type_post->value() - 1;
og(rt_impl, draw_context, r8, r9, unk);
ray_tracing_mode = old_mode;
Expand Down
55 changes: 51 additions & 4 deletions src/mods/Graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Graphics : public Mod {
static std::shared_ptr<Graphics>& get();

public:
std::optional<std::string> on_initialize() override;

std::string_view get_name() const override { return "Graphics"; };

void on_config_load(const utility::Config& cfg) override;
Expand Down Expand Up @@ -139,6 +141,7 @@ class Graphics : public Mod {
std::optional<size_t> m_rt_type_offset{};
sdk::intrusive_ptr<sdk::ManagedObject> m_rt_component{};
sdk::intrusive_ptr<sdk::ManagedObject> m_rt_cloned_component{};
sdk::intrusive_ptr<sdk::ManagedObject> m_rt_recreated_component{};
void* m_pt_pipeline_resource{nullptr};
void* m_dxr_shader_resource{nullptr};

Expand All @@ -165,7 +168,15 @@ class Graphics : public Mod {

const ModToggle::Ptr m_ultrawide_fix{ ModToggle::create(generate_name("UltrawideFix"), false) };
const ModToggle::Ptr m_ultrawide_vertical_fov{ ModToggle::create(generate_name("UltrawideFixVerticalFOV_V2"), false) };

// There is a trend with newer games where there actually is Ultrawide support, so we don't want to actually touch the FOV by default
// And sometimes messing with the FOV causes permanent issues with the UI, so don't touch it by default
#if TDB_VER >= 73
const ModToggle::Ptr m_ultrawide_custom_fov{ModToggle::create(generate_name("UltrawideCustomFOV"), true)};
#else
const ModToggle::Ptr m_ultrawide_custom_fov{ModToggle::create(generate_name("UltrawideCustomFOV"), false)};
#endif

const ModToggle::Ptr m_ultrawide_constrain_ui{ModToggle::create(generate_name("UltrawideConstrainUI"), false)};
const ModToggle::Ptr m_ultrawide_constrain_child_ui{ModToggle::create(generate_name("UltrawideConstrainChildUI"), false)};
const ModSlider::Ptr m_ultrawide_fov_multiplier{ ModSlider::create(generate_name("UltrawideFOVMultiplier_V2"), 0.01f, 3.0f, 1.0f) };
Expand All @@ -177,7 +188,7 @@ class Graphics : public Mod {
const ModToggle::Ptr m_shader_playground { ModToggle::create(generate_name("ShaderPlayground"), false) };
const ModToggle::Ptr m_ray_tracing_tweaks { ModToggle::create(generate_name("RayTracingTweaks"), false) };

enum class RayTraceType : uint8_t {
/*enum class RayTraceType : uint8_t {
Disabled = 0,
AmbientOcclusion = 1,
Hybrid = 2,
Expand All @@ -186,19 +197,53 @@ class Graphics : public Mod {
ScreenSpacePhotonMapping = 5,
Debug = 6,
ASVGF = 7,
};
};*/

static const inline std::vector<std::string> s_ray_trace_type {
// We will replace this dynamically with reflected data upon loading
static inline std::vector<std::string> s_ray_trace_type {
"Disabled",
"Ambient Occlusion",
"Hybrid Path Tracing",
"Pure Path Tracing",
"Path Space Filter",
"Screen Space Photon Mapping",
"Debug",
"ASVGF",
"A S V G F",
};

static std::string_view get_ray_trace_type_name(uint8_t type) {
if (type >= s_ray_trace_type.size()) {
return "Unknown";
}

return s_ray_trace_type[type];
}

static bool is_pt_type(uint8_t type) {
const auto name = get_ray_trace_type_name(type);

if (name == "Hybrid Path Tracing" || name == "Pure Path Tracing") {
return true;
}

// Added in TDB73, post dragon's dogma 2
if (name == "Prototype Reference") {
return true;
}

return false;
}

static bool is_pure_pt_type(uint8_t type) {
const auto name = get_ray_trace_type_name(type);

if (name == "Pure Path Tracing" || name == "Prototype Reference") {
return true;
}

return false;
}

static const inline std::vector<std::string> s_bounce_count {
"0",
"1",
Expand All @@ -215,6 +260,7 @@ class Graphics : public Mod {

const ModCombo::Ptr m_ray_trace_type{ ModCombo::create(generate_name("RayTraceType"), s_ray_trace_type) };
const ModToggle::Ptr m_ray_trace_disable_raster_shadows{ ModToggle::create(generate_name("RayTraceDisableRasterShadowsWithPT"), true) };
const ModToggle::Ptr m_ray_trace_always_recreate_rt_component{ ModToggle::create(generate_name("RayTraceAlwaysRecreateRTComponent"), false) };
bool m_was_shadows_disabled{ false };
const ModCombo::Ptr m_ray_trace_clone_type_true{ ModCombo::create(generate_name("RayTraceTrueCloneType"), s_ray_trace_type) };
const ModCombo::Ptr m_ray_trace_clone_type_pre{ ModCombo::create(generate_name("RayTraceCloneTypePre"), s_ray_trace_type) };
Expand Down Expand Up @@ -248,6 +294,7 @@ class Graphics : public Mod {
*m_ray_tracing_tweaks,
*m_ray_trace_type,
*m_ray_trace_disable_raster_shadows,
*m_ray_trace_always_recreate_rt_component,
*m_ray_trace_clone_type_true,
*m_ray_trace_clone_type_pre,
*m_ray_trace_clone_type_post,
Expand Down
5 changes: 5 additions & 0 deletions src/mods/IntegrityCheckBypass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ void IntegrityCheckBypass::disable_update_timers(std::string_view name) const {
void IntegrityCheckBypass::ignore_application_entries() {
Hooks::get()->ignore_application_entry(0x76b8100bec7c12c3);
Hooks::get()->ignore_application_entry(0x9f63c0fc4eea6626);

#if TDB_VER >= 73
Hooks::get()->ignore_application_entry(0x00c0ab9309584734);
Hooks::get()->ignore_application_entry(0xa474f1d3a294e6a4);
#endif
}

void IntegrityCheckBypass::immediate_patch_re8() {
Expand Down
8 changes: 7 additions & 1 deletion src/mods/VR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,13 @@ class VR : public Mod {
const ModToggle::Ptr m_force_volumetrics_settings{ ModToggle::create(generate_name("ForceVolumetrics"), true) };
const ModToggle::Ptr m_force_lensflares_settings{ ModToggle::create(generate_name("ForceLensFlares"), true) };
const ModToggle::Ptr m_force_dynamic_shadows_settings{ ModToggle::create(generate_name("ForceDynamicShadows"), true) };
const ModToggle::Ptr m_allow_engine_overlays{ ModToggle::create(generate_name("AllowEngineOverlays"), true) };

#if TDB_VER < 73
const ModToggle::Ptr m_allow_engine_overlays{ ModToggle::create(generate_name("AllowEngineOverlays_V2"), true) };
#else
const ModToggle::Ptr m_allow_engine_overlays{ ModToggle::create(generate_name("AllowEngineOverlays_V2"), false) };
#endif

const ModToggle::Ptr m_desktop_fix{ ModToggle::create(generate_name("DesktopRecordingFix"), true) };
const ModToggle::Ptr m_desktop_fix_skip_present{ ModToggle::create(generate_name("DesktopRecordingFixSkipPresent"), true) };

Expand Down

0 comments on commit 2bcb379

Please sign in to comment.