From: Dale Weiler Date: Sun, 22 Apr 2012 20:58:12 +0000 (-0400) Subject: -fdarkplaces-stringtablebug X-Git-Tag: 0.1-rc1~642 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=commitdiff_plain;h=691d146d9b19017e1211aa4ab3b19cb4e03dfb8f -fdarkplaces-stringtablebug --- diff --git a/code.c b/code.c index 674eb1a..66dc951 100644 --- a/code.c +++ b/code.c @@ -146,14 +146,23 @@ void code_write() { code_header.globals = (prog_section){code_header.functions.offset + sizeof(prog_section_function) *code_functions_elements, code_globals_elements }; code_header.strings = (prog_section){code_header.globals.offset + sizeof(int) *code_globals_elements, code_chars_elements }; code_header.entfield = 0; /* TODO: */ - + + if (opts_darkplaces_stringtablebug) { + util_debug("GEN", "Patching stringtable for -fdarkplaces-stringtablebug\n"); + + /* >= + padd */ + code_chars_add('\0'); /* > */ + code_chars_add('\0'); /* = */ + code_chars_add('\0'); /* P */ + } + /* ensure all data is in LE format */ - util_endianswap(&code_header, sizeof(prog_header), 1); - util_endianswap(code_statements_data, sizeof(prog_section_statement), code_statements_elements); - util_endianswap(code_defs_data, sizeof(prog_section_def), code_defs_elements); - util_endianswap(code_fields_data, sizeof(prog_section_field), code_fields_elements); - util_endianswap(code_functions_data, sizeof(prog_section_function), code_functions_elements); - util_endianswap(code_globals_data, sizeof(int), code_globals_elements); + util_endianswap(&code_header, 1, sizeof(prog_header)); + util_endianswap(code_statements_data, code_statements_elements, sizeof(prog_section_statement)); + util_endianswap(code_defs_data, code_defs_elements, sizeof(prog_section_def)); + util_endianswap(code_fields_data, code_fields_elements, sizeof(prog_section_field)); + util_endianswap(code_functions_data, code_functions_elements, sizeof(prog_section_function)); + util_endianswap(code_globals_data, code_globals_elements, sizeof(int)); FILE *fp = fopen("program.dat", "wb"); fwrite(&code_header, 1, sizeof(prog_header), fp); diff --git a/gmqcc.h b/gmqcc.h index e874ad4..f27f41e 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -484,4 +484,5 @@ enum { }; extern int opts_debug; extern int opts_memchk; +extern int opts_darkplaces_stringtablebug; #endif diff --git a/main.c b/main.c index 4828f26..2c0be85 100644 --- a/main.c +++ b/main.c @@ -26,9 +26,10 @@ typedef struct { char *name, type; } argitem; VECTOR_MAKE(argitem, items); /* global options */ -int opts_debug = 0; -int opts_memchk = 0; -int opts_compiler = COMPILER_GMQCC; +int opts_debug = 0; +int opts_memchk = 0; +int opts_compiler = COMPILER_GMQCC; +int opts_darkplaces_stringtablebug = 0; static const int usage(const char *const app) { printf("usage:\n"); @@ -47,6 +48,8 @@ static const int usage(const char *const app) { printf(" -std=ftqecc -- fteqcc QuakeC\n"); printf(" -std=qccx -- qccx QuakeC\n"); printf(" -std=gmqcc -- this compiler QuakeC (default selection)\n"); + printf(" code flags -f*\n"); + printf(" -fdarkplaces-stringtablebug -- patches the string table to work with bugged versions of darkplaces\n"); return -1; } @@ -87,6 +90,12 @@ int main(int argc, char **argv) { printf(" -std=gmqcc -- this compiler QuakeC (default selection)\n"); return 0; } + + /* code specific switches */ + if (!strncmp(&argv[1][1], "fdarkplaces-stringtablebug", 26)) { + opts_darkplaces_stringtablebug = 1; + break; + } return usage(app); } diff --git a/util.c b/util.c index 136b12a..62f6e14 100644 --- a/util.c +++ b/util.c @@ -156,15 +156,13 @@ void util_endianswap(void *m, int s, int l) { size_t i = 0; /* ignore if we're already LE */ - if(*((char *)&s)) - return; + // if(*((char *)&s)) + // return; for(; w < l; w++) { for(; i < s << 1; i++) { - unsigned char *p = (unsigned char *)m+w*s; - unsigned char t = p[i]; - p[i] = p[s-i-1]; - p[s-i-1] = t; + unsigned char *p = &((unsigned char *)m+w*s)[i]; + *p = ((*p * 0x0802LU & 0x22110LU) | (*p * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16; } } }