Skip to content

Commit

Permalink
Merge pull request #152 from SubnauticaModding/dev
Browse files Browse the repository at this point in the history
QModManager v3.3
  • Loading branch information
PrimeSonic authored Jun 29, 2020
2 parents 2e04ca4 + 8845106 commit da445ab
Show file tree
Hide file tree
Showing 21 changed files with 301 additions and 155 deletions.
Binary file modified Build/InstallerExtensions.dll
Binary file not shown.
Binary file modified Build/QModInstaller.dll
Binary file not shown.
35 changes: 35 additions & 0 deletions Build/QModInstaller.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Build/QModManager.exe
Binary file not shown.
Binary file modified Build/QModManager_Setup.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion Data/latest-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.1.0
3.3.0.0
4 changes: 2 additions & 2 deletions Executable/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("3.2.1.0")]
[assembly: AssemblyFileVersion("3.2.1.0")]
[assembly: AssemblyVersion("3.3.0.0")]
[assembly: AssemblyFileVersion("3.3.0.0")]
4 changes: 2 additions & 2 deletions Installer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

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

[assembly: AssemblyVersion("3.2.1.0")]
[assembly: AssemblyFileVersion("3.2.1.0")]
[assembly: AssemblyVersion("3.3.0.0")]
[assembly: AssemblyFileVersion("3.3.0.0")]
2 changes: 1 addition & 1 deletion Installer/QModsInstallerScript.iss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#endif

#define Name "QModManager" ; The name of the game will be added after it
#define Version "3.2.1"
#define Version "3.3.0"
#define Author "QModManager"
#define URL "https://github.com/QModManager/QModManager"
#define SupportURL "https://discord.gg/UpWuWwq"
Expand Down
2 changes: 1 addition & 1 deletion QModManager/Checks/NitroxCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class NitroxCheck
{
internal static bool IsInstalled { get; set; } = false;

[HarmonyPatch(typeof(GameInput), "Awake")]
[HarmonyPatch(typeof(GameInput), nameof(GameInput.Awake))]
internal static class AwakePatch
{
internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
Expand Down
14 changes: 5 additions & 9 deletions QModManager/HarmonyPatches/EnableConsoleSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
{
using Harmony;
using QModManager.Utility;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;

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

[HarmonyPostfix]
public static void Postfix(bool __result, string key)
public static void Postfix(bool defaultVal, string key, string label, ref bool __result)
{
if (key != "UWE.DisableConsole") return;

Config.EnableConsole = !__result;

return;
if (key == "UWE.DisableConsole")
{
Config.EnableConsole = !__result;
}
}
}
}
4 changes: 1 addition & 3 deletions QModManager/OptionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ internal static class OptionsManager
{
internal static int ModsTab;



[HarmonyPatch(typeof(uGUI_OptionsPanel), "AddTabs")]
[HarmonyPatch(typeof(uGUI_OptionsPanel), nameof(uGUI_OptionsPanel.AddTabs))]
internal static class OptionsPatch
{
[HarmonyPostfix]
Expand Down
2 changes: 2 additions & 0 deletions QModManager/Patching/ManifestValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public void CheckRequiredMods(QMod mod)
{
versionedDependencies.Add(new RequiredQMod(item.Key));
}

mod.RequiredDependencies.Add(item.Key);
}

mod.RequiredMods = versionedDependencies;
Expand Down
30 changes: 16 additions & 14 deletions QModManager/Patching/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal static void Patch()

Patched = true;

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

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

try
{
Logger.Info($"Folder structure:\n{IOUtilities.GetFolderStructureAsTree()}\n");
Logger.Info($"Folder structure:{IOUtilities.GetFolderStructureAsTree()}");
}
catch (Exception e)
{
Expand All @@ -81,15 +81,7 @@ internal static void Patch()

CurrentlyRunningGame = gameDetector.CurrentlyRunningGame;

try
{
PatchHarmony();
}
catch (Exception e)
{
Logger.Error("There was an error while trying to apply Harmony patches.");
Logger.Exception(e);
}
PatchHarmony();

if (NitroxCheck.IsInstalled)
{
Expand Down Expand Up @@ -171,9 +163,19 @@ private static void AddAssemblyResolveEvent()

private static void PatchHarmony()
{
Logger.Debug("Applying Harmony patches...");
HarmonyInstance.Create("qmodmanager").PatchAll();
Logger.Debug("Patched!");
try
{
Logger.Debug("Applying Harmony patches...");

HarmonyInstance.Create("qmodmanager").PatchAll();

Logger.Debug("Patched!");
}
catch (Exception e)
{
Logger.Error("There was an error while trying to apply Harmony patches.");
Logger.Exception(e);
}
}
}
}
24 changes: 12 additions & 12 deletions QModManager/Patching/QMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,40 @@ public QMod()
// Empty public constructor for JSON
}

[JsonProperty(Required = Required.Always)]
[JsonProperty]
public string Id { get; set; }

[JsonProperty(Required = Required.Always)]
[JsonProperty]
public string DisplayName { get; set; }

[JsonProperty(Required = Required.Always)]
[JsonProperty]
public string Author { get; set; }

[JsonProperty(Required = Required.Always)]
[JsonProperty]
public string Version { get; set; }

[JsonProperty(Required = Required.Default)]
[JsonProperty]
public string[] Dependencies { get; set; } = new string[0];

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

[JsonProperty(Required = Required.Default)]
[JsonProperty]
public string[] LoadBefore { get; set; } = new string[0];

[JsonProperty(Required = Required.Default)]
[JsonProperty]
public string[] LoadAfter { get; set; } = new string[0];

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

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

[JsonProperty(Required = Required.Always)]
[JsonProperty]
public string AssemblyName { get; set; }

[JsonProperty(Required = Required.Default)]
[JsonProperty]
public string EntryMethod { get; set; }

#endregion
Expand Down
7 changes: 5 additions & 2 deletions QModManager/Patching/QModFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,17 @@ private static QMod CreateFromJsonManifestFile(string subDirectory)

try
{
var settings = new JsonSerializerSettings
var deserializer = new JsonSerializer
{
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore
};

string jsonText = File.ReadAllText(jsonFile);

QMod mod = JsonConvert.DeserializeObject<QMod>(jsonText);
using StreamReader sr = new StreamReader(jsonFile);
using JsonReader reader = new JsonTextReader(sr);
QMod mod = deserializer.Deserialize<QMod>(reader);

mod.SubDirectory = subDirectory;

Expand Down
4 changes: 2 additions & 2 deletions QModManager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("3.2.1.0")]
[assembly: AssemblyFileVersion("3.2.1.0")]
[assembly: AssemblyVersion("3.3.0.0")]
[assembly: AssemblyFileVersion("3.3.0.0")]

[assembly: InternalsVisibleTo("QMMTests")]
[assembly: InternalsVisibleTo("QModManager")]
32 changes: 24 additions & 8 deletions QModManager/Utility/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,30 @@ internal static bool EnableDevMode

private static Dictionary<string, object> Cfg = new Dictionary<string, object>();
private static bool Loaded = false;
private static readonly JsonSerializer serializer = new JsonSerializer
{
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};

private static void Load()
private static void Load()
{
try
{
if (!File.Exists(ConfigPath)) File.WriteAllText(ConfigPath, "{}");
string text = File.ReadAllText(ConfigPath);
Cfg = JsonConvert.DeserializeObject<Dictionary<string, object>>(text);
if (!File.Exists(ConfigPath))
{
Save();
}

using StreamReader sr = new StreamReader(ConfigPath);
using JsonReader reader = new JsonTextReader(sr);
Cfg = serializer.Deserialize<Dictionary<string, object>>(reader);

if (Cfg == null)
{
File.WriteAllText(ConfigPath, "{}");
Cfg = new Dictionary<string, object>();
Save();
}

Loaded = true;
Expand All @@ -62,8 +74,9 @@ private static void Save()
{
try
{
string text = JsonConvert.SerializeObject(Cfg, Formatting.Indented);
File.WriteAllText(ConfigPath, text);
using StreamWriter sw = new StreamWriter(ConfigPath);
using JsonWriter writer = new JsonTextWriter(sw);
serializer.Serialize(writer, Cfg);
}
catch (Exception e)
{
Expand All @@ -74,7 +87,10 @@ private static void Save()

private static T Get<T>(string field, T def = default)
{
if (!Loaded) Load();
if (!Loaded)
{
Load();
}

if (!Cfg.TryGetValue(field, out object value))
return def;
Expand Down
Loading

0 comments on commit da445ab

Please sign in to comment.