mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-03-25 03:51:26 +00:00
-fdarkplaces-stringtablebug
This commit is contained in:
parent
4d001da04e
commit
691d146d9b
4 changed files with 33 additions and 16 deletions
23
code.c
23
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);
|
||||
|
|
1
gmqcc.h
1
gmqcc.h
|
@ -484,4 +484,5 @@ enum {
|
|||
};
|
||||
extern int opts_debug;
|
||||
extern int opts_memchk;
|
||||
extern int opts_darkplaces_stringtablebug;
|
||||
#endif
|
||||
|
|
15
main.c
15
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);
|
||||
|
||||
}
|
||||
|
|
10
util.c
10
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue