2023-03-06 15:40:07 -05:00
# include <std_include.hpp>
2023-05-11 16:50:11 -04:00
# include "platform.hpp"
2023-09-06 08:08:38 -04:00
# include "definitions/game.hpp"
2023-03-06 15:40:07 -05:00
# include "loader/component_loader.hpp"
2023-09-06 08:08:38 -04:00
2023-11-10 16:52:20 -05:00
# include <utilities/hook.hpp>
# include <utilities/string.hpp>
# include <utilities/identity.hpp>
# include <utilities/json_config.hpp>
# include <utilities/cryptography.hpp>
2023-09-06 08:08:38 -04:00
# include <WinReg.hpp>
2023-03-06 15:40:07 -05:00
namespace platform
{
2023-05-11 16:50:11 -04:00
uint64_t bnet_get_userid ( )
{
static uint64_t userid = 0 ;
if ( ! userid )
{
2023-11-10 16:52:20 -05:00
uint32_t default_xuid = utilities : : cryptography : : xxh32 : : compute ( utilities : : identity : : get_sys_username ( ) ) ;
userid = utilities : : json_config : : ReadUnsignedInteger64 ( " identity " , " xuid " , default_xuid ) ;
2023-05-11 16:50:11 -04:00
}
return userid ;
}
const char * bnet_get_username ( )
{
static std : : string username { } ;
if ( username . empty ( ) )
{
2023-11-10 16:52:20 -05:00
std : : string default_name = utilities : : identity : : get_sys_username ( ) ;
username = utilities : : json_config : : ReadString ( " identity " , " name " , default_name ) ;
2023-05-11 16:50:11 -04:00
}
return username . data ( ) ;
}
std : : string get_userdata_directory ( )
2023-03-06 15:40:07 -05:00
{
2023-05-11 16:50:11 -04:00
return std : : format ( " players/bnet-{} " , bnet_get_userid ( ) ) ;
}
2023-03-06 15:40:07 -05:00
2023-05-11 16:50:11 -04:00
namespace
{
2023-11-10 16:52:20 -05:00
utilities : : hook : : detour PC_TextChat_Print_Hook ;
2023-03-06 15:40:07 -05:00
void PC_TextChat_Print_Stub ( const char * text )
{
2023-05-11 16:50:11 -04:00
# ifdef DEBUG
2023-03-06 15:40:07 -05:00
logger : : write ( logger : : LOG_TYPE_DEBUG , " PC_TextChat_Print(%s) " , text ) ;
2023-05-11 16:50:11 -04:00
# endif
2023-03-06 15:40:07 -05:00
}
void check_platform_registry ( )
{
winreg : : RegKey key ;
winreg : : RegResult result = key . TryOpen ( HKEY_CURRENT_USER , L " SOFTWARE \\ Blizzard Entertainment \\ Battle.net " ) ;
if ( ! result )
{
MessageBoxA ( nullptr , " You need to have BlackOps4 from Battle.Net to use this product... " , " Error " , MB_ICONWARNING ) ;
ShellExecuteA ( nullptr , " open " , " http://battle.net/ " , nullptr , nullptr , SW_SHOWNORMAL ) ;
logger : : write ( logger : : LOG_TYPE_INFO , " [ PLATFORM ]: Couldnt find Battle.Net Launcher; Shutting down... " ) ;
TerminateProcess ( GetCurrentProcess ( ) , 1 ) ;
}
}
}
class component final : public component_interface
{
public :
void pre_start ( ) override
{
check_platform_registry ( ) ;
}
void post_unpack ( ) override
{
2023-11-10 16:52:20 -05:00
utilities : : hook : : set < uint16_t > ( 0x1423271D0 _g , 0x01B0 ) ; // BattleNet_IsDisabled (patch to mov al,1)
utilities : : hook : : set < uint32_t > ( 0x1423271E0 _g , 0x90C301B0 ) ; // BattleNet_IsConnected (patch to mov al,1 retn)
2023-03-06 15:40:07 -05:00
2023-11-10 16:52:20 -05:00
utilities : : hook : : set < uint8_t > ( 0x142325210 _g , 0xC3 ) ; // patch#1 Annoying function crashing game; related to BattleNet (TODO : Needs Further Investigation)
utilities : : hook : : set < uint8_t > ( 0x142307B40 _g , 0xC3 ) ; // patch#2 Annoying function crashing game; related to BattleNet (TODO : Needs Further Investigation)
utilities : : hook : : set < uint32_t > ( 0x143D08290 _g , 0x90C301B0 ) ; // patch#3 BattleNet_IsModeAvailable? (patch to mov al,1 retn)
2023-03-06 15:40:07 -05:00
2023-11-10 16:52:20 -05:00
utilities : : hook : : nop ( 0x1437DA454 _g , 13 ) ; // begin cross-auth even without platform being initialized [LiveConnect_BeginCrossAuthPlatform]
utilities : : hook : : set ( 0x1444D2D60 _g , 0xC301B0 ) ; // Auth3 Response RSA signature check [bdAuth::validateResponseSignature]
utilities : : hook : : set ( 0x1444E34C0 _g , 0xC301B0 ) ; // Auth3 Response platform extended data check [bdAuthPC::processPlatformData]
2023-03-06 15:40:07 -05:00
2023-11-10 16:52:20 -05:00
utilities : : hook : : nop ( 0x1438994E9 _g , 22 ) ; // get live name even without platform being initialized [Live_UserSignedIn]
utilities : : hook : : nop ( 0x1438C3476 _g , 22 ) ; // get live xuid even without platform being initialized [LiveUser_UserGetXuid]
2023-05-11 16:50:11 -04:00
2023-11-10 16:52:20 -05:00
utilities : : hook : : jump ( 0x142325C70 _g , bnet_get_username ) ; // detour battlenet username
utilities : : hook : : jump ( 0x142325CA0 _g , bnet_get_userid ) ; // detour battlenet userid
2023-05-11 16:50:11 -04:00
//PC_TextChat_Print_Hook.create(0x1422D4A20_g, PC_TextChat_Print_Stub); // Disable useless system messages passed into chat box
logger : : write ( logger : : LOG_TYPE_INFO , " [ PLATFORM ]: BattleTag: '%s', BattleID: '%llu' " , bnet_get_username ( ) , bnet_get_userid ( ) ) ;
2023-03-07 07:31:21 -05:00
}
2023-03-06 15:40:07 -05:00
} ;
}
REGISTER_COMPONENT ( platform : : component )