NeighTools / UnityDoorstop

Doorstop -- run C# before Unity does!
GNU Lesser General Public License v2.1
419 stars 62 forks source link

Mono search paths - multiple overrides and replace full mono search path #36

Closed CptMoore closed 1 year ago

CptMoore commented 1 year ago

Allow multiple directories for mono_dll_search_path_override and allow to remove the target_path_folder and root_dir.

Maybe something like this (inspired by AssemblySearchPaths in csproj):

mono_dll_search_paths=Z:\MostImportant;{override};{target};{root};D:\Fallback
mono_dll_search_paths=A:\TheOneAndOnly
mono_dll_search_paths=

quick overview of what is happening currently:

    if (has_override) {
        strcat(mono_search_path, override_dir_full);
        strcat(mono_search_path, PATH_SEP);
    }
    strcat(mono_search_path, target_path_folder);
    strcat(mono_search_path, PATH_SEP);
    strcat(mono_search_path, root_dir);

The "fallback" case is there to avoid when future updates of the game suddenly introduce their own versions of the assemblies. The "one and only" or "nothing" cases would allow using dynamic AppDomain.CurrentDomain.AssemblyResolve to programmatically resolve everything. (These are theoretical ideas that were not tested, so might not work well with Unity mono)

ghorsington commented 1 year ago

Greetings!

The current override was implemented to allow overwriting DLLs in the game's Managed folder without having to modify the folder contents. The use case is primarily for unstripping games, as you cannot generally even launch your DLL with the stripped assemblies, see #10.

I am not really into allowing freely swapping the order however you want, as mono's DLL search paths have a very high priority. Therefore I made it specifically very simple, only allowing one folder.

If you need an assembly resolver that is earlier than the one in AppDomain, you can install mono's native assembly search hooks, see for example:

Yes, you can implement the same hooks on C# side with P/Invoke.

CptMoore commented 1 year ago

Cool, ill look into the pInvoke stuff

CptMoore commented 1 year ago

So while playing around with search paths, i had cases where even an overridden search path wasn't adhered too. Im now force loading assemblies to make them first priority just to be sure in all cases. I wouldnt support this enhancements anymore either, due to the issues.