- Timestamp:
- Jul 26, 2009, 2:04:44 PM (15 years ago)
- Location:
- Daodan
- Files:
-
- 2 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
Daodan/src/Daodan.c
r447 r451 195 195 case s_options: 196 196 if (!stricmp(name, "usedaodanbsl")) 197 opt_usedaodanbsl = !stricmp( value, "true");197 opt_usedaodanbsl = !stricmp(inifile_cleanstr(value), "true"); 198 198 break; 199 199 case s_patch: 200 200 if (!stricmp(name, "fonttexturecache")) 201 patch_fonttexturecache = !stricmp( value, "true");201 patch_fonttexturecache = !stricmp(inifile_cleanstr(value), "true"); 202 202 else if (!stricmp(name, "largetextures")) 203 patch_largetextures = !stricmp( value, "true");203 patch_largetextures = !stricmp(inifile_cleanstr(value), "true"); 204 204 else if (!stricmp(name, "levelplugins")) 205 patch_levelplugins = !stricmp( value, "true");205 patch_levelplugins = !stricmp(inifile_cleanstr(value), "true"); 206 206 else if (!stricmp(name, "pathfinding")) 207 patch_pathfinding = !stricmp( value, "true");207 patch_pathfinding = !stricmp(inifile_cleanstr(value), "true"); 208 208 else if (!stricmp(name, "projaware")) 209 patch_projaware = !stricmp( value, "true");209 patch_projaware = !stricmp(inifile_cleanstr(value), "true"); 210 210 else if (!stricmp(name, "directinput")) 211 patch_directinput = !stricmp( value, "true");211 patch_directinput = !stricmp(inifile_cleanstr(value), "true"); 212 212 else if (!stricmp(name, "wpfadetime")) 213 patch_wpfadetime = !stricmp( value, "true");213 patch_wpfadetime = !stricmp(inifile_cleanstr(value), "true"); 214 214 else if (!stricmp(name, "kickguns")) 215 patch_kickguns = !stricmp( value, "true");215 patch_kickguns = !stricmp(inifile_cleanstr(value), "true"); 216 216 else if (!stricmp(name, "cooldowntimer")) 217 patch_cooldowntimer = !stricmp( value, "true");217 patch_cooldowntimer = !stricmp(inifile_cleanstr(value), "true"); 218 218 else if (!stricmp(name, "throwtest")) 219 patch_throwtest = !stricmp( value, "true");219 patch_throwtest = !stricmp(inifile_cleanstr(value), "true"); 220 220 else if (!stricmp(name, "alttab")) 221 patch_alttab = !stricmp( value, "true");221 patch_alttab = !stricmp(inifile_cleanstr(value), "true"); 222 222 else if (!stricmp(name, "particledisablebit")) 223 patch_particledisablebit = !stricmp( value, "true");223 patch_particledisablebit = !stricmp(inifile_cleanstr(value), "true"); 224 224 else if (!stricmp(name, "multibyte")) 225 patch_multibyte = !stricmp( value, "true");225 patch_multibyte = !stricmp(inifile_cleanstr(value), "true"); 226 226 else if (!stricmp(name, "cheattable")) 227 patch_cheattable = !stricmp( value, "true");227 patch_cheattable = !stricmp(inifile_cleanstr(value), "true"); 228 228 else if (!stricmp(name, "argb8888")) 229 patch_argb8888 = !stricmp( value, "true");229 patch_argb8888 = !stricmp(inifile_cleanstr(value), "true"); 230 230 else if (!stricmp(name, "safeprintf")) 231 patch_safeprintf = !stricmp( value, "true");231 patch_safeprintf = !stricmp(inifile_cleanstr(value), "true"); 232 232 else if (!stricmp(name, "daodandisplayenum")) 233 patch_daodandisplayenum = !stricmp( value, "true");233 patch_daodandisplayenum = !stricmp(inifile_cleanstr(value), "true"); 234 234 else if (!stricmp(name, "usegettickcount")) 235 patch_usegettickcount = !stricmp( value, "true");235 patch_usegettickcount = !stricmp(inifile_cleanstr(value), "true"); 236 236 else if (!stricmp(name, "cheatsenabled")) 237 patch_cheatsenabled = !stricmp( value, "true");237 patch_cheatsenabled = !stricmp(inifile_cleanstr(value), "true"); 238 238 else if (!stricmp(name, "usedaodangl")) 239 patch_usedaodangl = !stricmp( value, "true");239 patch_usedaodangl = !stricmp(inifile_cleanstr(value), "true"); 240 240 else if (!stricmp(name, "windowhack")) 241 patch_windowhack = !stricmp( value, "true");241 patch_windowhack = !stricmp(inifile_cleanstr(value), "true"); 242 242 else if (!stricmp(name, "daodaninit")) 243 patch_daodaninit = !stricmp( value, "true");243 patch_daodaninit = !stricmp(inifile_cleanstr(value), "true"); 244 244 else if (!stricmp(name, "bsl")) 245 patch_bsl = !stricmp( value, "true");245 patch_bsl = !stricmp(inifile_cleanstr(value), "true"); 246 246 else 247 247 DDrStartupMessage("unrecognised patch \"%s\"", name); 248 break;249 case s_bsl:250 251 248 break; 252 249 case s_language: … … 358 355 DDrStartupMessage("unrecognised language item \"%s\"", name); 359 356 break; 357 case s_bsl: 360 358 default: 361 359 break; -
Daodan/src/Daodan_BSL.c
r450 r451 1 1 #include <stdio.h> 2 #include <stdbool.h> 2 3 #include <time.h> 3 4 #include <ffi.h> 5 6 #include "inifile.h" 4 7 5 8 #include "Daodan_BSL.h" … … 149 152 is_lsi = 1; 150 153 } 151 else if(!strcmp(args[1].value_str32,"bossshield"))152 {153 ret->value_int32 = Chr[index].Flags & char_bossshield;154 ret->type = sl_int32;155 if (numargs >=3) {156 if (Chr[index].Flags & char_bossshield) Chr[index].Flags = Chr[index].Flags & ~char_bossshield;157 else Chr[index].Flags = Chr[index].Flags | char_bossshield;158 }159 return 0;160 }154 // else if(!strcmp(args[1].value_str32,"bossshield")) 155 // { 156 // ret->value_int32 = Chr[index].Flags & char_bossshield; 157 // ret->type = sl_int32; 158 // if (numargs >=3) { 159 // if (Chr[index].Flags & char_bossshield) Chr[index].Flags = Chr[index].Flags & ~char_bossshield; 160 // else Chr[index].Flags = Chr[index].Flags | char_bossshield; 161 // } 162 // return 0; 163 // } 161 164 else return 1; 162 165 //todo, add setting … … 228 231 ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]); 229 232 if ((int)Active == 0) return 1; 230 ret->value_int32 = Active->LastDamageSourceCharacter;233 // ret->value_int32 = Active->LastDamageSourceCharacter; 231 234 ret->type = sl_int32; 232 235 return 0; … … 386 389 } 387 390 391 bool ini_inbsl = false; 392 bool SLrIniCallback(char* section, bool newsection, char* name, char* value) 393 { 394 if (newsection && !stricmp(section, "bsl")) 395 ini_inbsl = true; 396 397 if (ini_inbsl) 398 { 399 bool isptr = false; 400 sl_type bsl_type; 401 402 if (value[0] == 'p' && value[1] == 't' && value[2] == 'r' && value[3] == ':') 403 { 404 isptr = true; 405 value += 4; 406 } 407 408 char* type = value; 409 410 for (; *type; type++) 411 if (*type == ':') 412 { 413 *type = '\0'; 414 type++; 415 break; 416 } 417 418 if (!*type) 419 DDrStartupMessage("badly formed bsl definition for \"%s\"", name); 420 421 if (!strcmp(type, "int")) 422 bsl_type = sl_int32; 423 else if (!strcmp(type, "string")) 424 bsl_type = sl_str32; 425 else if (!strcmp(type, "float")) 426 bsl_type = sl_float; 427 else if (!strcmp(type, "bool")) 428 bsl_type = sl_bool; 429 else 430 { 431 DDrStartupMessage("unknown type in bsl definition for \"%s\"", name); 432 return true; 433 } 434 435 if (isptr) 436 { 437 char* bsl_var = malloc(strlen(name) + 1); 438 memcpy(bsl_var, name, strlen(name) + 1); 439 switch (bsl_type) 440 { 441 case sl_int32: 442 SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", (int32_t*)(uint32_t)inifile_parseint(value, false)); 443 break; 444 case sl_float: 445 SLrGlobalVariable_Register_Float(bsl_var, "see daodan.ini", (float*)(uint32_t)inifile_parseint(value, false)); 446 break; 447 default: 448 break; 449 } 450 } 451 else 452 { 453 char* bsl_var = malloc(strlen(name) + 1 + sizeof(int32_t)); 454 int32_t* bsl_val = (int32_t*)bsl_var; 455 bsl_var += sizeof(int32_t); 456 memcpy(bsl_var, name, strlen(name) + 1); 457 458 switch (bsl_type) 459 { 460 case sl_int32: 461 *bsl_val = inifile_parseint(value, false); 462 SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", bsl_val); 463 break; 464 case sl_float: 465 break; 466 default: 467 break; 468 } 469 } 470 } 471 return true; 472 } 473 474 void SLrConfig() 475 { 476 DDrStartupMessage("re-parsing daodan.ini for bsl..."); 477 inifile_read("daodan.ini", SLrIniCallback); 478 DDrStartupMessage("finished parsing"); 479 } 480 388 481 void SLrDaodan_Initalize() 389 482 { 483 SLrConfig(); 484 390 485 SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul); 391 486 SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul); … … 411 506 SLrScript_Command_Register_ReturnType("sprintf", "C-style sprintf.", "format:string arg1 arg2 ...", sl_str32, bsl_sprintf); 412 507 SLrScript_Command_Register_ReturnType("dprintcolor", "prints to console in color", "text:string [color: r b g] [color: r b g]", sl_void, bsl_dprintcolored); 413 414 415 508 416 509 SLrScript_Command_Register_ReturnType("d_dprint", "prints to console in color", "text:string [color: r b g] [color: r b g]", sl_void, bsl_dprintcolored); 417 510 } 511 418 512 void SLrDaodan_Patch() 419 513 { 420 514 DDrPatch_Int32(OniExe + 0x000f3755, (int)cinematic_start_patch); 421 515 } 422 -
Daodan/src/inifile.h
r352 r451 4 4 5 5 #include <stdbool.h> 6 #include <stdint.h> 6 7 7 8 enum {inifile_cantread = -20}; … … 9 10 typedef bool (*inifile_callback)(char* section, bool newsection, char* name, char* value); 10 11 12 char* inifile_cleanstr(char* str); 13 int64_t inifile_parseint(const char* str, bool issigned); 11 14 bool inifile_read(const char* filename, inifile_callback callback); 12 15 -
Daodan/src/inifile_reader.c
r352 r451 6 6 7 7 #include "inifile.h" 8 /* 8 9 9 char* inifile_cleanstr(char* str) 10 10 { 11 int i; 12 for (i = strlen(str) - 1; i >= 0; i --) 13 if (!isspace(str[i])) 14 { 15 str[i + 1] = '\0'; 16 break; 17 } 18 11 19 while (isspace(*str)) 12 20 str++; 13 21 14 int i;15 for (i = 0; str[i]; i ++)16 {17 if18 }19 20 22 return str; 21 23 } 22 */ 24 25 int64_t inifile_parseint(const char* str, bool issigned) 26 { 27 int64_t ret = 0; 28 bool neg = false; 29 if (str[0] == '0' && str[1] == 'x') 30 { 31 int i; 32 if (str[2] == '\0') 33 return 0x100000000LL; 34 35 for (i = 0, str += 2; *str; i++, str++) 36 { 37 if (i == 8) 38 return 0x100000000LL; 39 40 ret <<= 4; 41 if (*str >= '0' && *str <= '9') 42 ret |= *str - '0'; 43 else if (*str >= 'a' && *str <= 'f') 44 ret |= *str - 'a' + 10; 45 else if (*str >= 'A' && *str <= 'F') 46 ret |= *str - 'A' + 10; 47 else 48 return 0x100000000LL; 49 } 50 return ret; 51 } 52 else if ((*str >= '0' && *str <= '9') || (neg = (*str == '-'))) 53 { 54 int i; 55 if (neg) 56 str++; 57 for (i = 0; *str; i++, str++) 58 { 59 if (i == 10) 60 return 0x100000000LL; 61 else if (i == 9 && !issigned && (ret > 429496729LL || (ret == 429496729LL && *str > '5'))) 62 return 0x100000000LL; 63 else if (i == 9 && issigned && (ret > 214748364LL || (ret == 214748364LL && *str > (neg ? '8' : '7')))) 64 return 0x100000000LL; 65 66 ret *= 10; 67 if (*str >= '0' && *str <= '9') 68 ret += *str - '0'; 69 else 70 return 0x100000000LL; 71 } 72 if (neg) 73 ret *= -1; 74 return ret; 75 } 76 else 77 return 0x100000000LL; 78 } 79 23 80 bool inifile_read(const char* filename, inifile_callback callback) 24 81 { -
Daodan/src/inifile_test.c
r346 r451 1 1 #include <stdio.h> 2 2 #include <stdbool.h> 3 #include <string.h> 3 4 #include "inifile.h" 4 5 … … 8 9 puts("New Section!"); 9 10 printf("Section: %s Name: %s Value: %s\n", section, name, value); 11 if (!stricmp(name, "cleantest")) 12 printf(" CleanTest: \"%s\" = \"%s\"\n", value, inifile_cleanstr(value)); 13 if (!stricmp(name, "inttest")) 14 printf(" IntTest: %s = %u\n", value, (uint32_t)inifile_parseint(value, false)); 15 if (!stricmp(name, "sinttest")) 16 printf(" IntTest: %s = %d\n", value, (int32_t)inifile_parseint(value, true)); 10 17 return true; 11 18 }
Note:
See TracChangeset
for help on using the changeset viewer.