-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
patch.diff
148 lines (140 loc) · 4.35 KB
/
patch.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
From 2e52aa2b6dc0fac659269facafa8fd22f01185a5 Mon Sep 17 00:00:00 2001
From: Nezz <[email protected]>
Date: Thu, 15 Apr 2021 21:50:55 +0300
Subject: [PATCH] Workaround for standalone WASM CTD
---
src/Sources/Code/Module.cpp | 115 +++++++++++++++++++++---------------
1 file changed, 68 insertions(+), 47 deletions(-)
diff --git a/src/Sources/Code/Module.cpp b/src/Sources/Code/Module.cpp
index 0d50782..7d4b8d4 100644
--- a/src/Sources/Code/Module.cpp
+++ b/src/Sources/Code/Module.cpp
@@ -11,8 +11,8 @@
HANDLE g_hSimConnect;
const char* version = "0.2.67";
const char* MobiFlightEventPrefix = "MobiFlight.";
-const char* FileEventsMobiFlight = "modules/events.txt";
-const char* FileEventsUser = "modules/events.user.txt";
+const char* FileEventsMobiFlight = "panel/events.txt";
+const char* FileEventsUser = "panel/events.user.txt";
std::vector<std::pair<std::string, std::string>> CodeEvents;
@@ -92,54 +92,75 @@ void RegisterEvents() {
SimConnect_SetNotificationGroupPriority(g_hSimConnect, MOBIFLIGHT_GROUP::DEFAULT, SIMCONNECT_GROUP_PRIORITY_HIGHEST);
}
-extern "C" MSFS_CALLBACK void module_init(void)
-{
- // load defintions
- LoadEventDefinitions(FileEventsMobiFlight);
- int eventDefinition = CodeEvents.size();
- LoadEventDefinitions(FileEventsUser);
-
- g_hSimConnect = 0;
- HRESULT hr = SimConnect_Open(&g_hSimConnect, "Standalone Module", (HWND) NULL, 0, 0, 0);
- if (hr != S_OK)
- {
- fprintf(stderr, "Could not open SimConnect connection.\n");
- return;
- }
- hr = SimConnect_SubscribeToSystemEvent(g_hSimConnect, EVENT_FLIGHT_LOADED, "FlightLoaded");
- if (hr != S_OK)
- {
- fprintf(stderr, "Could not subscribe to \"FlightLoaded\" system event.\n");
- return;
- }
-
- RegisterEvents();
-
- hr = SimConnect_CallDispatch(g_hSimConnect, MyDispatchProc, NULL);
- if (hr != S_OK)
- {
- fprintf(stderr, "Could not set dispatch proc.\n");
- return;
- }
-
- fprintf(stderr, "MobiFlight: Module Init Complete. Version: %s", version);
- fprintf(stderr, "MobiFlight: Loaded %u event defintions in total.", CodeEvents.size());
- fprintf(stderr, "MobiFlight: Loaded %u built-in event defintions.", eventDefinition);
- fprintf(stderr, "MobiFlight: Loaded %u user event defintions.", CodeEvents.size()-eventDefinition);
-}
+extern "C" {
-extern "C" MSFS_CALLBACK void module_deinit(void)
-{
-
- if (!g_hSimConnect)
- return;
- HRESULT hr = SimConnect_Close(g_hSimConnect);
- if (hr != S_OK)
+ MSFS_CALLBACK bool Mobiflight_gauge_callback(FsContext ctx, int service_id, void* pData)
{
- fprintf(stderr, "Could not close SimConnect connection.\n");
- return;
+ switch (service_id)
+ {
+ case PANEL_SERVICE_PRE_INSTALL:
+ {
+ return true;
+ }
+ break;
+ case PANEL_SERVICE_POST_INSTALL:
+ {
+ // load defintions
+ LoadEventDefinitions(FileEventsMobiFlight);
+ int eventDefinition = CodeEvents.size();
+ LoadEventDefinitions(FileEventsUser);
+
+ g_hSimConnect = 0;
+ HRESULT hr = SimConnect_Open(&g_hSimConnect, "Standalone Module", (HWND)NULL, 0, 0, 0);
+ if (hr != S_OK)
+ {
+ fprintf(stderr, "Could not open SimConnect connection.\n");
+ return false;
+ }
+ hr = SimConnect_SubscribeToSystemEvent(g_hSimConnect, EVENT_FLIGHT_LOADED, "FlightLoaded");
+ if (hr != S_OK)
+ {
+ fprintf(stderr, "Could not subscribe to \"FlightLoaded\" system event.\n");
+ return false;
+ }
+
+ RegisterEvents();
+
+ hr = SimConnect_CallDispatch(g_hSimConnect, MyDispatchProc, NULL);
+ if (hr != S_OK)
+ {
+ fprintf(stderr, "Could not set dispatch proc.\n");
+ return false;
+ }
+
+ fprintf(stderr, "MobiFlight: Module Init Complete. Version: %s", version);
+ fprintf(stderr, "MobiFlight: Loaded %u event defintions in total.", CodeEvents.size());
+ fprintf(stderr, "MobiFlight: Loaded %u built-in event defintions.", eventDefinition);
+ fprintf(stderr, "MobiFlight: Loaded %u user event defintions.", CodeEvents.size() - eventDefinition);
+ return true;
+ }
+ break;
+ case PANEL_SERVICE_PRE_DRAW:
+ return true;
+ break;
+ case PANEL_SERVICE_PRE_KILL:
+ {
+ if (!g_hSimConnect)
+ return true;
+
+ HRESULT hr = SimConnect_Close(g_hSimConnect);
+ if (hr != S_OK)
+ {
+ fprintf(stderr, "Could not close SimConnect connection.\n");
+ return false;
+ }
+
+ return true;
+ }
+ break;
+ }
+ return false;
}
-
}
void CALLBACK MyDispatchProc(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext)
--
2.30.0.windows.2