Skip to content
Angad edited this page Sep 26, 2023 · 4 revisions

CommonLibSF allows you to create DLL plugins for Starfield to be loaded by SFSE. Every plugin project that uses CommonLibSF must define the following two functions so that SFSE is able to load the plugin correctly. SFSEPluginLoad is a macro wrapper for the function called by SFSE when loading a DLL plugin–it is the main entry point for the plugin:

SFSEPluginLoad(const SFSE::LoadInterface* sfse)
{
    Init(sfse);

    // do stuff

    return true;
}

SFSEPluginVersion is a macro wrapper for a function that declares metadata about the plugin to SFSE for use during the plugin loading process. The following is an example of a Plugin.h header file that defines SFSEPluginVersion:

#pragma once

namespace Plugin
{
    using namespace std::string_view_literals;

    static constexpr auto Name{ "PluginName"sv };
    static constexpr auto Author{ "AuthorName"sv };
    static constexpr auto Version{
        REL::Version{0, 0, 1, 0}
    };
}

SFSEPluginVersion = []() noexcept {
    SFSE::PluginVersionData data{};

    data.PluginVersion(Plugin::Version.pack());
    data.PluginName(Plugin::Name);
    data.AuthorName(Plugin::Author);
    data.UsesAddressLibrary(true);
    data.IsLayoutDependent(true);
    data.CompatibleVersions({ SFSE::RUNTIME_LATEST });

    return data;
}();

See PluginAPI.h at the SFSE repo for more about SFSEPlugin_Load and SFSEPlugin_Version. SFSE's API also includes an SFSEPlugin_Preload function for which a macro is provided in CommonLibSF. See Interfaces.h for the macro definitions.

Including CommonLibSF in your project

vcpkg

Instructions for consuming CommonLibSF using vcpkg are provided at our vcpkg registry repo.

xrepo

Thanks to Qudix for maintaining the custom xmake repo!

Add the following to your xmake.lua:

-- add commonlibsf-xrepo repository
add_repositories("re https://github.com/Starfield-Reverse-Engineering/commonlibsf-xrepo")

-- require package dependencies
add_requires("commonlibsf")

target("name")
...
    -- bind packages to the target
    add_packages("commonlibsf")

git submodule

To consume CommonLibSF as a submodule, cd into your project directory and run:

git submodule add https://github.com/Starfield-Reverse-Engineering/CommonLibSF extern/CommonLibSF
git submodule update -f --init

Then add the following to your CMakeLists.txt:

add_subdirectory(extern/CommonLibSF)
target_link_libraries(
  ${PROJECT_NAME}
  PRIVATE
  CommonLibSF::CommonLibSF
)

NOTE: You may also use the custom add_commonlibsf_plugin command instead of target_link_libraries.