Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
PeerTool.c
Go to the documentation of this file.
1[WorkbenchPluginAttribute("Peer Tool", "Runs peer clients that connect to the WB instance.", "", "", {"WorldEditor"})]
2class PeerPlugin : WorldEditorPlugin
3{
4 [Attribute("game.exe", UIWidgets.FileNamePicker, desc: "Peer exe path", params: "exe FileNameFormat=absolute")]
5 string Executable;
6
7 [Attribute("Launch Delay", UIWidgets.EditBox, desc: "Delay in seconds before launching the windows", params: "0 1000 1")]
8 int launchDelay = 0;
9
10 [Attribute("Peers configuration")]
11 ref array<ref PeerConfig> PeersWindows;
12
13 ProcessHandle Handle = null;
14
15 static int launchIDs = 0;
16 int launchID = 0;
17
18 private string GetAddonsDirCLI()
19 {
20 string addonsDir;
21 array<string> addonsGUIDs = {};
22 GameProject.GetLoadedAddons(addonsGUIDs);
23
24 foreach (string GUID: addonsGUIDs)
25 {
26 if (!GameProject.IsVanillaAddon(GUID))
27 {
28 string addonPath = "$" + GameProject.GetAddonID(GUID) + ":";
29 string absPath;
30 if (Workbench.GetAbsolutePath(addonPath, absPath))
31 {
32 if (!addonsDir.IsEmpty())
33 addonsDir += ",";
34
35 addonsDir += absPath;
36 }
37 }
38 }
39 return "\"" + addonsDir + "\"";
40 }
41
42 private string GetAddonsCLI()
43 {
44 string addonIDs;
45
46 array<string> addonsGUIDs = {};
47 GameProject.GetLoadedAddons(addonsGUIDs);
48
49 foreach (string GUID: addonsGUIDs)
50 {
51 if (!GameProject.IsVanillaAddon(GUID))
52 {
53 if (!addonIDs.IsEmpty())
54 addonIDs += ",";
55
56 addonIDs += GameProject.GetAddonID(GUID);
57 }
58 }
59
60 return addonIDs;
61 }
62
63 void StartAllWindows()
64 {
65 int profileIndex = 0;
66
67 string addonsDir = GetAddonsDirCLI();
68 string addonIDs = GetAddonsCLI();
69
70 foreach(PeerConfig conf : PeersWindows)
71 {
72 if (!conf.Enabled)
73 continue;
74
75 profileIndex++; // start indexing peers from 1
76 string gproj = Workbench.GetCurrentGameProjectFile();
77 string sCmd = Executable + " -gproj \"" + gproj + "\" ";
78
79 if (!addonsDir.IsEmpty())
80 sCmd += "-addonsDir " + addonsDir + " ";
81 if (!addonIDs.IsEmpty())
82 sCmd += "-addons " + addonIDs + " ";
83 if(conf.Windowed)
84 sCmd += "-window ";
85 if(conf.X != -1)
86 sCmd += "-posX " + conf.X + " ";
87 if(conf.Y != -1)
88 sCmd += "-posY " + conf.Y + " ";
89 if(conf.Width != -1)
90 sCmd += "-screenWidth " + conf.Width + " ";
91 if(conf.Height != -1)
92 sCmd += "-screenHeight " + conf.Height + " ";
93 if(conf.MaxFPS > 0)
94 sCmd += "-maxFPS " + conf.MaxFPS + " ";
95 if(conf.ForceUpdate)
96 sCmd += "-forceupdate ";
97 if(conf.NoFocus)
98 sCmd += "-nofocus ";
99 if(conf.RplAutoJoin)
100 sCmd += "-client ";
101 if(conf.RplAutoReconnect)
102 sCmd += "-rpl-reconnect ";
103 if(conf.RplDisableTimeout)
104 sCmd += "-rpl-timeout-disable ";
105 if(conf.Profile)
106 sCmd += "-profile " + conf.Profile + profileIndex.ToString() + " ";
107 if (conf.Params)
108 sCmd += conf.Params + " ";
109
110 Print("Running command: " + sCmd);
111 conf.Handle = Workbench.RunProcess(sCmd);
112 if (!conf.Handle)
113 Print("Peer #" + profileIndex + " couldn't run. Check if your Executable or other settings are correct", LogLevel.ERROR);
114 }
115 }
116 void DelayedStart(int thisID)
117 {
118 Sleep(launchDelay * 1000);
119 if (launchID == thisID)
120 StartAllWindows();
121 }
122
123 void Start()
124 {
125 launchID = launchIDs;
126 launchIDs += 1;
127 if (launchDelay != 0)
128 {
129 thread DelayedStart(launchID);
130 return;
131 }
132
133 StartAllWindows();
134 }
135
136 void End()
137 {
138 launchID = -1;
139 foreach(PeerConfig conf : PeersWindows)
140 {
141 if (!conf.Handle) // what if the game mode wasn't the PeerTool?
142 continue;
143
144 Workbench.KillProcess(conf.Handle);
145 conf.Handle = null;
146 }
147 }
148
149 override void OnGameModeStarted(string worldName,
150 string gameMode,
151 bool playFromCameraPos,
152 vector cameraPosition,
153 vector cameraAngles)
154 {
155 if(gameMode == "Server localhost + PeerTool") // would consider different (if possible) solution for this. if this is changed on the C++ side, it will stop working
156 {
157 Start();
158 }
159 }
160
161 override void OnGameModeEnded()
162 {
163 End();
164 }
165
166 override void Configure()
167 {
168 Workbench.ScriptDialog("Configure Peer tool", "Settings:", this);
169 }
170
171 [ButtonAttribute("OK")]
172 void OkButton() {}
173}
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
void Start()
Start this tracking time in this menu, adds it to previous time if we have not yet sended previous da...
Configs ServerBrowser KickDialogs conf
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
override void Configure()
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute