From 9690ae6b8b0ef4ebd91a5b2a9d23a8df24f95a72 Mon Sep 17 00:00:00 2001 From: nastys <@> Date: Thu, 6 Aug 2020 00:57:32 +0200 Subject: [PATCH] [Patches+TLAC] Force toon (NPR1; option in launcher + press F9 to toggle) --- source-code/data/plugins/config.ini | 8 +++-- .../source/plugins/Launcher/framework.h | 15 ++++++---- .../source/plugins/Patches/dllmain.cpp | 21 +++++++++++-- .../TLAC/Components/Input/InputEmulator.cpp | 30 +++++++++++++++++++ .../TLAC/Components/Input/InputEmulator.h | 1 + source-code/source/plugins/TLAC/TLAC.vcxproj | 2 ++ .../source/plugins/TLAC/TLAC.vcxproj.filters | 6 ++++ source-code/source/plugins/TLAC/Utils.cpp | 12 ++++++++ source-code/source/plugins/TLAC/Utils.h | 4 +++ 9 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 source-code/source/plugins/TLAC/Utils.cpp create mode 100644 source-code/source/plugins/TLAC/Utils.h diff --git a/source-code/data/plugins/config.ini b/source-code/data/plugins/config.ini index c47843b..ac90063 100644 --- a/source-code/data/plugins/config.ini +++ b/source-code/data/plugins/config.ini @@ -64,9 +64,9 @@ No_Lyrics=0 No_Error=1 #Hide "CREDIT(S)"/"FREE PLAY" Hide_Freeplay=0 -#Show "FREE PLAY" instead of "CREDIT(S)" +#Show "FREE PLAY" instead of "CREDIT(S)" and don't require credits Freeplay=1 -#Show "PD Loader " instead of "FREE PLAY" +#Show "PD Loader" instead of "FREE PLAY" PDLoaderText=1 #Freeze the timer No_Timer=1 @@ -75,7 +75,7 @@ No_Timer_Sprite=1 #Unlock PSEUDO modules (incomplete, will default to Miku) Unlock_Pseudo=0 #Enable the card menu (incomplete, it doesn't bypass the card prompt) -Card=1 +Card=0 #Allow using a real arcade slider attached to COM11 Hardware_Slider=0 #Enable custom patches @@ -93,6 +93,8 @@ FPS.Limit.Verbose=0 TAA=1 # Morphological Anti-Aliasing MLAA=1 +# Toon shader (press F9 to toggle) -- 0=default, 1=force on, 2=force off +NPR1=0 # FrameRateManager motion rate (fps) FRM.Motion.Rate=400 diff --git a/source-code/source/plugins/Launcher/framework.h b/source-code/source/plugins/Launcher/framework.h index 05bc9cb..358a6ce 100644 --- a/source-code/source/plugins/Launcher/framework.h +++ b/source-code/source/plugins/Launcher/framework.h @@ -186,21 +186,21 @@ ConfigOptionBase* optionsArray[] = { new BooleanOption(L"no_lyrics", PATCHES_SECTION, CONFIG_FILE, L"Disable Lyrics", L"Disable showing lyrics.", false, false), new BooleanOption(L"no_error", PATCHES_SECTION, CONFIG_FILE, L"Disable Error Banner", L"Disable the error banner on the attract screen.", true, false), new BooleanOption(L"hide_freeplay", PATCHES_SECTION, CONFIG_FILE, L"Hide \"FREE PLAY\"/\"CREDIT(S)\"", L"Hide the \"FREE PLAY\"/\"CREDIT(S)\" text.", false, false), - new BooleanOption(L"freeplay", PATCHES_SECTION, CONFIG_FILE, L"FREE PLAY", L"Show \"FREE PLAY\" instead of \"CREDIT(S)\".", true, false), + new BooleanOption(L"freeplay", PATCHES_SECTION, CONFIG_FILE, L"FREE PLAY", L"Show \"FREE PLAY\" instead of \"CREDIT(S)\" and don't require credits.", true, false), new BooleanOption(L"pdloadertext", PATCHES_SECTION, CONFIG_FILE, L"PD Loader FREE PLAY", L"Show \"PD Loader\" instead of \"FREE PLAY\".", true, false), new BooleanOption(L"no_timer", PATCHES_SECTION, CONFIG_FILE, L"Freeze Timer", L"Disable the timer.", true, false), new BooleanOption(L"no_timer_sprite", PATCHES_SECTION, CONFIG_FILE, L"Disable Timer Sprite", L"Disable the timer sprite.", true, false), new OptionMetaSpacer(8), new BooleanOption(L"unlock_pseudo", PATCHES_SECTION, CONFIG_FILE, L"Unlock PSEUDO modules (incomplete)", L"Lets you play any PV with any performer.\n(incomplete, recommended modules will default to Miku)", false, false), - new BooleanOption(L"card", PATCHES_SECTION, CONFIG_FILE, L"Unlock card menu (incomplete)", L"Enables the card menu.\n(incomplete, it doesn't bypass the card prompt)", true, false), - new OptionMetaSpacer(8), - - new BooleanOption(L"hardware_slider", PATCHES_SECTION, CONFIG_FILE, L"Use Hardware Slider", L"Enable this if using a real arcade slider.\n(set the slider to port COM11)", false, false), + new BooleanOption(L"card", PATCHES_SECTION, CONFIG_FILE, L"Unlock card menu (incomplete)", L"Enables the card menu.\n(incomplete, it doesn't bypass the card prompt)", false, false), new OptionMetaSpacer(8), new BooleanOption(L"TAA", GRAPHICS_SECTION, CONFIG_FILE, L"TAA", L"Temporal Anti-Aliasing", true, false), new BooleanOption(L"MLAA", GRAPHICS_SECTION, CONFIG_FILE, L"MLAA", L"Morphological Anti-Aliasing", true, false), + new DropdownOption(L"NPR1", GRAPHICS_SECTION, CONFIG_FILE, L"Toon (F9):", L"NPR1 shader\n\nPress F9 to toggle.", 0, std::vector({ L"Default", L"Force on", L"Force off" })), + new OptionMetaSpacer(8), + new BooleanOption(L"FPS.Limit.LightMode", GRAPHICS_SECTION, CONFIG_FILE, L"Use Lightweight Limiter", L"Makes the FPS limiter use less CPU.\nMay have less consistent performance.", true, false), new NumericOption(L"FPS.Limit", GRAPHICS_SECTION, CONFIG_FILE, L"FPS Limit:", L"Allows you to set a frame rate cap. Set to -1 to unlock the frame rate.", 60, -1, INT_MAX), new NumericOption(L"frm.motion.rate", GRAPHICS_SECTION, CONFIG_FILE, L"FRM Motion Rate:", L"Sets the motion rate (fps) for the Frame Rate Manager component.\nLarger values should be smoother, but more CPU intensive and possibly buggier.", 300, 1, INT_MAX), @@ -212,7 +212,10 @@ ConfigOptionBase* optionsArray[] = { new BooleanOption(L"rumble", KEYCONFIG_SECTION, KEYCONFIG_FILE, L"XInput Rumble", L"Enables rumble during chainslides.", true, true), new NumericOption(L"xinput_preferred", KEYCONFIG_SECTION, KEYCONFIG_FILE, L"XInput Controller Num:", L"Sets the preferred XInput controller.\nIf unavailable, the next connected controller is used.", 0, 0, 3), new OptionMetaSpacer(8), - + + new BooleanOption(L"hardware_slider", PATCHES_SECTION, CONFIG_FILE, L"Use Hardware Slider", L"Enable this if using a real arcade slider.\n(set the slider to port COM11)", false, false), + new OptionMetaSpacer(8), + new BooleanOption(L"opengl_patch_a", LAUNCHER_SECTION, CONFIG_FILE, L"OpenGL Patch A", L"Ignores some OpenGL-related errors. Don't use both patches at the same time unless you're know what you're doing.", L"", false), new BooleanOption(L"opengl_patch_b", LAUNCHER_SECTION, CONFIG_FILE, L"OpenGL Patch B", L"Ignores some OpenGL-related errors. Don't use both patches at the same time unless you're know what you're doing.", L"", false), new OptionMetaSpacer(8), diff --git a/source-code/source/plugins/Patches/dllmain.cpp b/source-code/source/plugins/Patches/dllmain.cpp index adff4de..c3a4be0 100644 --- a/source-code/source/plugins/Patches/dllmain.cpp +++ b/source-code/source/plugins/Patches/dllmain.cpp @@ -230,6 +230,7 @@ void ApplyPatches() { auto nForceMouth = GetPrivateProfileIntW(L"patches", L"force_mouth", 0, CONFIG_FILE); auto nForceExpressions = GetPrivateProfileIntW(L"patches", L"force_expressions", 0, CONFIG_FILE); auto nForceLook = GetPrivateProfileIntW(L"patches", L"force_look", 0, CONFIG_FILE); + auto nNpr1 = GetPrivateProfileIntW(L"graphics", L"npr1", 0, CONFIG_FILE); std::string version_string = std::to_string(game_version); version_string.insert(version_string.begin()+1, '.'); @@ -291,7 +292,7 @@ void ApplyPatches() { *((byte*)0x000000014049258A + 2) = 0x90; VirtualProtect((BYTE*)0x000000014049258A, 3, oldProtect, &bck); } - printf("[TLAC] MLAA disabled\n"); + printf("[Patches] MLAA disabled\n"); } // Replace the hardcoded videos with MP4s, if they exist @@ -560,7 +561,7 @@ void ApplyPatches() { *((byte*)0x00000001404AB11A + 2) = 0x90; VirtualProtect((BYTE*)0x00000001404AB11A, 3, oldProtect, &bck); } - printf("[TLAC] MLAA disabled\n"); + printf("[Patches] MLAA disabled\n"); } // Replace the hardcoded videos with MP4s, if they exist @@ -889,7 +890,23 @@ void ApplyPatches() { printf("[Patches] FT look forced\n"); } } + // NPR1 + { + if (nNpr1 == 1) // force on + { + InjectCode((void*)0x0000000140502FC0, { 0xC7, 0x05, 0x6E }); + InjectCode((void*)0x0000000140502FC6, { 0x01, 0x00, 0x00, 0x00, 0xC3 }); + printf("[Patches] NPR1 forced\n"); + } + if (nNpr1 == 2) // force off + { + InjectCode((void*)0x0000000140502FC0, { 0xC7, 0x05, 0x6E }); + InjectCode((void*)0x0000000140502FC6, { 0x00, 0x00, 0x00, 0x00, 0xC3 }); + + printf("[Patches] NPR1 disabled\n"); + } + } } diff --git a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp index 8ccc70d..bbcb4d1 100644 --- a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp +++ b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.cpp @@ -14,6 +14,7 @@ #include "../../FileSystem/ConfigFile.h" #include "../GameState.h" #include "../Pause.h" +#include "../../Utils.h" const std::string KEY_CONFIG_FILE_NAME = "keyconfig.ini"; @@ -344,6 +345,9 @@ namespace TLAC::Components if (keyboard->IsIntervalTapped(VK_SPACE)) inputKey = 0x20; + if (keyboard->IsIntervalTapped(VK_F9)) + toggleNpr1(); + if (keyboard->IsDoubleTapped(VK_ESCAPE)) *(bool*)SHOULD_EXIT_BOOL_ADDRESS = true; @@ -435,4 +439,30 @@ namespace TLAC::Components if ((*(unsigned char*)0x14CD93A98) == 0) (*(unsigned char*)0x14CD93A98)++; } } + + void InputEmulator::toggleNpr1() + { + switch(*(byte*)0x0000000140502FC6) + { + case 0xC3: // default -> force on + InjectCode((void*)0x0000000140502FC0, { 0xC7, 0x05, 0x6E }); + InjectCode((void*)0x0000000140502FC6, { 0x01, 0x00, 0x00, 0x00, 0xC3 }); + *(byte*)0x00000001411AD638 = 1; + + printf("[TLAC] NPR1 forced\n"); + break; + case 0x01: // default -> force off + InjectCode((void*)0x0000000140502FC0, { 0xC7, 0x05, 0x6E }); + InjectCode((void*)0x0000000140502FC6, { 0x00, 0x00, 0x00, 0x00, 0xC3 }); + *(byte*)0x00000001411AD638 = 0; + + printf("[TLAC] NPR1 disabled\n"); + break; + default: // force off -> default + InjectCode((void*)0x0000000140502FC0, { 0x89, 0x0D, 0x72 }); + InjectCode((void*)0x0000000140502FC6, { 0xC3, 0xCC, 0xCC, 0xCC, 0xCC }); + + printf("[TLAC] NPR1 restored\n"); + } + } } \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.h b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.h index c0ff2f9..022f20d 100644 --- a/source-code/source/plugins/TLAC/Components/Input/InputEmulator.h +++ b/source-code/source/plugins/TLAC/Components/Input/InputEmulator.h @@ -110,5 +110,6 @@ namespace TLAC::Components void SetMetaButtons(); void addCoin(); + void toggleNpr1(); }; } diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj b/source-code/source/plugins/TLAC/TLAC.vcxproj index aed1d55..46efea8 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj @@ -173,6 +173,7 @@ + @@ -224,6 +225,7 @@ + diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters index 41ff9d0..836d77b 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters @@ -213,6 +213,9 @@ Header Files + + Header Files + @@ -362,5 +365,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Utils.cpp b/source-code/source/plugins/TLAC/Utils.cpp new file mode 100644 index 0000000..a77739d --- /dev/null +++ b/source-code/source/plugins/TLAC/Utils.cpp @@ -0,0 +1,12 @@ +#include "Utils.h" +#include + +void InjectCode(void* address, const std::vector data) +{ + const size_t byteCount = data.size() * sizeof(uint8_t); + + DWORD oldProtect; + VirtualProtect(address, byteCount, PAGE_EXECUTE_READWRITE, &oldProtect); + memcpy(address, data.data(), byteCount); + VirtualProtect(address, byteCount, oldProtect, nullptr); +} diff --git a/source-code/source/plugins/TLAC/Utils.h b/source-code/source/plugins/TLAC/Utils.h new file mode 100644 index 0000000..8202549 --- /dev/null +++ b/source-code/source/plugins/TLAC/Utils.h @@ -0,0 +1,4 @@ +#pragma once +#include + +void InjectCode(void* address, const std::vector data);