From fdec6d824abf331fe428ec4914e90744e16e3927 Mon Sep 17 00:00:00 2001 From: Michael Ripley Date: Mon, 30 Aug 2021 15:51:33 -0500 Subject: [PATCH] Add `advertiseversion` config if `advertiseversion=true` then your version string will be untouched. Defaults to `false`, which does the standard spoofing behavior. --- NeosModLoader/Configuration.cs | 5 +++ NeosModLoader/ModLoader.cs | 2 +- NeosModLoader/NeosVersionReset.cs | 57 +++++++++++++----------- NeosModLoader/Properties/AssemblyInfo.cs | 4 +- README.md | 12 ++--- 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/NeosModLoader/Configuration.cs b/NeosModLoader/Configuration.cs index b2cada8..b3ca5f2 100644 --- a/NeosModLoader/Configuration.cs +++ b/NeosModLoader/Configuration.cs @@ -43,6 +43,10 @@ internal static Configuration get() { _configuration.NoMods = true; } + else if ("advertiseversion".Equals(key) && "true".Equals(value)) + { + _configuration.AdvertiseVersion = true; + } } } } @@ -76,5 +80,6 @@ private static string GetAssemblyDirectory() public bool Unsafe { get; private set; } = false; public bool Debug { get; private set; } = false; public bool NoMods { get; private set; } = false; + public bool AdvertiseVersion { get; private set; } = false; } } diff --git a/NeosModLoader/ModLoader.cs b/NeosModLoader/ModLoader.cs index 6fd0a02..4583591 100644 --- a/NeosModLoader/ModLoader.cs +++ b/NeosModLoader/ModLoader.cs @@ -10,7 +10,7 @@ namespace NeosModLoader { internal class ModLoader { - public static readonly string VERSION = "1.2.2"; + public static readonly string VERSION = "1.3.0"; private static readonly Type NEOS_MOD_TYPE = typeof(NeosMod); internal static Dictionary LoadedMods { get; } = new Dictionary(); diff --git a/NeosModLoader/NeosVersionReset.cs b/NeosModLoader/NeosVersionReset.cs index ab37aaa..20ad23c 100644 --- a/NeosModLoader/NeosVersionReset.cs +++ b/NeosModLoader/NeosVersionReset.cs @@ -15,53 +15,57 @@ internal class NeosVersionReset { internal static void Initialize() { + Configuration config = Configuration.get(); Engine engine = Engine.Current; + List extraAssemblies = Engine.ExtraAssemblies; + bool nmlPresent = extraAssemblies.Contains("NeosModLoader.dll"); - if (!extraAssemblies.Remove("NeosModLoader.dll")) + if (!nmlPresent) { - Logger.ErrorInternal("assertion failed: Engine.ExtraAssemblies did not contain NeosModLoader.dll"); - return; + throw new Exception("assertion failed: Engine.ExtraAssemblies did not contain NeosModLoader.dll"); } - if (Configuration.get().Unsafe) + bool otherPluginsPresent = extraAssemblies.Count > 1; + bool shouldSpoofCompatibility = !otherPluginsPresent || config.Unsafe; + bool shouldSpoofVersion = !config.AdvertiseVersion && shouldSpoofCompatibility; + + bool success = true; + if (shouldSpoofVersion) { - Logger.WarnInternal("Unsafe mode is on! Version will be reset even if other plugins are detected! Beware of using plugin components in multiplayer!"); + // we intentionally attempt to set the version string first, so if it fails the compatibilty hash is left on the original value + // this is to prevent the case where a player simply doesn't know their version string is wrong extraAssemblies.Clear(); + success = SpoofVersionString(engine); } - else if (extraAssemblies.Count != 0) + if (success && shouldSpoofCompatibility) { - Logger.ErrorInternal("NeosModLoader.dll must be your only plugin to keep multiplayer compatibility!"); - return; + success = SpoofCompatibilityHash(engine); } + if (success) + { + Logger.MsgInternal("version spoofing succeeded"); + } + else + { + Logger.WarnInternal("version spoofing failed"); + } + } + private static bool SpoofCompatibilityHash(Engine engine) + { string vanillaCompatibilityHash; int? vanillaProtocolVersionMaybe = GetVanillaProtocolVersion(); if (vanillaProtocolVersionMaybe is int vanillaProtocolVersion) { Logger.DebugInternal($"vanilla protocol version is {vanillaProtocolVersion}"); vanillaCompatibilityHash = CalculateCompatibilityHash(vanillaProtocolVersion); + return SetCompatibilityHash(engine, vanillaCompatibilityHash); } else { Logger.ErrorInternal("unable to determine vanilla protocol version"); - return; - } - - // we intentionally attempt to set the version string first, so if it fails the compatibilty hash is left on the original value - // this is to prevent the case where a player simply doesn't know their version string is wrong - bool success = SetVersionString(engine); - if (success) - { - success = SetCompatibilityHash(engine, vanillaCompatibilityHash); - } - if (success) - { - Logger.MsgInternal("version spoofing succeeded"); - } - else - { - Logger.WarnInternal("version spoofing failed"); + return false; } } @@ -95,7 +99,8 @@ private static bool SetCompatibilityHash(Engine engine, string Target) return true; } } - private static bool SetVersionString(Engine engine) + + private static bool SpoofVersionString(Engine engine) { // calculate correct version string string target = Engine.VersionNumber; diff --git a/NeosModLoader/Properties/AssemblyInfo.cs b/NeosModLoader/Properties/AssemblyInfo.cs index 0da9d19..489aef1 100644 --- a/NeosModLoader/Properties/AssemblyInfo.cs +++ b/NeosModLoader/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.2.0")] -[assembly: AssemblyFileVersion("1.2.2.0")] +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")] diff --git a/README.md b/README.md index 00429d3..87f3073 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,11 @@ Sort answer: maybe? Long answer: [see here](doc/neos_guidelines.md). ### Will people know I'm using mods? -- NeosModLoader itself does not do anything identifiable over the network. You will appear to be running the vanilla Neos version to any component that shows your version strings or compatibility hash. +- By default, NeosModLoader does not do anything identifiable over the network. You will appear to be running the vanilla Neos version to any component that shows your version strings or compatibility hash. - If you are running other plugins, they will alter your version strings and compatibility hash. - NeosModLoader logs to the same log file Neos uses. If you send your logs to anyone it will be obvious that you are using a plugin. This is intended. - NeosModLoader mods may have effects visible to other users, depending on the mod. +- If you wish to opt in to using your real version string you can set `advertiseversion=true` in the NeosModLoader.config file. ### Are mods safe? Mods are not sandboxed in any way. In other words, they run with the same level of privilege as Neos itself. A poorly written mod could cause performance or stability issues. A maliciously designed mod could give a malicious actor a dangerous level of control over your computer. **Make sure you only use mods from sources you trust.** @@ -153,7 +154,8 @@ debug=true nomods=false ``` -| Configuration | Default | Description | -| ------------- | ------- | ----------- | -| `debug` | `false` | if `true`, NeosMod.Debug() logs will appear in your log file. Otherwise, they are hidden. | -| `nomods` | `false` | if `true`, mods will not be loaded. | +| Configuration | Default | Description | +| ------------------ | ------- | ----------- | +| `debug` | `false` | If `true`, NeosMod.Debug() logs will appear in your log file. Otherwise, they are hidden. | +| `nomods` | `false` | If `true`, mods will not be loaded. | +| `advertiseversion` | `false` | If `false`, your version will be spoofed and will resemble `2021.8.29.1240`. If `true`, your version will be left unaltered and will resemble `2021.8.29.1240+NeosModLoader.dll`. This version string is visible to other players under certain circumstances. |