Advertisement
malice936

Group.h

Apr 13th, 2025
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.48 KB | Gaming | 0 0
  1. #pragma once
  2.  
  3. #include "CoreMinimal.h"
  4. #include "Kismet/BlueprintFunctionLibrary.h"
  5. #include "GameID.h"
  6. #include "FormID.h"
  7. #include "Record.h"
  8. #include "Group.generated.h"
  9.  
  10. // Represents a group (GRUP) in Bethesda file formats, containing FormIDs of records or subgroups.
  11. USTRUCT(BlueprintType)
  12. struct FGroup
  13. {
  14.     GENERATED_BODY()
  15.  
  16.     // Array of FormIDs identifying records or subgroups within this group.
  17.     UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Group", meta=(ToolTip="Array of FormIDs in the group."))
  18.     TArray<FFormID> FormIds;
  19.  
  20.     // Group label, typically a string or integer identifier from the GRUP header.
  21.     UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Group", meta=(ToolTip="Group label or identifier."))
  22.     FString Label;
  23.  
  24.     // Default constructor, initializing to empty values.
  25.     FGroup() : FormIds(), Label(TEXT("")) {}
  26.  
  27.     // Parameterized constructor for initializing with specific values.
  28.     FGroup(const TArray<FFormID>& InFormIds, const FString& InLabel) : FormIds(InFormIds), Label(InLabel) {}
  29.  
  30.     // Equality operator to compare groups based on FormIDs and Label.
  31.     bool operator==(const FGroup& Other) const { return FormIds == Other.FormIds && Label == Other.Label; }
  32.  
  33.     // Inequality operator, defined using equality operator.
  34.     bool operator!=(const FGroup& Other) const { return !(*this == Other); }
  35. };
  36.  
  37. // Hash function for FGroup, enabling use in TMap/TSet.
  38. FORCEINLINE uint32 GetTypeHash(const FGroup& Group)
  39. {
  40.     return GetTypeHash(Group.FormIds) ^ GetTypeHash(Group.Label);
  41. }
  42.  
  43. // Blueprint Function Library for group-related utilities.
  44. UCLASS()
  45. class UNREALCREATIONENGINE_API UGroupHelper : public UBlueprintFunctionLibrary
  46. {
  47.     GENERATED_BODY()
  48.  
  49. public:
  50.     // Reads a group from a file with game-specific logic.
  51.     UFUNCTION(BlueprintCallable, Category = "Group", meta=(ToolTip="Reads a group from a file."))
  52.     static bool ReadGroupFromFile(FGroup& OutGroup, const FString& FilePath, EGameID GameID, bool bSkipSubrecords);
  53.  
  54.     // Reads a group from a byte array with game-specific logic.
  55.     UFUNCTION(BlueprintCallable, Category = "Group", meta=(ToolTip="Reads a group from a byte array."))
  56.     static bool ReadGroupFromBytes(FGroup& OutGroup, const TArray<uint8>& ByteArray, EGameID GameID, bool bSkipSubrecords);
  57.  
  58.     // Writes a group to a file with game-specific logic.
  59.     UFUNCTION(BlueprintCallable, Category = "Group", meta=(ToolTip="Writes a group to a file."))
  60.     static bool WriteGroupToFile(const FGroup& Group, const FString& FilePath, EGameID GameID);
  61.  
  62.     // Serializes a group to a byte array with game-specific logic.
  63.     UFUNCTION(BlueprintCallable, Category = "Group", meta=(ToolTip="Serializes a group to a byte array."))
  64.     static bool WriteGroupToBytes(const FGroup& Group, TArray<uint8>& OutByteArray, EGameID GameID);
  65.  
  66.     // Gets the FormIDs in the group.
  67.     UFUNCTION(BlueprintPure, Category = "Group", meta=(ToolTip="Gets the FormIDs in the group."))
  68.     static TArray<FFormID> GetFormIds(const FGroup& Group);
  69.  
  70.     // Gets the number of FormIDs in the group.
  71.     UFUNCTION(BlueprintPure, Category = "Group", meta=(ToolTip="Gets the number of FormIDs."))
  72.     static int32 GetFormIdCount(const FGroup& Group);
  73.  
  74.     // Checks if a specific FormID exists in the group.
  75.     UFUNCTION(BlueprintPure, Category = "Group", meta=(ToolTip="Checks if a FormID exists in the group."))
  76.     static bool HasFormId(const FGroup& Group, const FFormID& FormId);
  77.  
  78.     // Gets the group label.
  79.     UFUNCTION(BlueprintPure, Category = "Group", meta=(ToolTip="Gets the group label."))
  80.     static FString GetLabel(const FGroup& Group);
  81.  
  82.     // Adds a FormID to the group.
  83.     UFUNCTION(BlueprintCallable, Category = "Group", meta=(ToolTip="Adds a FormID to the group."))
  84.     static void AddFormId(FGroup& Group, const FFormID& FormId);
  85.  
  86.     // Removes a FormID from the group.
  87.     UFUNCTION(BlueprintCallable, Category = "Group", meta=(ToolTip="Removes a FormID from the group."))
  88.     static bool RemoveFormId(FGroup& Group, const FFormID& FormId);
  89.  
  90.     // Clears all FormIDs from the group.
  91.     UFUNCTION(BlueprintCallable, Category = "Group", meta=(ToolTip="Clears all FormIDs from the group."))
  92.     static void ClearFormIds(FGroup& Group);
  93.  
  94.     // Returns true if the group is valid (non-empty FormIDs, valid label).
  95.     UFUNCTION(BlueprintPure, Category = "Group", meta=(ToolTip="Returns true if the group is valid."))
  96.     static bool IsValidGroup(const FGroup& Group, EGameID GameID);
  97. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement