Skip to content

Instantly share code, notes, and snippets.

@grepwood
Created July 4, 2014 14:37
Show Gist options
  • Save grepwood/38c05c973458a93aab81 to your computer and use it in GitHub Desktop.
Save grepwood/38c05c973458a93aab81 to your computer and use it in GitHub Desktop.
This function will detect known languages based on the kind of Morrowind gamedata is being fed to it
/* Written by Michael Dec <grepwood@sucs.org>
* Language detection of Morrowind gamedata
*/
structure LDesc_struct
{
unsigned char code; /* Fingers crossed Morrowind wasn't translated to more than 255 languages */
char desc[32]; /* 32 bytes in the .esm that indicate what language this is */
};
/* The descriptions are like this because their character form is subject to character encoding.
* If we compare the numbers, then we will never get wrong results because of different encoding.
*/
LDesc_struct English = {{1},{84,104,101,32,109,97,105,110,32,100,97,116,97,32,102,105,108,101,32,70,111,114,32,77,111,114,114,111,119,105,110,100}};
LDesc_struct Polish = {{2},{80,108,105,107,32,103,179,243,119,110,121,32,100,108,97,32,103,114,121,32,77,111,114,114,111,119,105,110,100,46,0,0}};
#define LCOUNT 2
char * DLanguage[LCOUNT] = {English.desc,
Polish.desc};
unsigned char * CLanguage[LCOUNT] = { English.code,
Polish.code};
unsigned char GameLanguage(FILE * esm) {
char Description[32];
unsigned char count;
unsigned char result = 0;
int compresult;
fopen(esm,"rb");
fseek(esm,64,SEEK_SET);
fread(&Description,32,1,esm);
fclose(esm);
for(count = 0; count < LCOUNT, compresult; ++count) {
compresult = memcmp(Description,DLanguage[count],32);
}
if(!compresult) {
result = CLanguage[count];
}
return result;
}
/* If return is 0 then the function failed to detect the language */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment