You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.4 KiB

  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. using Steamworks;
  5. namespace IPA.Utilities.AntiPiracy
  6. {
  7. /// <summary>
  8. /// Provides checks for whether or not the game is pirated.
  9. /// </summary>
  10. public static class PiracyChecks
  11. {
  12. /// <summary>
  13. /// Runs through a list of checks to detect whether a game is pirated
  14. /// </summary>
  15. /// <returns></returns>
  16. public static bool IsPirated
  17. {
  18. get
  19. {
  20. // Check for spoofed Steam Client
  21. if (BeatSaber.ReleaseType == BeatSaber.Release.Steam && IsSpoofedSteam())
  22. return true;
  23. // Check for the presence of known pirated files
  24. if (HasKnownFiles())
  25. return true;
  26. // If we get here, probably not a pirate
  27. return false;
  28. }
  29. }
  30. /// <summary>
  31. /// Check common Steam Emulator values for red flags
  32. /// </summary>
  33. /// <returns></returns>
  34. static bool IsSpoofedSteam()
  35. {
  36. // Always resolves to "IGGGAMES"
  37. string userName = SteamFriends.GetFriendPersonaName(SteamUser.GetSteamID());
  38. // Always resolves to "SteamFriends"
  39. string friendName = SteamFriends.GetFriendPersonaName(new CSteamID(76561198042581607));
  40. // Return if they both resolve to known spoofed values
  41. return userName == "IGGGAMES" && friendName == "SteamFriends";
  42. }
  43. /// <summary>
  44. /// Check for files that are present in pirated copies
  45. /// </summary>
  46. /// <returns></returns>
  47. static bool HasKnownFiles()
  48. {
  49. // All known files
  50. string[] paths = new string[]
  51. {
  52. Path.Combine(Application.dataPath, "Plugins", "valve.ini"),
  53. Path.Combine(Application.dataPath, "Plugins", "steam.ini"),
  54. Path.Combine(Application.dataPath, "Plugins", "huhuvr.ini"),
  55. Path.GetFullPath(Path.Combine(Application.dataPath, "..", "SmartSteamEmu.ini")),
  56. };
  57. // Check for the existence of each file
  58. foreach (string path in paths)
  59. {
  60. // If one is found, probably pirated
  61. if (File.Exists(path))
  62. return true;
  63. }
  64. return false;
  65. }
  66. }
  67. }