mirror of https://github.com/OpenRCT2/OpenRCT2.git
prepare for loading a language file
This commit is contained in:
parent
96aaa87543
commit
13d95ded35
File diff suppressed because it is too large
Load Diff
|
@ -129,6 +129,12 @@
|
|||
<ItemGroup>
|
||||
<None Include="..\openrct2.exe" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\data\language\english.txt">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
</DeploymentContent>
|
||||
</Text>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{D24D94F6-2A74-480C-B512-629C306CE92F}</ProjectGuid>
|
||||
<RootNamespace>openrct2</RootNamespace>
|
||||
|
|
|
@ -16,6 +16,12 @@
|
|||
<Filter Include="Windows">
|
||||
<UniqueIdentifier>{611458dc-7dd2-4c37-af0f-306cf9d85fb9}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Data">
|
||||
<UniqueIdentifier>{ee2e3a6f-1209-407b-8000-a6a4b88d28d9}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Data\Language">
|
||||
<UniqueIdentifier>{b344ca0f-b412-4924-be08-54bb6f83c3dd}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\src\addresses.h">
|
||||
|
@ -350,4 +356,9 @@
|
|||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\data\language\english.txt">
|
||||
<Filter>Data\Language</Filter>
|
||||
</Text>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -49,6 +49,7 @@
|
|||
#include "track.h"
|
||||
#include "viewport.h"
|
||||
#include "sprite.h"
|
||||
#include "string_ids.h"
|
||||
|
||||
typedef struct tm tm_t;
|
||||
|
||||
|
@ -75,6 +76,9 @@ __declspec(dllexport) int StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInsta
|
|||
{
|
||||
print_launch_information();
|
||||
|
||||
// OpenRCT2 initialisation
|
||||
language_open("data/language/english.txt");
|
||||
|
||||
// Begin RCT2
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_HINSTANCE, HINSTANCE) = hInstance;
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_CMDLINE, LPSTR) = lpCmdLine;
|
||||
|
|
|
@ -1068,11 +1068,6 @@ char real_name_initials[] = {
|
|||
void format_string_part_from_raw(char **dest, const char *src, char **args);
|
||||
void format_string_part(char **dest, rct_string_id format, char **args);
|
||||
|
||||
const char *get_string(rct_string_id id)
|
||||
{
|
||||
return RCT2_ADDRESS(0x009BF2D4, const char*)[id];
|
||||
}
|
||||
|
||||
void format_integer(char **dest, int value)
|
||||
{
|
||||
int digit;
|
||||
|
@ -1661,3 +1656,73 @@ void reset_saved_strings() {
|
|||
RCT2_ADDRESS(0x135A8F4, uint8)[i * 32] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Buffer storing all the string data
|
||||
long language_buffer_size = 0;
|
||||
char *language_buffer = NULL;
|
||||
|
||||
// List of string pointers into the string data
|
||||
int language_num_strings = 0;
|
||||
char **language_strings = NULL;
|
||||
|
||||
const char *get_string(rct_string_id id)
|
||||
{
|
||||
const char *str = language_strings == NULL ?
|
||||
RCT2_ADDRESS(0x009BF2D4, const char*)[id] :
|
||||
language_strings[id];
|
||||
|
||||
return str == NULL ? "" : str;
|
||||
}
|
||||
|
||||
int language_open(const char *filename)
|
||||
{
|
||||
// WIP, file can be loaded in but not in a suitable state.
|
||||
// Due to loading an uncompiled text language file, tokens surrounded with braces need to be converted to the correct
|
||||
// format character code. Therefore the language can not stay in its raw form and must be re-written as the text file is
|
||||
// parsed.
|
||||
|
||||
// get_string returns the original game string address if no language is loaded in.
|
||||
return 0;
|
||||
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if (f == NULL)
|
||||
return 0;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
language_buffer_size = ftell(f);
|
||||
language_buffer = calloc(1, language_buffer_size);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
fread(language_buffer, language_buffer_size, 1, f);
|
||||
fclose(f);
|
||||
|
||||
language_strings = calloc(STR_COUNT, sizeof(char*));
|
||||
|
||||
int i, stringIndex = 0, searchForEndLine = 0;
|
||||
for (i = 0; i < language_buffer_size; i++) {
|
||||
char *c = &language_buffer[i];
|
||||
|
||||
if (searchForEndLine) {
|
||||
if (*c == '\n' || *c == '\r') {
|
||||
*c = 0;
|
||||
searchForEndLine = 0;
|
||||
}
|
||||
} else if (*c == ':') {
|
||||
language_strings[stringIndex++] = c + 1;
|
||||
searchForEndLine = 1;
|
||||
}
|
||||
}
|
||||
language_num_strings = stringIndex;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void language_close()
|
||||
{
|
||||
if (language_buffer != NULL)
|
||||
free(language_buffer);
|
||||
language_buffer_size = 0;
|
||||
|
||||
if (language_strings != NULL)
|
||||
free(language_strings);
|
||||
language_num_strings = 0;
|
||||
}
|
|
@ -28,6 +28,10 @@ void generate_string_file();
|
|||
void reset_saved_strings();
|
||||
void error_string_quit(int error, rct_string_id format);
|
||||
|
||||
const char *get_string(rct_string_id id);
|
||||
int language_open(const char *filename);
|
||||
void language_close();
|
||||
|
||||
enum {
|
||||
// Font format codes
|
||||
|
||||
|
@ -755,6 +759,8 @@ enum {
|
|||
STR_PAGE_3 = STR_PAGE_1 + 2,
|
||||
STR_PAGE_4 = STR_PAGE_1 + 3,
|
||||
STR_PAGE_5 = STR_PAGE_1 + 4,
|
||||
|
||||
STR_COUNT = 4000
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue