Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: universal build #33

Closed
wants to merge 2 commits into from
Closed

feat: universal build #33

wants to merge 2 commits into from

Conversation

timkurvers
Copy link
Owner

@timkurvers timkurvers commented Jul 28, 2023

This PR turns the build universal, supporting both Rosetta 2 and Apple Silicon, resolving #32.

Unfortunately, UnityPlayer is seemingly actively preventing OpenGL from being used on arm64, so this PR contains a binary patch to 'rectify' that.

Caution

This branch is no longer compatible with recent Valheim versions: the proposed workaround will likely need to be adjusted.

The native Apple Silicon build seems / feels a bit snappier to my untrained eye.

Things to figure out:

  • Is patching UnityPlayer.dylib in this manner safe / a good idea?
  • What are the implications of having to re-sign UnityPlayer.dylib?
  • Does Steam cloud sync / loading work properly? (initially, all characters were gone 😱 )
  • Does multiplayer work correctly? (have only tested single-player briefly)
  • What are these graphical glitches in the sky? (see video below)
  • Does Steamworks.NET.txt need updating? (left it as-is for now)
Screen.Recording.2023-07-28.at.10.40.57.mov

@timkurvers timkurvers self-assigned this Jul 28, 2023
@timkurvers timkurvers marked this pull request as draft July 28, 2023 09:14
@diericx
Copy link

diericx commented Jul 28, 2023

This is so cool!!

My saves are local so I can't comment on cloud save functionality.

Attempting to start a server throws this error.

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) Steamworks.NativeMethods.ISteamNetworkingUtils_SetConfigValue (intptr,Steamworks.ESteamNetworkingConfigValue,Steamworks.ESteamNetworkingConfigScope,intptr,Steamworks.ESteamNetworkingConfigDataType,intptr) <0x00007>
  at Steamworks.SteamNetworkingUtils.SetConfigValue (Steamworks.ESteamNetworkingConfigValue,Steamworks.ESteamNetworkingConfigScope,intptr,Steamworks.ESteamNetworkingConfigDataType,intptr) [0x00010] in <41ded11419264efb8272b696d45b3b19>:0
  at ZSteamSocket.RegisterGlobalCallbacks () [0x0005f] in <4d120e79a991451aa6d3a1b0239df629>:0
  at ZSteamSocket..ctor () [0x0003d] in <4d120e79a991451aa6d3a1b0239df629>:0
  at ZNet.Awake () [0x001a5] in <4d120e79a991451aa6d3a1b0239df629>:0
  at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) [0x00020] in <e5437daeca9a4c2a9c4cbe33a826b52a>:0

Connecting to a server could work though we didn't try that.

Single player works but I am noticing the same graphical issues you pointed out. After playing for a bit it seems that performance has not improved. I get around 80fps at first but then it drops to a mere 50 with stutters :( I suspect this change didn't help my situation because I am being throttled by my GPU. I wonder if any apple silicon products are being cpu throttled tbh (I am on an M2 air).

I assume any progress towards getting off translation/Rosetta would only alleviate cpu stress correct?

Screenshot 2023-07-28 at 11 51 23

@diericx
Copy link

diericx commented Jul 28, 2023

I wonder if any progress could be made using MoltenGL or MetalANGLE

@timkurvers
Copy link
Owner Author

Attempting to start a server throws this error.

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) Steamworks.NativeMethods.ISteamNetworkingUtils_SetConfigValue (intptr,Steamworks.ESteamNetworkingConfigValue,Steamworks.ESteamNetworkingConfigScope,intptr,Steamworks.ESteamNetworkingConfigDataType,intptr) <0x00007>
  at Steamworks.SteamNetworkingUtils.SetConfigValue (Steamworks.ESteamNetworkingConfigValue,Steamworks.ESteamNetworkingConfigScope,intptr,Steamworks.ESteamNetworkingConfigDataType,intptr) [0x00010] in <41ded11419264efb8272b696d45b3b19>:0
  at ZSteamSocket.RegisterGlobalCallbacks () [0x0005f] in <4d120e79a991451aa6d3a1b0239df629>:0
  at ZSteamSocket..ctor () [0x0003d] in <4d120e79a991451aa6d3a1b0239df629>:0
  at ZNet.Awake () [0x001a5] in <4d120e79a991451aa6d3a1b0239df629>:0
  at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) [0x00020] in <e5437daeca9a4c2a9c4cbe33a826b52a>:0

Connecting to a server could work though we didn't try that.

Ah, thanks for testing! That crash looks somewhat ominous 😱

Single player works but I am noticing the same graphical issues you pointed out. After playing for a bit it seems that performance has not improved. I get around 80fps at first but then it drops to a mere 50 with stutters :( I suspect this change didn't help my situation because I am being throttled by my GPU. I wonder if any apple silicon products are being cpu throttled tbh (I am on an M2 air).

I assume any progress towards getting off translation/Rosetta would only alleviate cpu stress correct?

I get somewhere between 60-80fps on M1 Pro @ 2650x1440. Can't exactly recall what type of quality settings I used.

Think your assumption is correct, there's likely GPU improvements possible, but it would require pure Metal, rather than OpenGL-over-Metal as is the case now.

@diericx
Copy link

diericx commented Jul 29, 2023

That crash looks somewhat ominous

Yeah it doesn't look good lol

I get somewhere between 60-80fps on M1 Pro @ 2650x1440

Huh, I am running at 1470x596... I would be very interested to see if you also notice performance/fps drop after around 5 minutes. I have also not noticed any thermal throttling so I really don't know what is happening.

@alimyuz
Copy link

alimyuz commented Sep 18, 2023

Tried the ARM build myself and I can confirm that:

  • My characters were synced from Steam without any issues
  • Was able to connect to a friend's server and play without any issues
  • Was able to start a server

My setup: M1 Air, Sonoma 14.0 Beta (23A5257q)

@hvab
Copy link

hvab commented Oct 7, 2023

With this build don't work mods mentioned in #9

@hamdeli
Copy link

hamdeli commented Jan 1, 2024

Just wanted to mention that this new build script requires you to have dotnet installed and symlinked properly otherwise the build script will fail on line 78:

./build.sh: line 78: dotnet: command not found

line 78 from the script:

    dotnet depotdownloader-2.5.0/DepotDownloader.dll -app $appid -depot $depotid -manifest $manifestid -beta $branch -os linux -username "$username"

Most of us have dotnet on our path, but for those that dont, install the homebrew cask for it.

Also: this branch is in desperate need of a rebase onto main to streamline some of the inline props... the versions are outdated behind mains

@timkurvers
Copy link
Owner Author

This branch is in desperate need of a rebase onto main to streamline some of the inline props... the versions are outdated behind mains.

Good catch, this is an old experimental branch that still requires dotnet, the main branch dropped this requirement a few days ago.

It might be possible to resurrect this branch, but the Unity OpenGL patch will need to be re-investigated as things have likely changed between Unity 2020 and 2022 (the version Valheim currently uses).

@mishatre
Copy link

@timkurvers If it's useful to you, I was able to find the same function that was patched in universal build but in unity 2022.3.12f1 and looks like it wasn't changed that much. And by patching same fallback line "mov w9, #0x4" I created build that was succesfully launched.

Other than that I copied script from main branch and update PlayFabParty to 1.9.1 event though I'm not sure it was nessesary.

New address:
6E4CAC MOV W9, #4

What line i change in script:
printf "\x29\x02" | dd of="$prefix/Frameworks/UnityPlayer.dylib" bs=1 seek=7228588 conv=notrunc

Cannot say about stability and perfomance, as I am launching valheim first time.

@ultrarationalist
Copy link

ultrarationalist commented Mar 2, 2024

New address: 6E4CAC MOV W9, #4

What line i change in script: printf "\x29\x02" | dd of="$prefix/Frameworks/UnityPlayer.dylib" bs=1 seek=7228588 conv=notrunc

What did work for me was to build the main branch, change script to arm64 and then manually patch the dylib with Binary Ninja - the address (6e4cac) is correct. No further changes needed. The patch via script line didn't work for me for some reason. It runs fine, except for the glitch with the clouds. Maybe there's a reason why OpenGL isn't supported.

@Alanko5
Copy link

Alanko5 commented Apr 15, 2024

you tried to update to Unity 2023.2.17 ?

working update:
playfabpartyversion="1.9.3"
playfabpartyasset="PlayFabPartyMac.framework-for-macOS-Release.zip"
playfabpartyhash="2032dd2cf93fa435a67908f68ed4f893"

Steamworks.NET have problem with ARM arch:
rlabrecque/Steamworks.NET#428
Facepunch/Facepunch.Steamworks#591

@mishatre
Copy link

@Alanko5 I stopped playing valheim some time ago, but out of sheer curiosity tried to find if i can repeat this trick in Unity 2022.2.17f.
And i was able to find same code block by 6E95E0 offset (7247328 for dd command) and successfully launched valheim. I didn't thoroughly test how good is it working but i was able to load my word and play. The only visible issue is cloud glitching (which was also preset on previous version)

@timkurvers
Copy link
Owner Author

Closing this PR as the official universal macOS client is now available! 🥳 (see #104)

@timkurvers timkurvers closed this Jul 22, 2024
@timkurvers timkurvers deleted the feat/universal-build branch July 22, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants