NeighTools / UnityDoorstop

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

Version.dll missing. #7

Closed dunawayc closed 4 years ago

dunawayc commented 4 years ago

I seem to be misunderstanding how Doorstep is supposed to work. The instruction all say to copy version.dll to the game folder, but I do not see version.dll in any release for Doorstep.

In addition, when I build Doorstep in VS 2019, no version.dll is created. A proxy.dll is created, but I do not know what to do with that file. Should it be renamed to version.dll?

Also, I had to change the pre-build event because the paths in the arguments to the powershell script seemed to be missing quotation marks. The following is what I changed it to to get it to build without error (note the quotes on the -File, -projectPath, and -templatePath arguments):

powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File "$(SolutionDir)\scripts\genproxy.ps1" -projectPath "$(ProjectDir)" -templatePath "$(SolutionDir)scripts" -arch $(PlatformArchitecture)

I don't know if this would cause my issue or not.

For reference I am trying to mod the game 7 Days 2 Die.

ghorsington commented 4 years ago

Greetings!

Pardon for a rather late response! Unfortunately the wiki was a tad out-of-date: the latest Doorstop builds proxy winhttp.dll instead of version.dll for better compatibility.

If you build Doorstop from source, it outputs proxy.dll on purpose. Doorstop allows you to easily swap the proxying DLL (or proxy multiple DLLs at once), so at build time there is no way to know which DLL you're proxying. As such, the build outputs a generic proxy.dll which you can then rename to winhttp.dll (or to another name of the DLL you chose to proxy). You can specify the proxy functions inside the dll.def definition file.

As for the pre-build event, I'm sorry to heard that. I'll fix the issue right away. I'll close the issue once it's fixed.

ghorsington commented 4 years ago

Fixed in https://github.com/NeighTools/UnityDoorstop/commit/5883842aec0e29f522ed533981c147e851f74c76

dunawayc commented 4 years ago

Thanks for the response.

Please pardon a noob question.

So by copying the proxy.dll (renamed to winhttp.dll) into the games root folder, does the game load the proxy instead of the 'real' winhttp.dll in c:\windows\system32?

I'm guessing then, that whatever we have configured in doorstop_config.ini, gets injected into the managed process and executed first. So I could then load, for example, the Harmony patching library to make mods for the game.

Have I understood correctly?

Thanks again!

------ Original Message ------ From: "Geoffrey Horsington" notifications@github.com To: "NeighTools/UnityDoorstop" UnityDoorstop@noreply.github.com Cc: "dunawayc" chrisadunaway@att.net; "Author" author@noreply.github.com Sent: 4/28/2020 2:20:16 PM Subject: Re: [NeighTools/UnityDoorstop] Version.dll missing. (#7)

Closed #7 https://github.com/NeighTools/UnityDoorstop/issues/7.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/NeighTools/UnityDoorstop/issues/7#event-3281774558, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADMVQDV4BBXYWGTKJ4KPJZDRO4T7BANCNFSM4MQ6FAGA.

ghorsington commented 4 years ago

You are indeed correct! When Unity loads itself up, it looks for winhttp.dll. Owing to the nature of dll load order, it picks up the proxy dll that is in the same folder as the game executable. From that, the proxy loads the original dll to ensure any game code still works and it then proceeds to hook itself into Mono's (the runtime Unity uses to run c# code) initialization code.

Then, when Unity initializes Mono, Doorstop's hook kicks in and it loads the DLL you specify in doorstop_config.ini. From there you can patch and manipulate the game however you want: you can patch things with Harmony or you can install assembly load hooks to run code when a certain assembly is loaded.

The main appeal of Doorstop is that your code runs as the very first thing, even before any of Unity's own dlls are loaded. This allows to do some more advanced manipulations, like actually editing the game assembles (e.g. add or remove classes, add or remove fields etc) before they are loaded. Such an example is the preloader of BepInEx framework: https://bepinex.github.io/bepinex_docs/v5.0/articles/dev_guide/preloader_patchers.html

Please refer to the updated wiki or the readme for info on how to configure Doorstop.