From 4f6e8bf8d184f3064d0d038f0439bf036f6a597b Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Thu, 8 Aug 2019 11:00:34 +0100 Subject: [PATCH] Trying PreserveAttribute instead --- Facepunch.Steamworks/Utility/Helpers.cs | 6 ++++++ Facepunch.Steamworks/Utility/SteamInterface.cs | 11 ----------- Facepunch.Steamworks/Utility/Utf8String.cs | 1 + 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Facepunch.Steamworks/Utility/Helpers.cs b/Facepunch.Steamworks/Utility/Helpers.cs index 26917a3..91dfe5e 100644 --- a/Facepunch.Steamworks/Utility/Helpers.cs +++ b/Facepunch.Steamworks/Utility/Helpers.cs @@ -73,4 +73,10 @@ internal class MonoPInvokeCallbackAttribute : Attribute { public MonoPInvokeCallbackAttribute() { } } + + /// + /// Prevent unity from stripping shit we depend on + /// https://docs.unity3d.com/Manual/ManagedCodeStripping.html + /// + internal class PreserveAttribute : System.Attribute { } } diff --git a/Facepunch.Steamworks/Utility/SteamInterface.cs b/Facepunch.Steamworks/Utility/SteamInterface.cs index 2ead970..d9d10ba 100644 --- a/Facepunch.Steamworks/Utility/SteamInterface.cs +++ b/Facepunch.Steamworks/Utility/SteamInterface.cs @@ -31,7 +31,6 @@ public void Init() return; } - PreservationHack(); throw new System.Exception( "Trying to initialize Steam Interface but Steam not initialized" ); } @@ -110,15 +109,5 @@ internal virtual void Shutdown() } public abstract void InitInternals(); - - internal void PreservationHack() - { - // - // Stop Utf8StringToNative.GetInstance getting culled by stuff like Unity's - // asselmbly optimization stuff. Here we just call it so it can't not exist. - // - var i = Utf8StringToNative.GetInstance( "don't cull this function" ); - i.GetNativeDataSize(); - } } } \ No newline at end of file diff --git a/Facepunch.Steamworks/Utility/Utf8String.cs b/Facepunch.Steamworks/Utility/Utf8String.cs index 062847d..ac73835 100644 --- a/Facepunch.Steamworks/Utility/Utf8String.cs +++ b/Facepunch.Steamworks/Utility/Utf8String.cs @@ -38,6 +38,7 @@ public IntPtr MarshalManagedToNative(object managedObj) public void CleanUpManagedData(object managedObj) => throw new System.NotImplementedException(); public int GetNativeDataSize() => -1; + [Preserve] public static ICustomMarshaler GetInstance(string cookie) => new Utf8StringToNative(); }