summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-05-05 13:57:07 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-05-05 13:57:07 +0000
commit9dc87bf9db25237ae4d904f92311352e6171d372 (patch)
treefe58100dd34d6ee12120f5a2d165b84cdb5a3ab2
parent0782cabc543c151f724f38f5132ab948f6346af4 (diff)
downloadhercules-9dc87bf9db25237ae4d904f92311352e6171d372.tar.gz
hercules-9dc87bf9db25237ae4d904f92311352e6171d372.tar.bz2
hercules-9dc87bf9db25237ae4d904f92311352e6171d372.tar.xz
hercules-9dc87bf9db25237ae4d904f92311352e6171d372.zip
- imported the latest working grfio code from stable
- re-added usage of managed allocation routines in grfio - eol-styled some new files - some cosmetic fixes here and there git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10468 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--conf-tmpl/grf-files.txt24
-rw-r--r--db/mob_pouch.txt672
-rw-r--r--src/common/grfio.c457
-rw-r--r--src/common/grfio.h2
-rw-r--r--src/common/mapindex.c4
-rw-r--r--src/login_sql/login.c2
-rw-r--r--src/map/map.c19
-rw-r--r--src/map/map.h11
-rw-r--r--src/map/npc.c8
-rw-r--r--src/map/pc.c2
-rw-r--r--src/map/status.h48
-rw-r--r--src/map/trade.c2
-rw-r--r--src/tool/mapcache.c4
13 files changed, 560 insertions, 695 deletions
diff --git a/conf-tmpl/grf-files.txt b/conf-tmpl/grf-files.txt
index 665ca74b4..39cee544e 100644
--- a/conf-tmpl/grf-files.txt
+++ b/conf-tmpl/grf-files.txt
@@ -1,12 +1,12 @@
-//-----------------------------------------
-// GRF List
-//-----------------------------------------
-// grf: C:\path\to\RO\data.grf
-// You may add more in this format
-// grf: <data file path>
-
-//------ Others ---------------------------
-
-// Data Directory (without the actual data\ though)
-// the below example would use C:\path\to\RO\data\
-//data_dir: C:\path\to\RO\
+//-----------------------------------------
+// GRF List
+//-----------------------------------------
+// grf: C:\path\to\RO\data.grf
+// You may add more in this format
+// grf: <data file path>
+
+//------ Others ---------------------------
+
+// Data Directory (without the actual data\ though)
+// the below example would use C:\path\to\RO\data\
+//data_dir: C:\path\to\RO\
diff --git a/db/mob_pouch.txt b/db/mob_pouch.txt
index dcb659b92..5a162666e 100644
--- a/db/mob_pouch.txt
+++ b/db/mob_pouch.txt
@@ -1,336 +1,336 @@
-// Red Pouch of Surprise Summonable Monsters Database
-//
-// Structure of Database:
-// MobID,DummyName,Rate
-
-0,Poring,1002
-1001,Scorpion,214285
-1002,Poring,1000000
-1004,Hornet,357142
-1005,Familiar,357142
-1007,Fabre,428571
-1008,Pupa,71428
-1009,Condor,357142
-1010,Willow,357142
-1011,Chonchon,357142
-1012,Roda Frog,357142
-1013,Wolf,357142
-1014,Spore,357142
-1015,Zombie,357142
-1016,Archer Skeleton,214285
-1018,Creamy,357142
-1019,Peco Peco,357142
-1020,Mandragora,357142
-1023,Orc Warrior,214285
-1024,Wormtail,357142
-1025,Boa,357142
-1026,Munak,214285
-1028,Soldier Skeleton,214285
-1029,Isis,71428
-1030,Anacondaq,214285
-1031,Poporing,357142
-1032,Verit,214285
-1033,Elder Willow,214285
-1034,Thara Frog,214285
-1035,Hunter Fly,71428
-1036,Ghoul,214285
-1037,Side Winder,71428
-1040,Golem,214285
-1041,Mummy,214285
-1042,Steel Chonchon,357142
-1044,Obeaune,214285
-1045,Marc,214285
-1047,Peco Peco Egg,71428
-1048,Thief Bug Egg,71428
-1049,Picky,357142
-1050,Picky,357142
-1051,Thief Bug,357142
-1052,Rocker,357142
-1053,Thief Bug Female,357142
-1054,Thief Bug Male,357142
-1055,Muka,357142
-1056,Smokie,357142
-1057,Yoyo,357142
-1058,Metaller,214285
-1060,Bigfoot,214285
-1061,Nightmare,71428
-1062,Santa Poring,357142
-1063,Lunatic,357142
-1064,Megalodon,214285
-1065,Strouf,214285
-1066,Vadon,357142
-1067,Cornutus,214285
-1068,Hydra,357142
-1069,Swordfish,214285
-1070,Kukre,357142
-1071,Pirate Skeleton,214285
-1072,Kaho,71428
-1073,Crab,214285
-1074,Shellfish,357142
-1076,Skeleton,357142
-1077,Poison Spore,357142
-1078,Red Plant,71428
-1079,Blue Plant,71428
-1080,Green Plant,71428
-1081,Yellow Plant,71428
-1082,White Plant,71428
-1083,Shining Plant,71428
-1084,Black Mushroom,71428
-1085,Red Mushroom,71428
-1088,Vocal,71428
-1089,Toad,71428
-1090,Mastering,71428
-1091,Dragon Fly,71428
-1092,Vagabond Wolf,71428
-1093,Eclipse,71428
-1094,Ambernite,357142
-1095,Andre,357142
-1096,Angeling,71428
-1097,Ant Egg,71428
-1099,Argiope,71428
-1100,Argos,214285
-1101,Baphomet Jr.,71428
-1102,Bathory,71428
-1103,Caramel,214285
-1104,Coco,357142
-1105,Deniro,357142
-1106,Desert Wolf,214285
-1107,Baby Desert Wolf,71428
-1108,Deviace,71428
-1109,Deviruchi,71428
-1110,Dokebi,214285
-1111,Drainliar,214285
-1113,Drops,357142
-1114,Dustiness,214285
-1116,Eggyra,214285
-1117,Evil Druid,71428
-1118,Flora,214285
-1119,Frilldora,214285
-1120,Ghostring,71428
-1121,Giearth,214285
-1122,Goblin,214285
-1123,Goblin,214285
-1124,Goblin,214285
-1125,Goblin,214285
-1126,Goblin,214285
-1127,Hode,214285
-1128,Horn,357142
-1129,Horong,214285
-1130,Jakk,214285
-1131,Joker,71428
-1132,Khalitzburg,71428
-1133,Kobold,214285
-1134,Kobold,214285
-1135,Kobold,214285
-1138,Magnolia,214285
-1139,Mantis,214285
-1140,Marduk,214285
-1141,Marina,214285
-1142,Marine Sphere,214285
-1143,Marionette,71428
-1144,Marse,214285
-1145,Martin,357142
-1146,Matyr,214285
-1148,Medusa,71428
-1149,Minorous,71428
-1151,Myst,214285
-1152,Orc Skeleton,214285
-1153,Orc Zombie,214285
-1154,Pasana,71428
-1155,Petite,71428
-1156,Petite,71428
-1158,Phen,214285
-1160,Piere,357142
-1161,Plankton,357142
-1163,Raydric,71428
-1164,Requiem,214285
-1165,Sandman,214285
-1166,Savage,214285
-1167,Savage Babe,357142
-1169,Skeleton Worker,214285
-1170,Sohee,214285
-1174,Stainer,357142
-1175,Tarou,357142
-1176,Vitata,214285
-1177,Zenorc,214285
-1178,Zerom,214285
-1179,Whisper,71428
-1180,Nine Tail,71428
-1182,Thief Mushroom,71428
-1185,Whisper,71428
-1186,Giant Whisper,71428
-1188,Bongun,214285
-1189,Orc Archer,71428
-1191,Mimic,71428
-1192,Wraith,71428
-1193,Alarm,71428
-1194,Arclouze,71428
-1195,Rideword,71428
-1196,Skeleton Prisoner,71428
-1197,Zombie Prisoner,71428
-1199,Punk,71428
-1200,Zealotus,71428
-1201,Rybio,71428
-1202,Phendark,71428
-1203,Mysteltainn,71428
-1204,Ogretooth,71428
-1205,Executioner,71428
-1206,Anolian,71428
-1207,Sting,71428
-1208,Wanderer,71428
-1209,Cramp,71428
-1211,Brilight,71428
-1212,Iron Fist,71428
-1213,High Orc,71428
-1214,Choco,71428
-1215,Stem Worm,214285
-1216,Penomena,71428
-1219,Abysmal Knight,71428
-1242,Marin,357142
-1243,Sasquatch,214285
-1245,Christmas Goblin,71428
-1246,Christmas Cookie,214285
-1248,Cruiser,214285
-1249,Myst Case,214285
-1250,Chepet,71428
-1253,Gargoyle,71428
-1254,Raggler,214285
-1255,Nereid,214285
-1256,Pest,214285
-1257,Injustice,71428
-1258,Goblin Archer,214285
-1259,Gryphon,71428
-1260,Dark Frame,71428
-1261,Wild Rose,214285
-1262,Mutant Dragonoid,71428
-1263,Wind Ghost,71428
-1264,Merman,71428
-1265,Cookie,214285
-1266,Aster,357142
-1267,Carat,71428
-1268,Bloody Knight,71428
-1269,Clock,71428
-1270,Clock Tower Manager,71428
-1271,Alligator,71428
-1273,Orc Lady,214285
-1274,Megalith,71428
-1275,Alice,71428
-1276,Raydric Archer,71428
-1277,Greatest General,214285
-1278,Stalactic Golem,71428
-1279,Tri Joint,214285
-1280,Goblin Steamrider,214285
-1281,Sage Worm,71428
-1282,Kobold Archer,214285
-1283,Chimera,71428
-1289,Maya Purple,71428
-1290,Skeleton General,71428
-1291,Wraith Dead,71428
-1292,Mini Demon,71428
-1293,Creamy Fear,71428
-1294,Killer Mantis,71428
-1295,Owl Baron,71428
-1296,Kobold Leader,71428
-1297,Ancient Mummy,71428
-1298,Zombie Master,71428
-1299,Goblin Leader,71428
-1300,Caterpillar,71428
-1301,Am Mut,71428
-1302,Dark Illusion,71428
-1303,Giant Hornet,71428
-1304,Giant Spider,71428
-1305,Ancient Worm,71428
-1306,Leib Olmai,71428
-1307,Cat o' Nine Tails,71428
-1308,Panzer Goblin,71428
-1309,Gajomart,71428
-1310,Majoruros,71428
-1311,Gullinbursti,71428
-1313,Mobster,71428
-1314,Permeter,71428
-1315,Assaulter,71428
-1316,Solider,71428
-1317,Seal,71428
-1318,Heater,71428
-1319,Freezer,71428
-1320,Owl Duke,71428
-1321,Dragon Tail,71428
-1322,Spring Rabbit,71428
-1323,Sea Otter,71428
-1365,Apocalypse,71428
-1366,Lava Golem,71428
-1367,Blazer,71428
-1368,Geographer,71428
-1369,Grand Peco,71428
-1370,Succubus,71428
-1371,False Angel,71428
-1372,Goat,71428
-1374,Incubus,71428
-1375,The Paper,71428
-1376,Harpy,71428
-1377,Elder,71428
-1378,Demon Pungus,71428
-1379,Nightmare Terror,71428
-1380,Driller,71428
-1381,Grizzly,71428
-1382,Diabolic,71428
-1383,Explosion,71428
-1384,Deleter,71428
-1385,Deleter,71428
-1386,Sleeper,71428
-1387,Gig,71428
-1390,Violy,71428
-1391,Galapago,71428
-1392,Rotar Zairo,214285
-1400,Karakasa,214285
-1401,Shinobi,71428
-1402,Poison Toad,71428
-1403,Firelock Soldier,71428
-1404,Miyabi Doll,214285
-1405,Tengu,71428
-1406,Kapha,71428
-1408,Bloody Butterfly,71428
-1409,Dumpling Child,214285
-1410,Enchanted Peach Tree,71428
-1412,Taoist Hermit,71428
-1413,Hermit Plant,71428
-1415,Baby Leopard,214285
-1416,Evil Nymph,71428
-1417,Zipper Bear,214285
-1493,Dryad,71428
-1494,Beetle King,214285
-1495,Stone Shooter,71428
-1497,Wooden Golem,71428
-1498,Wootan Shooter,214285
-1499,Wootan Fighter,71428
-1500,Parasite,214285
-1503,Gibbet,71428
-1504,Dullahan,71428
-1505,Loli Ruri,71428
-1506,Disguise,71428
-1507,Bloody Murderer,71428
-1508,Quve,214285
-1509,Lude,214285
-1510,Heirozoist,71428
-1512,Yao Jun,71428
-1513,Mao Guai,71428
-1514,Zhu Po Long,71428
-1515,Garm Baby,71428
-1516,Mi Gao,71428
-1517,Jing Guai,71428
-1519,Green Maiden,71428
-1520,Boiled Rice,71428
-1582,Deviling,71428
-1584,Tamruan,71428
-1586,Leaf Cat,71428
-1587,Kraben,71428
-1613,Metaling,71428
-1614,Mineral,71428
-1615,Obsidian,71428
-1616,Pitman,71428
-1617,Old Stove,71428
-1618,Ungoliant,71428
-1619,Porcellio,71428
-1620,Noxious,71428
-1621,Venomous,71428
-1622,Teddy Bear,71428
+// Red Pouch of Surprise Summonable Monsters Database
+//
+// Structure of Database:
+// MobID,DummyName,Rate
+
+0,Poring,1002
+1001,Scorpion,214285
+1002,Poring,1000000
+1004,Hornet,357142
+1005,Familiar,357142
+1007,Fabre,428571
+1008,Pupa,71428
+1009,Condor,357142
+1010,Willow,357142
+1011,Chonchon,357142
+1012,Roda Frog,357142
+1013,Wolf,357142
+1014,Spore,357142
+1015,Zombie,357142
+1016,Archer Skeleton,214285
+1018,Creamy,357142
+1019,Peco Peco,357142
+1020,Mandragora,357142
+1023,Orc Warrior,214285
+1024,Wormtail,357142
+1025,Boa,357142
+1026,Munak,214285
+1028,Soldier Skeleton,214285
+1029,Isis,71428
+1030,Anacondaq,214285
+1031,Poporing,357142
+1032,Verit,214285
+1033,Elder Willow,214285
+1034,Thara Frog,214285
+1035,Hunter Fly,71428
+1036,Ghoul,214285
+1037,Side Winder,71428
+1040,Golem,214285
+1041,Mummy,214285
+1042,Steel Chonchon,357142
+1044,Obeaune,214285
+1045,Marc,214285
+1047,Peco Peco Egg,71428
+1048,Thief Bug Egg,71428
+1049,Picky,357142
+1050,Picky,357142
+1051,Thief Bug,357142
+1052,Rocker,357142
+1053,Thief Bug Female,357142
+1054,Thief Bug Male,357142
+1055,Muka,357142
+1056,Smokie,357142
+1057,Yoyo,357142
+1058,Metaller,214285
+1060,Bigfoot,214285
+1061,Nightmare,71428
+1062,Santa Poring,357142
+1063,Lunatic,357142
+1064,Megalodon,214285
+1065,Strouf,214285
+1066,Vadon,357142
+1067,Cornutus,214285
+1068,Hydra,357142
+1069,Swordfish,214285
+1070,Kukre,357142
+1071,Pirate Skeleton,214285
+1072,Kaho,71428
+1073,Crab,214285
+1074,Shellfish,357142
+1076,Skeleton,357142
+1077,Poison Spore,357142
+1078,Red Plant,71428
+1079,Blue Plant,71428
+1080,Green Plant,71428
+1081,Yellow Plant,71428
+1082,White Plant,71428
+1083,Shining Plant,71428
+1084,Black Mushroom,71428
+1085,Red Mushroom,71428
+1088,Vocal,71428
+1089,Toad,71428
+1090,Mastering,71428
+1091,Dragon Fly,71428
+1092,Vagabond Wolf,71428
+1093,Eclipse,71428
+1094,Ambernite,357142
+1095,Andre,357142
+1096,Angeling,71428
+1097,Ant Egg,71428
+1099,Argiope,71428
+1100,Argos,214285
+1101,Baphomet Jr.,71428
+1102,Bathory,71428
+1103,Caramel,214285
+1104,Coco,357142
+1105,Deniro,357142
+1106,Desert Wolf,214285
+1107,Baby Desert Wolf,71428
+1108,Deviace,71428
+1109,Deviruchi,71428
+1110,Dokebi,214285
+1111,Drainliar,214285
+1113,Drops,357142
+1114,Dustiness,214285
+1116,Eggyra,214285
+1117,Evil Druid,71428
+1118,Flora,214285
+1119,Frilldora,214285
+1120,Ghostring,71428
+1121,Giearth,214285
+1122,Goblin,214285
+1123,Goblin,214285
+1124,Goblin,214285
+1125,Goblin,214285
+1126,Goblin,214285
+1127,Hode,214285
+1128,Horn,357142
+1129,Horong,214285
+1130,Jakk,214285
+1131,Joker,71428
+1132,Khalitzburg,71428
+1133,Kobold,214285
+1134,Kobold,214285
+1135,Kobold,214285
+1138,Magnolia,214285
+1139,Mantis,214285
+1140,Marduk,214285
+1141,Marina,214285
+1142,Marine Sphere,214285
+1143,Marionette,71428
+1144,Marse,214285
+1145,Martin,357142
+1146,Matyr,214285
+1148,Medusa,71428
+1149,Minorous,71428
+1151,Myst,214285
+1152,Orc Skeleton,214285
+1153,Orc Zombie,214285
+1154,Pasana,71428
+1155,Petite,71428
+1156,Petite,71428
+1158,Phen,214285
+1160,Piere,357142
+1161,Plankton,357142
+1163,Raydric,71428
+1164,Requiem,214285
+1165,Sandman,214285
+1166,Savage,214285
+1167,Savage Babe,357142
+1169,Skeleton Worker,214285
+1170,Sohee,214285
+1174,Stainer,357142
+1175,Tarou,357142
+1176,Vitata,214285
+1177,Zenorc,214285
+1178,Zerom,214285
+1179,Whisper,71428
+1180,Nine Tail,71428
+1182,Thief Mushroom,71428
+1185,Whisper,71428
+1186,Giant Whisper,71428
+1188,Bongun,214285
+1189,Orc Archer,71428
+1191,Mimic,71428
+1192,Wraith,71428
+1193,Alarm,71428
+1194,Arclouze,71428
+1195,Rideword,71428
+1196,Skeleton Prisoner,71428
+1197,Zombie Prisoner,71428
+1199,Punk,71428
+1200,Zealotus,71428
+1201,Rybio,71428
+1202,Phendark,71428
+1203,Mysteltainn,71428
+1204,Ogretooth,71428
+1205,Executioner,71428
+1206,Anolian,71428
+1207,Sting,71428
+1208,Wanderer,71428
+1209,Cramp,71428
+1211,Brilight,71428
+1212,Iron Fist,71428
+1213,High Orc,71428
+1214,Choco,71428
+1215,Stem Worm,214285
+1216,Penomena,71428
+1219,Abysmal Knight,71428
+1242,Marin,357142
+1243,Sasquatch,214285
+1245,Christmas Goblin,71428
+1246,Christmas Cookie,214285
+1248,Cruiser,214285
+1249,Myst Case,214285
+1250,Chepet,71428
+1253,Gargoyle,71428
+1254,Raggler,214285
+1255,Nereid,214285
+1256,Pest,214285
+1257,Injustice,71428
+1258,Goblin Archer,214285
+1259,Gryphon,71428
+1260,Dark Frame,71428
+1261,Wild Rose,214285
+1262,Mutant Dragonoid,71428
+1263,Wind Ghost,71428
+1264,Merman,71428
+1265,Cookie,214285
+1266,Aster,357142
+1267,Carat,71428
+1268,Bloody Knight,71428
+1269,Clock,71428
+1270,Clock Tower Manager,71428
+1271,Alligator,71428
+1273,Orc Lady,214285
+1274,Megalith,71428
+1275,Alice,71428
+1276,Raydric Archer,71428
+1277,Greatest General,214285
+1278,Stalactic Golem,71428
+1279,Tri Joint,214285
+1280,Goblin Steamrider,214285
+1281,Sage Worm,71428
+1282,Kobold Archer,214285
+1283,Chimera,71428
+1289,Maya Purple,71428
+1290,Skeleton General,71428
+1291,Wraith Dead,71428
+1292,Mini Demon,71428
+1293,Creamy Fear,71428
+1294,Killer Mantis,71428
+1295,Owl Baron,71428
+1296,Kobold Leader,71428
+1297,Ancient Mummy,71428
+1298,Zombie Master,71428
+1299,Goblin Leader,71428
+1300,Caterpillar,71428
+1301,Am Mut,71428
+1302,Dark Illusion,71428
+1303,Giant Hornet,71428
+1304,Giant Spider,71428
+1305,Ancient Worm,71428
+1306,Leib Olmai,71428
+1307,Cat o' Nine Tails,71428
+1308,Panzer Goblin,71428
+1309,Gajomart,71428
+1310,Majoruros,71428
+1311,Gullinbursti,71428
+1313,Mobster,71428
+1314,Permeter,71428
+1315,Assaulter,71428
+1316,Solider,71428
+1317,Seal,71428
+1318,Heater,71428
+1319,Freezer,71428
+1320,Owl Duke,71428
+1321,Dragon Tail,71428
+1322,Spring Rabbit,71428
+1323,Sea Otter,71428
+1365,Apocalypse,71428
+1366,Lava Golem,71428
+1367,Blazer,71428
+1368,Geographer,71428
+1369,Grand Peco,71428
+1370,Succubus,71428
+1371,False Angel,71428
+1372,Goat,71428
+1374,Incubus,71428
+1375,The Paper,71428
+1376,Harpy,71428
+1377,Elder,71428
+1378,Demon Pungus,71428
+1379,Nightmare Terror,71428
+1380,Driller,71428
+1381,Grizzly,71428
+1382,Diabolic,71428
+1383,Explosion,71428
+1384,Deleter,71428
+1385,Deleter,71428
+1386,Sleeper,71428
+1387,Gig,71428
+1390,Violy,71428
+1391,Galapago,71428
+1392,Rotar Zairo,214285
+1400,Karakasa,214285
+1401,Shinobi,71428
+1402,Poison Toad,71428
+1403,Firelock Soldier,71428
+1404,Miyabi Doll,214285
+1405,Tengu,71428
+1406,Kapha,71428
+1408,Bloody Butterfly,71428
+1409,Dumpling Child,214285
+1410,Enchanted Peach Tree,71428
+1412,Taoist Hermit,71428
+1413,Hermit Plant,71428
+1415,Baby Leopard,214285
+1416,Evil Nymph,71428
+1417,Zipper Bear,214285
+1493,Dryad,71428
+1494,Beetle King,214285
+1495,Stone Shooter,71428
+1497,Wooden Golem,71428
+1498,Wootan Shooter,214285
+1499,Wootan Fighter,71428
+1500,Parasite,214285
+1503,Gibbet,71428
+1504,Dullahan,71428
+1505,Loli Ruri,71428
+1506,Disguise,71428
+1507,Bloody Murderer,71428
+1508,Quve,214285
+1509,Lude,214285
+1510,Heirozoist,71428
+1512,Yao Jun,71428
+1513,Mao Guai,71428
+1514,Zhu Po Long,71428
+1515,Garm Baby,71428
+1516,Mi Gao,71428
+1517,Jing Guai,71428
+1519,Green Maiden,71428
+1520,Boiled Rice,71428
+1582,Deviling,71428
+1584,Tamruan,71428
+1586,Leaf Cat,71428
+1587,Kraben,71428
+1613,Metaling,71428
+1614,Mineral,71428
+1615,Obsidian,71428
+1616,Pitman,71428
+1617,Old Stove,71428
+1618,Ungoliant,71428
+1619,Porcellio,71428
+1620,Noxious,71428
+1621,Venomous,71428
+1622,Teddy Bear,71428
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 79978f3ac..314581abc 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -1,90 +1,61 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-/*********************************************************************
- *
- * Ragnarok Online Emulator : grfio.c -- grf file I/O Module
- *--------------------------------------------------------------------
- * special need library : zlib
- *********************************************************************
- * $Id: grfio.c,v 1.2 2004/09/29 17:31:49 kalaspuff Exp $
- *
- * 2002/12/18... the original edition
- * 2003/01/23 ... Code correction
- * 2003/02/01 ... An addition and decryption processing are improved for LocalFile and two or more GRF(s) check processing.
- * 2003/02/02 ... Even if there is no grf it does not stop -- as -- correction
- * 2003/02/02... grf reading specification can be added later -- as -- correction (grfio_add function addition)
- * 2003/02 / 03... at the time of grfio_resourcecheck processing the entry addition processing method -- correction
- * 2003/02/05... change of the processing in grfio_init
- * 2003/02/23... a local file check -- GRFIO_LOCAL -- switch (Defoe -- Function Off)
- * 2003/10/21 ... The data of alpha client was read.
- * 2003/11/10 ... Ready new grf format.
- * 2003/11/11 ... version check fix & bug fix
- * 2006/04/16 ... fixed crash grfio_find_file when file is not found.
- */
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
+#include <sys/stat.h>
#include "grfio.h"
-#include <sys/stat.h>
#include <zlib.h>
-#include "../common/mmo.h"
+
+#include "../common/cbasetypes.h"
#include "../common/showmsg.h"
#include "../common/malloc.h"
-typedef unsigned char BYTE;
-typedef unsigned short WORD;
-typedef unsigned long DWORD;
-
-//static char data_file[1024] = ""; // "data.grf";
-//static char sdata_file[1024] = ""; // "sdata.grf";
-//static char adata_file[1024] = ""; // "adata.grf";
-static char data_dir[1024] = ""; // "../";
//----------------------------
// file entry table struct
//----------------------------
-typedef struct {
- int srclen; // compressed size
- int srclen_aligned; //
+typedef struct _FILELIST {
+ int srclen; // compressed size
+ int srclen_aligned;
int declen; // original size
- int srcpos;
- int next; //[blackhole89] - like there can be only 2^15 files
- int cycle;
+ int srcpos; // position of entry in grf
+ int next; // index of next filelist entry with same hash (-1: end of entry chain)
+ int cycle;
char type;
char fn[128-4*5]; // file name
- char *fnd;
- signed char gentry; // read grf file select
+ char* fnd; // if the file was cloned, contains name of original file
+ char gentry; // read grf file select
} FILELIST;
-//gentry ... 0 : It acquires from a local file.
-// It acquires from the resource file of 1>=:gentry_table[gentry-1].
-// 1<=: Check a local file.
-// If it is, after re-setting to 0, it acquires from a local file.
-// If there is nothing, mark reversal will be carried out, and it will re-set, and will acquire from a resource file as well as 1>=.
-
-//Since char defines *FILELIST.gentry, the maximum which can be added by grfio_add becomes by 127 pieces.
-#define GENTRY_LIMIT 512
-#define FILELIST_LIMIT 1048576 // temporary maximum, and a theory top maximum are 2G.
+//gentry ... > 0 : data read from a grf file (gentry_table[gentry-1])
+//gentry ... 0 : data read from a local file (data directory)
+//gentry ... < 0 : entry "-(gentry)" is marked for a local file check
+// - if local file exists, gentry will be set to 0 (thus using the local file)
+// - if local file doesn't exist, sign is inverted (thus using the original file inside a grf)
+// (NOTE: this case is only used once (during startup) and only if GRFIO_LOCAL is enabled)
+// (NOTE: probably meant to be used to override grf contents by files in the data directory)
+//#define GRFIO_LOCAL
-//[blackhole89]
-#define malloc_tsetdword(a,b,c) memset(a,b,c)
+// stores info about every loaded file
+FILELIST* filelist = NULL;
+int filelist_entrys = 0;
+int filelist_maxentry = 0;
-static FILELIST *filelist = NULL;
-static int filelist_entrys = 0;
-static int filelist_maxentry = 0;
+// stores grf file names
+char** gentry_table = NULL;
+int gentry_entrys = 0;
+int gentry_maxentry = 0;
-static char **gentry_table = NULL;
-static int gentry_entrys = 0;
-static int gentry_maxentry = 0;
+// the path to the data directory
+char data_dir[1024] = "";
//----------------------------
// file list hash table
//----------------------------
-static int filelist_hash[256];
+int filelist_hash[256];
//----------------------------
// grf decode data table
@@ -133,50 +104,41 @@ static unsigned char NibbleData[4][64]={
0xa0, 0x9f, 0xf6, 0x5c, 0x6a, 0x09, 0x8d, 0xf0, 0x0f, 0xe3, 0x53, 0x25, 0x95, 0x36, 0x28, 0xcb,
}
};
-/*-----------------
- * long data get
- */
-static unsigned int getlong(unsigned char *p)
+
+// little endian char array to uint conversion
+static unsigned int getlong(unsigned char* p)
{
-// return *p+p[1]*256+(p[2]+p[3]*256)*65536;
- return p[0]
- | p[1] << 0x08
- | p[2] << 0x10
- | p[3] << 0x18; // Shinomori
+ return (p[0] | p[1] << 0x08 | p[2] << 0x10 | p[3] << 0x18);
}
/*==========================================
* Grf data decode : Subs
- *------------------------------------------
- */
-static void NibbleSwap(BYTE *Src, int len)
+ *------------------------------------------*/
+static void NibbleSwap(unsigned char* Src, int len)
{
for(;0<len;len--,Src++) {
*Src = (*Src>>4) | (*Src<<4);
}
}
-static void BitConvert(BYTE *Src,char *BitSwapTable)
+static void BitConvert(unsigned char* Src, char* BitSwapTable)
{
int lop,prm;
- BYTE tmp[8];
-// *(DWORD*)tmp=*(DWORD*)(tmp+4)=0;
- malloc_tsetdword(tmp,0,8);
+ unsigned char tmp[8];
+ memset(tmp,0,8);
for(lop=0;lop!=64;lop++) {
prm = BitSwapTable[lop]-1;
if (Src[(prm >> 3) & 7] & BitMaskTable[prm & 7]) {
tmp[(lop >> 3) & 7] |= BitMaskTable[lop & 7];
}
}
-// *(DWORD*)Src = *(DWORD*)tmp;
-// *(DWORD*)(Src+4) = *(DWORD*)(tmp+4);
memcpy(Src,tmp,8);
}
-static void BitConvert4(BYTE *Src)
+static void BitConvert4(unsigned char* Src)
{
int lop,prm;
- BYTE tmp[8];
+ unsigned char tmp[8];
tmp[0] = ((Src[7]<<5) | (Src[4]>>3)) & 0x3f; // ..0 vutsr
tmp[1] = ((Src[4]<<1) | (Src[5]>>7)) & 0x3f; // ..srqpo n
tmp[2] = ((Src[4]<<5) | (Src[5]>>3)) & 0x3f; // ..o nmlkj
@@ -191,39 +153,38 @@ static void BitConvert4(BYTE *Src)
| (NibbleData[lop][tmp[lop*2+1]] & 0x0f);
}
- *(DWORD*)(tmp+4)=0;
+ memset(tmp+4,0,4);
for(lop=0;lop!=32;lop++) {
prm = BitSwapTable3[lop]-1;
if (tmp[prm >> 3] & BitMaskTable[prm & 7]) {
tmp[(lop >> 3) + 4] |= BitMaskTable[lop & 7];
}
}
-// *(DWORD*)Src ^= *(DWORD*)(tmp+4);
Src[0] ^= tmp[4];
Src[1] ^= tmp[5];
Src[2] ^= tmp[6];
Src[3] ^= tmp[7];
}
-static void decode_des_etc(BYTE *buf,int len,int type,int cycle)
+static void decode_des_etc(unsigned char* buf, size_t len, int type, int cycle)
{
- int lop,cnt=0;
+ size_t lop,cnt=0;
if(cycle<3) cycle=3;
else if(cycle<5) cycle++;
else if(cycle<7) cycle+=9;
else cycle+=15;
- for(lop=0;lop*8<len;lop++,buf+=8) {
- if(lop<20 || (type==0 && lop%cycle==0)){ // des
+ for(lop=0; lop*8<len; lop++, buf+=8)
+ {
+ if(lop<20 || (type==0 && lop%cycle==0)) { // des
BitConvert(buf,BitSwapTable1);
BitConvert4(buf);
BitConvert(buf,BitSwapTable2);
} else {
- if(cnt==7 && type==0){
- int a;
- BYTE tmp[8];
- *(DWORD*)tmp = *(DWORD*)buf;
- *(DWORD*)(tmp+4) = *(DWORD*)(buf+4);
+ if(cnt==7 && type==0) {
+ unsigned char a;
+ unsigned char tmp[8];
+ memcpy(tmp,buf,8);
cnt=0;
buf[0]=tmp[3];
buf[1]=tmp[4];
@@ -255,9 +216,8 @@ static void decode_des_etc(BYTE *buf,int len,int type,int cycle)
}
/*==========================================
* Grf data decode sub : zip
- *------------------------------------------
- */
-int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen)
+ *------------------------------------------*/
+int decode_zip(unsigned char* dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen)
{
z_stream stream;
int err;
@@ -288,7 +248,8 @@ int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char*
return err;
}
-int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen) {
+int encode_zip(unsigned char* dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen)
+{
z_stream stream;
int err;
memset(&stream, 0, sizeof(stream));
@@ -318,7 +279,7 @@ int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char*
return err;
}
-unsigned long grfio_crc32 (const unsigned char *buf, unsigned int len)
+unsigned long grfio_crc32 (const unsigned char* buf, unsigned int len)
{
return crc32(crc32(0L, Z_NULL, 0), buf, len);
}
@@ -327,80 +288,65 @@ unsigned long grfio_crc32 (const unsigned char *buf, unsigned int len)
*** File List Subroutines ***
***********************************************************/
-/*==========================================
- * File List : Hash make
- *------------------------------------------
- */
-static int filehash(unsigned char *fname)
+// initializes the table that holds the first elements of all hash chains
+static void hashinit(void)
+{
+ int i;
+ for (i = 0; i < 256; i++)
+ filelist_hash[i] = -1;
+}
+
+// hashes a filename string into a number from {0..255}
+static int filehash(char* fname)
{
- unsigned int hash=0;
+ unsigned int hash = 0;
while(*fname) {
- hash = ((hash<<1)+(hash>>7)*9+tolower(*fname));
+ hash = (hash<<1) + (hash>>7)*9 + TOLOWER(*fname);
fname++;
}
return hash & 255;
}
-/*==========================================
- * File List : Hash initalize
- *------------------------------------------
- */
-static void hashinit(void)
-{
- int lop;
- for (lop = 0; lop < 256; lop++)
- filelist_hash[lop] = -1;
-}
-
-/*==========================================
- * File List : File find
- *------------------------------------------
- */
-static FILELIST *filelist_find(char *fname)
+// finds a FILELIST entry with the specified file name
+static FILELIST* filelist_find(char* fname)
{
- int hash;
+ int hash, index;
if (!filelist)
return NULL;
- for (hash = filelist_hash[filehash((unsigned char *) fname)]; hash >= 0; hash = filelist[hash].next) {
- if(strcmpi(filelist[hash].fn, fname) == 0)
+ hash = filelist_hash[filehash(fname)];
+ for (index = hash; index != -1; index = filelist[index].next)
+ if(!strcmpi(filelist[index].fn, fname))
break;
- }
- return (hash >= 0) ? &filelist[hash] : NULL;
+ return (index >= 0) ? &filelist[index] : NULL;
}
-char *grfio_find_file(char *fname){
+// returns the original file name
+char* grfio_find_file(char* fname)
+{
FILELIST *filelist = filelist_find(fname);
if (!filelist) return NULL;
- return (!filelist->fnd?filelist->fn:filelist->fnd);
+ return (!filelist->fnd ? filelist->fn : filelist->fnd);
}
-/*==========================================
- * File List : Filelist add
- *------------------------------------------
- */
-#define FILELIST_ADDS 1024 // number increment of file lists `
-
-static FILELIST* filelist_add(FILELIST *entry)
+// adds a FILELIST entry into the list of loaded files
+static FILELIST* filelist_add(FILELIST* entry)
{
int hash;
- if (filelist_entrys >= FILELIST_LIMIT) {
- ShowFatalError("GRF filelist limit reached (filelist_add)!\n");
- exit(1);
- }
+ #define FILELIST_ADDS 1024 // number increment of file lists `
if (filelist_entrys >= filelist_maxentry) {
filelist = (FILELIST *)aRealloc(filelist, (filelist_maxentry + FILELIST_ADDS) * sizeof(FILELIST));
- malloc_tsetdword(filelist + filelist_maxentry, '\0', FILELIST_ADDS * sizeof(FILELIST));
+ memset(filelist + filelist_maxentry, '\0', FILELIST_ADDS * sizeof(FILELIST));
filelist_maxentry += FILELIST_ADDS;
}
memcpy (&filelist[filelist_entrys], entry, sizeof(FILELIST));
- hash = filehash((unsigned char *) entry->fn);
+ hash = filehash(entry->fn);
filelist[filelist_entrys].next = filelist_hash[hash];
filelist_hash[hash] = filelist_entrys;
@@ -409,10 +355,11 @@ static FILELIST* filelist_add(FILELIST *entry)
return &filelist[filelist_entrys - 1];
}
-static FILELIST* filelist_modify(FILELIST *entry)
+// adds a new FILELIST entry or overwrites an existing one
+static FILELIST* filelist_modify(FILELIST* entry)
{
- FILELIST *fentry;
- if ((fentry = filelist_find(entry->fn)) != NULL) {
+ FILELIST* fentry = filelist_find(entry->fn);
+ if (fentry != NULL) {
int tmp = fentry->next;
memcpy(fentry, entry, sizeof(FILELIST));
fentry->next = tmp;
@@ -422,18 +369,15 @@ static FILELIST* filelist_modify(FILELIST *entry)
return fentry;
}
-/*==========================================
- * File List : filelist size adjust
- *------------------------------------------
- */
+// shrinks the file list array if too long
static void filelist_adjust(void)
{
- if (filelist != NULL) {
- if (filelist_maxentry > filelist_entrys) {
- filelist = (FILELIST *)aRealloc(
- filelist, filelist_entrys * sizeof(FILELIST));
- filelist_maxentry = filelist_entrys;
- }
+ if (filelist == NULL)
+ return;
+
+ if (filelist_entrys < filelist_maxentry) {
+ filelist = (FILELIST *)aRealloc(filelist, filelist_entrys * sizeof(FILELIST));
+ filelist_maxentry = filelist_entrys;
}
}
@@ -441,13 +385,11 @@ static void filelist_adjust(void)
*** Grfio Sobroutines ***
***********************************************************/
-/*==========================================
- * Grfio : Resource file size get
- *------------------------------------------
- */
-int grfio_size(char *fname)
+// returns a file's size
+/*
+int grfio_size(char* fname)
{
- FILELIST *entry;
+ FILELIST* entry;
entry = filelist_find(fname);
@@ -459,7 +401,7 @@ int grfio_size(char *fname)
sprintf(lfname, "%s%s", data_dir, fname);
for (p = &lfname[0]; *p != 0; p++)
- if (*p=='\\') *p = '/'; // * At the time of Unix
+ if (*p=='\\') *p = '/';
if (stat(lfname, &st) == 0) {
strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1);
@@ -469,22 +411,19 @@ int grfio_size(char *fname)
entry = filelist_modify(&lentry);
} else if (entry == NULL) {
ShowError("%s not found (grfio_size)\n", fname);
- //exit(1);
return -1;
}
}
return entry->declen;
}
+*/
-/*==========================================
- * Grfio : Resource file read & size get
- *------------------------------------------
- */
-void* grfio_reads(char *fname, int *size)
+// reads a file into a newly allocated buffer (from grf or data directory)
+void* grfio_reads(char* fname, int* size)
{
- FILE *in;
- FILELIST *entry;
- unsigned char *buf2 = NULL;
+ FILE* in;
+ FILELIST* entry;
+ unsigned char* buf2 = NULL;
entry = filelist_find(fname);
@@ -495,18 +434,18 @@ void* grfio_reads(char *fname, int *size)
sprintf(lfname, "%s%s", data_dir, fname);
for (p = &lfname[0]; *p != 0; p++)
- if (*p == '\\') *p = '/'; // * At the time of Unix
+ if (*p == '\\') *p = '/';
in = fopen(lfname, "rb");
if (in != NULL) {
if (entry != NULL && entry->gentry == 0) {
lentry.declen = entry->declen;
} else {
- fseek(in,0,2); // SEEK_END
+ fseek(in,0,SEEK_END);
lentry.declen = ftell(in);
}
- fseek(in,0,0); // SEEK_SET
- buf2 = (unsigned char *)aMallocA(lentry.declen + 1024);
+ fseek(in,0,SEEK_SET);
+ buf2 = (unsigned char *)malloc(lentry.declen + 1024);
fread(buf2, 1, lentry.declen, in);
fclose(in);
strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1);
@@ -523,8 +462,8 @@ void* grfio_reads(char *fname, int *size)
}
}
if (entry != NULL && entry->gentry > 0) { // Archive[GRF] File Read
- char *gfname = gentry_table[entry->gentry - 1];
- in = fopen(gfname, "rb");
+ char* grfname = gentry_table[entry->gentry - 1];
+ in = fopen(grfname, "rb");
if(in != NULL) {
unsigned char *buf = (unsigned char *)aMallocA(entry->srclen_aligned + 1024);
fseek(in, entry->srcpos, 0);
@@ -537,8 +476,8 @@ void* grfio_reads(char *fname, int *size)
decode_des_etc(buf, entry->srclen_aligned, entry->cycle == 0, entry->cycle);
len = entry->declen;
decode_zip(buf2, &len, buf, entry->srclen);
- if (len != entry->declen) {
- ShowError("decode_zip size miss match err: %d != %d\n", (int)len, entry->declen);
+ if (len != (uLong)entry->declen) {
+ ShowError("decode_zip size mismatch err: %d != %d\n", (int)len, entry->declen);
aFree(buf);
aFree(buf2);
return NULL;
@@ -548,7 +487,7 @@ void* grfio_reads(char *fname, int *size)
}
aFree(buf);
} else {
- ShowError("%s not found (grfio_reads - grf file %s)\n", fname, gfname);
+ ShowError("%s not found (grfio_reads - GRF file %s)\n", fname, grfname);
return NULL;
}
}
@@ -560,9 +499,8 @@ void* grfio_reads(char *fname, int *size)
/*==========================================
* Resource filename decode
- *------------------------------------------
- */
-static char * decode_filename(unsigned char *buf,int len)
+ *------------------------------------------*/
+static char* decode_filename(unsigned char* buf, int len)
{
int lop;
for(lop=0;lop<len;lop+=8) {
@@ -574,34 +512,33 @@ static char * decode_filename(unsigned char *buf,int len)
return (char*)buf;
}
-/*==========================================
- * Grfio : Entry table read
- *------------------------------------------
- */
-static int grfio_entryread(char *gfname,int gentry)
+// loads all entries in the specified grf file into the filelist
+// gentry - index of the grf file name in the gentry_table
+static int grfio_entryread(char* grfname, int gentry)
{
- FILE *fp;
+ FILE* fp;
long grf_size,list_size;
unsigned char grf_header[0x2e];
int lop,entry,entrys,ofs,grf_version;
char *fname;
unsigned char *grf_filelist;
- fp = fopen(gfname, "rb");
+ fp = fopen(grfname, "rb");
if (fp == NULL) {
- ShowWarning("GRF Data File not found: '"CL_WHITE"%s"CL_RESET"'.\n",gfname);
+ ShowWarning("GRF data file not found: '%s'\n",grfname);
return 1; // 1:not found error
- }
+ } else
+ ShowInfo("GRF data file found: '%s'\n",grfname);
- fseek(fp,0,2); // SEEK_END
+ fseek(fp,0,SEEK_END);
grf_size = ftell(fp);
- fseek(fp,0,0); // SEEK_SET
+ fseek(fp,0,SEEK_SET);
fread(grf_header,1,0x2e,fp);
if (strcmp((const char *) grf_header,"Master of Magic") ||
- fseek(fp,getlong(grf_header+0x1e),1)) // SEEK_CUR
+ fseek(fp,getlong(grf_header+0x1e),SEEK_CUR))
{
fclose(fp);
- ShowError("GRF %s read error\n",gfname);
+ ShowError("GRF %s read error\n", grfname);
return 2; // 2:file format error
}
@@ -610,11 +547,6 @@ static int grfio_entryread(char *gfname,int gentry)
if (grf_version == 0x01) { //****** Grf version 01xx ******
list_size = grf_size - ftell(fp);
grf_filelist = (unsigned char *) aMallocA(list_size);
- /*if (grf_filelist == NULL){
- fclose(fp);
- ShowError("out of memory : grf_filelist\n");
- return 3; // 3:memory alloc error
- }*/
fread(grf_filelist,1,list_size,fp);
fclose(fp);
@@ -622,8 +554,9 @@ static int grfio_entryread(char *gfname,int gentry)
// Get an entry
for (entry = 0,ofs = 0; entry < entrys; entry++) {
- int ofs2, srclen, srccount, type;
- char *period_ptr;
+ int ofs2, srclen, srccount;
+ unsigned char type;
+ char* period_ptr;
FILELIST aentry;
ofs2 = ofs+getlong(grf_filelist+ofs)+4;
@@ -679,25 +612,14 @@ static int grfio_entryread(char *gfname,int gentry)
rSize = getlong(eheader); // Read Size
eSize = getlong(eheader+4); // Extend Size
- if ((long)rSize > grf_size-ftell(fp)) { // Warning fix [Lance]
+ if ((long)rSize > grf_size-ftell(fp)) {
fclose(fp);
- ShowError("Illegal data format : grf compress entry size\n");
+ ShowError("Illegal data format: GRF compress entry size\n");
return 4;
}
rBuf = (unsigned char *)aMallocA(rSize); // Get a Read Size
- /*if (rBuf==NULL) {
- fclose(fp);
- ShowError("out of memory : grf compress entry table buffer\n");
- return 3;
- }*/
grf_filelist = (unsigned char *)aMallocA(eSize); // Get a Extend Size
- /*if (grf_filelist==NULL) {
- aFree(rBuf);
- fclose(fp);
- ShowError("out of memory : grf extract entry table buffer\n");
- return 3;
- }*/
fread(rBuf,1,rSize,fp);
fclose(fp);
decode_zip(grf_filelist, &eSize, rBuf, rSize); // Decode function
@@ -707,7 +629,7 @@ static int grfio_entryread(char *gfname,int gentry)
entrys = getlong(grf_header+0x26) - 7;
// Get an entry
- for(entry = 0, ofs = 0; entry < entrys; entry++){
+ for(entry = 0, ofs = 0; entry < entrys; entry++) {
int ofs2, srclen, srccount, type;
FILELIST aentry;
@@ -717,8 +639,7 @@ static int grfio_entryread(char *gfname,int gentry)
aFree(grf_filelist);
exit(1);
}
- //ofs2 = ofs+strlen((char*)(grf_filelist+ofs))+1;
- ofs2 = ofs + strlen(fname)+1;
+ ofs2 = ofs + (int)strlen(fname)+1;
type = grf_filelist[ofs2+12];
if (type == 1 || type == 3 || type == 5) {
srclen = getlong(grf_filelist+ofs2);
@@ -762,27 +683,27 @@ static int grfio_entryread(char *gfname,int gentry)
/*==========================================
* Grfio : Resource file check
- *------------------------------------------
- */
+ *------------------------------------------*/
static void grfio_resourcecheck(void)
{
char w1[256], w2[256], src[256], dst[256], restable[256], line[256];
char *ptr, *buf;
- FILELIST *entry;
- int size, i = 0;
- FILE *fp;
+ FILELIST* entry;
+ int size;
+ FILE* fp;
+ int i = 0;
// read resnametable from data directory and return if successful
sprintf(restable, "%sdata\\resnametable.txt", data_dir);
for (ptr = &restable[0]; *ptr != 0; ptr++)
if (*ptr == '\\') *ptr = '/';
- fp = fopen(restable,"rb");
+ fp = fopen(restable, "rb");
if (fp) {
while (fgets(line, sizeof(line) - 1, fp)) {
if (sscanf(line, "%[^#]#%[^#]#", w1, w2) == 2 &&
- // we only need the map names and text files
- (strstr(w2, ".gat") || strstr(w2, ".txt")))
+ // we only need the maps' GAT and RSW files
+ (strstr(w2, ".gat") || strstr(w2, ".rsw")))
{
sprintf(src, "data\\%s", w1);
sprintf(dst, "data\\%s", w2);
@@ -792,7 +713,7 @@ static void grfio_resourcecheck(void)
FILELIST fentry;
memcpy(&fentry, entry, sizeof(FILELIST));
strncpy(fentry.fn, src, sizeof(fentry.fn) - 1);
- fentry.fnd = grfio_alloc_ptr(dst);
+ fentry.fnd = strdup(dst);
filelist_modify(&fentry);
i++;
}
@@ -803,16 +724,15 @@ static void grfio_resourcecheck(void)
return; // we're done here!
}
- // read resnametable from loaded GRF's, only if it cannot be
- // loaded from the data directory
+ // read resnametable from loaded GRF's, only if it cannot be loaded from the data directory
buf = (char *)grfio_reads("data\\resnametable.txt", &size);
if (buf) {
buf[size] = 0;
- ptr = buf;
+ ptr = buf;
while (ptr - buf < size) {
if (sscanf(ptr, "%[^#]#%[^#]#", w1, w2) == 2 &&
- (strstr(w2, ".gat") || strstr(w2, ".txt")))
+ (strstr(w2, ".gat") || strstr(w2, ".rsw")))
{
sprintf(src, "data\\%s", w1);
sprintf(dst, "data\\%s", w2);
@@ -821,12 +741,12 @@ static void grfio_resourcecheck(void)
FILELIST fentry;
memcpy(&fentry, entry, sizeof(FILELIST));
strncpy(fentry.fn, src, sizeof(fentry.fn) - 1);
- fentry.fnd = grfio_alloc_ptr(dst);
+ fentry.fnd = strdup(dst);
filelist_modify(&fentry);
i++;
}
}
- ptr = strchr(ptr,'\n'); // Next line
+ ptr = strchr(ptr, '\n'); // Next line
if (!ptr) break;
ptr++;
}
@@ -835,49 +755,25 @@ static void grfio_resourcecheck(void)
return;
}
- //ShowWarning("GRF: No resnametable found! Panic?\n");
-}
-
-/*==========================================
- * Grfio : Resource add
- *------------------------------------------
- */
-#define GENTRY_ADDS 4 // The number increment of gentry_table entries
-
-static int grfio_add(char *fname)
-{
- grfio_alloc_ptr(fname);
-
- return grfio_entryread(fname, gentry_entrys - 1);
}
-char *grfio_alloc_ptr(char *fname)
+// reads a grf file and adds it to the list
+static int grfio_add(char* fname)
{
- int len;
- char *buf;
-
- if (gentry_entrys >= GENTRY_LIMIT) {
- ShowFatalError("gentrys limit : grfio_add\n");
- exit(1);
- }
+ #define GENTRY_ADDS 4 // The number increment of gentry_table entries
if (gentry_entrys >= gentry_maxentry) {
gentry_maxentry += GENTRY_ADDS;
gentry_table = (char**)aRealloc(gentry_table, gentry_maxentry * sizeof(char*));
- malloc_tsetdword(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS);
+ memset(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS);
}
- len = strlen( fname );
- buf = (char*)aMallocA(len + 1);
- strcpy(buf, fname);
- gentry_table[gentry_entrys++] = buf;
- return buf;
+ gentry_table[gentry_entrys++] = strdup(fname);
+
+ return grfio_entryread(fname, gentry_entrys - 1);
}
-/*==========================================
- * Grfio : Finalize
- *------------------------------------------
- */
+// removes all entries
void grfio_final(void)
{
if (filelist != NULL)
@@ -886,10 +782,10 @@ void grfio_final(void)
filelist_entrys = filelist_maxentry = 0;
if (gentry_table != NULL) {
- int lop;
- for (lop = 0; lop < gentry_entrys; lop++) {
- if (gentry_table[lop] != NULL)
- aFree(gentry_table[lop]);
+ int i;
+ for (i = 0; i < gentry_entrys; i++) {
+ if (gentry_table[i] != NULL)
+ aFree(gentry_table[i]);
}
aFree(gentry_table);
}
@@ -899,13 +795,12 @@ void grfio_final(void)
/*==========================================
* Grfio : Initialize
- *------------------------------------------
- */
-void grfio_init(char *fname)
+ *------------------------------------------*/
+void grfio_init(char* fname)
{
- FILE *data_conf;
+ FILE* data_conf;
char line[1024], w1[1024], w2[1024];
- int result = 0;
+ int grf_num = 0;
hashinit(); // hash table initialization
@@ -918,27 +813,23 @@ void grfio_init(char *fname)
if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
continue;
// Entry table reading
- if(strcmp(w1, "grf") == 0 ||
- strcmp(w1, "data") == 0 || // Primary data file
- strcmp(w1, "sdata") == 0 || // Sakray data file
- strcmp(w1, "adata") == 0) // Alpha version data file
- // increment if successfully loaded
- result += (grfio_add(w2) == 0);
- else if(strcmp(w1,"data_dir") == 0) // Data directory
+ if(strcmp(w1, "grf") == 0) // GRF file
+ grf_num += (grfio_add(w2) == 0);
+ else if(strcmp(w1,"data_dir") == 0) { // Data directory
strcpy(data_dir, w2);
+ }
}
-
fclose(data_conf);
ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n", fname);
} // end of reading grf-files.txt
- if (result == 0) {
- ShowInfo("No grf's loaded.. using default data directory\n");
- //exit(1); // It ends, if a resource cannot read one.
+ if (grf_num == 0) {
+ ShowInfo("No GRF loaded, using default data directory\n");
}
- // Unnecessary area release of filelist
+ // Unneccessary area release of filelist
filelist_adjust();
+
// Resource check
grfio_resourcecheck();
diff --git a/src/common/grfio.h b/src/common/grfio.h
index 408dafd1b..57439b16d 100644
--- a/src/common/grfio.h
+++ b/src/common/grfio.h
@@ -8,7 +8,6 @@ void grfio_init(char*); // GRFIO Initialize
void grfio_final(void); // GRFIO Finalize
void* grfio_reads(char*,int*); // GRFIO data file read & size get
char *grfio_find_file(char *fname);
-char *grfio_alloc_ptr(char *fname);
#define grfio_read(fn) grfio_reads(fn, NULL)
@@ -17,6 +16,5 @@ unsigned long grfio_crc32(const unsigned char *buf, unsigned int len);
int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen);
int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen);
-int deflate_file (const char *source, const char *filename);
#endif /* _GRFIO_H_ */
diff --git a/src/common/mapindex.c b/src/common/mapindex.c
index b8bb12c18..37afcad3d 100644
--- a/src/common/mapindex.c
+++ b/src/common/mapindex.c
@@ -29,9 +29,7 @@ char *mapindex_normalize_name(char *mapname)
if (ptr) { //Check and remove extension.
while (ptr[1] && (ptr2 = strchr(ptr+1, '.')))
ptr = ptr2; //Skip to the last dot.
- if(stricmp(ptr,".gat") == 0 ||
- stricmp(ptr,".afm") == 0 ||
- stricmp(ptr,".af2") == 0)
+ if(stricmp(ptr,".gat") == 0)
*ptr = '\0'; //Remove extension.
}
return mapname;
diff --git a/src/login_sql/login.c b/src/login_sql/login.c
index b8e57544a..bff047492 100644
--- a/src/login_sql/login.c
+++ b/src/login_sql/login.c
@@ -513,7 +513,7 @@ int mmo_auth(struct mmo_account* account, int fd)
char t_uid[256];
char user_password[256], password[256];
long connect_until;
- int encpasswdok = 0, state;
+ int state;
char ip[16];
uint32 ipl = session[fd]->client_addr;
diff --git a/src/map/map.c b/src/map/map.c
index c65e49d21..ca2fd6565 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -2856,24 +2856,17 @@ int map_config_read(char *cfgName) {
} else if(strcmpi(w1,"db_path") == 0) {
strncpy(db_path,w2,255);
} else if (strcmpi(w1, "console") == 0) {
- if(strcmpi(w2,"on") == 0 || strcmpi(w2,"yes") == 0 ) {
- console = 1;
+ console = config_switch(w2);
+ if (console)
ShowNotice("Console Commands are enabled.\n");
- }
} else if (strcmpi(w1, "enable_spy") == 0) {
- if(strcmpi(w2,"on") == 0 || strcmpi(w2,"yes") == 0 )
- enable_spy = 1;
- else
- enable_spy = 0;
- } else if (strcmpi(w1, "use_grf") == 0) { //[blackhole89]
- if(strcmpi(w2,"on") == 0 || strcmpi(w2,"yes") == 0 )
- enable_grf = 1;
- else
- enable_grf = 0;
+ enable_spy = config_switch(w2);
+ } else if (strcmpi(w1, "use_grf") == 0) {
+ enable_grf = config_switch(w2);
} else if (strcmpi(w1, "import") == 0) {
map_config_read(w2);
} else
- ShowWarning("Unknown setting [%s] in file %s\n", w1, cfgName);
+ ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName);
}
}
fclose(fp);
diff --git a/src/map/map.h b/src/map/map.h
index a2bf8d455..6178b364d 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -1271,12 +1271,6 @@ extern char db_path[256];
int map_getcell(int,int,int,cell_t);
int map_getcellp(struct map_data*,int,int,cell_t);
void map_setcell(int,int,int,int);
-extern int map_read_flag; // 0: grfիE1: ëE2: ëE?)
-enum {
- READ_FROM_GAT, READ_FROM_AFM,
- READ_FROM_BITMAP, CREATE_BITMAP,
- READ_FROM_BITMAP_COMPRESSED, CREATE_BITMAP_COMPRESSED
-};
extern char motd_txt[];
extern char help_txt[];
@@ -1356,11 +1350,6 @@ int map_check_dir(int s_dir,int t_dir);
int map_calc_dir( struct block_list *src,int x,int y);
int map_random_dir(struct block_list *bl, short *x, short *y); // [Skotlex]
-// Water functions...
-//
-int map_setwaterheight(int m, char *mapname, int height);
-int map_waterheight(char *mapname);
-
// path.c
int path_search_real(struct walkpath_data *wpd,int m,int x0,int y0,int x1,int y1,int flag,cell_t flag2);
#define path_search(wpd,m,x0,y0,x1,y1,flag) path_search_real(wpd,m,x0,y0,x1,y1,flag,CELL_CHKNOPASS)
diff --git a/src/map/npc.c b/src/map/npc.c
index 97034402e..49cb4f1a0 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -2930,7 +2930,6 @@ static int npc_read_event_script_sub(DBKey key,void *data,va_list ap)
void npc_read_event_script(void)
{
int i;
- unsigned char buf[64]="::";
struct {
char *name;
char *event_name;
@@ -2946,15 +2945,14 @@ void npc_read_event_script(void)
};
for (i = 0; i < NPCE_MAX; i++) {
- if (script_event[i].nd)
- script_event[i].nd = NULL;
- if (script_event[i].event_count)
- script_event[i].event_count = 0;
+ script_event[i].nd = NULL;
+ script_event[i].event_count = 0;
if (!script_config.event_script_type) {
//Use a single NPC as event source.
script_event[i].nd = npc_name2id(config[i].event_name);
} else {
//Use an array of Events
+ char buf[64]="::";
strncpy(buf+2,config[i].event_name,62);
ev_db->foreach(ev_db,npc_read_event_script_sub,buf,
&script_event[i].event,
diff --git a/src/map/pc.c b/src/map/pc.c
index ae2914b6f..dd031aadb 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -2966,7 +2966,7 @@ int pc_isUseitem(struct map_session_data *sd,int n)
//Butterfly Wing (can't use noreturn flag is on)
if(nameid == 602 && map[sd->bl.m].flag.noreturn)
return 0;
- //Dead Branch & Red Pouch & Bloody Branch & Porings Box (can't use at GVG and when nobranch flag is on)
+ //Dead Branch & Red Pouch & Bloody Branch & Poring Box (can't use at GVG and when nobranch flag is on)
if((nameid == 604 || nameid == 12024 || nameid == 12103 || nameid == 12109) && (map[sd->bl.m].flag.nobranch || map_flag_gvg(sd->bl.m)))
return 0;
diff --git a/src/map/status.h b/src/map/status.h
index 0ea31cdec..380694eba 100644
--- a/src/map/status.h
+++ b/src/map/status.h
@@ -258,14 +258,14 @@ enum {
SC_CHANGE,
SC_BLOODLUST,
SC_FLEET,
- SC_SPEED, //[orn]
- SC_DEFENCE, //[orn]
+ SC_SPEED,
+ SC_DEFENCE,
SC_INCAGIRATE,
SC_INCDEXRATE,
SC_JAILED,
SC_ENCHANTARMS, //250
SC_MAGICALATTACK,
- SC_MAX, //Automatically updated max, used in for's and at startup to check we are within bounds. [Skotlex]
+ SC_MAX, //Automatically updated max, used in for's to check we are within bounds.
};
int SkillStatusChangeTable(int skill);
extern int StatusSkillChangeTable[SC_MAX];
@@ -314,8 +314,8 @@ enum {
//38: Again Aspd Potion
//39: Again Aspd Potion
//40: Again Aspd Potion
- SI_SPEEDPOTION1 = 41,
- SI_SPEEDPOTION2 = 42,
+ SI_SPEEDPOTION1 = 41,
+ SI_SPEEDPOTION2 = 42,
SI_STRIPWEAPON = 50,
SI_STRIPSHIELD = 51,
SI_STRIPARMOR = 52,
@@ -336,7 +336,7 @@ enum {
SI_WATERWEAPON = 91,
SI_WINDWEAPON = 92,
SI_EARTHWEAPON = 93,
- SI_UNDEAD = 97,
+ SI_UNDEAD = 97,
// 102 = again gloria - from what I saw on screenshots, I wonder if it isn't gospel... [DracoRPG]
SI_AURABLADE = 103,
SI_PARRYING = 104,
@@ -344,7 +344,7 @@ enum {
SI_TENSIONRELAX = 106,
SI_BERSERK = 107,
SI_ASSUMPTIO = 110,
- SI_LANDENDOW = 112,
+ SI_LANDENDOW = 112,
SI_MAGICPOWER = 113,
SI_EDP = 114,
SI_TRUESIGHT = 115,
@@ -359,7 +359,7 @@ enum {
SI_BLEEDING = 124,
SI_JOINTBEAT = 125,
SI_BABY = 130,
- SI_AUTOBERSERK = 132,
+ SI_AUTOBERSERK = 132,
SI_RUN = 133,
SI_BUMP = 134,
SI_READYSTORM = 135,
@@ -368,7 +368,7 @@ enum {
SI_READYCOUNTER = 141,
SI_DODGE = 143,
//SI_RUN = 144, //is not RUN. need info on what this is.
- SI_SPURT = 145,
+ SI_SPURT = 145,
SI_SHADOWWEAPON = 146,
SI_ADRENALINE2 = 147,
SI_GHOSTWEAPON = 148,
@@ -378,7 +378,7 @@ enum {
SI_KAIZEL = 156,
SI_KAAHI = 157,
SI_KAUPE = 158,
- SI_SMA = 159,
+ SI_SMA = 159,
SI_NIGHT = 160,
SI_ONEHAND = 161,
SI_WARM = 165,
@@ -388,8 +388,8 @@ enum {
SI_MOON_COMFORT = 170,
SI_STAR_COMFORT = 171,
SI_PRESERVE = 181,
- SI_INCSTR = 182,
- SI_INTRAVISION = 184,
+ SI_INCSTR = 182,
+ SI_INTRAVISION = 184,
SI_DOUBLECAST = 186,
SI_MAXOVERTHRUST = 188,
SI_TAROT = 191, // the icon allows no doubt... but what is it really used for ?? [DracoRPG]
@@ -401,20 +401,20 @@ enum {
SI_MADNESSCANCEL = 203, //[blackhole89]
SI_GATLINGFEVER = 204,
SI_TKREST = 205, // 205 = Gloria again (but TK- Happy State looks like it)
- SI_UTSUSEMI = 206,
+ SI_UTSUSEMI = 206,
SI_BUNSINJYUTSU = 207,
- SI_NEN = 208,
+ SI_NEN = 208,
SI_ADJUSTMENT = 209,
- SI_ACCURACY = 210,
- SI_FOODSTR = 241,
- SI_FOODAGI = 242,
- SI_FOODVIT = 243,
- SI_FOODDEX = 244,
- SI_FOODINT = 245,
- SI_FOODLUK = 246,
- SI_FOODFLEE = 247,
- SI_FOODHIT = 248,
- SI_FOODCRI = 249,
+ SI_ACCURACY = 210,
+ SI_FOODSTR = 241,
+ SI_FOODAGI = 242,
+ SI_FOODVIT = 243,
+ SI_FOODDEX = 244,
+ SI_FOODINT = 245,
+ SI_FOODLUK = 246,
+ SI_FOODFLEE = 247,
+ SI_FOODHIT = 248,
+ SI_FOODCRI = 249,
};
// JOINTBEAT stackable ailments
diff --git a/src/map/trade.c b/src/map/trade.c
index 41d919daa..f8c939424 100644
--- a/src/map/trade.c
+++ b/src/map/trade.c
@@ -54,7 +54,7 @@ void trade_traderequest(struct map_session_data *sd, struct map_session_data *ta
}
if ((target_sd->trade_partner != 0) || (sd->trade_partner != 0)) {
- clif_tradestart(sd, 2); // person is in another trade
+ clif_tradestart(sd, 2); // person is in another trade
return;
}
diff --git a/src/tool/mapcache.c b/src/tool/mapcache.c
index aa0ab0c94..5db46c123 100644
--- a/src/tool/mapcache.c
+++ b/src/tool/mapcache.c
@@ -218,9 +218,7 @@ char *remove_extension(char *mapname)
if (ptr) { //Check and remove extension.
while (ptr[1] && (ptr2 = strchr(ptr+1, '.')))
ptr = ptr2; //Skip to the last dot.
- if (strcmp(ptr,".gat") == 0 ||
- strcmp(ptr,".afm") == 0 ||
- strcmp(ptr,".af2") == 0)
+ if (strcmp(ptr,".gat") == 0)
*ptr = '\0'; //Remove extension.
}
return mapname;