Cavestory Mod API
Classes
LanguageResource.h File Reference
#include <CSMAPI_begincode.h>
#include <CSMAPI_endcode.h>

Go to the source code of this file.

Classes

struct  PXLANG_DEBUG_SYMBOL_STRUCT
 Holds information about a specific debug symbol. More...
 
struct  PXLANG_STRING_STRUCT
 Holds information about a specific localization string. More...
 
struct  PXLANG_GROUP_STRUCT
 Holds information about a localization group. More...
 
struct  PXLANG_RESOURCE_STRUCT
 Holds information for a compiled pixel language file (.pxclang). More...
 
#define PXLANG_MAGIC   "PXLANG"
 
#define PXLANG_VERSION   2
 
#define PXLANG_VALID_CRC   0x1F5F1F44
 
#define PXLANG_SYMBOL_MAGIC   "PXLNGS"
 
#define PXLANG_SYMBOL_VERSION   1
 
#define __VA_NARGS_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...)   N
 
#define __EXPAND(x)   x
 
#define __VA_NARGS(...)   __EXPAND(__VA_NARGS_IMPL(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1))
 
#define _LOC(x, ...)   x
 
#define LOCALE_STATIC
 
#define USE_LOCALE_NAME_AS_DEFAULT   NULL
 
#define UseGlobalLocaleBuffer(x)   CSM_PxLang_GetGlobalBuffer(x), -1
 
#define UseStaticLocaleBuffer(BUFFER)   BUFFER, sizeof(BUFFER)
 
#define UseDynamicLocaleBuffer(BUFFER, BUFFERSIZE)   BUFFER, BUFFERSIZE
 
#define GetLocaleStringWithArgumentsA(LOCALE_NAME, ARG_FORMAT, DEFAULT_STRING, ...)   CSM_PxLang_GetString(LOCALE_NAME, NULL, -1, DEFAULT_STRING, NULL, ARG_FORMAT, __VA_NARGS(__VA_ARGS__), ## __VA_ARGS__)
 
#define GetLocaleStringA(LOCALE_NAME, DEFAULT_STRING)   CSM_PxLang_GetString(LOCALE_NAME, NULL, -1, DEFAULT_STRING, NULL, NULL, 0)
 
#define CopyLocaleStringWithArgumentsA(BUFFERINFO, LOCALE_NAME, ARG_FORMAT, DEFAULT_STRING, ...)   CSM_PxLang_GetString(LOCALE_NAME, BUFFERINFO, DEFAULT_STRING, NULL, ARG_FORMAT, __VA_NARGS(__VA_ARGS__), ## __VA_ARGS__)
 
#define CopyLocaleStringA(BUFFERINFO, LOCALE_NAME, DEFAULT_STRING)   CSM_PxLang_GetString(LOCALE_NAME, BUFFERINFO, DEFAULT_STRING, NULL, NULL, 0)
 
#define BuildLocaleString(STRING)   CSM_PxLang_BuildFormat(STRING)
 Build a locale string. More...
 
#define LoadNonLocaleFont(FONTNAME, FONTW, FONTH)   (CSM_PxLang_IsLoaded(&gCurrentLocalization) && strcmpi(gCurrentLocalization.font_name, "Courier New") ? FontHandle(NULL, (gCurrentLocalization.font_width / 1.1), (gCurrentLocalization.font_height / 1.1)) : FontHandle(FONTNAME, FONTW, FONTH))
 
#define LoadNonLocaleFontWithSubstitue(FONTNAME, FONTNAME2, FONTW, FONTH)   (CSM_PxLang_IsLoaded(&gCurrentLocalization) && strcmpi(gCurrentLocalization.font_name, "Courier New") ? FontHandle(FONTNAME2, (gCurrentLocalization.font_width / 1.1), (gCurrentLocalization.font_height / 1.1)) : FontHandle(FONTNAME, FONTW, FONTH))
 
#define LoadNonLocaleFontCustomMag(INPUT_MAG, FONTNAME, FONTW, FONTH)   (CSM_PxLang_IsLoaded(&gCurrentLocalization) && strcmpi(gCurrentLocalization.font_name, "Courier New") ? FontHandle(NULL, (gCurrentLocalization.font_width / 1.1), (gCurrentLocalization.font_height / 1.1), INPUT_MAG) : FontHandle(FONTNAME, FONTW, FONTH, INPUT_MAG))
 
