Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable HDR feature through Windows registry modification #299

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add hdr support
  • Loading branch information
binyang committed Dec 21, 2023
commit dd4c739497da816da4d340cd218a631204ee5a84
1 change: 1 addition & 0 deletions unlockfps_clr/MainForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ namespace unlockfpsclr
settings->FPSTarget = std::clamp(settings->FPSTarget, tbFPS->Minimum, tbFPS->Maximum); // sanitize

ckbAutoStart->DataBindings->Add("Checked", settings, "AutoStart");
ckbHDR->DataBindings->Add("Checked", settings, "EnableHdr");
tbFPS->DataBindings->Add("Value", settings, "FPSTarget", false, DataSourceUpdateMode::OnPropertyChanged);
inputFPS->DataBindings->Add("Value", settings, "FPSTarget", false, DataSourceUpdateMode::OnPropertyChanged);

Expand Down
57 changes: 38 additions & 19 deletions unlockfps_clr/MainForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ namespace unlockfpsclr {
private: System::Windows::Forms::ContextMenuStrip^ contextMenuNotify;
private: System::Windows::Forms::ToolStripMenuItem^ toolStripMenuExit;
private: System::Windows::Forms::ToolStripMenuItem^ menuItemAbout;
private: System::Windows::Forms::CheckBox^ ckbHDR;




Expand Down Expand Up @@ -115,6 +117,7 @@ namespace unlockfpsclr {
this->notifyIcon = (gcnew System::Windows::Forms::NotifyIcon(this->components));
this->contextMenuNotify = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
this->toolStripMenuExit = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->ckbHDR = (gcnew System::Windows::Forms::CheckBox());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->tbFPS))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->inputFPS))->BeginInit();
this->menuStrip1->SuspendLayout();
Expand All @@ -123,9 +126,9 @@ namespace unlockfpsclr {
//
// btnStartGame
//
this->btnStartGame->Location = System::Drawing::Point(197, 80);
this->btnStartGame->Location = System::Drawing::Point(197, 95);
this->btnStartGame->Name = L"btnStartGame";
this->btnStartGame->Size = System::Drawing::Size(75, 23);
this->btnStartGame->Size = System::Drawing::Size(75, 21);
this->btnStartGame->TabIndex = 0;
this->btnStartGame->TabStop = false;
this->btnStartGame->Text = L"Start Game";
Expand All @@ -135,9 +138,9 @@ namespace unlockfpsclr {
// ckbAutoStart
//
this->ckbAutoStart->AutoSize = true;
this->ckbAutoStart->Location = System::Drawing::Point(15, 84);
this->ckbAutoStart->Location = System::Drawing::Point(15, 100);
this->ckbAutoStart->Name = L"ckbAutoStart";
this->ckbAutoStart->Size = System::Drawing::Size(144, 17);
this->ckbAutoStart->Size = System::Drawing::Size(168, 16);
this->ckbAutoStart->TabIndex = 1;
this->ckbAutoStart->TabStop = false;
this->ckbAutoStart->Text = L"Start Game Automatically";
Expand All @@ -154,11 +157,11 @@ namespace unlockfpsclr {
//
this->tbFPS->AutoSize = false;
this->tbFPS->Cursor = System::Windows::Forms::Cursors::Hand;
this->tbFPS->Location = System::Drawing::Point(15, 57);
this->tbFPS->Location = System::Drawing::Point(15, 53);
this->tbFPS->Maximum = 360;
this->tbFPS->Minimum = 1;
this->tbFPS->Name = L"tbFPS";
this->tbFPS->Size = System::Drawing::Size(257, 21);
this->tbFPS->Size = System::Drawing::Size(257, 19);
this->tbFPS->TabIndex = 2;
this->tbFPS->TabStop = false;
this->tbFPS->TickStyle = System::Windows::Forms::TickStyle::None;
Expand All @@ -167,19 +170,19 @@ namespace unlockfpsclr {
// labelFPS
//
this->labelFPS->AutoSize = true;
this->labelFPS->Location = System::Drawing::Point(12, 33);
this->labelFPS->Location = System::Drawing::Point(12, 30);
this->labelFPS->Name = L"labelFPS";
this->labelFPS->Size = System::Drawing::Size(33, 13);
this->labelFPS->Size = System::Drawing::Size(35, 12);
this->labelFPS->TabIndex = 3;
this->labelFPS->Text = L"FPS: ";
//
// inputFPS
//
this->inputFPS->Location = System::Drawing::Point(48, 31);
this->inputFPS->Location = System::Drawing::Point(48, 29);
this->inputFPS->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 360, 0, 0, 0 });
this->inputFPS->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 1, 0, 0, 0 });
this->inputFPS->Name = L"inputFPS";
this->inputFPS->Size = System::Drawing::Size(224, 20);
this->inputFPS->Size = System::Drawing::Size(224, 21);
this->inputFPS->TabIndex = 4;
this->inputFPS->TabStop = false;
this->inputFPS->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 120, 0, 0, 0 });
Expand All @@ -189,7 +192,7 @@ namespace unlockfpsclr {
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->toolStripMenuItem });
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(284, 24);
this->menuStrip1->Size = System::Drawing::Size(284, 25);
this->menuStrip1->TabIndex = 5;
this->menuStrip1->Text = L"menuStrip1";
//
Expand All @@ -200,27 +203,27 @@ namespace unlockfpsclr {
this->menuItemSetup, this->menuItemAbout
});
this->toolStripMenuItem->Name = L"toolStripMenuItem";
this->toolStripMenuItem->Size = System::Drawing::Size(61, 20);
this->toolStripMenuItem->Size = System::Drawing::Size(66, 21);
this->toolStripMenuItem->Text = L"Options";
//
// menuItemSettings
//
this->menuItemSettings->Name = L"menuItemSettings";
this->menuItemSettings->Size = System::Drawing::Size(116, 22);
this->menuItemSettings->Size = System::Drawing::Size(180, 22);
this->menuItemSettings->Text = L"Settings";
this->menuItemSettings->Click += gcnew System::EventHandler(this, &MainForm::settingsMenuItem_Click);
//
// menuItemSetup
//
this->menuItemSetup->Name = L"menuItemSetup";
this->menuItemSetup->Size = System::Drawing::Size(116, 22);
this->menuItemSetup->Size = System::Drawing::Size(180, 22);
this->menuItemSetup->Text = L"Setup";
this->menuItemSetup->Click += gcnew System::EventHandler(this, &MainForm::setupMenuItem_Click);
//
// menuItemAbout
//
this->menuItemAbout->Name = L"menuItemAbout";
this->menuItemAbout->Size = System::Drawing::Size(116, 22);
this->menuItemAbout->Size = System::Drawing::Size(180, 22);
this->menuItemAbout->Text = L"About";
this->menuItemAbout->Click += gcnew System::EventHandler(this, &MainForm::menuItemAbout_Click);
//
Expand All @@ -244,20 +247,34 @@ namespace unlockfpsclr {
this->contextMenuNotify->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->toolStripMenuExit });
this->contextMenuNotify->Name = L"contextMenuNotify";
this->contextMenuNotify->ShowItemToolTips = false;
this->contextMenuNotify->Size = System::Drawing::Size(94, 26);
this->contextMenuNotify->Size = System::Drawing::Size(97, 26);
//
// toolStripMenuExit
//
this->toolStripMenuExit->Name = L"toolStripMenuExit";
this->toolStripMenuExit->Size = System::Drawing::Size(93, 22);
this->toolStripMenuExit->Size = System::Drawing::Size(96, 22);
this->toolStripMenuExit->Text = L"Exit";
this->toolStripMenuExit->Click += gcnew System::EventHandler(this, &MainForm::toolStripMenuExit_Click);
//
// ckbHDR
//
this->ckbHDR->AutoSize = true;
this->ckbHDR->Location = System::Drawing::Point(15, 78);
this->ckbHDR->Name = L"ckbHDR";
this->ckbHDR->Size = System::Drawing::Size(84, 16);
this->ckbHDR->TabIndex = 6;
this->ckbHDR->TabStop = false;
this->ckbHDR->Text = L"Enable HDR";
this->ttAutoStart->SetToolTip(this->ckbHDR, L"This will take effect on subsequent launch");
this->ckbHDR->UseVisualStyleBackColor = true;
this->ckbHDR->CheckedChanged += gcnew System::EventHandler(this, &MainForm::checkBox1_CheckedChanged);
//
// MainForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 115);
this->ClientSize = System::Drawing::Size(284, 126);
this->Controls->Add(this->ckbHDR);
this->Controls->Add(this->inputFPS);
this->Controls->Add(this->labelFPS);
this->Controls->Add(this->tbFPS);
Expand Down Expand Up @@ -292,5 +309,7 @@ namespace unlockfpsclr {
private: Void toolStripMenuExit_Click(Object^ sender, EventArgs^ e);
private: Void OnFormClosing(Object^ sender, FormClosingEventArgs^ e);
private: Void menuItemAbout_Click(Object^ sender, EventArgs^ e);
private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
}
};
}
5 changes: 5 additions & 0 deletions unlockfps_clr/Managed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ bool Managed::StartGame(Settings^ settings)
return false;
}

if (settings->EnableHdr) {
Unmanaged::registerHDREntry();
}


String^ commandLine = "";

if (settings->PopupWindow)
Expand Down
1 change: 1 addition & 0 deletions unlockfps_clr/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Settings^ Settings::InitializeDefaults()
UseCustomRes = false;
IsExclusiveFullscreen = false;
UsePowerSave = false;
EnableHdr = false;

FPSTarget = 120;
CustomResX = 1920;
Expand Down
1 change: 1 addition & 0 deletions unlockfps_clr/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public ref class Settings
property bool IsExclusiveFullscreen;
property bool StartMinimized;
property bool UsePowerSave;
property bool EnableHdr;

property int FPSTarget;
property int CustomResX;
Expand Down
28 changes: 28 additions & 0 deletions unlockfps_clr/Unmanaged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,32 @@ bool Unmanaged::VerifyDLL(PVOID module)
return ntHeader->FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64;
}

void Unmanaged::registerHDREntry()
{
// ����ע���·����Ҫ�޸ĵļ���
HKEY hKey;
LPCWSTR regPath = L"SOFTWARE\\miHoYo\\ԭ��";
LPCWSTR regValueName = L"WINDOWS_HDR_ON_h3132281285";

// �򿪻򴴽�ע�����
LONG result = RegCreateKeyExW(HKEY_CURRENT_USER, regPath, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL);
if (result == ERROR_SUCCESS) {
// ����Ҫд�����ֵ
DWORD newValue = 1;

// д��ע���ֵ
result = RegSetValueExW(hKey, regValueName, 0, REG_DWORD, (BYTE*)&newValue, sizeof(newValue));
if (result != ERROR_SUCCESS) {
std::string message = "Failed to change HDR registry";
MessageBoxA(nullptr, message.c_str(), "Error", MB_OK | MB_ICONERROR);
}
// �ر�ע�����
RegCloseKey(hKey);
}
else {
std::string message = "Failed to open or create HDR registry";
MessageBoxA(nullptr, message.c_str(), "Error", MB_OK | MB_ICONERROR);
}
}

#pragma managed
1 change: 1 addition & 0 deletions unlockfps_clr/Unmanaged.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace Unmanaged
bool SetupData();
bool ShowError(std::string apiName, DWORD code);
bool VerifyDLL(PVOID module);
void registerHDREntry();

DWORD GetPID(std::string ProcessName);
uintptr_t PatternScan(PVOID module, LPCSTR signature);
Expand Down
11 changes: 6 additions & 5 deletions unlockfps_clr/unlockfps_clr.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CLRSupport>true</CLRSupport>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CLRSupport>true</CLRSupport>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
Expand Down Expand Up @@ -80,7 +80,7 @@
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies />
<AdditionalDependencies>Advapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -92,7 +92,7 @@
<AdditionalOptions>/Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<AdditionalDependencies />
<AdditionalDependencies>Advapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<EntryPointSymbol>main</EntryPointSymbol>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
Expand All @@ -104,7 +104,7 @@
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies />
<AdditionalDependencies>Advapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -123,6 +123,7 @@
<OptimizeReferences>true</OptimizeReferences>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>false</DataExecutionPrevention>
<AdditionalDependencies>Advapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down