-
Notifications
You must be signed in to change notification settings - Fork 148
/
fnc_preInit.sqf
208 lines (167 loc) · 7.24 KB
/
fnc_preInit.sqf
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Internal Function: CBA_fnc_preInit
Description:
Occurs once per mission before objects are initialized.
Internal use only.
Parameters:
None
Returns:
None
Author:
commy2
---------------------------------------------------------------------------- */
if (ISPROCESSED(missionNamespace)) exitWith {
XEH_LOG("preInit already executed. Abort preInit.");
};
SETPROCESSED(missionNamespace);
SLX_XEH_DisableLogging = uiNamespace getVariable ["SLX_XEH_DisableLogging", false]; // get from preStart
XEH_LOG("PreInit started. v" + getText (configFile >> "CfgPatches" >> "cba_common" >> "versionStr"));
SLX_XEH_STR = ""; // does nothing, never changes, backwards compatibility
SLX_XEH_COMPILE = compileFinal "diag_log text format ['[CBA-XEH] old SLX_XEH_COMPILE macro used on %1', _this]; compileScript [_this]"; //backwards compat
SLX_XEH_COMPILE_NEW = CBA_fnc_compileFunction; //backwards comp
SLX_XEH_DUMMY = "Logic"; // backwards comp
SLX_XEH_MACHINE = [ // backwards compatibility, deprecated
!isDedicated, // 0 - isClient (and thus has player)
didJIP, // 1 - isJip
!isServer, // 2 - isDedicatedClient (and thus not a Client-Server)
isServer, // 3 - isServer
isDedicated, // 4 - isDedicatedServer (and thus not a Client-Server)
false, // 5 - Player Check finished, no longer works
!isMultiplayer, // 6 - isSingleplayer
false, // 7 - PreInit passed
false, // 8 - PostInit passed
isMultiplayer, // 9 - Multiplayer && respawn
if (isDedicated) then {0} else {[2, 1] select isServer}, // 10 - Machine type (only 3 possible configurations)
0, // 11 - SESSION_ID
0, // 12 - LEVEL - Used for version determination
false, // 13 - TIMEOUT - PostInit timedOut, always false
productVersion, // 14 - Game
3 // 15 - Product+Version, always Arma 3
];
CBA_isHeadlessClient = !hasInterface && !isDedicated;
// make case insensitive list of all supported events
GVAR(EventsLowercase) = [];
{
private _header = "";
#ifndef SKIP_SCRIPT_NAME
_header = format ["scriptName 'XEH:%1';", _x];
#endif
// generate event functions
switch _x do {
case "Init": {
FUNC(Init) = compileFinal (_header + "(_this select 0) call CBA_fnc_initEvents; (_this select 0) call CBA_fnc_init");
};
// This prevents double execution of the Killed event on the same unit.
case "Killed": {
FUNC(Killed) = compileFinal (_header + format ['\
params ["_unit"];\
if (_unit getVariable [QGVAR(killedBody), objNull] != _unit) then {\
_unit setVariable [QGVAR(killedBody), _unit];\
private "_unit";\
{call _x} forEach ((_this select 0) getVariable QGVAR(%1));\
};',
_x]);
};
case "HitPart": {
FUNC(HitPart) = compileFinal (_header + format ['{call _x} forEach ((_this select 0 select 0) getVariable QGVAR(%1))', _x]);
};
default {
missionNamespace setVariable [
format [QFUNC(%1), _x],
compileFinal (_header + format ['{call _x} forEach ((_this select 0) getVariable QGVAR(%1))', _x])
];
};
};
GVAR(EventsLowercase) pushBack toLower _x;
} forEach [XEH_EVENTS];
// generate list of incompatible classes
GVAR(incompatible) = [] call CBA_fnc_createNamespace;
{
private _class = configFile >> "CfgVehicles" >> _x;
while {isClass _class && {!ISINCOMP(configName _class)}} do {
SETINCOMP(configName _class);
_class = inheritsFrom _class;
};
} forEach call (uiNamespace getVariable [QGVAR(incompatibleClasses), {[]}]);
// always recompile extended event handlers
#ifdef DEBUG_MODE_FULL
XEH_LOG("Compiling XEH START");
#endif
//Get configFile eventhandlers from cache that was generated at preStart
GVAR(allEventHandlers) = call (uiNamespace getVariable [QGVAR(configFileEventHandlers), {[]}]);
{
GVAR(allEventHandlers) append (_x call CBA_fnc_compileEventHandlers);
} forEach [campaignConfigFile, missionConfigFile];
#ifdef DEBUG_MODE_FULL
XEH_LOG("Compiling XEH END");
#endif
// add extended event handlers to classes
GVAR(fallbackRunning) = false;
// call PreInit events and add event handlers to object classes
{
if (_x select 0 == "") then {
if (_x select 1 == "preInit") then {
(_x select 2) call {
private "_x";
[] call (_this select 0);
if (!isDedicated) then {
[] call (_this select 1);
};
if (isServer) then {
[] call (_this select 2);
};
};
};
} else {
_x params ["_className", "_eventName", "_eventFunc", "_allowInheritance", "_excludedClasses"];
// backwards comp, args in _this are already switched
if (_eventName == "firedBis") then {
_eventName = "fired";
};
_eventFunc params ["_funcAll", "_funcClient", "_funcServer"];
if (_funcAll isNotEqualTo {}) then {
private _success = [_className, _eventName, _funcAll, _allowInheritance, _excludedClasses] call CBA_fnc_addClassEventHandler;
TRACE_3("addClassEventHandler",_className,_eventName,_success);
};
if (!isDedicated && {_funcClient isNotEqualTo {}}) then {
private _success = [_className, _eventName, _funcClient, _allowInheritance, _excludedClasses] call CBA_fnc_addClassEventHandler;
TRACE_3("addClassEventHandler",_className,_eventName,_success);
};
if (isServer && {_funcServer isNotEqualTo {}}) then {
private _success = [_className, _eventName, _funcServer, _allowInheritance, _excludedClasses] call CBA_fnc_addClassEventHandler;
TRACE_3("addClassEventHandler",_className,_eventName,_success);
};
};
} forEach GVAR(allEventHandlers);
GVAR(initPostStack) = [];
#ifdef DEBUG_MODE_FULL
diag_log text format ["isScheduled = %1", call CBA_fnc_isScheduled];
#endif
SLX_XEH_MACHINE set [7, true]; // PreInit passed
#ifdef DEBUG_MODE_FULL
[QGVAR(LoadingScreenStarted), {diag_log [QGVAR(LoadingScreenStarted), _this]}] call CBA_fnc_addEventHandler;
[QGVAR(LoadingScreenEnded), {diag_log [QGVAR(LoadingScreenEnded), _this]}] call CBA_fnc_addEventHandler;
#endif
// CBA_loadingScreenDone event
GVAR(expectedLoadingScreens) = ["bis_fnc_preload", "bis_fnc_initRespawn"];
if (!isServer) then { // only on client
GVAR(expectedLoadingScreens) pushBack "bis_fnc_initFunctions";
};
// check if this was the last loading screen, if so, fire event
[QGVAR(LoadingScreenEnded), {
params ["_loadingScreen"];
if (!isNil QGVAR(expectedLoadingScreens)) then {
GVAR(expectedLoadingScreens) deleteAt (GVAR(expectedLoadingScreens) find _loadingScreen);
if (count GVAR(expectedLoadingScreens) == 0) then {
GVAR(expectedLoadingScreens) = nil;
["CBA_loadingScreenDone", []] call CBA_fnc_localEvent;
};
};
}] call CBA_fnc_addEventHandler;
#ifdef DEBUG_MODE_FULL
["CBA_loadingScreenDone", {
playSound "Beep_Target";
}] call CBA_fnc_addEventHandler;
#endif
XEH_LOG("PreInit finished.");