Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Add advertiseversion config
Browse files Browse the repository at this point in the history
if `advertiseversion=true` then your version string will be untouched. Defaults to `false`, which does the standard spoofing behavior.
  • Loading branch information
zkxs committed Aug 30, 2021
1 parent 2b1e9b3 commit fdec6d8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 34 deletions.
5 changes: 5 additions & 0 deletions NeosModLoader/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ internal static Configuration get()
{
_configuration.NoMods = true;
}
else if ("advertiseversion".Equals(key) && "true".Equals(value))
{
_configuration.AdvertiseVersion = true;
}
}
}
}
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion NeosModLoader/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Assembly, NeosMod> LoadedMods { get; } = new Dictionary<Assembly, NeosMod>();

Expand Down
57 changes: 31 additions & 26 deletions NeosModLoader/NeosVersionReset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,57 @@ internal class NeosVersionReset
{
internal static void Initialize()
{
Configuration config = Configuration.get();
Engine engine = Engine.Current;

List<string> 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;
}
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions NeosModLoader/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**
Expand Down Expand Up @@ -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. |

0 comments on commit fdec6d8

Please sign in to comment.