Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localization cleanup #511

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
0e88906
Minor fixes to localization.cpp
winterheart Jul 31, 2024
6d682c2
Remove calling once guard in LoadStringTables()
winterheart Jul 31, 2024
ef1be32
Add unittests for localization functions
winterheart Jul 31, 2024
e5caf32
Rewrite localization to use std::string
winterheart Jul 31, 2024
ac7b574
Use std::fs::path in localization functions
winterheart Aug 1, 2024
c214992
Unify load messages in scripts
winterheart Aug 1, 2024
0a156ba
Fill OsirisModule functions manually
winterheart Aug 1, 2024
b4ea38e
Implement MessageMap localization for scripts
winterheart Aug 1, 2024
5568bb0
Normalize message file names
winterheart Aug 2, 2024
7c7a5a2
Convert TrainingMission to new Message system
winterheart Aug 2, 2024
a8b3b77
Convert Y2K to new Message system
winterheart Aug 2, 2024
3540f2b
Convert BatteriesIncluded to new Message system
winterheart Aug 2, 2024
4899a17
Convert barney.cpp to new Message system
winterheart Aug 2, 2024
abdd9d2
Convert BossCamera.cpp to new Message system
winterheart Aug 2, 2024
849d5e1
Convert CanyonsCTF.cpp to new Message system
winterheart Aug 2, 2024
3c440e9
Convert CellTestLevel.cpp to new Message system
winterheart Aug 2, 2024
e287242
Convert ChrisTest.cpp to new Message system
winterheart Aug 2, 2024
f73fc52
Convert Geodomes.cpp to new Message system
winterheart Aug 2, 2024
f3c1807
Convert HalfPipe.cpp to new Message system
winterheart Aug 2, 2024
bcfdd54
Convert InfernalBolt.cpp to new Message system
winterheart Aug 2, 2024
d37e816
Convert Inversion.cpp to new Message system
winterheart Aug 2, 2024
01d9a31
Convert LEVEL0.cpp to new Message system
winterheart Aug 2, 2024
aab9471
Convert level1.cpp to new Message system
winterheart Aug 2, 2024
187c25c
Convert level2.cpp to new Message system
winterheart Aug 2, 2024
7ffa332
Convert level3.cpp to new Message system
winterheart Aug 2, 2024
76f9148
Convert level4.cpp to new Message system
winterheart Aug 2, 2024
f9d8d11
Convert level5.cpp to new Message system
winterheart Aug 2, 2024
ec650e5
Convert level6.cpp to new Message system
winterheart Aug 2, 2024
e6e8d7c
Convert level7.cpp to new Message system
winterheart Aug 2, 2024
cee4486
Convert level8.cpp to new Message system
winterheart Aug 2, 2024
1c9578d
Convert level9.cpp to new Message system
winterheart Aug 2, 2024
a7df0de
Convert level10.cpp to new Message system
winterheart Aug 2, 2024
821279f
Convert level11.cpp to new Message system
winterheart Aug 2, 2024
1059816
Convert level12.cpp to new Message system
winterheart Aug 2, 2024
38b6e7b
Convert level13.cpp to new Message system
winterheart Aug 2, 2024
94f2a0e
Convert level14.cpp to new Message system
winterheart Aug 2, 2024
6def6d6
Convert level15.cpp to new Message system
winterheart Aug 2, 2024
9d5eef1
Convert level16.cpp to new Message system
winterheart Aug 2, 2024
3ea8533
Convert level17.cpp to new Message system
winterheart Aug 2, 2024
d64d814
Convert levelS1.cpp to new Message system
winterheart Aug 2, 2024
3a4e593
Convert levelS2.cpp to new Message system
winterheart Aug 2, 2024
849bde3
Convert merc1.cpp to new Message system
winterheart Aug 2, 2024
5ccf7aa
Convert merc02.cpp to new Message system
winterheart Aug 2, 2024
66ebd0e
Convert merc3.cpp to new Message system
winterheart Aug 2, 2024
71fdd82
Convert merc4.cpp to new Message system
winterheart Aug 2, 2024
dd46162
Convert merc5.cpp to new Message system
winterheart Aug 2, 2024
38c1791
Convert merc6.cpp to new Message system
winterheart Aug 2, 2024
f646fb0
Convert merc7.cpp to new Message system
winterheart Aug 2, 2024
8ca8cef
Convert myPowerHouse.cpp to new Message system
winterheart Aug 2, 2024
91a091a
Convert Mysterious_Isle.cpp to new Message system
winterheart Aug 2, 2024
9ef1f7a
Convert orbital.cpp to new Message system
winterheart Aug 2, 2024
2aa5d0e
Convert Paranoia.cpp to new Message system
winterheart Aug 2, 2024
778d243
Convert PiccuStation.cpp to new Message system
winterheart Aug 2, 2024
2b47948
Convert Polaris.cpp to new Message system
winterheart Aug 2, 2024
f83f087
Convert Quadsomniac.cpp to new Message system
winterheart Aug 2, 2024
77081cd
Convert RudeAwakening.cpp to new Message system
winterheart Aug 2, 2024
ead5ed3
Convert SewerRat.cpp to new Message system
winterheart Aug 2, 2024
faf1f3f
Add to tOSIRISModuleInit serial_version field
winterheart Aug 11, 2024
77bb924
Rename GetMessage() to GetMessageMap()
winterheart Aug 11, 2024
fca5318
Remove static variable String_table_size
winterheart Sep 7, 2024
37e163a
Change GetStringFromTable() signature
winterheart Sep 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ endif()

# 64 bit machines have a different game checksum than 32 bit machines
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions(-DCHECKSUM=2273889835UL)
add_definitions(-DCHECKSUM=2273864794UL)
else()
add_definitions(-DCHECKSUM=2273873307UL)
add_definitions(-DCHECKSUM=2273860746UL)
endif()

if(BUILD_TESTING)
Expand Down
42 changes: 22 additions & 20 deletions Descent3/CtlCfgElem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,20 @@
* $NoKeywords: $
*/

#include <cstring>
#include <string>
#include <vector>

#include "CtlCfgElem.h"
#include "descent.h"

#include "Macros.h"
#include "ddio.h"
#include "application.h"
#include "renderer.h"
#include "stringtable.h"
#include "gamefont.h"
#include "localization.h"

#include <string.h>
#include "joystick.h"

// all controller binding texts
Expand Down Expand Up @@ -417,58 +419,58 @@ extern char Ctltext_MseBtnBindings[][32];
extern char Ctltext_MseAxisBindings[][32];

void Localize_ctl_bindings() {
char **strtable;
int n_strings, i;
std::vector<std::string> strtable;
int i;

// keyboard translations.
// no need to do for english!
if (Localization_GetLanguage() == LANGUAGE_ENGLISH)
return;

if (CreateStringTable("bindkey.str", &strtable, &n_strings)) {
if (CreateStringTable("bindkey.str", strtable)) {
i = 0;
while (key_binding_indices[i] != 0xff) {
if (i >= n_strings) {
if (i >= strtable.size()) {
break;
}
strcpy(Ctltext_KeyBindings[key_binding_indices[i]], strtable[i]);
strcpy(Ctltext_KeyBindings[key_binding_indices[i]], strtable[i].c_str());
i++;
}
DestroyStringTable(strtable, n_strings);
DestroyStringTable(strtable);
}

// mouse translations.
if (CreateStringTable("bindmse.str", &strtable, &n_strings)) {
if (CreateStringTable("bindmse.str", strtable)) {
for (i = 0; i < 6; i++) {
if (i >= n_strings) {
if (i >= strtable.size()) {
break;
}
strcpy(Ctltext_MseBtnBindings[i], strtable[i]);
strcpy(Ctltext_MseBtnBindings[i], strtable[i].c_str());
}
for (i = 0; i < 3; i++) {
if ((i + 6) >= n_strings) {
if ((i + 6) >= strtable.size()) {
break;
}
strcpy(Ctltext_MseAxisBindings[i], strtable[i + 6]);
strcpy(Ctltext_MseAxisBindings[i], strtable[i + 6].c_str());
}
DestroyStringTable(strtable, n_strings);
DestroyStringTable(strtable);
}

// joystick translations.
if (CreateStringTable("bindjoy.str", &strtable, &n_strings)) {
if (CreateStringTable("bindjoy.str", strtable)) {
for (i = 0; i < 6; i++) {
if (i >= n_strings) {
if (i >= strtable.size()) {
break;
}
strcpy(Ctltext_AxisBindings[i + 1], strtable[i]);
strcpy(Ctltext_AxisBindings[i + 1], strtable[i].c_str());
}
for (i = 0; i < 4; i++) {
if ((i + 6) >= n_strings) {
if ((i + 6) >= strtable.size()) {
break;
}
strcpy(Ctltext_PovBindings[i + 1], strtable[i + 6]);
strcpy(Ctltext_PovBindings[i + 1], strtable[i + 6].c_str());
}
DestroyStringTable(strtable, n_strings);
DestroyStringTable(strtable);
}
}

Expand Down
5 changes: 4 additions & 1 deletion Descent3/Game2DLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/

#include <algorithm>
#include <string>
#include <vector>

#include "pstypes.h"
#include "pserror.h"
Expand Down Expand Up @@ -62,6 +64,7 @@
#include "ObjScript.h"
#include "args.h"


void SelectNextCameraView(int window);
#define NUM_CAMERA_VIEWS 3
extern int Camera_view_mode[NUM_CAMERA_VIEWS];
Expand Down Expand Up @@ -539,7 +542,7 @@ void GetGameAPI(game_api *api) {

api->osiris_functions = &Multi_d3m_osiris_funcs;
Osiris_CreateModuleInitStruct(&Multi_d3m_osiris_funcs);
Multi_d3m_osiris_funcs.string_table = NULL;
Multi_d3m_osiris_funcs.string_table.clear();
Multi_d3m_osiris_funcs.string_count = 0;
Multi_d3m_osiris_funcs.module_identifier = 0xEDF7;
Multi_d3m_osiris_funcs.module_is_static = false;
Expand Down
31 changes: 13 additions & 18 deletions Descent3/LoadLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1237,10 +1237,11 @@
* $NoKeywords: $
*/

#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cerrno>
#include <algorithm>
#include <string>
#include <vector>

#include "LoadLevel.h"

Expand Down Expand Up @@ -5712,18 +5713,12 @@ int CountDataToPageIn() {

#endif

void Localization_SetLanguage(int type);

int Localization_GetLanguage(void);

char *LocalizeLevelName(char *level) {
static char local_name[101];

char **english_names;
int num_english_names;
std::vector<std::string> english_names;

char **local_names;
int num_local_names;
std::vector<std::string> local_names;

local_name[0] = 0;

Expand All @@ -5736,7 +5731,7 @@ char *LocalizeLevelName(char *level) {

Localization_SetLanguage(LANGUAGE_ENGLISH);
// Save the current language, then bash it to english
if (!CreateStringTable("level_names.str", &english_names, &num_english_names)) {
if (!CreateStringTable("level_names.str", english_names)) {
LOG_WARNING << "Couldn't open level_names stringtable!";
Localization_SetLanguage(save_lang);
strcpy(local_name, level);
Expand All @@ -5746,22 +5741,22 @@ char *LocalizeLevelName(char *level) {
// Restore the correct language
Localization_SetLanguage(save_lang);

if (!CreateStringTable("level_names.str", &local_names, &num_local_names)) {
if (!CreateStringTable("level_names.str", local_names)) {
LOG_WARNING << "Couldn't open level_names stringtable!";
// destroy the english stringtable...
DestroyStringTable(english_names, num_english_names);
DestroyStringTable(english_names);

strcpy(local_name, level);
return local_name;
}

// Now search for the correct level
for (int i = 0; i < num_english_names; i++) {
if (0 == stricmp(level, english_names[i])) {
for (int i = 0; i < english_names.size(); i++) {
if (0 == stricmp(level, english_names[i].c_str())) {
// Ok, we found a match. So return the local text.
strcpy(local_name, local_names[i]);
DestroyStringTable(english_names, num_english_names);
DestroyStringTable(local_names, num_local_names);
strcpy(local_name, local_names[i].c_str());
DestroyStringTable(english_names);
DestroyStringTable(local_names);
return local_name;
}
}
Expand Down
32 changes: 16 additions & 16 deletions Descent3/Mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@
#include <cstring>
#include <cstdlib>
#include <filesystem>
#include <string>
#include <vector>

#include "Mission.h"
#include "3d.h"
Expand All @@ -648,6 +650,8 @@
#include "cfile.h"
#include "gamefont.h"
#include "grdefs.h"
#include "levelgoal.h"
#include "localization.h"
#include "descent.h"
#include "ddio.h"
#include "d3movie.h"
Expand All @@ -672,6 +676,7 @@
#include "terrain.h"
#include "multi.h"
#include "hud.h"

// ---------------------------------------------------------------------------
// Data
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1245,25 +1250,20 @@ void FreeMission() {
Current_mission.hog = NULL;
Current_level = NULL;
}
#include "localization.h"
#include "levelgoal.h"
// Load the text (goal strings) for a level
void LoadLevelText(const char *level_filename) {
char pathname[_MAX_FNAME], filename[_MAX_FNAME];
int n_strings;
ddio_SplitPath(level_filename, pathname, filename, NULL);
strcat(pathname, filename);
strcat(pathname, ".str");
char **goal_strings;
if (CreateStringTable(pathname, &goal_strings, &n_strings)) {

void LoadLevelText(const std::filesystem::path &level_filename) {
std::filesystem::path pathname = level_filename;
pathname.replace_extension(".str");
std::vector<std::string> goal_strings;
if (CreateStringTable(pathname, goal_strings)) {
int n_goals = Level_goals.GetNumGoals();
ASSERT(n_strings == (n_goals * 3));
ASSERT(goal_strings.size() == (n_goals * 3));
for (int i = 0; i < n_goals; i++) {
Level_goals.GoalSetName(i, goal_strings[i * 3]);
Level_goals.GoalSetItemName(i, goal_strings[i * 3 + 1]);
Level_goals.GoalSetDesc(i, goal_strings[i * 3 + 2]);
Level_goals.GoalSetName(i, (char *)goal_strings[i * 3].c_str());
Level_goals.GoalSetItemName(i, (char *)goal_strings[i * 3 + 1].c_str());
Level_goals.GoalSetDesc(i, (char *)goal_strings[i * 3 + 2].c_str());
}
DestroyStringTable(goal_strings, n_strings);
DestroyStringTable(goal_strings);
}
}

Expand Down
6 changes: 4 additions & 2 deletions Descent3/Mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@
#ifndef MISSION_H
#define MISSION_H

#include "pstypes.h"
#include "descent.h"

// *** CONSTANTS ***
Expand All @@ -177,11 +176,14 @@
#define LOAD_PROGRESS_PREPARE 4
#define LOAD_PROGRESS_DONE 200

// Load the text (goal strings) for a level
void LoadLevelText(const std::filesystem::path &level_filename);

// Load level progress worker
void LoadLevelProgress(int step, float percent, const char *chunk = NULL);

// array constants
const int MSN_FILENAMELEN = _MAX_PATH, MSN_URLLEN = 256;
const int MSN_URLLEN = 256;

#define MAX_KEYWORDLEN 300

Expand Down
Loading
Loading