Advertisement
malice936

FormID.h

Apr 13th, 2025
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.66 KB | Gaming | 0 0
  1. #pragma once
  2.  
  3. // Include the minimal set of Unreal Engine headers required for core functionality.
  4. // Provides access to essential types like FString and macros like UPROPERTY.
  5. #include "CoreMinimal.h"
  6.  
  7. // Include the generated header for this struct, containing reflection code.
  8. // Required for Unreal Engine's reflection system to support Blueprint integration and serialization.
  9. #include "FormID.generated.h"
  10.  
  11. // Define a struct to represent a FormID, a 32-bit integer identifier for records in Bethesda game files (.ESM, .ESP, .ESL).
  12. // Marked as USTRUCT(BlueprintType) to enable usage as a variable type in Blueprints for modding purposes.
  13. USTRUCT(BlueprintType)
  14. struct FFormID
  15. {
  16.     // Macro required for all USTRUCTs to generate reflection code.
  17.     // Ensures the struct is recognized by Unreal Engine's reflection system for Blueprint and serialization support.
  18.     GENERATED_BODY()
  19.  
  20.     // The raw 32-bit value of the FormID, uniquely identifying a record in a game file.
  21.     // UPROPERTY(BlueprintReadWrite, EditAnywhere) allows access and modification in Blueprints and editing in the Unreal Editor.
  22.     UPROPERTY(BlueprintReadWrite, EditAnywhere)
  23.     int32 Value;
  24.  
  25.     // Default constructor, initializing Value to 0.
  26.     // A Value of 0 is typically considered an invalid FormID, ensuring a safe default state.
  27.     FFormID() : Value(0) {}
  28.  
  29.     // Parameterized constructor, initializing Value with a specified int32.
  30.     // Enables creation of FFormID instances with known values, such as those parsed from game files.
  31.     FFormID(int32 InValue) : Value(InValue) {}
  32.  
  33.     // Converts the FormID to a hexadecimal string, e.g., "0x00000001".
  34.     // Useful for debugging, logging, or displaying the FormID in a human-readable format.
  35.     // Returns an FString formatted with a "0x" prefix and 8 hexadecimal digits.
  36.     FString ToString() const { return FString::Printf(TEXT("0x%08X"), Value); }
  37.  
  38.     // Compares this FormID with another for equality.
  39.     // Returns true if the Values are equal, false otherwise.
  40.     // Used in C++ code for validation or branching logic.
  41.     bool Equals(const FFormID& Other) const { return Value == Other.Value; }
  42.  
  43.     // Checks if the FormID is valid.
  44.     // A FormID is considered valid if its Value is non-zero, as 0 typically represents an invalid or null record.
  45.     // Returns true for non-zero Values, false for zero.
  46.     bool IsValid() const { return Value != 0; }
  47.  
  48.     // Overloaded equality operator for comparing two FFormID instances in C++.
  49.     // Returns true if the Values are equal, enabling direct comparisons like `if (FormID1 == FormID2)`.
  50.     bool operator==(const FFormID& Other) const { return Value == Other.Value; }
  51.  
  52.     // Overloaded inequality operator for comparing two FFormID instances in C++.
  53.     // Returns true if the Values are not equal, useful for filtering or validation checks.
  54.     bool operator!=(const FFormID& Other) const { return Value != Other.Value; }
  55.  
  56.     // Overloaded less-than operator for sorting FFormID instances in C++.
  57.     // Compares Values, enabling use in ordered containers like TArray or TSet for sorting purposes.
  58.     bool operator<(const FFormID& Other) const { return Value < Other.Value; }
  59. };
  60.  
  61. // Define a hash function for FFormID to enable its use as a key in Unreal Engine's TMap or TSet.
  62. // Marked as FORCEINLINE to optimize performance by inlining the function, reducing call overhead.
  63. FORCEINLINE uint32 GetTypeHash(const FFormID& FormID)
  64. {
  65.     // Use Unreal Engine's built-in GetTypeHash for the int32 Value member.
  66.     // Ensures compatibility with Unreal's hash-based containers, allowing FFormID to map to records or other data.
  67.     return GetTypeHash(FormID.Value);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement