| 12299 | } |
| 12300 | |
| 12301 | void EquipmentModelOffsets_t::readBaseItemsFromFile() |
| 12302 | { |
| 12303 | std::string filename = "models/creatures/"; |
| 12304 | filename += "item_model_positions.json"; |
| 12305 | |
| 12306 | if ( !PHYSFS_getRealDir(filename.c_str()) ) |
| 12307 | { |
| 12308 | //printlog("[JSON]: Error: Could not locate json file %s", filename.c_str()); |
| 12309 | return; |
| 12310 | } |
| 12311 | |
| 12312 | std::string inputPath = PHYSFS_getRealDir(filename.c_str()); |
| 12313 | inputPath.append(PHYSFS_getDirSeparator()); |
| 12314 | inputPath.append(filename.c_str()); |
| 12315 | |
| 12316 | File* fp = FileIO::open(inputPath.c_str(), "rb"); |
| 12317 | if ( !fp ) |
| 12318 | { |
| 12319 | printlog("[JSON]: Error: Could not locate json file %s", inputPath.c_str()); |
| 12320 | return; |
| 12321 | } |
| 12322 | |
| 12323 | static char buf[32000]; |
| 12324 | int count = fp->read(buf, sizeof(buf[0]), sizeof(buf) - 1); |
| 12325 | buf[count] = '\0'; |
| 12326 | rapidjson::StringStream is(buf); |
| 12327 | FileIO::close(fp); |
| 12328 | |
| 12329 | rapidjson::Document d; |
| 12330 | d.ParseStream(is); |
| 12331 | if ( !d.IsObject() ) |
| 12332 | { |
| 12333 | return; |
| 12334 | } |
| 12335 | if ( !d.HasMember("version") || !d.HasMember("items") ) |
| 12336 | { |
| 12337 | printlog("[JSON]: Error: No 'version' value in json file, or JSON syntax incorrect! %s", inputPath.c_str()); |
| 12338 | return; |
| 12339 | } |
| 12340 | |
| 12341 | int version = d["version"].GetInt(); |
| 12342 | |
| 12343 | miscItemsBaseOffsets.clear(); |
| 12344 | |
| 12345 | auto& itemsArr = d["items"]; |
| 12346 | for ( auto it = itemsArr.Begin(); it != itemsArr.End(); ++it ) |
| 12347 | { |
| 12348 | for ( auto it2 = it->MemberBegin(); it2 != it->MemberEnd(); ++it2 ) |
| 12349 | { |
| 12350 | std::string itemName = it2->name.GetString(); |
| 12351 | if ( ItemTooltips.itemNameStringToItemID.find(itemName) == ItemTooltips.itemNameStringToItemID.end() ) |
| 12352 | { |
| 12353 | continue; |
| 12354 | } |
| 12355 | ItemType itemType = (ItemType)ItemTooltips.itemNameStringToItemID[itemName]; |
| 12356 | std::vector<int> models; |
| 12357 | if ( it2->value.HasMember("models") ) |
| 12358 | { |