From 69d806a83aab61e2c4587694d86bf07c735bb4fe Mon Sep 17 00:00:00 2001 From: iota97 Date: Sat, 16 May 2020 22:01:16 +0200 Subject: [PATCH 1/4] Add postprocessing CWCHEAT --- Core/CwCheat.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index bf66680122e9..3fdfeee9a642 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -421,6 +421,7 @@ enum class CheatOp { CopyBytesFrom, Vibration, VibrationFromMemory, + PostShader, Delay, Assert, @@ -475,6 +476,13 @@ struct CheatOperation { uint8_t vibrLTime; uint8_t vibrRTime; } vibrationValues; + struct { + union { + float f; + uint32_t i; + } value; + uint8_t uniform; + } PostShaderUniform; }; }; @@ -620,6 +628,13 @@ CheatOperation CWCheatEngine::InterpretNextCwCheat(const CheatCode &cheat, size_ case 0x1: // 0x1 reads value for gamepad vibration from memory addr = line1.part2; return { CheatOp::VibrationFromMemory, addr }; + case 0x2: // 0x2 sets postprocessing shader uniform + { + CheatOperation op = { CheatOp::PostShader }; + op.PostShaderUniform.uniform = line1.part1 & 0x000000FF; + op.PostShaderUniform.value.i = line1.part2; + return op; + } // Place for other PPSSPP specific cheats default: return { CheatOp::Invalid }; @@ -919,6 +934,11 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat, } break; + case CheatOp::PostShader: + if (op.PostShaderUniform.uniform >= 0 && op.PostShaderUniform.uniform < 4) + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", g_Config.sPostShaderName.c_str(), op.PostShaderUniform.uniform + 1)] = op.PostShaderUniform.value.f; + break; + case CheatOp::Delay: // TODO: Not supported. break; From c83e2fb07001ba66957d2bcf766010e27d47bdc7 Mon Sep 17 00:00:00 2001 From: iota97 Date: Sun, 17 May 2020 00:13:11 +0200 Subject: [PATCH 2/4] Memory reading CWCheat --- Core/CwCheat.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 3fdfeee9a642..2a648960fdbb 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -422,6 +422,7 @@ enum class CheatOp { Vibration, VibrationFromMemory, PostShader, + PostShaderFromMemory, Delay, Assert, @@ -482,6 +483,7 @@ struct CheatOperation { uint32_t i; } value; uint8_t uniform; + uint8_t format; } PostShaderUniform; }; }; @@ -635,6 +637,14 @@ CheatOperation CWCheatEngine::InterpretNextCwCheat(const CheatCode &cheat, size_ op.PostShaderUniform.value.i = line1.part2; return op; } + case 0x3: // 0x3 sets postprocessing shader uniform from memory + { + addr = line1.part2; + CheatOperation op = { CheatOp::PostShaderFromMemory, addr }; + op.PostShaderUniform.uniform = line1.part1 & 0x000000FF; + op.PostShaderUniform.format = (line1.part1 >> 8) & 0x000000FF; + return op; + } // Place for other PPSSPP specific cheats default: return { CheatOp::Invalid }; @@ -939,6 +949,30 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat, g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", g_Config.sPostShaderName.c_str(), op.PostShaderUniform.uniform + 1)] = op.PostShaderUniform.value.f; break; + case CheatOp::PostShaderFromMemory: + if (Memory::IsValidAddress(op.addr) && op.PostShaderUniform.uniform >= 0 && op.PostShaderUniform.uniform < 4) { + union { + float f; + uint32_t u; + } value; + value.u = Memory::Read_U32(op.addr); + switch (op.PostShaderUniform.format) { + case (0): + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", g_Config.sPostShaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x000000FF; + break; + case (1): + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", g_Config.sPostShaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x0000FFFF; + break; + case (2): + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", g_Config.sPostShaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u; + break; + case (3): + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", g_Config.sPostShaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.f; + break; + } + } + break; + case CheatOp::Delay: // TODO: Not supported. break; From 6f59f02b38acb5824da46e3b1e72bd0d22d9cc35 Mon Sep 17 00:00:00 2001 From: iota97 Date: Sun, 17 May 2020 19:06:23 +0200 Subject: [PATCH 3/4] Support chain --- Core/CwCheat.cpp | 62 ++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 2a648960fdbb..771215374096 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -16,6 +16,7 @@ #include "Core/System.h" #include "Core/HLE/sceCtrl.h" #include "Core/MIPS/JitCommon/JitCommon.h" +#include "GPU/Common/PostShader.h" #ifdef _WIN32 #include "util/text/utf8.h" @@ -480,8 +481,9 @@ struct CheatOperation { struct { union { float f; - uint32_t i; + uint32_t u; } value; + uint8_t shader; uint8_t uniform; uint8_t format; } PostShaderUniform; @@ -634,7 +636,8 @@ CheatOperation CWCheatEngine::InterpretNextCwCheat(const CheatCode &cheat, size_ { CheatOperation op = { CheatOp::PostShader }; op.PostShaderUniform.uniform = line1.part1 & 0x000000FF; - op.PostShaderUniform.value.i = line1.part2; + op.PostShaderUniform.shader = (line1.part1 >> 16) & 0x000000FF; + op.PostShaderUniform.value.u = line1.part2; return op; } case 0x3: // 0x3 sets postprocessing shader uniform from memory @@ -643,6 +646,7 @@ CheatOperation CWCheatEngine::InterpretNextCwCheat(const CheatCode &cheat, size_ CheatOperation op = { CheatOp::PostShaderFromMemory, addr }; op.PostShaderUniform.uniform = line1.part1 & 0x000000FF; op.PostShaderUniform.format = (line1.part1 >> 8) & 0x000000FF; + op.PostShaderUniform.shader = (line1.part1 >> 16) & 0x000000FF; return op; } // Place for other PPSSPP specific cheats @@ -945,30 +949,42 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat, break; case CheatOp::PostShader: - if (op.PostShaderUniform.uniform >= 0 && op.PostShaderUniform.uniform < 4) - g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", g_Config.sPostShaderName.c_str(), op.PostShaderUniform.uniform + 1)] = op.PostShaderUniform.value.f; + { + auto shaderChain = GetPostShaderChain(g_Config.sPostShaderName); + if (op.PostShaderUniform.shader < shaderChain.size()) { + std::string shaderName = shaderChain[op.PostShaderUniform.shader]->section; + if (shaderName != "Off") + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = op.PostShaderUniform.value.f; + } + } break; case CheatOp::PostShaderFromMemory: - if (Memory::IsValidAddress(op.addr) && op.PostShaderUniform.uniform >= 0 && op.PostShaderUniform.uniform < 4) { - union { - float f; - uint32_t u; - } value; - value.u = Memory::Read_U32(op.addr); - switch (op.PostShaderUniform.format) { - case (0): - g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", g_Config.sPostShaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x000000FF; - break; - case (1): - g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", g_Config.sPostShaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x0000FFFF; - break; - case (2): - g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", g_Config.sPostShaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u; - break; - case (3): - g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", g_Config.sPostShaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.f; - break; + { + auto shaderChain = GetPostShaderChain(g_Config.sPostShaderName); + if (Memory::IsValidAddress(op.addr) && op.PostShaderUniform.shader < shaderChain.size()) { + union { + float f; + uint32_t u; + } value; + value.u = Memory::Read_U32(op.addr); + std::string shaderName = shaderChain[op.PostShaderUniform.shader]->section; + if (shaderName != "Off") { + switch (op.PostShaderUniform.format) { + case (0): + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x000000FF; + break; + case (1): + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x0000FFFF; + break; + case (2): + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u; + break; + case (3): + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.f; + break; + } + } } } break; From 45bfb4f52baf0185dc9ab1704c32c2cd54c6cbb9 Mon Sep 17 00:00:00 2001 From: iota97 Date: Thu, 4 Jun 2020 19:08:10 +0200 Subject: [PATCH 4/4] Code style fix --- Core/CwCheat.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 771215374096..3b8e64309705 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -971,16 +971,16 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat, std::string shaderName = shaderChain[op.PostShaderUniform.shader]->section; if (shaderName != "Off") { switch (op.PostShaderUniform.format) { - case (0): + case 0: g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x000000FF; break; - case (1): + case 1: g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x0000FFFF; break; - case (2): + case 2: g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u; break; - case (3): + case 3: g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.f; break; }