Skip to content

Commit

Permalink
GUID On runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Louvenarde committed Feb 2, 2024
1 parent 0d222e3 commit 67bd079
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 111 deletions.
5 changes: 0 additions & 5 deletions src/Components/Modules/AssetInterfaces/IXModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,11 +873,6 @@ namespace Assets

void IXModel::ConvertPlayerModelFromSingleplayerToMultiplayer(Game::XModel* model, Utils::Memory::Allocator& allocator)
{
if (model->name == "body_airport_com_a"s)
{
printf("");
}

std::string requiredBonesForHumanoid[] = {
"j_spinelower",
"j_spineupper",
Expand Down
111 changes: 61 additions & 50 deletions src/Components/Modules/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ namespace Components

std::vector<std::uint64_t> Auth::BannedUids =
{
0xf4d2c30b712ac6e3,
// No longer necessary
/* 0xf4d2c30b712ac6e3,
0xf7e33c4081337fa3,
0x6f5597f103cc50e9,
0xecd542eee54ffccf,
0xecd542eee54ffccf,*/
};

bool Auth::HasAccessToReservedSlot;

void Auth::Frame()
{
if (TokenContainer.generating)
Expand All @@ -45,15 +46,15 @@ namespace Components
if (mseconds < 0) mseconds = 0;
}

Localization::Set("MPUI_SECURITY_INCREASE_MESSAGE", Utils::String::VA("Increasing security level from %d to %d (est. %s)",GetSecurityLevel(), TokenContainer.targetLevel, Utils::String::FormatTimeSpan(static_cast<int>(mseconds)).data()));
Localization::Set("MPUI_SECURITY_INCREASE_MESSAGE", Utils::String::VA("Increasing security level from %d to %d (est. %s)", GetSecurityLevel(), TokenContainer.targetLevel, Utils::String::FormatTimeSpan(static_cast<int>(mseconds)).data()));
}
else if (TokenContainer.thread.joinable())
{
TokenContainer.thread.join();
TokenContainer.generating = false;

StoreKey();
Logger::Debug("Security level is {}",GetSecurityLevel());
Logger::Debug("Security level is {}", GetSecurityLevel());
Command::Execute("closemenu security_increase_popmenu", false);

if (!TokenContainer.cancel)
Expand Down Expand Up @@ -212,7 +213,7 @@ namespace Components
SteamID guid;
guid.bits = xuid;

if (Bans::IsBanned({guid, address.getIP()}))
if (Bans::IsBanned({ guid, address.getIP() }))
{
Logger::PrintFail2Ban("Failed connect attempt from IP address: {}\n", Network::AdrToString(address));
Network::Send(address, "error\nEXE_ERR_BANNED_PERM");
Expand Down Expand Up @@ -304,15 +305,15 @@ namespace Components
xor eax, eax
jmp safeContinue

noAccess:
mov eax, dword ptr [edx + 0x10]
noAccess :
mov eax, dword ptr[edx + 0x10]

safeContinue:
// Game code skipped by hook
add esp, 0xC
safeContinue :
// Game code skipped by hook
add esp, 0xC

push 0x460FB3
ret
push 0x460FB3
ret
}
}

Expand Down Expand Up @@ -342,6 +343,8 @@ namespace Components

void Auth::StoreKey()
{
// We write the key as a decoy I suppose - it's really no longer needed
// TODO Remove this part
if (!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled() && GuidKey.isValid())
{
Proto::Auth::Certificate cert;
Expand All @@ -366,23 +369,31 @@ namespace Components
if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) return;
if (!force && GuidKey.isValid()) return;

// We no longer read the key from disk
// While having obvious advantages to palliate the fact that some users are not playing on Steam,
// it is creating a lot of issues because GUID files get packaged with the game when people share it
// and it makes it harder for server owners to identify players uniquely
// Note that we could store it in Appdata, but then it would be dissociated from the rest of player files,
// so for now we're doing something else: the key is generated uniquely from the machine's characteristics
// It is not (necessarily) stored and therefore, not loaded, so it could make it harder to evade bans without
// using a custom client that would need regeneration at each update.
#if false
Proto::Auth::Certificate cert;
if (cert.ParseFromString(::Utils::IO::ReadFile("players/guid.dat")))
{
GuidKey.deserialize(cert.privatekey());
GuidToken = cert.token();
ComputeToken = cert.ctoken();
}
}
else
{
GuidKey.free();
}

if (!GuidKey.isValid())
{
#endif
Auth::GenerateKey();
}
}
}

uint32_t Auth::GetSecurityLevel()
{
Expand All @@ -404,18 +415,18 @@ namespace Components

// Start thread
TokenContainer.thread = std::thread([&level]()
{
TokenContainer.generating = true;
TokenContainer.hashes = 0;
TokenContainer.startTime = Game::Sys_Milliseconds();
IncrementToken(GuidToken, ComputeToken, GuidKey.getPublicKey(), TokenContainer.targetLevel, &TokenContainer.cancel, &TokenContainer.hashes);
TokenContainer.generating = false;

if (TokenContainer.cancel)
{
Logger::Print("Token incrementation thread terminated\n");
}
});
TokenContainer.generating = true;
TokenContainer.hashes = 0;
TokenContainer.startTime = Game::Sys_Milliseconds();
IncrementToken(GuidToken, ComputeToken, GuidKey.getPublicKey(), TokenContainer.targetLevel, &TokenContainer.cancel, &TokenContainer.hashes);
TokenContainer.generating = false;

if (TokenContainer.cancel)
{
Logger::Print("Token incrementation thread terminated\n");
}
});
}
}

Expand Down Expand Up @@ -521,36 +532,36 @@ namespace Components

// Guid command
Command::Add("guid", []
{
Logger::Print("Your guid: {:#X}\n", Steam::SteamUser()->GetSteamID().bits);
});
{
Logger::Print("Your guid: {:#X}\n", Steam::SteamUser()->GetSteamID().bits);
});

if (!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled())
{
Command::Add("securityLevel", [](const Command::Params* params)
{
if (params->size() < 2)
{
const auto level = GetZeroBits(GuidToken, GuidKey.getPublicKey());
Logger::Print("Your current security level is {}\n", level);
Logger::Print("Your security token is: {}\n", Utils::String::DumpHex(GuidToken.toString(), ""));
Logger::Print("Your computation token is: {}\n", Utils::String::DumpHex(ComputeToken.toString(), ""));

Toast::Show("cardicon_locked", "^5Security Level", Utils::String::VA("Your security level is %d", level), 3000);
}
else
{
const auto level = std::strtoul(params->get(1), nullptr, 10);
IncreaseSecurityLevel(level);
}
});
if (params->size() < 2)
{
const auto level = GetZeroBits(GuidToken, GuidKey.getPublicKey());
Logger::Print("Your current security level is {}\n", level);
Logger::Print("Your security token is: {}\n", Utils::String::DumpHex(GuidToken.toString(), ""));
Logger::Print("Your computation token is: {}\n", Utils::String::DumpHex(ComputeToken.toString(), ""));

Toast::Show("cardicon_locked", "^5Security Level", Utils::String::VA("Your security level is %d", level), 3000);
}
else
{
const auto level = std::strtoul(params->get(1), nullptr, 10);
IncreaseSecurityLevel(level);
}
});
}

UIScript::Add("security_increase_cancel", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
{
TokenContainer.cancel = true;
Logger::Print("Token incrementation process canceled!\n");
});
{
TokenContainer.cancel = true;
Logger::Print("Token incrementation process canceled!\n");
});
}

Auth::~Auth()
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Modules/Download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ namespace Components

void Download::Reply(mg_connection* connection, const std::string& contentType, const std::string& data)
{
const auto formatted = std::format("Content-Type: {}\r\n", contentType);
const auto formatted = std::format("Content-Type: {}\r\nAccess-Control-Allow-Origin: *\r\n", contentType);
mg_http_reply(connection, 200, formatted.c_str(), "%s", data.c_str());
}

Expand Down
3 changes: 3 additions & 0 deletions src/STDInclude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
#include <dwmapi.h>
#pragma comment (lib, "dwmapi.lib")

#include <iphlpapi.h>
#pragma comment (lib, "iphlpapi.lib")

// Ignore the warnings
#pragma warning(push)
#pragma warning(disable: 4100)
Expand Down
Loading

0 comments on commit 67bd079

Please sign in to comment.