Advertisement
malice936

GameID.h

Apr 13th, 2025
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.21 KB | Gaming | 0 0
  1. #pragma once
  2.  
  3. // Include the minimal set of headers required for Unreal Engine functionality.
  4. // This ensures access to core Unreal Engine types and macros.
  5. #include "CoreMinimal.h"
  6. // Include the generated header for this class, which is automatically created by Unreal Engine
  7. // for UCLASS and USTRUCT definitions, ensuring proper reflection and serialization.
  8. #include "GameID.generated.h"
  9.  
  10. // Enum to identify different Bethesda games, each with a unique value for easy selection in Blueprints.
  11. // This enum replaces the original GameId enum, where some games (e.g., Fallout 3, New Vegas, Fallout 4)
  12. // shared the same value as Skyrim, to avoid confusion when selecting games in Blueprints.
  13. // The UMETA(DisplayName) attribute provides a human-readable name for each game, which is displayed
  14. // in Blueprints for better usability and accessibility for modders.
  15. // Using uint8 as the underlying type ensures memory efficiency given the small number of games.
  16. UENUM(BlueprintType)
  17. enum class EGameID : uint8
  18. {
  19.     Oblivion UMETA(DisplayName = "Oblivion"),      // Identifier for The Elder Scrolls IV: Oblivion
  20.     Skyrim UMETA(DisplayName = "Skyrim"),          // Identifier for The Elder Scrolls V: Skyrim
  21.     Fallout3 UMETA(DisplayName = "Fallout 3"),     // Identifier for Fallout 3
  22.     FalloutNV UMETA(DisplayName = "Fallout: New Vegas"), // Identifier for Fallout: New Vegas
  23.     Morrowind UMETA(DisplayName = "Morrowind"),    // Identifier for The Elder Scrolls III: Morrowind
  24.     Fallout4 UMETA(DisplayName = "Fallout 4")      // Identifier for Fallout 4
  25. };
  26.  
  27. // Enum to group games that share similar parsing logic for .ESM, .ESP, and .ESL files.
  28. // This preserves the original functionality where certain games (e.g., Skyrim, Fallout 3, New Vegas,
  29. // Fallout 4) are treated the same way during parsing, reflecting shared file formats due to similar
  30. // game engines (e.g., Creation Engine).
  31. // Each group corresponds to a set of games with compatible file formats, allowing for efficient
  32. // handling of game-specific data in the parsing system.
  33. // The UMETA(DisplayName) attribute ensures clear naming in Blueprints for modders.
  34. UENUM(BlueprintType)
  35. enum class EGameGroup : uint8
  36. {
  37.     Oblivion UMETA(DisplayName = "Oblivion"),          // Group for Oblivion, which has unique parsing logic
  38.     SkyrimLike UMETA(DisplayName = "Skyrim/Fallout 3/NV/4"), // Group for Skyrim, Fallout 3, New Vegas, and Fallout 4,
  39.     // which share similar parsing logic due to engine similarities
  40.     Morrowind UMETA(DisplayName = "Morrowind")         // Group for Morrowind, which has unique parsing logic
  41. };
  42.  
  43. // Helper class providing utility functions for working with game IDs in Blueprints.
  44. // This class is a Blueprint Function Library, allowing its functions to be easily called from Blueprints
  45. // without needing to instantiate an object, enhancing usability for modders.
  46. // It contains static functions that do not modify any state (BlueprintPure), making them safe and
  47. // efficient for use in Blueprints, aligning with the project's goal of exposing data to Blueprints.
  48. UCLASS()
  49. class UNREALCREATIONENGINE_API UGameIDHelper : public UBlueprintFunctionLibrary
  50. {
  51.     GENERATED_BODY()
  52.  
  53. public:
  54.     // Function to retrieve the name of a game as a string based on its EGameID.
  55.     // This is useful for logging, displaying game names in the UI, or any other context where
  56.     // a human-readable game name is needed, enhancing modder experience.
  57.     // The function uses a switch statement to map each EGameID to its corresponding string representation,
  58.     // ensuring a clear and maintainable mapping.
  59.     // Marked as BlueprintPure to indicate it has no side effects and can be used in Blueprint graphs.
  60.     // Categorized under "GameID" for easy discovery in Blueprint function lists.
  61.     UFUNCTION(BlueprintPure, Category = "GameID")
  62.     static FString GetGameName(EGameID GameID)
  63.     {
  64.         switch (GameID)
  65.         {
  66.         case EGameID::Oblivion: return "Oblivion";          // Returns the name for Oblivion
  67.         case EGameID::Skyrim: return "Skyrim";              // Returns the name for Skyrim
  68.         case EGameID::Fallout3: return "Fallout 3";         // Returns the name for Fallout 3
  69.         case EGameID::FalloutNV: return "Fallout: New Vegas"; // Returns the name for Fallout: New Vegas
  70.         case EGameID::Morrowind: return "Morrowind";        // Returns the name for Morrowind
  71.         case EGameID::Fallout4: return "Fallout 4";         // Returns the name for Fallout 4
  72.         default: return "Unknown";                          // Returns "Unknown" for any unrecognized EGameID,
  73.             // ensuring robustness against invalid inputs
  74.         }
  75.     }
  76.  
  77.     // Function to determine the game group for a given EGameID.
  78.     // This helps in identifying which parsing logic to use for the game's .ESM, .ESP, or .ESL files,
  79.     // preserving the original system's behavior where certain games share parsing logic.
  80.     // The function maps each EGameID to its corresponding EGameGroup, reflecting the grouping in the
  81.     // original enum (e.g., Skyrim, Fallout 3, New Vegas, Fallout 4 all map to SkyrimLike).
  82.     // Uses a switch statement for clear and maintainable logic, with fall-through cases for grouped games.
  83.     // The default case returns SkyrimLike to handle unrecognized inputs, aligning with the most common group.
  84.     // Marked as BlueprintPure for use in Blueprints without side effects, categorized under "GameID".
  85.     UFUNCTION(BlueprintPure, Category = "GameID")
  86.     static EGameGroup GetGameGroup(EGameID GameID)
  87.     {
  88.         switch (GameID)
  89.         {
  90.         case EGameID::Oblivion: return EGameGroup::Oblivion; // Oblivion has its own unique group
  91.         case EGameID::Skyrim:
  92.         case EGameID::Fallout3:
  93.         case EGameID::FalloutNV:
  94.         case EGameID::Fallout4: return EGameGroup::SkyrimLike; // These games share the SkyrimLike group,
  95.             // reflecting shared file formats and engine similarities
  96.         case EGameID::Morrowind: return EGameGroup::Morrowind; // Morrowind has its own unique group
  97.         default: return EGameGroup::SkyrimLike; // Default to SkyrimLike for any unrecognized EGameID,
  98.             // ensuring consistent behavior for unknown cases
  99.         }
  100.     }
  101. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement