Skip to content

Commit

Permalink
[skip ci] Load Genshin graphics settings from globalPerfData (#302)
Browse files Browse the repository at this point in the history
* Load Genshin graphics settings from ``globalPerfData``

* Throw an exception if registry key could not be found
  • Loading branch information
shatyuka authored Oct 29, 2023
1 parent c850fa3 commit 45ebc2a
Show file tree
Hide file tree
Showing 6 changed files with 572 additions and 444 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,132 +7,139 @@ internal static class DictionaryCategory
// HoYoooooooo :wogreeee:
internal static Dictionary<double, int> RenderResolutionOption = new Dictionary<double, int>
{
{ 0.6d, 1 },
{ 0.8d, 2 },
{ 0.9d, 9 },
{ 1.0d, 3 },
{ 1.1d, 4 },
{ 1.2d, 5 },
{ 1.3d, 6 },
{ 1.4d, 7 },
{ 1.5d, 8 }
{ 0.6d, 0 },
{ 0.8d, 1 },
{ 0.9d, 8 },
{ 1.0d, 2 },
{ 1.1d, 3 },
{ 1.2d, 4 },
{ 1.3d, 5 },
{ 1.4d, 6 },
{ 1.5d, 7 }
};
}

enum FPSOption : int
{
f30 = 1,
f60 = 2,
f45 = 3
f30,
f60,
f45
}

enum ShadowQualityOption
{
Lowest = 1,
Low = 2,
Medium = 3,
High = 4
Lowest,
Low,
Medium,
High
}

enum VisualEffectsOption
{
Lowest = 1,
Low = 2,
Medium = 3,
High = 4
Lowest,
Low,
Medium,
High
}

enum SFXQualityOption
{
Lowest = 1,
Low = 2,
Medium = 3,
High = 4
Lowest,
Low,
Medium,
High
}

enum EnvironmentDetailOption
{
Lowest = 1,
Low = 2,
Medium = 3,
High = 4,
Highest = 5
Lowest,
Low,
Medium,
High,
Highest
}

enum VerticalSyncOption
{
Off = 1,
On = 2
Off,
On
}

enum AntialiasingOption
{
Off = 1,
FSR2 = 2,
SMAA = 3
Off,
FSR2,
SMAA
}

enum VolumetricFogOption
{
Off = 1,
On = 2
Off,
On
}

enum ReflectionsOption
{
Off = 1,
On = 2
Off,
On
}

enum MotionBlurOption
{
Off = 1,
Low = 2,
High = 3,
Extreme = 4
Off,
Low,
High,
Extreme
}

enum BloomOption
{
Off = 1,
On = 2
Off,
On
}

enum CrowdDensityOption
{
Low = 1,
High = 2
Low,
High
}

enum SubsurfaceScatteringOption
{
Off = 1,
Medium = 2,
High = 3
Off,
Medium,
High
}

enum CoOpTeammateEffectsOption
{
Off = 1,
PartiallyOff = 2,
On = 3
Off,
PartiallyOff,
On
}

enum AnisotropicFilteringOption
{
x1 = 1,
x2 = 2,
x4 = 3,
x8 = 4,
x16 = 5
x1,
x2,
x4,
x8,
x16
}

enum GraphicsQualityOption
{
Lowest,
Low,
Medium,
High
}

enum GlobalIlluminationOption
{
Off = 1,
Medium = 2,
High = 3,
Extreme = 4
Off,
Medium,
High,
Extreme
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -320,36 +320,29 @@ public static GeneralData Load()
{
try
{
if (RegistryRoot == null) throw new NullReferenceException($"Cannot load {_ValueName} RegistryKey is unexpectedly not initialized!");
object? value = RegistryRoot.GetValue(_ValueName, null);
if (RegistryRoot == null) throw new NullReferenceException($"Cannot load {_ValueName} since RegistryKey is unexpectedly not initialized!");
object value = RegistryRoot.GetValue(_ValueName) ?? throw new ArgumentNullException($"Cannot find registry key {_ValueName}");

if (value != null)
{
ReadOnlySpan<byte> byteStr = (byte[])value;
ReadOnlySpan<byte> byteStr = (byte[])value;
#if DUMPGIJSON
// Dump GeneralData as raw string
LogWriteLine($"RAW Genshin Settings: {_ValueName}\r\n" +
$"{Encoding.UTF8.GetString(byteStr.TrimEnd((byte)0))}", LogType.Debug, true);

// Dump GeneralData as indented JSON output using GeneralData properties
LogWriteLine($"Deserialized Genshin Settings: {_ValueName}\r\n{byteStr
.Deserialize<GeneralData>(GenshinSettingsJSONContext.Default)
.Serialize(GenshinSettingsJSONContext.Default, false, true)}", LogType.Debug, true);
// Dump GeneralData as raw string
LogWriteLine($"RAW Genshin Settings: {_ValueName}\r\n" +
$"{Encoding.UTF8.GetString(byteStr.TrimEnd((byte)0))}", LogType.Debug, true);

// Dump GeneralData as indented JSON output using GeneralData properties
LogWriteLine($"Deserialized Genshin Settings: {_ValueName}\r\n{byteStr
.Deserialize<GeneralData>(GenshinSettingsJSONContext.Default)
.Serialize(GenshinSettingsJSONContext.Default, false, true)}", LogType.Debug, true);
#endif
#if DEBUG
LogWriteLine($"Loaded Genshin Settings: {_ValueName}", LogType.Debug, true);
LogWriteLine($"Loaded Genshin Settings: {_ValueName}", LogType.Debug, true);
#else
LogWriteLine($"Loaded Genshin Settings", LogType.Default, true);
LogWriteLine($"Loaded Genshin Settings", LogType.Default, true);
#endif
GeneralData data = byteStr.Deserialize<GeneralData>(GenshinSettingsJSONContext.Default) ?? new GeneralData();
data.graphicsData = GraphicsData.Load(data._graphicsData);
data.globalPerfData = new();
return data;
}
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
GraphicsData.Load(null);
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
return new GeneralData();
GeneralData data = byteStr.Deserialize<GeneralData>(GenshinSettingsJSONContext.Default) ?? new GeneralData();
data.graphicsData = GraphicsData.Load(data._graphicsData);
data.globalPerfData = GlobalPerfData.Load(data._globalPerfData, data.graphicsData);
return data;
}
catch (Exception ex)
{
Expand All @@ -372,8 +365,8 @@ public void Save()
{
if (RegistryRoot == null) throw new NullReferenceException($"Cannot save {_ValueName} since RegistryKey is unexpectedly not initialized!");

_graphicsData = graphicsData.Save();
_globalPerfData = globalPerfData.Create(graphicsData, graphicsData.volatileVersion);
_graphicsData = graphicsData.Create(globalPerfData);
_globalPerfData = globalPerfData.Save();

string data = this.Serialize(GenshinSettingsJSONContext.Default);
byte[] dataByte = Encoding.UTF8.GetBytes(data);
Expand Down
Loading

0 comments on commit 45ebc2a

Please sign in to comment.