#define LoadNonLocaleFontWithSubstitueCustomMag(INPUT_MAG, FONTNAME, FONTNAME2, FONTW, FONTH)   (CSM_PxLang_IsLoaded(&gCurrentLocalization) && strcmpi(gCurrentLocalization.font_name, "Courier New") ? FontHandle(FONTNAME2, (gCurrentLocalization.font_width / 1.1), (gCurrentLocalization.font_height / 1.1), INPUT_MAG) : FontHandle(FONTNAME, FONTW, FONTH, INPUT_MAG))
 
enum  PXLANG_ArgType { PXLANG_TYPE_STRING = 0 , PXLANG_TYPE_INT = 1 }
 Argument types for compiled pxlang files.
 
enum  PXLANG_SymbolType { PXLANG_SYMBOL_TYPE_GROUP = 0 , PXLANG_SYMBOL_TYPE_STRING = 1 , MAX_PXLANG_SYMBOL_COUNT }
 Type of debug symbol for pxlang symbol file.
 
CAVESTORY_MOD_API PXLANG_RESOURCE_STRUCT gCurrentLocalization
 This global variable holds the currently loaded localization file.
 
CAVESTORY_MOD_API int CSM_PxLang_Compile (const char *pFileName, bool bForceDebugSymbols=false)
 Compile a language resource file. More...
 
CAVESTORY_MOD_API int CSM_PxLang_Load (PXLANG_RESOURCE_STRUCT *pLangObj, const char *pFileName, const char *pGroupName=NULL, bool bRecompile=true, bool bForceDebugSymbols=false)
 Load a language resource file. More...
 
CAVESTORY_MOD_API BOOL CSM_PxLang_Free (PXLANG_RESOURCE_STRUCT *pLangObj)
 Free up a language resource object. More...
 
CAVESTORY_MOD_API BOOL CSM_PxLang_IsLoaded (PXLANG_RESOURCE_STRUCT *pLangObj)
 Check to see if a language object is loaded. More...
 
CAVESTORY_MOD_API BOOL CSM_PxLang_HasString (const char *pStringName, PXLANG_RESOURCE_STRUCT *pLangObj=NULL)
 Check to see if a language object has a localization string. More...
 
CAVESTORY_MOD_API const char * CSM_PxLang_GetString (const char *pStringName, char *pBuffer=NULL, int iBufferSize=-1, const char *pDefaultValue=NULL, PXLANG_RESOURCE_STRUCT *pLangObj=NULL, const char *pArgFormat=NULL, int iArgCount=0,...)
 Get a string from a language object. More...
 
CAVESTORY_MOD_API char * CSM_PxLang_GetGlobalBuffer (unsigned int iBufferID)
 Get a global PxLang buffer. More...
 
CAVESTORY_MOD_API bool CSM_PxLang_LoadDebugSymbols (PXLANG_RESOURCE_STRUCT *pLangObj)
 Load debug symbols for a PxLang object. More...
 
CAVESTORY_MOD_API BOOL CSM_PxLang_SetCurrentLocalization (const char *pLanguageName, bool bUseData=false)
 Set the current localization object. More...
 
CAVESTORY_MOD_API void CSM_PxLang_SetGroup (const char *pGroupName, PXLANG_RESOURCE_STRUCT *pLangObj=NULL)
 Set the current localization object. More...
 
CAVESTORY_MOD_API const char * CSM_PxLang_BuildFormat (const char *pFormat)
 Build an argumentitive string. More...
 

Macro Definition Documentation

◆ BuildLocaleString

#define BuildLocaleString (   STRING)    CSM_PxLang_BuildFormat(STRING)

Build a locale string.

Instead of '{<arg_index>}' you will use 's' in this string, regardless of whether the input argument type is a string or not.

See also
CopyLocaleStringWithArgumentsA
GetLocaleStringWithArgumentsA

Function Documentation

◆ CSM_PxLang_BuildFormat()

CAVESTORY_MOD_API const char* CSM_PxLang_BuildFormat ( const char *  pFormat)

Build an argumentitive string.

Parameters
Theformat string. Only use 's' for specifying arguments.
Returns
Returns a pointer to a static buffer with the built result.

◆ CSM_PxLang_Compile()

CAVESTORY_MOD_API int CSM_PxLang_Compile ( const char *  pFileName,
bool  bForceDebugSymbols = false 
)

Compile a language resource file.

Parameters
pFileNameThe file path of the pxlang file.
bForceDebugSymbolsWhether to force debug symbols to be compiled or not.
Returns
Returns 0 on success, non-zero on error.

◆ CSM_PxLang_Free()

CAVESTORY_MOD_API BOOL CSM_PxLang_Free ( PXLANG_RESOURCE_STRUCT pLangObj)

Free up a language resource object.

