Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
1,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include "API/ARK/Ark.h"
  4. #include <IApiUtils.h>
  5. #include <API/UE/Math/ColorList.h>
  6. #include "Requests.h"
  7.  
  8. #include <nlohmann/json.hpp>
  9.  
  10. #include <fstream>
  11. #include <iostream>
  12.  
  13. #pragma comment(lib, "ArkApi.lib")
  14.  
  15. DECLARE_HOOK(AShooterGameMode_PreLogin, void, AShooterGameMode*, FString *, FString *, TSharedPtr<FUniqueNetId, 0> *, FString *, FString *);
  16.  
  17. DECLARE_HOOK(AShooterGameMode_StartNewShooterPlayer, void, AShooterGameMode*, APlayerController *, bool, bool, FPrimalPlayerCharacterConfigStruct *, UPrimalPlayerData *);
  18.  
  19. nlohmann::json config;
  20. std::vector<uint64> familysharing;
  21.  
  22. bool VectorContains(uint64 steamId)
  23. {
  24. return std::find(familysharing.begin(), familysharing.end(), steamId) != familysharing.end();
  25. }
  26.  
  27. void isPlayingSharedGame(bool success, std::string response, uint64 steamId)
  28. {
  29. if (success)
  30. {
  31. if (!response.empty() && !response.find("Forbidden"))
  32. {
  33. nlohmann::json parsedResponse = nlohmann::json::parse(response);
  34. const uint64 lenderSteamId = std::stoull(
  35. static_cast<std::string>(parsedResponse["response"]["lender_steamid"]), nullptr);
  36. if (lenderSteamId != 0)
  37. {
  38. if (!VectorContains(steamId))
  39. {
  40. familysharing.push_back(steamId);
  41. }
  42. }
  43. }
  44. else
  45. {
  46. Log::GetLog()->warn("Please check your config for a valid API Key");
  47. }
  48. }
  49. else
  50. {
  51. Log::GetLog()->warn("API Limit reached(100.000 per 24h) / Steam API down");
  52. }
  53. }
  54.  
  55. void Hook_AShooterGameMode_PreLogin(AShooterGameMode* _this, FString* Options, FString* Address,
  56. TSharedPtr<FUniqueNetId, 0>* UniqueId, FString* authToken, FString* ErrorMessage)
  57. {
  58. const uint64 steamId = static_cast<FUniqueNetIdSteam*>(UniqueId->Get())->UniqueNetId;
  59.  
  60. std::string apiKey = config["APIKey"];
  61. FString url = FString::Format(
  62. "http://api.steampowered.com/IPlayerService/IsPlayingSharedGame/v0001/?key={}&steamid={}&appid_playing=346110&format=json",
  63. apiKey, steamId);
  64.  
  65. API::Requests::Get().CreateGetRequest(url.ToString(), [steamId](bool success, std::string response)
  66. {
  67. isPlayingSharedGame(success, response, steamId);
  68. });
  69. AShooterGameMode_PreLogin_original(_this, Options, Address, UniqueId, authToken, ErrorMessage);
  70. }
  71.  
  72. void handleFamilysharing(uint64 steamId)
  73. {
  74. std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  75.  
  76. AShooterPlayerController* player = ArkApi::GetApiUtils().FindPlayerFromSteamId(steamId);
  77. if (player)
  78. {
  79.  
  80. ArkApi::GetApiUtils().GetShooterGameMode()->KickPlayerController(player, &FString("Family Shared Accounts Are Not Allowed On DopeArk, Connect With a Different Account"));
  81.  
  82. std::thread familyShare(handleFamilysharing, steamId);
  83. familyShare.detach();
  84. }
  85. else
  86. {
  87. Log::GetLog()->info("{} This Loser Has Tried To Connect With a Family Shared Account!", steamId);
  88. }
  89. }
  90.  
  91. void Hook_AShooterGameMode_StartNewShooterPlayer(AShooterGameMode* _this, APlayerController* NewPlayer, bool bForceCreateNewPlayerData, bool bIsFromLogin, FPrimalPlayerCharacterConfigStruct* charConfig, UPrimalPlayerData* ArkPlayerData)
  92. {
  93. if (NewPlayer)
  94. {
  95. AShooterPlayerController* player = static_cast<AShooterPlayerController*>(NewPlayer);
  96. const uint64 steamId = ArkApi::GetApiUtils().GetSteamIdFromController(player);
  97. if (VectorContains(steamId))
  98. {
  99. std::thread familyShare(handleFamilysharing, steamId);
  100. familyShare.detach();
  101. }
  102. }
  103.  
  104. AShooterGameMode_StartNewShooterPlayer_original(_this, NewPlayer, bForceCreateNewPlayerData, bIsFromLogin, charConfig, ArkPlayerData);
  105. }
  106.  
  107. void loadConfig()
  108. {
  109. const std::string config_path = ArkApi::Tools::GetCurrentDir() + "/ArkApi/Plugins/AntiFamilysharing/config.json";
  110. std::ifstream file(config_path);
  111. if (!file.is_open())
  112. throw std::runtime_error("Can't open config.json");
  113. file >> config;
  114. file.close();
  115. }
  116.  
  117. void Load()
  118. {
  119. Log::Get().Init("AntiFamilysharing");
  120. loadConfig();
  121.  
  122. ArkApi::GetHooks().SetHook("AShooterGameMode.PreLogin", &Hook_AShooterGameMode_PreLogin, &AShooterGameMode_PreLogin_original);
  123. ArkApi::GetHooks().SetHook("AShooterGameMode.StartNewShooterPlayer", &Hook_AShooterGameMode_StartNewShooterPlayer, &AShooterGameMode_StartNewShooterPlayer_original);
  124. }
  125.  
  126. void Unload()
  127. {
  128. ArkApi::GetHooks().DisableHook("AShooterGameMode.PreLogin", &Hook_AShooterGameMode_PreLogin);
  129. ArkApi::GetHooks().DisableHook("AShooterGameMode.StartNewShooterPlayer", &Hook_AShooterGameMode_StartNewShooterPlayer);
  130. }
  131.  
  132.  
  133. BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  134. {
  135. switch (ul_reason_for_call)
  136. {
  137. case DLL_PROCESS_ATTACH:
  138. Load();
  139. break;
  140. case DLL_PROCESS_DETACH:
  141. Unload();
  142. break;
  143. }
  144. return TRUE;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement