From 0251cf7679e33aee48bc88d83567bc4e85b4e9e7 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 14 Aug 2014 19:27:13 +0100 Subject: [PATCH] Added comments capability to language.txt. Now reads string number --- data/language/english.txt | 5 +++++ src/string_ids.c | 28 ++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/data/language/english.txt b/data/language/english.txt index 61b3873735..86cf22e001 100644 --- a/data/language/english.txt +++ b/data/language/english.txt @@ -1,3 +1,6 @@ +# STR_XXXX part is read and XXXX becomes the string id number. +# Everything after the colon and before the new line will be saved as the string. +# Use # at the beginning of a line to leave a comment. STR_0000 : STR_0001 :{STRINGID} {COMMA16} STR_0002 :Ride @@ -2758,6 +2761,7 @@ STR_2756 :??? STR_2757 :??? STR_2758 :??? STR_2759 :??? +# New strings used in the cheats window previously these were ??? STR_2760 :+5K Money STR_2761 :Pay For Entrance STR_2762 :Pay For Rides @@ -2771,6 +2775,7 @@ STR_2769 :Open Park STR_2770 :Close Park STR_2771 :Slower Gamespeed STR_2772 :Faster Gamespeed +# End of new strings STR_2773 :??? STR_2774 :??? STR_2775 :??? diff --git a/src/string_ids.c b/src/string_ids.c index 9fafdc888b..40da3f789c 100644 --- a/src/string_ids.c +++ b/src/string_ids.c @@ -1720,8 +1720,9 @@ const char *get_string(rct_string_id id) * read / write strings in some way is decompiled. The original game used a DIY extended 8-bit extended ASCII set for special * characters, format codes and accents. * - * In terms of reading the language files, the STR_XXXX part is completely ignored at the moment. It just parses each line from - * the colon and thus not allowing gaps in the string indices. + * In terms of reading the language files, the STR_XXXX part is read and XXXX becomes the string id number. Everything after the + * colon and before the new line will be saved as the string. Tokens are written with inside curly braces {TOKEN}. + * Use # at the beginning of a line to leave a comment. */ int language_open(const char *filename) { @@ -1740,18 +1741,29 @@ int language_open(const char *filename) char *dst, *token; char tokenBuffer[64]; - int i, stringIndex = 0, mode = 0; + int i, stringIndex = 0, mode = 0, string_no; for (i = 0; i < language_buffer_size; i++) { char *src = &language_buffer[i]; switch (mode) { case 0: - // Search for colon - if (*src == ':') { + // Search for a comment + if (*src == '#'){ + mode = 3; + } + else if (*src == ':' && string_no != -1) { + // Search for colon dst = src + 1; - language_strings[stringIndex++] = dst; + language_strings[string_no] = dst; + stringIndex++; mode = 1; } + else if (!strncmp(src, "STR_", 4)){ + // Copy in the string number + if (sscanf(src, "STR_%d", &string_no) != 1){ + string_no = -1; + } + } break; case 1: // Copy string over, stop at line break @@ -1778,6 +1790,10 @@ int language_open(const char *filename) mode = 1; } break; + case 3: + if (*src == '\n' || *src == '\r'){ + mode = 0; + } } } language_num_strings = stringIndex;