Parameters
pLangObjThe object to free the memory of.
Returns
Returns TRUE on success, FALSE on failure.

◆ CSM_PxLang_GetGlobalBuffer()

CAVESTORY_MOD_API char* CSM_PxLang_GetGlobalBuffer ( unsigned int  iBufferID)

Get a global PxLang buffer.

Parameters
iBufferIDThe buffer ID.
Returns
Always returns NULL.
Note
This should only be used with CopyLocaleStringA and CopyLocaleStringWithArgumentsA.

◆ CSM_PxLang_GetString()

CAVESTORY_MOD_API const char* CSM_PxLang_GetString ( const char *  pStringName,
char *  pBuffer = NULL,
int  iBufferSize = -1,
const char *  pDefaultValue = NULL,
PXLANG_RESOURCE_STRUCT pLangObj = NULL,
const char *  pArgFormat = NULL,
int  iArgCount = 0,
  ... 
)

Get a string from a language object.

Parameters
pStringNameThe name of the localization string.
pBufferA pointer to a buffer that will hold the information.
pLangObjThe localization object to reference. If this is NULL, then the currently loaded global localization object will be used.
pDefaultValueThe default value to set if the string is not defined.
iArgCountThe amount of arguments to replace.
...A list of arguments.
Returns
Returns TRUE if the string was found, FALSE otherwise.

◆ CSM_PxLang_HasString()

CAVESTORY_MOD_API BOOL CSM_PxLang_HasString ( const char *  pStringName,
PXLANG_RESOURCE_STRUCT pLangObj = NULL 
)

Check to see if a language object has a localization string.

Parameters
pStringNameThe name of the localization string.
pLangObjThe localization object to reference. If this is NULL, then the currently loaded global localization object will be used.
Returns
Returns TRUE if the string was found, FALSE otherwise.

◆ CSM_PxLang_IsLoaded()

CAVESTORY_MOD_API BOOL CSM_PxLang_IsLoaded ( PXLANG_RESOURCE_STRUCT pLangObj)

Check to see if a language object is loaded.

Parameters
pLangObjThe localization object to check.
Returns
Returns TRUE if it is loaded, FALSE otherwise.

◆ CSM_PxLang_Load()

CAVESTORY_MOD_API int CSM_PxLang_Load ( PXLANG_RESOURCE_STRUCT pLangObj,
const char *  pFileName,
const char *  pGroupName = NULL,
bool  bRecompile = true,
bool  bForceDebugSymbols = false 
)

Load a language resource file.

Parameters
pLangObjThe language resource object to load the pxlang file into.
pFileNameThe file path of the pxlang file.
pGroupNameThe name of the group to be loaded.
bRecompileRecompile the file if the file's CRC mismatches
bForceDebugSymbolsWhether to forcibly load debug symbols for this pxlang. If a symbol file doesn't exist, it will be compiled.
Returns
Returns 0 on success, non-zero on error.
Note
If the language object is already allocated to another pxlang file, then this will free the previous contents.
If no compiled pxlang file is found that matches the given pxlang file, then one will be compiled on the fly.

◆ CSM_PxLang_LoadDebugSymbols()

CAVESTORY_MOD_API bool CSM_PxLang_LoadDebugSymbols ( PXLANG_RESOURCE_STRUCT pLangObj)

Load debug symbols for a PxLang object.

Parameters
pLangObjThe localization object to load.
Returns
Returns true if debug symbols were loaded, false otherwise.
Note
This function can only fail if
This should only be used with CopyLocaleStringA and CopyLocaleStringWithArgumentsA.

◆ CSM_PxLang_SetCurrentLocalization()

CAVESTORY_MOD_API BOOL CSM_PxLang_SetCurrentLocalization ( const char *  pLanguageName,
bool  bUseData = false 
)

Set the current localization object.

Parameters
pFileNameThe name of the pxlang file to load.
bUseDataWhether to use 'data' as the mod directory (TRUE), or the currently loaded mod (FALSE).
Returns
Returns TRUE on success, FALSE on failure.
Note
You can safely free pLangObj afterwards if it was an allocated resource struct, but do not call CSM_PxLang_Free with it.
This loads the file from '<mod folder name>/Language/<pLanguageName>/main.pxlang'.

◆ CSM_PxLang_SetGroup()

CAVESTORY_MOD_API void CSM_PxLang_SetGroup ( const char *  pGroupName,
PXLANG_RESOURCE_STRUCT pLangObj = NULL 
)

Set the current localization object.

Parameters
pGroupNameThe group name to use.
pLangObjThe localization object to set as current. If this is 'NULL', then it uses gCurrentLocalization.