Cavestory Mod API
LanguageResource.h
Go to the documentation of this file.
1 /*
2  Cavestory Multiplayer API
3  Copyright (C) 2021 Johnny Ledger
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
26 #ifndef CAVESTORY_MOD_API_H_
27 #error "Please include CavestoryModAPI.h before including sub-classes."
28 #endif
29 
30 #include <CSMAPI_begincode.h>
31 
32 #pragma once
33 
37 
38 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
39 
40 #define PXLANG_MAGIC "PXLANG"
41 #define PXLANG_VERSION 2
42 #define PXLANG_VALID_CRC 0x1F5F1F44
43 #define PXLANG_SYMBOL_MAGIC "PXLNGS"
44 #define PXLANG_SYMBOL_VERSION 1
45 
46 // Enable to always recompile PXLANG. Useful when working on the compiler.
47 //#define ALWAYS_RECOMPILE_PXLANG
48 
49 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
50 
51 #define __VA_NARGS_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
52 #define __EXPAND(x) x
53 #define __VA_NARGS(...) __EXPAND(__VA_NARGS_IMPL(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1))
54 #define _LOC(x, ...) x
55 #define LOCALE_STATIC
56 #define USE_LOCALE_NAME_AS_DEFAULT NULL
57 
58 // Buffer info
59 #define UseGlobalLocaleBuffer(x) CSM_PxLang_GetGlobalBuffer(x), -1
60 #define UseStaticLocaleBuffer(BUFFER) BUFFER, sizeof(BUFFER)
61 #define UseDynamicLocaleBuffer(BUFFER, BUFFERSIZE) BUFFER, BUFFERSIZE
62 
63 // Localization Macros
64 #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__)
65 #define GetLocaleStringA(LOCALE_NAME, DEFAULT_STRING) CSM_PxLang_GetString(LOCALE_NAME, NULL, -1, DEFAULT_STRING, NULL, NULL, 0)
66 
67 // Safe copy macros
68 // Use USE_BUFFER_FOR_LOCALE or USE_GLOBAL_LOCALE_BUFFER for BUFFERINFO.
69 #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__)
70 #define CopyLocaleStringA(BUFFERINFO, LOCALE_NAME, DEFAULT_STRING) CSM_PxLang_GetString(LOCALE_NAME, BUFFERINFO, DEFAULT_STRING, NULL, NULL, 0)
71 
75 #define BuildLocaleString(STRING) CSM_PxLang_BuildFormat(STRING)
76 #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))
77 #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))
78 #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))
79 #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))
80 
81 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
82 
86 {
87  PXLANG_TYPE_STRING = 0,
88  PXLANG_TYPE_INT = 1
89 };
90 
94 {
95  PXLANG_SYMBOL_TYPE_GROUP = 0,
96  PXLANG_SYMBOL_TYPE_STRING = 1,
97 
98  MAX_PXLANG_SYMBOL_COUNT
99 };
100 
101 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
102 
106 {
110 
113  unsigned int crc;
114 
117  char* name;
118 
121  int line;
122 };
123 
127 {
130  unsigned int crc;
131 
134  wchar_t* content;
135 
139 
142  int symbol;
143 
147 };
148 
152 {
155  unsigned int crc;
156 
159  unsigned int string_size;
160 
163  unsigned int string_count;
164 
168 
171  bool loaded;
172 
175  int symbol;
176 };
177 
181 {
182  // Internal ------------------------------------------------
183 
187  unsigned int valid_crc;
188 
189  // Metadata ------------------------------------------------
190 
193  char* path_name;
194 
197  unsigned int font_width;
198 
201  unsigned int font_height;
202 
205  unsigned int file_crc;
206 
209  char* file_name;
210 
213  char* font_name;
214 
215  // Resource configuration ----------------------------------
216 
220 
224 
228 
231  unsigned int selected_group_crc;
232 
235  unsigned int group_count;
236 
240 
243  unsigned int string_table_size;
244 
247  wchar_t** string_table;
248 
251  bool hidden;
252 
255  unsigned char char_travel;
256 
257  // Linkage -------------------------------------------------
258 
262 
266 
270 
271  // Debug ---------------------------------------------------
272 
275  unsigned int symbol_count;
276 
280 };
281 
282 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
283 
287 
288 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
289 
297 (
298  const char* pFileName,
299  bool bForceDebugSymbols = false
300 );
301 
302 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
303 
316 (
317  PXLANG_RESOURCE_STRUCT* pLangObj,
318  const char* pFileName,
319  const char* pGroupName = NULL,
320  bool bRecompile = true,
321  bool bForceDebugSymbols = false
322 );
323 
330 (
331  PXLANG_RESOURCE_STRUCT* pLangObj
332 );
333 
334 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
335 
342 (
343  PXLANG_RESOURCE_STRUCT* pLangObj
344 );
345 
353 (
354  const char* pStringName,
355  PXLANG_RESOURCE_STRUCT* pLangObj = NULL
356 );
357 
369 (
370  const char* pStringName,
371  char* pBuffer = NULL,
372  int iBufferSize = -1,
373  const char* pDefaultValue = NULL,
374  PXLANG_RESOURCE_STRUCT* pLangObj = NULL,
375  const char* pArgFormat = NULL,
376  int iArgCount = 0,
377  ...
378 );
379 
387 (
388  unsigned int iBufferID
389 );
390 
399 (
400  PXLANG_RESOURCE_STRUCT* pLangObj
401 );
402 
403 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
404 
414 (
415  const char* pLanguageName,
416  bool bUseData = false
417 );
418 
424 (
425  const char* pGroupName,
426  PXLANG_RESOURCE_STRUCT* pLangObj = NULL
427 );
428 
435 (
436  const char* pFormat
437 );
438 
439 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
440 
441 #include <CSMAPI_endcode.h>
442 
444 ///
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.
CAVESTORY_MOD_API bool CSM_PxLang_LoadDebugSymbols(PXLANG_RESOURCE_STRUCT *pLangObj)
Load debug symbols for a PxLang object.
CAVESTORY_MOD_API char * CSM_PxLang_GetGlobalBuffer(unsigned int iBufferID)
Get a global PxLang buffer.
CAVESTORY_MOD_API BOOL CSM_PxLang_SetCurrentLocalization(const char *pLanguageName, bool bUseData=false)
Set the current localization object.
CAVESTORY_MOD_API void CSM_PxLang_SetGroup(const char *pGroupName, PXLANG_RESOURCE_STRUCT *pLangObj=NULL)
Set the current localization object.
PXLANG_SymbolType
Type of debug symbol for pxlang symbol file.
Definition: LanguageResource.h:94
CAVESTORY_MOD_API BOOL CSM_PxLang_IsLoaded(PXLANG_RESOURCE_STRUCT *pLangObj)
Check to see if a language object is loaded.
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.
CAVESTORY_MOD_API PXLANG_RESOURCE_STRUCT gCurrentLocalization
This global variable holds the currently loaded localization file.
CAVESTORY_MOD_API const char * CSM_PxLang_BuildFormat(const char *pFormat)
Build an argumentitive string.
CAVESTORY_MOD_API BOOL CSM_PxLang_Free(PXLANG_RESOURCE_STRUCT *pLangObj)
Free up a language resource object.
CAVESTORY_MOD_API int CSM_PxLang_Compile(const char *pFileName, bool bForceDebugSymbols=false)
Compile a language resource file.
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.
PXLANG_ArgType
Argument types for compiled pxlang files.
Definition: LanguageResource.h:86
#define CAVESTORY_MOD_API
Exports / imports Cavestory Mod API functions & classes.
Definition: CSMAPI_begincode.h:30
Holds information about a specific debug symbol.
Definition: LanguageResource.h:106
int line
The line number for this symbol.
Definition: LanguageResource.h:121
PXLANG_SymbolType type
The type of symbol this is.
Definition: LanguageResource.h:109
char * name
The actual name of this localization string.
Definition: LanguageResource.h:117
unsigned int crc
The CRC checksum of the name for this localization string.
Definition: LanguageResource.h:113
Holds information about a localization group.
Definition: LanguageResource.h:152
int symbol
The debug symbol assigned to this string.
Definition: LanguageResource.h:175
unsigned int string_count
The amount of loaded strings in this group.
Definition: LanguageResource.h:163
unsigned int crc
The CRC checksum of this group's name.
Definition: LanguageResource.h:155
bool loaded
Whether this group's strings are loaded or not.
Definition: LanguageResource.h:171
unsigned int string_size
The amount of localized strings in this group.
Definition: LanguageResource.h:159
PXLANG_STRING_STRUCT * string_list
The string list.
Definition: LanguageResource.h:167
Holds information for a compiled pixel language file (.pxclang).
Definition: LanguageResource.h:181
unsigned int font_height
This localization resource's desired font height.
Definition: LanguageResource.h:201
PXLANG_RESOURCE_STRUCT * prev
The previous language resource.
Definition: LanguageResource.h:269
unsigned char char_travel
Used to compare against the uncompiled file's CRC, and if they are different, then it will be re-comp...
Definition: LanguageResource.h:255
unsigned int selected_group_crc
The selected group CRC.
Definition: LanguageResource.h:231
char * file_name
The file name of this resource.
Definition: LanguageResource.h:209
char * font_name
The font name of this resource.
Definition: LanguageResource.h:213
unsigned int symbol_count
The amount of symbols.
Definition: LanguageResource.h:275
unsigned int file_crc
Used to compare against the uncompiled file's CRC, and if they are different, then it will be re-comp...
Definition: LanguageResource.h:205
PXLANG_GROUP_STRUCT * group_list
The group list.
Definition: LanguageResource.h:239
int encoding_type
The encoding type.
Definition: LanguageResource.h:219
wchar_t ** string_table
The string list.
Definition: LanguageResource.h:247
char * display_name
The display name of this localization file.
Definition: LanguageResource.h:227
unsigned int font_width
This localization resource's desired font width.
Definition: LanguageResource.h:197
PXLANG_DEBUG_SYMBOL_STRUCT * symbol_list
The string list.
Definition: LanguageResource.h:279
bool hidden
Whether this resource is hidden or not.
Definition: LanguageResource.h:251
int charset_type
The charset type.
Definition: LanguageResource.h:223
static PXLANG_RESOURCE_STRUCT * first
The first language resource.
Definition: LanguageResource.h:261
unsigned int string_table_size
The amount of localized strings.
Definition: LanguageResource.h:243
char * path_name
The path name of this resource.
Definition: LanguageResource.h:193
PXLANG_RESOURCE_STRUCT * next
The next language resource.
Definition: LanguageResource.h:265
unsigned int group_count
The amount of groups in this resource.
Definition: LanguageResource.h:235
Holds information about a specific localization string.
Definition: LanguageResource.h:127
unsigned int crc
The CRC checksum of the name for this localization string.
Definition: LanguageResource.h:130
int symbol
The debug symbol assigned to this string.
Definition: LanguageResource.h:142
bool special_content
The debug symbol assigned to this string.
Definition: LanguageResource.h:146
wchar_t * content
The content of this string.
Definition: LanguageResource.h:134
char * content_ascii
The ASCII content of this string.
Definition: LanguageResource.h:138