Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- // Include the minimal set of Unreal Engine headers required for core functionality.
- // Provides access to essential types like FString and macros like UPROPERTY.
- #include "CoreMinimal.h"
- // Include the generated header for this struct, containing reflection code.
- // Required for Unreal Engine's reflection system to support Blueprint integration and serialization.
- #include "FormID.generated.h"
- // Define a struct to represent a FormID, a 32-bit integer identifier for records in Bethesda game files (.ESM, .ESP, .ESL).
- // Marked as USTRUCT(BlueprintType) to enable usage as a variable type in Blueprints for modding purposes.
- USTRUCT(BlueprintType)
- struct FFormID
- {
- // Macro required for all USTRUCTs to generate reflection code.
- // Ensures the struct is recognized by Unreal Engine's reflection system for Blueprint and serialization support.
- GENERATED_BODY()
- // The raw 32-bit value of the FormID, uniquely identifying a record in a game file.
- // UPROPERTY(BlueprintReadWrite, EditAnywhere) allows access and modification in Blueprints and editing in the Unreal Editor.
- UPROPERTY(BlueprintReadWrite, EditAnywhere)
- int32 Value;
- // Default constructor, initializing Value to 0.
- // A Value of 0 is typically considered an invalid FormID, ensuring a safe default state.
- FFormID() : Value(0) {}
- // Parameterized constructor, initializing Value with a specified int32.
- // Enables creation of FFormID instances with known values, such as those parsed from game files.
- FFormID(int32 InValue) : Value(InValue) {}
- // Converts the FormID to a hexadecimal string, e.g., "0x00000001".
- // Useful for debugging, logging, or displaying the FormID in a human-readable format.
- // Returns an FString formatted with a "0x" prefix and 8 hexadecimal digits.
- FString ToString() const { return FString::Printf(TEXT("0x%08X"), Value); }
- // Compares this FormID with another for equality.
- // Returns true if the Values are equal, false otherwise.
- // Used in C++ code for validation or branching logic.
- bool Equals(const FFormID& Other) const { return Value == Other.Value; }
- // Checks if the FormID is valid.
- // A FormID is considered valid if its Value is non-zero, as 0 typically represents an invalid or null record.
- // Returns true for non-zero Values, false for zero.
- bool IsValid() const { return Value != 0; }
- // Overloaded equality operator for comparing two FFormID instances in C++.
- // Returns true if the Values are equal, enabling direct comparisons like `if (FormID1 == FormID2)`.
- bool operator==(const FFormID& Other) const { return Value == Other.Value; }
- // Overloaded inequality operator for comparing two FFormID instances in C++.
- // Returns true if the Values are not equal, useful for filtering or validation checks.
- bool operator!=(const FFormID& Other) const { return Value != Other.Value; }
- // Overloaded less-than operator for sorting FFormID instances in C++.
- // Compares Values, enabling use in ordered containers like TArray or TSet for sorting purposes.
- bool operator<(const FFormID& Other) const { return Value < Other.Value; }
- };
- // Define a hash function for FFormID to enable its use as a key in Unreal Engine's TMap or TSet.
- // Marked as FORCEINLINE to optimize performance by inlining the function, reducing call overhead.
- FORCEINLINE uint32 GetTypeHash(const FFormID& FormID)
- {
- // Use Unreal Engine's built-in GetTypeHash for the int32 Value member.
- // Ensures compatibility with Unreal's hash-based containers, allowing FFormID to map to records or other data.
- return GetTypeHash(FormID.Value);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement