Skip to content

Commit da445ab

Browse files
authored
Merge pull request #152 from SubnauticaModding/dev
QModManager v3.3
2 parents 2e04ca4 + 8845106 commit da445ab

21 files changed

+301
-155
lines changed

Build/InstallerExtensions.dll

0 Bytes
Binary file not shown.

Build/QModInstaller.dll

5.5 KB
Binary file not shown.

Build/QModInstaller.xml

+35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Build/QModManager.exe

512 Bytes
Binary file not shown.

Build/QModManager_Setup.exe

3.16 KB
Binary file not shown.

Data/latest-version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.1.0
1+
3.3.0.0

Executable/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
[assembly: ComVisible(false)]
1414

15-
[assembly: AssemblyVersion("3.2.1.0")]
16-
[assembly: AssemblyFileVersion("3.2.1.0")]
15+
[assembly: AssemblyVersion("3.3.0.0")]
16+
[assembly: AssemblyFileVersion("3.3.0.0")]

Installer/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414

1515
[assembly: Guid("8c6c9a0b-80c4-43d2-89f2-749e6f09fdda")]
1616

17-
[assembly: AssemblyVersion("3.2.1.0")]
18-
[assembly: AssemblyFileVersion("3.2.1.0")]
17+
[assembly: AssemblyVersion("3.3.0.0")]
18+
[assembly: AssemblyFileVersion("3.3.0.0")]

Installer/QModsInstallerScript.iss

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#endif
66

77
#define Name "QModManager" ; The name of the game will be added after it
8-
#define Version "3.2.1"
8+
#define Version "3.3.0"
99
#define Author "QModManager"
1010
#define URL "https://github.com/QModManager/QModManager"
1111
#define SupportURL "https://discord.gg/UpWuWwq"

QModManager/Checks/NitroxCheck.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static class NitroxCheck
99
{
1010
internal static bool IsInstalled { get; set; } = false;
1111

12-
[HarmonyPatch(typeof(GameInput), "Awake")]
12+
[HarmonyPatch(typeof(GameInput), nameof(GameInput.Awake))]
1313
internal static class AwakePatch
1414
{
1515
internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)

QModManager/HarmonyPatches/EnableConsoleSetting.cs

+5-9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
{
33
using Harmony;
44
using QModManager.Utility;
5-
using System.Collections.Generic;
6-
using System.Reflection;
7-
using System.Reflection.Emit;
85
using UnityEngine;
96

107
[HarmonyPatch(typeof(DevConsole), nameof(DevConsole.Awake))]
@@ -26,13 +23,12 @@ internal static class PlayerPrefsUtils_PrefsToggle_Patch
2623
// This patch syncronizes the "Disable console" UI element in the F3 debug menu
2724

2825
[HarmonyPostfix]
29-
public static void Postfix(bool __result, string key)
26+
public static void Postfix(bool defaultVal, string key, string label, ref bool __result)
3027
{
31-
if (key != "UWE.DisableConsole") return;
32-
33-
Config.EnableConsole = !__result;
34-
35-
return;
28+
if (key == "UWE.DisableConsole")
29+
{
30+
Config.EnableConsole = !__result;
31+
}
3632
}
3733
}
3834
}

