Advertisement
malice936

FormIDHelper.h

Apr 13th, 2025
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.42 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 IFileManager for file operations (optional, not strictly needed here).
  8. #include "HAL/FileManager.h"
  9.  
  10. // Include the BlueprintFunctionLibrary base class header.
  11. // Enables the creation of a static function library accessible in Blueprints without instantiation.
  12. #include "Kismet/BlueprintFunctionLibrary.h"
  13.  
  14. // Include the FormID header to access the FFormID struct definition.
  15. // Necessary for function parameters that operate on FFormID instances.
  16. #include "FormID.h"
  17.  
  18. // Include the generated header for this class, containing reflection code.
  19. // Required for Unreal Engine's reflection system to support Blueprint integration and serialization.
  20. #include "FormIDHelper.generated.h"
  21.  
  22. // Define the FExtendedFormID struct, which extends FFormID with plugin context.
  23. // Marked as USTRUCT(BlueprintType) to enable its use as a variable type in Blueprints.
  24. USTRUCT(BlueprintType)
  25. struct FExtendedFormID
  26. {
  27.     GENERATED_BODY()
  28.  
  29.     // The base FormID, representing the raw identifier.
  30.     UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FormID")
  31.     FFormID FormID;
  32.  
  33.     // The name of the parent plugin file (e.g., "MyPlugin.esp").
  34.     UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FormID")
  35.     FString ParentPluginName;
  36.  
  37.     // Array of master plugin file names that this plugin depends on.
  38.     UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FormID")
  39.     TArray<FString> Masters;
  40.  
  41.     // Default constructor initializing members to safe defaults.
  42.     FExtendedFormID()
  43.         : FormID(0)
  44.         , ParentPluginName(TEXT(""))
  45.         , Masters()
  46.     {
  47.     }
  48.  
  49.     // Equality operator to compare two FExtendedFormIDs.
  50.     bool operator==(const FExtendedFormID& Other) const
  51.     {
  52.         return FormID == Other.FormID && ParentPluginName == Other.ParentPluginName && Masters == Other.Masters;
  53.     }
  54.  
  55.     // Inequality operator derived from equality.
  56.     bool operator!=(const FExtendedFormID& Other) const
  57.     {
  58.         return !(*this == Other);
  59.     }
  60. };
  61.  
  62. // Define a class UFormIDHelper as a static Blueprint function library.
  63. // Inherits from UBlueprintFunctionLibrary to provide utility functions for FFormID operations in Blueprints.
  64. // Marked with UCLASS() for reflection and UNREALCREATIONENGINE_API for DLL export/import across modules.
  65. UCLASS()
  66. class UNREALCREATIONENGINE_API UFormIDHelper : public UBlueprintFunctionLibrary
  67. {
  68.     // Macro required for all UCLASSes to generate reflection code.
  69.     // Ensures the class is recognized by Unreal Engine's reflection system for Blueprint exposure.
  70.     GENERATED_BODY()
  71.  
  72. public:
  73.     // Function to convert a FormID to a hexadecimal string representation.
  74.     // Marked as UFUNCTION(BlueprintPure) to indicate it has no side effects and can be used in Blueprint graphs.
  75.     // Categorized under "FormID" for easy discovery in the Blueprint function library.
  76.     // Takes an FFormID and returns an FString formatted as "0xXXXXXXXX".
  77.     UFUNCTION(BlueprintPure, Category = "FormID")
  78.     static FString ToString(const FFormID& FormID);
  79.  
  80.     // Function to compare two FormIDs for equality.
  81.     // BlueprintPure ensures it is side-effect-free and usable in Blueprint logic.
  82.     // Categorized under "FormID" for organization in Blueprint menus.
  83.     // Takes two FFormID parameters and returns true if their Values are equal, false otherwise.
  84.     UFUNCTION(BlueprintPure, Category = "FormID")
  85.     static bool Equals(const FFormID& A, const FFormID& B);
  86.  
  87.     // Function to check if a FormID is valid (non-zero Value).
  88.     // BlueprintPure allows safe use in Blueprint calculations or conditions.
  89.     // Categorized under "FormID" for clarity in Blueprint interfaces.
  90.     // Takes an FFormID and returns true if its Value is non-zero, false if zero.
  91.     UFUNCTION(BlueprintPure, Category = "FormID")
  92.     static bool IsValid(const FFormID& FormID);
  93.  
  94.     // Function to extract the plugin index from a standard FormID (non-ESL).
  95.     // BlueprintPure ensures it is safe for Blueprint computations.
  96.     // Categorized under "FormID" for accessibility in Blueprint nodes.
  97.     // Takes an FFormID and returns the plugin index (bits 24-31) as an int32.
  98.     UFUNCTION(BlueprintPure, Category = "FormID")
  99.     static int32 GetPluginIndex(const FFormID& FormID);
  100.  
  101.     // Function to extract the record index from a standard FormID (non-ESL).
  102.     // BlueprintPure indicates no side effects, suitable for Blueprint data processing.
  103.     // Categorized under "FormID" for organization in Blueprint function lists.
  104.     // Takes an FFormID and returns the record index (bits 0-23) as an int32.
  105.     UFUNCTION(BlueprintPure, Category = "FormID")
  106.     static int32 GetRecordIndex(const FFormID& FormID);
  107.  
  108.     // Function to determine if a FormID belongs to an ESL (Elder Scrolls Light) plugin.
  109.     // BlueprintPure allows use in Blueprint logic without modifying state.
  110.     // Categorized under "FormID" for easy access in Blueprint interfaces.
  111.     // Takes an FFormID and returns true if the top byte is 0xFE (indicating ESL), false otherwise.
  112.     UFUNCTION(BlueprintPure, Category = "FormID")
  113.     static bool IsESL(const FFormID& FormID);
  114.  
  115.     // Function to get the ESL index from a FormID if it is an ESL plugin.
  116.     // BlueprintPure ensures it is safe for Blueprint calculations.
  117.     // Categorized under "FormID" for clarity in Blueprint menus.
  118.     // Takes an FFormID and returns the ESL index (bits 12-23) as an int32, or -1 if not ESL.
  119.     UFUNCTION(BlueprintPure, Category = "FormID")
  120.     static int32 GetESLIndex(const FFormID& FormID);
  121.  
  122.     // Function to get the record index from a FormID if it is an ESL plugin.
  123.     // BlueprintPure indicates it can be used in Blueprint logic without side effects.
  124.     // Categorized under "FormID" for organization in Blueprint function libraries.
  125.     // Takes an FFormID and returns the ESL record index (bits 0-11) as an int32, or -1 if not ESL.
  126.     UFUNCTION(BlueprintPure, Category = "FormID")
  127.     static int32 GetESLRecordIndex(const FFormID& FormID);
  128.  
  129.     // New functions for FExtendedFormID support
  130.  
  131.     // Function to create an FExtendedFormID with plugin context.
  132.     // BlueprintCallable allows it to be invoked from Blueprints to construct an FExtendedFormID instance.
  133.     // Categorized under "FormID" for consistency with other FormID-related functions.
  134.     UFUNCTION(BlueprintCallable, Category = "FormID")
  135.     static FExtendedFormID CreateExtendedFormID(const FString& InParentPluginName, const TArray<FString>& InMasters, int32 InRawId);
  136.  
  137.     // Function to normalize a plugin name to a full file path, adding .esp if no extension is present.
  138.     // BlueprintPure indicates it has no side effects and is suitable for Blueprint computations.
  139.     // Includes a tooltip for clarity in Blueprint interfaces.
  140.     UFUNCTION(BlueprintPure, Category = "FormID", meta=(ToolTip="Converts a plugin name to a full file path, adding .esp if needed."))
  141.     static FString NormalizePluginName(const FString& PluginName);
  142.  
  143.     // Function to validate the existence of plugin files, logging warnings if any are missing.
  144.     // BlueprintCallable since it performs logging, which is a side effect.
  145.     // Includes a tooltip describing its purpose.
  146.     UFUNCTION(BlueprintCallable, Category = "FormID", meta=(ToolTip="Checks if plugin files exist, logging warnings if missing."))
  147.     static bool ValidatePluginFiles(const FExtendedFormID& ExtendedFormID);
  148.  
  149.     // Function to check if a plugin name has a valid extension (.esm, .esp, or .esl).
  150.     // BlueprintPure ensures it is side-effect-free and usable in Blueprint logic.
  151.     // Includes a tooltip for Blueprint users.
  152.     UFUNCTION(BlueprintPure, Category = "FormID", meta=(ToolTip="Returns true if the plugin name has a valid extension."))
  153.     static bool IsValidPluginExtension(const FString& PluginName);
  154.  
  155.     // Function to retrieve the record index within the plugin for an FExtendedFormID.
  156.     // BlueprintPure allows its use in Blueprint calculations without modifying state.
  157.     // Includes a tooltip for clarity.
  158.     UFUNCTION(BlueprintPure, Category = "FormID", meta=(ToolTip="Gets the record index within the plugin."))
  159.     static int32 GetObjectIndex(const FExtendedFormID& ExtendedFormID);
  160.  
  161.     // Function to retrieve the plugin file path for an FExtendedFormID.
  162.     // BlueprintPure indicates it is a read-only operation suitable for Blueprints.
  163.     // Includes a tooltip describing its output.
  164.     UFUNCTION(BlueprintPure, Category = "FormID", meta=(ToolTip="Gets the plugin file path for this FormID."))
  165.     static FString GetPluginName(const FExtendedFormID& ExtendedFormID);
  166.  
  167.     // Function to retrieve all plugin file paths (parent and masters) for an FExtendedFormID.
  168.     // BlueprintPure ensures it is safe for Blueprint data retrieval.
  169.     // Includes a tooltip explaining the returned array.
  170.     UFUNCTION(BlueprintPure, Category = "FormID", meta=(ToolTip="Gets all plugin file paths (parent and masters)."))
  171.     static TArray<FString> GetAllPluginNames(const FExtendedFormID& ExtendedFormID);
  172.  
  173.     // Function to check if a specific plugin is listed as a master dependency in an FExtendedFormID.
  174.     // BlueprintPure allows its use in Blueprint conditions without side effects.
  175.     // Includes a tooltip for user guidance.
  176.     UFUNCTION(BlueprintPure, Category = "FormID", meta=(ToolTip="Returns true if the plugin is a master dependency."))
  177.     static bool HasMaster(const FExtendedFormID& ExtendedFormID, const FString& MasterName);
  178.  
  179.     // Function to estimate the load order index for an FExtendedFormID’s plugin.
  180.     // BlueprintPure indicates it is a computation without side effects.
  181.     // Includes a tooltip explaining the load order concept.
  182.     UFUNCTION(BlueprintPure, Category = "FormID", meta=(ToolTip="Estimates load order index (0-based, higher means later)."))
  183.     static int32 GetPluginLoadOrderIndex(const FExtendedFormID& ExtendedFormID);
  184.  
  185.     // Function to compare two FExtendedFormIDs based on plugin names and object indices.
  186.     // BlueprintPure ensures it is suitable for Blueprint comparisons.
  187.     // Includes a tooltip describing the comparison logic.
  188.     UFUNCTION(BlueprintPure, Category = "FormID", meta=(ToolTip="Compares plugin names (case-insensitive) and indices."))
  189.     static bool IsLessThan(const FExtendedFormID& A, const FExtendedFormID& B);
  190. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement