Advertisement
test12333

Untitled

Nov 1st, 2022
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.50 KB | None | 0 0
  1. EGCResults hook::functions::ISteamGameCoordinator__SendMessage( uintptr_t thisptr, uint32 unMsgType, ProtoBufMsgHeader_t* pubData, uint32 cubData ) {
  2.     const auto msg_id = unMsgType & 0x7FFFFFFF;
  3.     if ( msg_id == k_EMsgClientToGCEquipItems ) {
  4.         const auto body = (void*)((uintptr_t)pubData + (sizeof( ProtoBufMsgHeader_t ) + pubData->m_cubProtoBufExtHdr));
  5.         const auto body_bytes = cubData - (sizeof( ProtoBufMsgHeader_t ) + pubData->m_cubProtoBufExtHdr);
  6.  
  7.         const auto header = (const void*)((uintptr_t)pubData + sizeof( ProtoBufMsgHeader_t ));
  8.         const auto header_size = pubData->m_cubProtoBufExtHdr;
  9.  
  10.         if ( header_size > 0 ) {
  11.             CMsgClientToGCEquipItems OriginalBody;
  12.             CMsgProtoBufHeader OriginalHeader;
  13.  
  14.             CMsgClientToGCEquipItemsResponse FakeBody;
  15.             FakeBody.set_so_cache_version_id( 0 );
  16.             CMsgProtoBufHeader FakeHeader;
  17.  
  18.             if ( OriginalBody.ParsePartialFromArray( body, body_bytes ) ) {
  19.                 std::vector<BYTE> bytes_of_message;
  20.  
  21.                 if ( OriginalHeader.ParsePartialFromArray( header, header_size ) ) {
  22.  
  23.                     FakeHeader.set_job_id_target( OriginalHeader.job_id_source( ) );
  24.                 }
  25.  
  26.                 ProtoBufMsgHeader_t meta_header = { 0xA0A, (uint32_t)FakeHeader.ByteSizeLong( ) };
  27.                 bytes_of_message.resize( sizeof( meta_header ) + FakeHeader.ByteSizeLong( ) + FakeBody.ByteSizeLong( ) );
  28.                 *reinterpret_cast<ProtoBufMsgHeader_t*>(bytes_of_message.data( )) = meta_header;
  29.                 FakeHeader.SerializeToArray( bytes_of_message.data( ) + sizeof( ProtoBufMsgHeader_t ), FakeHeader.ByteSizeLong( ) );
  30.                 FakeBody.SerializeToArray( bytes_of_message.data( ) + sizeof( ProtoBufMsgHeader_t ) + FakeHeader.ByteSizeLong( ), FakeBody.ByteSizeLong( ) );
  31.  
  32.                 cheat_data.MessageList.push( bytes_of_message );
  33.  
  34.                 const auto& data = OriginalBody.equips( ).Get( 0 );
  35.                 CEconItem* item = g_pLocalInventory->FindItem( data.item_id( ) );
  36.                 if ( item ) {
  37.                     item->Equip( data.new_class( ), data.new_slot( ) );
  38.                     g_pLocalInventory->SOUpdated( g_pLocalInventory->m_pSOID, item, ESOCacheEvent::eSOCacheEvent_Incremental );
  39.                 }
  40.             }
  41.         }
  42.  
  43.         return EGCResults::k_EGCResultOK;
  44.     }
  45.  
  46.     auto ret = hook::original::fpSClientSendMessage( thisptr, unMsgType, pubData, cubData );
  47.     return ret;
  48. }
  49.  
  50. EGCResults hook::functions::ISteamGameCoordinator__RetrieveMessage( uintptr_t thisptr, uint32* punMsgType, ProtoBufMsgHeader_t* pubDest, uint32 cubDest, uint32* pcubMsgSize ) {
  51.  
  52.     if ( !cheat_data.MessageList.empty( ) )
  53.     {
  54.         const auto& Message = cheat_data.MessageList.front( );
  55.         *pcubMsgSize = (uint32)Message.size( );
  56.  
  57.         if ( cubDest < *pcubMsgSize )
  58.             return EGCResults::k_EGCResultBufferTooSmall;
  59.  
  60.         auto MessageHeader = reinterpret_cast<const ProtoBufMsgHeader_t*>(Message.data( ));
  61.         *punMsgType = MessageHeader->m_EMsgFlagged;
  62.         util::memcpy( (void*)pubDest, MessageHeader, Message.size( ) );
  63.         cheat_data.MessageList.pop( );
  64.  
  65.         return EGCResults::k_EGCResultOK;
  66.     }
  67.     return hook::original::fpSClientRetrieveMessage( thisptr, punMsgType, pubDest, cubDest, pcubMsgSize );
  68. }
  69.  
  70. bool hook::functions::ISteamGameCoordinator__IsMessageAvailable( uintptr_t thisptr, uint32* pcubMsgSize ) {
  71.     // std::cout << "ismsgav: " << _ReturnAddress() << std::endl;
  72.  
  73.     if ( !cheat_data.MessageList.empty( ) )
  74.     {
  75.         *pcubMsgSize = cheat_data.MessageList.front( ).size( );
  76.         return true;
  77.     }
  78.  
  79.     return hook::original::fpSClientIsMessageAvailable( thisptr, pcubMsgSize );
  80. }
  81.  
  82. void __fastcall hook::functions::RunFrame( uintptr_t rcx ) {
  83.     if ( !cheat_data.MessageList.empty( ) ) functions_call::OnGCMessageAvailable( global::g_CGCClient );
  84.     ...
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement