Pārlūkot izejas kodu

Fixed a few issues with TXT item db parsing (#2940)

Fixed an issue with comments in the middle of the line
Fixed the curly mismatches not being reported

Fixes #2938

Thanks to @kaninhot004
Lemongrass3110 7 gadi atpakaļ
vecāks
revīzija
d7f226a66b
2 mainītis faili ar 16 papildinājumiem un 8 dzēšanām
  1. 1 1
      db/re/item_db.txt
  2. 15 7
      src/map/itemdb.cpp

+ 1 - 1
db/re/item_db.txt

@@ -11483,7 +11483,7 @@
 27166,Faceworm_Egg_Card,Faceworm Egg Card,6,20,,10,,,,,,,,64,,,,,{ .@r = getrefine(); .@sub = 2+(.@r >= 9 ? 3 : .@r >= 7 ? 1 : 0); bonus bNearAtkDef,.@sub; bonus bMagicAtkDef,.@sub; },{},{}
 27167,Faceworm_Larva_Card,Faceworm Larva Card,6,20,,10,,,,,,,,4,,,,,{ bonus2 bSubEle,Ele_Neutral,15; bonus2 bMagicAddSize,Size_All,getrefine()*3; },{},{}
 27168,Irene_High_Elder_Card,Irene High Elder Card,6,20,,10,,,,,,,,4,,,,,{ bonus bHit,10 + 5 * (getrefine()/3); },{},{}
-27169,Payon_Soldier_Card,Payon Soldier Card,6,20,,10,,,,,,,,2,,,,,{ .@atk = 5; .@r = getrefine(); if(getiteminfo(getequipid(EQI_HAND_R),11) == W_SPEAR && .@r >= 10){ .@atk += 20; if(.@r >= 14){ .@atk += 20; } } } bonus bAtk,.@atk; bonus bMatk,.@atk; },{},{}
+27169,Payon_Soldier_Card,Payon Soldier Card,6,20,,10,,,,,,,,2,,,,,{ .@atk = 5; .@r = getrefine(); if(getiteminfo(getequipid(EQI_HAND_R),11) == W_SPEAR && .@r >= 10){ .@atk += 20; if(.@r >= 14){ .@atk += 20; } } bonus bAtk,.@atk; bonus bMatk,.@atk; },{},{}
 27181,Airship_Raid_Card,Airship Raid Card,6,20,,10,,,,,,,,2,,,,,{ .@r = getrefine(); bonus bLongAtkRate,1 + .@r/2; bonus bCritical,.@r/2; },{},{}
 27182,Captain_Felock_Card,Captain Felock Card,6,20,,10,,,,,,,,2,,,,,{ bonus bAtk,30; .@r = getrefine(); bonus2 bSkillAtk,"RL_AM_BLAST",.@r >= 10 ? 60 : 30; bonus2 bSkillAtk,"RL_HAMMER_OF_GOD",.@r >= 10 ? 60 : 30; },{},{}
 27183,Gigantes_Card,Gigantes Card,6,20,,10,,,,,,,,128,,,,,{ bonus bAtk,20; if(readparam(bStr) >= 120) { bonus bAtk,20; bonus bAspdRate,-3; } },{},{}

+ 15 - 7
src/map/itemdb.cpp

@@ -1419,6 +1419,12 @@ static int itemdb_readdb(void){
 				continue;
 			memset(str, 0, sizeof(str));
 
+			p = strstr(line,"//");
+
+			if( p != nullptr ){
+				*p = '\0';
+			}
+
 			p = line;
 			while( ISSPACE(*p) )
 				++p;
@@ -1446,14 +1452,14 @@ static int itemdb_readdb(void){
 				ShowError("itemdb_readdb: Invalid format (Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
 				continue;
 			}
-			str[19] = p;
+			str[19] = p + 1;
 			p = strstr(p+1,"},");
 			if( p == NULL )
 			{
 				ShowError("itemdb_readdb: Invalid format (Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
 				continue;
 			}
-			p[1] = '\0';
+			*p = '\0';
 			p += 2;
 
 			// OnEquip_Script
@@ -1462,14 +1468,14 @@ static int itemdb_readdb(void){
 				ShowError("itemdb_readdb: Invalid format (OnEquip_Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
 				continue;
 			}
-			str[20] = p;
+			str[20] = p + 1;
 			p = strstr(p+1,"},");
 			if( p == NULL )
 			{
 				ShowError("itemdb_readdb: Invalid format (OnEquip_Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
 				continue;
 			}
-			p[1] = '\0';
+			*p = '\0';
 			p += 2;
 
 			// OnUnequip_Script (last column)
@@ -1478,9 +1484,10 @@ static int itemdb_readdb(void){
 				ShowError("itemdb_readdb: Invalid format (OnUnequip_Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
 				continue;
 			}
-			str[21] = p;
+			str[21] = p + 1;
+			p = &str[21][strlen(str[21]) - 2];
 
-			if ( str[21][strlen(str[21])-2] != '}' ) {
+			if ( *p != '}' ) {
 				/* lets count to ensure it's not something silly e.g. a extra space at line ending */
 				int v, lcurly = 0, rcurly = 0;
 
@@ -1496,8 +1503,9 @@ static int itemdb_readdb(void){
 					continue;
 				}
 			}
+			*p = '\0';
 
-			if (!itemdb_parse_dbrow(str, path, lines, 0))
+			if (!itemdb_parse_dbrow(str, path, lines, SCRIPT_IGNORE_EXTERNAL_BRACKETS))
 				continue;
 
 			count++;