Skip to content

Commit 52535c5

Browse files
committed
Improved VS Display / Update C# Client / Workaround/Bugfix for App not closing
1 parent e9a56e3 commit 52535c5

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

PilotsDeck_FNX2PLD/ElementManager.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,20 @@ private void UpdateFCU(MemoryPattern fcu, bool isLightTest)
247247
else
248248
result = "FPA\n";
249249

250-
int vs = 0;
250+
//int vs = 0;
251+
//if (isAltVs)
252+
// vs = fcu.MemoryOffsets["fcuVsFma"].GetValue() ?? 0;
253+
//else
254+
// vs = fcu.MemoryOffsets["fcuVsDisplay"].GetValue() ?? 0;
255+
256+
//if (!isAltVs)
257+
// result += "-----";
258+
int vs = fcu.MemoryOffsets["fcuVsDisplay"].GetValue() ?? 0;
259+
bool sourceIsDisplay = vs != 0;
251260
if (isAltVs)
252261
vs = fcu.MemoryOffsets["fcuVsFma"].GetValue() ?? 0;
253-
else
254-
vs = fcu.MemoryOffsets["fcuVsDisplay"].GetValue() ?? 0;
255262

256-
if (!isAltVs)
263+
if (!isAltVs && vs == 0)
257264
result += "-----";
258265
else if (isModeHdgVs)
259266
{

PilotsDeck_FNX2PLD/IPCManager.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FSUIPC;
22
using Serilog;
3+
using System.Diagnostics;
34

45
namespace PilotsDeck_FNX2PLD
56
{
@@ -74,6 +75,12 @@ public static double ReadLVar(string name)
7475
return result;
7576
}
7677

78+
public static bool IsSimOpen()
79+
{
80+
Process? msfs = Process.GetProcessesByName("FlightSimulator").FirstOrDefault();
81+
return msfs != null;
82+
}
83+
7784
public static bool IsAircraftFenix()
7885
{
7986
return currentAirString.Contains("fnx320");

PilotsDeck_FNX2PLD/PilotsDeck_FNX2PLD.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<IsPublishable>False</IsPublishable>
1010
<PlatformTarget>x64</PlatformTarget>
1111
<SignAssembly>False</SignAssembly>
12-
<AssemblyVersion>0.3</AssemblyVersion>
13-
<FileVersion>0.3</FileVersion>
14-
<Version>0.3</Version>
12+
<AssemblyVersion>0.4</AssemblyVersion>
13+
<FileVersion>0.4</FileVersion>
14+
<Version>0.4</Version>
1515
<Copyright>Fragtality © 2022</Copyright>
1616
</PropertyGroup>
1717

@@ -20,7 +20,7 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="FSUIPCClientDLL" Version="3.2.20" />
23+
<PackageReference Include="FSUIPCClientDLL" Version="3.2.21" />
2424
<PackageReference Include="Serilog" Version="2.12.0" />
2525
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
2626
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />

PilotsDeck_FNX2PLD/Program.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public static void Main()
6363
Log.Logger.Error($"Program: FSUIPC Connection is closed - exiting.");
6464
break;
6565
}
66+
else if (!IPCManager.IsSimOpen())
67+
{
68+
Log.Logger.Error($"Program: Simulator has closed - exiting.");
69+
break;
70+
}
6671
else if (!IPCManager.IsAircraftFenix() && !ignoreCurrentAC)
6772
{
6873
Log.Logger.Warning($"Program: Loaded Aircraft is not a Fenix - exiting.");
@@ -137,23 +142,42 @@ private static bool Wait()
137142
Log.Information($"Program: Wating for until Fenix is the loaded Aircraft and Sim is unpaused, sleeping for {waitTick * 4}s");
138143
Thread.Sleep(waitTick * 1000 * 4);
139144
}
140-
if (!FSUIPCConnection.IsOpen)
145+
if (!IPCManager.IsSimOpen())
146+
{
147+
Log.Information($"Sim has closed while waiting for Aircraft / unpaused");
141148
return false;
149+
}
142150
}
143151
while (!IPCManager.IsAircraftFenix() || isMenu.Value == 1 || isPaused.Value == 1);
144152

145153
//Wait until the Fenix Executable is running
146154
Process? fenixProc = null;
147-
while (fenixProc == null && FSUIPCConnection.IsOpen)
155+
while (fenixProc == null)
148156
{
149157
fenixProc = Process.GetProcessesByName(FenixExecutable).FirstOrDefault();
150158
if (fenixProc != null)
151159
scanner = new MemoryScanner(fenixProc);
152160
else
153161
{
154162
startDirect = false;
155-
Log.Warning($"Program: Could not find Process {FenixExecutable}, trying again in {waitTick * 2}s");
156-
Thread.Sleep(waitTick * 1000 * 2);
163+
if (FSUIPCConnection.IsOpen)
164+
{
165+
if (IPCManager.IsSimOpen())
166+
{
167+
Log.Warning($"Program: Could not find Process {FenixExecutable}, trying again in {waitTick * 2}s");
168+
Thread.Sleep(waitTick * 1000 * 2);
169+
}
170+
else
171+
{
172+
Log.Information($"Sim has closed while waiting for Process");
173+
return false;
174+
}
175+
}
176+
else
177+
{
178+
Log.Error($"Program: FSUIPC Closed while waiting on Fenix Process - exiting!");
179+
return false;
180+
}
157181
}
158182
}
159183

@@ -172,8 +196,9 @@ private static bool Wait()
172196

173197
//Start WASM and ElementManager
174198
Log.Information($"Program: Initializing WASM Module");
175-
MSFSVariableServices.Init(Process.GetCurrentProcess().MainWindowHandle);
199+
MSFSVariableServices.Init();
176200
MSFSVariableServices.LVARUpdateFrequency = 0;
201+
MSFSVariableServices.LogLevel = LOGLEVEL.LOG_LEVEL_INFO;
177202
MSFSVariableServices.Start();
178203
if (!MSFSVariableServices.IsRunning)
179204
{

0 commit comments

Comments
 (0)