Jump to content

SA2B Mod Loader: Difference between revisions

From SA Docs
Writing SA2B Mod Loader page and documentation.
(No difference)

Revision as of 14:51, 4 October 2025

Source Code


HelperFunctions API

Struct

Below is the initialized version of the HelperFunctions struct. For the definition of the struct, you can find that in SA2ModInfo.h

HelperFunctions helperFunctions = 
{
    ModLoaderVer,
    RegisterStartPosition,
    ClearStartPositionList,
    Register2PIntroPosition,
    Clear2PIntroPositionList,
    GetMainSavePath,
    GetChaoSavePath,
    RegisterEndPosition,
    ClearEndPositionList,
    RegisterMission23EndPosition,
    ClearMission23EndPositionList,
    HookExport,
    GetReplaceablePath,
    _ReplaceFile,
    SetWindowTitle,
    debug_text::SetFontSize,
    debug_text::SetFontColor,
    debug_text::DisplayString,
    debug_text::DisplayStringFormatted,
    debug_text::DisplayNumber,
    &loaderSettings,
    &modList,
    &RegisterVoice,
    &ReplaceTexture,
    &UnreplaceFile,
    &PushInterpolationFix,
    &PopInterpolationFix,
};

Properties

Mod Loader Version

int ModLoaderVer;

This returns the version of the mod loader. This can be used to check if the user has an old version of the mod loader that may not have functionality your mod requires.

Example

if (globalHelperFunctions.ModLoaderVer <= 10)
    PrintDebug("This Mod Loader is way out of date.\n");

Mod Loader Settings

LoaderSettings loaderSettings;


Example


Mod List

std::vector<Mod> modlist;

Example


Functions

Register Start Position

void RegisterStartPosition(unsigned char character, const StartPosition& position)

Registers a Start Position for the specified character.

Example

// This is a declaration of an SA2 StartPosition struct.
StartPosition myStageStartPos = { 
    1,                          // Level ID
    0x4000,                     // Single Player Y Rotation 
    0x4000,                     // Multiplayer, Player 1 Y Rotation
    0x4000,                     // Multiplayer, Player 2 Y Rotation
    { 100.0f, 200.0f, 100.0f }, // Single Player Start Position
    { 90.0f, 200.0f, 100.0f },  // Multiplayer, Player 1 Start Position
    { 110.0f, 200.0f, 100.0f }  // Multiplayer, Player 2 Start Position
};

// We pass our StagePosition variable as a pointer to this function
// and we have specified Sonic, so the level for this ID would now use
// our StartPosition instead of the original.
globalHelperFunctions.RegisterStartPosition(Characters_Sonic, &myStageStartPos);

Clear Start Position List

void ClearStartPositionList(unsigned char character)

Clears the Start Positions for the specified character.

Example


Register 2P Intro Position

void Register2PIntroPosition(unsigned char character, const LevelEndPosition& position)

Registers a Multiplayer Intro Position for the specified character.

Example


Clear 2P Intro Position List

void Clear2PIntroPositionList(unsigned char character)

Clears all Multiplayer Intro Positions for the specified character.

Example


Get Main Save Path

const char* GetMainSavePath()

Returns the game's Main Save File's path.

Example


Get Chao Save Path

const char* GetChaoSavePath()

Example


Register End Position

void RegisterEndPosition(unsigned char character, const StartPosition& position)

Example


Clear End Position List

void ClearEndPositionList(unsigned char character)

Example


Register Mission 2/3 End Position

void RegisterMission23EndPosition(unsigned char character, const LevelEndPosition& position)

Example


Clear Mission 2/3 End Position List

void ClearMission23EndPositionList(unsigned char character)

Example


Hook Export

void HookExport(LPCSTR exportName, const void* newdata)

Example


Get Replaceable Path

const char* __cdecl GetReplaceablePath(const char* path)

Example


Replace File

void _ReplaceFile(const char* src, const char* dst)

Example


Set Window Title

void SetWindowTitle(const wchar_t* title)

Example


Debug Text : Set Font Size

void SetFontSize(float size)

Example


Debug Text : Set Font Color

void SetFontColor(int color)

Example


Debug Text : Display String

void DisplayString(int loc, const char* str)

Example


Debug Text : Display String Formatted

void DisplayStringFormatted(int loc, const char* Format, ...)

Example


Debug Text : Display Number

void DisplayNumber(int loc, int value, int numdigits)

Example


Register Voice

uint16_t RegisterVoice(const char* fileJP, const char* fileEN)

Example


Replace Texture

void ReplaceTexture(const char* pvm_name, const char* tex_name, const char* file_path, uint32_t gbix, uint32_t width, uint32_t height)

Example


Unreplace File

void UnreplaceFile(const char* file)

Example


Push Interpolation Fix

void PushInterpolationFix()

Example


Pop Interpolation Fix

void PopInterpolationFix()

Example


Get File Mod Index

int GetFileModIndex(const char* path)

Example


Replace File At Index

void ReplaceFileAtIndex(const char* src, const char* dst, int modIndex)

Example