Added multilanguage support & removed skybox tiles

This commit is contained in:
NoHomoBoi 2020-08-22 20:54:13 -05:00
parent 1ad8751eeb
commit 757cc51dde
13 changed files with 9851 additions and 93 deletions

View File

@ -223,7 +223,7 @@ LEVEL_DIRS := $(patsubst levels/%,%,$(dir $(wildcard levels/*/header.h)))
# Directories containing source files
# Hi, I'm a PC
SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels bin data assets src/pc src/pc/gfx src/pc/audio src/pc/controller src/pc/fs src/pc/fs/packtypes
SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels bin data assets src/text src/text/libs src/pc src/pc/gfx src/pc/audio src/pc/controller src/pc/fs src/pc/fs/packtypes
ifeq ($(DISCORDRPC),1)
SRC_DIRS += src/pc/discord
@ -607,6 +607,7 @@ $(BASEPACK_LST): $(EXE)
@find actors -name \*.png -exec echo "{} gfx/{}" >> $(BASEPACK_LST) \;
@find levels -name \*.png -exec echo "{} gfx/{}" >> $(BASEPACK_LST) \;
@find textures -name \*.png -exec echo "{} gfx/{}" >> $(BASEPACK_LST) \;
@find texts -name \*.json -exec echo "{} {}" >> $(BASEPACK_LST) \;
# prepares the resource ZIP with base data
$(BASEPACK_PATH): $(BASEPACK_LST)

View File

@ -31,6 +31,8 @@
#include "options_menu.h"
#endif
#include "text/text-loader.h"
u16 gDialogColorFadeTimer;
s8 gLastDialogLineNum;
s32 gDialogVariable;
@ -1691,31 +1693,10 @@ s8 gDialogCourseActNum = 1;
#endif
void render_dialog_entries(void) {
#ifdef VERSION_EU
s8 lowerBound;
#endif
void **dialogTable;
struct DialogEntry * dialog;
#ifdef VERSION_US
dialog = segmented_to_virtual(dialogPool[gDialogID]);
s8 lowerBound;
#endif
#ifdef VERSION_EU
gInGameLanguage = eu_get_language();
switch (gInGameLanguage) {
case LANGUAGE_ENGLISH:
dialogTable = segmented_to_virtual(dialog_table_eu_en);
break;
case LANGUAGE_FRENCH:
dialogTable = segmented_to_virtual(dialog_table_eu_fr);
break;
case LANGUAGE_GERMAN:
dialogTable = segmented_to_virtual(dialog_table_eu_de);
break;
}
#else
dialogTable = segmented_to_virtual(seg2_dialog_table);
#endif
dialog = segmented_to_virtual(dialogTable[gDialogID]);
// if the dialog entry is invalid, set the ID to -1.
if (segmented_to_virtual(NULL) == dialog) {
@ -2010,26 +1991,9 @@ void do_cutscene_handler(void) {
// "Dear Mario" message handler
void print_peach_letter_message(void) {
void **dialogTable;
struct DialogEntry *dialog;
u8 *str;
#ifdef VERSION_EU
gInGameLanguage = eu_get_language();
switch (gInGameLanguage) {
case LANGUAGE_ENGLISH:
dialogTable = segmented_to_virtual(dialog_table_eu_en);
break;
case LANGUAGE_FRENCH:
dialogTable = segmented_to_virtual(dialog_table_eu_fr);
break;
case LANGUAGE_GERMAN:
dialogTable = segmented_to_virtual(dialog_table_eu_de);
break;
}
#else
dialogTable = segmented_to_virtual(seg2_dialog_table);
#endif
dialog = segmented_to_virtual(dialogTable[gDialogID]);
dialog = segmented_to_virtual(dialogPool[gDialogID]);
str = segmented_to_virtual(dialog->str);
@ -2042,15 +2006,10 @@ void print_peach_letter_message(void) {
gDPSetEnvColor(gDisplayListHead++, 20, 20, 20, gCutsceneMsgFade);
print_generic_string(STR_X, STR_Y, str);
#if defined(VERSION_JP) || defined(VERSION_SH)
gSPDisplayList(gDisplayListHead++, dl_ia_text_end);
#endif
gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 255);
#ifndef VERSION_JP
gSPDisplayList(gDisplayListHead++, dl_ia_text_end);
gDPSetEnvColor(gDisplayListHead++, 200, 80, 120, gCutsceneMsgFade);
gSPDisplayList(gDisplayListHead++, castle_grounds_seg7_us_dl_0700F2E8);
#endif
// at the start/end of message, reset the fade.
if (gCutsceneMsgTimer == 0) {

View File

@ -60,30 +60,17 @@ struct Skybox {
struct Skybox sSkyBoxInfo[2];
typedef const u8 *const SkyboxTexture[80];
extern SkyboxTexture bbh_skybox_ptrlist;
extern SkyboxTexture bidw_skybox_ptrlist;
extern SkyboxTexture bitfs_skybox_ptrlist;
extern SkyboxTexture bits_skybox_ptrlist;
extern SkyboxTexture ccm_skybox_ptrlist;
extern SkyboxTexture cloud_floor_skybox_ptrlist;
extern SkyboxTexture clouds_skybox_ptrlist;
extern SkyboxTexture ssl_skybox_ptrlist;
extern SkyboxTexture water_skybox_ptrlist;
extern SkyboxTexture wdw_skybox_ptrlist;
SkyboxTexture *sSkyboxTextures[10] = {
&water_skybox_ptrlist,
&bitfs_skybox_ptrlist,
&wdw_skybox_ptrlist,
&cloud_floor_skybox_ptrlist,
&ccm_skybox_ptrlist,
&ssl_skybox_ptrlist,
&bbh_skybox_ptrlist,
&bidw_skybox_ptrlist,
&clouds_skybox_ptrlist,
&bits_skybox_ptrlist,
char * sSkyboxTextures[10] = {
"textures/skyboxes/water",
"textures/skyboxes/bitfs",
"textures/skyboxes/wdw",
"textures/skyboxes/cloud_floor",
"textures/skyboxes/ccm",
"textures/skyboxes/ssl",
"textures/skyboxes/bbh",
"textures/skyboxes/bidw",
"textures/skyboxes/clouds",
"textures/skyboxes/bits",
};
/**
@ -98,31 +85,31 @@ u8 sSkyboxColors[][3] = {
/**
* Constant used to scale the skybox horizontally to a multiple of the screen's width
*/
#define SKYBOX_WIDTH (4 * SCREEN_WIDTH)
#define SKYBOX_WIDTH (2 * SCREEN_WIDTH)
/**
* Constant used to scale the skybox vertically to a multiple of the screen's height
*/
#define SKYBOX_HEIGHT (4 * SCREEN_HEIGHT)
#define SKYBOX_HEIGHT (2 * SCREEN_HEIGHT)
/**
* The tile's width in world space.
* By default, two full tiles can fit in the screen.
*/
#define SKYBOX_TILE_WIDTH (SCREEN_WIDTH / 2)
#define SKYBOX_TILE_WIDTH SKYBOX_WIDTH
/**
* The tile's height in world space.
* By default, two full tiles can fit in the screen.
*/
#define SKYBOX_TILE_HEIGHT (SCREEN_HEIGHT / 2)
#define SKYBOX_TILE_HEIGHT SKYBOX_HEIGHT
/**
* The horizontal length of the skybox tilemap in tiles.
*/
#define SKYBOX_COLS (10)
#define SKYBOX_COLS 1
/**
* The vertical length of the skybox tilemap in tiles.
*/
#define SKYBOX_ROWS (8)
#define SKYBOX_ROWS 1
/**
@ -144,7 +131,7 @@ f32 calculate_skybox_scaled_x(s8 player, f32 fov) {
if (scaledX > SKYBOX_WIDTH) {
scaledX -= (s32) scaledX / SKYBOX_WIDTH * SKYBOX_WIDTH;
}
return SKYBOX_WIDTH - scaledX;
return 0;
}
/**
@ -162,7 +149,7 @@ f32 calculate_skybox_scaled_y(s8 player, UNUSED f32 fov) {
// Since pitch can be negative, and the tile grid starts 1 octant above the camera's focus, add
// 5 octants to the y position
f32 scaledY = degreesToScale + 5 * SKYBOX_TILE_HEIGHT;
f32 scaledY = degreesToScale + 5 * SKYBOX_TILE_HEIGHT / 4;
if (scaledY > SKYBOX_HEIGHT) {
scaledY = SKYBOX_HEIGHT;
@ -180,7 +167,7 @@ static int get_top_left_tile_idx(s8 player) {
s32 tileCol = sSkyBoxInfo[player].scaledX / SKYBOX_TILE_WIDTH;
s32 tileRow = (SKYBOX_HEIGHT - sSkyBoxInfo[player].scaledY) / SKYBOX_TILE_HEIGHT;
return tileRow * SKYBOX_COLS + tileCol;
return 0;
}
/**
@ -218,19 +205,13 @@ void draw_skybox_tile_grid(Gfx **dlist, s8 background, s8 player, s8 colorIndex)
s32 row;
s32 col;
for (row = 0; row < 3; row++) {
for (col = 0; col < 3; col++) {
s32 tileIndex = sSkyBoxInfo[player].upperLeftTile + row * SKYBOX_COLS + col;
const u8 *const texture =
(*(SkyboxTexture *) segmented_to_virtual(sSkyboxTextures[background]))[tileIndex];
Vtx *vertices = make_skybox_rect(tileIndex, colorIndex);
const u8 *const texture = sSkyboxTextures[background];
Vtx *vertices = make_skybox_rect(0, colorIndex);
gLoadBlockTexture((*dlist)++, 32, 32, G_IM_FMT_RGBA, texture);
gSPVertex((*dlist)++, VIRTUAL_TO_PHYSICAL(vertices), 4, 0);
gSPDisplayList((*dlist)++, dl_draw_quad_verts_0123);
}
}
}
void *create_skybox_ortho_matrix(s8 player) {
f32 left = sSkyBoxInfo[player].scaledX;

View File

@ -39,6 +39,8 @@
#include "pc/discord/discordrpc.h"
#endif
#include "text/text-loader.h"
OSMesg D_80339BEC;
OSMesgQueue gSIEventMesgQueue;
@ -179,7 +181,7 @@ void main_func(void) {
const char *gamedir = gCLIOpts.GameDir[0] ? gCLIOpts.GameDir : FS_BASEDIR;
const char *userpath = gCLIOpts.SavePath[0] ? gCLIOpts.SavePath : sys_user_path();
fs_init(sys_ropaths, gamedir, userpath);
alloc_dialog_pool();
configfile_load(configfile_name());
if (gCLIOpts.FullScreen == 1)

3096
src/text/libs/cJSON.c Normal file

File diff suppressed because it is too large Load Diff

293
src/text/libs/cJSON.h Normal file
View File

@ -0,0 +1,293 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef cJSON__h
#define cJSON__h
#ifdef __cplusplus
extern "C"
{
#endif
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
#if defined(CJSON_HIDE_SYMBOLS)
#define CJSON_PUBLIC(type) type CJSON_STDCALL
#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
#elif defined(CJSON_IMPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
#endif
#else /* !__WINDOWS__ */
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
#endif
#endif
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 13
#include <stddef.h>
/* cJSON Types: */
#define cJSON_Invalid (0)
#define cJSON_False (1 << 0)
#define cJSON_True (1 << 1)
#define cJSON_NULL (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7) /* raw json */
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
/* The type of the item, as above. */
int type;
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
typedef struct cJSON_Hooks
{
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
/* returns the version of cJSON as a string */
CJSON_PUBLIC(const char*) cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check item type and return its value */
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
/* These functions check the type of an item */
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
/* These calls create a cJSON item of the appropriate type. */
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
/* raw json */
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
/* Create a string where valuestring references a string so
* it will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
/* Create an object/array that only references it's elements so
* they will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
* but should point to a readable and writable adress area. */
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
#ifdef __cplusplus
}
#endif
#endif

97
src/text/text-loader.c Normal file
View File

@ -0,0 +1,97 @@
#include "text-loader.h"
#include "txtconv.h"
#include "libs/cJSON.h"
#include <stdio.h>
#include <string.h>
#include "dialog_ids.h"
#include "game/ingame_menu.h"
struct DialogEntry* * dialogPool;
char* load_file(char const* path) {
char* buffer = 0;
long length = 0;
FILE * f = fopen (path, "rb");
if (f) {
fseek (f, 0, SEEK_END);
length = ftell (f);
fseek (f, 0, SEEK_SET);
buffer = (char*) malloc((length+1)*sizeof(char));
if (buffer) {
fread(buffer, sizeof(char), length, f);
}
fclose(f);
}
buffer[length] = '\0';
return buffer;
}
void preloadTexts(){
char * jsonTxt = load_file("res/texts/es.json");
cJSON *json = cJSON_Parse(jsonTxt);
if (json == NULL) {
const char *error_ptr = cJSON_GetErrorPtr();
if (error_ptr != NULL)
{
fprintf(stderr, "Error before: %s\n", error_ptr);
}
exit(1);
}
const cJSON *dialog = NULL;
const cJSON *dialogs = NULL;
dialogs = cJSON_GetObjectItemCaseSensitive(json, "dialogs");
cJSON_ArrayForEach(dialog, dialogs) {
int id = cJSON_GetObjectItemCaseSensitive(dialog, "ID")->valueint;
struct DialogEntry *entry = malloc (sizeof (struct DialogEntry));
entry->unused = 1;
entry->linesPerBox = cJSON_GetObjectItemCaseSensitive(dialog, "linesPerBox")->valueint;
entry->leftOffset = cJSON_GetObjectItemCaseSensitive(dialog, "leftOffset")->valueint;
entry->width = cJSON_GetObjectItemCaseSensitive(dialog, "width")->valueint;
const cJSON *line = NULL;
const cJSON *lines = NULL;
lines = cJSON_GetObjectItemCaseSensitive(dialog, "lines");
int lineAmount = cJSON_GetArraySize(lines);
int dialogSize = lineAmount * 45;
char* dialogTxt = malloc(dialogSize * sizeof(char));
strcpy(dialogTxt, "");
int currLine = 0;
cJSON_ArrayForEach(line, lines) {
char * str = line->valuestring;
strcat(dialogTxt, str);
if(currLine < lineAmount - 1) {
strcat(dialogTxt, "\n");
currLine++;
}
}
entry->str = getTranslatedText(dialogTxt);
free(dialogTxt);
dialogPool[id] = entry;
}
free(jsonTxt);
}
void alloc_dialog_pool(void){
dialogPool = malloc(DIALOG_COUNT * sizeof(struct DialogEntry));
for(int i = 0; i < DIALOG_COUNT; i++){
struct DialogEntry *entry = malloc (sizeof (struct DialogEntry));
entry->unused = 1;
entry->linesPerBox = 6;
entry->leftOffset = 95;
entry->width = 200;
entry->str = getTranslatedText("You are not supposed\nto be here.\n\nKeep this as a secret\n\n- Render96 Team");
dialogPool[i] = entry;
}
preloadTexts();
}

9
src/text/text-loader.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef TXTLOADER
#define TXTLOADER
#include "types.h"
extern struct DialogEntry ** dialogPool;
extern void alloc_dialog_pool(void);
#endif

95
src/text/txtconv.c Normal file
View File

@ -0,0 +1,95 @@
#include "txtconv.h"
struct Character charmap[340] = {
{"0", 0x00}, {"", 0x00}, {"1", 0x01}, {"", 0x01}, {"2", 0x02}, {"", 0x02}, {"3", 0x03}, {"", 0x03}, {"4", 0x04},
{"", 0x04}, {"5", 0x05}, {"", 0x05}, {"6", 0x06}, {"", 0x06}, {"7", 0x07}, {"", 0x07}, {"8", 0x08}, {"", 0x08},
{"9", 0x09}, {"", 0x09}, {"A", 0x0A}, {"", 0x0A}, {"B", 0x0B}, {"", 0x0B}, {"C", 0x0C}, {"", 0x0C}, {"D", 0x0D},
{"", 0x0D}, {"E", 0x0E}, {"", 0x0E}, {"F", 0x0F}, {"", 0x0F}, {"G", 0x10}, {"", 0x10}, {"H", 0x11}, {"", 0x11},
{"I", 0x12}, {"", 0x12}, {"J", 0x13}, {"", 0x13}, {"K", 0x14}, {"", 0x14}, {"L", 0x15}, {"", 0x15}, {"M", 0x16},
{"", 0x16}, {"N", 0x17}, {"", 0x17}, {"O", 0x18}, {"", 0x18}, {"P", 0x19}, {"", 0x19}, {"Q", 0x1A}, {"", 0x1A},
{"R", 0x1B}, {"", 0x1B}, {"S", 0x1C}, {"", 0x1C}, {"T", 0x1D}, {"", 0x1D}, {"U", 0x1E}, {"", 0x1E}, {"V", 0x1F},
{"", 0x1F}, {"W", 0x20}, {"", 0x20}, {"X", 0x21}, {"", 0x21}, {"Y", 0x22}, {"", 0x22}, {"Z", 0x23}, {"", 0x23},
{"a", 0x24}, {"b", 0x25}, {"c", 0x26}, {"d", 0x27}, {"e", 0x28}, {"f", 0x29}, {"g", 0x2A}, {"h", 0x2B}, {"i", 0x2C},
{"j", 0x2D}, {"k", 0x2E}, {"l", 0x2F}, {"m", 0x30}, {"n", 0x31}, {"o", 0x32}, {"p", 0x33}, {"q", 0x34}, {"r", 0x35},
{"s", 0x36}, {"t", 0x37}, {"u", 0x38}, {"v", 0x39}, {"w", 0x3A}, {"x", 0x3B}, {"y", 0x3C}, {"z", 0x3D}, {"\\", 0x3E},
{".", 0x3F}, {"", 0x41}, {"", 0x40}, {"", 0x41}, {"", 0x42}, {"", 0x43}, {"", 0x44}, {"", 0x45}, {"", 0x46},
{"", 0x47}, {"", 0x48}, {"", 0x49}, {"", 0x4A}, {"", 0x4B}, {"", 0x4C}, {"", 0x4D}, {"", 0x4E}, {"", 0x4F},
{"", 0x50}, {"", 0x51}, {"", 0x52}, {"", 0x53}, {"", 0x54}, {"", 0x55}, {"", 0x56}, {"", 0x57}, {"", 0x58},
{"", 0x59}, {"", 0x5A}, {"", 0x5B}, {"", 0x5C}, {"", 0x5D}, {"", 0x5E}, {"", 0x5F}, {"", 0x60}, {"", 0x61},
{"", 0x62}, {"", 0x63}, {"", 0x64}, {"", 0x65}, {"", 0x66}, {"", 0x67}, {"", 0x68}, {"", 0x69}, {"", 0x6A},
{"", 0x6B}, {"", 0x6C}, {"", 0x6D}, {"", 0x6E}, {",", 0x6F}, {"", 0x6F}, {"", 0x70}, {"", 0x71}, {"", 0x72},
{"", 0x73}, {"", 0x74}, {"", 0x75}, {"", 0x76}, {"", 0x77}, {"", 0x78}, {"", 0x79}, {"", 0x7A}, {"", 0x7B},
{"", 0x7C}, {"", 0x7D}, {"", 0x7E}, {"", 0x7F}, {"", 0x80}, {"", 0x81}, {"", 0x82}, {"", 0x83}, {"", 0x84},
{"", 0x85}, {"", 0x86}, {"", 0x87}, {"", 0x88}, {"", 0x89}, {"", 0x8A}, {"", 0x8B}, {"", 0x8C}, {"", 0x8D},
{"", 0x8E}, {"", 0x8F}, {"", 0x90}, {"", 0x91}, {"", 0x92}, {"", 0x93}, {"", 0x94}, {"", 0x95}, {"", 0x96},
{"", 0x97}, {"", 0x98}, {"", 0x99}, {"", 0x9A}, {"", 0x9B}, {"", 0x9C}, {"", 0x9D}, {" ", 0x9E}, {" ", 0x9E},
{"-", 0x9F}, {"", 0x9F}, {"", 0xA0}, {"", 0xA1}, {"", 0xA2}, {"", 0xA3}, {"", 0xA4}, {"", 0xA5}, {"", 0xA6},
{"", 0xA7}, {"", 0xA8}, {"", 0xD0}, {"", 0xD1}, {"", 0xD2}, {"", 0xD3}, {"", 0xD4}, {"", 0xD5}, {"", 0xD6},
{"", 0xD7}, {"", 0xD8}, {"[%]", 0xE0}, {"(", 0xE1}, {"", 0xE1}, {")(", 0xE2}, {"", 0xE2}, {")", 0xE3}, {"", 0xE3},
{"+", 0xE4}, {"", 0xE4}, {"&", 0xE5}, {":", 0xE6}, {"", 0xF0}, {"", 0xF1}, {"!", 0xF2}, {"", 0xF2}, {"%", 0xF3},
{"", 0xF3}, {"?", 0xF4}, {"", 0xF4}, {"", 0xF5}, {"", 0xF6}, {"~", 0xF7}, {"", 0xF7}, {"", 0xF8}, {"$", 0xF9},
{"", 0xFA}, {"×", 0xFB}, {"", 0xFC}, {"", 0xFD}, {"\n", 0xFE}, {"", 0x45}, {"", 0x46}, {"", 0x47}, {"", 0x48},
{"", 0x49}, {"", 0x4A}, {"", 0x4B}, {"", 0x4C}, {"", 0x4D}, {"", 0x4E}, {"", 0x4F}, {"", 0x50}, {"", 0x51},
{"", 0x52}, {"", 0x53}, {"", 0x59}, {"", 0x5A}, {"", 0x5B}, {"", 0x5C}, {"", 0x5D}, {"", 0x75}, {"", 0x76},
{"", 0x77}, {"", 0x78}, {"", 0x79}, {"", 0x7A}, {"", 0x7B}, {"", 0x7C}, {"", 0x7D}, {"", 0x7E}, {"", 0x7F},
{"", 0x80}, {"", 0x81}, {"", 0x82}, {"", 0x83}, {"", 0x89}, {"", 0x8A}, {"", 0x8B}, {"", 0x8C}, {"", 0x8D},
{"", 0x59}, {"", 0x5A}, {"", 0x5B}, {"", 0x5C}, {"", 0x5D}, {"", 0x89}, {"", 0x8A}, {"", 0x8B}, {"", 0x8C},
{"", 0x8D}, {"^", 0x50}, {"|", 0x51}, {"<", 0x52}, {">", 0x53}, {"[A]", 0x54}, {"[B]", 0x55}, {"[C]", 0x56}, {"[Z]", 0x57},
{"[R]", 0x58}, {"/", 0xD0}, {"the", 0xD1}, {"you", 0xD2}, {"à", 0x60}, {"â", 0x61}, {"ä", 0x62}, {"À", 0x64}, {"Â", 0x65},
{"Ä", 0x66}, {"è", 0x70}, {"ê", 0x71}, {"ë", 0x72}, {"é", 0x73}, {"È", 0x74}, {"Ê", 0x75}, {"Ë", 0x76}, {"É", 0x77},
{"ù", 0x80}, {"û", 0x81}, {"ü", 0x82}, {"Ù", 0x84}, {"Û", 0x85}, {"Ü", 0x86}, {"ô", 0x91}, {"ö", 0x92}, {"Ô", 0x95},
{"Ö", 0x96}, {"î", 0xA1}, {"ï", 0xA2}, {"ß", 0xEC}, {"Ç", 0xED}, {"ç", 0xEE}, {"", 0xF0}
};
struct Character getCharacter(char* ch){
struct Character tmp = {NULL, 0};
for(s32 cmid = 0; cmid < 340; cmid++){
if(strcmp(charmap[cmid].txt, ch) == 0) {
tmp = charmap[cmid];
break;
}
}
return tmp;
}
u8 * getTranslatedText(char * txt){
s32 cid;
s32 strSize = strlen(txt);
u8 * tmp = malloc((strSize + 1) * sizeof(u8));
u8 icon = FALSE;
s32 shiftArr = 0;
char tmpId = 0;
char tmpIcon[3];
s32 ignoreUntil = 0;
for(cid = 0; cid < strSize; cid++){
char ch = txt[cid];
if(ch == '['){
tmpIcon[0] = ch;
tmpIcon[1] = txt[cid + 1];
tmpIcon[2] = txt[cid + 2];
struct Character ctm = getCharacter(tmpIcon);
if(ctm.value != NULL){
tmp[cid - shiftArr] = ctm.value;
shiftArr += 2;
cid += 2;
memset(tmpIcon, 0, sizeof(tmpIcon));
}
}else{
char findTxt[1] = {ch};
struct Character ctm = getCharacter(findTxt);
if(ctm.value != NULL){
tmp[cid - shiftArr] = ctm.value;
}else{
tmp[cid - shiftArr] = 0x9E;
}
}
}
tmp = realloc(tmp, (strSize - shiftArr + 1) * sizeof(u8));
tmp[strSize - shiftArr] = 0xFF;
return tmp;
}

15
src/text/txtconv.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef TXTDATA
#define TXTDATA
#include "types.h"
struct Character{
char * txt;
s32 value;
};
extern struct Character charmap[340];
u8 * getTranslatedText(char * txt);
#endif

3100
texts/es.json Normal file

File diff suppressed because it is too large Load Diff

3074
texts/us.json Normal file

File diff suppressed because it is too large Load Diff

36
tools/text2ascii.py Normal file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env python3
import sys
import os
import os.path
import glob
import re
from pathlib import Path
path = "/home/alex/Documents/Projects/Render96/Render96ex - FastBuild/charmap.txt"
lines = open(os.path.abspath(path), 'r').readlines()
lineID = {}
for lineIndex, uline in enumerate(lines, 0):
line = uline.strip()
if(line.startswith("'")):
unf = line.split(" = ")
char = unf[0].replace("'", "")
value = unf[1] if len(unf[1].split(", ")) < 2 else unf[1].split(", ")[1]
lineID[lineIndex] = "{"+f"\"{char}\", {value}"+"}, "
print(f"Array size: {len(lineID)}")
lines = 0
counter = 0
for b in lineID:
a = lineID[b]
print(a, end = '' if counter < 8 else '\n')
counter += 1
lines += 1
if counter > 8:
counter = 0
print('\n')
print(f' LINES {lines}\n')