upload
No files matched your search
@@ -0,0 +1,20 @@
|
|||||||
|
# Build outputs
|
||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Visual Studio / IDE
|
||||||
|
.vs/
|
||||||
|
*.user
|
||||||
|
*.suo
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# Logs and temporary files
|
||||||
|
*.log
|
||||||
|
*.tmp
|
||||||
|
*.bak
|
||||||
|
Thumbs.db
|
||||||
|
Desktop.ini
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using VibranceHud;
|
||||||
|
using VibranceHud.Hotkeys;
|
||||||
|
using VibranceHud.Licensing;
|
||||||
|
|
||||||
|
namespace A;
|
||||||
|
|
||||||
|
internal static class A
|
||||||
|
{
|
||||||
|
internal static bool Available
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ServedNightVision.Live;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void ForgetIfUnavailable()
|
||||||
|
{
|
||||||
|
if (!Available)
|
||||||
|
{
|
||||||
|
HotkeyStatus.Forget(HotkeySlot.NightVision);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using VibranceHud;
|
||||||
|
using VibranceHud.Licensing;
|
||||||
|
|
||||||
|
namespace A;
|
||||||
|
|
||||||
|
internal static class e
|
||||||
|
{
|
||||||
|
private static readonly Lazy<ServedVibranceCurve> FallbackCurve = new Lazy<ServedVibranceCurve>(BuildFallback);
|
||||||
|
|
||||||
|
internal static ServedVibranceCurve Fallback => FallbackCurve.Value;
|
||||||
|
|
||||||
|
internal static ServedVibrancePoint A(int P_0, bool P_1, bool P_2)
|
||||||
|
{
|
||||||
|
return Fallback.At(P_0, P_1, P_2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ServedVibranceCurve BuildFallback()
|
||||||
|
{
|
||||||
|
float[][] array = new float[351][];
|
||||||
|
for (int i = 0; i < array.Length; i++)
|
||||||
|
{
|
||||||
|
float num = VibranceEngine.SoftwareVibranceFactor(i, driverAvailable: false);
|
||||||
|
float num2 = VibranceEngine.SoftwareVibranceFactor(i, driverAvailable: true);
|
||||||
|
array[i] = new float[5]
|
||||||
|
{
|
||||||
|
Math.Min(i, 100),
|
||||||
|
1f + (num - 1f) * 0.55f,
|
||||||
|
num,
|
||||||
|
1f + (num2 - 1f) * 0.55f,
|
||||||
|
num2
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return new ServedVibranceCurve(array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 194 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 187 KiB |
|
After Width: | Height: | Size: 161 KiB |
|
After Width: | Height: | Size: 184 KiB |
|
After Width: | Height: | Size: 196 KiB |
|
After Width: | Height: | Size: 196 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 185 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 204 KiB |
|
After Width: | Height: | Size: 200 KiB |
|
After Width: | Height: | Size: 212 KiB |
|
After Width: | Height: | Size: 190 KiB |
|
After Width: | Height: | Size: 183 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 117 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 109 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 117 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 165 KiB |
@@ -0,0 +1,31 @@
|
|||||||
|
Texture2D<float4> desktopTex : register(t0);
|
||||||
|
SamplerState linearSampler : register(s0);
|
||||||
|
|
||||||
|
cbuffer ColorMatrix : register(b0)
|
||||||
|
{
|
||||||
|
float4 row0;
|
||||||
|
float4 row1;
|
||||||
|
float4 row2;
|
||||||
|
float4 row3;
|
||||||
|
float4 row4;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PSInput
|
||||||
|
{
|
||||||
|
float4 pos : SV_POSITION;
|
||||||
|
float2 uv : TEXCOORD0;
|
||||||
|
};
|
||||||
|
|
||||||
|
float4 main(PSInput input) : SV_Target
|
||||||
|
{
|
||||||
|
float4 c = desktopTex.Sample(linearSampler, input.uv);
|
||||||
|
|
||||||
|
// Apply the 5x5 color matrix (row-major, identical to ColorAdjust.Build()).
|
||||||
|
// The bottom row is identity for alpha and the homogeneous w coordinate.
|
||||||
|
float4 outColor;
|
||||||
|
outColor.r = dot(row0, float4(c.rgb, 1.0));
|
||||||
|
outColor.g = dot(row1, float4(c.rgb, 1.0));
|
||||||
|
outColor.b = dot(row2, float4(c.rgb, 1.0));
|
||||||
|
outColor.a = c.a;
|
||||||
|
return outColor;
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 135 KiB |
|
After Width: | Height: | Size: 1.0 MiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 323 KiB |
@@ -0,0 +1,55 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<AssemblyName>PlexusX</AssemblyName>
|
||||||
|
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<UseWindowsForms>True</UseWindowsForms>
|
||||||
|
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
|
||||||
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<LangVersion>14.0</LangVersion>
|
||||||
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
|
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ApplicationIcon>Assets\Icons\app.ico</ApplicationIcon>
|
||||||
|
<RootNamespace />
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="Assets\Icons\PlexusX.ico" />
|
||||||
|
<None Remove="Assets\Brand\*.png" />
|
||||||
|
<None Remove="Assets\Presets\preset-*.png" />
|
||||||
|
<None Remove="Assets\Shaders\PlexusX.saturation.hlsl" />
|
||||||
|
<EmbeddedResource Include="Assets\Icons\PlexusX.ico" LogicalName="PlexusX.ico" />
|
||||||
|
<EmbeddedResource Include="Assets\Brand\*.png" LogicalName="%(Filename)%(Extension)" />
|
||||||
|
<EmbeddedResource Include="Assets\Presets\preset-*.png" LogicalName="%(Filename)%(Extension)" />
|
||||||
|
<EmbeddedResource Include="Assets\Shaders\PlexusX.saturation.hlsl" LogicalName="PlexusX.saturation.hlsl" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="SharpDX.DXGI">
|
||||||
|
<HintPath>libs\SharpDX.DXGI.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="SharpDX.Direct3D11">
|
||||||
|
<HintPath>libs\SharpDX.Direct3D11.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="SharpDX">
|
||||||
|
<HintPath>libs\SharpDX.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="SharpDX.D3DCompiler">
|
||||||
|
<HintPath>libs\SharpDX.D3DCompiler.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="NvAPIWrapper">
|
||||||
|
<HintPath>libs\NvAPIWrapper.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Windows.SDK.NET">
|
||||||
|
<HintPath>libs\Microsoft.Windows.SDK.NET.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Management">
|
||||||
|
<HintPath>libs\System.Management.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="WinRT.Runtime">
|
||||||
|
<HintPath>libs\WinRT.Runtime.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.0.31903.59
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexusX", "PlexusX.csproj", "{B4E2A9C1-7F3D-4A1E-9B6C-8D5E2F1A3C4B}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{B4E2A9C1-7F3D-4A1E-9B6C-8D5E2F1A3C4B}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{B4E2A9C1-7F3D-4A1E-9B6C-8D5E2F1A3C4B}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{B4E2A9C1-7F3D-4A1E-9B6C-8D5E2F1A3C4B}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{B4E2A9C1-7F3D-4A1E-9B6C-8D5E2F1A3C4B}.Release|x64.Build.0 = Release|x64
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.Versioning;
|
||||||
|
|
||||||
|
[assembly: InternalsVisibleTo("VibranceHud.Tests")]
|
||||||
|
[assembly: AssemblyCompany("PlexusX")]
|
||||||
|
[assembly: AssemblyConfiguration("Release")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © PlexusX")]
|
||||||
|
[assembly: AssemblyDescription("Digital vibrance, colour, resolution and monitor control for Windows.")]
|
||||||
|
[assembly: AssemblyFileVersion("2.1.17.0")]
|
||||||
|
[assembly: AssemblyInformationalVersion("2.1.17")]
|
||||||
|
[assembly: AssemblyProduct("PlexusX")]
|
||||||
|
[assembly: AssemblyTitle("PlexusX")]
|
||||||
|
[assembly: TargetPlatform("Windows10.0.19041.0")]
|
||||||
|
[assembly: SupportedOSPlatform("Windows10.0.19041.0")]
|
||||||
|
[assembly: AssemblyVersion("2.1.17.0")]
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<p align="center">
|
||||||
|
<img src="Assets/ss.png" alt="Skid Solutions Banner" width="350" />
|
||||||
|
<br>
|
||||||
|
<font size="6"><b>OpenPlexusX</b></font>
|
||||||
|
<br>
|
||||||
|
<font size="3">by Skid Solutions</font>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://discord.gg/MqHfS3je6W">https://discord.gg/MqHfS3je6W</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="Assets/jak.jpg" alt="jak" height="150" />
|
||||||
|
<img src="Assets/hack.jpg" alt="hack" height="150" />
|
||||||
|
<img src="Assets/deobf2.png" alt="deobf2" height="150" />
|
||||||
|
<img src="Assets/deobf.jpg" alt="deobf" height="150" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
This is NOT a Remake or Recreation.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## How to build
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
- **OS**: Windows 10 (build 19041+) or Windows 11 (x64)
|
||||||
|
- **.NET SDK**: .NET 10 SDK or newer (required for C# 14 / `<LangVersion>14.0</LangVersion>` in `PlexusX.csproj`; targets `net8.0-windows10.0.19041.0`)
|
||||||
|
- **.NET Desktop Runtime**: .NET 8.0 Desktop Runtime (x64) to run the built executable
|
||||||
|
- Required third-party libraries (`SharpDX`, `NvAPIWrapper`, `Microsoft.Windows.SDK.NET`, `WinRT.Runtime`, `System.Management`) are already bundled in `libs/`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Building PlexusX
|
||||||
|
|
||||||
|
Run from this folder:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
dotnet build PlexusX.sln -c Release -p:Platform=x64
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, open `PlexusX.sln` in Visual Studio and build the `Release | x64` configuration.
|
||||||
|
|
||||||
|
Generated `bin/x64/Release/net8.0-windows10.0.19041.0/`:
|
||||||
|
- `PlexusX.exe`
|
||||||
|
- `PlexusX.dll` (alongside the copied dependencies from `libs/`)
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class AnimationClockPolicy
|
||||||
|
{
|
||||||
|
public static int IntervalFor(TimeSpan sinceLastInput, bool movingPicture)
|
||||||
|
{
|
||||||
|
if (!movingPicture && !(sinceLastInput < TimeSpan.FromSeconds(3.0)))
|
||||||
|
{
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
return 47;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ShouldRun(bool visible, bool minimized, bool movingOrSizing, bool goingAway, bool active)
|
||||||
|
{
|
||||||
|
return (visible && !minimized && !movingOrSizing && !goingAway) & active;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class AppFolders
|
||||||
|
{
|
||||||
|
public static string Roaming => For(Environment.SpecialFolder.ApplicationData, RootForTest ?? SecurityCandidate.StorageRoot, FlavourPolicy.Current.DataFolderName);
|
||||||
|
|
||||||
|
public static string Local => For(Environment.SpecialFolder.LocalApplicationData, RootForTest ?? SecurityCandidate.StorageRoot, FlavourPolicy.Current.DataFolderName);
|
||||||
|
|
||||||
|
public static string Pictures => For(Environment.SpecialFolder.MyPictures, RootForTest ?? SecurityCandidate.StorageRoot);
|
||||||
|
|
||||||
|
public static string TaskbarPins => PinnedIn(RootForTest ?? SecurityCandidate.StorageRoot);
|
||||||
|
|
||||||
|
internal static string? RootForTest { get; set; }
|
||||||
|
|
||||||
|
internal static string PinnedIn(string? root)
|
||||||
|
{
|
||||||
|
return Path.Combine((root == null) ? Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) : Path.Combine(root, Environment.SpecialFolder.ApplicationData.ToString()), "Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar");
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string For(Environment.SpecialFolder folder, string? root)
|
||||||
|
{
|
||||||
|
return For(folder, root, "PlexusX");
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string For(Environment.SpecialFolder folder, string? root, string folderName)
|
||||||
|
{
|
||||||
|
return Path.Combine((root == null) ? Environment.GetFolderPath(folder) : Path.Combine(root, folder.ToString()), folderName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class AppIcon
|
||||||
|
{
|
||||||
|
private static Icon? _icon;
|
||||||
|
|
||||||
|
public static Icon Value => _icon ?? (_icon = Load());
|
||||||
|
|
||||||
|
private static Icon Load()
|
||||||
|
{
|
||||||
|
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PlexusX.ico");
|
||||||
|
return (stream != null) ? new Icon(stream) : SystemIcons.Application;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class AppInfo
|
||||||
|
{
|
||||||
|
public const string ProductName = "PlexusX";
|
||||||
|
|
||||||
|
public const string Tagline = "Sharper colours. Every game.";
|
||||||
|
|
||||||
|
public const string DiscordUrl = "https://plexusx.lol/discord";
|
||||||
|
|
||||||
|
public const string SiteUrl = "https://plexusx.lol";
|
||||||
|
|
||||||
|
public const string PresetUploadUrl = "https://plexusx.lol/dashboard?tab=presets";
|
||||||
|
|
||||||
|
public const string SupportEmail = "[email protected]";
|
||||||
|
|
||||||
|
public static string VersionText => FormatVersion(UpdateService.CurrentVersion);
|
||||||
|
|
||||||
|
internal static string PresetReportUrl(string id)
|
||||||
|
{
|
||||||
|
return "https://plexusx.lol/presets?report=" + Uri.EscapeDataString(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string FormatVersion(Version v)
|
||||||
|
{
|
||||||
|
return $"v{v.Major}.{v.Minor}.{Math.Max(v.Build, 0)}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,562 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using VibranceHud.Capabilities;
|
||||||
|
using VibranceHud.Crosshair;
|
||||||
|
using VibranceHud.Customize;
|
||||||
|
using VibranceHud.DarkBoost;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public sealed class AppSettings
|
||||||
|
{
|
||||||
|
public sealed class PanelSettings
|
||||||
|
{
|
||||||
|
public int Index { get; set; }
|
||||||
|
|
||||||
|
public int Brightness { get; set; } = -1;
|
||||||
|
|
||||||
|
public int Contrast { get; set; } = -1;
|
||||||
|
|
||||||
|
public int LowBlue { get; set; } = -1;
|
||||||
|
|
||||||
|
public int RedGain { get; set; } = -1;
|
||||||
|
|
||||||
|
public int GreenGain { get; set; } = -1;
|
||||||
|
|
||||||
|
public string Key { get; set; } = "";
|
||||||
|
|
||||||
|
public bool PanelTouched { get; set; }
|
||||||
|
|
||||||
|
public int WroteBrightness { get; set; } = -1;
|
||||||
|
|
||||||
|
public int WroteContrast { get; set; } = -1;
|
||||||
|
|
||||||
|
public int WroteBlueGain { get; set; } = -1;
|
||||||
|
|
||||||
|
public int WroteRedGain { get; set; } = -1;
|
||||||
|
|
||||||
|
public int WroteGreenGain { get; set; } = -1;
|
||||||
|
|
||||||
|
public bool HasOriginals { get; set; }
|
||||||
|
|
||||||
|
public int OriginalBrightness { get; set; }
|
||||||
|
|
||||||
|
public int OriginalContrast { get; set; }
|
||||||
|
|
||||||
|
public int OriginalBlueGain { get; set; }
|
||||||
|
|
||||||
|
public int OriginalRedGain { get; set; }
|
||||||
|
|
||||||
|
public int OriginalGreenGain { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal const uint ZoomDefaultVirtualKey = 6u;
|
||||||
|
|
||||||
|
public int Level { get; set; } = 100;
|
||||||
|
|
||||||
|
public int? VibrancePercent { get; set; }
|
||||||
|
|
||||||
|
public int? SaturationPercent { get; set; }
|
||||||
|
|
||||||
|
public int ResolvedVibrance => VibrancePercent ?? Math.Min(Level, 100);
|
||||||
|
|
||||||
|
public int ResolvedSaturation
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int? saturationPercent = SaturationPercent;
|
||||||
|
if (!saturationPercent.HasValue)
|
||||||
|
{
|
||||||
|
if (Level <= 100)
|
||||||
|
{
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
return Level;
|
||||||
|
}
|
||||||
|
return saturationPercent.GetValueOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool VibranceChosenByUser { get; set; }
|
||||||
|
|
||||||
|
public int VibranceOwnershipVersion { get; set; }
|
||||||
|
|
||||||
|
public int? DriverVibranceWeLastWrote { get; set; }
|
||||||
|
|
||||||
|
public bool StartWithWindows { get; set; }
|
||||||
|
|
||||||
|
public bool KeepDesktopComposited { get; set; }
|
||||||
|
|
||||||
|
public bool LowLatencyResetDone { get; set; }
|
||||||
|
|
||||||
|
public bool CompositionKeeperDefaultOnDone { get; set; }
|
||||||
|
|
||||||
|
public bool CompositionKeeperDefaultOffDone { get; set; }
|
||||||
|
|
||||||
|
public int OpacityPercent { get; set; } = 100;
|
||||||
|
|
||||||
|
public bool LightTheme { get; set; }
|
||||||
|
|
||||||
|
public string ThemeName { get; set; } = "";
|
||||||
|
|
||||||
|
public string BackdropLookName { get; set; } = "";
|
||||||
|
|
||||||
|
public string AccessEndingWarnedFor { get; set; } = "";
|
||||||
|
|
||||||
|
public string OfflineNoticeShownFor { get; set; } = "";
|
||||||
|
|
||||||
|
public string ServerNoticeShownId { get; set; } = "";
|
||||||
|
|
||||||
|
public string ServerNoticeShownAt { get; set; } = "";
|
||||||
|
|
||||||
|
public string SignInBrowserPath { get; set; } = "";
|
||||||
|
|
||||||
|
public string SignInBrowserName { get; set; } = "";
|
||||||
|
|
||||||
|
public string SurfaceStyleName { get; set; } = "";
|
||||||
|
|
||||||
|
public string ChromeName { get; set; } = "";
|
||||||
|
|
||||||
|
public int ColourModeLookVersion { get; set; }
|
||||||
|
|
||||||
|
public int Hue { get; set; }
|
||||||
|
|
||||||
|
public int RedGain { get; set; } = 100;
|
||||||
|
|
||||||
|
public int GreenGain { get; set; } = 100;
|
||||||
|
|
||||||
|
public int BlueGain { get; set; } = 100;
|
||||||
|
|
||||||
|
public string TaskbarStyleName { get; set; } = "";
|
||||||
|
|
||||||
|
public uint TaskbarColorArgb { get; set; }
|
||||||
|
|
||||||
|
public bool TaskbarFollowsAccent { get; set; }
|
||||||
|
|
||||||
|
public int BrightnessPercent { get; set; } = 100;
|
||||||
|
|
||||||
|
public int GammaPercent { get; set; } = 100;
|
||||||
|
|
||||||
|
public int ContrastPercent { get; set; } = 100;
|
||||||
|
|
||||||
|
public int? Temperature { get; set; }
|
||||||
|
|
||||||
|
public bool EyeCare { get; set; }
|
||||||
|
|
||||||
|
public int ResolvedTemperature
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int? temperature = Temperature;
|
||||||
|
if (!temperature.HasValue)
|
||||||
|
{
|
||||||
|
if (!EyeCare)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
return temperature.GetValueOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColourVisionMode ColourVision { get; set; }
|
||||||
|
|
||||||
|
public bool ColourVisionFromPreset { get; set; }
|
||||||
|
|
||||||
|
public ColourVisionMode UserColourVision { get; set; }
|
||||||
|
|
||||||
|
public List<DisplayPreset> CustomPresets { get; set; } = new List<DisplayPreset>();
|
||||||
|
|
||||||
|
public OverlayMode OverlayMode { get; set; }
|
||||||
|
|
||||||
|
public DxInitFailureKind DxFailure { get; set; }
|
||||||
|
|
||||||
|
public string DxFailureMessage { get; set; } = "";
|
||||||
|
|
||||||
|
public int DxFailureCode { get; set; }
|
||||||
|
|
||||||
|
public bool QualityColour { get; set; }
|
||||||
|
|
||||||
|
public string CustomBackgroundFile { get; set; } = "";
|
||||||
|
|
||||||
|
public int CustomBackgroundDim { get; set; } = 40;
|
||||||
|
|
||||||
|
public int CustomBackgroundBlur { get; set; }
|
||||||
|
|
||||||
|
public int CustomBackgroundMatteArgb { get; set; }
|
||||||
|
|
||||||
|
public int SlateGuiOpacityPercent { get; set; }
|
||||||
|
|
||||||
|
public bool SlateMatteBlur { get; set; } = true;
|
||||||
|
|
||||||
|
public int CustomAccentArgb { get; set; }
|
||||||
|
|
||||||
|
public bool NightVisionOn { get; set; }
|
||||||
|
|
||||||
|
public bool DarkBoostBanRiskAccepted { get; set; }
|
||||||
|
|
||||||
|
public bool NightVisionCodeValidated { get; set; }
|
||||||
|
|
||||||
|
public uint NightVisionHotkeyModifierMask { get; set; }
|
||||||
|
|
||||||
|
public uint NightVisionHotkeyVirtualKey { get; set; }
|
||||||
|
|
||||||
|
public bool NightVisionHotkeyEnabled { get; set; }
|
||||||
|
|
||||||
|
public bool ZoomEnabled { get; set; }
|
||||||
|
|
||||||
|
public float ZoomLevel { get; set; } = 2f;
|
||||||
|
|
||||||
|
public uint ZoomHotkeyModifierMask { get; set; }
|
||||||
|
|
||||||
|
public uint ZoomHotkeyVirtualKey { get; set; }
|
||||||
|
|
||||||
|
public bool ZoomSmooth { get; set; } = true;
|
||||||
|
|
||||||
|
public bool ZoomSmoothEdges { get; set; }
|
||||||
|
|
||||||
|
public bool ZoomKeyDefaulted { get; set; }
|
||||||
|
|
||||||
|
public bool CrosshairEnabled { get; set; }
|
||||||
|
|
||||||
|
public CrosshairConfig ActiveCrosshair { get; set; } = new CrosshairConfig();
|
||||||
|
|
||||||
|
public List<CrosshairConfig> SavedCrosshairs { get; set; } = new List<CrosshairConfig>();
|
||||||
|
|
||||||
|
public List<string> FavouriteCrosshairs { get; set; } = new List<string>();
|
||||||
|
|
||||||
|
public string PendingUpdateInstaller { get; set; } = "";
|
||||||
|
|
||||||
|
public string PendingUpdateSha256 { get; set; } = "";
|
||||||
|
|
||||||
|
public string PendingUpdateSignedManifest { get; set; } = "";
|
||||||
|
|
||||||
|
public string PendingUpdateVersion { get; set; } = "";
|
||||||
|
|
||||||
|
public string UpdateRefusedSha256 { get; set; } = "";
|
||||||
|
|
||||||
|
public string UpdateRefusedAtUtc { get; set; } = "";
|
||||||
|
|
||||||
|
public string UpdateRefusedNoticedSha256 { get; set; } = "";
|
||||||
|
|
||||||
|
public string LastSeenVersion { get; set; } = "";
|
||||||
|
|
||||||
|
public bool OnboardingComplete { get; set; }
|
||||||
|
|
||||||
|
public bool ForcedResignInDone { get; set; }
|
||||||
|
|
||||||
|
public string MovedMachineNoticeShownFor { get; set; } = "";
|
||||||
|
|
||||||
|
public bool PlansShown { get; set; }
|
||||||
|
|
||||||
|
public string FavoriteGame { get; set; } = "";
|
||||||
|
|
||||||
|
public string CurrentGameId { get; set; } = "";
|
||||||
|
|
||||||
|
public string PendingGameOfferId { get; set; } = "";
|
||||||
|
|
||||||
|
public string PendingDisplayRestore { get; set; } = "";
|
||||||
|
|
||||||
|
public GameLookSnapshot? LookBeforeGame { get; set; }
|
||||||
|
|
||||||
|
public List<string> DeclinedGameOffers { get; set; } = new List<string>();
|
||||||
|
|
||||||
|
public List<MonitorRule> MonitorRules { get; set; } = new List<MonitorRule>();
|
||||||
|
|
||||||
|
public int RustResolutionWidth { get; set; }
|
||||||
|
|
||||||
|
public int RustResolutionHeight { get; set; }
|
||||||
|
|
||||||
|
public bool AudioEdgeEnabled { get; set; }
|
||||||
|
|
||||||
|
public int AudioEdgeThresholdPercent { get; set; } = 50;
|
||||||
|
|
||||||
|
public float AudioEdgeRestoreVolume { get; set; } = 1f;
|
||||||
|
|
||||||
|
public bool AudioEdgeRestorePending { get; set; }
|
||||||
|
|
||||||
|
public int NvapiRestoreLevel { get; set; } = -1;
|
||||||
|
|
||||||
|
public Dictionary<string, int> NvapiRestoreLevels { get; set; } = new Dictionary<string, int>();
|
||||||
|
|
||||||
|
public bool NvapiRestorePending { get; set; }
|
||||||
|
|
||||||
|
public bool GammaRestorePending { get; set; }
|
||||||
|
|
||||||
|
public int EyeCareWarmth { get; set; }
|
||||||
|
|
||||||
|
public int EyeCareDim { get; set; }
|
||||||
|
|
||||||
|
public uint HotkeyModifierMask { get; set; } = 3u;
|
||||||
|
|
||||||
|
public uint HotkeyVirtualKey { get; set; } = 86u;
|
||||||
|
|
||||||
|
public bool ScreenshotHotkeyEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
public uint ScreenshotHotkeyModifierMask { get; set; } = 3u;
|
||||||
|
|
||||||
|
public uint ScreenshotHotkeyVirtualKey { get; set; } = 83u;
|
||||||
|
|
||||||
|
public int VibranceScaleVersion { get; set; }
|
||||||
|
|
||||||
|
public bool StreamingMode { get; set; }
|
||||||
|
|
||||||
|
public bool CompetitiveMode { get; set; }
|
||||||
|
|
||||||
|
public bool MainHotkeyEnabled { get; set; }
|
||||||
|
|
||||||
|
public uint MainHotkeyModifierMask { get; set; } = 6u;
|
||||||
|
|
||||||
|
public uint MainHotkeyVirtualKey { get; set; } = 77u;
|
||||||
|
|
||||||
|
public List<PresetKeyBinding> PresetKeyBindings { get; set; } = new List<PresetKeyBinding>();
|
||||||
|
|
||||||
|
public List<MonitorColourSetting> MonitorColours { get; set; } = new List<MonitorColourSetting>();
|
||||||
|
|
||||||
|
public List<string>? SelectedMonitorIds { get; set; }
|
||||||
|
|
||||||
|
public List<string>? UntickedDeviceKeys { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<string, int>? OwnedMonitorVibrance { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<string, int>? OwnedMonitorVibranceLastWritten { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<string, ushort[]>? OwnedMonitorGamma { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public bool ManualOverrideActive { get; set; }
|
||||||
|
|
||||||
|
public int PopupX { get; set; } = int.MinValue;
|
||||||
|
|
||||||
|
public int PopupY { get; set; } = int.MinValue;
|
||||||
|
|
||||||
|
public int WindowX { get; set; }
|
||||||
|
|
||||||
|
public int WindowY { get; set; }
|
||||||
|
|
||||||
|
public int WindowWidth { get; set; }
|
||||||
|
|
||||||
|
public int WindowHeight { get; set; }
|
||||||
|
|
||||||
|
public bool WindowMaximized { get; set; }
|
||||||
|
|
||||||
|
public ToneSettings? Tone { get; set; }
|
||||||
|
|
||||||
|
public float[]? Mix { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public ChannelMix ResolvedMix => ChannelMix.FromArray(Mix);
|
||||||
|
|
||||||
|
public List<PanelSettings> Panels { get; set; } = new List<PanelSettings>();
|
||||||
|
|
||||||
|
public string ColourPresetGame { get; set; } = "";
|
||||||
|
|
||||||
|
public string ColourPresetName { get; set; } = "";
|
||||||
|
|
||||||
|
public bool ShowOnDiscord { get; set; } = true;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public ToneSettings ResolvedTone
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
ToneSettings toneSettings = Tone ?? ToneSettings.Neutral;
|
||||||
|
return toneSettings with
|
||||||
|
{
|
||||||
|
Gamma = GammaPercent
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomizationSettings Customization { get; set; } = new CustomizationSettings();
|
||||||
|
|
||||||
|
public SaturationMetric SaturationFormula { get; set; }
|
||||||
|
|
||||||
|
public int Darken { get; set; }
|
||||||
|
|
||||||
|
public int DarkenHue { get; set; } = 120;
|
||||||
|
|
||||||
|
public int HueTurn { get; set; }
|
||||||
|
|
||||||
|
public int HueTurnAmount { get; set; } = 100;
|
||||||
|
|
||||||
|
public int HueComplement { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public ColourDepth Depth
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new ColourDepth(SaturationFormula, Darken, DarkenHue, HueTurn, HueTurnAmount, HueComplement);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SaturationFormula = value.Formula;
|
||||||
|
Darken = value.Darken;
|
||||||
|
DarkenHue = value.DarkenHue;
|
||||||
|
HueTurn = value.HueTurn;
|
||||||
|
HueTurnAmount = value.HueTurnAmount;
|
||||||
|
HueComplement = value.HueComplement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MusicHotkeyEnabled { get; set; }
|
||||||
|
|
||||||
|
public uint MusicHotkeyModifierMask { get; set; } = 3u;
|
||||||
|
|
||||||
|
public uint MusicHotkeyVirtualKey { get; set; } = 80u;
|
||||||
|
|
||||||
|
public bool NightVisionHotkeyHold { get; set; }
|
||||||
|
|
||||||
|
public bool HotkeysOnlyInGames { get; set; } = true;
|
||||||
|
|
||||||
|
public List<DarkBoostSetup> DarkBoostSetups { get; set; } = new List<DarkBoostSetup> { VibranceHud.DarkBoost.DarkBoostSetups.Default };
|
||||||
|
|
||||||
|
public int DarkBoostSelected { get; set; }
|
||||||
|
|
||||||
|
public bool DarkBoostFade { get; set; } = true;
|
||||||
|
|
||||||
|
public uint DarkBoostNextKeyModifierMask { get; set; }
|
||||||
|
|
||||||
|
public uint DarkBoostNextKeyVirtualKey { get; set; }
|
||||||
|
|
||||||
|
public int? MusicMiniX { get; set; }
|
||||||
|
|
||||||
|
public int? MusicMiniY { get; set; }
|
||||||
|
|
||||||
|
public bool MusicPlayPauseHotkeyEnabled { get; set; }
|
||||||
|
|
||||||
|
public uint MusicPlayPauseHotkeyModifierMask { get; set; }
|
||||||
|
|
||||||
|
public uint MusicPlayPauseHotkeyVirtualKey { get; set; }
|
||||||
|
|
||||||
|
public bool MusicNextHotkeyEnabled { get; set; }
|
||||||
|
|
||||||
|
public uint MusicNextHotkeyModifierMask { get; set; }
|
||||||
|
|
||||||
|
public uint MusicNextHotkeyVirtualKey { get; set; }
|
||||||
|
|
||||||
|
public bool MusicPreviousHotkeyEnabled { get; set; }
|
||||||
|
|
||||||
|
public uint MusicPreviousHotkeyModifierMask { get; set; }
|
||||||
|
|
||||||
|
public uint MusicPreviousHotkeyVirtualKey { get; set; }
|
||||||
|
|
||||||
|
public GammaProbeMemory? GammaProbeMemory { get; set; }
|
||||||
|
|
||||||
|
public static void MigrateVibranceOwnership(AppSettings settings)
|
||||||
|
{
|
||||||
|
if (settings.VibranceOwnershipVersion < 1)
|
||||||
|
{
|
||||||
|
settings.VibranceChosenByUser = settings.VibrancePercent.HasValue || settings.Level != 100;
|
||||||
|
settings.VibranceOwnershipVersion = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool ApplyZoomKeyDefault(AppSettings settings)
|
||||||
|
{
|
||||||
|
if (settings.ZoomKeyDefaulted)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (settings.ZoomHotkeyVirtualKey == 0 && !ADarkBoostKeyIsTheZoomDefault(settings) && !HotkeyConflicts.Owner(settings, HotkeySlot.Zoom, 0u, 6u).HasValue)
|
||||||
|
{
|
||||||
|
settings.ZoomHotkeyModifierMask = 0u;
|
||||||
|
settings.ZoomHotkeyVirtualKey = 6u;
|
||||||
|
}
|
||||||
|
settings.ZoomKeyDefaulted = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool ADarkBoostKeyIsTheZoomDefault(AppSettings s)
|
||||||
|
{
|
||||||
|
if (s.NightVisionHotkeyVirtualKey != 6 || s.NightVisionHotkeyModifierMask != 0)
|
||||||
|
{
|
||||||
|
if (s.DarkBoostNextKeyVirtualKey == 6)
|
||||||
|
{
|
||||||
|
return s.DarkBoostNextKeyModifierMask == 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal bool HoldsTheNextSetupKey(uint mask, uint vk)
|
||||||
|
{
|
||||||
|
if (DarkBoostNextKeyVirtualKey == vk)
|
||||||
|
{
|
||||||
|
return DarkBoostNextKeyModifierMask == mask;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PanelSettings PanelFor(int index)
|
||||||
|
{
|
||||||
|
if (Panels == null)
|
||||||
|
{
|
||||||
|
List<PanelSettings> list = (Panels = new List<PanelSettings>());
|
||||||
|
}
|
||||||
|
PanelSettings panelSettings = Panels.FirstOrDefault((PanelSettings p) => p.Index == index);
|
||||||
|
if (panelSettings != null)
|
||||||
|
{
|
||||||
|
return panelSettings;
|
||||||
|
}
|
||||||
|
panelSettings = new PanelSettings
|
||||||
|
{
|
||||||
|
Index = index
|
||||||
|
};
|
||||||
|
Panels.Add(panelSettings);
|
||||||
|
return panelSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PanelSettings PanelFor(string key, int index, IReadOnlyCollection<string>? connectedKeys = null)
|
||||||
|
{
|
||||||
|
if (Panels == null)
|
||||||
|
{
|
||||||
|
List<PanelSettings> list = (Panels = new List<PanelSettings>());
|
||||||
|
}
|
||||||
|
PanelSettings panelSettings = Panels.FirstOrDefault((PanelSettings p) => p.Key == key);
|
||||||
|
if (panelSettings != null)
|
||||||
|
{
|
||||||
|
panelSettings.Index = index;
|
||||||
|
return panelSettings;
|
||||||
|
}
|
||||||
|
string desc = Desc(key);
|
||||||
|
if (desc.Length > 0 && connectedKeys != null && Enumerable.Count(connectedKeys, (string k) => Desc(k) == desc) <= 1)
|
||||||
|
{
|
||||||
|
List<PanelSettings> list3 = Panels.Where((PanelSettings p) => p.Key.Length > 0 && Desc(p.Key) == desc && !connectedKeys.Contains(p.Key)).ToList();
|
||||||
|
if (list3.Count == 1)
|
||||||
|
{
|
||||||
|
PanelSettings panelSettings2 = list3[0];
|
||||||
|
panelSettings2.Key = key;
|
||||||
|
panelSettings2.Index = index;
|
||||||
|
return panelSettings2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PanelSettings panelSettings3 = Panels.FirstOrDefault((PanelSettings p) => p.Key.Length == 0 && p.Index == index);
|
||||||
|
if (panelSettings3 != null)
|
||||||
|
{
|
||||||
|
panelSettings3.Key = key;
|
||||||
|
return panelSettings3;
|
||||||
|
}
|
||||||
|
PanelSettings panelSettings4 = new PanelSettings
|
||||||
|
{
|
||||||
|
Index = index,
|
||||||
|
Key = key
|
||||||
|
};
|
||||||
|
Panels.Add(panelSettings4);
|
||||||
|
return panelSettings4;
|
||||||
|
static string Desc(string k)
|
||||||
|
{
|
||||||
|
int num = k.LastIndexOf('|');
|
||||||
|
if (num < 0)
|
||||||
|
{
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
return k.Substring(num + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public sealed class AppStatus
|
||||||
|
{
|
||||||
|
public Version? MinimumVersion { get; init; }
|
||||||
|
|
||||||
|
public IReadOnlyList<string> BlockedFlavours { get; init; } = Array.Empty<string>();
|
||||||
|
|
||||||
|
public string Message { get; init; } = "";
|
||||||
|
|
||||||
|
public string MessageId { get; init; } = "";
|
||||||
|
|
||||||
|
public string MessageUrl { get; init; } = "";
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using VibranceHud.Licensing;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class AppStatusService
|
||||||
|
{
|
||||||
|
private static string StatusUrl => ActivationEndpoint.StatusUrlFor("store");
|
||||||
|
|
||||||
|
private static string CacheDir => AppFolders.Local;
|
||||||
|
|
||||||
|
private static string CachePath => Path.Combine(CacheDir, "app-status-cache.json");
|
||||||
|
|
||||||
|
public static AppStatus? LastFetched { get; private set; }
|
||||||
|
|
||||||
|
private static AppStatus ReadCache()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!File.Exists(CachePath))
|
||||||
|
{
|
||||||
|
return new AppStatus();
|
||||||
|
}
|
||||||
|
return VersionGate.Parse(File.ReadAllText(CachePath));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return new AppStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Version? CachedMinimum()
|
||||||
|
{
|
||||||
|
return ReadCache().MinimumVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IReadOnlyList<string> CachedBlockedFlavours()
|
||||||
|
{
|
||||||
|
return ReadCache().BlockedFlavours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string CachedMessage()
|
||||||
|
{
|
||||||
|
return ReadCache().Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ThisBuildIsBlocked()
|
||||||
|
{
|
||||||
|
AppStatus appStatus = ReadCache();
|
||||||
|
return VersionGate.IsBlocked(UpdateService.CurrentVersion, appStatus.MinimumVersion, "store", appStatus.BlockedFlavours);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ThisBuildIsBlockedByVersion()
|
||||||
|
{
|
||||||
|
return VersionGate.IsBlocked(UpdateService.CurrentVersion, ReadCache().MinimumVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<Version?> RefreshAsync()
|
||||||
|
{
|
||||||
|
AppStatus cache = ReadCache();
|
||||||
|
Version cached = cache.MinimumVersion;
|
||||||
|
Version fetched = null;
|
||||||
|
IReadOnlyList<string> fetchedFlavours = Array.Empty<string>();
|
||||||
|
string message = "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using HttpClient client = new HttpClient
|
||||||
|
{
|
||||||
|
Timeout = TimeSpan.FromSeconds(10.0)
|
||||||
|
};
|
||||||
|
client.DefaultRequestHeaders.UserAgent.ParseAdd(UpdateService.UpdaterUserAgent);
|
||||||
|
AppStatus appStatus = VersionGate.Parse(await client.GetStringAsync(StatusUrl));
|
||||||
|
fetched = appStatus.MinimumVersion;
|
||||||
|
fetchedFlavours = appStatus.BlockedFlavours;
|
||||||
|
message = appStatus.Message;
|
||||||
|
LastFetched = appStatus;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Version version = VersionGate.Resolve(fetched, cached);
|
||||||
|
IReadOnlyList<string> readOnlyList = VersionGate.ResolveFlavours(fetchedFlavours, cache.BlockedFlavours);
|
||||||
|
bool num = version != null && (cached == null || version > cached);
|
||||||
|
bool flag = readOnlyList.Count > cache.BlockedFlavours.Count;
|
||||||
|
if (num | flag)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(CacheDir);
|
||||||
|
File.WriteAllText(CachePath, VersionGate.Serialize(version, message, readOnlyList));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace VibranceHud.Audio;
|
||||||
|
|
||||||
|
public sealed class AudioEdgeService : IDisposable
|
||||||
|
{
|
||||||
|
public enum MeterState
|
||||||
|
{
|
||||||
|
Off,
|
||||||
|
NoReading,
|
||||||
|
Holding,
|
||||||
|
Clear
|
||||||
|
}
|
||||||
|
|
||||||
|
public const int TickMs = 30;
|
||||||
|
|
||||||
|
public const float ExternalChangeTolerance = 0.001f;
|
||||||
|
|
||||||
|
public const int HoldTicks = 20;
|
||||||
|
|
||||||
|
public const float WriteEpsilon = 0.002f;
|
||||||
|
|
||||||
|
private readonly IAudioOutput _output;
|
||||||
|
|
||||||
|
private CancellationTokenSource? _cts;
|
||||||
|
|
||||||
|
private float _restoreVolume = 1f;
|
||||||
|
|
||||||
|
private float _lastWritten = float.NaN;
|
||||||
|
|
||||||
|
private readonly float[] _recentPeaks = new float[20];
|
||||||
|
|
||||||
|
private int _nextPeak;
|
||||||
|
|
||||||
|
internal int WriteCount { get; private set; }
|
||||||
|
|
||||||
|
public float Threshold { get; set; } = 0.3f;
|
||||||
|
|
||||||
|
public bool IsRunning => _cts != null;
|
||||||
|
|
||||||
|
public float Peak => _output.Peak;
|
||||||
|
|
||||||
|
public float CurrentVolume => _output.Volume;
|
||||||
|
|
||||||
|
public float RestoreVolume => _restoreVolume;
|
||||||
|
|
||||||
|
public MeterState Meter
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!IsRunning)
|
||||||
|
{
|
||||||
|
return MeterState.Off;
|
||||||
|
}
|
||||||
|
float currentVolume = CurrentVolume;
|
||||||
|
float restoreVolume = _restoreVolume;
|
||||||
|
if (float.IsNaN(currentVolume) || float.IsNaN(restoreVolume))
|
||||||
|
{
|
||||||
|
return MeterState.NoReading;
|
||||||
|
}
|
||||||
|
if (!(currentVolume < restoreVolume - 0.01f))
|
||||||
|
{
|
||||||
|
return MeterState.Clear;
|
||||||
|
}
|
||||||
|
return MeterState.Holding;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event Action<float>? OnRestorePointCaptured;
|
||||||
|
|
||||||
|
public event Action? OnRestoreCompleted;
|
||||||
|
|
||||||
|
public AudioEdgeService(IAudioOutput output)
|
||||||
|
{
|
||||||
|
_output = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
Start(runLoop: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void StartWithoutLoopForTest()
|
||||||
|
{
|
||||||
|
Start(runLoop: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start(bool runLoop)
|
||||||
|
{
|
||||||
|
if (IsRunning)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
float f = (_restoreVolume = _output.Volume);
|
||||||
|
_lastWritten = float.NaN;
|
||||||
|
Array.Clear(_recentPeaks);
|
||||||
|
_nextPeak = 0;
|
||||||
|
if (!float.IsNaN(f))
|
||||||
|
{
|
||||||
|
OnRestorePointCaptured?.Invoke(_restoreVolume);
|
||||||
|
}
|
||||||
|
_cts = new CancellationTokenSource();
|
||||||
|
CancellationToken token = _cts.Token;
|
||||||
|
if (!runLoop)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (!token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
Tick();
|
||||||
|
await Task.Delay(30, token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (!float.IsNaN(_restoreVolume))
|
||||||
|
{
|
||||||
|
_output.Volume = _restoreVolume;
|
||||||
|
}
|
||||||
|
OnRestoreCompleted?.Invoke();
|
||||||
|
}
|
||||||
|
}, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ForceRestore(float volume)
|
||||||
|
{
|
||||||
|
_output.Volume = Math.Clamp(volume, 0f, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick()
|
||||||
|
{
|
||||||
|
float volume = _output.Volume;
|
||||||
|
if (float.IsNaN(volume))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (float.IsNaN(_restoreVolume))
|
||||||
|
{
|
||||||
|
_restoreVolume = volume;
|
||||||
|
_lastWritten = float.NaN;
|
||||||
|
OnRestorePointCaptured?.Invoke(_restoreVolume);
|
||||||
|
}
|
||||||
|
if (!float.IsNaN(_lastWritten))
|
||||||
|
{
|
||||||
|
float num = volume - _lastWritten;
|
||||||
|
if (MathF.Abs(num) > 0.001f)
|
||||||
|
{
|
||||||
|
_restoreVolume = Math.Clamp(_restoreVolume + num, 0.05f, 1f);
|
||||||
|
OnRestorePointCaptured?.Invoke(_restoreVolume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_recentPeaks[_nextPeak] = _output.Peak;
|
||||||
|
_nextPeak = (_nextPeak + 1) % _recentPeaks.Length;
|
||||||
|
float num2 = 0f;
|
||||||
|
float[] recentPeaks = _recentPeaks;
|
||||||
|
foreach (float y in recentPeaks)
|
||||||
|
{
|
||||||
|
num2 = MathF.Max(num2, y);
|
||||||
|
}
|
||||||
|
float num3 = AudioLimiter.NextVolume(num2, Threshold, volume, _restoreVolume);
|
||||||
|
if (MathF.Abs(num3 - volume) > 0.002f)
|
||||||
|
{
|
||||||
|
float volume2 = _output.Volume;
|
||||||
|
if (!float.IsNaN(volume2))
|
||||||
|
{
|
||||||
|
if (MathF.Abs(volume2 - volume) > 0.001f)
|
||||||
|
{
|
||||||
|
_restoreVolume = Math.Clamp(_restoreVolume + (volume2 - volume), 0.05f, 1f);
|
||||||
|
_lastWritten = volume2;
|
||||||
|
OnRestorePointCaptured?.Invoke(_restoreVolume);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_output.Volume = num3;
|
||||||
|
_lastWritten = _output.Volume;
|
||||||
|
WriteCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_lastWritten = volume;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
CancellationTokenSource cts = _cts;
|
||||||
|
_cts = null;
|
||||||
|
if (cts != null)
|
||||||
|
{
|
||||||
|
cts.Cancel();
|
||||||
|
cts.Dispose();
|
||||||
|
if (!float.IsNaN(_restoreVolume))
|
||||||
|
{
|
||||||
|
_output.Volume = _restoreVolume;
|
||||||
|
}
|
||||||
|
_lastWritten = float.NaN;
|
||||||
|
OnRestoreCompleted?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
(_output as IDisposable)?.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace VibranceHud.Audio;
|
||||||
|
|
||||||
|
public static class AudioLimiter
|
||||||
|
{
|
||||||
|
public const float MinVolume = 0.05f;
|
||||||
|
|
||||||
|
public const float DefaultAttack = 0.5f;
|
||||||
|
|
||||||
|
public const float DefaultRelease = 0.3f;
|
||||||
|
|
||||||
|
public static float NextVolume(float peak, float threshold, float currentVolume, float maxVolume, float attack = 0.5f, float release = 0.3f)
|
||||||
|
{
|
||||||
|
float num = ((peak > 0.0001f) ? MathF.Min(maxVolume, threshold / peak) : maxVolume);
|
||||||
|
float num2 = ((num < currentVolume) ? attack : release);
|
||||||
|
return Math.Clamp(currentVolume + (num - currentVolume) * num2, 0.05f, maxVolume);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace VibranceHud.Audio;
|
||||||
|
|
||||||
|
internal static class AudioLoopDiagnostic
|
||||||
|
{
|
||||||
|
public static void RunAndPrint()
|
||||||
|
{
|
||||||
|
using WindowsAudioOutput windowsAudioOutput = new WindowsAudioOutput();
|
||||||
|
float volume = windowsAudioOutput.Volume;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
float[] array = new float[3] { 1f, 0.5f, 0.25f };
|
||||||
|
for (int i = 0; i < array.Length; i++)
|
||||||
|
{
|
||||||
|
float value = (windowsAudioOutput.Volume = array[i]);
|
||||||
|
Thread.Sleep(500);
|
||||||
|
Console.WriteLine($"Volume {value:P0} -> Peak {windowsAudioOutput.Peak:F3}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
windowsAudioOutput.Volume = volume;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace VibranceHud.Audio;
|
||||||
|
|
||||||
|
public interface IAudioOutput
|
||||||
|
{
|
||||||
|
float Peak { get; }
|
||||||
|
|
||||||
|
float Volume { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace VibranceHud.Audio;
|
||||||
|
|
||||||
|
internal sealed class RestorePointSaver
|
||||||
|
{
|
||||||
|
private readonly Action _save;
|
||||||
|
|
||||||
|
private readonly int _quietMs;
|
||||||
|
|
||||||
|
private readonly Func<int, Action, IDisposable> _startTimer;
|
||||||
|
|
||||||
|
private readonly object _gate = new object();
|
||||||
|
|
||||||
|
private IDisposable? _timer;
|
||||||
|
|
||||||
|
private int _generation;
|
||||||
|
|
||||||
|
private bool _dirty;
|
||||||
|
|
||||||
|
public RestorePointSaver(Action save, int quietMs = 400, Func<int, Action, IDisposable>? startTimer = null)
|
||||||
|
{
|
||||||
|
_save = save;
|
||||||
|
_quietMs = quietMs;
|
||||||
|
_startTimer = startTimer ?? new Func<int, Action, IDisposable>(DefaultTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Captured(float volume, AppSettings settings)
|
||||||
|
{
|
||||||
|
lock (_gate)
|
||||||
|
{
|
||||||
|
settings.AudioEdgeRestoreVolume = volume;
|
||||||
|
if (!settings.AudioEdgeRestorePending)
|
||||||
|
{
|
||||||
|
settings.AudioEdgeRestorePending = true;
|
||||||
|
CancelTimer();
|
||||||
|
_dirty = false;
|
||||||
|
_save();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_dirty = true;
|
||||||
|
if (_timer == null)
|
||||||
|
{
|
||||||
|
CancelTimer();
|
||||||
|
int gen = _generation;
|
||||||
|
_timer = _startTimer(_quietMs, () =>
|
||||||
|
{
|
||||||
|
OnDue(gen);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Completed(AppSettings settings)
|
||||||
|
{
|
||||||
|
lock (_gate)
|
||||||
|
{
|
||||||
|
CancelTimer();
|
||||||
|
_dirty = false;
|
||||||
|
settings.AudioEdgeRestorePending = false;
|
||||||
|
_save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Flush()
|
||||||
|
{
|
||||||
|
lock (_gate)
|
||||||
|
{
|
||||||
|
CancelTimer();
|
||||||
|
if (_dirty)
|
||||||
|
{
|
||||||
|
_dirty = false;
|
||||||
|
_save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDue(int generation)
|
||||||
|
{
|
||||||
|
lock (_gate)
|
||||||
|
{
|
||||||
|
if (generation == _generation)
|
||||||
|
{
|
||||||
|
_timer?.Dispose();
|
||||||
|
_timer = null;
|
||||||
|
if (_dirty)
|
||||||
|
{
|
||||||
|
_dirty = false;
|
||||||
|
_save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CancelTimer()
|
||||||
|
{
|
||||||
|
_generation++;
|
||||||
|
_timer?.Dispose();
|
||||||
|
_timer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IDisposable DefaultTimer(int delayMs, Action callback)
|
||||||
|
{
|
||||||
|
return new Timer((object? _) =>
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
}, null, delayMs, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace VibranceHud.Audio;
|
||||||
|
|
||||||
|
public sealed class WindowsAudioOutput : IAudioOutput, IDisposable
|
||||||
|
{
|
||||||
|
[ComImport]
|
||||||
|
[Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")]
|
||||||
|
private class MMDeviceEnumerator
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComImport]
|
||||||
|
[Guid("A95664D2-9614-4F35-A746-DE8DB63617E6")]
|
||||||
|
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||||
|
private interface IMMDeviceEnumerator
|
||||||
|
{
|
||||||
|
[PreserveSig]
|
||||||
|
int EnumAudioEndpoints(int dataFlow, int stateMask, out nint devices);
|
||||||
|
|
||||||
|
[PreserveSig]
|
||||||
|
int GetDefaultAudioEndpoint(int dataFlow, int role, out IMMDevice device);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComImport]
|
||||||
|
[Guid("D666063F-1587-4E43-81F1-B948E807363F")]
|
||||||
|
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||||
|
private interface IMMDevice
|
||||||
|
{
|
||||||
|
[PreserveSig]
|
||||||
|
int Activate(ref Guid iid, int clsCtx, nint activationParams, [MarshalAs(UnmanagedType.IUnknown)] out object iface);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComImport]
|
||||||
|
[Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064")]
|
||||||
|
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||||
|
private interface IAudioMeterInformation
|
||||||
|
{
|
||||||
|
[PreserveSig]
|
||||||
|
int GetPeakValue(out float peak);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComImport]
|
||||||
|
[Guid("5CDF2C82-841E-4546-9722-0CF74078229A")]
|
||||||
|
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||||
|
private interface IAudioEndpointVolume
|
||||||
|
{
|
||||||
|
[PreserveSig]
|
||||||
|
int RegisterControlChangeNotify(nint notify);
|
||||||
|
|
||||||
|
[PreserveSig]
|
||||||
|
int UnregisterControlChangeNotify(nint notify);
|
||||||
|
|
||||||
|
[PreserveSig]
|
||||||
|
int GetChannelCount(out uint count);
|
||||||
|
|
||||||
|
[PreserveSig]
|
||||||
|
int SetMasterVolumeLevel(float level, ref Guid eventContext);
|
||||||
|
|
||||||
|
[PreserveSig]
|
||||||
|
int SetMasterVolumeLevelScalar(float level, ref Guid eventContext);
|
||||||
|
|
||||||
|
[PreserveSig]
|
||||||
|
int GetMasterVolumeLevel(out float level);
|
||||||
|
|
||||||
|
[PreserveSig]
|
||||||
|
int GetMasterVolumeLevelScalar(out float level);
|
||||||
|
}
|
||||||
|
|
||||||
|
private const int ERender = 0;
|
||||||
|
|
||||||
|
private const int EConsole = 0;
|
||||||
|
|
||||||
|
private const int ClsCtxAll = 23;
|
||||||
|
|
||||||
|
private static Guid _meterIid = new Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064");
|
||||||
|
|
||||||
|
private static Guid _volumeIid = new Guid("5CDF2C82-841E-4546-9722-0CF74078229A");
|
||||||
|
|
||||||
|
private static Guid _noEvent = Guid.Empty;
|
||||||
|
|
||||||
|
private readonly IAudioMeterInformation _meter;
|
||||||
|
|
||||||
|
private readonly IAudioEndpointVolume _volume;
|
||||||
|
|
||||||
|
public float Peak
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
float peak;
|
||||||
|
return (_meter.GetPeakValue(out peak) == 0) ? peak : 0f;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Volume
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
float level;
|
||||||
|
return (_volume.GetMasterVolumeLevelScalar(out level) == 0) ? level : float.NaN;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return float.NaN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_volume.SetMasterVolumeLevelScalar(Math.Clamp(value, 0f, 1f), ref _noEvent);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowsAudioOutput()
|
||||||
|
{
|
||||||
|
Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)new MMDeviceEnumerator()).GetDefaultAudioEndpoint(0, 0, out IMMDevice device));
|
||||||
|
Marshal.ThrowExceptionForHR(device.Activate(ref _meterIid, 23, IntPtr.Zero, out object iface));
|
||||||
|
Marshal.ThrowExceptionForHR(device.Activate(ref _volumeIid, 23, IntPtr.Zero, out object iface2));
|
||||||
|
_meter = (IAudioMeterInformation)iface;
|
||||||
|
_volume = (IAudioEndpointVolume)iface2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (Marshal.IsComObject(_meter))
|
||||||
|
{
|
||||||
|
Marshal.ReleaseComObject(_meter);
|
||||||
|
}
|
||||||
|
if (Marshal.IsComObject(_volume))
|
||||||
|
{
|
||||||
|
Marshal.ReleaseComObject(_volume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using VibranceHud.Updates;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public sealed class BackgroundUpdateChecker : IDisposable
|
||||||
|
{
|
||||||
|
internal const int CheckIntervalMs = 7200000;
|
||||||
|
|
||||||
|
private readonly AppSettings _settings;
|
||||||
|
|
||||||
|
private readonly SettingsStore _store;
|
||||||
|
|
||||||
|
private readonly NotifyIcon _trayIcon;
|
||||||
|
|
||||||
|
private readonly System.Windows.Forms.Timer _timer;
|
||||||
|
|
||||||
|
private readonly Task? _startupUpdateStep;
|
||||||
|
|
||||||
|
private bool _isRunning;
|
||||||
|
|
||||||
|
private int _ticksBegun;
|
||||||
|
|
||||||
|
private int _manifestChecks;
|
||||||
|
|
||||||
|
internal int TicksBegun => Volatile.Read(in _ticksBegun);
|
||||||
|
|
||||||
|
internal int ManifestChecks => Volatile.Read(in _manifestChecks);
|
||||||
|
|
||||||
|
internal Func<bool> SafeNowCheck { get; set; } = SafeToRestart.IsNow;
|
||||||
|
|
||||||
|
internal static bool ShouldTick(FlavourPolicy policy)
|
||||||
|
{
|
||||||
|
return policy.SelfUpdates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BackgroundUpdateChecker(AppSettings settings, SettingsStore store, NotifyIcon trayIcon, Task? startupUpdateStep = null)
|
||||||
|
{
|
||||||
|
_settings = settings;
|
||||||
|
_store = store;
|
||||||
|
_trayIcon = trayIcon;
|
||||||
|
_startupUpdateStep = startupUpdateStep;
|
||||||
|
_timer = new System.Windows.Forms.Timer
|
||||||
|
{
|
||||||
|
Interval = 7200000
|
||||||
|
};
|
||||||
|
_timer.Tick += async (object? s, EventArgs e) =>
|
||||||
|
{
|
||||||
|
await TickAsync();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
_timer.Start();
|
||||||
|
FirstTickAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal async Task FirstTickAsync()
|
||||||
|
{
|
||||||
|
await Task.Delay(3000);
|
||||||
|
if (_startupUpdateStep != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _startupUpdateStep;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await TickAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task TickAsync()
|
||||||
|
{
|
||||||
|
Interlocked.Increment(ref _ticksBegun);
|
||||||
|
if (!ShouldTick(FlavourPolicy.Current) || _isRunning)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_isRunning = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!RemoteSwitches.IsOn("updates") || UpdateService.InstallerStartedThisRun)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(_settings.PendingUpdateVersion))
|
||||||
|
{
|
||||||
|
await InstallIfNobodyIsBusyAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Interlocked.Increment(ref _manifestChecks);
|
||||||
|
ReleaseInfo release = RefusedUpdate.Unless(release: await UpdateService.TryGetSignedUpdateAsync(), settings: _settings);
|
||||||
|
if (!(release == null) && SafeNowCheck())
|
||||||
|
{
|
||||||
|
string text = await UpdateService.DownloadAndStageAsync(release);
|
||||||
|
if (!string.IsNullOrWhiteSpace(text))
|
||||||
|
{
|
||||||
|
UpdateService.RecordPending?.Invoke(release, text);
|
||||||
|
await InstallIfNobodyIsBusyAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isRunning = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task InstallIfNobodyIsBusyAsync()
|
||||||
|
{
|
||||||
|
if (!SafeNowCheck())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string refusedBefore = _settings.UpdateRefusedSha256 + "|" + _settings.UpdateRefusedNoticedSha256;
|
||||||
|
await UpdateService.RunPendingUpdateIfAnyAsync(_settings);
|
||||||
|
if (!(refusedBefore != _settings.UpdateRefusedSha256 + "|" + _settings.UpdateRefusedNoticedSha256))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_store.Save(_settings);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Task TickForTest()
|
||||||
|
{
|
||||||
|
return TickAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_timer.Stop();
|
||||||
|
_timer.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class BrandAssets
|
||||||
|
{
|
||||||
|
private static readonly Dictionary<string, Image?> _cache = new Dictionary<string, Image>();
|
||||||
|
|
||||||
|
private static readonly object _gate = new object();
|
||||||
|
|
||||||
|
public static readonly object DrawGate = new object();
|
||||||
|
|
||||||
|
public static string LogoResourceName(bool light)
|
||||||
|
{
|
||||||
|
if (!light)
|
||||||
|
{
|
||||||
|
return "logo-horizontal-white.png";
|
||||||
|
}
|
||||||
|
return "logo-horizontal-black.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Image? HorizontalLogo(bool light)
|
||||||
|
{
|
||||||
|
return Load(LogoResourceName(light));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Image? PresetChip(string art)
|
||||||
|
{
|
||||||
|
return Load("preset-" + art + ".png");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Image? Load(string resourceName)
|
||||||
|
{
|
||||||
|
lock (_gate)
|
||||||
|
{
|
||||||
|
if (_cache.TryGetValue(resourceName, out Image value))
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
Image image = null;
|
||||||
|
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
|
||||||
|
{
|
||||||
|
if (stream != null)
|
||||||
|
{
|
||||||
|
using Image original = Image.FromStream(stream);
|
||||||
|
image = new Bitmap(original);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (image != null)
|
||||||
|
{
|
||||||
|
_cache[resourceName] = image;
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class BuildFlavour
|
||||||
|
{
|
||||||
|
public const string Public = "public";
|
||||||
|
|
||||||
|
public const string NightVision = "nightvision";
|
||||||
|
|
||||||
|
public const string NightVisionGift = "nightvision-gift";
|
||||||
|
|
||||||
|
public const string Store = "store";
|
||||||
|
|
||||||
|
public const string Current = "store";
|
||||||
|
}
|
||||||
@@ -0,0 +1,448 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Security.Principal;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public static class CapabilityProbe
|
||||||
|
{
|
||||||
|
private sealed class PerDeviceGammaTarget : IPerDeviceGammaProbeTarget
|
||||||
|
{
|
||||||
|
public IReadOnlyList<string> Devices()
|
||||||
|
{
|
||||||
|
return MultiMonitorGammaRamp.Devices();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TrySet(string device, ushort[] ramp)
|
||||||
|
{
|
||||||
|
return MultiMonitorGammaRamp.SetRampOn(device, ramp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ushort[]? TryGet(string device)
|
||||||
|
{
|
||||||
|
return MultiMonitorGammaRamp.ReadRampOn(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct POINT
|
||||||
|
{
|
||||||
|
public int X;
|
||||||
|
|
||||||
|
public int Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class ScreenGammaTarget : IGammaProbeTarget
|
||||||
|
{
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern nint GetDC(nint hWnd);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern int ReleaseDC(nint hWnd, nint hDC);
|
||||||
|
|
||||||
|
[DllImport("gdi32.dll")]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
private static extern bool SetDeviceGammaRamp(nint hDC, ushort[] ramp);
|
||||||
|
|
||||||
|
[DllImport("gdi32.dll")]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
private static extern bool GetDeviceGammaRamp(nint hDC, ushort[] ramp);
|
||||||
|
|
||||||
|
public bool TrySet(ushort[] ramp)
|
||||||
|
{
|
||||||
|
nint dC = GetDC(IntPtr.Zero);
|
||||||
|
if (dC == IntPtr.Zero)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SetDeviceGammaRamp(dC, ramp);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ReleaseDC(IntPtr.Zero, dC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ushort[]? TryGet()
|
||||||
|
{
|
||||||
|
nint dC = GetDC(IntPtr.Zero);
|
||||||
|
if (dC == IntPtr.Zero)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ushort[] array = new ushort[768];
|
||||||
|
return GetDeviceGammaRamp(dC, array) ? array : null;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ReleaseDC(IntPtr.Zero, dC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal const int SameCurveTolerance = 512;
|
||||||
|
|
||||||
|
internal const float TestGamma = 6f;
|
||||||
|
|
||||||
|
private const int MONITOR_DEFAULTTONEAREST = 2;
|
||||||
|
|
||||||
|
internal static GammaSupport Classify(ushort[] written, ushort[]? readback, ushort[] identity)
|
||||||
|
{
|
||||||
|
if (readback == null || written.Length == 0 || readback.Length != written.Length)
|
||||||
|
{
|
||||||
|
return GammaSupport.Untested;
|
||||||
|
}
|
||||||
|
double num = MeanAbsoluteDifference(readback, written);
|
||||||
|
double num2 = MeanAbsoluteDifference(readback, identity);
|
||||||
|
if (num <= 512.0)
|
||||||
|
{
|
||||||
|
return GammaSupport.Working;
|
||||||
|
}
|
||||||
|
if (num2 <= 512.0)
|
||||||
|
{
|
||||||
|
return GammaSupport.Refused;
|
||||||
|
}
|
||||||
|
return GammaSupport.Clamped;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double MeanAbsoluteDifference(ushort[] a, ushort[] b)
|
||||||
|
{
|
||||||
|
long num = 0L;
|
||||||
|
for (int i = 0; i < a.Length; i++)
|
||||||
|
{
|
||||||
|
num += Math.Abs(a[i] - b[i]);
|
||||||
|
}
|
||||||
|
return (double)num / (double)a.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static GammaRefusal WhyRefused(GammaSupport result, bool writeAccepted, bool elevated, bool hdrActive, ushort[]? before, ushort[] identity)
|
||||||
|
{
|
||||||
|
if (result != GammaSupport.Refused)
|
||||||
|
{
|
||||||
|
return GammaRefusal.None;
|
||||||
|
}
|
||||||
|
if (hdrActive)
|
||||||
|
{
|
||||||
|
return GammaRefusal.HdrOn;
|
||||||
|
}
|
||||||
|
if (!elevated)
|
||||||
|
{
|
||||||
|
return GammaRefusal.NotElevated;
|
||||||
|
}
|
||||||
|
if (!writeAccepted)
|
||||||
|
{
|
||||||
|
return GammaRefusal.WriteFailed;
|
||||||
|
}
|
||||||
|
if (before != null && before.Length == identity.Length && MeanAbsoluteDifference(before, identity) > 512.0)
|
||||||
|
{
|
||||||
|
return GammaRefusal.RampHeldByOther;
|
||||||
|
}
|
||||||
|
return GammaRefusal.ReadbackIdentity;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static ushort[] TestRamp()
|
||||||
|
{
|
||||||
|
return GammaCurve.Build(6f);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static ushort[] GentleRamp()
|
||||||
|
{
|
||||||
|
return GammaCurve.Build(1.15f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool GentleGetsThrough(Func<ushort[], bool> trySet, Func<ushort[]?> tryGet)
|
||||||
|
{
|
||||||
|
ushort[] array = GentleRamp();
|
||||||
|
if (trySet(array))
|
||||||
|
{
|
||||||
|
return Classify(array, tryGet(), GammaCurve.Identity()) == GammaSupport.Working;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static GammaSupport ProbeGamma(IGammaProbeTarget target)
|
||||||
|
{
|
||||||
|
bool couldRead;
|
||||||
|
return ProbeGamma(target, out couldRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static GammaSupport ProbeGamma(IGammaProbeTarget target, out bool couldRead)
|
||||||
|
{
|
||||||
|
couldRead = false;
|
||||||
|
if (target == null)
|
||||||
|
{
|
||||||
|
return GammaSupport.Untested;
|
||||||
|
}
|
||||||
|
ushort[] array = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
array = target.TryGet();
|
||||||
|
couldRead = array != null;
|
||||||
|
if (array == null)
|
||||||
|
{
|
||||||
|
return GammaSupport.Refused;
|
||||||
|
}
|
||||||
|
ushort[] array2 = TestRamp();
|
||||||
|
GammaSupport gammaSupport = (target.TrySet(array2) ? Classify(array2, target.TryGet(), GammaCurve.Identity()) : GammaSupport.Refused);
|
||||||
|
if (gammaSupport == GammaSupport.Refused && GentleGetsThrough(target.TrySet, target.TryGet))
|
||||||
|
{
|
||||||
|
return GammaSupport.Clamped;
|
||||||
|
}
|
||||||
|
return gammaSupport;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return GammaSupport.Untested;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (array != null)
|
||||||
|
{
|
||||||
|
target.TrySet(array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static IReadOnlyList<DeviceGamma> ProbeDevices(IPerDeviceGammaProbeTarget target, bool elevated, bool hdrActive)
|
||||||
|
{
|
||||||
|
bool anyReadable;
|
||||||
|
return ProbeDevices(target, elevated, hdrActive, out anyReadable);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static IReadOnlyList<DeviceGamma> ProbeDevices(IPerDeviceGammaProbeTarget target, bool elevated, bool hdrActive, out bool anyReadable)
|
||||||
|
{
|
||||||
|
anyReadable = false;
|
||||||
|
List<DeviceGamma> list = new List<DeviceGamma>();
|
||||||
|
if (target == null)
|
||||||
|
{
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
IReadOnlyList<string> readOnlyList;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
readOnlyList = target.Devices() ?? Array.Empty<string>();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
ushort[] identity = GammaCurve.Identity();
|
||||||
|
foreach (string device in readOnlyList)
|
||||||
|
{
|
||||||
|
ushort[] array = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
array = target.TryGet(device);
|
||||||
|
if (array != null)
|
||||||
|
{
|
||||||
|
anyReadable = true;
|
||||||
|
ushort[] array2 = TestRamp();
|
||||||
|
bool flag = target.TrySet(device, array2);
|
||||||
|
ushort[] readback = (flag ? target.TryGet(device) : null);
|
||||||
|
GammaSupport gammaSupport = (flag ? Classify(array2, readback, identity) : GammaSupport.Refused);
|
||||||
|
if (gammaSupport == GammaSupport.Refused && GentleGetsThrough((ushort[] r) => target.TrySet(device, r), () => target.TryGet(device)))
|
||||||
|
{
|
||||||
|
gammaSupport = GammaSupport.Clamped;
|
||||||
|
}
|
||||||
|
list.Add(new DeviceGamma(device, gammaSupport, WhyRefused(gammaSupport, flag, elevated, hdrActive, array, identity)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list.Add(new DeviceGamma(device, GammaSupport.Untested, GammaRefusal.None));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
list.Add(new DeviceGamma(device, GammaSupport.Untested, GammaRefusal.None));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (array != null)
|
||||||
|
{
|
||||||
|
target.TrySet(device, array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MachineCapabilities Run(bool driverVibrance, OverlayMode overlayPath, IGammaProbeTarget? gammaTarget = null, IPerDeviceGammaProbeTarget? perDeviceTarget = null)
|
||||||
|
{
|
||||||
|
GammaProbeMemory measured;
|
||||||
|
return Run(driverVibrance, overlayPath, null, out measured, gammaTarget, perDeviceTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MachineCapabilities Run(bool driverVibrance, OverlayMode overlayPath, GammaProbeMemory? remembered, out GammaProbeMemory? measured, IGammaProbeTarget? gammaTarget = null, IPerDeviceGammaProbeTarget? perDeviceTarget = null)
|
||||||
|
{
|
||||||
|
measured = null;
|
||||||
|
bool elevated = SafeElevated();
|
||||||
|
bool flag = SafeHdr();
|
||||||
|
IPerDeviceGammaProbeTarget perDeviceGammaProbeTarget = perDeviceTarget ?? new PerDeviceGammaTarget();
|
||||||
|
perDeviceTarget = perDeviceGammaProbeTarget;
|
||||||
|
IReadOnlyList<string> devices;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
devices = perDeviceGammaProbeTarget.Devices() ?? Array.Empty<string>();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
devices = Array.Empty<string>();
|
||||||
|
}
|
||||||
|
string key = GammaProbeMemory.KeyFor(devices, elevated, flag, AppInfo.VersionText);
|
||||||
|
if (remembered != null && remembered.Reusable(key))
|
||||||
|
{
|
||||||
|
measured = remembered;
|
||||||
|
return new MachineCapabilities(remembered.Ramp, flag, SafeVendor(), driverVibrance, SafeMonitorCount(), SafeMixedDpi(), elevated, overlayPath, remembered.Why, remembered.Devices);
|
||||||
|
}
|
||||||
|
GammaSupport gammaSupport = GammaSupport.Untested;
|
||||||
|
bool couldRead = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
gammaSupport = ProbeGamma(gammaTarget ?? new ScreenGammaTarget(), out couldRead);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
IReadOnlyList<DeviceGamma> readOnlyList = Array.Empty<DeviceGamma>();
|
||||||
|
bool anyReadable = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
readOnlyList = ProbeDevices(perDeviceTarget ?? new PerDeviceGammaTarget(), elevated, flag, out anyReadable);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
GammaRefusal gammaRefusal = GammaRefusal.None;
|
||||||
|
foreach (DeviceGamma item in readOnlyList)
|
||||||
|
{
|
||||||
|
if (item.Why != GammaRefusal.None)
|
||||||
|
{
|
||||||
|
gammaRefusal = item.Why;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (gammaRefusal == GammaRefusal.None)
|
||||||
|
{
|
||||||
|
gammaRefusal = WhyRefused(gammaSupport, writeAccepted: true, elevated, flag, null, GammaCurve.Identity());
|
||||||
|
}
|
||||||
|
if (gammaSupport == GammaSupport.Refused && !couldRead && !anyReadable)
|
||||||
|
{
|
||||||
|
gammaRefusal = GammaRefusal.ScreenUnreadable;
|
||||||
|
}
|
||||||
|
if (gammaSupport != GammaSupport.Refused)
|
||||||
|
{
|
||||||
|
measured = new GammaProbeMemory(key, gammaSupport, gammaRefusal, new List<DeviceGamma>(readOnlyList));
|
||||||
|
}
|
||||||
|
return new MachineCapabilities(gammaSupport, flag, SafeVendor(), driverVibrance, SafeMonitorCount(), SafeMixedDpi(), elevated, overlayPath, gammaRefusal, readOnlyList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool SafeHdr()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return HdrDetection.AnyDisplayInHdr();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GpuVendor SafeVendor()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return GpuDetection.PrimaryVendor();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return GpuVendor.Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int SafeMonitorCount()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Math.Max(1, Screen.AllScreens.Length);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool SafeMixedDpi()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Screen[] allScreens = Screen.AllScreens;
|
||||||
|
if (allScreens.Length < 2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint num = DpiOf(allScreens[0]);
|
||||||
|
for (int i = 1; i < allScreens.Length; i++)
|
||||||
|
{
|
||||||
|
if (DpiOf(allScreens[i]) != num)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint DpiOf(Screen screen)
|
||||||
|
{
|
||||||
|
if (GetDpiForMonitor(MonitorFromPoint(new POINT
|
||||||
|
{
|
||||||
|
X = screen.Bounds.Left + 1,
|
||||||
|
Y = screen.Bounds.Top + 1
|
||||||
|
}, 2), 0, out var x, out var _) != 0)
|
||||||
|
{
|
||||||
|
return 96u;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool SafeElevated()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using WindowsIdentity ntIdentity = WindowsIdentity.GetCurrent();
|
||||||
|
return new WindowsPrincipal(ntIdentity).IsInRole(WindowsBuiltInRole.Administrator);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern nint MonitorFromPoint(POINT pt, int flags);
|
||||||
|
|
||||||
|
[DllImport("shcore.dll")]
|
||||||
|
private static extern int GetDpiForMonitor(nint monitor, int type, out uint x, out uint y);
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public sealed record DeviceGamma(string Device, GammaSupport Result, GammaRefusal Why);
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public sealed record GammaProbeMemory(string Key, GammaSupport Ramp, GammaRefusal Why, List<DeviceGamma> Devices)
|
||||||
|
{
|
||||||
|
internal const string Version = "g1";
|
||||||
|
|
||||||
|
internal static string KeyFor(IEnumerable<string> devices, bool elevated, bool hdr, string appVersion)
|
||||||
|
{
|
||||||
|
return "g1|" + appVersion + "|" + (elevated ? "E" : "e") + (hdr ? "H" : "h") + "|" + string.Join(";", devices.OrderBy((string d) => d, StringComparer.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal bool Reusable(string key)
|
||||||
|
{
|
||||||
|
bool flag = Key == key;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
GammaSupport ramp = Ramp;
|
||||||
|
bool flag2 = (uint)(ramp - 1) <= 1u;
|
||||||
|
flag = flag2;
|
||||||
|
}
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
return Why != GammaRefusal.ScreenUnreadable;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public enum GammaRefusal
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
NotElevated,
|
||||||
|
HdrOn,
|
||||||
|
RampHeldByOther,
|
||||||
|
WriteFailed,
|
||||||
|
ReadbackIdentity,
|
||||||
|
ScreenUnreadable
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public enum GammaSupport
|
||||||
|
{
|
||||||
|
Untested,
|
||||||
|
Working,
|
||||||
|
Clamped,
|
||||||
|
Refused
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using SharpDX.DXGI;
|
||||||
|
|
||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
internal static class GpuDetection
|
||||||
|
{
|
||||||
|
public static GpuVendor PrimaryVendor()
|
||||||
|
{
|
||||||
|
using Factory1 factory = new Factory1();
|
||||||
|
using Adapter1 adapter = factory.GetAdapter1(0);
|
||||||
|
switch (adapter.Description1.VendorId)
|
||||||
|
{
|
||||||
|
case 4318:
|
||||||
|
return GpuVendor.Nvidia;
|
||||||
|
case 4098:
|
||||||
|
case 4130:
|
||||||
|
return GpuVendor.Amd;
|
||||||
|
case 32902:
|
||||||
|
return GpuVendor.Intel;
|
||||||
|
default:
|
||||||
|
return GpuVendor.Other;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public enum GpuVendor
|
||||||
|
{
|
||||||
|
Unknown,
|
||||||
|
Nvidia,
|
||||||
|
Amd,
|
||||||
|
Intel,
|
||||||
|
Other
|
||||||
|
}
|
||||||
@@ -0,0 +1,559 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using VibranceHud.Controls;
|
||||||
|
|
||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
internal static class HdrDetection
|
||||||
|
{
|
||||||
|
private struct DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE
|
||||||
|
{
|
||||||
|
public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
|
||||||
|
|
||||||
|
public uint value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct LUID
|
||||||
|
{
|
||||||
|
public uint LowPart;
|
||||||
|
|
||||||
|
public int HighPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct DISPLAYCONFIG_PATH_SOURCE_INFO
|
||||||
|
{
|
||||||
|
public LUID adapterId;
|
||||||
|
|
||||||
|
public uint id;
|
||||||
|
|
||||||
|
public uint modeInfoIdx;
|
||||||
|
|
||||||
|
public uint statusFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct DISPLAYCONFIG_RATIONAL
|
||||||
|
{
|
||||||
|
public uint Numerator;
|
||||||
|
|
||||||
|
public uint Denominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct DISPLAYCONFIG_PATH_TARGET_INFO
|
||||||
|
{
|
||||||
|
public LUID adapterId;
|
||||||
|
|
||||||
|
public uint id;
|
||||||
|
|
||||||
|
public uint modeInfoIdx;
|
||||||
|
|
||||||
|
public uint outputTechnology;
|
||||||
|
|
||||||
|
public uint rotation;
|
||||||
|
|
||||||
|
public uint scaling;
|
||||||
|
|
||||||
|
public DISPLAYCONFIG_RATIONAL refreshRate;
|
||||||
|
|
||||||
|
public uint scanLineOrdering;
|
||||||
|
|
||||||
|
[MarshalAs(UnmanagedType.Bool)]
|
||||||
|
public bool targetAvailable;
|
||||||
|
|
||||||
|
public uint statusFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct DISPLAYCONFIG_PATH_INFO
|
||||||
|
{
|
||||||
|
public DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo;
|
||||||
|
|
||||||
|
public DISPLAYCONFIG_PATH_TARGET_INFO targetInfo;
|
||||||
|
|
||||||
|
public uint flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential, Size = 64)]
|
||||||
|
private struct DISPLAYCONFIG_MODE_INFO
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||||
|
{
|
||||||
|
public int type;
|
||||||
|
|
||||||
|
public int size;
|
||||||
|
|
||||||
|
public LUID adapterId;
|
||||||
|
|
||||||
|
public uint id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO
|
||||||
|
{
|
||||||
|
public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
|
||||||
|
|
||||||
|
public uint value;
|
||||||
|
|
||||||
|
public uint colorEncoding;
|
||||||
|
|
||||||
|
public int bitsPerColorChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2
|
||||||
|
{
|
||||||
|
public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
|
||||||
|
|
||||||
|
public uint value;
|
||||||
|
|
||||||
|
public uint colorEncoding;
|
||||||
|
|
||||||
|
public uint bitsPerColorChannel;
|
||||||
|
|
||||||
|
public uint activeColorMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||||
|
private struct DISPLAYCONFIG_SOURCE_DEVICE_NAME
|
||||||
|
{
|
||||||
|
public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
|
||||||
|
|
||||||
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
||||||
|
public string viewGdiDeviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private const uint ColorModeWcg = 1u;
|
||||||
|
|
||||||
|
private const uint ColorModeHdr = 2u;
|
||||||
|
|
||||||
|
private const uint QDC_ONLY_ACTIVE_PATHS = 2u;
|
||||||
|
|
||||||
|
private const int DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1;
|
||||||
|
|
||||||
|
private const int DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO = 9;
|
||||||
|
|
||||||
|
private const int DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE = 10;
|
||||||
|
|
||||||
|
private const int DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO_2 = 15;
|
||||||
|
|
||||||
|
private const int DISPLAYCONFIG_DEVICE_INFO_SET_HDR_STATE = 16;
|
||||||
|
|
||||||
|
public static bool AnyDisplayInHdr()
|
||||||
|
{
|
||||||
|
return AnyDisplayInHdr(ActivePaths(), AdvancedColourOf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IReadOnlyList<HdrDisplay> Report()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Report(ActivePaths(), AdvancedColourOf, SourceNameOf);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return Array.Empty<HdrDisplay>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool AnyDisplayInHdr<TPath>(IReadOnlyList<TPath>? paths, Func<TPath, (uint Flags, int BitsPerColorChannel)?> advancedColour)
|
||||||
|
{
|
||||||
|
return Displays(paths, advancedColour, (TPath _) => "", includeNames: false).Any((HdrDisplay d) => d.Enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static IReadOnlyList<HdrDisplay> Report<TPath>(IReadOnlyList<TPath>? paths, Func<TPath, (uint Flags, int BitsPerColorChannel)?> advancedColour, Func<TPath, string> sourceName)
|
||||||
|
{
|
||||||
|
return Displays(paths, advancedColour, sourceName, includeNames: true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<HdrDisplay> Displays<TPath>(IReadOnlyList<TPath>? paths, Func<TPath, (uint Flags, int BitsPerColorChannel)?> advancedColour, Func<TPath, string> sourceName, bool includeNames)
|
||||||
|
{
|
||||||
|
if (paths == null)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
foreach (TPath path in paths)
|
||||||
|
{
|
||||||
|
(uint, int)? tuple = advancedColour(path);
|
||||||
|
if (tuple.HasValue)
|
||||||
|
{
|
||||||
|
(uint, int) valueOrDefault = tuple.GetValueOrDefault();
|
||||||
|
string device = (includeNames ? sourceName(path) : "");
|
||||||
|
bool supported = (valueOrDefault.Item1 & 1) != 0;
|
||||||
|
bool enabled = (valueOrDefault.Item1 & 2) != 0 && (valueOrDefault.Item1 & 4) == 0;
|
||||||
|
int item = valueOrDefault.Item2;
|
||||||
|
yield return new HdrDisplay(device, supported, enabled, (item > 0 && item < 64) ? valueOrDefault.Item2 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static (uint Flags, int BitsPerColorChannel) FromAdvancedColorInfo2(uint value, uint activeColorMode, int bitsPerColorChannel)
|
||||||
|
{
|
||||||
|
uint num = 0u;
|
||||||
|
if ((value & 0x10) != 0)
|
||||||
|
{
|
||||||
|
num |= 1;
|
||||||
|
}
|
||||||
|
switch (activeColorMode)
|
||||||
|
{
|
||||||
|
case 2u:
|
||||||
|
num |= 2;
|
||||||
|
break;
|
||||||
|
case 1u:
|
||||||
|
num |= 6;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return (Flags: num, BitsPerColorChannel: bitsPerColorChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static IReadOnlyList<(string Device, uint Value, uint Mode)>? RawInfo2ForTest()
|
||||||
|
{
|
||||||
|
IReadOnlyList<DISPLAYCONFIG_PATH_INFO> readOnlyList = ActivePaths();
|
||||||
|
if (readOnlyList == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<(string, uint, uint)> list = new List<(string, uint, uint)>();
|
||||||
|
foreach (DISPLAYCONFIG_PATH_INFO item in readOnlyList)
|
||||||
|
{
|
||||||
|
(uint, uint, uint)? tuple = ReadInfo2(item);
|
||||||
|
if (tuple.HasValue)
|
||||||
|
{
|
||||||
|
(uint, uint, uint) valueOrDefault = tuple.GetValueOrDefault();
|
||||||
|
list.Add((SourceNameOf(item), valueOrDefault.Item1, valueOrDefault.Item2));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static IReadOnlyList<int> PickPaths(IReadOnlyList<string> sourceNames, string? device)
|
||||||
|
{
|
||||||
|
List<int> list = new List<int>();
|
||||||
|
if (string.IsNullOrEmpty(device))
|
||||||
|
{
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < sourceNames.Count; i++)
|
||||||
|
{
|
||||||
|
if (string.Equals(sourceNames[i], device, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
list.Add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool AllColouredDisplaysInHdr(IReadOnlyList<string> coloured, IReadOnlyList<HdrDisplay> report)
|
||||||
|
{
|
||||||
|
if (coloured.Count == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach (string device in coloured)
|
||||||
|
{
|
||||||
|
if (!report.Any((HdrDisplay d) => d.Enabled && string.Equals(d.Device, device, StringComparison.OrdinalIgnoreCase)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool AllColouredDisplaysInHdr()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return AllColouredDisplaysInHdr(MultiMonitorGammaRamp.Devices(), Report());
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool? IsHdrOn(string? gdiDeviceName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string b = ResolveDevice(gdiDeviceName);
|
||||||
|
foreach (HdrDisplay item in Report())
|
||||||
|
{
|
||||||
|
if (string.Equals(item.Device, b, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return item.Enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? ResolveDevice(string? gdiDeviceName)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(gdiDeviceName))
|
||||||
|
{
|
||||||
|
return gdiDeviceName;
|
||||||
|
}
|
||||||
|
return Screen.PrimaryScreen?.DeviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static HdrSwitchOutcome SwitchWithRevert(bool enabled, string? device, Func<string?, bool?> isHdrOn, Func<bool, string?, bool> set, Func<bool> keep)
|
||||||
|
{
|
||||||
|
bool? flag = isHdrOn(device);
|
||||||
|
if (flag.HasValue)
|
||||||
|
{
|
||||||
|
bool valueOrDefault = flag == true;
|
||||||
|
if (valueOrDefault == enabled)
|
||||||
|
{
|
||||||
|
return HdrSwitchOutcome.Unchanged;
|
||||||
|
}
|
||||||
|
if (!set(enabled, device))
|
||||||
|
{
|
||||||
|
return HdrSwitchOutcome.Failed;
|
||||||
|
}
|
||||||
|
if (isHdrOn(device) != enabled)
|
||||||
|
{
|
||||||
|
set(valueOrDefault, device);
|
||||||
|
return HdrSwitchOutcome.Failed;
|
||||||
|
}
|
||||||
|
if (keep())
|
||||||
|
{
|
||||||
|
return HdrSwitchOutcome.Kept;
|
||||||
|
}
|
||||||
|
if (!set(valueOrDefault, device))
|
||||||
|
{
|
||||||
|
return HdrSwitchOutcome.Failed;
|
||||||
|
}
|
||||||
|
return HdrSwitchOutcome.Reverted;
|
||||||
|
}
|
||||||
|
return HdrSwitchOutcome.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static HdrSwitchOutcome SwitchWithRevertReal(bool enabled, string? device, TimeSpan grace)
|
||||||
|
{
|
||||||
|
string name = ResolveDevice(device) ?? "";
|
||||||
|
return SwitchWithRevert(enabled, name, IsHdrOn, TrySetHdr, () =>
|
||||||
|
{
|
||||||
|
bool confirmed = false;
|
||||||
|
using RevertConfirmForm revertConfirmForm = new RevertConfirmForm($"HDR is now {(enabled ? "on" : "off")} for {name}.", Math.Max(1, (int)Math.Ceiling(grace.TotalSeconds)));
|
||||||
|
revertConfirmForm.Confirmed += () =>
|
||||||
|
{
|
||||||
|
confirmed = true;
|
||||||
|
};
|
||||||
|
revertConfirmForm.ShowDialog();
|
||||||
|
return confirmed;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IReadOnlyList<DISPLAYCONFIG_PATH_INFO>? ActivePaths()
|
||||||
|
{
|
||||||
|
if (GetDisplayConfigBufferSizes(2u, out var pathCount, out var modeCount) != 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DISPLAYCONFIG_PATH_INFO[] array = new DISPLAYCONFIG_PATH_INFO[pathCount];
|
||||||
|
DISPLAYCONFIG_MODE_INFO[] modes = new DISPLAYCONFIG_MODE_INFO[modeCount];
|
||||||
|
if (QueryDisplayConfig(2u, ref pathCount, array, ref modeCount, modes, IntPtr.Zero) != 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ArraySegment<DISPLAYCONFIG_PATH_INFO>(array, 0, (int)pathCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static (uint Flags, int BitsPerColorChannel)? AdvancedColourOf(DISPLAYCONFIG_PATH_INFO path)
|
||||||
|
{
|
||||||
|
(uint, uint, uint)? tuple = ReadInfo2(path);
|
||||||
|
if (tuple.HasValue)
|
||||||
|
{
|
||||||
|
(uint, uint, uint) valueOrDefault = tuple.GetValueOrDefault();
|
||||||
|
return FromAdvancedColorInfo2(valueOrDefault.Item1, valueOrDefault.Item2, (int)valueOrDefault.Item3);
|
||||||
|
}
|
||||||
|
DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO info = new DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO
|
||||||
|
{
|
||||||
|
header = new DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||||
|
{
|
||||||
|
type = 9,
|
||||||
|
size = Marshal.SizeOf<DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO>(),
|
||||||
|
adapterId = path.targetInfo.adapterId,
|
||||||
|
id = path.targetInfo.id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (DisplayConfigGetDeviceInfo(ref info) != 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (info.value, info.bitsPerColorChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static (uint Value, uint Mode, uint Bits)? ReadInfo2(DISPLAYCONFIG_PATH_INFO path)
|
||||||
|
{
|
||||||
|
DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2 info = new DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2
|
||||||
|
{
|
||||||
|
header = new DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||||
|
{
|
||||||
|
type = 15,
|
||||||
|
size = Marshal.SizeOf<DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2>(),
|
||||||
|
adapterId = path.targetInfo.adapterId,
|
||||||
|
id = path.targetInfo.id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (DisplayConfigGetDeviceInfo(ref info) != 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (info.value, info.activeColorMode, info.bitsPerColorChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string SourceNameOf(DISPLAYCONFIG_PATH_INFO path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DISPLAYCONFIG_SOURCE_DEVICE_NAME info = new DISPLAYCONFIG_SOURCE_DEVICE_NAME
|
||||||
|
{
|
||||||
|
header = new DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||||
|
{
|
||||||
|
type = 1,
|
||||||
|
size = Marshal.SizeOf<DISPLAYCONFIG_SOURCE_DEVICE_NAME>(),
|
||||||
|
adapterId = path.sourceInfo.adapterId,
|
||||||
|
id = path.sourceInfo.id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (DisplayConfigGetDeviceInfo(ref info) == 0) ? (info.viewGdiDeviceName ?? "").TrimEnd('\0') : "";
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TrySetHdr(bool enabled, string? gdiDeviceName)
|
||||||
|
{
|
||||||
|
IReadOnlyList<DISPLAYCONFIG_PATH_INFO> readOnlyList = ActivePaths();
|
||||||
|
if (readOnlyList == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
IReadOnlyList<int> readOnlyList2 = PickPaths(readOnlyList.Select(SourceNameOf).ToList(), ResolveDevice(gdiDeviceName));
|
||||||
|
if (readOnlyList2.Count == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool result = false;
|
||||||
|
foreach (int item in readOnlyList2)
|
||||||
|
{
|
||||||
|
DISPLAYCONFIG_PATH_INFO path = readOnlyList[item];
|
||||||
|
(uint, uint, uint)? tuple = ReadInfo2(path);
|
||||||
|
if (tuple.HasValue)
|
||||||
|
{
|
||||||
|
(uint, uint, uint) valueOrDefault = tuple.GetValueOrDefault();
|
||||||
|
if ((valueOrDefault.Item1 & 0x10) == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (valueOrDefault.Item2 == 2 == enabled)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE info = new DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE
|
||||||
|
{
|
||||||
|
header = SetHeader(16, path),
|
||||||
|
value = (enabled ? 1u : 0u)
|
||||||
|
};
|
||||||
|
if (DisplayConfigSetDeviceInfo(ref info) != 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
tuple = ReadInfo2(path);
|
||||||
|
if (tuple.HasValue && tuple.GetValueOrDefault().Item2 == 2 == enabled)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Thread.Sleep(150);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO info2 = new DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO
|
||||||
|
{
|
||||||
|
header = new DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||||
|
{
|
||||||
|
type = 9,
|
||||||
|
size = Marshal.SizeOf<DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO>(),
|
||||||
|
adapterId = path.targetInfo.adapterId,
|
||||||
|
id = path.targetInfo.id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (DisplayConfigGetDeviceInfo(ref info2) != 0 || (info2.value & 1) == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (((info2.value & 2) != 0 && (info2.value & 4) == 0) == enabled)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE info3 = new DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE
|
||||||
|
{
|
||||||
|
header = SetHeader(10, path),
|
||||||
|
value = (enabled ? 1u : 0u)
|
||||||
|
};
|
||||||
|
if (DisplayConfigSetDeviceInfo(ref info3) == 0)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DISPLAYCONFIG_DEVICE_INFO_HEADER SetHeader(int type, DISPLAYCONFIG_PATH_INFO path)
|
||||||
|
{
|
||||||
|
return new DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||||
|
{
|
||||||
|
type = type,
|
||||||
|
size = Marshal.SizeOf<DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE>(),
|
||||||
|
adapterId = path.targetInfo.adapterId,
|
||||||
|
id = path.targetInfo.id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern int DisplayConfigSetDeviceInfo(ref DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE info);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern int GetDisplayConfigBufferSizes(uint flags, out uint pathCount, out uint modeCount);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern int QueryDisplayConfig(uint flags, ref uint pathCount, [Out] DISPLAYCONFIG_PATH_INFO[] paths, ref uint modeCount, [Out] DISPLAYCONFIG_MODE_INFO[] modes, nint currentTopologyId);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern int DisplayConfigGetDeviceInfo(ref DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO info);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern int DisplayConfigGetDeviceInfo(ref DISPLAYCONFIG_SOURCE_DEVICE_NAME info);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern int DisplayConfigGetDeviceInfo(ref DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2 info);
|
||||||
|
|
||||||
|
internal static (int Target, int Path) MarshalledSizesForTest()
|
||||||
|
{
|
||||||
|
return (Target: Marshal.SizeOf<DISPLAYCONFIG_PATH_TARGET_INFO>(), Path: Marshal.SizeOf<DISPLAYCONFIG_PATH_INFO>());
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static int SourceNameSizeForTest()
|
||||||
|
{
|
||||||
|
return Marshal.SizeOf<DISPLAYCONFIG_SOURCE_DEVICE_NAME>();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static int AdvancedColorInfo2SizeForTest()
|
||||||
|
{
|
||||||
|
return Marshal.SizeOf<DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public readonly record struct HdrDisplay(string Device, bool Supported, bool Enabled, int BitsPerChannel);
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public enum HdrSwitchOutcome
|
||||||
|
{
|
||||||
|
Failed,
|
||||||
|
Unchanged,
|
||||||
|
Kept,
|
||||||
|
Reverted
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public static class HdrWords
|
||||||
|
{
|
||||||
|
private const string Method = "PlexusX reads Windows' own advanced colour setting for each display";
|
||||||
|
|
||||||
|
public static string DetectionLine(IReadOnlyList<HdrDisplay> displays, bool coloursLimited = true)
|
||||||
|
{
|
||||||
|
if (displays == null || displays.Count == 0)
|
||||||
|
{
|
||||||
|
return "PlexusX couldn't read HDR from Windows on this PC.";
|
||||||
|
}
|
||||||
|
List<HdrDisplay> list = displays.Where((HdrDisplay d) => d.Enabled).ToList();
|
||||||
|
if (list.Count != 0)
|
||||||
|
{
|
||||||
|
if (coloursLimited)
|
||||||
|
{
|
||||||
|
return $"HDR is on for {Names(list)}, which is why screen-colour changes are limited there. {"PlexusX reads Windows' own advanced colour setting for each display"}.";
|
||||||
|
}
|
||||||
|
return $"HDR is on for {Names(list)}. {"PlexusX reads Windows' own advanced colour setting for each display"}.";
|
||||||
|
}
|
||||||
|
return $"HDR is off on {Names(displays)}. {"PlexusX reads Windows' own advanced colour setting for each display"}.";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string Names(IReadOnlyList<HdrDisplay> displays)
|
||||||
|
{
|
||||||
|
List<string> list = displays.Select((HdrDisplay d) => (!string.IsNullOrWhiteSpace(d.Device)) ? d.Device : "an unnamed display").ToList();
|
||||||
|
if (list.Count == 1)
|
||||||
|
{
|
||||||
|
return list[0];
|
||||||
|
}
|
||||||
|
return string.Join(", ", list.Take(list.Count - 1)) + " and " + list[list.Count - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public interface IGammaProbeTarget
|
||||||
|
{
|
||||||
|
bool TrySet(ushort[] ramp);
|
||||||
|
|
||||||
|
ushort[]? TryGet();
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public interface IPerDeviceGammaProbeTarget
|
||||||
|
{
|
||||||
|
IReadOnlyList<string> Devices();
|
||||||
|
|
||||||
|
bool TrySet(string device, ushort[] ramp);
|
||||||
|
|
||||||
|
ushort[]? TryGet(string device);
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public static class Machine
|
||||||
|
{
|
||||||
|
public static MachineCapabilities Current { get; private set; } = MachineCapabilities.Unknown;
|
||||||
|
|
||||||
|
public static void Measure(bool driverVibrance, OverlayMode overlayPath)
|
||||||
|
{
|
||||||
|
Current = CapabilityProbe.Run(driverVibrance, overlayPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool MeasureOrReuse(bool driverVibrance, OverlayMode overlayPath, AppSettings settings)
|
||||||
|
{
|
||||||
|
Current = CapabilityProbe.Run(driverVibrance, overlayPath, settings.GammaProbeMemory, out GammaProbeMemory measured);
|
||||||
|
if (measured == null || object.Equals(measured, settings.GammaProbeMemory))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
settings.GammaProbeMemory = measured;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool MeasureAndRemember(bool driverVibrance, OverlayMode overlayPath, AppSettings settings)
|
||||||
|
{
|
||||||
|
Current = CapabilityProbe.Run(driverVibrance, overlayPath, null, out GammaProbeMemory measured);
|
||||||
|
if (measured == null || object.Equals(measured, settings.GammaProbeMemory))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
settings.GammaProbeMemory = measured;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void OverrideForTests(MachineCapabilities caps)
|
||||||
|
{
|
||||||
|
Current = caps;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public sealed record MachineCapabilities(GammaSupport GammaRamp = GammaSupport.Untested, bool HdrActive = false, GpuVendor Gpu = GpuVendor.Unknown, bool DriverVibrance = false, int MonitorCount = 1, bool MixedDpi = false, bool Elevated = false, OverlayMode OverlayPath = OverlayMode.Mag, GammaRefusal RefusedWhy = GammaRefusal.None, IReadOnlyList<DeviceGamma>? PerDeviceGamma = null)
|
||||||
|
{
|
||||||
|
public static MachineCapabilities Unknown => new MachineCapabilities();
|
||||||
|
|
||||||
|
public IReadOnlyList<DeviceGamma> Devices => PerDeviceGamma ?? Array.Empty<DeviceGamma>();
|
||||||
|
|
||||||
|
public bool ToneControlsWork
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
GammaSupport gammaRamp = GammaRamp;
|
||||||
|
if ((uint)(gammaRamp - 1) <= 1u)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ToneLimitation
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
switch (GammaRamp)
|
||||||
|
{
|
||||||
|
case GammaSupport.Refused:
|
||||||
|
{
|
||||||
|
if (HdrActive)
|
||||||
|
{
|
||||||
|
return "HDR is on, and Windows ignores screen-colour changes while it is. Turn HDR off to use these.";
|
||||||
|
}
|
||||||
|
if (RefusedWhy == GammaRefusal.ScreenUnreadable)
|
||||||
|
{
|
||||||
|
return "PlexusX couldn't find your screen when it started - maybe the monitor was off. Restart PlexusX with the screen on to use these. Saturation above works either way.";
|
||||||
|
}
|
||||||
|
if (!Elevated)
|
||||||
|
{
|
||||||
|
return "Windows is blocking screen-colour changes because PlexusX is not running as administrator. Settings has a Fix this button that restarts it properly. Saturation above works either way.";
|
||||||
|
}
|
||||||
|
if (Gpu == GpuVendor.Nvidia)
|
||||||
|
{
|
||||||
|
return "Your NVIDIA driver is refusing screen-colour changes. Something else is usually holding them - Windows Night light, f.lux, or NVIDIA Freestyle. Close those and reopen PlexusX. Saturation above works either way.";
|
||||||
|
}
|
||||||
|
GpuVendor gpu = Gpu;
|
||||||
|
if ((uint)(gpu - 2) <= 1u)
|
||||||
|
{
|
||||||
|
return "Your graphics driver is refusing screen-colour changes. Check for a colour or night-light setting in your GPU control panel, and close anything else that tints the screen. Saturation above works either way.";
|
||||||
|
}
|
||||||
|
return "Your graphics driver is refusing screen-colour changes, so these won't do anything. Saturation and vibrance above still work.";
|
||||||
|
}
|
||||||
|
case GammaSupport.Clamped:
|
||||||
|
if (HdrActive)
|
||||||
|
{
|
||||||
|
return "HDR is on, so Windows is limiting these. They'll work, but weaker than the numbers suggest.";
|
||||||
|
}
|
||||||
|
return "Windows is limiting how far these can go on this PC, so they'll be weaker than the numbers suggest.";
|
||||||
|
case GammaSupport.Untested:
|
||||||
|
return "";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
internal static class RemeasurePolicy
|
||||||
|
{
|
||||||
|
internal const int MaxTries = 3;
|
||||||
|
|
||||||
|
internal static bool ShouldRemeasure(MachineCapabilities current, int triesSoFar)
|
||||||
|
{
|
||||||
|
if (current.GammaRamp != GammaSupport.Refused)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (current.RefusedWhy != GammaRefusal.ScreenUnreadable)
|
||||||
|
{
|
||||||
|
return triesSoFar < 1;
|
||||||
|
}
|
||||||
|
return triesSoFar < 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public static class Repair
|
||||||
|
{
|
||||||
|
public static string RelaunchArguments => "--relaunch";
|
||||||
|
|
||||||
|
public static RepairKind Plan(MachineCapabilities caps)
|
||||||
|
{
|
||||||
|
return Plan(caps, FlavourPolicy.Current);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RepairKind Plan(MachineCapabilities caps, FlavourPolicy policy)
|
||||||
|
{
|
||||||
|
GammaSupport gammaRamp = caps.GammaRamp;
|
||||||
|
if ((uint)(gammaRamp - 2) > 1u)
|
||||||
|
{
|
||||||
|
return RepairKind.None;
|
||||||
|
}
|
||||||
|
if (caps.HdrActive)
|
||||||
|
{
|
||||||
|
return RepairKind.OpenHdrSettings;
|
||||||
|
}
|
||||||
|
if (caps.RefusedWhy == GammaRefusal.ScreenUnreadable)
|
||||||
|
{
|
||||||
|
return RepairKind.None;
|
||||||
|
}
|
||||||
|
if (!caps.Elevated)
|
||||||
|
{
|
||||||
|
if (!policy.OffersElevation)
|
||||||
|
{
|
||||||
|
return RepairKind.None;
|
||||||
|
}
|
||||||
|
return RepairKind.RestartAsAdministrator;
|
||||||
|
}
|
||||||
|
return RepairKind.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ButtonText(RepairKind kind)
|
||||||
|
{
|
||||||
|
return kind switch
|
||||||
|
{
|
||||||
|
RepairKind.RestartAsAdministrator => "Fix this",
|
||||||
|
RepairKind.OpenHdrSettings => "Open HDR settings",
|
||||||
|
_ => "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Explain(RepairKind kind)
|
||||||
|
{
|
||||||
|
return kind switch
|
||||||
|
{
|
||||||
|
RepairKind.RestartAsAdministrator => "PlexusX will close and open again as administrator. Windows will ask you to confirm.",
|
||||||
|
RepairKind.OpenHdrSettings => "Opens the Windows HDR page. Turn HDR off there, then come back.",
|
||||||
|
_ => "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool Run(RepairKind kind, Action? beforeRestart = null)
|
||||||
|
{
|
||||||
|
return Run(kind, FlavourPolicy.Current, (ProcessStartInfo elevated) => Process.Start(elevated), beforeRestart);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool Run(RepairKind kind, FlavourPolicy policy, Func<ProcessStartInfo, Process?> start, Action? beforeRestart)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
switch (kind)
|
||||||
|
{
|
||||||
|
case RepairKind.RestartAsAdministrator:
|
||||||
|
{
|
||||||
|
if (!policy.OffersElevation)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
string processPath = Environment.ProcessPath;
|
||||||
|
if (string.IsNullOrEmpty(processPath))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ProcessStartInfo arg = new ProcessStartInfo(processPath, RelaunchArguments)
|
||||||
|
{
|
||||||
|
UseShellExecute = true,
|
||||||
|
Verb = "runas"
|
||||||
|
};
|
||||||
|
if (start(arg) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
beforeRestart?.Invoke();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case RepairKind.OpenHdrSettings:
|
||||||
|
Process.Start(new ProcessStartInfo("ms-settings:display")
|
||||||
|
{
|
||||||
|
UseShellExecute = true
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public enum RepairKind
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
RestartAsAdministrator,
|
||||||
|
OpenHdrSettings
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
|
namespace VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
public static class WindowsRampRule
|
||||||
|
{
|
||||||
|
public const int DefaultRange = 128;
|
||||||
|
|
||||||
|
public const int UnlockedRange = 256;
|
||||||
|
|
||||||
|
public static bool WindowsAcceptsRamp(ushort[] ramp, int range = 128)
|
||||||
|
{
|
||||||
|
if (ramp.Length != 768)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (range >= 256)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 256; j++)
|
||||||
|
{
|
||||||
|
if (Math.Abs((ramp[i * 256 + j] >> 8) - j) > range)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int? ReadGammaRange()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ICM");
|
||||||
|
return (registryKey?.GetValue("GdiIcmGammaRange") is int value) ? new int?(value) : ((int?)null);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int WorstDeviation(ushort[] ramp)
|
||||||
|
{
|
||||||
|
int num = 0;
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 256; j++)
|
||||||
|
{
|
||||||
|
num = Math.Max(num, Math.Abs((ramp[i * 256 + j] >> 8) - j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace VibranceHud.Capture;
|
||||||
|
|
||||||
|
public static class ColourScreenshot
|
||||||
|
{
|
||||||
|
public static string Folder => AppFolders.Pictures;
|
||||||
|
|
||||||
|
public static void ApplyLook(Bitmap bmp, float[]? matrix, ushort[]? ramp)
|
||||||
|
{
|
||||||
|
if (bmp == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("bmp");
|
||||||
|
}
|
||||||
|
if (matrix == null && ramp == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
byte[] array = null;
|
||||||
|
if (ramp != null)
|
||||||
|
{
|
||||||
|
array = new byte[768];
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 256; j++)
|
||||||
|
{
|
||||||
|
array[i * 256 + j] = (byte)(ramp[i * 256 + j] >> 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
||||||
|
BitmapData bitmapData = bmp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int num = Math.Abs(bitmapData.Stride) * bmp.Height;
|
||||||
|
byte[] array2 = new byte[num];
|
||||||
|
Marshal.Copy(bitmapData.Scan0, array2, 0, num);
|
||||||
|
for (int k = 0; k < num; k += 4)
|
||||||
|
{
|
||||||
|
float num2 = (float)(int)array2[k] / 255f;
|
||||||
|
float num3 = (float)(int)array2[k + 1] / 255f;
|
||||||
|
float num4 = (float)(int)array2[k + 2] / 255f;
|
||||||
|
if (matrix != null)
|
||||||
|
{
|
||||||
|
float num5 = num4 * matrix[0] + num3 * matrix[5] + num2 * matrix[10] + matrix[20];
|
||||||
|
float num6 = num4 * matrix[1] + num3 * matrix[6] + num2 * matrix[11] + matrix[21];
|
||||||
|
float num7 = num4 * matrix[2] + num3 * matrix[7] + num2 * matrix[12] + matrix[22];
|
||||||
|
num4 = num5;
|
||||||
|
num3 = num6;
|
||||||
|
num2 = num7;
|
||||||
|
}
|
||||||
|
byte b = Clamp(num4);
|
||||||
|
byte b2 = Clamp(num3);
|
||||||
|
byte b3 = Clamp(num2);
|
||||||
|
if (array != null)
|
||||||
|
{
|
||||||
|
b = array[b];
|
||||||
|
b2 = array[256 + b2];
|
||||||
|
b3 = array[512 + b3];
|
||||||
|
}
|
||||||
|
array2[k] = b3;
|
||||||
|
array2[k + 1] = b2;
|
||||||
|
array2[k + 2] = b;
|
||||||
|
}
|
||||||
|
Marshal.Copy(array2, 0, bitmapData.Scan0, num);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
bmp.UnlockBits(bitmapData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte Clamp(float v)
|
||||||
|
{
|
||||||
|
if (!(v <= 0f))
|
||||||
|
{
|
||||||
|
if (!(v >= 1f))
|
||||||
|
{
|
||||||
|
return (byte)(v * 255f + 0.5f);
|
||||||
|
}
|
||||||
|
return byte.MaxValue;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Bitmap Grab()
|
||||||
|
{
|
||||||
|
Rectangle virtualScreen = SystemInformation.VirtualScreen;
|
||||||
|
Bitmap bitmap = new Bitmap(virtualScreen.Width, virtualScreen.Height, PixelFormat.Format32bppArgb);
|
||||||
|
using Graphics graphics = Graphics.FromImage(bitmap);
|
||||||
|
graphics.CopyFromScreen(virtualScreen.Left, virtualScreen.Top, 0, 0, virtualScreen.Size, CopyPixelOperation.SourceCopy);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string FileNameFor(DateTime when)
|
||||||
|
{
|
||||||
|
return $"PlexusX-{when:yyyy-MM-dd-HHmmss}.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string UniquePath(string folder, DateTime now)
|
||||||
|
{
|
||||||
|
string text = Path.Combine(folder, FileNameFor(now));
|
||||||
|
int num = 2;
|
||||||
|
while (File.Exists(text) && num < 100)
|
||||||
|
{
|
||||||
|
text = Path.Combine(folder, Path.GetFileNameWithoutExtension(FileNameFor(now)) + " (" + num + ").png");
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Take(VibranceEngine engine, DateTime now)
|
||||||
|
{
|
||||||
|
if (engine == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("engine");
|
||||||
|
}
|
||||||
|
using Bitmap bitmap = Grab();
|
||||||
|
ApplyLook(bitmap, engine.CurrentMatrix(), engine.CurrentRamp());
|
||||||
|
Directory.CreateDirectory(Folder);
|
||||||
|
string text = UniquePath(Folder, now);
|
||||||
|
bitmap.Save(text, ImageFormat.Png);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Clipboard.SetImage(bitmap);
|
||||||
|
}
|
||||||
|
catch (ExternalException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch (ThreadStateException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,456 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using SharpDX;
|
||||||
|
using SharpDX.DXGI;
|
||||||
|
using SharpDX.Direct3D11;
|
||||||
|
using VibranceHud.Capabilities;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class CaptureDiagnostic
|
||||||
|
{
|
||||||
|
private const int Pairs = 10;
|
||||||
|
|
||||||
|
private const float TestSaturation = 3f;
|
||||||
|
|
||||||
|
private const double ReachesThreshold = 1.4;
|
||||||
|
|
||||||
|
private const double MissesThreshold = 1.1;
|
||||||
|
|
||||||
|
private const int DxgiErrorUnsupported = -2005270524;
|
||||||
|
|
||||||
|
internal const string DifferentChipWords = "This laptop's screen runs on a different graphics chip, so the test can't look. In OBS, try Display Capture with Capture Method 'Windows 10 (1903 and up)'";
|
||||||
|
|
||||||
|
internal const string GenericWords = "Windows wouldn't let the test look at your screen";
|
||||||
|
|
||||||
|
internal const string NoScreenOnAnyChipWords = "The test couldn't find your screen on any graphics chip, so it can't look. In OBS, try Display Capture with Capture Method 'Windows 10 (1903 and up)'";
|
||||||
|
|
||||||
|
private const int DxgiErrorNotFound = -2005270526;
|
||||||
|
|
||||||
|
public static CaptureProbe Probe(ISaturationOverlay overlay)
|
||||||
|
{
|
||||||
|
if (overlay == null)
|
||||||
|
{
|
||||||
|
return CaptureProbe.Failed("The colour effect isn't running, so there is nothing to test", "no overlay");
|
||||||
|
}
|
||||||
|
Factory1 factory = null;
|
||||||
|
Adapter1 adapter = null;
|
||||||
|
SharpDX.Direct3D11.Device device = null;
|
||||||
|
Output output = null;
|
||||||
|
Output1 output2 = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Factory1 f;
|
||||||
|
factory = (f = new Factory1());
|
||||||
|
int index = FirstAdapterWithAnOutput(CountAdapters(f), (int i) => AdapterHasAScreen(f, i));
|
||||||
|
adapter = factory.GetAdapter1(index);
|
||||||
|
device = new SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.BgraSupport);
|
||||||
|
output = adapter.GetOutput(0);
|
||||||
|
output2 = output.QueryInterface<Output1>();
|
||||||
|
double[] array = new double[10];
|
||||||
|
for (int num = 0; num < 10; num++)
|
||||||
|
{
|
||||||
|
overlay.Clear();
|
||||||
|
Thread.Sleep(180);
|
||||||
|
double num2 = MeanChroma(device, output2);
|
||||||
|
overlay.Apply(SaturationMatrix.Build(3f));
|
||||||
|
Thread.Sleep(180);
|
||||||
|
double num3 = MeanChroma(device, output2);
|
||||||
|
array[num] = ((num2 > 0.001) ? (num3 / num2) : 1.0);
|
||||||
|
}
|
||||||
|
overlay.Clear();
|
||||||
|
Array.Sort(array);
|
||||||
|
double num4 = (array[4] + array[5]) / 2.0;
|
||||||
|
if (num4 >= 1.4)
|
||||||
|
{
|
||||||
|
return new CaptureProbe(Ran: true, num4, ReachesCapture: true, "the colour effect IS in the desktop-duplication path (Discord screen share sees it)");
|
||||||
|
}
|
||||||
|
if (num4 <= 1.1)
|
||||||
|
{
|
||||||
|
return new CaptureProbe(Ran: true, num4, ReachesCapture: false, "not in the desktop-duplication path (Discord screen share won't see it; OBS still will)");
|
||||||
|
}
|
||||||
|
return new CaptureProbe(Ran: true, num4, ReachesCapture: false, "inconclusive - the screen was changing too much while measuring");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return FailedBecause(ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
output2?.Dispose();
|
||||||
|
output?.Dispose();
|
||||||
|
device?.Dispose();
|
||||||
|
adapter?.Dispose();
|
||||||
|
factory?.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string BuildReport(AppSettings settings, bool driverVibrance, CaptureProbe probe)
|
||||||
|
{
|
||||||
|
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.AppendLine("PlexusX capture report");
|
||||||
|
stringBuilder.AppendLine("----------------------");
|
||||||
|
StringBuilder stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder3 = stringBuilder2;
|
||||||
|
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("app : ");
|
||||||
|
handler.AppendFormatted(AppInfo.VersionText);
|
||||||
|
stringBuilder3.AppendLine(ref handler);
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder4 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(18, 2, stringBuilder2);
|
||||||
|
handler.AppendLiteral("windows : ");
|
||||||
|
handler.AppendFormatted(Environment.OSVersion.Version);
|
||||||
|
handler.AppendLiteral(" (");
|
||||||
|
handler.AppendFormatted(Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit");
|
||||||
|
handler.AppendLiteral(")");
|
||||||
|
stringBuilder4.AppendLine(ref handler);
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder5 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("gpu : ");
|
||||||
|
handler.AppendFormatted(DescribeAdapters());
|
||||||
|
stringBuilder5.AppendLine(ref handler);
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder6 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("driver vibr. : ");
|
||||||
|
handler.AppendFormatted(driverVibrance ? "available (NVIDIA)" : "not available");
|
||||||
|
stringBuilder6.AppendLine(ref handler);
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder7 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("display path : ");
|
||||||
|
handler.AppendFormatted((settings.OverlayMode == OverlayMode.Dx) ? "DX11" : "Magnification");
|
||||||
|
stringBuilder7.AppendLine(ref handler);
|
||||||
|
if (settings.OverlayMode != OverlayMode.Dx)
|
||||||
|
{
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder8 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(18, 2, stringBuilder2);
|
||||||
|
handler.AppendLiteral("dx11 failed : ");
|
||||||
|
handler.AppendFormatted(settings.DxFailure);
|
||||||
|
handler.AppendLiteral(" - ");
|
||||||
|
handler.AppendFormatted(settings.DxFailureMessage);
|
||||||
|
stringBuilder8.AppendLine(ref handler);
|
||||||
|
if (settings.DxFailureCode != 0)
|
||||||
|
{
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder9 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(17, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("dx11 code : 0x");
|
||||||
|
handler.AppendFormatted(settings.DxFailureCode, "X8");
|
||||||
|
stringBuilder9.AppendLine(ref handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder10 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("composited : ");
|
||||||
|
handler.AppendFormatted(settings.KeepDesktopComposited ? "forced on" : "off");
|
||||||
|
stringBuilder10.AppendLine(ref handler);
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder11 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("streaming : ");
|
||||||
|
handler.AppendFormatted(settings.StreamingMode ? "on" : "off");
|
||||||
|
stringBuilder11.AppendLine(ref handler);
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder12 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(18, 2, stringBuilder2);
|
||||||
|
handler.AppendLiteral("vibrance/sat : ");
|
||||||
|
handler.AppendFormatted(settings.VibrancePercent);
|
||||||
|
handler.AppendLiteral(" / ");
|
||||||
|
handler.AppendFormatted(settings.SaturationPercent);
|
||||||
|
stringBuilder12.AppendLine(ref handler);
|
||||||
|
MachineCapabilities current = Machine.Current;
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder13 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("gamma ramp : ");
|
||||||
|
handler.AppendFormatted(current.GammaRamp);
|
||||||
|
stringBuilder13.AppendLine(ref handler);
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder14 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("hdr : ");
|
||||||
|
handler.AppendFormatted(current.HdrActive ? "ON" : "off");
|
||||||
|
stringBuilder14.AppendLine(ref handler);
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder15 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 2, stringBuilder2);
|
||||||
|
handler.AppendLiteral("monitors : ");
|
||||||
|
handler.AppendFormatted(current.MonitorCount);
|
||||||
|
handler.AppendFormatted(current.MixedDpi ? " (mixed scaling)" : "");
|
||||||
|
stringBuilder15.AppendLine(ref handler);
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder16 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("elevated : ");
|
||||||
|
handler.AppendFormatted(current.Elevated ? "yes" : "no");
|
||||||
|
stringBuilder16.AppendLine(ref handler);
|
||||||
|
stringBuilder.AppendLine();
|
||||||
|
if (!probe.Ran)
|
||||||
|
{
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder17 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(31, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("capture test : could not run (");
|
||||||
|
handler.AppendFormatted(probe.Note);
|
||||||
|
handler.AppendLiteral(")");
|
||||||
|
stringBuilder17.AppendLine(ref handler);
|
||||||
|
if (!string.IsNullOrEmpty(probe.Detail))
|
||||||
|
{
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder18 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral(" detail : ");
|
||||||
|
handler.AppendFormatted(probe.Detail);
|
||||||
|
stringBuilder18.AppendLine(ref handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stringBuilder2 = stringBuilder;
|
||||||
|
StringBuilder stringBuilder19 = stringBuilder2;
|
||||||
|
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||||
|
handler.AppendLiteral("capture test : ");
|
||||||
|
handler.AppendFormatted(probe.Note);
|
||||||
|
stringBuilder19.AppendLine(ref handler);
|
||||||
|
stringBuilder.AppendLine(" measured : " + probe.MedianRatio.ToString("F3", invariantCulture) + " (1.0 = capture saw no change, ~2.0 = capture saw the effect)");
|
||||||
|
}
|
||||||
|
return stringBuilder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string DescribeAdapters()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using Factory1 factory = new Factory1();
|
||||||
|
List<string> list = new List<string>();
|
||||||
|
int num = 0;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Adapter1 adapter;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
adapter = factory.GetAdapter1(num);
|
||||||
|
}
|
||||||
|
catch (SharpDXException)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
using (adapter)
|
||||||
|
{
|
||||||
|
AdapterDescription1 description = adapter.Description1;
|
||||||
|
if ((description.Flags & AdapterFlags.Software) == 0)
|
||||||
|
{
|
||||||
|
list.Add(description.Description.Trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
return (list.Count == 0) ? "none found" : string.Join(" + ", list);
|
||||||
|
}
|
||||||
|
catch (Exception ex2)
|
||||||
|
{
|
||||||
|
return "unavailable (" + ex2.GetType().Name + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CaptureProbe FailedBecause(Exception ex)
|
||||||
|
{
|
||||||
|
return FailedBecause(ex, CountHardwareAdapters());
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static CaptureProbe FailedBecause(Exception ex, int hardwareAdapters)
|
||||||
|
{
|
||||||
|
string detail = ex.GetType().Name + ": " + Short(ex.Message) + $" (0x{ex.HResult:X8})";
|
||||||
|
string why;
|
||||||
|
if (ex.HResult == -2005270524)
|
||||||
|
{
|
||||||
|
why = "This laptop's screen runs on a different graphics chip, so the test can't look. In OBS, try Display Capture with Capture Method 'Windows 10 (1903 and up)'";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
why = ((ex.HResult == -2005270526 && hardwareAdapters > 1) ? "The test couldn't find your screen on any graphics chip, so it can't look. In OBS, try Display Capture with Capture Method 'Windows 10 (1903 and up)'" : "Windows wouldn't let the test look at your screen");
|
||||||
|
}
|
||||||
|
return CaptureProbe.Failed(why, detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static int FirstAdapterWithAnOutput(int adapters, Func<int, bool> hasOutput)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < adapters; i++)
|
||||||
|
{
|
||||||
|
if (hasOutput(i))
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int CountAdapters(Factory1 factory)
|
||||||
|
{
|
||||||
|
int num = 0;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (factory.GetAdapter1(num))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SharpDXException)
|
||||||
|
{
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool AdapterHasAScreen(Factory1 factory, int index)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using Adapter1 adapter = factory.GetAdapter1(index);
|
||||||
|
if ((adapter.Description1.Flags & AdapterFlags.Software) != 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
using (adapter.GetOutput(0))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SharpDXException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int CountHardwareAdapters()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using Factory1 factory = new Factory1();
|
||||||
|
int num = 0;
|
||||||
|
int num2 = 0;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Adapter1 adapter;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
adapter = factory.GetAdapter1(num2);
|
||||||
|
}
|
||||||
|
catch (SharpDXException)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
using (adapter)
|
||||||
|
{
|
||||||
|
if ((adapter.Description1.Flags & AdapterFlags.Software) == 0)
|
||||||
|
{
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num2++;
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string Short(string s)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(s))
|
||||||
|
{
|
||||||
|
return s.Split('\n')[0].Trim();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double MeanChroma(SharpDX.Direct3D11.Device device, Output1 output1)
|
||||||
|
{
|
||||||
|
using OutputDuplication outputDuplication = output1.DuplicateOutput(device);
|
||||||
|
SharpDX.DXGI.Resource resource = null;
|
||||||
|
for (int i = 0; i < 40; i++)
|
||||||
|
{
|
||||||
|
if (resource != null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (outputDuplication.TryAcquireNextFrame(250, out var _, out var desktopResourceOut).Success && desktopResourceOut != null)
|
||||||
|
{
|
||||||
|
resource = desktopResourceOut;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Thread.Sleep(25);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (resource == null)
|
||||||
|
{
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
using (resource)
|
||||||
|
{
|
||||||
|
using Texture2D texture2D = resource.QueryInterface<Texture2D>();
|
||||||
|
Texture2DDescription description = texture2D.Description;
|
||||||
|
using Texture2D texture2D2 = new Texture2D(device, new Texture2DDescription
|
||||||
|
{
|
||||||
|
Width = description.Width,
|
||||||
|
Height = description.Height,
|
||||||
|
MipLevels = 1,
|
||||||
|
ArraySize = 1,
|
||||||
|
Format = description.Format,
|
||||||
|
SampleDescription = new SampleDescription(1, 0),
|
||||||
|
Usage = ResourceUsage.Staging,
|
||||||
|
BindFlags = BindFlags.None,
|
||||||
|
CpuAccessFlags = CpuAccessFlags.Read,
|
||||||
|
OptionFlags = ResourceOptionFlags.None
|
||||||
|
});
|
||||||
|
device.ImmediateContext.CopyResource(texture2D, texture2D2);
|
||||||
|
DataBox dataBox = device.ImmediateContext.MapSubresource(texture2D2, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None);
|
||||||
|
double num = 0.0;
|
||||||
|
int num2 = 0;
|
||||||
|
byte[] array = new byte[dataBox.RowPitch];
|
||||||
|
for (int j = 0; j < description.Height; j += 4)
|
||||||
|
{
|
||||||
|
Marshal.Copy(dataBox.DataPointer + j * dataBox.RowPitch, array, 0, dataBox.RowPitch);
|
||||||
|
for (int k = 0; k < description.Width; k += 4)
|
||||||
|
{
|
||||||
|
int num3 = k * 4;
|
||||||
|
if (num3 + 2 >= array.Length)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
byte val = array[num3];
|
||||||
|
byte val2 = array[num3 + 1];
|
||||||
|
byte val3 = array[num3 + 2];
|
||||||
|
int num4 = Math.Max(val3, Math.Max(val2, val));
|
||||||
|
int num5 = Math.Min(val3, Math.Min(val2, val));
|
||||||
|
num += (double)(num4 - num5);
|
||||||
|
num2++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
device.ImmediateContext.UnmapSubresource(texture2D2, 0);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
outputDuplication.ReleaseFrame();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return (num2 == 0) ? 0.0 : (num / (double)num2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public sealed record CaptureProbe(bool Ran, double MedianRatio, bool ReachesCapture, string Note, string Detail = "")
|
||||||
|
{
|
||||||
|
public static CaptureProbe Failed(string why, string detail = "")
|
||||||
|
{
|
||||||
|
return new CaptureProbe(Ran: false, 0.0, ReachesCapture: false, why, detail);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public enum CaptureState
|
||||||
|
{
|
||||||
|
Visible,
|
||||||
|
NeedsStreamingMode,
|
||||||
|
DependsOnCaptureMethod
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class CaptureStatus
|
||||||
|
{
|
||||||
|
public const string AlwaysTrue = "In OBS use Display Capture, not Game Capture - Game Capture reads the game directly and never sees this. Gamma is never captured either way.";
|
||||||
|
|
||||||
|
public static CaptureState Resolve(OverlayMode overlay, bool driverVibranceAvailable, bool streamingMode)
|
||||||
|
{
|
||||||
|
if (overlay == OverlayMode.Mag)
|
||||||
|
{
|
||||||
|
return CaptureState.DependsOnCaptureMethod;
|
||||||
|
}
|
||||||
|
if (!driverVibranceAvailable)
|
||||||
|
{
|
||||||
|
return CaptureState.Visible;
|
||||||
|
}
|
||||||
|
if (!streamingMode)
|
||||||
|
{
|
||||||
|
return CaptureState.NeedsStreamingMode;
|
||||||
|
}
|
||||||
|
return CaptureState.Visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ToggleCanHelp(OverlayMode overlay, bool driverVibranceAvailable)
|
||||||
|
{
|
||||||
|
return driverVibranceAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Headline(CaptureState state)
|
||||||
|
{
|
||||||
|
return state switch
|
||||||
|
{
|
||||||
|
CaptureState.Visible => "Recordings show your colours.",
|
||||||
|
CaptureState.NeedsStreamingMode => "Recordings are missing your vibrance right now.",
|
||||||
|
_ => "Recordings show your colours - screen share may not.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Reason(CaptureState state, bool driverVibranceAvailable)
|
||||||
|
{
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case CaptureState.NeedsStreamingMode:
|
||||||
|
return "Your vibrance is being applied by the graphics driver, after recording software has already read the screen. Turn on \"Move my colours where recording can see them\" above to move it somewhere they can see it.";
|
||||||
|
case CaptureState.DependsOnCaptureMethod:
|
||||||
|
if (driverVibranceAvailable)
|
||||||
|
{
|
||||||
|
return "Recordings and screen share both show your colours - most of it comes from your NVIDIA driver, which every capture path can see.\n\nSaturation pushed past 100 is done in software, and that part reaches OBS but not Discord screen share.";
|
||||||
|
}
|
||||||
|
return "OBS records your colours with its default Display Capture settings - confirmed on AMD. If they don't appear, open your Display Capture source and set Capture Method to \"Windows 10 (1903 and up)\".\n\nDiscord screen share reads the screen a different way and won't show them. Your card has no driver-level colour for PlexusX to use yet, which is what would fix that.";
|
||||||
|
default:
|
||||||
|
return driverVibranceAvailable ? "Your vibrance is being applied early enough for capture to pick it up." : "Your colours are already applied in software, which capture reads - so there was never anything to move. That switch is for NVIDIA driver vibrance.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public sealed class CardPanel : Panel
|
||||||
|
{
|
||||||
|
private readonly CardSurface _surface = new CardSurface();
|
||||||
|
|
||||||
|
public CardPanel()
|
||||||
|
{
|
||||||
|
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||||
|
BackColor = Color.Transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
|
{
|
||||||
|
_surface.Paint(this, e.Graphics);
|
||||||
|
base.OnPaint(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
_surface.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using VibranceHud.Design;
|
||||||
|
using VibranceHud.Theming;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
internal sealed class CardSurface : IDisposable
|
||||||
|
{
|
||||||
|
private Bitmap? _glass;
|
||||||
|
|
||||||
|
private Size _glassSize;
|
||||||
|
|
||||||
|
private string _glassTheme = "";
|
||||||
|
|
||||||
|
private Size _failedSize;
|
||||||
|
|
||||||
|
private string _failedKey = "";
|
||||||
|
|
||||||
|
private bool _failureLogged;
|
||||||
|
|
||||||
|
private static int Radius => Tokens.Scale(8);
|
||||||
|
|
||||||
|
internal Action<string>? FailPointForTest { get; set; }
|
||||||
|
|
||||||
|
private static bool IsGdiFailure(Exception ex)
|
||||||
|
{
|
||||||
|
if (!(ex is OutOfMemoryException) && !(ex is ExternalException) && !(ex is ArgumentException))
|
||||||
|
{
|
||||||
|
return ex is InvalidOperationException;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LogOnce(Exception ex)
|
||||||
|
{
|
||||||
|
if (!_failureLogged)
|
||||||
|
{
|
||||||
|
_failureLogged = true;
|
||||||
|
CrashLog.Write(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Paint(Control owner, Graphics g)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (SlateSurface.Active && AppBackground.IsSet)
|
||||||
|
{
|
||||||
|
Glass.PaintPanel(g, new RectangleF(0.5f, 0.5f, owner.Width - 1, owner.Height - 1), Radius, Glass.BackdropOffsetOf(owner));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bitmap = EnsureGlass(owner.Size);
|
||||||
|
if (bitmap != null)
|
||||||
|
{
|
||||||
|
FailPointForTest?.Invoke("draw");
|
||||||
|
g.DrawImageUnscaled(bitmap, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (IsGdiFailure(ex))
|
||||||
|
{
|
||||||
|
LogOnce(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PaintSignalCard(Graphics g, Size size)
|
||||||
|
{
|
||||||
|
RectangleF rectangleF = new RectangleF(0.5f, 0.5f, size.Width - 1, size.Height - 1);
|
||||||
|
float num = Radius;
|
||||||
|
using GraphicsPath graphicsPath = new GraphicsPath();
|
||||||
|
graphicsPath.AddArc(rectangleF.X, rectangleF.Y, num, num, 180f, 90f);
|
||||||
|
graphicsPath.AddArc(rectangleF.Right - num, rectangleF.Y, num, num, 270f, 90f);
|
||||||
|
graphicsPath.AddArc(rectangleF.Right - num, rectangleF.Bottom - num, num, num, 0f, 90f);
|
||||||
|
graphicsPath.AddArc(rectangleF.X, rectangleF.Bottom - num, num, num, 90f, 90f);
|
||||||
|
graphicsPath.CloseFigure();
|
||||||
|
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||||
|
using (SolidBrush brush = new SolidBrush(SignalTokens.Ash.Surface1))
|
||||||
|
{
|
||||||
|
g.FillPath(brush, graphicsPath);
|
||||||
|
}
|
||||||
|
using Pen pen = new Pen(SignalTokens.Ash.Border, 1f);
|
||||||
|
g.DrawPath(pen, graphicsPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Bitmap? EnsureGlass(Size size)
|
||||||
|
{
|
||||||
|
if (size.Width < 2 || size.Height < 2)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
string text = Theme.CurrentName + "|" + Glass.ActiveChrome;
|
||||||
|
if (_glass != null && _glassSize == size && _glassTheme == text)
|
||||||
|
{
|
||||||
|
return _glass;
|
||||||
|
}
|
||||||
|
if (_failedSize == size && _failedKey == text)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FailPointForTest?.Invoke("build");
|
||||||
|
_glass?.Dispose();
|
||||||
|
_glass = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb);
|
||||||
|
_glassSize = size;
|
||||||
|
_glassTheme = text;
|
||||||
|
using Graphics graphics = Graphics.FromImage(_glass);
|
||||||
|
graphics.Clear(Color.Transparent);
|
||||||
|
if (SlateSurface.Active)
|
||||||
|
{
|
||||||
|
Glass.PaintPanel(graphics, new RectangleF(0.5f, 0.5f, size.Width - 1, size.Height - 1), Radius);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PaintSignalCard(graphics, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
_glass?.Dispose();
|
||||||
|
_glass = null;
|
||||||
|
_glassSize = Size.Empty;
|
||||||
|
_glassTheme = "";
|
||||||
|
_failedSize = size;
|
||||||
|
_failedKey = text;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
_failedSize = Size.Empty;
|
||||||
|
_failedKey = "";
|
||||||
|
return _glass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_glass?.Dispose();
|
||||||
|
_glass = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public sealed record ChannelMix(float RR, float RG, float RB, float GR, float GG, float GB, float BR, float BG, float BB)
|
||||||
|
{
|
||||||
|
public bool IsIdentity => Near(Identity);
|
||||||
|
|
||||||
|
public static readonly ChannelMix Identity = new ChannelMix(1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f);
|
||||||
|
|
||||||
|
private const float Tolerance = 0.0005f;
|
||||||
|
|
||||||
|
public bool Near(ChannelMix other)
|
||||||
|
{
|
||||||
|
return ToArray().Zip(other.ToArray(), (float a, float b) => Math.Abs(a - b)).All((float d) => d <= 0.0005f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] ToArray()
|
||||||
|
{
|
||||||
|
return new float[9] { RR, RG, RB, GR, GG, GB, BR, BG, BB };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChannelMix FromArray(float[]? nine)
|
||||||
|
{
|
||||||
|
if (nine == null || nine.Length != 9 || nine.Any((float v) => float.IsNaN(v) || float.IsInfinity(v)))
|
||||||
|
{
|
||||||
|
return Identity;
|
||||||
|
}
|
||||||
|
return new ChannelMix(nine[0], nine[1], nine[2], nine[3], nine[4], nine[5], nine[6], nine[7], nine[8]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChannelMix FromPercent(params int[] nine)
|
||||||
|
{
|
||||||
|
if (nine.Length != 9)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("a channel mix is nine numbers", "nine");
|
||||||
|
}
|
||||||
|
return FromArray(nine.Select((int v) => (float)v / 100f).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] ToMatrix()
|
||||||
|
{
|
||||||
|
return new float[25]
|
||||||
|
{
|
||||||
|
RR, RG, RB, 0f, 0f, GR, GG, GB, 0f, 0f,
|
||||||
|
BR, BG, BB, 0f, 0f, 0f, 0f, 0f, 1f, 0f,
|
||||||
|
0f, 0f, 0f, 0f, 1f
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] ComposeInto(float[] matrix)
|
||||||
|
{
|
||||||
|
if (!IsIdentity)
|
||||||
|
{
|
||||||
|
return ColourVision.Compose(matrix, ToMatrix());
|
||||||
|
}
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return "[" + string.Join(",", from v in ToArray()
|
||||||
|
select Math.Round(v * 100f).ToString(CultureInfo.InvariantCulture)) + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,288 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using VibranceHud.Design;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public sealed class ChipButton : Control
|
||||||
|
{
|
||||||
|
private sealed class ChipAccessibleObject : ControlAccessibleObject
|
||||||
|
{
|
||||||
|
private readonly ChipButton _owner;
|
||||||
|
|
||||||
|
public override AccessibleStates State => (AccessibleStates)((int)base.State | (_owner._active ? 16 : 0));
|
||||||
|
|
||||||
|
public ChipAccessibleObject(ChipButton owner)
|
||||||
|
: base(owner)
|
||||||
|
{
|
||||||
|
_owner = owner;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _active;
|
||||||
|
|
||||||
|
private readonly HoverFade _fade;
|
||||||
|
|
||||||
|
private readonly HoverFade _press;
|
||||||
|
|
||||||
|
private readonly OutsideFocusRing _ring;
|
||||||
|
|
||||||
|
private string _suffix = "";
|
||||||
|
|
||||||
|
private ContentAlignment _align = ContentAlignment.MiddleCenter;
|
||||||
|
|
||||||
|
public int Level { get; init; }
|
||||||
|
|
||||||
|
public bool Active
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _active;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_active != value)
|
||||||
|
{
|
||||||
|
_active = value;
|
||||||
|
Invalidate();
|
||||||
|
if (IsHandleCreated)
|
||||||
|
{
|
||||||
|
AccessibilityNotifyClients(AccessibleEvents.StateChange, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Suffix
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _suffix;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
|
if (!(_suffix == value))
|
||||||
|
{
|
||||||
|
_suffix = value;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentAlignment TextAlign
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _align;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_align != value)
|
||||||
|
{
|
||||||
|
_align = value;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override AccessibleObject CreateAccessibilityInstance()
|
||||||
|
{
|
||||||
|
return new ChipAccessibleObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChipButton()
|
||||||
|
{
|
||||||
|
_fade = new HoverFade(this);
|
||||||
|
_press = new HoverFade(this);
|
||||||
|
_ring = new OutsideFocusRing(this, () => Radius(ControlInk.Dpi(this)));
|
||||||
|
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||||
|
BackColor = Color.Transparent;
|
||||||
|
Cursor = Cursors.Hand;
|
||||||
|
Height = 32;
|
||||||
|
TabStop = true;
|
||||||
|
SetStyle(ControlStyles.Selectable, value: true);
|
||||||
|
AccessibleRole = AccessibleRole.PushButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnTextChanged(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnTextChanged(e);
|
||||||
|
AccessibleName = Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnGotFocus(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnGotFocus(e);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnLostFocus(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnLostFocus(e);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseDown(e);
|
||||||
|
Focus();
|
||||||
|
if (e.Button == MouseButtons.Left)
|
||||||
|
{
|
||||||
|
_press.Snap(hot: true);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseUp(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseUp(e);
|
||||||
|
_press.Set(hot: false);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnKeyDown(KeyEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnKeyDown(e);
|
||||||
|
Keys keyCode = e.KeyCode;
|
||||||
|
if ((keyCode == Keys.Return || keyCode == Keys.Space) ? true : false)
|
||||||
|
{
|
||||||
|
e.Handled = true;
|
||||||
|
OnClick(EventArgs.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void TestPressKey(Keys key)
|
||||||
|
{
|
||||||
|
OnKeyDown(new KeyEventArgs(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void TestSetHover(bool on)
|
||||||
|
{
|
||||||
|
_fade.Snap(on);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void TestSetPressed(bool on)
|
||||||
|
{
|
||||||
|
_press.Snap(on);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseEnter(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseEnter(e);
|
||||||
|
_fade.Set(hot: true);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseLeave(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseLeave(e);
|
||||||
|
_fade.Set(hot: false);
|
||||||
|
_press.Set(hot: false);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnEnabledChanged(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnEnabledChanged(e);
|
||||||
|
Cursor = (Enabled ? Cursors.Hand : Cursors.Default);
|
||||||
|
_fade.Snap(hot: false);
|
||||||
|
_press.Snap(hot: false);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnParentChanged(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnParentChanged(e);
|
||||||
|
_ring.Rehook();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
_ring.Release();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float Radius(int dpi)
|
||||||
|
{
|
||||||
|
return ControlInk.PxF(dpi, 4f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Font LabelFont(bool strong)
|
||||||
|
{
|
||||||
|
if (!strong)
|
||||||
|
{
|
||||||
|
return Font;
|
||||||
|
}
|
||||||
|
if (Math.Abs(Font.SizeInPoints - Fonts.Body.SizeInPoints) < 0.1f)
|
||||||
|
{
|
||||||
|
return Fonts.BodyBold;
|
||||||
|
}
|
||||||
|
if (Math.Abs(Font.SizeInPoints - Fonts.Caption.SizeInPoints) < 0.1f)
|
||||||
|
{
|
||||||
|
return Fonts.CaptionBold;
|
||||||
|
}
|
||||||
|
return Font;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
|
{
|
||||||
|
Graphics graphics = e.Graphics;
|
||||||
|
int dpi = ControlInk.Dpi(this);
|
||||||
|
Color transparent = Color.Transparent;
|
||||||
|
float t = (Enabled ? _fade.Value : 0f);
|
||||||
|
float t2 = (Enabled ? _press.Value : 0f);
|
||||||
|
Color fill;
|
||||||
|
Color edge;
|
||||||
|
Color foreColor;
|
||||||
|
Color foreColor2;
|
||||||
|
if (!Enabled)
|
||||||
|
{
|
||||||
|
fill = (_active ? ControlInk.Surface2 : transparent);
|
||||||
|
edge = (_active ? ControlInk.Surface2 : ControlInk.TextDisabled);
|
||||||
|
foreColor = (foreColor2 = ControlInk.TextDisabledInk);
|
||||||
|
}
|
||||||
|
else if (_active)
|
||||||
|
{
|
||||||
|
fill = (edge = ControlInk.Accent);
|
||||||
|
foreColor = ControlInk.OnAccent;
|
||||||
|
foreColor2 = ControlInk.SelectedSuffix;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Color hover = ControlInk.Hover;
|
||||||
|
fill = ControlInk.Mix(ControlInk.Mix(Color.FromArgb(0, hover), hover, t), ControlInk.Pressed, t2);
|
||||||
|
edge = ControlInk.Edge;
|
||||||
|
foreColor = ControlInk.Text1;
|
||||||
|
foreColor2 = ControlInk.Text3;
|
||||||
|
}
|
||||||
|
ControlInk.PaintBox(graphics, ClientSize, Radius(dpi), ControlInk.Hairline(dpi), fill, edge);
|
||||||
|
Font font = LabelFont(_active);
|
||||||
|
int width = TextRenderer.MeasureText(graphics, Text, font, Size.Empty, TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding).Width;
|
||||||
|
int num = ControlInk.Px(dpi, 8);
|
||||||
|
Font caption = Fonts.Caption;
|
||||||
|
int num2 = ((_suffix.Length != 0) ? TextRenderer.MeasureText(graphics, _suffix, caption, Size.Empty, TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding).Width : 0);
|
||||||
|
int num3 = width + ((num2 > 0) ? (num + num2) : 0);
|
||||||
|
int num4 = ((_align == ContentAlignment.MiddleLeft) ? ControlInk.Px(dpi, 12) : ((Width - num3) / 2));
|
||||||
|
TextRenderer.DrawText(graphics, Text, font, new Rectangle(num4, 0, width + 2, Height), foreColor, TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||||
|
if (num2 > 0)
|
||||||
|
{
|
||||||
|
TextRenderer.DrawText(graphics, _suffix, caption, new Rectangle(num4 + width + num, 0, num2 + 2, Height), foreColor2, TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||||
|
}
|
||||||
|
if (Focused && ShowFocusCues)
|
||||||
|
{
|
||||||
|
_ring.Show(show: true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_ring.Show(show: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class ColorAdjust
|
||||||
|
{
|
||||||
|
public const float WarmGreenCut = 0.12f;
|
||||||
|
|
||||||
|
public const float WarmBlueCut = 0.38f;
|
||||||
|
|
||||||
|
public const float VibranceRedHold = 0.55f;
|
||||||
|
|
||||||
|
public static float[] Build(float saturation, float brightness, float warmth)
|
||||||
|
{
|
||||||
|
return BuildWithVibranceNumbers(saturation, 1f, 1f, 1f, brightness, warmth);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static float[] BuildWithVibranceNumbers(float saturation, float red, float chroma, float contrast, float brightness, float warmth)
|
||||||
|
{
|
||||||
|
return BuildWithVibranceNumbers(saturation, red, chroma, contrast, brightness, warmth, ColourDepth.Neutral);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static float[] BuildWithVibranceNumbers(float saturation, float red, float chroma, float contrast, float brightness, float warmth, ColourDepth depth)
|
||||||
|
{
|
||||||
|
float[] array = (depth.IsNeutral ? SaturationMatrix.Build(saturation * red, saturation * chroma, saturation * chroma) : SaturationMetrics.BuildWithVibranceNumbers(depth.Formula, saturation, red, chroma, depth));
|
||||||
|
float num = Math.Max(0f, warmth);
|
||||||
|
float num2 = Math.Max(0f, 0f - warmth);
|
||||||
|
float num3 = 1f - 0.38f * num2;
|
||||||
|
float num4 = 1f - 0.12f * (num + num2);
|
||||||
|
float num5 = 1f - 0.38f * num;
|
||||||
|
float num6 = brightness * num3 * contrast;
|
||||||
|
float num7 = brightness * num4 * contrast;
|
||||||
|
float num8 = brightness * num5 * contrast;
|
||||||
|
float num9 = 0.5f * (1f - contrast);
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
array[i * 5] *= num6;
|
||||||
|
array[i * 5 + 1] *= num7;
|
||||||
|
array[i * 5 + 2] *= num8;
|
||||||
|
}
|
||||||
|
array[20] = num9;
|
||||||
|
array[21] = num9;
|
||||||
|
array[22] = num9;
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsIdentity(float saturation, float brightness, float warmth)
|
||||||
|
{
|
||||||
|
return IsIdentity(saturation, 1f, brightness, warmth);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsIdentity(float saturation, float vibrance, float brightness, float warmth)
|
||||||
|
{
|
||||||
|
return IsIdentity(saturation, vibrance, 1f, brightness, warmth);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsIdentity(float saturation, float vibrance, float contrast, float brightness, float warmth)
|
||||||
|
{
|
||||||
|
if (Math.Abs(saturation - 1f) < 0.001f && Math.Abs(vibrance - 1f) < 0.001f && Math.Abs(contrast - 1f) < 0.001f && Math.Abs(brightness - 1f) < 0.001f)
|
||||||
|
{
|
||||||
|
return Math.Abs(warmth) < 0.001f;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class ColourBalance
|
||||||
|
{
|
||||||
|
public const int MinHue = -180;
|
||||||
|
|
||||||
|
public const int MaxHue = 180;
|
||||||
|
|
||||||
|
public const int MinGain = 50;
|
||||||
|
|
||||||
|
public const int MaxGain = 150;
|
||||||
|
|
||||||
|
public static bool GainsNeutral(int red, int green, int blue)
|
||||||
|
{
|
||||||
|
if (red == 100 && green == 100)
|
||||||
|
{
|
||||||
|
return blue == 100;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsNeutral(int hue, int red, int green, int blue)
|
||||||
|
{
|
||||||
|
if (hue == 0)
|
||||||
|
{
|
||||||
|
return GainsNeutral(red, green, blue);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float[] HueMatrix(int degrees)
|
||||||
|
{
|
||||||
|
double num = (double)Math.Clamp(degrees, -180, 180) * Math.PI / 180.0;
|
||||||
|
double num2 = Math.Cos(num);
|
||||||
|
double num3 = Math.Sin(num);
|
||||||
|
double num4 = (1.0 - num2) / 3.0;
|
||||||
|
double num5 = num3 / Math.Sqrt(3.0);
|
||||||
|
int[,] array = new int[3, 3]
|
||||||
|
{
|
||||||
|
{ 0, -1, 1 },
|
||||||
|
{ 1, 0, -1 },
|
||||||
|
{ -1, 1, 0 }
|
||||||
|
};
|
||||||
|
float[] array2 = new float[25];
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
array2[i * 5 + j] = (float)(((i == j) ? num2 : 0.0) + num4 + num5 * (double)array[j, i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array2[18] = 1f;
|
||||||
|
array2[24] = 1f;
|
||||||
|
return array2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float[] GainMatrix(int red, int green, int blue)
|
||||||
|
{
|
||||||
|
return new float[25]
|
||||||
|
{
|
||||||
|
(float)Math.Clamp(red, 50, 150) / 100f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
(float)Math.Clamp(green, 50, 150) / 100f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
(float)Math.Clamp(blue, 50, 150) / 100f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
1f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
1f
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float[] ComposeInto(float[] matrix, int hue, int red, int green, int blue)
|
||||||
|
{
|
||||||
|
if (IsNeutral(hue, red, green, blue))
|
||||||
|
{
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
float[] array = matrix;
|
||||||
|
if (hue != 0)
|
||||||
|
{
|
||||||
|
array = Multiply(array, HueMatrix(hue));
|
||||||
|
}
|
||||||
|
if (!GainsNeutral(red, green, blue))
|
||||||
|
{
|
||||||
|
array = Multiply(array, GainMatrix(red, green, blue));
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static float[] Multiply(float[] a, float[] b)
|
||||||
|
{
|
||||||
|
float[] array = new float[25];
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 5; j++)
|
||||||
|
{
|
||||||
|
double num = 0.0;
|
||||||
|
for (int k = 0; k < 5; k++)
|
||||||
|
{
|
||||||
|
num += (double)a[i * 5 + k] * (double)b[k * 5 + j];
|
||||||
|
}
|
||||||
|
array[i * 5 + j] = (float)num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public readonly record struct ColourDepth(SaturationMetric Formula = SaturationMetric.Rec709, int Darken = 0, int DarkenHue = 120, int HueTurn = 0, int HueTurnAmount = 100, int HueComplement = 0)
|
||||||
|
{
|
||||||
|
public static ColourDepth Neutral => new ColourDepth(SaturationMetric.Rec709, 0, 120, 0, 100, 0);
|
||||||
|
|
||||||
|
public bool IsNeutral
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Formula == SaturationMetric.Rec709 && Darken == 0 && HueComplement == 0)
|
||||||
|
{
|
||||||
|
if (HueTurn != 0)
|
||||||
|
{
|
||||||
|
return HueTurnAmount == 0;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public const int MinDarken = 0;
|
||||||
|
|
||||||
|
public const int MaxDarken = 400;
|
||||||
|
|
||||||
|
public const int MinDarkenHue = 0;
|
||||||
|
|
||||||
|
public const int MaxDarkenHue = 359;
|
||||||
|
|
||||||
|
public const int MinHueTurn = -180;
|
||||||
|
|
||||||
|
public const int MaxHueTurn = 180;
|
||||||
|
|
||||||
|
public const int MinHueTurnAmount = 0;
|
||||||
|
|
||||||
|
public const int MaxHueTurnAmount = 100;
|
||||||
|
|
||||||
|
public const int MinHueComplement = 0;
|
||||||
|
|
||||||
|
public const int MaxHueComplement = 100;
|
||||||
|
|
||||||
|
public ColourDepth Clamped()
|
||||||
|
{
|
||||||
|
return new ColourDepth(Enum.IsDefined(typeof(SaturationMetric), Formula) ? Formula : SaturationMetric.Rec709, Math.Clamp(Darken, 0, 400), Math.Clamp(DarkenHue, 0, 359), Math.Clamp(HueTurn, -180, 180), Math.Clamp(HueTurnAmount, 0, 100), Math.Clamp(HueComplement, 0, 100));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public readonly record struct ColourReachFacts(bool ExclusiveFullscreen, bool OverlayLive, DxInitFailureKind DxFailure, bool DxTried, bool DisplayIsCarryingTheLook = false, string? WhatTheDisplayCannotHold = null, GammaDelivery RampOutcome = default(GammaDelivery), bool CompetitiveOn = false);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public readonly record struct ColourReachLine(ColourReachSeverity Severity, string Text);
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public enum ColourReachSeverity
|
||||||
|
{
|
||||||
|
Ok,
|
||||||
|
Note,
|
||||||
|
Refused
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
public static class ColourReachStatus
|
||||||
|
{
|
||||||
|
public const string FullscreenSentence = "Fullscreen: colour comes from the driver. Borderless gives the full look.";
|
||||||
|
|
||||||
|
public const string CompetitiveSentence = "Colour on the driver: in full-screen games Competitive mode keeps your colour on the NVIDIA driver. Hue, channel mix, colour aids and Eye care pause there.";
|
||||||
|
|
||||||
|
public const string ScreenEffectRefusedSentence = "Colour engine off: Windows could not start the screen effect (Magnification). Restart PlexusX; if it stays off, tell us.";
|
||||||
|
|
||||||
|
public const string DisplayCarriesItSentence = "Full screen: your monitor is holding this look. It is the closest it can get.";
|
||||||
|
|
||||||
|
public const string RampRefusedSentence = "Full screen: Windows refused this look on this monitor. Borderless gives the full look.";
|
||||||
|
|
||||||
|
public const string RampIgnoredHdrSentence = "Full screen: HDR is on, and Windows ignores this look there. Borderless gives the full look.";
|
||||||
|
|
||||||
|
public const string LookShowsInBorderless = "This look shows in Borderless or Windowed mode. In exclusive fullscreen the game only gets the driver's colour.";
|
||||||
|
|
||||||
|
public const string LookNeedsPaidColourControls = "This look needs the paid colour controls, and they are off on this PC right now.";
|
||||||
|
|
||||||
|
public static string DisplayCarriesItButNot(string missing)
|
||||||
|
{
|
||||||
|
return "Full screen: your monitor is holding this look, but not " + missing + ". Borderless gives the full look.";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string RampSoftenedSentence(string step)
|
||||||
|
{
|
||||||
|
return "Full screen: Windows only let " + StepWords(step) + " of this look through. Borderless gives the full look.";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string StepWords(string step)
|
||||||
|
{
|
||||||
|
return step switch
|
||||||
|
{
|
||||||
|
"1/2" => "half",
|
||||||
|
"1/4" => "a quarter",
|
||||||
|
"1/8" => "an eighth",
|
||||||
|
_ => "part",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ColourReachLine For(ColourReachFacts facts)
|
||||||
|
{
|
||||||
|
if (!facts.OverlayLive && (!facts.DxTried || facts.DxFailure == DxInitFailureKind.None))
|
||||||
|
{
|
||||||
|
return new ColourReachLine(ColourReachSeverity.Refused, "Colour engine off: Windows could not start the screen effect (Magnification). Restart PlexusX; if it stays off, tell us.");
|
||||||
|
}
|
||||||
|
if (!facts.OverlayLive)
|
||||||
|
{
|
||||||
|
return new ColourReachLine(ColourReachSeverity.Refused, "Colour engine off: " + Because(facts.DxFailure) + ".");
|
||||||
|
}
|
||||||
|
if (facts.ExclusiveFullscreen && facts.DisplayIsCarryingTheLook && !facts.RampOutcome.IsFull)
|
||||||
|
{
|
||||||
|
return new ColourReachLine(ColourReachSeverity.Note, facts.RampOutcome.Kind switch
|
||||||
|
{
|
||||||
|
GammaDeliveryKind.Softened => RampSoftenedSentence(facts.RampOutcome.Step),
|
||||||
|
GammaDeliveryKind.IgnoredHdr => "Full screen: HDR is on, and Windows ignores this look there. Borderless gives the full look.",
|
||||||
|
_ => "Full screen: Windows refused this look on this monitor. Borderless gives the full look.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (facts.ExclusiveFullscreen && facts.DisplayIsCarryingTheLook)
|
||||||
|
{
|
||||||
|
return new ColourReachLine(ColourReachSeverity.Note, string.IsNullOrEmpty(facts.WhatTheDisplayCannotHold) ? "Full screen: your monitor is holding this look. It is the closest it can get." : DisplayCarriesItButNot(facts.WhatTheDisplayCannotHold));
|
||||||
|
}
|
||||||
|
if (facts.ExclusiveFullscreen)
|
||||||
|
{
|
||||||
|
return new ColourReachLine(ColourReachSeverity.Note, "Fullscreen: colour comes from the driver. Borderless gives the full look.");
|
||||||
|
}
|
||||||
|
if (facts.CompetitiveOn)
|
||||||
|
{
|
||||||
|
return new ColourReachLine(ColourReachSeverity.Note, "Colour on the driver: in full-screen games Competitive mode keeps your colour on the NVIDIA driver. Hue, channel mix, colour aids and Eye care pause there.");
|
||||||
|
}
|
||||||
|
return new ColourReachLine(ColourReachSeverity.Ok, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Because(DxInitFailureKind kind)
|
||||||
|
{
|
||||||
|
return kind switch
|
||||||
|
{
|
||||||
|
DxInitFailureKind.None => "DirectX started but no monitor could be rendered",
|
||||||
|
DxInitFailureKind.NoCompatibleAdapter => "no graphics card here can do DirectX 11",
|
||||||
|
DxInitFailureKind.DeviceCreationFailed => "Windows would not give PlexusX a DirectX device",
|
||||||
|
DxInitFailureKind.NoOutputs => "Windows reported no display",
|
||||||
|
DxInitFailureKind.DriverIssue => "your display driver turned DirectX 11 down",
|
||||||
|
DxInitFailureKind.SdkIssue => "the DirectX 11 runtime is not installed",
|
||||||
|
DxInitFailureKind.OutOfMemory => "your graphics memory is full",
|
||||||
|
DxInitFailureKind.CaptureInUse => "another app is capturing this display",
|
||||||
|
DxInitFailureKind.Unknown => "DirectX 11 would not start on this PC",
|
||||||
|
_ => "DirectX 11 would not start on this PC",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using VibranceHud.Support;
|
||||||
|
|
||||||
|
namespace VibranceHud;
|
||||||
|
|
||||||
|
internal static class ColourTrace
|
||||||
|
{
|
||||||
|
internal static readonly bool Enabled = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PLEXUSX_SAT_TRACE"));
|
||||||
|
|
||||||
|
private static readonly string Path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "plexusx-sat.log");
|
||||||
|
|
||||||
|
private static readonly object Gate = new object();
|
||||||
|
|
||||||
|
private const int Frames = 12;
|
||||||
|
|
||||||
|
public static void Value(string name, int was, int now)
|
||||||
|
{
|
||||||
|
if (Enabled && was != now)
|
||||||
|
{
|
||||||
|
Write(string.Format(CultureInfo.InvariantCulture, "{0} {1}->{2} {3}", name, was, now, Caller()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Screen(bool cleared, int saturation)
|
||||||
|
{
|
||||||
|
if (Enabled)
|
||||||
|
{
|
||||||
|
Write(string.Format(CultureInfo.InvariantCulture, "SCREEN {0} (saturation still reads {1}) {2}", cleared ? "CLEARED - picture now neutral" : "applied", saturation, Caller()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Meter(ReassertMeter meter)
|
||||||
|
{
|
||||||
|
if (Enabled && meter != null)
|
||||||
|
{
|
||||||
|
Write("REASSERT" + Environment.NewLine + meter.Describe());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Refused(string layer, string why)
|
||||||
|
{
|
||||||
|
if (Enabled)
|
||||||
|
{
|
||||||
|
Write(string.Format(CultureInfo.InvariantCulture, "REFUSED {0}: {1} {2}", layer, why, Caller()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Fallback(string what)
|
||||||
|
{
|
||||||
|
if (Enabled)
|
||||||
|
{
|
||||||
|
Write(string.Format(CultureInfo.InvariantCulture, "FALLBACK {0} {1}", what, Caller()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string Caller()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StackTrace stackTrace = new StackTrace(2, fNeedFileInfo: false);
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
int num = Math.Min(12, stackTrace.FrameCount);
|
||||||
|
for (int i = 0; i < num; i++)
|
||||||
|
{
|
||||||
|
MethodBase methodBase = stackTrace.GetFrame(i)?.GetMethod();
|
||||||
|
if (!(methodBase == null))
|
||||||
|
{
|
||||||
|
stringBuilder.Append(methodBase.DeclaringType?.Name).Append('.').Append(methodBase.Name)
|
||||||
|
.Append(" <- ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stringBuilder.ToString();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return "(no stack)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Write(string message)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string text = string.Format(CultureInfo.InvariantCulture, "{0:HH:mm:ss.fff} {1}", DateTime.Now, message);
|
||||||
|
lock (Gate)
|
||||||
|
{
|
||||||
|
File.AppendAllText(Path, text + Environment.NewLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||