Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Plugin.h
- #pragma once
- // Core Unreal Engine types and macros
- #include "CoreMinimal.h"
- // Required for TSet operations like Difference()
- #include "Containers/Set.h"
- // Blueprint function library base class
- #include "Kismet/BlueprintFunctionLibrary.h"
- // Custom enum for game identification (e.g., Skyrim, Morrowind)
- #include "GameID.h"
- // Struct for unique FormIDs
- #include "FormID.h"
- // Struct for plugin header records
- #include "Record.h"
- // Struct for group data in plugins
- #include "Group.h"
- // Generated code for USTRUCT and UCLASS
- #include "Plugin.generated.h"
- // Represents a Bethesda plugin file (.ESM, .ESP, .ESL) with metadata and FormIDs
- USTRUCT(BlueprintType)
- struct FPlugin
- {
- GENERATED_BODY()
- // Game identifier (e.g., Skyrim, Morrowind) for plugin context
- UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Plugin", meta = (ToolTip = "Game identifier (e.g., Skyrim, Morrowind)."))
- EGameID GameId;
- // Plugin filename (e.g., "MyPlugin.esp") without path
- UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Plugin", meta = (ToolTip = "Plugin filename."))
- FString Name;
- // Header record (TES3 for Morrowind, TES4 for others) containing metadata
- UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Plugin", meta = (ToolTip = "Header record of the plugin."))
- FRecord HeaderRecord;
- // Set of unique FormIDs from records or groups in the plugin
- UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Plugin", meta = (ToolTip = "Unique FormIDs in the plugin."))
- TSet<FFormID> FormIds;
- // Default constructor initializing to safe defaults
- FPlugin()
- : GameId(EGameID::Skyrim) // Default to Skyrim for safety
- , Name(TEXT("")) // Empty name
- , HeaderRecord() // Default header record
- , FormIds() // Empty FormID set
- {
- }
- // Parameterized constructor for initializing with specific values
- FPlugin(EGameID InGameId, const FString& InName, const FRecord& InHeaderRecord, const TSet<FFormID>& InFormIds)
- : GameId(InGameId) // Set game identifier
- , Name(InName) // Set plugin filename
- , HeaderRecord(InHeaderRecord) // Set header record
- , FormIds(InFormIds) // Set FormIDs
- {
- }
- // Equality operator to compare two plugins
- bool operator==(const FPlugin& Other) const
- {
- // Compare GameId, Name, HeaderRecord, and FormIds
- // FormIds comparison uses Num() for size and Difference() for content equality
- return GameId == Other.GameId &&
- Name == Other.Name &&
- HeaderRecord == Other.HeaderRecord &&
- FormIds.Num() == Other.FormIds.Num() &&
- FormIds.Difference(Other.FormIds).IsEmpty();
- }
- // Inequality operator derived from equality
- bool operator!=(const FPlugin& Other) const
- {
- return !(*this == Other); // Negate result of operator==
- }
- };
- // Hash function for using FPlugin in TMap/TSet containers
- FORCEINLINE uint32 GetTypeHash(const FPlugin& Plugin)
- {
- uint32 Hash = 0; // Initialize hash value
- // Combine hashes of GameId (cast to uint8 for enum), Name, and HeaderRecord
- Hash = HashCombine(Hash, GetTypeHash(static_cast<uint8>(Plugin.GameId)));
- Hash = HashCombine(Hash, GetTypeHash(Plugin.Name));
- Hash = HashCombine(Hash, GetTypeHash(Plugin.HeaderRecord));
- // Iterate over FormIds and combine their hashes
- for (const FFormID& FormId : Plugin.FormIds)
- {
- Hash = HashCombine(Hash, GetTypeHash(FormId));
- }
- return Hash; // Return final hash value
- }
- // Blueprint function library for plugin-related operations
- UCLASS()
- class UNREALCREATIONENGINE_API UPluginHelper : public UBlueprintFunctionLibrary
- {
- GENERATED_BODY()
- public:
- // Loads a plugin from a file, optionally reading only the header
- UFUNCTION(BlueprintCallable, Category = "Plugin", meta = (ToolTip = "Loads a plugin from a file, optionally header-only."))
- static bool LoadPlugin(FPlugin& OutPlugin, const FString& FilePath, EGameID GameID, bool bLoadHeaderOnly = false);
- // Loads a plugin from a byte array, optionally reading only the header
- UFUNCTION(BlueprintCallable, Category = "Plugin", meta = (ToolTip = "Loads a plugin from a byte array, optionally header-only."))
- static bool LoadPluginFromBytes(FPlugin& OutPlugin, const TArray<uint8>& ByteArray, EGameID GameID, bool bLoadHeaderOnly = false);
- // Checks if a plugin file is valid by attempting to load it
- UFUNCTION(BlueprintCallable, Category = "Plugin", meta = (ToolTip = "Returns true if the plugin file is valid."))
- static bool IsValidPlugin(const FString& FilePath, EGameID GameID, bool bLoadHeaderOnly = false);
- // Gets the plugin's filename
- UFUNCTION(BlueprintPure, Category = "Plugin", meta = (ToolTip = "Gets the plugin filename."))
- static FString GetName(const FPlugin& Plugin);
- // Checks if the plugin is a master file (.esm or flagged)
- UFUNCTION(BlueprintPure, Category = "Plugin", meta = (ToolTip = "Returns true if the plugin is a master file (.esm or flagged)."))
- static bool IsMasterFile(const FPlugin& Plugin);
- // Gets the list of master plugin filenames
- UFUNCTION(BlueprintPure, Category = "Plugin", meta = (ToolTip = "Gets the list of master plugins."))
- static TArray<FString> GetMasters(const FPlugin& Plugin);
- // Gets the plugin description from HEDR (Morrowind) or SNAM (others)
- UFUNCTION(BlueprintPure, Category = "Plugin", meta = (ToolTip = "Gets the plugin description from HEDR/SNAM."))
- static FString GetDescription(const FPlugin& Plugin);
- // Gets the unique FormIDs (non-Morrowind plugins only)
- UFUNCTION(BlueprintPure, Category = "Plugin", meta = (ToolTip = "Gets the unique FormIDs (non-Morrowind only)."))
- static TArray<FFormID> GetFormIds(const FPlugin& Plugin);
- // Gets the total number of records and groups from HEDR
- UFUNCTION(BlueprintPure, Category = "Plugin", meta = (ToolTip = "Gets the total number of records and groups."))
- static int32 GetRecordAndGroupCount(const FPlugin& Plugin);
- // Checks if a specific master plugin is listed as a dependency
- UFUNCTION(BlueprintPure, Category = "Plugin", meta = (ToolTip = "Returns true if the plugin is a master dependency."))
- static bool HasMaster(const FPlugin& Plugin, const FString& MasterName);
- // Gets the number of master plugins
- UFUNCTION(BlueprintPure, Category = "Plugin", meta = (ToolTip = "Gets the number of master plugins."))
- static int32 GetMasterCount(const FPlugin& Plugin);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement