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

Conversation

@zkxs
Copy link
Collaborator

@zkxs zkxs commented Aug 17, 2022

Resolves #58.

This enumerates all loaded assemblies and uses a couple of heuristics to make a very educated guess about which ones are plugins. Those plugins are then used in the compatibility hash calculation.


edit: I'll go into more detail

  1. Enumerate all loaded assemblies using Froox's own [module: Description("POSTX_PROCESSED")] marker to filter to just the PostX processed assemblies
  2. Attempt to correlate the PostX'd assemblies with Neos's Engine.ExtraAssemblies. ExtraAssemblies is a list of the loaded plugins, but it only contains their filenames. No path information.
  3. Do some set theory to check for assemblies we couldn't match to plugins and plugins we couldn't match to assemblies.
    • assemblies we couldn't match to plugins aren't a huge deal, and we actually expect a few of these. Specifically, NeosModLoader, FrooxEngine, and BusinessX are all PostX'd assemblies we shouldn't treat as plugins. Anything not in this expected set I warn about.
    • plugins we couldn't match to assemblies are a bigger deal, and indicate that my plugin detection code failed. We can't version spoof properly in this case.
  4. Deal with the Unsafe and AdvertiseVersion configs
  5. Make sure I sort the assemblies in the same order Froox does
  6. Spoof the version string and the compatibility hash, but this time respecting plugins

@zkxs
Copy link
Collaborator Author

zkxs commented Aug 17, 2022

/home/runner/work/NeosModLoader/NeosModLoader/NeosModLoader/AssemblyLoader.cs(51,36): error WHITESPACE: Fix whitespace formatting. Delete 1 characters. [/home/runner/work/NeosModLoader/NeosModLoader/NeosModLoader/NeosModLoader.csproj]
/home/runner/work/NeosModLoader/NeosModLoader/NeosModLoader/Util.cs(77,1): error WHITESPACE: Fix whitespace formatting. Replace 17 characters with '\n\s\s\s\s\s\s\s\s'. [/home/runner/work/NeosModLoader/NeosModLoader/NeosModLoader/NeosModLoader.csproj]
/home/runner/work/NeosModLoader/NeosModLoader/NeosModLoader/Util.cs(78,69): error WHITESPACE: Fix whitespace formatting. Replace 9 characters with '\n\s\s\s\s\s\s\s\s'. [/home/runner/work/NeosModLoader/NeosModLoader/NeosModLoader/NeosModLoader.csproj]

I have no idea what the linter is complaining about. Those line/column targets don't appear valid to me.


edit: LJ fixed this with some dark magic of some sort

@zkxs
Copy link
Collaborator Author

zkxs commented Aug 17, 2022

Some example logs using a couple of plugins I have lying around.

with unsafe false

11:12:13 AM.760 (  0 FPS)	[DEBUG][NeosModLoader] Found 5 potential plugins: BusinessX.dll, FrooxEngine.dll, NeosDynamicBoneWizard.dll, NeosModLoader.dll, NQuery.dll
11:12:13 AM.768 (  0 FPS)	[DEBUG][NeosModLoader] Found 2 actual plugins: NeosDynamicBoneWizard.dll, NQuery.dll
11:12:13 AM.769 (  0 FPS)	[INFO] [NeosModLoader] Adding NeosModLoader.dll to version string because you have AdvertiseVersion set to true.
11:12:13 AM.771 (  0 FPS)	[DEBUG][NeosModLoader] Changing version string from 2022.1.28.1310+NeosModLoader.dll+NeosDynamicBoneWizard.dll+NQuery.dll to 2022.1.28.1310+NeosModLoader.dll+NeosDynamicBoneWizard.dll+NQuery.dll
11:12:13 AM.930 (  0 FPS)	[DEBUG][NeosModLoader] Vanilla protocol version is 843
11:12:13 AM.931 (  0 FPS)	[DEBUG][NeosModLoader] Changing compatibility hash from kTRVbxu53sCD7StS8J0Ehw== to rmJkVwWyIByK8lE5qvz+eA==
11:12:13 AM.931 (  0 FPS)	[INFO] [NeosModLoader] Compatibility hash spoofing succeeded

with unsafe true

11:13:09 AM.257 (  0 FPS)	[DEBUG][NeosModLoader] Found 5 potential plugins: BusinessX.dll, FrooxEngine.dll, NeosDynamicBoneWizard.dll, NeosModLoader.dll, NQuery.dll
11:13:09 AM.264 (  0 FPS)	[DEBUG][NeosModLoader] Found 2 actual plugins: NeosDynamicBoneWizard.dll, NQuery.dll
11:13:09 AM.265 (  0 FPS)	[WARN] [NeosModLoader] Unsafe mode is enabled! Not that you had a warranty, but now it's DOUBLE void!
11:13:09 AM.265 (  0 FPS)	[INFO] [NeosModLoader] Adding NeosModLoader.dll to version string because you have AdvertiseVersion set to true.
11:13:09 AM.267 (  0 FPS)	[DEBUG][NeosModLoader] Changing version string from 2022.1.28.1310+NeosModLoader.dll+NeosDynamicBoneWizard.dll+NQuery.dll to 2022.1.28.1310+NeosModLoader.dll+NeosDynamicBoneWizard.dll+NQuery.dll
11:13:09 AM.420 (  0 FPS)	[DEBUG][NeosModLoader] Vanilla protocol version is 843
11:13:09 AM.421 (  0 FPS)	[DEBUG][NeosModLoader] Changing compatibility hash from kTRVbxu53sCD7StS8J0Ehw== to jnnkdwkBqGv5+jlf1u/k7A==
11:13:09 AM.421 (  0 FPS)	[INFO] [NeosModLoader] Compatibility hash spoofing succeeded

@zkxs zkxs force-pushed the version-spoof-2-the-version-spoofining branch from 375e40e to c9c80fb Compare August 17, 2022 18:54
@zkxs zkxs requested review from EIA485 and l-2-j August 17, 2022 19:06
@l-2-j
Copy link
Member

l-2-j commented Aug 21, 2022

This sounds like a very hacky way to proceed, especially if we're having to deal with things such as

Make sure I sort the assemblies in the same order Froox does

...But I guess we can't do transpiler magic to just remove NeosModLoader, since the hash is calculated before NML loads?

@zkxs
Copy link
Collaborator Author

zkxs commented Aug 21, 2022

This sounds like a very hacky way to proceed, especially if we're having to deal with things such as

Make sure I sort the assemblies in the same order Froox does

...But I guess we can't do transpiler magic to just remove NeosModLoader, since the hash is calculated before NML loads?

Correct, the compatibility hash is calculated before NML is loaded, and Neos does not keep a list of loaded plugins I can use to recalculate after the fact. So the real problem here is how to get the list of plugins. I have two ideas for this I've listed in #58 (comment), and this PR uses the idea that, in my opinion, is the lesser of the evils.

The only way to get a non-hacky solution for this would for NML to not be a plugin at all, and to hook into Neos using a more "normal" modloader technique. And at that point we might as well just use a prexisting modloader, like BepinEx.

@zkxs zkxs changed the title Fix compatibility hash spoofing when plugins are present. Resolves #58. Fix compatibility hash spoofing when plugins are present. Aug 22, 2022
bool otherPluginsPresent = extraAssemblies.Count > 1;
bool shouldSpoofCompatibility = !otherPluginsPresent || config.Unsafe;
bool shouldSpoofVersion = !config.AdvertiseVersion && shouldSpoofCompatibility;
// get all PostX'd assemblies. This is useful, as plugins can't NOT be PostX'd.
Copy link
Member

@EIA485 EIA485 Aug 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some plugin authors use external tools to postX their plugins before they are loaded into neos

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's either PostX'd or not, and it doesn't matter if it's been done a month ago or seconds ago by neos.

public class ModLoader
{
internal const string VERSION_CONSTANT = "1.11.3";
internal const string VERSION_CONSTANT = "1.12.0";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that version bumps should usually just be done by @zkxs directly to the main branch in a commit that also tags it as the v1.12.0 for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're probably right. It'd definitely make the commit log easier to read. I'll start doing that in the future.

Copy link
Member

@l-2-j l-2-j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't say I thoroughly reviewed this, but as it seemed okay and can always be changed later on, 👍

@EIA485
Copy link
Member

EIA485 commented Aug 28, 2022

Can't say I thoroughly reviewed this, but as it seemed okay and can always be changed later on, 👍

yep, we can always change it later.

@zkxs zkxs merged commit f7b9ae2 into master Aug 29, 2022
@zkxs zkxs deleted the version-spoof-2-the-version-spoofining branch August 29, 2022 00:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using NML alongside other plugins, NML should not ruin the compatibility hash.

4 participants