Skip to content

Commit

Permalink
Add main menu skip (default) and pedestrian removal
Browse files Browse the repository at this point in the history
  • Loading branch information
maximegmd committed Dec 16, 2020
1 parent 9078341 commit 5a469e5
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ This plugin fixes some Cyberpunk 2077 issues and adds some features.
* [UnhingedDoork](https://www.reddit.com/r/Amd/comments/kbp0np/cyberpunk_2077_seems_to_ignore_smt_and_mostly/gfjf1vo/?utm_source=reddit&utm_medium=web2x&context=3)
* [CookiePLMonster](https://www.reddit.com/r/pcgaming/comments/kbsywg/cyberpunk_2077_used_an_intel_c_compiler_which/gfknein/?utm_source=reddit&utm_medium=web2x&context=3)
* [SirLynix](https://github.com/DigitalPulseSoftware/BurgWar) for the CI file.
* [emoose](https://github.com/yamashi/PerformanceOverhaulCyberpunk/issues/75) for pedestrian removal and start menu skip research.
4 changes: 4 additions & 0 deletions src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Options::Options(HMODULE aModule)
this->PatchUnlockMenu = config.value("unlock_menu", this->PatchUnlockMenu);
this->CPUMemoryPoolFraction = config.value("cpu_memory_pool_fraction", this->CPUMemoryPoolFraction);
this->GPUMemoryPoolFraction = config.value("gpu_memory_pool_fraction", this->GPUMemoryPoolFraction);
this->PatchRemovePedestrians = config.value("remove_pedestrians", this->PatchRemovePedestrians);
this->PatchSkipStartMenu = config.value("skip_start_menu", this->PatchSkipStartMenu);
}

nlohmann::json config;
Expand All @@ -58,6 +60,8 @@ Options::Options(HMODULE aModule)
config["unlock_menu"] = this->PatchUnlockMenu;
config["cpu_memory_pool_fraction"] = this->CPUMemoryPoolFraction;
config["gpu_memory_pool_fraction"] = this->GPUMemoryPoolFraction;
config["remove_pedestrians"] = this->PatchRemovePedestrians;
config["skip_start_menu"] = this->PatchSkipStartMenu;

std::ofstream o(configPath);
o << config.dump(4) << std::endl;
Expand Down
2 changes: 2 additions & 0 deletions src/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct Options
bool PatchVirtualInput{ true };
bool PatchMemoryPool{ true };
bool PatchUnlockMenu{ false };
bool PatchRemovePedestrians{ false };
bool PatchSkipStartMenu{ true };
float CPUMemoryPoolFraction{ 0.5f };
float GPUMemoryPoolFraction{ 1.f };
std::filesystem::path Path;
Expand Down
45 changes: 45 additions & 0 deletions src/Pattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "Pattern.h"
#include <spdlog/spdlog.h>

bool CompareByteArray(uint8_t* Data, const std::vector<uint8_t>& aSignature)
{
uint8_t* pData = Data;

for (auto i : aSignature)
{
auto current = *pData;
pData++;

if (i == 0xCC)
{
continue;
}

if (current != i)
{
return false;
}
}

return true;
}

uint8_t* FindSignature(uint8_t* apStart, uint8_t* apEnd, std::vector<uint8_t> aSignature) noexcept
{
const uint8_t first = aSignature[0];
const uint8_t* pEnd = apEnd - aSignature.size();

for (; apStart < pEnd; ++apStart)
{
if (*apStart != first)
{
continue;
}
if (CompareByteArray(apStart, aSignature))
{
return apStart;
}
}

return nullptr;
}
6 changes: 6 additions & 0 deletions src/Pattern.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <cstdint>
#include <vector>

uint8_t* FindSignature(uint8_t* apStart, uint8_t* apEnd, std::vector<uint8_t> apSignature) noexcept;
8 changes: 8 additions & 0 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ void PatchAvx(Image* apImage);
void SpectrePatch(Image* apImage);
void StringInitializerPatch(Image* apImage);
void SpinLockPatch(Image* apImage);
void StartScreenPatch(Image* apImage);
void RemovePedsPatch(Image* apImage);

void Initialize(HMODULE mod)
{
Expand Down Expand Up @@ -47,6 +49,12 @@ void Initialize(HMODULE mod)
if (options.PatchUnlockMenu)
UnlockMenuPatch(&image);

if(options.PatchSkipStartMenu)
StartScreenPatch(&image);

if(options.PatchRemovePedestrians)
RemovePedsPatch(&image);

spdlog::default_logger()->flush();
}

Expand Down
23 changes: 23 additions & 0 deletions src/remove_peds_patch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <windows.h>

#include "Image.h"
#include <spdlog/spdlog.h>
#include "Pattern.h"

void RemovePedsPatch(Image* apImage)
{
auto pLocation = FindSignature(apImage->pTextStart, apImage->pTextEnd, { 0x3B, 0xD8, 0x0F, 0x4E, 0xC3, 0x8B, 0xD8, 0x85, 0xDB, 0x0F, 0x8E });
if(pLocation == nullptr)
{
spdlog::info("\tRemove peds patch: failed, could not be found");
return;
}

DWORD oldProtect = 0;
VirtualProtect(pLocation, 32, PAGE_EXECUTE_WRITECOPY, &oldProtect);
pLocation[9] = 0x90;
pLocation[10] = 0xE9;
VirtualProtect(pLocation, 32, oldProtect, nullptr);

spdlog::info("\tRemove peds patch: success");
}
25 changes: 25 additions & 0 deletions src/skip_start_screen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <windows.h>

#include "Image.h"
#include <spdlog/spdlog.h>
#include "Pattern.h"

void StartScreenPatch(Image* apImage)
{
auto pLocation = FindSignature(apImage->pTextStart, apImage->pTextEnd, { 0x48, 0xBB , 0xE6 , 0xF8 , 0xA5, 0xA3, 0x36, 0x56, 0x4E, 0xA7, 0xC6 , 0x85, 0xB0, 0xCC, 0xCC, 0xCC, 0x01 });
if(pLocation == nullptr)
{
spdlog::info("\tStart screen patch: failed, could not be found");
return;
}

pLocation -= 9;

DWORD oldProtect = 0;
VirtualProtect(pLocation, 32, PAGE_EXECUTE_WRITECOPY, &oldProtect);
pLocation[0] = 0x90;
pLocation[1] = 0x90;
VirtualProtect(pLocation, 32, oldProtect, nullptr);

spdlog::info("\tStart screen patch: success");
}

1 comment on commit 5a469e5

@Morritz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That pedestrian removal, in my case helped framerate, and there is no frame stuttering like before. My graphics card is below minimum requirements, it is playable but not the best experience it could be. Keep it up. I hope that dev's patches and yours combined altogether will make it right.

Please sign in to comment.