From d46c5775c1fb6afef9c35e8eb618b49f2fe5d72c Mon Sep 17 00:00:00 2001 From: SRG27 <59260202+SRG27@users.noreply.github.com> Date: Sun, 18 Jun 2023 01:27:23 +0200 Subject: [PATCH 1/2] Add "Tiny Screen" Effect --- ChaosMod/ChaosMod.vcxproj | 1 + .../Screen/Shaders/ScreenShaderTinyScreen.cpp | 49 +++++++++++++++++++ ConfigApp/Effects.cs | 1 + 3 files changed, 51 insertions(+) create mode 100644 ChaosMod/Effects/db/Screen/Shaders/ScreenShaderTinyScreen.cpp diff --git a/ChaosMod/ChaosMod.vcxproj b/ChaosMod/ChaosMod.vcxproj index 9c1054f8f..d743a194a 100644 --- a/ChaosMod/ChaosMod.vcxproj +++ b/ChaosMod/ChaosMod.vcxproj @@ -206,6 +206,7 @@ + diff --git a/ChaosMod/Effects/db/Screen/Shaders/ScreenShaderTinyScreen.cpp b/ChaosMod/Effects/db/Screen/Shaders/ScreenShaderTinyScreen.cpp new file mode 100644 index 000000000..f7082f77a --- /dev/null +++ b/ChaosMod/Effects/db/Screen/Shaders/ScreenShaderTinyScreen.cpp @@ -0,0 +1,49 @@ +#include + +#include "Memory/Hooks/ShaderHook.h" + +static const char *ms_ShaderSrc = R"SRC( +Texture2D HDRSampler : register(t5); +SamplerState g_samLinear : register(s5) +{ + Filter = MIN_MAG_MIP_LINEAR; + AddressU = Wrap; + AddressV = Wrap; +}; + +float4 main(float4 position : SV_POSITION, float3 texcoord : TEXCOORD0, float4 color : COLOR0) : SV_Target0 +{ + float multiplier = 25; + + texcoord.x = (texcoord.x - 0.5) * multiplier + 0.5; + texcoord.y = (texcoord.y - 0.5) * multiplier + 0.5; + + if (texcoord.x > 1. || texcoord.y > 1. || texcoord.x < 0. || texcoord.y < 0.) { + return (0., 0., 0., 0.); + } + + return HDRSampler.Sample(g_samLinear, texcoord); +} +)SRC"; + +static void OnStart() +{ + Hooks::OverrideShader(OverrideShaderType::LensDistortion, ms_ShaderSrc); +} + +static void OnStop() +{ + Hooks::ResetShader(); +} + +// clang-format off +REGISTER_EFFECT(OnStart, OnStop, nullptr, EffectInfo + { + .Name = "Tiny Screen", + .Id = "screen_tinyscreen", + .IsTimed = true, + .IsShortDuration = true, + .EffectCategory = EffectCategory::Shader, + .EffectGroupType = EffectGroupType::Shader + } +); \ No newline at end of file diff --git a/ConfigApp/Effects.cs b/ConfigApp/Effects.cs index 07ab2713f..41276af02 100644 --- a/ConfigApp/Effects.cs +++ b/ConfigApp/Effects.cs @@ -400,6 +400,7 @@ public enum EffectTimedType { "misc_go_to_jail", new EffectInfo("Bad Boys", EffectCategory.Misc) }, { "misc_muffled_audio", new EffectInfo("Muffled Audio", EffectCategory.Misc, true) }, { "misc_esp", new EffectInfo("ESP", EffectCategory.Misc, true) }, + { "screen_tinyscreen", new EffectInfo("Tiny Screen", EffectCategory.Screen, true, true) }, }; } } From 5c6d8a4eaaa3f6d0e397dbcafe8640c082943bc7 Mon Sep 17 00:00:00 2001 From: SRG27 <59260202+SRG27@users.noreply.github.com> Date: Sun, 18 Jun 2023 23:55:24 +0200 Subject: [PATCH 2/2] Made the size of the tiny screen random --- .../Effects/db/Screen/Shaders/ScreenShaderTinyScreen.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ChaosMod/Effects/db/Screen/Shaders/ScreenShaderTinyScreen.cpp b/ChaosMod/Effects/db/Screen/Shaders/ScreenShaderTinyScreen.cpp index f7082f77a..ce0235451 100644 --- a/ChaosMod/Effects/db/Screen/Shaders/ScreenShaderTinyScreen.cpp +++ b/ChaosMod/Effects/db/Screen/Shaders/ScreenShaderTinyScreen.cpp @@ -2,7 +2,7 @@ #include "Memory/Hooks/ShaderHook.h" -static const char *ms_ShaderSrc = R"SRC( +static const char *ms_ShaderSrcPrefix = R"SRC( Texture2D HDRSampler : register(t5); SamplerState g_samLinear : register(s5) { @@ -13,8 +13,9 @@ SamplerState g_samLinear : register(s5) float4 main(float4 position : SV_POSITION, float3 texcoord : TEXCOORD0, float4 color : COLOR0) : SV_Target0 { - float multiplier = 25; + float multiplier =)SRC"; +static const char *ms_ShaderSrcSuffix = R"SRC(; texcoord.x = (texcoord.x - 0.5) * multiplier + 0.5; texcoord.y = (texcoord.y - 0.5) * multiplier + 0.5; @@ -28,7 +29,7 @@ float4 main(float4 position : SV_POSITION, float3 texcoord : TEXCOORD0, float4 c static void OnStart() { - Hooks::OverrideShader(OverrideShaderType::LensDistortion, ms_ShaderSrc); + Hooks::OverrideShader(OverrideShaderType::LensDistortion, ms_ShaderSrcPrefix + std::to_string(g_Random.GetRandomInt(9, 40)) + ms_ShaderSrcSuffix); } static void OnStop()