From 7aea826f8e1a62e88cae5887787cff9173e2798a Mon Sep 17 00:00:00 2001 From: nastys <@> Date: Tue, 26 Nov 2019 20:50:34 +0100 Subject: [PATCH] Add IGNORE, @ (hide patch), syntax example --- .../patches/custom_freeplay_text_example.p | 18 +++++++--- .../source/plugins/Patches/dllmain.cpp | 34 ++++++++++++++----- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/source-code/data/patches/custom_freeplay_text_example.p b/source-code/data/patches/custom_freeplay_text_example.p index a41445e..e3b4681 100644 --- a/source-code/data/patches/custom_freeplay_text_example.p +++ b/source-code/data/patches/custom_freeplay_text_example.p @@ -1,6 +1,16 @@ -//# Enable FREE PLAY +IGNORE +# Enable FREE PLAY // Just in case it's disabled... -//1403BABEA:75 // ...enable it. +@1403BABEA:75 // ...enable it. -//# Custom FREE PLAY text -//1409F61F0:!My text \ No newline at end of file +# Custom FREE PLAY text +1409F61F0:!My text + +// Syntax: +// "#" console comment +// "//" hidden comment +// "@" omit patch console output +// ":" address:bytes (hex) +// " " byte byte +// ":!" address:!string +// "IGNORE" skip patch file \ No newline at end of file diff --git a/source-code/source/plugins/Patches/dllmain.cpp b/source-code/source/plugins/Patches/dllmain.cpp index f3df9f0..b0ce3fc 100644 --- a/source-code/source/plugins/Patches/dllmain.cpp +++ b/source-code/source/plugins/Patches/dllmain.cpp @@ -488,12 +488,19 @@ void ApplyCustomPatches(std::wstring CPATCH_FILE_STRING) std::cout << "[Patches]" << line.substr(1, line.size()-1) << std::endl; continue; } + if (line == "IGNORE") break; if (line.find(':') == std::string::npos || (line[0] == '/' && line[1] == '/')) continue; std::vector commentHSplit = SplitString(line, "#"); std::vector commentDSSplit = SplitString(commentHSplit[0], "//"); std::vector colonSplit = SplitString(commentDSSplit[0], ":"); if (colonSplit.size() != 2) continue; + bool echo = true; + if (colonSplit[0].at(0) == '@') + { + echo = false; + colonSplit[0].at(0) = ' '; + } long long int address; std::istringstream iss(colonSplit[0]); iss >> std::setbase(16) >> address; @@ -501,17 +508,17 @@ void ApplyCustomPatches(std::wstring CPATCH_FILE_STRING) if (colonSplit[1].at(0) == '!') { - std::cout << "[Patches] Patching: " << std::hex << address << ":!"; + if (echo) std::cout << "[Patches] Patching: " << std::hex << address << ":!"; std::vector fullColonSplit = SplitString(line, ":"); for (int i = 1; i < fullColonSplit[1].size(); i++) { - std::cout << fullColonSplit[1].at(i); + if (echo) std::cout << fullColonSplit[1].at(i); unsigned char byte_u = fullColonSplit[1].at(i); std::vector patch = { byte_u }; InjectCode((void*)address, patch); address++; } - std::cout << std::endl; + if (echo) std::cout << std::endl; } else { @@ -534,24 +541,33 @@ void ApplyCustomPatches(std::wstring CPATCH_FILE_STRING) } } - std::cout << "[Patches] Patching: " << std::hex << address << ":"; + if (echo) std::cout << "[Patches] Patching: " << std::hex << address << ":"; for (std::string bytestring : bytes) { int byte; std::istringstream issb(bytestring); issb >> std::setbase(16) >> byte; unsigned char byte_u = byte; - std::cout << std::hex << byte << " "; - if (comment_counter < comment_string.length()) + if (echo) { - std::cout << "(" << comment_string.at(comment_counter) << ") "; - comment_counter++; + std::cout << std::hex << byte << " "; + if (comment_counter < comment_string.length()) + { + std::cout << "(" << comment_string.at(comment_counter) << ") "; + comment_counter++; + } } std::vector patch = { byte_u }; InjectCode((void*)address, patch); address++; } - std::cout << std::endl; + if (echo) std::cout << std::endl; + else if (comment_string.length() > 0) + { + std::cout << "[Patches]";; + if (comment_string.at(0) != ' ') std::cout << ' '; + std::cout << comment_string << std::endl; + } } }