QModManager/OptionsManager.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ internal static class OptionsManager
88
{
99
internal static int ModsTab;
1010

11-
12-
13-
[HarmonyPatch(typeof(uGUI_OptionsPanel), "AddTabs")]
11+
[HarmonyPatch(typeof(uGUI_OptionsPanel), nameof(uGUI_OptionsPanel.AddTabs))]
1412
internal static class OptionsPatch
1513
{
1614
[HarmonyPostfix]

QModManager/Patching/ManifestValidator.cs

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public void CheckRequiredMods(QMod mod)
144144
{
145145
versionedDependencies.Add(new RequiredQMod(item.Key));
146146
}
147+
148+
mod.RequiredDependencies.Add(item.Key);
147149
}
148150

149151
mod.RequiredMods = versionedDependencies;

QModManager/Patching/Patcher.cs

+16-14
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal static void Patch()
4141

4242
Patched = true;
4343

44-
Logger.Info("Game Version: " + SNUtils.GetPlasticChangeSetOfBuild() + " Build Date: " + SNUtils.GetDateTimeOfBuild().ToLongDateString());
44+
Logger.Info($"Game Version: {SNUtils.GetPlasticChangeSetOfBuild()} Build Date: {SNUtils.GetDateTimeOfBuild():dd-MMMM-yyyy}");
4545
Logger.Info($"Loading QModManager v{Assembly.GetExecutingAssembly().GetName().Version.ToStringParsed()}...");
4646
Logger.Info($"Today is {DateTime.Today:dd-MMMM-yyyy}");
4747

@@ -64,7 +64,7 @@ internal static void Patch()
6464

6565
try
6666
{
67-
Logger.Info($"Folder structure:\n{IOUtilities.GetFolderStructureAsTree()}\n");
67+
Logger.Info($"Folder structure:{IOUtilities.GetFolderStructureAsTree()}");
6868
}
6969
catch (Exception e)
7070
{
@@ -81,15 +81,7 @@ internal static void Patch()
8181

8282
CurrentlyRunningGame = gameDetector.CurrentlyRunningGame;
8383

84-
try
85-
{
86-
PatchHarmony();
87-
}
88-
catch (Exception e)
89-
{
90-
Logger.Error("There was an error while trying to apply Harmony patches.");
91-
Logger.Exception(e);
92-
}
84+
PatchHarmony();
9385

9486
if (NitroxCheck.IsInstalled)
9587
{
@@ -171,9 +163,19 @@ private static void AddAssemblyResolveEvent()
171163

172164
private static void PatchHarmony()
173165
{
174-
Logger.Debug("Applying Harmony patches...");
175-
HarmonyInstance.Create("qmodmanager").PatchAll();
176-
Logger.Debug("Patched!");
166+
try
167+
{
168+
Logger.Debug("Applying Harmony patches...");
169+
170+
HarmonyInstance.Create("qmodmanager").PatchAll();
171+
172+
Logger.Debug("Patched!");
173+
}
174+
catch (Exception e)
175+
{
176+
Logger.Error("There was an error while trying to apply Harmony patches.");
177+
Logger.Exception(e);
178+
}
177179
}
178180
}
179181
}

QModManager/Patching/QMod.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,40 @@ public QMod()
1919
// Empty public constructor for JSON
2020
}
2121

22-
[JsonProperty(Required = Required.Always)]
22+
[JsonProperty]
2323
public string Id { get; set; }
2424

25-
[JsonProperty(Required = Required.Always)]
25+
[JsonProperty]
2626
public string DisplayName { get; set; }
2727

28-
[JsonProperty(Required = Required.Always)]
28+
[JsonProperty]
2929
public string Author { get; set; }
3030

31-
[JsonProperty(Required = Required.Always)]
31+
[JsonProperty]
3232
public string Version { get; set; }
3333

34-
[JsonProperty(Required = Required.Default)]
34+
[JsonProperty]
3535
public string[] Dependencies { get; set; } = new string[0];
3636

37-
[JsonProperty(Required = Required.Default)]
37+
[JsonProperty]
3838
public Dictionary<string, string> VersionDependencies { get; set; } = new Dictionary<string, string>();
3939

40-
[JsonProperty(Required = Required.Default)]
40+
[JsonProperty]
4141
public string[] LoadBefore { get; set; } = new string[0];
4242

43-
[JsonProperty(Required = Required.Default)]
43+
[JsonProperty]
4444
public string[] LoadAfter { get; set; } = new string[0];
4545

46-
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
46+
[JsonProperty]
4747
public bool Enable { get; set; } = true;
4848

49-
[JsonProperty(Required = Required.DisallowNull)]
49+
[JsonProperty]
5050
public string Game { get; set; } = $"{QModGame.Subnautica}";
5151

52-
[JsonProperty(Required = Required.Always)]
52+
[JsonProperty]
5353
public string AssemblyName { get; set; }
5454

55-
[JsonProperty(Required = Required.Default)]
55+
[JsonProperty]
5656
public string EntryMethod { get; set; }
5757

5858
#endregion

QModManager/Patching/QModFactory.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,17 @@ private static QMod CreateFromJsonManifestFile(string subDirectory)
165165

166166
try
167167
{
168-
var settings = new JsonSerializerSettings
168+
var deserializer = new JsonSerializer
169169
{
170+
NullValueHandling = NullValueHandling.Ignore,
170171
MissingMemberHandling = MissingMemberHandling.Ignore
171172
};
172173

173174
string jsonText = File.ReadAllText(jsonFile);
174175

175-
QMod mod = JsonConvert.DeserializeObject<QMod>(jsonText);
176+
using StreamReader sr = new StreamReader(jsonFile);
177+
using JsonReader reader = new JsonTextReader(sr);
178+
QMod mod = deserializer.Deserialize<QMod>(reader);
176179

177180
mod.SubDirectory = subDirectory;
178181

QModManager/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
[assembly: ComVisible(false)]
1515

16-
[assembly: AssemblyVersion("3.2.1.0")]
17-
[assembly: AssemblyFileVersion("3.2.1.0")]
16+
[assembly: AssemblyVersion("3.3.0.0")]
17+
[assembly: AssemblyFileVersion("3.3.0.0")]
1818

1919
[assembly: InternalsVisibleTo("QMMTests")]
2020
[assembly: InternalsVisibleTo("QModManager")]

QModManager/Utility/Config.cs

+24-8
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,30 @@ internal static bool EnableDevMode
3535

3636
private static Dictionary<string, object> Cfg = new Dictionary<string, object>();
3737
private static bool Loaded = false;
38+
private static readonly JsonSerializer serializer = new JsonSerializer
39+
{
40+
NullValueHandling = NullValueHandling.Ignore,
41+
MissingMemberHandling = MissingMemberHandling.Ignore,
42+
DefaultValueHandling = DefaultValueHandling.Ignore
43+
};
3844

39-
private static void Load()
45+
private static void Load()
4046
{
4147
try
4248
{
43-
if (!File.Exists(ConfigPath)) File.WriteAllText(ConfigPath, "{}");
44-
string text = File.ReadAllText(ConfigPath);
45-
Cfg = JsonConvert.DeserializeObject<Dictionary<string, object>>(text);
49+
if (!File.Exists(ConfigPath))
50+
{
51+
Save();
52+
}
53+
54+
using StreamReader sr = new StreamReader(ConfigPath);
55+
using JsonReader reader = new JsonTextReader(sr);
56+
Cfg = serializer.Deserialize<Dictionary<string, object>>(reader);
57+
4658
if (Cfg == null)
4759
{
48-
File.WriteAllText(ConfigPath, "{}");
4960
Cfg = new Dictionary<string, object>();
61+
Save();
5062
}
5163

5264
Loaded = true;
@@ -62,8 +74,9 @@ private static void Save()
6274
{
6375
try
6476
{
65-
string text = JsonConvert.SerializeObject(Cfg, Formatting.Indented);
66-
File.WriteAllText(ConfigPath, text);
77+
using StreamWriter sw = new StreamWriter(ConfigPath);
78+
using JsonWriter writer = new JsonTextWriter(sw);
79+
serializer.Serialize(writer, Cfg);
6780
}
6881
catch (Exception e)
6982
{
@@ -74,7 +87,10 @@ private static void Save()
7487

7588
private static T Get<T>(string field, T def = default)
7689
{
77-
if (!Loaded) Load();
90+
if (!Loaded)
91+
{
92+
Load();
93+
}
7894

7995
if (!Cfg.TryGetValue(field, out object value))
8096
return def;

0 commit comments

Comments
 (0)