From be6f532c1ef5366375604770b6547835413759da Mon Sep 17 00:00:00 2001 From: Joshua Date: Mon, 16 Aug 2021 12:52:44 -0400 Subject: [PATCH] Added new steam sessions functions IsOverlay Enabled InitTextFiltering FilterText IsSteamInBigPictureMode --- .../Classes/AdvancedSteamFriendsLibrary.h | 34 +++++++++ .../Private/AdvancedSteamFriendsLibrary.cpp | 75 +++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/AdvancedSteamSessions/Source/AdvancedSteamSessions/Classes/AdvancedSteamFriendsLibrary.h b/AdvancedSteamSessions/Source/AdvancedSteamSessions/Classes/AdvancedSteamFriendsLibrary.h index 0a35350..aaa37cf 100644 --- a/AdvancedSteamSessions/Source/AdvancedSteamSessions/Classes/AdvancedSteamFriendsLibrary.h +++ b/AdvancedSteamSessions/Source/AdvancedSteamSessions/Classes/AdvancedSteamFriendsLibrary.h @@ -305,6 +305,19 @@ public: }; +UENUM(Blueprintable) +enum class EBPTextFilteringContext : uint8 +{ + /*Unknown context.*/ + FContext_Unknown = 0, + /*Game content, only legally required filtering is performed.*/ + FContext_GameContent = 1, + /*Char from another player.*/ + FContext_Chat = 2, + /*Character or item name.*/ + FContext_Name = 3 +}; + UCLASS() class UAdvancedSteamFriendsLibrary : public UBlueprintFunctionLibrary { @@ -325,6 +338,10 @@ public: UFUNCTION(BlueprintCallable, Category = "Online|AdvancedFriends|SteamAPI") static bool OpenSteamUserOverlay(const FBPUniqueNetId UniqueNetId, ESteamUserOverlayType DialogType); + // Returns if the steam overlay is currently active (this can return false during initial overlay hooking) + UFUNCTION(BlueprintPure, Category = "Online|AdvancedFriends|SteamAPI") + static bool IsOverlayEnabled(); + // Gets the level of a friends steam account, STEAM ONLY, Returns -1 if the steam level is not known, might need RequestSteamFriendInfo called first. UFUNCTION(BlueprintCallable, Category = "Online|AdvancedFriends|SteamAPI") static int32 GetFriendSteamLevel(const FBPUniqueNetId UniqueNetId); @@ -350,4 +367,21 @@ public: // Get a full list of steam groups UFUNCTION(BlueprintCallable, Category = "Online|SteamAPI|SteamGroups") static void GetSteamGroups(TArray & SteamGroups); + + // Initializes text filtering (pre-loading dictonaries) + // Returns if it succeeded, false if filtering is unavailable for the games language + UFUNCTION(BlueprintCallable, Category = "Online|SteamAPI|TextFiltering") + static bool InitTextFiltering(); + + // Attempts to filter a string with the given filtering context + // Returns true if the text has been filtered, false if it hasn't (no filtering required or operation failed) + // If false it will still output the original text + // Textsource is the steam id that is the source of the text (player name / chat) + // Requires that InitTextFiltering be called first!! + UFUNCTION(BlueprintCallable, Category = "Online|SteamAPI|TextFiltering") + static bool FilterText(FString TextToFilter, EBPTextFilteringContext Context, const FBPUniqueNetId TextSourceID, FString& FilteredText); + + // Returns if steam is running in big picture mode + UFUNCTION(BlueprintPure, Category = "Online|SteamAPI") + static bool IsSteamInBigPictureMode(); }; diff --git a/AdvancedSteamSessions/Source/AdvancedSteamSessions/Private/AdvancedSteamFriendsLibrary.cpp b/AdvancedSteamSessions/Source/AdvancedSteamSessions/Private/AdvancedSteamFriendsLibrary.cpp index 4c2dc00..1422d17 100644 --- a/AdvancedSteamSessions/Source/AdvancedSteamSessions/Private/AdvancedSteamFriendsLibrary.cpp +++ b/AdvancedSteamSessions/Source/AdvancedSteamSessions/Private/AdvancedSteamFriendsLibrary.cpp @@ -255,6 +255,19 @@ bool UAdvancedSteamFriendsLibrary::OpenSteamUserOverlay(const FBPUniqueNetId Uni return false; } +bool UAdvancedSteamFriendsLibrary::IsOverlayEnabled() +{ +#if PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX + if (SteamAPI_Init()) + { + return SteamUtils()->IsOverlayEnabled(); + } +#endif + + UE_LOG(AdvancedSteamFriendsLog, Warning, TEXT("OpenSteamUserOverlay Couldn't init steamAPI!")); + return false; +} + UTexture2D * UAdvancedSteamFriendsLibrary::GetSteamFriendAvatar(const FBPUniqueNetId UniqueNetId, EBlueprintAsyncResultSwitch &Result, SteamAvatarSize AvatarSize) { #if PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX @@ -350,4 +363,66 @@ UTexture2D * UAdvancedSteamFriendsLibrary::GetSteamFriendAvatar(const FBPUniqueN UE_LOG(AdvancedSteamFriendsLog, Warning, TEXT("STEAM Couldn't be verified as initialized")); Result = EBlueprintAsyncResultSwitch::OnFailure; return nullptr; +} + +bool UAdvancedSteamFriendsLibrary::InitTextFiltering() +{ +#if PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX + + if (SteamAPI_Init()) + { + return SteamUtils()->InitFilterText(); + } + +#endif + + return false; +} + +bool UAdvancedSteamFriendsLibrary::FilterText(FString TextToFilter, EBPTextFilteringContext Context, const FBPUniqueNetId TextSourceID, FString& FilteredText) +{ +#if PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX + + if (SteamAPI_Init()) + { + uint32 BufferLen = TextToFilter.Len() + 10; // Docs say 1 byte excess min, going with 10 + char* OutText = new char[BufferLen]; + + uint64 id = 0; + + if (TextSourceID.IsValid()) + { + id = *((uint64*)TextSourceID.UniqueNetId->GetBytes()); + } + + int FilterCount = SteamUtils()->FilterText((ETextFilteringContext)Context, id, TCHAR_TO_ANSI(*TextToFilter), OutText, BufferLen); + + if (FilterCount > 0) + { + FilteredText = FString(UTF8_TO_TCHAR(OutText)); + delete[] OutText; + return true; + } + + delete[] OutText; + } + +#endif + + FilteredText = TextToFilter; + return false; +} + +bool UAdvancedSteamFriendsLibrary::IsSteamInBigPictureMode() +{ +#if PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX + + if (SteamAPI_Init()) + { + return SteamUtils()->IsSteamInBigPictureMode(); + } + +#endif + + return false; } \ No newline at end of file