2020-12-28 09:51:40 +01:00
|
|
|
#include "driver2.h"
|
2020-12-29 17:21:51 +01:00
|
|
|
#include "C/system.h"
|
2022-01-25 20:58:58 +01:00
|
|
|
#include "C/pres.h"
|
2020-12-29 17:21:51 +01:00
|
|
|
#include "platform.h"
|
2020-12-22 12:45:33 +01:00
|
|
|
|
|
|
|
#ifndef PSX
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
|
|
|
|
2022-01-25 20:58:58 +01:00
|
|
|
|
2020-12-22 12:45:33 +01:00
|
|
|
int gUserLanguage = 0;
|
|
|
|
|
|
|
|
char* gMisssionLanguageBuffer = NULL;
|
|
|
|
char* gGameLanguageBuffer = NULL;
|
|
|
|
|
|
|
|
char* gGameLangTable[MAX_LANGUAGE_TEXT];
|
|
|
|
char* gMissionLangTable[MAX_LANGUAGE_TEXT];
|
|
|
|
|
|
|
|
char* LanguageNames[5] =
|
|
|
|
{
|
2020-12-29 17:21:51 +01:00
|
|
|
"EN",
|
|
|
|
"IT",
|
|
|
|
"GE",
|
|
|
|
"FR",
|
|
|
|
"SP",
|
2020-12-22 12:45:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef PSX
|
|
|
|
// [D] Driver 1 PC function
|
2020-12-22 13:04:33 +01:00
|
|
|
int InitStringMng()
|
2020-12-22 12:45:33 +01:00
|
|
|
{
|
2020-12-30 22:43:50 +01:00
|
|
|
char filename[80];
|
2020-12-22 12:45:33 +01:00
|
|
|
|
|
|
|
if (gUserLanguage < 0 || gUserLanguage >= 6)
|
|
|
|
gUserLanguage = 0;
|
|
|
|
|
2020-12-29 17:21:51 +01:00
|
|
|
sprintf(filename, "%sLANG\\%s_GAME.LTXT", gDataFolder, LanguageNames[gUserLanguage]);
|
2021-02-26 18:37:08 +01:00
|
|
|
FS_FixPathSlashes(filename);
|
2020-12-29 17:21:51 +01:00
|
|
|
|
2020-12-22 13:04:33 +01:00
|
|
|
if(InitStringLanguage(filename, 0) == -1)
|
|
|
|
return 0;
|
2020-12-22 12:45:33 +01:00
|
|
|
|
2020-12-29 17:21:51 +01:00
|
|
|
sprintf(filename, "%sLANG\\%s_MISSION.LTXT", gDataFolder, LanguageNames[gUserLanguage]);
|
2021-02-26 18:37:08 +01:00
|
|
|
FS_FixPathSlashes(filename);
|
2020-12-29 17:21:51 +01:00
|
|
|
|
2020-12-22 13:04:33 +01:00
|
|
|
if(InitStringLanguage(filename, 1) == -1)
|
|
|
|
return 0;
|
|
|
|
|
2021-02-19 08:21:36 +01:00
|
|
|
#ifdef DEBUG_OPTIONS
|
2021-02-19 08:08:33 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int nchars;
|
|
|
|
char table[256];
|
|
|
|
char* file;
|
|
|
|
|
2021-04-04 11:24:16 +02:00
|
|
|
file = (char*)_frontend_buffer;
|
2021-02-19 08:08:33 +01:00
|
|
|
|
|
|
|
Loadfile("GFX\\FONT2.FNT", file);
|
|
|
|
|
|
|
|
nchars = *(int *)file;
|
|
|
|
file += sizeof(int);
|
|
|
|
|
|
|
|
// skip character info
|
|
|
|
file += nchars * sizeof(OUT_FONTINFO);
|
|
|
|
|
|
|
|
// get ASCII table
|
|
|
|
memcpy((u_char*)table, file, 256);
|
|
|
|
|
|
|
|
printInfo("Performing '%s' LANG to FONT text check...\n", LanguageNames[gUserLanguage]);
|
|
|
|
for (i = 0; i < MAX_LANGUAGE_TEXT; i++)
|
|
|
|
{
|
|
|
|
char* base = gGameLangTable[i];
|
|
|
|
char* testPtr = base;
|
|
|
|
while (*testPtr)
|
|
|
|
{
|
|
|
|
u_char chr = *testPtr;
|
|
|
|
|
|
|
|
if (chr != 32 && (chr < 32 || chr > 138 || chr < 128) && table[chr] == -1)
|
|
|
|
{
|
|
|
|
printWarning("WARN - incorrect GAME text symbol '%c', line %d, col %d\n", chr, i + 1, testPtr - base + 1);
|
|
|
|
}
|
|
|
|
testPtr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_LANGUAGE_TEXT; i++)
|
|
|
|
{
|
|
|
|
char* base = gMissionLangTable[i];
|
|
|
|
char* testPtr = base;
|
|
|
|
while (*testPtr)
|
|
|
|
{
|
|
|
|
u_char chr = *testPtr;
|
|
|
|
|
|
|
|
if (chr != 32 && (chr < 32 || chr > 138 || chr < 128) && table[chr] == -1)
|
|
|
|
{
|
|
|
|
printWarning("WARN - incorrect MISSION text symbol '%c', line %d, col %d\n", chr, i + 1, testPtr - base + 1);
|
|
|
|
}
|
|
|
|
testPtr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-19 08:21:36 +01:00
|
|
|
#endif
|
2020-12-22 13:04:33 +01:00
|
|
|
return 1;
|
2020-12-22 12:45:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeinitStringMng()
|
|
|
|
{
|
|
|
|
if (gGameLanguageBuffer)
|
|
|
|
free(gGameLanguageBuffer);
|
|
|
|
|
|
|
|
if (gMisssionLanguageBuffer)
|
|
|
|
free(gMisssionLanguageBuffer);
|
|
|
|
|
|
|
|
gGameLanguageBuffer = NULL;
|
|
|
|
gMisssionLanguageBuffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [D] Driver 1 PC function
|
|
|
|
int InitStringLanguage(char *filename, int mission)
|
|
|
|
{
|
2020-12-29 11:58:36 +01:00
|
|
|
unsigned char *buffer;
|
|
|
|
unsigned char *cptr;
|
|
|
|
unsigned char *ln;
|
2020-12-22 12:45:33 +01:00
|
|
|
int i;
|
|
|
|
int size;
|
2020-12-29 17:21:51 +01:00
|
|
|
|
2020-12-22 12:45:33 +01:00
|
|
|
FILE* fp = fopen(filename, "rb");
|
2020-12-22 13:04:33 +01:00
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
printError("ERROR! Cannot open language file '%s'!\n", filename);
|
2020-12-22 12:45:33 +01:00
|
|
|
return -1;
|
2020-12-22 13:04:33 +01:00
|
|
|
}
|
2020-12-22 12:45:33 +01:00
|
|
|
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
size = ftell(fp);
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
|
2020-12-29 11:58:36 +01:00
|
|
|
buffer = (unsigned char*)malloc(size);
|
2020-12-22 12:45:33 +01:00
|
|
|
fread(buffer, 1, size, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
if (mission)
|
2020-12-29 11:58:36 +01:00
|
|
|
gMisssionLanguageBuffer = (char*)buffer;
|
2020-12-22 12:45:33 +01:00
|
|
|
else
|
2020-12-29 11:58:36 +01:00
|
|
|
gGameLanguageBuffer = (char*)buffer;
|
2020-12-22 12:45:33 +01:00
|
|
|
|
|
|
|
cptr = buffer;
|
|
|
|
for (i = 0; i < MAX_LANGUAGE_TEXT; i++)
|
|
|
|
{
|
|
|
|
if (size <= 0)
|
|
|
|
{
|
|
|
|
if (mission)
|
|
|
|
gMissionLangTable[i] = "Mission.? missing!";
|
|
|
|
else
|
|
|
|
gGameLangTable[i] = "Lang.? missing!";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mission)
|
2020-12-29 11:58:36 +01:00
|
|
|
gMissionLangTable[i] = (char*)cptr;
|
2020-12-22 12:45:33 +01:00
|
|
|
else
|
2020-12-29 11:58:36 +01:00
|
|
|
gGameLangTable[i] = (char*)cptr;
|
2020-12-22 12:45:33 +01:00
|
|
|
|
|
|
|
// go to next line
|
|
|
|
ln = cptr;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (*cptr == '\n' || *cptr == '\r')
|
|
|
|
{
|
|
|
|
while(*cptr == '\r')
|
|
|
|
{
|
|
|
|
*cptr++;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*cptr >= 32)
|
|
|
|
ln = cptr + 1;
|
|
|
|
|
|
|
|
size--;
|
|
|
|
cptr++;
|
|
|
|
} while (size > 1);
|
|
|
|
|
|
|
|
*ln = 0; // zero on end of the line
|
|
|
|
|
|
|
|
cptr++;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
#endif
|