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

Make CheckSteamAPIDLL usable #276

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions Plugins/Steamworks.NET/InteropHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

#if !DISABLESTEAMWORKS

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
#define DLLCHECK
#endif

using System.Runtime.InteropServices;
using IntPtr = System.IntPtr;

Expand All @@ -19,7 +23,7 @@
namespace Steamworks {
public class InteropHelp {
public static void TestIfPlatformSupported() {
#if !UNITY_EDITOR && !UNITY_STANDALONE && !STEAMWORKS_WIN && !STEAMWORKS_LIN_OSX
#if !UNITY_EDITOR && !UNITY_STANDALONE
throw new System.InvalidOperationException("Steamworks functions can only be called on platforms that Steam is available on.");
#endif
}
Expand Down Expand Up @@ -65,7 +69,7 @@ public static string PtrToStringUTF8(IntPtr nativeUtf8) {

// This is for 'const char *' arguments which we need to ensure do not get GC'd while Steam is using them.
// We can't use an ICustomMarshaler because Unity crashes when a string between 96 and 127 characters long is defined/initialized at the top of class scope...
#if UNITY_EDITOR || UNITY_STANDALONE || STEAMWORKS_WIN || STEAMWORKS_LIN_OSX
#if UNITY_EDITOR || UNITY_STANDALONE
public class UTF8StringHandle : Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid {
public UTF8StringHandle(string str)
: base(true) {
Expand Down Expand Up @@ -189,7 +193,7 @@ public static implicit operator IntPtr(MMKVPMarshaller that) {
}

public class DllCheck {
#if DISABLED
#if DLLCHECK
[DllImport("kernel32.dll")]
public static extern IntPtr GetModuleHandle(string lpModuleName);

Expand All @@ -201,13 +205,14 @@ public class DllCheck {
/// This is an optional runtime check to ensure that the dlls are the correct version. Returns false only if the steam_api.dll is found and it's the wrong size or version number.
/// </summary>
public static bool Test() {
#if DISABLED
bool ret = CheckSteamAPIDLL();
#endif
#if DLLCHECK
return CheckSteamAPIDLL();
#else
return true;
#endif
}

#if DISABLED
#if DLLCHECK
private static bool CheckSteamAPIDLL() {
string fileName;
int fileBytes;
Expand Down Expand Up @@ -235,10 +240,11 @@ private static bool CheckSteamAPIDLL() {
if (fInfo.Length != fileBytes) {
return false;
}

#if !ENABLE_IL2CPP
if (System.Diagnostics.FileVersionInfo.GetVersionInfo(file).FileVersion != Version.SteamAPIDLLVersion) {
return false;
}
#endif
}
return true;
}
Expand Down