Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AddonTools.c
Go to the documentation of this file.
1 class ParamEnumAddons : array<ref ParamEnum>
2 {
3  protected static const int CORE_MODULE_COUNT = 2;
4 
5  //------------------------------------------------------------------------------------------------
15  static ParamEnumArray FromEnum(int titleFormat = 2, int hideCoreModules = 0)
16  {
17  ParamEnumArray params = new ParamEnumArray();
18  array<string> addonGUIDs = {};
19  GameProject.GetLoadedAddons(addonGUIDs);
20 
21  for (int i, count = addonGUIDs.Count(); i < count; i++)
22  {
23  string addonGUID = addonGUIDs[i];
24 
25  if (hideCoreModules == 1 && GameProject.IsVanillaAddon(addonGUID))
26  continue;
27 
28  if (hideCoreModules == 2 && count > CORE_MODULE_COUNT && GameProject.IsVanillaAddon(addonGUID))
29  continue;
30 
31  string title;
32  switch (titleFormat)
33  {
34  case 0: title = GameProject.GetAddonID(addonGUID); break;
35  case 1: title = GameProject.GetAddonTitle(addonGUID); break;
36  default:
37  case 2: title = string.Format("%1 (%2)", GameProject.GetAddonTitle(addonGUID), GameProject.GetAddonID(addonGUID)); break;
38  }
39  params.Insert(new ParamEnum(title, i.ToString()));
40  }
41 
42  return params;
43  }
44 }
45 
46 // TODO: rename to SCR_AddonTools?
47 class SCR_AddonTool
48 {
49  protected static const ref array<string> CORE_ADDONS = { "core", "ArmaReforger" };
50 
51  //------------------------------------------------------------------------------------------------
56  static array<string> GetResourceAddons(ResourceName prefab, bool ignoreCoreAddons = false)
57  {
58  array<string> addonNames = {};
59 
60  if (prefab.IsEmpty())
61  return addonNames;
62 
63  Resource prefabResource = BaseContainerTools.LoadContainer(prefab);
64  if (!prefabResource)
65  return addonNames;
66 
67  BaseResourceObject configContainer;
68  configContainer = prefabResource.GetResource();
69  if (!configContainer)
70  return addonNames;
71 
72  BaseContainer configBase = configContainer.ToBaseContainer();
73  if (!configBase)
74  return addonNames;
75 
76  configBase.GetSourceAddons(addonNames);
77 
78  if (ignoreCoreAddons && !addonNames.IsEmpty())
79  {
80  foreach (string item : CORE_ADDONS)
81  {
82  addonNames.RemoveItem(item);
83  }
84  }
85 
86  return addonNames;
87  }
88 
89  //------------------------------------------------------------------------------------------------
93  static string GetResourceLastAddon(ResourceName prefab)
94  {
95  array<string> addonNames = GetResourceAddons(prefab);
96  if (addonNames.IsEmpty())
97  return string.Empty;
98 
99  return addonNames[addonNames.Count() - 1];
100  }
101 
102  //------------------------------------------------------------------------------------------------
107  static string GetAddonIndex(int index)
108  {
109  array<string> addons = {};
110  GameProject.GetLoadedAddons(addons);
111 
112  return GameProject.GetAddonID(addons[index]);
113  }
114 
115  //------------------------------------------------------------------------------------------------
124  static string StripFileSystem(string fileSystemPath)
125  {
126  int length = fileSystemPath.Length();
127  if (fileSystemPath.IsEmpty())
128  return fileSystemPath;
129 
130  if (!fileSystemPath.StartsWith("$"))
131  return fileSystemPath;
132 
133  int colonIndex /* ha, ha */ = fileSystemPath.IndexOf(":");
134  if (colonIndex < 0)
135  return fileSystemPath;
136 
137  colonIndex++;
138  if (colonIndex == length)
139  return string.Empty;
140 
141  return fileSystemPath.Substring(colonIndex, length - colonIndex);
142  }
143 
144  //------------------------------------------------------------------------------------------------
149  static string ToFileSystem(string addon)
150  {
151  return "$" + addon + ":";
152  }
153 
154 #ifdef WORKBENCH
155  //------------------------------------------------------------------------------------------------
159  static bool GetAddonAbsolutePath(int addonId, string relativeDirPath, out string result, bool mustExist = true)
160  {
161  return Workbench.GetAbsolutePath(ToFileSystem(GetAddonIndex(addonId)) + relativeDirPath, result, mustExist);
162  }
163 
164  //------------------------------------------------------------------------------------------------
169  static bool GetAddonAbsolutePath(int addonId, ResourceName directory, out string result, bool mustExist = true)
170  {
171  return Workbench.GetAbsolutePath(ToFileSystem(GetAddonIndex(addonId)) + directory.GetPath(), result, mustExist);
172  }
173 #endif
174 }
ParamEnumAddons
Definition: SCR_AddonTools.c:1
CORE_ADDONS
ParamEnumAddons CORE_ADDONS
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24