diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index 09f91444..4b1458e6 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -38,8 +38,11 @@ namespace IPA.Injector loader.Debug("Prepping bootstrapper"); - // // This will load Mono.Cecil + // This will load Mono.Cecil InstallBootstrapPatch(); + + // loads Assembly-CSharp-firstpass + PiracyChecks(); } catch (Exception e) { @@ -143,6 +146,14 @@ namespace IPA.Injector #endregion } + private static void PiracyChecks() + { + if (Utilities.AntiPiracy.PiracyChecks.IsPirated) + { + log.Critical("You are using a pirated copy of the game! You will not recieve support for any mods."); + } + } + private static bool bootstrapped = false; private static void CreateBootstrapper() { diff --git a/IPA.Loader/Utilities/AntiPiracy.cs b/IPA.Loader/Utilities/AntiPiracy.cs new file mode 100644 index 00000000..d171cd4d --- /dev/null +++ b/IPA.Loader/Utilities/AntiPiracy.cs @@ -0,0 +1,76 @@ +using System; +using System.IO; +using UnityEngine; +using Steamworks; + +namespace IPA.Utilities.AntiPiracy +{ + /// + /// Provides checks for whether or not the game is pirated. + /// + public static class PiracyChecks + { + /// + /// Runs through a list of checks to detect whether a game is pirated + /// + /// + public static bool IsPirated + { + get + { + // Check for spoofed Steam Client + if (BeatSaber.ReleaseType == BeatSaber.Release.Steam && IsSpoofedSteam()) + return true; + + // Check for the presence of known pirated files + if (HasKnownFiles()) + return true; + + // If we get here, probably not a pirate + return false; + } + } + + /// + /// Check common Steam Emulator values for red flags + /// + /// + static bool IsSpoofedSteam() + { + // Always resolves to "IGGGAMES" + string userName = SteamFriends.GetFriendPersonaName(SteamUser.GetSteamID()); + + // Always resolves to "SteamFriends" + string friendName = SteamFriends.GetFriendPersonaName(new CSteamID(76561198042581607)); + + // Return if they both resolve to known spoofed values + return userName == "IGGGAMES" && friendName == "SteamFriends"; + } + + /// + /// Check for files that are present in pirated copies + /// + /// + static bool HasKnownFiles() + { + // All known files + string[] paths = new string[] + { + Path.Combine(Application.dataPath, "Plugins", "valve.ini"), + Path.Combine(Application.dataPath, "Plugins", "steam.ini"), + Path.Combine(Application.dataPath, "Plugins", "huhuvr.ini"), + Path.GetFullPath(Path.Combine(Application.dataPath, "..", "SmartSteamEmu.ini")), + }; + + // Check for the existence of each file + foreach (string path in paths) + { + // If one is found, probably pirated + if (File.Exists(path)) + return true; + } + + return false; + } + } +} \ No newline at end of file