Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "API/ARK/Ark.h"
- #include <IApiUtils.h>
- #include <API/UE/Math/ColorList.h>
- #include "Requests.h"
- #include <nlohmann/json.hpp>
- #include <fstream>
- #include <iostream>
- #pragma comment(lib, "ArkApi.lib")
- DECLARE_HOOK(AShooterGameMode_PreLogin, void, AShooterGameMode*, FString *, FString *, TSharedPtr<FUniqueNetId, 0> *, FString *, FString *);
- DECLARE_HOOK(AShooterGameMode_StartNewShooterPlayer, void, AShooterGameMode*, APlayerController *, bool, bool, FPrimalPlayerCharacterConfigStruct *, UPrimalPlayerData *);
- nlohmann::json config;
- std::vector<uint64> familysharing;
- bool VectorContains(uint64 steamId)
- {
- return std::find(familysharing.begin(), familysharing.end(), steamId) != familysharing.end();
- }
- void isPlayingSharedGame(bool success, std::string response, uint64 steamId)
- {
- if (success)
- {
- if (!response.empty() && !response.find("Forbidden"))
- {
- nlohmann::json parsedResponse = nlohmann::json::parse(response);
- const uint64 lenderSteamId = std::stoull(
- static_cast<std::string>(parsedResponse["response"]["lender_steamid"]), nullptr);
- if (lenderSteamId != 0)
- {
- if (!VectorContains(steamId))
- {
- familysharing.push_back(steamId);
- }
- }
- }
- else
- {
- Log::GetLog()->warn("Please check your config for a valid API Key");
- }
- }
- else
- {
- Log::GetLog()->warn("API Limit reached(100.000 per 24h) / Steam API down");
- }
- }
- void Hook_AShooterGameMode_PreLogin(AShooterGameMode* _this, FString* Options, FString* Address,
- TSharedPtr<FUniqueNetId, 0>* UniqueId, FString* authToken, FString* ErrorMessage)
- {
- const uint64 steamId = static_cast<FUniqueNetIdSteam*>(UniqueId->Get())->UniqueNetId;
- std::string apiKey = config["APIKey"];
- FString url = FString::Format(
- "http://api.steampowered.com/IPlayerService/IsPlayingSharedGame/v0001/?key={}&steamid={}&appid_playing=346110&format=json",
- apiKey, steamId);
- API::Requests::Get().CreateGetRequest(url.ToString(), [steamId](bool success, std::string response)
- {
- isPlayingSharedGame(success, response, steamId);
- });
- AShooterGameMode_PreLogin_original(_this, Options, Address, UniqueId, authToken, ErrorMessage);
- }
- void handleFamilysharing(uint64 steamId)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- AShooterPlayerController* player = ArkApi::GetApiUtils().FindPlayerFromSteamId(steamId);
- if (player)
- {
- ArkApi::GetApiUtils().GetShooterGameMode()->KickPlayerController(player, &FString("Family Shared Accounts Are Not Allowed On DopeArk, Connect With a Different Account"));
- std::thread familyShare(handleFamilysharing, steamId);
- familyShare.detach();
- }
- else
- {
- Log::GetLog()->info("{} This Loser Has Tried To Connect With a Family Shared Account!", steamId);
- }
- }
- void Hook_AShooterGameMode_StartNewShooterPlayer(AShooterGameMode* _this, APlayerController* NewPlayer, bool bForceCreateNewPlayerData, bool bIsFromLogin, FPrimalPlayerCharacterConfigStruct* charConfig, UPrimalPlayerData* ArkPlayerData)
- {
- if (NewPlayer)
- {
- AShooterPlayerController* player = static_cast<AShooterPlayerController*>(NewPlayer);
- const uint64 steamId = ArkApi::GetApiUtils().GetSteamIdFromController(player);
- if (VectorContains(steamId))
- {
- std::thread familyShare(handleFamilysharing, steamId);
- familyShare.detach();
- }
- }
- AShooterGameMode_StartNewShooterPlayer_original(_this, NewPlayer, bForceCreateNewPlayerData, bIsFromLogin, charConfig, ArkPlayerData);
- }
- void loadConfig()
- {
- const std::string config_path = ArkApi::Tools::GetCurrentDir() + "/ArkApi/Plugins/AntiFamilysharing/config.json";
- std::ifstream file(config_path);
- if (!file.is_open())
- throw std::runtime_error("Can't open config.json");
- file >> config;
- file.close();
- }
- void Load()
- {
- Log::Get().Init("AntiFamilysharing");
- loadConfig();
- ArkApi::GetHooks().SetHook("AShooterGameMode.PreLogin", &Hook_AShooterGameMode_PreLogin, &AShooterGameMode_PreLogin_original);
- ArkApi::GetHooks().SetHook("AShooterGameMode.StartNewShooterPlayer", &Hook_AShooterGameMode_StartNewShooterPlayer, &AShooterGameMode_StartNewShooterPlayer_original);
- }
- void Unload()
- {
- ArkApi::GetHooks().DisableHook("AShooterGameMode.PreLogin", &Hook_AShooterGameMode_PreLogin);
- ArkApi::GetHooks().DisableHook("AShooterGameMode.StartNewShooterPlayer", &Hook_AShooterGameMode_StartNewShooterPlayer);
- }
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- Load();
- break;
- case DLL_PROCESS_DETACH:
- Unload();
- break;
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement