Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LaunchInitializer.cs
Go to the documentation of this file.
1using System;
5
7
8public static class LaunchInitializer
9{
10 public static void LoadParameters(Main game)
11 {
13 if (Main.dedServ)
14 {
16 }
18 }
19
20 private static void LoadSharedParameters(Main game)
21 {
22 string path;
23 if ((path = TryParameter("-loadlib")) != null)
24 {
25 game.loadLib(path);
26 }
27 string s;
28 if ((s = TryParameter("-p", "-port")) != null && int.TryParse(s, out var result))
29 {
30 Netplay.ListenPort = result;
31 }
32 }
33
34 private static void LoadClientParameters(Main game)
35 {
36 string iP;
37 if ((iP = TryParameter("-j", "-join")) != null)
38 {
39 game.AutoJoin(iP);
40 }
41 string arg;
42 if ((arg = TryParameter("-pass", "-password")) != null)
43 {
44 Netplay.ServerPassword = Main.ConvertFromSafeArgument(arg);
45 game.AutoPass();
46 }
47 if (HasParameter("-host"))
48 {
49 game.AutoHost();
50 }
51 }
52
53 private static void LoadServerParameters(Main game)
54 {
55 try
56 {
57 string s;
58 if ((s = TryParameter("-forcepriority")) != null)
59 {
60 Process currentProcess = Process.GetCurrentProcess();
61 if (int.TryParse(s, out var result))
62 {
63 switch (result)
64 {
65 case 0:
66 currentProcess.PriorityClass = ProcessPriorityClass.RealTime;
67 break;
68 case 1:
69 currentProcess.PriorityClass = ProcessPriorityClass.High;
70 break;
71 case 2:
72 currentProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
73 break;
74 case 3:
75 currentProcess.PriorityClass = ProcessPriorityClass.Normal;
76 break;
77 case 4:
78 currentProcess.PriorityClass = ProcessPriorityClass.BelowNormal;
79 break;
80 case 5:
81 currentProcess.PriorityClass = ProcessPriorityClass.Idle;
82 break;
83 default:
84 currentProcess.PriorityClass = ProcessPriorityClass.High;
85 break;
86 }
87 }
88 else
89 {
90 currentProcess.PriorityClass = ProcessPriorityClass.High;
91 }
92 }
93 else
94 {
95 Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
96 }
97 }
98 catch
99 {
100 }
101 string value;
102 if ((value = TryParameter("-maxplayers", "-players")) != null)
103 {
104 int num = Convert.ToInt32(value);
105 if (num <= 255 && num >= 1)
106 {
107 game.SetNetPlayers(num);
108 }
109 }
110 string arg;
111 if ((arg = TryParameter("-pass", "-password")) != null)
112 {
113 Netplay.ServerPassword = Main.ConvertFromSafeArgument(arg);
114 }
115 string s2;
116 if ((s2 = TryParameter("-lang")) != null && int.TryParse(s2, out var result2))
117 {
118 LanguageManager.Instance.SetLanguage(result2);
119 }
120 if ((s2 = TryParameter("-language")) != null)
121 {
122 LanguageManager.Instance.SetLanguage(s2);
123 }
124 string worldName;
125 if ((worldName = TryParameter("-worldname")) != null)
126 {
127 game.SetWorldName(worldName);
128 }
129 string newMOTD;
130 if ((newMOTD = TryParameter("-motd")) != null)
131 {
132 game.NewMOTD(newMOTD);
133 }
134 string banFilePath;
135 if ((banFilePath = TryParameter("-banlist")) != null)
136 {
137 Netplay.BanFilePath = banFilePath;
138 }
139 if (HasParameter("-autoshutdown"))
140 {
141 game.EnableAutoShutdown();
142 }
143 if (HasParameter("-secure"))
144 {
145 Netplay.SpamCheck = true;
146 }
147 string serverWorldRollbacks;
148 if ((serverWorldRollbacks = TryParameter("-worldrollbackstokeep")) != null)
149 {
150 game.setServerWorldRollbacks(serverWorldRollbacks);
151 }
152 string worldSize;
153 if ((worldSize = TryParameter("-autocreate")) != null)
154 {
155 game.autoCreate(worldSize);
156 }
157 if (HasParameter("-noupnp"))
158 {
159 Netplay.UseUPNP = false;
160 }
161 if (HasParameter("-experimental"))
162 {
163 Main.UseExperimentalFeatures = true;
164 }
165 string world;
166 if ((world = TryParameter("-world")) != null)
167 {
168 game.SetWorld(world, cloud: false);
169 }
170 else if (SocialAPI.Mode == SocialMode.Steam && (world = TryParameter("-cloudworld")) != null)
171 {
172 game.SetWorld(world, cloud: true);
173 }
174 string configPath;
175 if ((configPath = TryParameter("-config")) != null)
176 {
177 game.LoadDedConfig(configPath);
178 }
179 string autogenSeedName;
180 if ((autogenSeedName = TryParameter("-seed")) != null)
181 {
182 Main.AutogenSeedName = autogenSeedName;
183 }
184 }
185
186 private static bool HasParameter(params string[] keys)
187 {
188 for (int i = 0; i < keys.Length; i++)
189 {
190 if (Program.LaunchParameters.ContainsKey(keys[i]))
191 {
192 return true;
193 }
194 }
195 return false;
196 }
197
198 private static string TryParameter(params string[] keys)
199 {
200 for (int i = 0; i < keys.Length; i++)
201 {
202 if (Program.LaunchParameters.TryGetValue(keys[i], out var value))
203 {
204 if (value == null)
205 {
206 return "";
207 }
208 return value;
209 }
210 }
211 return null;
212 }
213}
static int ToInt32(object? value)
Definition Convert.cs:1320
static Process GetCurrentProcess()
Definition Process.cs:1107
static string TryParameter(params string[] keys)
static bool HasParameter(params string[] keys)
void setServerWorldRollbacks(string rollBacksToKeep)
Definition Main.cs:4515
void AutoHost()
Definition Main.cs:4789
static bool dedServ
Definition Main.cs:1226
void EnableAutoShutdown()
Definition Main.cs:4765
void AutoJoin(string IP)
Definition Main.cs:4781
void NewMOTD(string newMOTD)
Definition Main.cs:4545
void autoCreate(string worldSize)
Definition Main.cs:4520
void loadLib(string path)
Definition Main.cs:4797
void LoadDedConfig(string configPath)
Definition Main.cs:4560
void SetWorld(string world, bool cloud)
Definition Main.cs:4755
void SetNetPlayers(int mPlayers)
Definition Main.cs:4750
void SetWorldName(string world)
Definition Main.cs:4760
static string ConvertFromSafeArgument(string arg)
Definition Main.cs:4555
void AutoPass()
Definition Main.cs:4776
static Dictionary< string, string > LaunchParameters
Definition Program.cs:29
static SocialMode Mode
Definition SocialAPI.cs:32