Skip to content

Commit

Permalink
v0.4.0 Formal Release
Browse files Browse the repository at this point in the history
  • Loading branch information
ResetXPDR committed Dec 16, 2024
1 parent 38f5a4c commit 0b8ee35
Show file tree
Hide file tree
Showing 17 changed files with 700 additions and 150 deletions.
Binary file modified DynamicLOD_ResetEdition-latest.zip
Binary file not shown.
64 changes: 60 additions & 4 deletions DynamicLOD_ResetEdition/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ public partial class App : Application
private TaskbarIcon notifyIcon;

public static new App Current => Application.Current as App;
public static string ConfigFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DynamicLOD_ResetEdition\DynamicLOD_ResetEdition.config";
public static string AppDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DynamicLOD_ResetEdition\bin";
public static readonly string ConfigFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DynamicLOD_ResetEdition\DynamicLOD_ResetEdition.config";
public static readonly string ConfigFile2024 = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DynamicLOD_ResetEdition\DynamicLOD2024_ResetEdition.config";
public static readonly string AppDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DynamicLOD_ResetEdition\bin";
public static readonly string msConfigStore = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalCache\UserCfg.opt";
public static readonly string msConfigSteam = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft Flight Simulator\UserCfg.opt";
public static readonly string msConfigStore2024 = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Packages\Microsoft.Limitless_8wekyb3d8bbwe\LocalCache\UserCfg.opt";
public static readonly string msConfigSteam2024 = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft Flight Simulator 2024\UserCfg.opt";


protected override void OnStartup(StartupEventArgs e)
{
Expand All @@ -39,6 +45,20 @@ protected override void OnStartup(StartupEventArgs e)
return;
}

if (Process.GetProcessesByName("MSFS_AutoFPS").Length > 0)
{
MessageBox.Show("MSFS_AutoFPS is already running!", "Critical Error", MessageBoxButton.OK, MessageBoxImage.Error);
Application.Current.Shutdown();
return;
}

if (Process.GetProcessesByName("MSFS2024_AutoFPS").Length > 0)
{
MessageBox.Show("MSFS2024_AutoFPS is already running!", "Critical Error", MessageBoxButton.OK, MessageBoxImage.Error);
Application.Current.Shutdown();
return;
}

if (Process.GetProcessesByName("MSFS2020_AutoFPS").Length > 0)
{
MessageBox.Show("MSFS2020_AutoFPS is already running!", "Critical Error", MessageBoxButton.OK, MessageBoxImage.Error);
Expand All @@ -61,7 +81,7 @@ protected override void OnStartup(StartupEventArgs e)
string ConfigFileDefault = Directory.GetCurrentDirectory() + @"\DynamicLOD_ResetEdition.config";
if (!File.Exists(ConfigFileDefault))
{
MessageBox.Show("No Configuration File found! Closing ...", "Critical Error", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show("No MSFS 2020 Configuration File found! Closing ...", "Critical Error", MessageBoxButton.OK, MessageBoxImage.Error);
Application.Current.Shutdown();
return;
}
Expand All @@ -71,6 +91,20 @@ protected override void OnStartup(StartupEventArgs e)
}
}

if (!File.Exists(ConfigFile2024))
{
string ConfigFileDefault = Directory.GetCurrentDirectory() + @"\DynamicLOD2024_ResetEdition.config";
if (!File.Exists(ConfigFileDefault))
{
MessageBox.Show("No MSFS 2024 Configuration File found! Closing ...", "Critical Error", MessageBoxButton.OK, MessageBoxImage.Error);
Application.Current.Shutdown();
return;
}
else
{
File.Copy(ConfigFileDefault, ConfigFile2024);
}
}
Model = new();
InitLog();
InitSystray();
Expand Down Expand Up @@ -105,6 +139,28 @@ protected override void OnExit(ExitEventArgs e)
Logger.Log(LogLevel.Information, "App:OnExit", $"Resetting cloud quality to {ServiceModel.CloudQualityText(Model.DefaultCloudQ)} / VR {ServiceModel.CloudQualityText(Model.DefaultCloudQ_VR)}");
Model.MemoryAccess.SetCloudQ(Model.DefaultCloudQ);
Model.MemoryAccess.SetCloudQ_VR(Model.DefaultCloudQ_VR);
if (Model.isMSFS2024)
{
Logger.Log(LogLevel.Information, "App:OnExit", $"Resetting Dynamic Settings to PC {Model.DefaultDynSet} / VR {Model.DefaultDynSetVR}");
Model.MemoryAccess.SetDynSet(Model.DefaultDynSet);
Model.MemoryAccess.SetDynSetVR(Model.DefaultDynSetVR);
}
if (Model.MemoryAccess.GetTLOD_PC() == Model.DefaultTLOD) // As long as one setting restoration stuck
{
Model.ConfigurationFile.RemoveSetting("defaultTLOD");
Model.ConfigurationFile.RemoveSetting("defaultTLOD_VR");
Model.ConfigurationFile.RemoveSetting("defaultOLOD");
Model.ConfigurationFile.RemoveSetting("defaultOLOD_VR");
Model.ConfigurationFile.RemoveSetting("defaultCloudQ");
Model.ConfigurationFile.RemoveSetting("defaultCloudQ_VR");
if (Model.isMSFS2024)
{
Model.ConfigurationFile.RemoveSetting("defaultDynSet");
Model.ConfigurationFile.RemoveSetting("defaultDynSetVR");
}
Logger.Log(LogLevel.Information, "App:OnExit", "Default MSFS settings reset successful. Removed back up default MSFS settings from DynamicLOD_ResetEdition" + (Model.isMSFS2024 ? "2024" : "") + " config file.");
}
else Logger.Log(LogLevel.Information, "App:OnExit", "Default MSFS settings reset failed. Retained back up default MSFS settings in DynamicLOD_ResetEdition" + (Model.isMSFS2024 ? "2024" : "") + " config file.");
}
}
notifyIcon?.Dispose();
Expand All @@ -124,7 +180,7 @@ protected void OnTick(object sender, EventArgs e)

protected void InitLog()
{
string logFilePath = @"..\log\" + Model.GetSetting("logFilePath", "DynamicLOD_ResetEdition.log");
string logFilePath = @"..\log\DynamicLOD_ResetEdition.log";
string logLevel = Model.GetSetting("logLevel", "Debug"); ;
LoggerConfiguration loggerConfiguration = new LoggerConfiguration().WriteTo.File(logFilePath, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 3,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {Message} {NewLine}{Exception}");
Expand Down
15 changes: 12 additions & 3 deletions DynamicLOD_ResetEdition/ConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,39 @@ public class ConfigurationFile
{
private Dictionary<string, string> appSettings = new();
private XmlDocument xmlDoc = new();
private string ConfigFile = App.ConfigFile;
private string ConfigFileLast = App.ConfigFile;

public string this[string key]
{
get => GetSetting(key);
set => SetSetting(key, value);
}

public void LoadConfiguration()
public bool LoadConfiguration(bool isSim2024)
{
ConfigFile = isSim2024 ? App.ConfigFile2024 : App.ConfigFile;
xmlDoc = new();
xmlDoc.LoadXml(File.ReadAllText(App.ConfigFile));
xmlDoc.LoadXml(File.ReadAllText(ConfigFile));

XmlNode xmlSettings = xmlDoc.ChildNodes[1];
appSettings.Clear();
foreach(XmlNode child in xmlSettings.ChildNodes)
appSettings.Add(child.Attributes["key"].Value, child.Attributes["value"].Value);
if (ConfigFile != ConfigFileLast )
{
ConfigFileLast = ConfigFile;
return true;
}
else return false;
}

public void SaveConfiguration()
{
foreach (XmlNode child in xmlDoc.ChildNodes[1])
child.Attributes["value"].Value = appSettings[child.Attributes["key"].Value];

xmlDoc.Save(App.ConfigFile);
xmlDoc.Save(ConfigFile);
}
public bool SettingExists(string key)
{
Expand Down
57 changes: 57 additions & 0 deletions DynamicLOD_ResetEdition/DynamicLOD2024_ResetEdition.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<appSettings>
<add key="mfLvarPerFrame" value="15" />
<add key="ConfigVersion" value="1" />
<add key="logFilePath" value="DynamicLOD2024_ResetEdition.log" />
<add key="logLevel" value="Debug" />
<add key="waitForConnect" value="true" />
<add key="openWindow" value="true" />
<add key="simBinary" value="FlightSimulator2024" />
<add key="simModule" value="WwiseLibPCx64P.dll" />
<add key="offsetPointerTlod" value="0x358" />
<add key="offsetPointerTlodVr" value="0x480" />
<add key="offsetPointerOlod" value="0x36C" />
<add key="offsetPointerOlodVR" value="0x494" />
<add key="offsetPointerCloudQ" value="0x3A4" />
<add key="offsetPointerCloudQVr" value="0x4CC" />
<add key="offsetPointerVrMode" value="0x334" />
<add key="offsetPointerFgMode" value="0x304" />
<add key="offsetPointerAnsio" value="0x20" />
<add key="offsetPointerDynSet" value="0x328" />
<add key="offsetPointerDynSetVR" value="0x329" />
<add key="offsetPointerCubeMap" value="0x6C" />
<add key="simMinLod" value="10" />
<add key="selectedProfile" value="0" />
<add key="tlodPairs0" value="0:100|1500:150|5000:200" />
<add key="olodPairs0" value="0:100|2500:150|7500:200" />
<add key="isVr0" value="false" />
<add key="tlodPairs1" value="0:100|500:125|2000:150|7500:175|15000:200|20000:225" />
<add key="olodPairs1" value="0:100|500:125|2500:150|5000:175|9500:200" />
<add key="isVr1" value="false" />
<add key="tlodPairs2" value="0:100|1500:150|5000:200" />
<add key="olodPairs2" value="0:100|2500:150|7500:200" />
<add key="isVr2" value="true" />
<add key="tlodPairs3" value="0:100|1000:150|2000:200|3000:250|4000:300" />
<add key="olodPairs3" value="0:100|1000:70|2000:50|3000:30|4000:10" />
<add key="tlodPairs4" value="0:100|1000:200|2000:300|3000:400" />
<add key="olodPairs4" value="0:200|1000:150|2000:100|3000:50" />
<add key="tlodPairs5" value="0:100|1500:150|5000:200" />
<add key="olodPairs5" value="0:100|2500:150|7500:200" />
<add key="useTargetFps" value="false" />
<add key="targetFpsIndex" value="0" />
<add key="targetFps" value="40" />
<add key="constraintTicks" value="60" />
<add key="constraintDelayTicks" value="1" />
<add key="decreaseTlod" value="50" />
<add key="decreaseOlod" value="50" />
<add key="minLod" value="100" />
<add key="CruiseLODUpdates" value="false" />
<add key="DecCloudQ" value="false" />
<add key="CloudRecoveryFPS" value="0" />
<add key="PauseMSFSFocusLost" value="false" />
<add key="minTLod" value="100" />
<add key="minOLod" value="100" />
<add key="LodStepMax" value="false" />
<add key="LodStepMaxInc" value="5" />
<add key="LodStepMaxDec" value="5" />
</appSettings>
1 change: 0 additions & 1 deletion DynamicLOD_ResetEdition/DynamicLOD_ResetEdition.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<add key="openWindow" value="true" />
<add key="simBinary" value="FlightSimulator" />
<add key="simModule" value="WwiseLibPCx64P.dll" />
<add key="offsetModuleBase" value="0x004B2368" />
<add key="offsetPointerMain" value="0x3D0" />
<add key="offsetPointerTlod" value="0xC" />
<add key="offsetPointerTlodVr" value="0x114" />
Expand Down
10 changes: 9 additions & 1 deletion DynamicLOD_ResetEdition/DynamicLOD_ResetEdition.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
Work</Description>
<Copyright>Copyright © 2024</Copyright>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<Version>0.3.9</Version>
<Version>0.4.0</Version>
<AssemblyVersion>0.4.0</AssemblyVersion>
<FileVersion>0.4.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down Expand Up @@ -54,6 +56,12 @@ Work</Description>
<None Update="DynamicLOD_ResetEdition.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="DynamicLOD2024_ResetEdition.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="exe.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Microsoft.FlightSimulator.SimConnect.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
15 changes: 12 additions & 3 deletions DynamicLOD_ResetEdition/IPCManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ public static bool IsProcessRunning(string name)
return proc != null && proc.ProcessName == name;
}

public static bool IsSim2024()
{
return IsProcessRunning("FlightSimulator2024");
}

public static bool IsSimRunning()
{
return IsProcessRunning("FlightSimulator");
return (IsProcessRunning("FlightSimulator") || IsProcessRunning("FlightSimulator2024"));
}

public static bool WaitForConnection(ServiceModel model)
{
if (!IsSimRunning())
Expand Down Expand Up @@ -120,7 +125,11 @@ public static bool IsCamReady()
float value = SimConnect.ReadSimVar("CAMERA STATE", "Enum");
bool parkState = SimConnect.ReadSimVar("PLANE IN PARKING STATE", "Bool") == 1;

return value >= 2 && value <= 5 && !parkState;
// Logger.Log(LogLevel.Information, "IPCManager:IsCamReady", "Cam State " + value);

// New 2024 Camera States: 26 walkaround, 27 photo, 29 transition to in flight menu, 33 free look, 35 in flight menu

return ((value >= 2 && value <= 5) || value == 26 || value == 27 || value == 29 || value == 33 || value == 35) && !parkState;
}

public static void CloseSafe()
Expand Down
Loading

0 comments on commit 0b8ee35

Please sign in to comment.