]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
-fdarkplaces-stringtablebug
authorDale Weiler <killfieldengine@gmail.com>
Sun, 22 Apr 2012 20:58:12 +0000 (16:58 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Sun, 22 Apr 2012 20:58:12 +0000 (16:58 -0400)
code.c
gmqcc.h
main.c
util.c

diff --git a/code.c b/code.c
index 674eb1aca4a7fdfc0fa75440645e3edbf4a022bf..66dc9517a68f008abf498748c1f9e0728246bd70 100644 (file)
--- 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 e874ad454ac3f06e052e95b259cc40d0224af244..f27f41ea982eb6edf23f485aded40eedcd29d7cc 100644 (file)
--- 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 4828f26fd850bb91fcd4927d68a303ab60d099e1..2c0be85ca4797ac62cb0b4d8bad6f1f511dc724e 100644 (file)
--- 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 136b12a6e92124ee107d1abd379a67f732efdbc3..62f6e149ec04db07a27ea5a2f8f2866b9d58664b 100644 (file)
--- 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; 
         }
     }
 }