14 static char *GetSpecialTownNameString(char *buff, int ind); |
14 static char *GetSpecialTownNameString(char *buff, int ind); |
15 static char *GetSpecialPlayerNameString(char *buff, int ind); |
15 static char *GetSpecialPlayerNameString(char *buff, int ind); |
16 |
16 |
17 static char *DecodeString(char *buff, const char *str); |
17 static char *DecodeString(char *buff, const char *str); |
18 |
18 |
19 static char **_langpack_offs; |
|
20 static char *_langpack; |
|
21 static uint _langtab_num[32]; // Offset into langpack offs |
|
22 static uint _langtab_start[32]; // Offset into langpack offs |
|
23 |
|
24 extern const char _openttd_revision[]; |
19 extern const char _openttd_revision[]; |
25 |
20 |
26 typedef struct { |
21 typedef struct LanguagePack { |
27 uint32 ident; |
22 uint32 ident; |
28 uint32 version; // 32-bits of auto generated version info which is basically a hash of strings.h |
23 uint32 version; // 32-bits of auto generated version info which is basically a hash of strings.h |
29 char name[32]; // the international name of this language |
24 char name[32]; // the international name of this language |
30 char own_name[32]; // the localized name of this language |
25 char own_name[32]; // the localized name of this language |
31 uint16 offsets[32]; // the offsets |
26 uint16 offsets[32]; // the offsets |
32 } LanguagePackHeader; |
27 char data[VARARRAY_SIZE]; |
|
28 } LanguagePack; |
|
29 |
|
30 static char **_langpack_offs; |
|
31 static LanguagePack *_langpack; |
|
32 static uint _langtab_num[32]; // Offset into langpack offs |
|
33 static uint _langtab_start[32]; // Offset into langpack offs |
33 |
34 |
34 const uint16 _currency_string_list[] = { |
35 const uint16 _currency_string_list[] = { |
35 STR_CURR_GBP, |
36 STR_CURR_GBP, |
36 STR_CURR_USD, |
37 STR_CURR_USD, |
37 STR_CURR_EUR, |
38 STR_CURR_EUR, |
755 } |
756 } |
756 |
757 |
757 // language name? |
758 // language name? |
758 if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) { |
759 if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) { |
759 int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4); |
760 int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4); |
760 return str_cat(buff, i == _dynlang.curr ? ((LanguagePackHeader*)_langpack)->own_name : _dynlang.ent[i].name); |
761 return str_cat(buff, i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name); |
761 } |
762 } |
762 |
763 |
763 // resolution size? |
764 // resolution size? |
764 if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) { |
765 if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) { |
765 int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4); |
766 int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4); |
791 } |
792 } |
792 |
793 |
793 bool ReadLanguagePack(int lang_index) |
794 bool ReadLanguagePack(int lang_index) |
794 { |
795 { |
795 int tot_count, i; |
796 int tot_count, i; |
796 char *lang_pack; |
797 LanguagePack *lang_pack; |
797 size_t len; |
798 size_t len; |
798 char **langpack_offs; |
799 char **langpack_offs; |
799 char *s; |
800 char *s; |
800 |
801 |
801 #define HDR ((LanguagePackHeader*)lang_pack) |
|
802 { |
802 { |
803 char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file); |
803 char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file); |
804 lang_pack = ReadFileToMem(lang, &len, 100000); |
804 lang_pack = ReadFileToMem(lang, &len, 100000); |
805 free(lang); |
805 free(lang); |
806 } |
806 } |
807 if (lang_pack == NULL) return false; |
807 if (lang_pack == NULL) return false; |
808 if (len < sizeof(LanguagePackHeader) || |
808 if (len < sizeof(LanguagePack) || |
809 HDR->ident != TO_LE32(LANGUAGE_PACK_IDENT) || |
809 lang_pack->ident != TO_LE32(LANGUAGE_PACK_IDENT) || |
810 HDR->version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
810 lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
811 free(lang_pack); |
811 free(lang_pack); |
812 return false; |
812 return false; |
813 } |
813 } |
814 #undef HDR |
|
815 |
814 |
816 #if defined(TTD_BIG_ENDIAN) |
815 #if defined(TTD_BIG_ENDIAN) |
817 for (i = 0; i != 32; i++) { |
816 for (i = 0; i != 32; i++) { |
818 ((LanguagePackHeader*)lang_pack)->offsets[i] = READ_LE_UINT16(&((LanguagePackHeader*)lang_pack)->offsets[i]); |
817 lang_pack->offsets[i] = READ_LE_UINT16(&lang_pack->offsets[i]); |
819 } |
818 } |
820 #endif |
819 #endif |
821 |
820 |
822 tot_count = 0; |
821 tot_count = 0; |
823 for (i = 0; i != 32; i++) { |
822 for (i = 0; i != 32; i++) { |
824 uint num = ((LanguagePackHeader*)lang_pack)->offsets[i]; |
823 uint num = lang_pack->offsets[i]; |
825 _langtab_start[i] = tot_count; |
824 _langtab_start[i] = tot_count; |
826 _langtab_num[i] = num; |
825 _langtab_num[i] = num; |
827 tot_count += num; |
826 tot_count += num; |
828 } |
827 } |
829 |
828 |
830 // Allocate offsets |
829 // Allocate offsets |
831 langpack_offs = malloc(tot_count * sizeof(*langpack_offs)); |
830 langpack_offs = malloc(tot_count * sizeof(*langpack_offs)); |
832 |
831 |
833 // Fill offsets |
832 // Fill offsets |
834 s = lang_pack + sizeof(LanguagePackHeader); |
833 s = lang_pack->data; |
835 for (i = 0; i != tot_count; i++) { |
834 for (i = 0; i != tot_count; i++) { |
836 len = (byte)*s; |
835 len = (byte)*s; |
837 *s++ = '\0'; // zero terminate the string before. |
836 *s++ = '\0'; // zero terminate the string before. |
838 if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++; |
837 if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++; |
839 langpack_offs[i] = s; |
838 langpack_offs[i] = s; |
856 // make a list of the available language packs. put the data in _dynlang struct. |
855 // make a list of the available language packs. put the data in _dynlang struct. |
857 void InitializeLanguagePacks(void) |
856 void InitializeLanguagePacks(void) |
858 { |
857 { |
859 DynamicLanguages *dl = &_dynlang; |
858 DynamicLanguages *dl = &_dynlang; |
860 int i, j, n, m,def; |
859 int i, j, n, m,def; |
861 LanguagePackHeader hdr; |
860 LanguagePack hdr; |
862 FILE *in; |
861 FILE *in; |
863 char *files[32]; |
862 char *files[32]; |
864 |
863 |
865 n = GetLanguageList(files, lengthof(files)); |
864 n = GetLanguageList(files, lengthof(files)); |
866 |
865 |