Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
400 changes: 400 additions & 0 deletions vibrance.GUI/.gitignore

Large diffs are not rendered by default.

115 changes: 96 additions & 19 deletions vibrance.GUI/AMD/AmdDynamicVibranceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using vibrance.GUI.AMD.vendor;
using vibrance.GUI.common;
Expand All @@ -13,6 +12,29 @@ namespace vibrance.GUI.AMD
{
public class AmdDynamicVibranceProxy : IVibranceProxy
{
#region DllImports
[DllImport("gdi32.dll")]
public static extern bool GetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);

[DllImport("gdi32.dll")]
public static extern bool SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct RAMP
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public UInt16[] Red;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public UInt16[] Green;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public UInt16[] Blue;
}
#endregion

public const int AmdMinLevel = 0;
public const int AmdMaxLevel = 300;
public const int AmdDefaultLevel = 100;

private readonly IAmdAdapter _amdAdapter;
private List<ApplicationSetting> _applicationSettings;
private readonly Dictionary<string, Tuple<ResolutionModeWrapper, List<ResolutionModeWrapper>>> _windowsResolutionSettings;
Expand Down Expand Up @@ -69,6 +91,33 @@ public void SetNeverSwitchResolution(bool neverChangeResolution)
_vibranceInfo.neverChangeResolution = neverChangeResolution;
}

public void SetNeverChangeColorSettings(bool neverChangeColorSettings)
{
_vibranceInfo.neverChangeColorSettings = neverChangeColorSettings;
}

public void SetWindowsColorSettings(int brightness, int contrast, int gamma)
{
_vibranceInfo.userColorSettings.brightness = brightness;
_vibranceInfo.userColorSettings.contrast = contrast;
_vibranceInfo.userColorSettings.gamma = gamma;
}

public void SetWindowsColorBrightness(int brightness)
{
_vibranceInfo.userColorSettings.brightness = brightness;
}

public void SetWindowsColorContrast(int contrast)
{
_vibranceInfo.userColorSettings.contrast = contrast;
}

public void SetWindowsColorGamma(int gamma)
{
_vibranceInfo.userColorSettings.gamma = gamma;
}

public void SetVibranceWindowsLevel(int vibranceWindowsLevel)
{
_vibranceInfo.userVibranceSettingDefault = vibranceWindowsLevel;
Expand Down Expand Up @@ -112,26 +161,38 @@ private void OnWinEventHook(object sender, WinEventHookEventArgs e)
ApplicationSetting applicationSetting = _applicationSettings.FirstOrDefault(x => string.Equals(x.Name, e.ProcessName, StringComparison.OrdinalIgnoreCase));
if (applicationSetting != null)
{
//test if a resolution change is needed
Screen screen = Screen.FromHandle(e.Handle);
if (_vibranceInfo.neverChangeResolution == false &&
applicationSetting.IsResolutionChangeNeeded &&
_gameScreen = screen;

//apply application specific saturation
if (_vibranceInfo.userVibranceSettingDefault != applicationSetting.IngameLevel)
{
if (_vibranceInfo.affectPrimaryMonitorOnly)
{
_amdAdapter.SetSaturationOnDisplay(applicationSetting.IngameLevel, screen.DeviceName);
}
else
{
_amdAdapter.SetSaturationOnAllDisplays(applicationSetting.IngameLevel);
}
}

//test if a resolution change is needed
if (_vibranceInfo.neverChangeResolution == false && applicationSetting.IsResolutionChangeNeeded &&
IsResolutionChangeNeeded(screen, applicationSetting.ResolutionSettings) &&
_windowsResolutionSettings.ContainsKey(screen.DeviceName) &&
_windowsResolutionSettings[screen.DeviceName].Item2.Contains(applicationSetting.ResolutionSettings))
{
_gameScreen = screen;
PerformResolutionChange(screen, applicationSetting.ResolutionSettings);
_vibranceInfo.isResolutionChangeApplied = true;
}

_amdAdapter.SetSaturationOnAllDisplays(_vibranceInfo.userVibranceSettingDefault);
if (_vibranceInfo.affectPrimaryMonitorOnly)
{
_amdAdapter.SetSaturationOnDisplay(applicationSetting.IngameLevel, screen.DeviceName);
}
else
//test if color settings change is needed
if (_vibranceInfo.neverChangeColorSettings == false && _vibranceInfo.isColorSettingApplied == false &&
DeviceGammaRampHelper.IsGammaRampEqualToWindowsValues(_vibranceInfo, applicationSetting) == false)
{
_amdAdapter.SetSaturationOnAllDisplays(applicationSetting.IngameLevel);
DeviceGammaRampHelper.SetGammaRamp(screen, applicationSetting.Gamma, applicationSetting.Brightness, applicationSetting.Contrast);
_vibranceInfo.isColorSettingApplied = true;
}
}
else
Expand All @@ -140,17 +201,33 @@ private void OnWinEventHook(object sender, WinEventHookEventArgs e)
if (GetForegroundWindow() != processHandle)
return;

//apply Windows saturation
_amdAdapter.SetSaturationOnAllDisplays(_vibranceInfo.userVibranceSettingDefault);

//test if a resolution change is needed
Screen screen = Screen.FromHandle(processHandle);
if (_vibranceInfo.neverChangeResolution == false &&
_gameScreen != null && _gameScreen.Equals(screen) &&
_windowsResolutionSettings.ContainsKey(screen.DeviceName) &&
IsResolutionChangeNeeded(screen, _windowsResolutionSettings[screen.DeviceName].Item1))
Screen currentScreen = Screen.FromHandle(processHandle);
if (_vibranceInfo.neverChangeResolution == false && _vibranceInfo.isResolutionChangeApplied == true &&
_gameScreen != null && _gameScreen.Equals(currentScreen) &&
_windowsResolutionSettings.ContainsKey(currentScreen.DeviceName) &&
IsResolutionChangeNeeded(currentScreen, _windowsResolutionSettings[currentScreen.DeviceName].Item1))
{
PerformResolutionChange(screen, _windowsResolutionSettings[screen.DeviceName].Item1);
PerformResolutionChange(currentScreen, _windowsResolutionSettings[currentScreen.DeviceName].Item1);
_vibranceInfo.isResolutionChangeApplied = false;
}

_amdAdapter.SetSaturationOnAllDisplays(_vibranceInfo.userVibranceSettingDefault);
//apply windows color settings if color settings were previously changed
if (_vibranceInfo.neverChangeColorSettings == false && _vibranceInfo.isColorSettingApplied == true)
{
if (_vibranceInfo.affectPrimaryMonitorOnly && _gameScreen != null && _gameScreen.DeviceName.Equals(currentScreen.DeviceName))
{
DeviceGammaRampHelper.SetGammaRamp(_gameScreen, _vibranceInfo.userColorSettings.brightness, _vibranceInfo.userColorSettings.contrast, _vibranceInfo.userColorSettings.gamma);
}
else
{
Screen.AllScreens.ToList().ForEach(screen => DeviceGammaRampHelper.SetGammaRamp(screen, _vibranceInfo.userColorSettings.brightness, _vibranceInfo.userColorSettings.contrast, _vibranceInfo.userColorSettings.gamma));
}
_vibranceInfo.isColorSettingApplied = false;
}
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions vibrance.GUI/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura/>

<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>
111 changes: 111 additions & 0 deletions vibrance.GUI/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCompression" type="xs:boolean">
<xs:annotation>
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCleanup" type="xs:boolean">
<xs:annotation>
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
Loading