Advertisement
Guest User

Steam Bp function

a guest
Jul 20th, 2018
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. PrintStringFTW
  2.  
  3. This is a blueprint function i made to return an array of structs called OutFriends that contain the players
  4. steam friends data
  5.  
  6. // special mention of Cedric_Exi . few lines of code relating to converting the raw avatar data was taken from
  7. his SteamFriends Unreal live training video.
  8.  
  9. //// header file ///////
  10.  
  11. //make a BP struct to hold the friends steam data
  12. USTRUCT(BlueprintType)
  13. struct FSteamFriends
  14. {
  15. GENERATED_USTRUCT_BODY()
  16.  
  17. public:
  18. UPROPERTY(BlueprintReadOnly, Category = "Steam | Utils")
  19. FString DisplayName;
  20.  
  21. UPROPERTY(BlueprintReadOnly, Category = "Steam | Utils")
  22. UTexture2D* PlayerAvatar;
  23. };
  24.  
  25. /* declare a blueprint function that returns an array of our steam friends struct we made above
  26. and also the total count of how many friends we have. */
  27. UFUNCTION(BlueprintCallable, Category = "Steam|Utils")
  28. void GetSteamFriends(TArray<FSteamFriends>& OutMySteamFriends, int32& OutFriendCount);
  29.  
  30. //// header file ///////
  31.  
  32. //// CPP file ///////
  33.  
  34. void AUDPSocketMain::GetSteamFriends(TArray<FSteamFriends>& OutFriends, int32& OutFriendCount)
  35. {
  36.  
  37. // create a temp steam friends struct
  38. FSteamFriends TempSteamFriends;
  39.  
  40. // get the total count of how many steam friends we have.
  41. int SteamFriendsCount = SteamFriends()->GetFriendCount(k_EFriendFlagImmediate);
  42.  
  43. // set our OutFriendCount variable to be equal to the SteamFriendsCount we just got above
  44. OutFriendCount = SteamFriendsCount;
  45.  
  46. // check to make sure the user is logged in
  47. if (SteamFriendsCount == -1)
  48. {
  49. // user not logged in
  50. return;
  51. }
  52.  
  53. // loop through and find all friends data
  54. for (int FriendIndex = 0; FriendIndex < SteamFriendsCount; FriendIndex++)
  55. {
  56. // variables for the friends avatar data
  57. int AvatarSizeIndex = 0;
  58. uint32 AvatarWidth = 0;
  59. uint32 AvatarHeight = 0;
  60.  
  61.  
  62. // get the current friends CSteamID
  63. CSteamID FriendsSteamID = SteamFriends()->GetFriendByIndex(FriendIndex, k_EFriendFlagImmediate);
  64.  
  65. // get the freinds medium avatar index handle
  66. AvatarSizeIndex = SteamFriends()->GetMediumFriendAvatar(FriendsSteamID);
  67.  
  68. // get the actual image size so we can reserve the correct memory
  69. bool bGetImageSize = SteamUtils()->GetImageSize(AvatarSizeIndex, &AvatarWidth, &AvatarHeight);
  70. if (!bGetImageSize)
  71. {
  72. // unable to get image size
  73. }
  74.  
  75. // create buffer for the RGBA data (* 4 because R(1) G(2) B(3) A(4) )
  76. uint8* AvatarRGBA = new uint8[AvatarHeight * AvatarWidth * 4];
  77.  
  78. bool GetImageRGBA = SteamUtils()->GetImageRGBA(AvatarSizeIndex, AvatarRGBA, AvatarHeight * AvatarWidth * 4 * sizeof(char));
  79. if (!GetImageRGBA)
  80. {
  81. // error getting the RGBA data
  82. }
  83.  
  84. // create a placeholder texture to fill the buffer in
  85. UTexture2D* AvatarTexture = UTexture2D::CreateTransient(AvatarWidth, AvatarHeight, PF_R8G8B8A8);
  86.  
  87. // lock the BulkData and MemCopy
  88. uint8* MipData = (uint8*)AvatarTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
  89. FMemory::Memcpy(MipData, (void*)AvatarRGBA, AvatarHeight * AvatarWidth * 4);
  90. AvatarTexture->PlatformData->Mips[0].BulkData.Unlock();
  91.  
  92. //clear up the memory
  93. delete[] AvatarRGBA;
  94.  
  95. // update the texture2d settings
  96. AvatarTexture->PlatformData->NumSlices = 1;
  97. AvatarTexture->NeverStream = true;
  98. AvatarTexture->UpdateResource();
  99.  
  100. // set the TempSteamFriends Struct data
  101.  
  102. // get the friends display name store it in the temporary struct
  103. TempSteamFriends.DisplayName = SteamFriends()->GetFriendPersonaName(FriendsSteamID);
  104.  
  105. // get the friends player avatar store it in the temporary struct
  106. TempSteamFriends.PlayerAvatar = AvatarTexture;
  107.  
  108. // add the temporary struct data to the OutFriends array
  109. OutFriends.Add(TempSteamFriends);
  110. }
  111. }
  112.  
  113. //// CPP file ///////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement