CommonLibSSE NG

repository·main·Indexed 41 days ago

https://github.com/charmedbaryon/commonlibsse-ng

An enhanced fork of CommonLibSSE for Skyrim SE, AE, and VR plugin development. It features multi-runtime targeting for single DLL support across editions, simplified CMake integration via add_commonlibsse_plugin, and improved support for modern compilers like Clang. Available as a Vcpkg port and via Conan (version 3.5.0+).

Tokens
2K
Snippets
7
Records
10
Agent score
2%

What's inside CommonLibSSE NG

  1. How multi-targeting works in CommonLibSSE NG

    main

    CommonLibSSE NG supports creating single DLLs that work across multiple Skyrim runtimes (SE, AE, and VR).

    Key Concepts:

    • Single DLL: A single build can target multiple ABI-incompatible runtimes, improving developer productivity and end-user experience.
    • Runtime Abstractions: The library provides minimal abstractions that allow code to run transparently regardless of the Skyrim edition.
    • Feature Probing: While all functionality and classes for all runtimes are available, you should use the provided support for probing features to dynamically alter behavior (e.g., using VR-specific features only when a VR runtime is detected).
  2. Install CommonLibSSE NG via Conan

    main

    CommonLibSSE NG can be consumed via Conan (available since version 3.5.0). You can specify the requirement in a conanfile.txt or conanfile.py.

    By default, the package includes support for all runtimes (AE, SE, and VR). You can selectively enable or disable specific runtimes using package options.

    Supported binary combinations (x86_64 Windows, Visual Studio 16/17):

    • Debug/Release x Debug/Release
    • x86_64
    • Visual Studio 16 (2019) or 17 (2022)
    # conanfile.txt example
    [requires]
    commonlibsse-ng/3.5.2
    
    [options]
    commonlibsse-ng:ae=True
    commonlibsse-ng:se=True
    commonlibsse-ng:vr=True
    # conanfile.py example
    class MyProject:
        # ...
        requires = 'commonlibsse-ng/3.5.2'
        default_options = {
          # ...
          'commonlibsse-ng:with_ae': True,
          'commonlibsse-ng:with_se': True,
          'commonlibsse-ng:with_vr': True
        }
  3. Install CommonLibSSE NG via Vcpkg

    main

    CommonLibSSE NG is available as a Vcpkg port through the Color-Glass Studios registry. To use it, you must create a vcpkg-configuration.json file in your project root (alongside vcpkg.json) to register the git repository and set a baseline.

    After configuring the registry, add the desired package to your vcpkg.json dependencies. You can use the general commonlibsse-ng package for multi-runtime support or specific runtime-only ports to avoid dynamic lookups and access version-specific reverse-engineered content.

    {
        "registries": [
            {
                "kind": "git",
                "repository": "https://gitlab.com/colorglass/vcpkg-colorglass",
                // Update this baseline to the latest commit from the above repo.
                "baseline": "9eae9f03f03e0ca96fce5031f44f4e64cd6debdc",
                "packages": [
                    "commonlibsse-ng",
                    "commonlibsse-ng-ae",
                    "commonlibsse-ng-se",
                    "commonlibsse-ng-vr",
                    "commonlibsse-ng-flatrim"
                ]
            }
        ]
    }
  4. Link CommonLibSSE NG in CMake

    main

    To compile and link your project against CommonLibSSE NG, ensure your CMakeLists.txt includes the following commands to find the package and link the target to your project.

    find_package(CommonLibSSE REQUIRED)
    target_link_libraries(${PROJECT_NAME} PUBLIC CommonLibSSE::CommonLibSSE)
  5. Simplify Plugin Declaration with add_commonlibsse_plugin

    main

    CommonLibSSE NG simplifies the creation of SKSE plugins by removing the need to manually define SKSEPlugin_Version or SKSEPlugin_Query.

    Instead of using the standard CMake add_library, use the add_commonlibsse_plugin command. This command automatically:

    1. Creates your shared library target.
    2. Configures CommonLibSSE linkage.
    3. Auto-generates and injects the necessary plugin detection content into the binary.
    find_package(CommonLibSSE REQUIRED)
    
    add_commonlibsse_plugin(${PROJECT_NAME}
        SOURCES ${headers} ${sources})
  6. Reference: Vcpkg Runtime-Specific Packages

    main

    When using Vcpkg, you can choose specific ports depending on your target Skyrim runtime. Using a specific port prevents the plugin from attempting to dynamically lookup the Skyrim version at runtime and allows access to non-portable, version-specific content.

    commonlibsse-ng         : General package
    commonlibsse-ng-ae      : Supports AE executables (1.6.x) only
    commonlibsse-ng-se      : Supports pre-AE executables (1.5.x) only
    commonlibsse-ng-vr      : Supports VR only
    commonlibsse-ng-flatrim : Supports SE/AE, but not VR
  7. Use the RE::Main class

    main

    The RE::Main class provides access to core engine components and global state. It inherits from BSTEventSink for PositionPlayerEvent and BSGamerProfileEvent, allowing it to process these specific events via its overridden ProcessEvent methods.

    Key Methods

    • static Main* GetSingleton(): Returns the singleton instance.
    • static float QFrameAnimTime(): Returns the animation time for the current frame.
    • static NiCamera* WorldRootCamera(): Returns the root camera of the world.
    • static Scenegraph* WorldRootNode(): Returns the root node of the scenegraph.
    • void SetActive(bool a_active): Sets the active state of the main instance.

    Key Members

    • bool gameActive: Indicates if the game is currently active.
    • bool quitGame: Indicates if the game is requesting a shutdown.
    • bool resetGame: Indicates if the game is requesting a reset.
    • REX::W32::HWND wnd: The window handle (HWND) for the game window.
    • REX::W32::HINSTANCE instance: The application instance handle.
    • std::uint32_t threadID: The ID of the main thread.
    RE::Main* main = RE::Main::GetSingleton();
    if (main->gameActive) {
        float animTime = RE::Main::QFrameAnimTime();
        RE::NiCamera* camera = RE::Main::WorldRootCamera();
    }
  8. Reference the BSSaveDataSystemUtilityImage structure

    main

    The RE::BSSaveDataSystemUtilityImage structure defines the layout for system utility images used in save data (such as background or icon images).

    Fields

    • std::uint32_t size: Size of the image data.
    • std::uint32_t width: Image width.
    • std::uint32_t height: Image height.
    • char* buffer: Pointer to the raw image buffer.
  9. Reference the BSPackedTaskQueue structure

    main

    The RE::BSPackedTaskQueue structure manages a queue of BSPackedTask objects using a BSTCommonScrapHeapMessageQueue. It uses a RE::Semaphore for synchronization and requires an UnpackFunc_t callback to process tasks.

    Structure Members

    • BSTCommonScrapHeapMessageQueue<BSPackedTask> queue: The underlying message queue.
    • mutable Semaphore semaphore: A semaphore used for thread synchronization.
    • UnpackFunc_t* unpackFunc: A pointer to the function used to unpack tasks.