-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathkOSCustomParameters.cs
More file actions
259 lines (228 loc) · 11.6 KB
/
Copy pathkOSCustomParameters.cs
File metadata and controls
259 lines (228 loc) · 11.6 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
using KSP.IO;
using System;
using System.Reflection;
namespace kOS.Module
{
public class kOSCustomParameters : GameParameters.CustomParameterNode
{
private static kOSCustomParameters instance;
public static kOSCustomParameters Instance
{
get
{
if (instance == null)
{
if (HighLogic.CurrentGame != null)
{
instance = HighLogic.CurrentGame.Parameters.CustomParams<kOSCustomParameters>();
}
}
return instance;
}
}
public const string MIGRATION_DIALOG_TEXT = "Some kOS settings are now tracked seperately per-game " +
"using the stock settings menu. " +
"\n\n" +
"You currently seem to have some of these settings stored in kOS's " +
"global folder, probably because you were using a previous version of kOS in the past. " +
"You can migrate these settings from their global (now unused) location into this game's individual settings if you like. " +
"(Note that the telnet server settings are still kept globally, but everything else has moved.)" +
"\n\n<color=#ffffff>" +
"The new place to adjust the settings in-game is in the <color=#ffff00>\"Difficulty Options\"</color> button " +
"of the in-game settings window. (Press <color=#ffff00>ESC</color>, pick <color=#ffff00>Settings</color>, " +
"then <color=#ffff00>Difficulty Options</color>, then <color=#ffff00>kOS</color> to reach them now.)" +
"\n" +
"The settings are there despite them not really being about \"Difficulty\". " +
"That's just the location where KSP allows mods to make custom parameters." +
"</color>\n\n" +
"Would you like to migrate now?";
[GameParameters.CustomParameterUI("")]
public bool migrated = false;
[GameParameters.CustomIntParameterUI("")]
public int version = 0;
// these values constrain and back the InstructionsPerUpdate property so that it is clamped both in the
// user interface and when set from within a script.
private const int ipuMin = 50;
private const int ipuMax = 2000;
private int instructionsPerUpdate = 200;
[GameParameters.CustomIntParameterUI("Instructions per update", minValue = ipuMin, maxValue = ipuMax,
toolTip = "All CPU's run at a speed that executes up to\n" +
"this many kRISC opcodes per physics 'tick'.")]
public int InstructionsPerUpdate
{
get
{
return instructionsPerUpdate;
}
set
{
instructionsPerUpdate = Math.Max(ipuMin, Math.Min(ipuMax, value));
}
}
[GameParameters.CustomParameterUI("Enable compressed storage",
toolTip = "When storing local volumes' data in the saved game,\n"+
"it will be compressed then base64 encoded.")]
public bool useCompressedPersistence = true;
[GameParameters.CustomParameterUI("Show statistics",
toolTip = "After the outermost program is finished, you will\n" +
"see some profiling output describing how fast it ran.")]
public bool showStatistics = false;
[GameParameters.CustomParameterUI("Start on the archive",
toolTip = "When launching a new ship, or reloading a scene,\n" +
"the default volume will start as 0 instead of 1.")]
public bool startOnArchive = false;
[GameParameters.CustomParameterUI("Obey hide UI toggle",
toolTip = "When you press the \"Hide UI\" button (F2 in default bindings)\n" +
"kOS's terminals will hide themselves too.")]
public bool obeyHideUi = true;
[GameParameters.CustomParameterUI("Enable safe mode",
toolTip = "kOS will throw an error if Infinity or Not-A-Number is the result\n" +
"of any expression. This ensures no such values can ever get\n"+
"passed in to KSP's stock API, which doesn't protect itself against their effects.")]
public bool enableSafeMode = true;
[GameParameters.CustomParameterUI("Audible exceptions",
toolTip = "When kOS throws an error, you hear a sound effect.")]
public bool audibleExceptions = true;
[GameParameters.CustomParameterUI("Verbose exceptions",
toolTip = "When kOS has an error, some error messages have alternative longer\n" +
"paragraph-length descriptions that this enables.")]
public bool verboseExceptions = true;
[GameParameters.CustomParameterUI("Only use Blizzy toolbar",
toolTip = "If you have the \"Blizzy Toolbar\" mod installed, only put the kOS\n" +
"button on it instead of both it and the stock toolbar.")]
public bool useBlizzyToolbarOnly = false;
[GameParameters.CustomParameterUI("Debug each opcode",
toolTip = "(For mod developers) Spams the Unity log file with a message for every time\n" +
"an opcode is executed in the virtual machine. Very laggy.")]
public bool debugEachOpcode = false;
[GameParameters.CustomParameterUI("Pause when compile",
toolTip = "A game will be frozen while kOS compiles script.")]
public bool pauseOnCompile = false;
public override GameParameters.GameMode GameMode
{
get
{
return GameParameters.GameMode.ANY;
}
}
public override bool HasPresets
{
get
{
return false;
}
}
public override string Section
{
get
{
return "kOS";
}
}
public override int SectionOrder
{
get
{
return 0;
}
}
public override string Title
{
get
{
return "CONFIG";
}
}
public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);
instance = null;
}
public override bool Enabled(MemberInfo member, GameParameters parameters)
{
if (member.Name == "migrated" || member.Name == "version")
{
return false;
}
return base.Enabled(member, parameters);
}
public void CheckMigrateSettings()
{
Safe.Utilities.SafeHouse.Logger.SuperVerbose("kOSCustomParameters.CheckMigrateSettings()");
if (!migrated)
{
var config = PluginConfiguration.CreateForType<kOSCustomParameters>();
config.load();
var ipu = config.GetValue("InstructionsPerUpdate", -1);
// if the ipu is set below zero, it means that the file was created after we switch to
// the new system, or that the user selected to prevent future migrations.
if (ipu > 0)
{
kOSSettingsChecker.QueueDialog(new MultiOptionDialog(
MIGRATION_DIALOG_TEXT,
"kOS",
HighLogic.UISkin,
new DialogGUIButton("Yes: migrate settings", MigrateSettingsNormal, true),
new DialogGUIButton("Yes: migrate settings this one time,\nbut never ask again for this or any other game", MigrateSettingsPrevent, true),
new DialogGUIButton("No: start with new default settings", DontMigrate, true),
new DialogGUIButton("No: start with new default settings\nand never ask again for this or any other game", DontMigrateAndPrevent, true)
));
}
else
{
Safe.Utilities.SafeHouse.Logger.LogError("ipu: " + ipu.ToString());
migrated = true;
}
}
}
public void MigrateSettingsNormal()
{
MigrateSettings(false);
}
public void MigrateSettingsPrevent()
{
MigrateSettings(true);
}
public void MigrateSettings(bool preventFuture)
{
var config = PluginConfiguration.CreateForType<kOSCustomParameters>();
config.load();
InstructionsPerUpdate = config.GetValue("InstructionsPerUpdate", -1);
useCompressedPersistence = config.GetValue<bool>("InstructionsPerUpdate");
showStatistics = config.GetValue<bool>("InstructionsPerUpdate");
startOnArchive = config.GetValue<bool>("StartOnArchive");
obeyHideUi = config.GetValue<bool>("ObeyHideUI");
enableSafeMode = config.GetValue<bool>("EnableSafeMode");
audibleExceptions = config.GetValue<bool>("AudibleExceptions");
verboseExceptions = config.GetValue<bool>("VerboseExceptions");
debugEachOpcode = config.GetValue<bool>("DebugEachOpcode");
useBlizzyToolbarOnly = config.GetValue<bool>("UseBlizzyToolbarOnly");
config.SetValue("SettingMigrationComment", "All settings except telnet settings are now stored in the game's save file. Settings stored here will be ignored.");
if (preventFuture)
{
config.SetValue("InstructionsPerUpdate", -2); // using -2 so it's different from the default value used above
config.SetValue("PreventFutureMigrationComment", "The user selected to prevent future migration notices when loading or creating save files. Change the IPU value to a positive value to re-enable migrations.");
}
config.save();
migrated = true;
}
public void DontMigrate()
{
var config = PluginConfiguration.CreateForType<kOSCustomParameters>();
config.load();
config.SetValue("SettingMigrationComment", "All settings except telnet settings are now stored in the game's save file. Settings stored here will be ignored.");
config.save();
migrated = true;
}
public void DontMigrateAndPrevent()
{
var config = PluginConfiguration.CreateForType<kOSCustomParameters>();
config.load();
config.SetValue("InstructionsPerUpdate", -2); // using -2 so it's different from the default value
config.SetValue("SettingMigrationComment", "All settings except telnet settings are now stored in the game's save file. Settings stored here will be ignored.");
config.SetValue("PreventFutureMigrationComment", "The user selected to prevent future migration notices when loading or creating save files. Change the IPU value to a positive value to re-enable migrations.");
config.save();
migrated = true;
}
}
}