Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AddonTools.c
Go to the documentation of this file.
1[Obsolete("Use SCR_ParamEnumArray")]
2class ParamEnumAddons : array<ref ParamEnum>
3{
4 //------------------------------------------------------------------------------------------------
5 [Obsolete("Use SCR_ParamEnumArray.FromAddons instead")]
6 private static ParamEnumArray FromEnum(int titleFormat = 2, int hideCoreModules = 0)
7 {
8 return SCR_ParamEnumArray.FromAddons(titleFormat, hideCoreModules);
9 }
10}
11
12// TODO: rename to SCR_AddonTools?
13class SCR_AddonTool
14{
15 protected static const ref array<string> LOADED_ADDON_IDS = {}; // static values get reset every time addons are loaded/unloaded
16 protected static const ref array<string> LOADED_ADDON_GUIDS = {};
17
18 protected static const ref array<string> CORE_ADDONS = { "core", "ArmaReforger" };
19
20 //------------------------------------------------------------------------------------------------
25 static array<string> GetResourceAddons(ResourceName prefab, bool ignoreCoreAddons = false)
26 {
27 array<string> addonNames = {};
28
29 if (prefab.IsEmpty())
30 return addonNames;
31
32 Resource prefabResource = BaseContainerTools.LoadContainer(prefab);
33 if (!prefabResource)
34 return addonNames;
35
36 BaseResourceObject configContainer;
37 configContainer = prefabResource.GetResource();
38 if (!configContainer)
39 return addonNames;
40
41 BaseContainer configBase = configContainer.ToBaseContainer();
42 if (!configBase)
43 return addonNames;
44
45 configBase.GetSourceAddons(addonNames);
46
47 if (ignoreCoreAddons && !addonNames.IsEmpty())
48 {
49 foreach (string item : CORE_ADDONS)
50 {
51 addonNames.RemoveItem(item);
52 }
53 }
54
55 return addonNames;
56 }
57
58 //------------------------------------------------------------------------------------------------
62 static string GetResourceLastAddon(ResourceName prefab)
63 {
64 array<string> addonNames = GetResourceAddons(prefab);
65 if (addonNames.IsEmpty())
66 return string.Empty;
67
68 return addonNames[addonNames.Count() - 1];
69 }
70
71 //------------------------------------------------------------------------------------------------
76 static string GetAddonID(int index)
77 {
78 LoadAddons();
79
80 if (!LOADED_ADDON_IDS.IsIndexValid(index))
81 return string.Empty;
82
83 return LOADED_ADDON_IDS[index];
84 }
85
86 //------------------------------------------------------------------------------------------------
87 // \param[in] ignoreCoreAddons
89 static array<string> GetAllAddonIDs(/* bool ignoreCoreAddons = false */)
90 {
91 LoadAddons();
92
93 return SCR_ArrayHelperT<string>.GetCopy(LOADED_ADDON_IDS);
94 }
95
96 //------------------------------------------------------------------------------------------------
99 static string GetAddonFileSystem(int addonIndex)
100 {
101 LoadAddons();
102
103 if (!LOADED_ADDON_IDS.IsIndexValid(addonIndex))
104 return string.Empty;
105
106 return ToFileSystem(LOADED_ADDON_IDS[addonIndex]);
107 }
108
109 //------------------------------------------------------------------------------------------------
110 // \param[in] ignoreCoreAddons
112 static array<string> GetAllAddonFileSystems(/* bool ignoreCoreAddons = false */)
113 {
114 LoadAddons();
115
116 array<string> result = {};
117
118 foreach (string addonID : LOADED_ADDON_IDS)
119 {
120 result.Insert(ToFileSystem(addonID));
121 }
122
123 return result;
124 }
125
126 //------------------------------------------------------------------------------------------------
129 static bool IsVanillaAddon(int addonIndex)
130 {
131 if (!LOADED_ADDON_GUIDS.IsIndexValid(addonIndex))
132 return false;
133
134 return GameProject.IsVanillaAddon(LOADED_ADDON_GUIDS[addonIndex]);
135 }
136
137 //------------------------------------------------------------------------------------------------
140 static bool IsVanillaAddon(string addonID)
141 {
142 int addonIndex = LOADED_ADDON_IDS.Find(addonID);
143 if (addonIndex < 0)
144 return false;
145
146 return GameProject.IsVanillaAddon(LOADED_ADDON_GUIDS[addonIndex]);
147 }
148
149 //------------------------------------------------------------------------------------------------
159 static string StripFileSystem(string fileSystemPath)
160 {
161 int length = fileSystemPath.Length();
162 if (fileSystemPath.IsEmpty())
163 return fileSystemPath;
164
165 if (!fileSystemPath.StartsWith("$"))
166 return fileSystemPath;
167
168 int colonIndex /* ha, ha */ = fileSystemPath.IndexOf(":");
169 if (colonIndex < 0)
170 return fileSystemPath;
171
172 ++colonIndex;
173 if (colonIndex == length)
174 return string.Empty;
175
176 return fileSystemPath.Substring(colonIndex, length - colonIndex);
177 }
178
179 //------------------------------------------------------------------------------------------------
184 static string ToFileSystem(string addonID)
185 {
186 addonID.TrimInPlace();
187 if (!addonID) // !.IsEmpty()
188 return string.Empty;
189
190 return string.Format("$%1:", addonID);
191 }
192
193 //------------------------------------------------------------------------------------------------
194 protected static void LoadAddons()
195 {
196 if (!LOADED_ADDON_IDS.IsEmpty())
197 return;
198
199 array<string> guids = {};
200 GameProject.GetLoadedAddons(guids);
201
202 LOADED_ADDON_GUIDS.Copy(guids);
203 foreach (string addonGUID : LOADED_ADDON_GUIDS)
204 {
205 LOADED_ADDON_IDS.Insert(GameProject.GetAddonID(addonGUID));
206 }
207 }
208
209#ifdef WORKBENCH
210 //------------------------------------------------------------------------------------------------
217 static bool GetAddonAbsolutePath(int addonId, string relativeDirPath, out string result, bool mustExist = true)
218 {
219 return Workbench.GetAbsolutePath(ToFileSystem(GetAddonID(addonId)) + relativeDirPath, result, mustExist);
220 }
221
222 //------------------------------------------------------------------------------------------------
230 static bool GetAddonAbsolutePath(int addonId, ResourceName directory, out string result, bool mustExist = true)
231 {
232 return Workbench.GetAbsolutePath(ToFileSystem(GetAddonID(addonId)) + directory.GetPath(), result, mustExist);
233 }
234#endif
235}
ParamEnumAddons LOADED_ADDON_IDS
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
static ParamEnumArray FromAddons(int titleFormat=2, int hideCoreModules=0)