PDL3 part 2

This commit is contained in:
nastys
2021-07-22 04:35:52 +02:00
parent adb5c02256
commit 362b28da6e
22 changed files with 1582 additions and 295 deletions
@@ -1,7 +1,7 @@
#pragma once
#include <vector>
#include "PatchApplier.h"
#include "framework.h"
#include "patches-framework.h"
class PatchApplier600 : public PatchApplier {
virtual void ApplyPatches() {
@@ -127,14 +127,6 @@ class PatchApplier600 : public PatchApplier {
printf("[Patches] MLAA disabled\n");
}
// Replace the hardcoded videos with MP4s, if they exist
if (nMP4Movies)
{
patchMovieExt("adv_cfm_cm", (void*)0x0000000140989ED5);
patchMovieExt("adv_sega_cm", (void*)0x0000000140989EF6);
patchMovieExt("diva_adv02", (void*)0x00000001409C537D);
patchMovieExt("diva_adv", (void*)0x00000001409C53AB);
}
// Hide "FREE PLAY"
if (nHideFreeplay)
{
@@ -3,7 +3,7 @@
#pragma once
#include <vector>
#include "PatchApplier.h"
#include "framework.h"
#include "patches-framework.h"
class PatchApplier710 : public PatchApplier {
virtual void ApplyPatches() {
@@ -129,17 +129,6 @@ class PatchApplier710 : public PatchApplier {
printf("[Patches] MLAA disabled\n");
}
// Replace the hardcoded videos with MP4s, if they exist
if (nMP4Movies)
{
patchMovieExt("adv_cm_01", (void*)0x00000001409A53CC);
patchMovieExt("adv_cm_02", (void*)0x00000001409A53E4);
patchMovieExt("adv_cm_03", (void*)0x00000001409A53FC);
patchMovieExt("adv_cfm_cm", (void*)0x00000001409C22CD);
patchMovieExt("adv_sega_cm", (void*)0x00000001409C22EE);
patchMovieExt("diva_adv02", (void*)0x00000001409FF455);
patchMovieExt("diva_adv", (void*)0x00000001409FF483);
}
// Hide "FREE PLAY"
if (nHideFreeplay)
{
@@ -157,7 +146,10 @@ class PatchApplier710 : public PatchApplier {
if (nPDLoaderText && !nHideFreeplay)
{
InjectCode((void*)0x00000001409F61F0, { 0x50, 0x44, 0x20, 0x4C, 0x6F, 0x61, 0x64, 0x65, 0x72, 0x20, 0x00 });
InjectCode((void*)0x00000001409F61F0, { 0x50, 0x44, 0x20 });
InjectCode((void*)0x00000001409F61F3, { 0x4C, 0x6F, 0x61 });
InjectCode((void*)0x00000001409F61F6, { 0x64, 0x65, 0x72 });
InjectCode((void*)0x00000001409F61F9, { 0x20, 0x00 });
printf("[Patches] Show PD Loader text\n");
}
}
@@ -689,5 +681,109 @@ class PatchApplier710 : public PatchApplier {
printf("[Patches] Lag Compensation: %f\n", startPos);
}
// no message bar
if (nNoMessageBar)
{
InjectCode((void*)(0x1409F6470), { 0x00 });
// no scrolling message by snakemi
InjectCode((void*)(0x1403B98FD), { 0x00, 0x00, 0x00, 0x00 });
InjectCode((void*)(0x1403B9904), { 0x00, 0x00, 0x00, 0x00 });
InjectCode((void*)(0x1403B990B), { 0x00, 0x00, 0x00, 0x00 });
}
// no stage text
if (nNoStageText)
{
InjectCode((void*)(0x140A3D4C8), { 0x00 });
InjectCode((void*)(0x140A3D4D8), { 0x00 });
InjectCode((void*)(0x140A3D4E8), { 0x00 });
InjectCode((void*)(0x140A3D4F8), { 0x00 });
InjectCode((void*)(0x140A3D508), { 0x00 });
InjectCode((void*)(0x140A3D518), { 0x00 });
InjectCode((void*)(0x140A3D530), { 0x00 });
InjectCode((void*)(0x140A3D540), { 0x00 });
InjectCode((void*)(0x140A3D550), { 0x00 });
}
// no osage play data by Skyth
if (nNoOpd)
{
InjectCode((void*)(0x1404728C0), { 0xC3 });
InjectCode((void*)(0x1404789C3), { 0x0D });
}
// debug scaling by somewhatlurker
if (nDwguiScaling)
{
InjectCode((void*)(0x1402ffccf), { 0x0d, 0x00, 0x00, 0x00 }); // 720p res index
InjectCode((void*)(0x1403025f2), { 0x48, 0x8d, 0x05, 0x17, 0x65, 0x6b, 0x00 }); // LEA RAX, [0x1409b8b10] (720p res info at +0xc, +-x10)
InjectCode((void*)(0x1403025f9), { 0xeb, 0xb3 }); // JMP 0x1403025ae
InjectCode((void*)(0x1403025a9), { 0xeb, 0x47 }); // JMP 0x1403025f2
// hacky fix for mouse input scaling
// someone please fix this properly if possible
// directly load mouse coordinates to xmm0 to save code space
InjectCode((void*)(0x140300a62), { 0x0f, 0x2a, 0x86, 0xa0, 0x00, 0x00, 0x00 }); // CVTPI2PS XMM0, qword ptr[RSI + 0xa0]
// load 720p
InjectCode((void*)(0x140300a69), { 0x0f, 0x2a, 0x0d, 0xac, 0x80, 0x6b, 0x00 }); // CVTPI2PS XMM1, qword ptr [0x1409b8b1c]
// load native res (140eda8b0 is the native res version of the above 720p res info)
InjectCode((void*)(0x140300a70), { 0x0f, 0x2a, 0x15, 0x45, 0x9e, 0xbd, 0x00 }); // CVTPI2PS XMM2, qword ptr [0x140eda8bc]
// math
InjectCode((void*)(0x140300a77), { 0x0f, 0x59, 0xc1 }); // MULPS XMM0, XMM1
InjectCode((void*)(0x140300a7a), { 0x0f, 0x5e, 0xc2 }); // DIVPS XMM0, XMM2
// used this space, go elsewhere
InjectCode((void*)(0x140300a7d), { 0xe9, 0x83, 0x06, 0x00, 0x00 }); // JMP 0x140301105
// need to restore this instruction
InjectCode((void*)(0x140301105), { 0x0f, 0x57, 0xe4 }); // XORPS XMM4, XMM4
// need to unpack XMM0 into XMM1 and XMM0
InjectCode((void*)(0x140301108), { 0xf3, 0x0f, 0x10, 0xc8 }); // MOVSS XMM1, XMM0
// move to new space
InjectCode((void*)(0x14030110c), { 0xeb, 0x07 }); // JMP 0x140301115
// copy high float of xmm0 to low float of xmm0
InjectCode((void*)(0x140301115), { 0x0f, 0xc6, 0xc0, 0x55 }); // SHUFPS XMM0, XMM0, 0x55
// finally back to original code
InjectCode((void*)(0x140301119), { 0xe9, 0x64, 0xf9, 0xff, 0xff }); // JMP 0x140300a82
// don't need these anymore
InjectCode((void*)(0x140300a82), { 0x90, 0x90, 0x90 }); // NOPs
InjectCode((void*)(0x140300a88), { 0x90, 0x90, 0x90 }); // NOPs
}
// modpack redirection
/*{
wchar_t* mpstr = NULL;
mpstr = (wchar_t*)malloc(256);
memset(mpstr, 0, 256);
GetPrivateProfileStringW(L"Mods", L"Modpack", L"", mpstr, 256, CONFIG_FILE_NAME);
std::string modpack_name(std::filesystem::path(mpstr).string());
free(mpstr);
std::cout << "[Patches] Modpack name: " << modpack_name << std::endl;
if (modpack_name != "")
{
// ram
std::string modpack_path = "modpacks\\" + modpack_name;
std::cout << "[Patches] New ram path: " << modpack_path << std::endl;
char* mpstr_path = (char*)malloc(modpack_path.size());
memcpy(mpstr_path, modpack_path.c_str(), modpack_path.size());
InjectLong((void*)0x0000000014096C120, (long)mpstr_path);
// mdata
std::string modpack_mdata = "modpacks\\" + modpack_name + "\\mdata";
std::cout << "[Patches] New mdata path: " << modpack_mdata << std::endl;
char* mpstr_mdata = (char*)malloc(modpack_mdata.size());
memcpy(mpstr_mdata, modpack_mdata.c_str(), modpack_mdata.size());
InjectCode((void*)0x000000014066CEA0, { 0x48, 0xC7, 0xC2 });
InjectInt((void*)0x000000014066CEA3, (int)mpstr_mdata);
InjectCode((void*)0x000000014066CE9C, { (unsigned char)modpack_mdata.size() });
InjectCode((void*)0x000000014066CEAE, { (unsigned char)modpack_mdata.size() });
}
}*/
}
};
@@ -47,37 +47,28 @@ void InjectCode(void* address, const std::vector<uint8_t> data)
VirtualProtect(address, byteCount, oldProtect, nullptr);
}
// patchMovieExt will modify an extension to mp4 only if the file exists on disk as an mp4
void patchMovieExt(std::string moviefile, void* address)
void InjectInt(void* address, const int data)
{
bool isinmdata = 0;
try {
for (std::filesystem::path p : std::filesystem::directory_iterator("../mdata"))
{
if (std::filesystem::path(p).filename().string().at(0) != 'M' || std::filesystem::path(p).filename().string().length() > 4) continue;
if (std::filesystem::exists(p.string() + "/rom/movie/" + moviefile + ".mp4"))
{
isinmdata = 1;
//std::cout << "[Patches] Movie " << moviefile << ".mp4 found in M" << ss.str() << std::endl;
break;
}
}
}
catch (const std::filesystem::filesystem_error& e) {
std::cout << "[Patches] File system error " << e.what() << " " << e.path1() << " " << e.path2() << " " << e.code() << std::endl;
}
const size_t byteCount = sizeof(int);
if (isinmdata || std::filesystem::exists("../rom/movie/" + moviefile + ".mp4"))
{
InjectCode(address, { 0x6D, 0x70, 0x34 });
std::cout << "[Patches] Movie " << moviefile << " patched to mp4\n";
return;
}
//std::cout << "[Patches] Movie " << moviefile << " NOT patched to mp4\n";
return;
DWORD oldProtect;
VirtualProtect(address, byteCount, PAGE_EXECUTE_READWRITE, &oldProtect);
*(int*)address = data;
VirtualProtect(address, byteCount, oldProtect, nullptr);
}
const LPCWSTR CONFIG_FILE = L".\\config.ini";
void InjectLong(void* address, const long data)
{
const size_t byteCount = sizeof(long);
DWORD oldProtect;
VirtualProtect(address, byteCount, PAGE_EXECUTE_READWRITE, &oldProtect);
*(long*)address = data;
VirtualProtect(address, byteCount, oldProtect, nullptr);
}
const LPCWSTR CONFIG_FILE = L"plugins\\config.ini";
const LPCWSTR CONFIG_FILE_NAME = L".\\config.ini";
auto nCursor = GetPrivateProfileIntW(L"patches", L"cursor", TRUE, CONFIG_FILE);
auto nHideFreeplay = GetPrivateProfileIntW(L"patches", L"hide_freeplay", FALSE, CONFIG_FILE);
@@ -89,7 +80,6 @@ auto nNoPVUi = GetPrivateProfileIntW(L"patches", L"no_pv_ui", FALSE, CONFIG_FILE
auto nHideVolCtrl = GetPrivateProfileIntW(L"patches", L"hide_volume", FALSE, CONFIG_FILE);
auto nNoLyrics = GetPrivateProfileIntW(L"patches", L"no_lyrics", FALSE, CONFIG_FILE);
auto nNoMovies = GetPrivateProfileIntW(L"patches", L"no_movies", FALSE, CONFIG_FILE);
auto nMP4Movies = GetPrivateProfileIntW(L"patches", L"mp4_movies", FALSE, CONFIG_FILE);
auto nNoError = GetPrivateProfileIntW(L"patches", L"no_error", FALSE, CONFIG_FILE);
auto nNoTimer = GetPrivateProfileIntW(L"patches", L"no_timer", TRUE, CONFIG_FILE);
auto nNoTimerSprite = GetPrivateProfileIntW(L"patches", L"no_timer_sprite", TRUE, CONFIG_FILE);
@@ -105,7 +95,8 @@ auto nMLAA = GetPrivateProfileIntW(L"graphics", L"mlaa", TRUE, CONFIG_FILE);
auto nDoF = GetPrivateProfileIntW(L"graphics", L"dof", TRUE, CONFIG_FILE);
auto nMAG = GetPrivateProfileIntW(L"graphics", L"mag", 0, CONFIG_FILE);
auto nStereo = GetPrivateProfileIntW(L"patches", L"stereo", TRUE, CONFIG_FILE);
auto nCustomPatches = GetPrivateProfileIntW(L"patches", L"custom_patches", TRUE, CONFIG_FILE);
auto nBuiltinPatches = GetPrivateProfileIntW(L"global", L"builtin_patches", TRUE, CONFIG_FILE);
auto nCustomPatches = GetPrivateProfileIntW(L"global", L"custom_patches", TRUE, CONFIG_FILE);
auto nQuickStart = GetPrivateProfileIntW(L"patches", L"quick_start", 1, CONFIG_FILE);
auto nNoScrollingSfx = GetPrivateProfileIntW(L"patches", L"no_scrolling_sfx", FALSE, CONFIG_FILE);
auto nNoHandScaling = GetPrivateProfileIntW(L"patches", L"no_hand_scaling", FALSE, CONFIG_FILE);
@@ -126,4 +117,8 @@ auto nReflectResWidth = GetPrivateProfileIntW(L"graphics", L"reflect_res_width",
auto nReflectResHeight = GetPrivateProfileIntW(L"graphics", L"reflect_res_height", 256, CONFIG_FILE);
auto nRefractResWidth = GetPrivateProfileIntW(L"graphics", L"refract_res_width", 512, CONFIG_FILE);
auto nRefractResHeight = GetPrivateProfileIntW(L"graphics", L"refract_res_height", 256, CONFIG_FILE);
auto nLagCompensation = GetPrivateProfileIntW(L"graphics", L"lag_compensation", 0, CONFIG_FILE);
auto nLagCompensation = GetPrivateProfileIntW(L"graphics", L"lag_compensation", 0, CONFIG_FILE);
auto nNoMessageBar = GetPrivateProfileIntW(L"patches", L"no_message_bar", FALSE, CONFIG_FILE);
auto nNoStageText = GetPrivateProfileIntW(L"patches", L"no_stage_text", FALSE, CONFIG_FILE);
auto nNoOpd = GetPrivateProfileIntW(L"patches", L"no_opd", FALSE, CONFIG_FILE);
auto nDwguiScaling = GetPrivateProfileIntW(L"patches", L"dwgui_scaling", FALSE, CONFIG_FILE);
@@ -7,24 +7,19 @@
#include <filesystem>
#include <sstream>
#include <iomanip>
#include "PluginConfigApi.h"
#include "patches.h"
//#include "PluginConfigApi.h"
#include "PatchApplier.h"
#include "PatchApplier600.h"
#include "PatchApplier710.h"
#include <detours.h>
#include "framework.h"
#include "patches-framework.h"
#pragma comment(lib, "detours.lib")
unsigned short game_version = 710;
extern unsigned short game_version;
void InjectCode(void* address, const std::vector<uint8_t> data);
void ApplyPatches();
void ApplyCustomPatches(std::wstring CPATCH_FILE_STRING);
HMODULE *hModulePtr;
/*HMODULE* hModulePtr;
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
@@ -35,7 +30,6 @@ BOOL APIENTRY DllMain(HMODULE hModule,
{
case DLL_PROCESS_ATTACH:
hModulePtr = &hModule;
if (*(char*)0x140A570F0 == '6') game_version = 600;
ApplyPatches();
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
@@ -43,43 +37,54 @@ BOOL APIENTRY DllMain(HMODULE hModule,
break;
}
return TRUE;
}
}*/
void ApplyPatches() {
std::string version_string = std::to_string(game_version);
version_string.insert(version_string.begin()+1, '.');
std::cout << "[Patches] Game version " + version_string << std::endl;
PatchApplier* pa;
switch (game_version)
if (nBuiltinPatches)
{
case 600:
pa = new PatchApplier600;
break;
default:
pa = new PatchApplier710;
if (*(char*)0x140A570F0 == '6') game_version = 600;
std::string version_string = std::to_string(game_version);
version_string.insert(version_string.begin()+1, '.');
std::cout << "[Patches] Game version " + version_string << std::endl;
PatchApplier* pa;
switch (game_version)
{
case 600:
pa = new PatchApplier600;
break;
default:
pa = new PatchApplier710;
}
pa->ApplyPatches();
printf("[Patches] Patches applied\n");
}
}
pa->ApplyPatches();
printf("[Patches] Patches applied\n");
void ApplyAllCustomPatches()
{
if (nCustomPatches)
{
std::cout << "[Patches] Reading custom patches...\n";
std::cout << "[Patches] Reading custom patches in " << std::filesystem::current_path().string() << "\\patches" << std::endl;
try {
for (std::filesystem::path p : std::filesystem::directory_iterator("../patches"))
for (std::filesystem::path p : std::filesystem::directory_iterator("patches"))
{
std::string extension = std::filesystem::path(p).extension().string();
if ((extension == ".p" || extension == ".P" || extension == ".p2" || extension == ".P2") &&
GetPrivateProfileIntW(L"plugins", std::filesystem::path(p).filename().c_str(), TRUE, CONFIG_FILE))
if ((extension == ".p" || extension == ".P" || extension == ".p2" || extension == ".P2"))
{
std::cout << "[Patches] Reading custom patch file: " << std::filesystem::path(p).filename().string() << std::endl;
ApplyCustomPatches(std::filesystem::path(p).wstring());
if (GetPrivateProfileIntW(L"plugins", std::filesystem::path(p).filename().c_str(), FALSE, CONFIG_FILE))
{
std::cout << "[Patches] Reading custom patch file: " << std::filesystem::path(p).filename().string() << std::endl;
ApplyCustomPatches(std::filesystem::path(p).wstring());
}
else std::cout << "[Patches] Skipping disabled patch file: " << std::filesystem::path(p).filename().string() << std::endl;
}
}
}
catch (const std::filesystem::filesystem_error &e) {
catch (const std::filesystem::filesystem_error& e) {
std::cout << "[Patches] File system error " << e.what() << " " << e.path1() << " " << e.path2() << " " << e.code() << std::endl;
}
@@ -87,8 +92,6 @@ void ApplyPatches() {
}
}
void ApplyCustomPatches(std::wstring CPATCH_FILE_STRING)
{
LPCWSTR CPATCH_FILE = CPATCH_FILE_STRING.c_str();
@@ -242,7 +245,7 @@ void ApplyCustomPatches(std::wstring CPATCH_FILE_STRING)
}
using namespace PluginConfig;
/*using namespace PluginConfig;
extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void)
{
@@ -252,4 +255,4 @@ extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void)
extern "C" __declspec(dllexport) LPCWSTR GetPluginDescription(void)
{
return L"Applies patches/tweaks to the game before it starts.\nThis plugin is required.";
}
}*/
@@ -0,0 +1,5 @@
#pragma once
void InjectCode(void* address, const std::vector<uint8_t> data);
void ApplyPatches();
void ApplyAllCustomPatches();
void ApplyCustomPatches(std::wstring CPATCH_FILE_STRING);