NeighTools / UnityDoorstop

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

UnityDoorstop 4.0.0-rc.7 not working on mac #26

Closed KYPremco closed 2 years ago

KYPremco commented 2 years ago

Hello,

I'm trying to get UnityDoorstop 4 working on MacOS Mac version: macOS Catalina 10.15.5 Zip: doorstop_macos_release_4.0.0-rc.7.zip executable_name="Game.app" target_assembly="Doorstop.dll"

Tried the entrypoint example to write file on .NET 5 with .netstandard 2.1 & .NET 6. Works on Windows 11.

Error real mac: dyld: could not load inserted library 'libdoorstop.dylib' because image not found Error vm mac: dyld: could not load inserted library ' ' because image not found

Result of echo "${doorstop_name}": libdoorstop.dylib

I'm not experienced with .sh files the only thing I was able to find is that the game is able to start by changing export DYLD_INSERT_LIBRARIES="${doorstop_name}:${DYLD_INSERT_LIBRARIES}" to: export DYLD_INSERT_LIBRARIES="${doorstop_name}"

But it won't trigger the entrypoint or Mac can't write files with that script for some reason?

mo10 commented 2 years ago

This should be the same problem as #25 I am tracking this problem on x86_64 and arm platforms.

KYPremco commented 2 years ago

This should be the same problem as #25 I am tracking this problem on x86_64 and arm platforms.

In your issue you state that doorstop does load? Does this mean the initial entrypoint in the dll gets called?

As far I know in our machine it wont even start doorstop. And crashed already on the .sh at the end when exporting doorstop.dylib.

mo10 commented 2 years ago

This should be the same problem as #25 I am tracking this problem on x86_64 and arm platforms.

In your issue you state that doorstop does load? Does this mean the initial entrypoint in the dll gets called?

As far I know in our machine it wont even start doorstop. And crashed already on the .sh at the end when exporting doorstop.dylib.

If you run in the terminal, you should see that it tries to hook some functions but fails. A temporary solution is: replace plthook_open_by_address with plthook_open_by_handle https://github.com/NeighTools/UnityDoorstop/blob/2441a60f6b7d946d9e6c1493378796d196edac29/src/nix/entrypoint.c#L78

I am still testing. If there are no problems, I will create pr.

KYPremco commented 2 years ago

This should be the same problem as #25 I am tracking this problem on x86_64 and arm platforms.

In your issue you state that doorstop does load? Does this mean the initial entrypoint in the dll gets called? As far I know in our machine it wont even start doorstop. And crashed already on the .sh at the end when exporting doorstop.dylib.

If you run in the terminal, you should see that it tries to hook some functions but fails. A temporary solution is: replace plthook_open_by_address with plthook_open_by_handle

https://github.com/NeighTools/UnityDoorstop/blob/2441a60f6b7d946d9e6c1493378796d196edac29/src/nix/entrypoint.c#L78

I am still testing. If there are no problems, I will create pr.

That's the problem, it get's stuck before that part already I think. My console reads: vmware_TGbucw3QYr

vmware_U8vrbazpnw

Steps i've taken:

  1. Download https://doorstop_macos_debug_4.0.0-rc.7.zip
  2. Moved files from x64 to game root directory next to the .app
  3. Edited the executable name to the game
  4. Edited target_assembly to my build dll with just a File.WriteLine...
  5. Run the command chmod +x ./run.sh
  6. Run command ./run.sh

Am I missing something? Or do I need to build the dll different for a macOS user?

mo10 commented 2 years ago

Try replace to the last few lines of export commands

export LD_LIBRARY_PATH="${doorstop_directory}:${corlib_dir}:${LD_LIBRARY_PATH}"
if [ -z "$LD_PRELOAD" ]; then
    export LD_PRELOAD="${doorstop_name}"
else
    export LD_PRELOAD="${doorstop_name}:${LD_PRELOAD}"
fi

export DYLD_LIBRARY_PATH="${doorstop_directory}:${DYLD_LIBRARY_PATH}"
if [ -z "$DYLD_INSERT_LIBRARIES" ]; then
    export DYLD_INSERT_LIBRARIES="${doorstop_name}"
else
    export DYLD_INSERT_LIBRARIES="${doorstop_name}:${DYLD_INSERT_LIBRARIES}"
fi

This error occurs if your DYLD_INSERT_LIBRARIES contains an extra colon ":" This means that the DYLD_INSERT_LIBRARIES variable is empty or does not exist, but the script tries to concat it to end.

KYPremco commented 2 years ago

Try replace to the last few lines of export commands

export LD_LIBRARY_PATH="${doorstop_directory}:${corlib_dir}:${LD_LIBRARY_PATH}"
if [ -z "$LD_PRELOAD" ]; then
    export LD_PRELOAD="${doorstop_name}"
else
    export LD_PRELOAD="${doorstop_name}:${LD_PRELOAD}"
fi

export DYLD_LIBRARY_PATH="${doorstop_directory}:${DYLD_LIBRARY_PATH}"
if [ -z "$DYLD_INSERT_LIBRARIES" ]; then
    export DYLD_INSERT_LIBRARIES="${doorstop_name}"
else
    export DYLD_INSERT_LIBRARIES="${doorstop_name}:${DYLD_INSERT_LIBRARIES}"
fi

This error occurs if your DYLD_INSERT_LIBRARIES contains an extra colon ":" This means that the DYLD_INSERT_LIBRARIES variable is empty or does not exist, but the script tries to concat it to end.

Thank you very much, I was only able to locate the position of the error but would never known how to fix it. The updated run.sh + changing to plthook_open_by_handle seems to have worked for the default Doorstop example!! Hope to see your PR soon.