-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathaddon.cpp
More file actions
1786 lines (1653 loc) · 74.4 KB
/
Copy pathaddon.cpp
File metadata and controls
1786 lines (1653 loc) · 74.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2024 Carlos Lopez
* SPDX-License-Identifier: MIT
*/
#define ImTextureID ImU64
// #define DEBUG_LEVEL_0
#include <algorithm>
#include <mutex>
#include <shared_mutex>
#include <sstream>
#include <unordered_map>
#include <deps/imgui/imgui.h>
#include <include/reshade.hpp>
#include <embed/shaders.h>
#include "../../mods/shader.hpp"
#include "../../mods/swapchain.hpp"
#include "../../utils/bitwise.hpp"
#include "../../utils/data.hpp"
#include "../../utils/hash.hpp"
#include "../../utils/random.hpp"
#include "../../utils/settings.hpp"
#include "../../utils/state.hpp"
#include "../../utils/swapchain.hpp"
#include "./shared.h"
namespace {
renodx::mods::shader::CustomShaders custom_shaders = {__ALL_CUSTOM_SHADERS};
ShaderInjectData shader_injection;
const std::string build_date = __DATE__;
const std::string build_time = __TIME__;
float current_settings_mode = 0;
float current_render_reshade_before_ui = 0;
bool UsingSwapchainUpgrade() {
return true;
}
bool UsingSwapchainUtil() {
return (current_render_reshade_before_ui != 0.f
|| UsingSwapchainUpgrade());
}
void ApplySwapChainEncodingTarget(float encoding_value) {
const bool is_hdr10 = encoding_value == 4.f;
const bool is_scrgb = encoding_value == 5.f;
if (is_hdr10) {
renodx::mods::swapchain::target_format = reshade::api::format::r10g10b10a2_unorm;
renodx::mods::swapchain::target_color_space = reshade::api::color_space::hdr10_st2084;
renodx::mods::swapchain::use_resize_buffer = false;
} else if (is_scrgb) {
renodx::mods::swapchain::target_format = reshade::api::format::r16g16b16a16_float;
renodx::mods::swapchain::target_color_space = reshade::api::color_space::extended_srgb_linear;
renodx::mods::swapchain::use_resize_buffer = false;
} else {
renodx::mods::swapchain::target_format = reshade::api::format::r8g8b8a8_unorm;
renodx::mods::swapchain::target_color_space = reshade::api::color_space::srgb_nonlinear;
renodx::mods::swapchain::use_resize_buffer = true;
}
renodx::utils::device_proxy::SetTargetFormat(renodx::mods::swapchain::target_format);
renodx::utils::device_proxy::SetTargetColorSpace(renodx::mods::swapchain::target_color_space);
shader_injection.swap_chain_encoding_color_space = is_hdr10 ? 1.f : 0.f;
}
// Helper to update resolution-based uniform variables in ReShade effects
void UpdateReshadeResolutionUniforms(reshade::api::effect_runtime* runtime, uint32_t width, uint32_t height) {
float fwidth = static_cast<float>(width);
float fheight = static_cast<float>(height);
// Enumerate all uniform variables and update those with resolution-related source annotations
runtime->enumerate_uniform_variables(nullptr, [fwidth, fheight](reshade::api::effect_runtime* rt, reshade::api::effect_uniform_variable variable) {
char source[64] = {};
if (rt->get_annotation_string_from_uniform_variable(variable, "source", source)) {
// Update BUFFER_WIDTH uniform
if (std::strcmp(source, "bufwidth") == 0) {
rt->set_uniform_value_float(variable, fwidth);
}
// Update BUFFER_HEIGHT uniform
else if (std::strcmp(source, "bufheight") == 0) {
rt->set_uniform_value_float(variable, fheight);
}
// Update reciprocal width (1.0 / BUFFER_WIDTH)
else if (std::strcmp(source, "rcpwidth") == 0 || std::strcmp(source, "bufwidth_rcp") == 0) {
rt->set_uniform_value_float(variable, 1.0f / fwidth);
}
// Update reciprocal height (1.0 / BUFFER_HEIGHT)
else if (std::strcmp(source, "rcpheight") == 0 || std::strcmp(source, "bufheight_rcp") == 0) {
rt->set_uniform_value_float(variable, 1.0f / fheight);
}
// Update BUFFER_RCP_WIDTH (alternative naming convention)
else if (std::strcmp(source, "buffer_rcp_width") == 0) {
rt->set_uniform_value_float(variable, 1.0f / fwidth);
}
// Update BUFFER_RCP_HEIGHT (alternative naming convention)
else if (std::strcmp(source, "buffer_rcp_height") == 0) {
rt->set_uniform_value_float(variable, 1.0f / fheight);
}
// Update pixel size (float2 with 1/width, 1/height)
else if (std::strcmp(source, "pixelsize") == 0) {
float pixel_size[2] = { 1.0f / fwidth, 1.0f / fheight };
rt->set_uniform_value_float(variable, pixel_size, 2);
}
// Update screen size (float2 with width, height)
else if (std::strcmp(source, "screensize") == 0) {
float screen_size[2] = { fwidth, fheight };
rt->set_uniform_value_float(variable, screen_size, 2);
}
}
});
}
// Track the last known RTV resolution to detect resolution changes
static uint32_t last_rtv_width = 0;
static uint32_t last_rtv_height = 0;
// Flag to track if we're currently executing our bypass render
// This prevents ReShade from rendering during normal present while allowing our bypass to work
static bool bypass_render_active = false;
// Deferred Tech Test preset application (avoids crash from UpdateSetting inside on_change_value)
static int pending_tech_test_preset = -1; // -1 = none, 0 = restore defaults, 1 = apply tech test
static float prev_tech_test_look = -1.f; // impossible initial value forces first-frame detection
// Callback to disable effects during normal present when bypass is enabled
// This prevents double-rendering (once via bypass, once via normal present)
void OnReshadeBeginEffects(reshade::api::effect_runtime* runtime,
reshade::api::command_list* cmd_list,
reshade::api::resource_view rtv,
reshade::api::resource_view rtv_srgb) {
// Only intercept if bypass is enabled AND we're not currently in bypass render
// When bypass is disabled (current_render_reshade_before_ui == 0), let ReShade render normally
if (current_render_reshade_before_ui != 0.f && !bypass_render_active) {
runtime->set_effects_state(false);
}
}
// Callback to re-enable effects after present (keeps effects available for bypass)
void OnReshadeFinishEffects(reshade::api::effect_runtime* runtime,
reshade::api::command_list* cmd_list,
reshade::api::resource_view rtv,
reshade::api::resource_view rtv_srgb) {
// Only re-enable if bypass is enabled AND we disabled them
if (current_render_reshade_before_ui != 0.f && !bypass_render_active) {
runtime->set_effects_state(true);
}
}
bool ExecuteReshadeEffects(reshade::api::command_list* cmd_list) {
if (current_render_reshade_before_ui == 0.f) return true;
if (!UsingSwapchainUtil()) return true;
auto* cmd_list_data = renodx::utils::data::Get<renodx::utils::swapchain::CommandListData>(cmd_list);
if (cmd_list_data == nullptr) return true;
if (cmd_list_data->current_render_targets.empty()) return true;
// Get the ORIGINAL RTV from deferred lighting - do NOT use the clone here
// The clone is at swapchain resolution (e.g., 3840x2160) but we want to render
// ReShade effects at the pre-upscale resolution
auto rtv0 = cmd_list_data->current_render_targets[0];
if (rtv0.handle == 0) return true;
auto* device = cmd_list->get_device();
auto* data = renodx::utils::data::Get<renodx::utils::swapchain::DeviceData>(device);
if (data == nullptr) return true;
// Get the render target resolution
auto resource = device->get_resource_from_view(rtv0);
auto resource_desc = device->get_resource_desc(resource);
uint32_t rtv_width = resource_desc.texture.width;
uint32_t rtv_height = resource_desc.texture.height;
const std::shared_lock lock(data->mutex);
for (auto* runtime : data->effect_runtimes) {
if (rtv_width != last_rtv_width || rtv_height != last_rtv_height) {
#ifdef DEBUG_LEVEL_0
uint32_t swapchain_width = 0, swapchain_height = 0;
runtime->get_screenshot_width_and_height(&swapchain_width, &swapchain_height);
std::stringstream ss;
ss << "[Endfield] ExecuteReshadeEffects: Rendering at RTV=" << rtv_width << "x" << rtv_height
<< " (Swapchain=" << swapchain_width << "x" << swapchain_height << ")";
reshade::log::message(reshade::log::level::info, ss.str().c_str());
#endif
last_rtv_width = rtv_width;
last_rtv_height = rtv_height;
}
UpdateReshadeResolutionUniforms(runtime, rtv_width, rtv_height);
bypass_render_active = true;
runtime->set_effects_state(true);
runtime->render_effects(cmd_list, rtv0, rtv0);
bypass_render_active = false;
}
return true;
}
// Hotkey state tracking
bool ui_toggle_key_was_pressed = false;
int ui_toggle_hotkey = 0;
bool hotkey_input_active = false;
// Heuristic tracking for UID UI
bool is_ping_input_candidate = false;
bool is_ping_drawn = false;
bool is_uid_input_candidate = false;
uint32_t draw_call_vertex_count = 0; // Track vertex count from draw calls (not draw_indexed)
struct __declspec(uuid("019bf1c8-074a-7e13-b353-54ce3ceec3de")) VfxCommandListData {
reshade::api::resource_view pixel_srv_t0 = {0u};
};
struct VfxBoostMatch {
uint32_t shader_crc;
uint32_t texture_crc;
};
constexpr VfxBoostMatch vfx_boost_matches[] = {
{0x97BF4335u, 0x512923BCu},
{0x4D4DDEBEu, 0xFA6BD53Au},
{0x50898C70u, 0x1A45F4EBu},
{0x1BF3323Du, 0xF38B0BAAu},
};
std::shared_mutex vfx_handle_mutex;
std::unordered_map<uint64_t, uint32_t> vfx_handle_shaders;
void OnInitVfxResource(
reshade::api::device* /*device*/,
const reshade::api::resource_desc& desc,
const reshade::api::subresource_data* initial_data,
reshade::api::resource_usage /*initial_state*/,
reshade::api::resource resource) {
if (resource.handle == 0u
|| initial_data == nullptr
|| initial_data->data == nullptr
|| desc.type != reshade::api::resource_type::texture_2d
|| desc.texture.format != reshade::api::format::bc7_unorm_srgb
|| desc.texture.width != 256u
|| desc.texture.height != 256u) {
return;
}
const auto source_size = initial_data->slice_pitch != 0u
? initial_data->slice_pitch
: reshade::api::format_slice_pitch(
desc.texture.format,
initial_data->row_pitch != 0u
? initial_data->row_pitch
: reshade::api::format_row_pitch(desc.texture.format, desc.texture.width),
desc.texture.height);
if (source_size != 65536u) return;
const auto texture_crc = renodx::utils::hash::ComputeCRC32(
static_cast<const uint8_t*>(initial_data->data), source_size);
const auto match = std::ranges::find(vfx_boost_matches, texture_crc, &VfxBoostMatch::texture_crc);
if (match == std::end(vfx_boost_matches)) return;
const std::lock_guard lock(vfx_handle_mutex);
vfx_handle_shaders[resource.handle] = match->shader_crc;
}
void OnDestroyVfxResource(reshade::api::device* /*device*/, reshade::api::resource resource) {
const std::lock_guard lock(vfx_handle_mutex);
vfx_handle_shaders.erase(resource.handle);
}
void OnInitVfxResourceView(
reshade::api::device* /*device*/,
reshade::api::resource resource,
reshade::api::resource_usage /*usage*/,
const reshade::api::resource_view_desc& /*desc*/,
reshade::api::resource_view view) {
const std::lock_guard lock(vfx_handle_mutex);
const auto match = vfx_handle_shaders.find(resource.handle);
if (match != vfx_handle_shaders.end()) {
vfx_handle_shaders[view.handle] = match->second;
}
}
void OnDestroyVfxResourceView(reshade::api::device* /*device*/, reshade::api::resource_view view) {
const std::lock_guard lock(vfx_handle_mutex);
vfx_handle_shaders.erase(view.handle);
}
void OnInitVfxCommandList(reshade::api::command_list* cmd_list) {
renodx::utils::data::Create<VfxCommandListData>(cmd_list);
}
void OnDestroyVfxCommandList(reshade::api::command_list* cmd_list) {
renodx::utils::data::Delete<VfxCommandListData>(cmd_list);
}
void OnResetVfxCommandList(reshade::api::command_list* cmd_list) {
auto* data = renodx::utils::data::Get<VfxCommandListData>(cmd_list);
if (data != nullptr) {
data->pixel_srv_t0 = {0u};
}
}
void OnPushVfxDescriptors(
reshade::api::command_list* cmd_list,
reshade::api::shader_stage stages,
reshade::api::pipeline_layout /*layout*/,
uint32_t layout_param,
const reshade::api::descriptor_table_update& update) {
if (layout_param != 1u
|| update.type != reshade::api::descriptor_type::shader_resource_view
|| update.binding != 0u
|| update.count == 0u
|| !renodx::utils::bitwise::HasFlag(stages, reshade::api::shader_stage::pixel)) {
return;
}
auto* data = renodx::utils::data::Get<VfxCommandListData>(cmd_list);
if (data == nullptr) return;
data->pixel_srv_t0 = static_cast<const reshade::api::resource_view*>(update.descriptors)[0];
}
bool IsVisible(float value) {
return value >= 0.5f;
}
reshade::api::rect IntersectRects(const reshade::api::rect& lhs, const reshade::api::rect& rhs) {
return {
.left = std::max(lhs.left, rhs.left),
.top = std::max(lhs.top, rhs.top),
.right = std::min(lhs.right, rhs.right),
.bottom = std::min(lhs.bottom, rhs.bottom),
};
}
bool DrawTextRegion(
reshade::api::command_list* cmd_list,
uint32_t index_count,
uint32_t instance_count,
uint32_t first_index,
int32_t vertex_offset,
uint32_t first_instance,
bool keep_latency_text) {
auto* current_state = renodx::utils::state::GetCurrentState(cmd_list);
if (current_state == nullptr || current_state->viewports.empty()) return false;
const auto previous_state = *current_state;
const auto& viewport = current_state->viewports[0];
const int32_t left = static_cast<int32_t>(viewport.x);
const int32_t top = static_cast<int32_t>(viewport.y);
const int32_t right = static_cast<int32_t>(viewport.x + viewport.width);
const int32_t bottom = static_cast<int32_t>(viewport.y + viewport.height);
if (right <= left || bottom <= top) return false;
constexpr float kTextSplitFromHeight = 192.f / 2160.f;
const int32_t split_x = left + static_cast<int32_t>((bottom - top) * kTextSplitFromHeight + 0.5f);
reshade::api::rect clip_rect = keep_latency_text
? reshade::api::rect{.left = left, .top = top, .right = split_x, .bottom = bottom}
: reshade::api::rect{.left = split_x, .top = top, .right = right, .bottom = bottom};
if (!current_state->scissor_rects.empty()) {
clip_rect = IntersectRects(clip_rect, current_state->scissor_rects[0]);
}
if (clip_rect.right <= clip_rect.left || clip_rect.bottom <= clip_rect.top) return true;
cmd_list->bind_scissor_rects(0, 1, &clip_rect);
cmd_list->draw_indexed(index_count, instance_count, first_index, vertex_offset, first_instance);
previous_state.Apply(cmd_list);
return true;
}
// on_draw callback for ping/latency bar shader (0xF1B0E28A)
bool OnPingDraw(reshade::api::command_list* cmd_list) {
if (is_ping_input_candidate) {
is_ping_drawn = true;
} else {
is_ping_drawn = false;
}
return true;
}
bool OnUIDDraw(reshade::api::command_list* cmd_list) {
if (is_uid_input_candidate) {
if (!IsVisible(shader_injection.status_text_opacity) &&
!IsVisible(shader_injection.latency_text_opacity)) {
return false;
}
}
return true;
}
bool OnUiVisibilityDraw(reshade::api::command_list* cmd_list) {
return shader_injection.ui_visibility >= 0.5f;
}
bool OnUidOrUiVisibilityDraw(reshade::api::command_list* cmd_list) {
if (shader_injection.ui_visibility < 0.5f) return false;
return OnUIDDraw(cmd_list);
}
bool KeepOriginalShader(reshade::api::command_list* cmd_list) {
return false;
}
void RestoreVFXBoostShader(
reshade::api::command_list* cmd_list,
renodx::utils::shader::CommandListData* shader_state) {
if (shader_state == nullptr) return;
auto* pixel_state = renodx::utils::shader::GetCurrentPixelState(shader_state);
if (pixel_state->pipeline.handle == 0u) return;
cmd_list->bind_pipeline(pixel_state->applied_stage, pixel_state->pipeline);
}
bool ReplaceVFXBoostShader(reshade::api::command_list* cmd_list) {
auto* shader_state = renodx::utils::shader::GetCurrentState(cmd_list);
if (shader_state == nullptr) return false;
if (shader_injection.perchannelblowout < 0.5f) {
RestoreVFXBoostShader(cmd_list, shader_state);
return false;
}
auto* data = renodx::utils::data::Get<VfxCommandListData>(cmd_list);
if (data == nullptr || data->pixel_srv_t0.handle == 0u) {
RestoreVFXBoostShader(cmd_list, shader_state);
return false;
}
const auto shader_crc = renodx::utils::shader::GetCurrentPixelShaderHash(shader_state);
const std::shared_lock lock(vfx_handle_mutex);
const auto match = vfx_handle_shaders.find(data->pixel_srv_t0.handle);
const bool should_replace = match != vfx_handle_shaders.end() && match->second == shader_crc;
if (!should_replace) {
RestoreVFXBoostShader(cmd_list, shader_state);
}
return should_replace;
}
bool ReplaceImprovedGTAOShader(reshade::api::command_list* cmd_list) {
return shader_injection.improved_gtao >= 0.5f
|| shader_injection.disable_game_ao >= 0.5f;
}
bool ReplaceDisableGTAOShader(reshade::api::command_list* cmd_list) {
return shader_injection.disable_game_ao >= 0.5f;
}
void RegisterUiVisibilityBypassShader(uint32_t crc) {
auto it = custom_shaders.find(crc);
if (it == custom_shaders.end()) {
renodx::mods::shader::CustomShader cs{};
cs.crc32 = crc;
cs.on_draw = OnUiVisibilityDraw;
cs.on_replace = KeepOriginalShader;
custom_shaders.emplace(crc, std::move(cs));
return;
}
it->second.on_draw = OnUiVisibilityDraw;
it->second.on_replace = KeepOriginalShader;
}
void RegisterUidBypassShader(uint32_t crc) {
auto it = custom_shaders.find(crc);
if (it == custom_shaders.end()) {
renodx::mods::shader::CustomShader cs{};
cs.crc32 = crc;
cs.on_draw = OnUidOrUiVisibilityDraw;
cs.on_replace = KeepOriginalShader;
custom_shaders.emplace(crc, std::move(cs));
return;
}
it->second.on_draw = OnUidOrUiVisibilityDraw;
it->second.on_replace = KeepOriginalShader;
}
// Helper function to get key name from virtual key code
std::string GetKeyName(int keycode) {
if (keycode == 0 || keycode >= 256) return "";
static const char* keyboard_keys[256] = {
"", "Left Mouse", "Right Mouse", "Cancel", "Middle Mouse", "X1 Mouse", "X2 Mouse", "", "Backspace", "Tab", "", "", "Clear", "Enter", "", "",
"Shift", "Control", "Alt", "Pause", "Caps Lock", "", "", "", "", "", "", "Escape", "", "", "", "",
"Space", "Page Up", "Page Down", "End", "Home", "Left Arrow", "Up Arrow", "Right Arrow", "Down Arrow", "Select", "", "", "Print Screen", "Insert", "Delete", "Help",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "", "", "", "", "", "",
"", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Left Windows", "Right Windows", "Apps", "", "Sleep",
"Numpad 0", "Numpad 1", "Numpad 2", "Numpad 3", "Numpad 4", "Numpad 5", "Numpad 6", "Numpad 7", "Numpad 8", "Numpad 9", "Numpad *", "Numpad +", "", "Numpad -", "Numpad Decimal", "Numpad /",
"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16",
"F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24", "", "", "", "", "", "", "", "",
"Num Lock", "Scroll Lock", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"Left Shift", "Right Shift", "Left Control", "Right Control", "Left Menu", "Right Menu", "Browser Back", "Browser Forward", "Browser Refresh", "Browser Stop", "Browser Search", "Browser Favorites", "Browser Home", "Volume Mute", "Volume Down", "Volume Up",
"Next Track", "Previous Track", "Media Stop", "Media Play/Pause", "Mail", "Media Select", "Launch App 1", "Launch App 2", "", "", "OEM ;", "OEM +", "OEM ,", "OEM -", "OEM .", "OEM /",
"OEM ~", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "OEM [", "OEM \\", "OEM ]", "OEM '", "OEM 8",
"", "", "OEM <", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "Attn", "CrSel", "ExSel", "Erase EOF", "Play", "Zoom", "", "PA1", "OEM Clear", ""
};
return keyboard_keys[keycode];
}
int GetLastKeyPressedImGui() {
struct KeyMapping {
ImGuiKey imgui_key;
int vk_code;
};
static const KeyMapping kKeyMappings[] = {
// Function keys
{ImGuiKey_F1, VK_F1}, {ImGuiKey_F2, VK_F2}, {ImGuiKey_F3, VK_F3}, {ImGuiKey_F4, VK_F4},
{ImGuiKey_F5, VK_F5}, {ImGuiKey_F6, VK_F6}, {ImGuiKey_F7, VK_F7}, {ImGuiKey_F8, VK_F8},
{ImGuiKey_F9, VK_F9}, {ImGuiKey_F10, VK_F10}, {ImGuiKey_F11, VK_F11}, {ImGuiKey_F12, VK_F12},
// Navigation keys
{ImGuiKey_Insert, VK_INSERT}, {ImGuiKey_Delete, VK_DELETE}, {ImGuiKey_Home, VK_HOME}, {ImGuiKey_End, VK_END},
{ImGuiKey_PageUp, VK_PRIOR}, {ImGuiKey_PageDown, VK_NEXT},
// Arrow keys
{ImGuiKey_LeftArrow, VK_LEFT}, {ImGuiKey_RightArrow, VK_RIGHT}, {ImGuiKey_UpArrow, VK_UP}, {ImGuiKey_DownArrow, VK_DOWN},
// Special keys
{ImGuiKey_Backspace, VK_BACK}, {ImGuiKey_Space, VK_SPACE}, {ImGuiKey_Enter, VK_RETURN},
{ImGuiKey_Escape, VK_ESCAPE}, {ImGuiKey_Tab, VK_TAB},
{ImGuiKey_Pause, VK_PAUSE}, {ImGuiKey_ScrollLock, VK_SCROLL}, {ImGuiKey_PrintScreen, VK_SNAPSHOT},
// Numpad
{ImGuiKey_Keypad0, VK_NUMPAD0}, {ImGuiKey_Keypad1, VK_NUMPAD1}, {ImGuiKey_Keypad2, VK_NUMPAD2},
{ImGuiKey_Keypad3, VK_NUMPAD3}, {ImGuiKey_Keypad4, VK_NUMPAD4}, {ImGuiKey_Keypad5, VK_NUMPAD5},
{ImGuiKey_Keypad6, VK_NUMPAD6}, {ImGuiKey_Keypad7, VK_NUMPAD7}, {ImGuiKey_Keypad8, VK_NUMPAD8},
{ImGuiKey_Keypad9, VK_NUMPAD9}, {ImGuiKey_KeypadDecimal, VK_DECIMAL},
{ImGuiKey_KeypadDivide, VK_DIVIDE}, {ImGuiKey_KeypadMultiply, VK_MULTIPLY},
{ImGuiKey_KeypadSubtract, VK_SUBTRACT}, {ImGuiKey_KeypadAdd, VK_ADD}, {ImGuiKey_KeypadEnter, VK_RETURN},
// Letters
{ImGuiKey_A, 'A'}, {ImGuiKey_B, 'B'}, {ImGuiKey_C, 'C'}, {ImGuiKey_D, 'D'}, {ImGuiKey_E, 'E'},
{ImGuiKey_F, 'F'}, {ImGuiKey_G, 'G'}, {ImGuiKey_H, 'H'}, {ImGuiKey_I, 'I'}, {ImGuiKey_J, 'J'},
{ImGuiKey_K, 'K'}, {ImGuiKey_L, 'L'}, {ImGuiKey_M, 'M'}, {ImGuiKey_N, 'N'}, {ImGuiKey_O, 'O'},
{ImGuiKey_P, 'P'}, {ImGuiKey_Q, 'Q'}, {ImGuiKey_R, 'R'}, {ImGuiKey_S, 'S'}, {ImGuiKey_T, 'T'},
{ImGuiKey_U, 'U'}, {ImGuiKey_V, 'V'}, {ImGuiKey_W, 'W'}, {ImGuiKey_X, 'X'}, {ImGuiKey_Y, 'Y'}, {ImGuiKey_Z, 'Z'},
// Numbers
{ImGuiKey_0, '0'}, {ImGuiKey_1, '1'}, {ImGuiKey_2, '2'}, {ImGuiKey_3, '3'}, {ImGuiKey_4, '4'},
{ImGuiKey_5, '5'}, {ImGuiKey_6, '6'}, {ImGuiKey_7, '7'}, {ImGuiKey_8, '8'}, {ImGuiKey_9, '9'},
// Punctuation
{ImGuiKey_GraveAccent, VK_OEM_3}, {ImGuiKey_Minus, VK_OEM_MINUS}, {ImGuiKey_Equal, VK_OEM_PLUS},
{ImGuiKey_LeftBracket, VK_OEM_4}, {ImGuiKey_RightBracket, VK_OEM_6}, {ImGuiKey_Backslash, VK_OEM_5},
{ImGuiKey_Semicolon, VK_OEM_1}, {ImGuiKey_Apostrophe, VK_OEM_7},
{ImGuiKey_Comma, VK_OEM_COMMA}, {ImGuiKey_Period, VK_OEM_PERIOD}, {ImGuiKey_Slash, VK_OEM_2},
};
for (const auto& mapping : kKeyMappings) {
if (ImGui::IsKeyPressed(mapping.imgui_key, false)) {
return mapping.vk_code;
}
}
return 0;
}
renodx::utils::settings::Settings settings = {
new renodx::utils::settings::Setting{
.key = "SettingsMode",
.binding = ¤t_settings_mode,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 0.f,
.can_reset = false,
.label = "Settings Mode",
.labels = {"Simple", "Intermediate", "Advanced"},
.is_global = true,
},
new renodx::utils::settings::Setting{
.key = "ToneMapType",
.binding = &shader_injection.tone_map_type,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 1.f,
.can_reset = false,
.label = "Tone Mapper",
.section = "Tone Mapping",
.tooltip = "Sets the tone mapper type. True Vanilla requires going back to the LOGIN MENU for all the changes to have an effect.",
.labels = {"Vanilla", "RenoDRT"},
.is_visible = []() { return current_settings_mode >= 1; },
},
new renodx::utils::settings::Setting{
.key = "ToneMapMethod",
.binding = &shader_injection.reno_drt_tone_map_method,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 1.f,
.label = "Tone Map Method",
.section = "Tone Mapping",
.tooltip = "Selects the RenoDRT curve",
.labels = {"Reinhard", "Hermite Spline"},
.parse = [](float value) { return value + 1.f; },
.is_visible = []() { return false;},
},
new renodx::utils::settings::Setting{
.key = "ToneMapPeakNits",
.binding = &shader_injection.peak_white_nits,
.default_value = 1000.f,
.can_reset = true,
.label = "Peak Brightness",
.section = "Tone Mapping",
.tooltip = "Sets the value of peak white in nits",
.min = 48.f,
.max = 4000.f,
},
new renodx::utils::settings::Setting{
.key = "ToneMapGameNits",
.binding = &shader_injection.diffuse_white_nits,
.default_value = 203.f,
.label = "Game Brightness",
.section = "Tone Mapping",
.tooltip = "Sets the value of 100% white in nits",
.min = 48.f,
.max = 500.f,
},
new renodx::utils::settings::Setting{
.key = "ToneMapUINits",
.binding = &shader_injection.graphics_white_nits,
.default_value = 203.f,
.label = "UI Brightness",
.section = "Tone Mapping",
.tooltip = "Sets the brightness of UI and HUD elements in nits",
.min = 48.f,
.max = 500.f,
},
new renodx::utils::settings::Setting{
.key = "GammaCorrection",
.binding = &shader_injection.gamma_correction,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 1.f,
.label = "Scene Gamma Correction",
.section = "Tone Mapping",
.tooltip = "Emulates a display EOTF.",
.labels = {"Off", "2.2", "BT.1886"},
.is_visible = []() { return current_settings_mode >= 1; },
},
new renodx::utils::settings::Setting{
.key = "SwapChainGammaCorrection",
.binding = &shader_injection.swap_chain_gamma_correction,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 1.f,
.label = "UI Gamma Correction",
.section = "Tone Mapping",
.labels = {"None", "2.2", "2.4"},
.is_enabled = []() { return shader_injection.tone_map_type >= 1; },
.is_visible = []() { return current_settings_mode >= 2; },
},
new renodx::utils::settings::Setting{
.key = "ToneMapScaling",
.binding = &shader_injection.tone_map_per_channel,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 0.f,
.label = "Scaling",
.section = "Tone Mapping",
.tooltip = "Luminance scales colors consistently while per-channel saturates and blows out sooner",
.labels = {"Luminance", "Per Channel"},
.is_enabled = []() { return shader_injection.tone_map_type >= 1; },
.is_visible = []() { return false; },
},
new renodx::utils::settings::Setting{
.key = "ToneMapWorkingColorSpace",
.binding = &shader_injection.tone_map_working_color_space,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 0.f,
.label = "Working Color Space",
.section = "Tone Mapping",
.labels = {"BT709", "BT2020", "AP1"},
.is_enabled = []() { return shader_injection.tone_map_type >= 1; },
.is_visible = []() { return false; },
},
new renodx::utils::settings::Setting{
.key = "ToneMapHueProcessor",
.binding = &shader_injection.tone_map_hue_processor,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 0.f,
.label = "Hue Processor",
.section = "Tone Mapping",
.tooltip = "Selects hue processor",
.labels = {"OKLab", "ICtCp", "darkTable UCS"},
.is_enabled = []() { return shader_injection.tone_map_type >= 1; },
.is_visible = []() { return false; },
},
new renodx::utils::settings::Setting{
.key = "ToneMapHueCorrection",
.binding = &shader_injection.tone_map_hue_correction,
.default_value = 100.f,
.label = "Hue Correction",
.section = "Tone Mapping",
.tooltip = "Hue retention strength.",
.min = 0.f,
.max = 100.f,
.parse = [](float value) { return value * 0.01f; },
.is_visible = []() { return false;},
},
new renodx::utils::settings::Setting{
.key = "ToneMapHueShift",
.binding = &shader_injection.tone_map_hue_shift,
.default_value = 85.f,
.label = "Hue Shift",
.section = "Tone Mapping",
.tooltip = "Hue-shift emulation strength.",
.min = 0.f,
.max = 100.f,
.parse = [](float value) { return value * 0.01f; },
.is_visible = []() { return current_settings_mode >= 1; },
},
new renodx::utils::settings::Setting{
.key = "ToneMapPerChannelBlowout",
.binding = &shader_injection.tone_map_blowout,
.default_value = 75.f,
.label = "Per Channel Blowout",
.section = "Tone Mapping",
.tooltip = "Per Channel Blowout strength.",
.min = 0.f,
.max = 100.f,
.parse = [](float value) { return value * 0.01f; },
.is_visible = []() { return current_settings_mode >= 1; },
},
new renodx::utils::settings::Setting{
.key = "ToneMapClampColorSpace",
.binding = &shader_injection.tone_map_clamp_color_space,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 0.f,
.label = "Clamp Color Space",
.section = "Tone Mapping",
.tooltip = "Hue-shift emulation strength.",
.labels = {"None", "BT709", "BT2020", "AP1"},
.is_enabled = []() { return shader_injection.tone_map_type >= 1; },
.parse = [](float value) { return value - 1.f; },
.is_visible = []() { return false; },
},
new renodx::utils::settings::Setting{
.key = "ToneMapClampPeak",
.binding = &shader_injection.tone_map_clamp_peak,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 0.f,
.label = "Clamp Peak",
.section = "Tone Mapping",
.tooltip = "Hue-shift emulation strength.",
.labels = {"None", "BT709", "BT2020", "AP1"},
.is_enabled = []() { return shader_injection.tone_map_type >= 1; },
.parse = [](float value) { return value - 1.f; },
.is_visible = []() { return false; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeExposure",
.binding = &shader_injection.tone_map_exposure,
.default_value = 1.f,
.label = "Exposure",
.section = "Color Grading",
.max = 2.f,
.format = "%.2f",
.is_visible = []() { return current_settings_mode >= 1; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeHighlights",
.binding = &shader_injection.tone_map_highlights,
.default_value = 50.f,
.label = "Highlights",
.section = "Color Grading",
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
.is_visible = []() { return current_settings_mode >= 1; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeShadows",
.binding = &shader_injection.tone_map_shadows,
.default_value = 50.f,
.label = "Shadows",
.section = "Color Grading",
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
.is_visible = []() { return current_settings_mode >= 1; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeContrast",
.binding = &shader_injection.tone_map_contrast,
.default_value = 50.f,
.label = "Contrast",
.section = "Color Grading",
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeSaturation",
.binding = &shader_injection.tone_map_saturation,
.default_value = 50.f,
.label = "Saturation",
.section = "Color Grading",
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeHighlightSaturation",
.binding = &shader_injection.tone_map_highlight_saturation,
.default_value = 50.f,
.label = "Highlight Saturation",
.section = "Color Grading",
.tooltip = "Adds or removes highlight color.",
.max = 100.f,
.is_enabled = []() { return shader_injection.tone_map_type >= 1; },
.parse = [](float value) { return value * 0.02f; },
.is_visible = []() { return current_settings_mode >= 1; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeBlowout",
.binding = &shader_injection.tone_map_dechroma,
.default_value = 0.f,
.label = "Blowout",
.section = "Color Grading",
.tooltip = "Controls highlight desaturation due to overexposure.",
.max = 100.f,
.parse = [](float value) { return value * 0.01f; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeFlare",
.binding = &shader_injection.tone_map_flare,
.default_value = 0.f,
.label = "Flare",
.section = "Color Grading",
.tooltip = "Flare/Glare Compensation",
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeScene",
.binding = &shader_injection.color_grade_strength,
.default_value = 100.f,
.label = "Scene Grading",
.section = "Color Grading",
.tooltip = "Scene grading as applied by the game",
.max = 100.f,
.is_enabled = []() { return shader_injection.tone_map_type > 0; },
.parse = [](float value) { return value * 0.01f; },
},
new renodx::utils::settings::Setting{
.key = "UIOpacityStatusText",
.binding = &shader_injection.status_text_opacity,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 0.f,
.label = "UID Text",
.section = "User Interface & Video",
.tooltip = "Toggle UID text visibility",
.labels = {"Hidden", "Visible"},
},
new renodx::utils::settings::Setting{
.key = "UIOpacityLatencyText",
.binding = &shader_injection.latency_text_opacity,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 0.f,
.label = "Latency Text",
.section = "User Interface & Video",
.tooltip = "Toggle latency text visibility",
.labels = {"Hidden", "Visible"},
},
new renodx::utils::settings::Setting{
.key = "UIOpacityPingText",
.binding = &shader_injection.ping_text_opacity,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 0.f,
.label = "Latency Bar",
.section = "User Interface & Video",
.tooltip = "Toggle latency bar visibility",
.labels = {"Hidden", "Visible"},
},
new renodx::utils::settings::Setting{
.key = "UIVisibility",
.binding = &shader_injection.ui_visibility,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 1.f,
.label = "UI Visibility",
.section = "User Interface & Video",
.tooltip = "Toggle UI visibility for screenshots (use hotkey for quick toggle)",
.labels = {"Hidden", "Visible"},
},
new renodx::utils::settings::Setting{
.key = "UIVisibilityHotkey",
.value_type = renodx::utils::settings::SettingValueType::CUSTOM,
.default_value = 0.f,
.label = "UI Toggle Hotkey",
.section = "User Interface & Video",
.tooltip = "Click in the field and press any key to set the hotkey, or press Backspace/Delete to clear",
.on_draw = []() {
static bool key_was_pressed = false;
bool changed = false;
// Get current key name for display
std::string key_name = ui_toggle_hotkey != 0 ? GetKeyName(ui_toggle_hotkey) : "";
char buf[64] = {0};
if (!key_name.empty()) {
size_t copy_len = (key_name.size() < sizeof(buf) - 1) ? key_name.size() : sizeof(buf) - 1;
memcpy(buf, key_name.c_str(), copy_len);
}
// Create the input text widget
ImGui::InputTextWithHint(
"UI Toggle Hotkey",
"Click to set keyboard shortcut",
buf,
sizeof(buf),
ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_NoUndoRedo | ImGuiInputTextFlags_NoHorizontalScroll
);
// Check if widget is active and capture key presses
if (ImGui::IsItemActive()) {
hotkey_input_active = true;
int key_pressed = GetLastKeyPressedImGui();
if (key_pressed != 0 && !key_was_pressed) {
if (key_pressed == VK_BACK || key_pressed == VK_DELETE) {
ui_toggle_hotkey = 0;
changed = true;
} else if (key_pressed != VK_ESCAPE) {
ui_toggle_hotkey = key_pressed;
changed = true;
}
if (changed) {
reshade::set_config_value(nullptr, renodx::utils::settings::global_name.c_str(), "UIVisibilityHotkey", ui_toggle_hotkey);
}
key_was_pressed = true;
} else if (key_pressed == 0) {
key_was_pressed = false;
}
} else {
hotkey_input_active = false;
key_was_pressed = false;
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip)) {
ImGui::SetTooltip("Click and press any key to set hotkey.\nPress Backspace or Delete to clear.");
}
return changed;
},
.is_global = true,
},
new renodx::utils::settings::Setting{
.key = "VideoAutoHDR",
.binding = &shader_injection.tone_map_hdr_video,
.value_type = renodx::utils::settings::SettingValueType::BOOLEAN,
.default_value = 1.f,
.label = "Video AutoHDR",
.section = "User Interface & Video",
.tooltip = "Upgrades SDR videos to HDR.",
},
new renodx::utils::settings::Setting{
.key = "ToneMapVideoNits",
.binding = &shader_injection.tone_map_video_nits,
.default_value = 500.f,
.can_reset = true,
.label = "Video Brightness",
.section = "User Interface & Video",
.tooltip = "Sets the peak brightness for video content in nits",
.min = 48.f,
.max = 1000.f,
},
new renodx::utils::settings::Setting{
.key = "fxRCASSharpening",
.binding = &shader_injection.fx_rcas_sharpening,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 0.f,
.label = "FSR RCAS Sharpening",
.section = "Effects",
.tooltip = "Enable Robust Contrast Adaptive Sharpening."
"\nProvides better image clarity.",
.labels = {"Off", "On"},
},
new renodx::utils::settings::Setting{
.key = "fxRCASAmount",
.binding = &shader_injection.fx_rcas_amount,
.default_value = 50.f,
.label = "RCAS Sharpening Amount",
.section = "Effects",
.tooltip = "Adjusts RCAS sharpening strength.",
.max = 100.f,
.is_enabled = []() { return shader_injection.fx_rcas_sharpening >= 1.f; },
.parse = [](float value) { return value * 0.01f; },
},
new renodx::utils::settings::Setting({
.key = "FxGrainStrength",
.binding = &shader_injection.custom_grain_strength,
.default_value = 0.f,
.label = "Perceptual Grain Strength",
.section = "Effects",
.parse = [](float value) { return value * 0.01f; },
}),
new renodx::utils::settings::Setting{
.key = "VignetteStrength",
.binding = &shader_injection.vignette_strength,
.default_value = 50.f,
.label = "Vignette Strength",
.section = "Effects",
.min = 0.f,
.max = 100.f,