From f07202d449845376132b6e2e20018df523ab85d0 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 9 Jul 2025 16:53:53 +0100 Subject: [PATCH] fix: show asset that failed when not being able to parse jsons --- .../Leaderboard/JsonLeaderboardDefLoader.cpp | 26 +++++------ .../Leaderboard/JsonLeaderboardDefLoader.cpp | 26 +++++------ .../IW5/Weapon/JsonWeaponAttachmentLoader.cpp | 26 +++++------ .../Leaderboard/JsonLeaderboardDefLoader.cpp | 26 +++++------ .../Game/T6/Weapon/JsonWeaponCamoLoaderT6.cpp | 26 +++++------ .../Material/JsonMaterialLoader.cpp.template | 46 +++++++++---------- .../XModel/LoaderXModel.cpp.template | 26 +++++------ 7 files changed, 101 insertions(+), 101 deletions(-) diff --git a/src/ObjLoading/Game/IW4/Leaderboard/JsonLeaderboardDefLoader.cpp b/src/ObjLoading/Game/IW4/Leaderboard/JsonLeaderboardDefLoader.cpp index cff973f9..35c64c27 100644 --- a/src/ObjLoading/Game/IW4/Leaderboard/JsonLeaderboardDefLoader.cpp +++ b/src/ObjLoading/Game/IW4/Leaderboard/JsonLeaderboardDefLoader.cpp @@ -23,21 +23,21 @@ namespace bool Load(LeaderboardDef& leaderboardDef) const { - const auto jRoot = json::parse(m_stream); - std::string type; - unsigned version; - - jRoot.at("_type").get_to(type); - jRoot.at("_version").get_to(version); - - if (type != "leaderboard" || version != 1u) - { - std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name); - return false; - } - try { + const auto jRoot = json::parse(m_stream); + std::string type; + unsigned version; + + jRoot.at("_type").get_to(type); + jRoot.at("_version").get_to(version); + + if (type != "leaderboard" || version != 1u) + { + std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name); + return false; + } + const auto jLeaderboard = jRoot.get(); return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef); } diff --git a/src/ObjLoading/Game/IW5/Leaderboard/JsonLeaderboardDefLoader.cpp b/src/ObjLoading/Game/IW5/Leaderboard/JsonLeaderboardDefLoader.cpp index 5c896d66..df4d9625 100644 --- a/src/ObjLoading/Game/IW5/Leaderboard/JsonLeaderboardDefLoader.cpp +++ b/src/ObjLoading/Game/IW5/Leaderboard/JsonLeaderboardDefLoader.cpp @@ -23,21 +23,21 @@ namespace bool Load(LeaderboardDef& leaderboardDef) const { - const auto jRoot = json::parse(m_stream); - std::string type; - unsigned version; - - jRoot.at("_type").get_to(type); - jRoot.at("_version").get_to(version); - - if (type != "leaderboard" || version != 1u) - { - std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name); - return false; - } - try { + const auto jRoot = json::parse(m_stream); + std::string type; + unsigned version; + + jRoot.at("_type").get_to(type); + jRoot.at("_version").get_to(version); + + if (type != "leaderboard" || version != 1u) + { + std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name); + return false; + } + const auto jLeaderboard = jRoot.get(); return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef); } diff --git a/src/ObjLoading/Game/IW5/Weapon/JsonWeaponAttachmentLoader.cpp b/src/ObjLoading/Game/IW5/Weapon/JsonWeaponAttachmentLoader.cpp index f6ef081e..44d1bf68 100644 --- a/src/ObjLoading/Game/IW5/Weapon/JsonWeaponAttachmentLoader.cpp +++ b/src/ObjLoading/Game/IW5/Weapon/JsonWeaponAttachmentLoader.cpp @@ -26,21 +26,21 @@ namespace bool Load(WeaponAttachment& attachment) const { - const auto jRoot = json::parse(m_stream); - std::string type; - unsigned version; - - jRoot.at("_type").get_to(type); - jRoot.at("_version").get_to(version); - - if (type != "attachment" || version != 1u) - { - std::cerr << "Tried to load attachment \"" << attachment.szInternalName << "\" but did not find expected type attachment of version 1\n"; - return false; - } - try { + const auto jRoot = json::parse(m_stream); + std::string type; + unsigned version; + + jRoot.at("_type").get_to(type); + jRoot.at("_version").get_to(version); + + if (type != "attachment" || version != 1u) + { + std::cerr << "Tried to load attachment \"" << attachment.szInternalName << "\" but did not find expected type attachment of version 1\n"; + return false; + } + const auto jAttachment = jRoot.get(); return CreateWeaponAttachmentFromJson(jAttachment, attachment); } diff --git a/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.cpp b/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.cpp index 6e8686c3..b4f7823f 100644 --- a/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.cpp +++ b/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.cpp @@ -23,21 +23,21 @@ namespace bool Load(LeaderboardDef& leaderboardDef) const { - const auto jRoot = json::parse(m_stream); - std::string type; - unsigned version; - - jRoot.at("_type").get_to(type); - jRoot.at("_version").get_to(version); - - if (type != "leaderboard" || version != 1u) - { - std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name); - return false; - } - try { + const auto jRoot = json::parse(m_stream); + std::string type; + unsigned version; + + jRoot.at("_type").get_to(type); + jRoot.at("_version").get_to(version); + + if (type != "leaderboard" || version != 1u) + { + std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name); + return false; + } + const auto jLeaderboard = jRoot.get(); return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef); } diff --git a/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.cpp b/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.cpp index fbe08536..75bbe247 100644 --- a/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.cpp +++ b/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.cpp @@ -26,21 +26,21 @@ namespace bool Load(WeaponCamo& weaponCamo) const { - const auto jRoot = json::parse(m_stream); - std::string type; - unsigned version; - - jRoot.at("_type").get_to(type); - jRoot.at("_version").get_to(version); - - if (type != "weaponCamo" || version != 1u) - { - std::cerr << std::format("Tried to load weapon camo \"{}\" but did not find expected type weaponCamo of version {}\n", weaponCamo.name, 1u); - return false; - } - try { + const auto jRoot = json::parse(m_stream); + std::string type; + unsigned version; + + jRoot.at("_type").get_to(type); + jRoot.at("_version").get_to(version); + + if (type != "weaponCamo" || version != 1u) + { + std::cerr << std::format("Tried to load weapon camo \"{}\" but did not find expected type weaponCamo of version {}\n", weaponCamo.name, 1u); + return false; + } + const auto jWeaponCamo = jRoot.get(); return CreateWeaponCamoFromJson(jWeaponCamo, weaponCamo); } diff --git a/src/ObjLoading/Material/JsonMaterialLoader.cpp.template b/src/ObjLoading/Material/JsonMaterialLoader.cpp.template index 49250488..3f8bcebc 100644 --- a/src/ObjLoading/Material/JsonMaterialLoader.cpp.template +++ b/src/ObjLoading/Material/JsonMaterialLoader.cpp.template @@ -61,31 +61,31 @@ namespace bool Load(Material& material) const { - const auto jRoot = json::parse(m_stream); - std::string type; - unsigned version; - - jRoot.at("_type").get_to(type); - jRoot.at("_version").get_to(version); - - if (type != "material" || version != 1u) - { - std::cerr << std::format("Tried to load material \"{}\" but did not find expected type material of version 1\n", material.info.name); - return false; - } - -#ifndef FEATURE_T6 // T6 did not have this check in version 1, so to stay backwards compatible, let it stay that way - std::string game; - jRoot.at("_game").get_to(game); - if (game != GAME_LOWER) - { - std::cerr << std::format("Tried to load material \"{}\" but \"_game\" did not find expected type value {}\n", material.info.name, GAME_LOWER); - return false; - } -#endif - try { + const auto jRoot = json::parse(m_stream); + std::string type; + unsigned version; + + jRoot.at("_type").get_to(type); + jRoot.at("_version").get_to(version); + + if (type != "material" || version != 1u) + { + std::cerr << std::format("Tried to load material \"{}\" but did not find expected type material of version 1\n", material.info.name); + return false; + } + +#ifndef FEATURE_T6 // T6 did not have this check in version 1, so to stay backwards compatible, let it stay that way + std::string game; + jRoot.at("_game").get_to(game); + if (game != GAME_LOWER) + { + std::cerr << std::format("Tried to load material \"{}\" but \"_game\" did not find expected type value {}\n", material.info.name, GAME_LOWER); + return false; + } +#endif + const auto jMaterial = jRoot.get(); return CreateMaterialFromJson(jMaterial, material); } diff --git a/src/ObjLoading/XModel/LoaderXModel.cpp.template b/src/ObjLoading/XModel/LoaderXModel.cpp.template index d0396fcf..ff4bf151 100644 --- a/src/ObjLoading/XModel/LoaderXModel.cpp.template +++ b/src/ObjLoading/XModel/LoaderXModel.cpp.template @@ -81,21 +81,21 @@ namespace private: bool LoadFromFile(std::istream& jsonStream, XModel& xmodel, AssetCreationContext& context, AssetRegistration& registration) { - const auto jRoot = nlohmann::json::parse(jsonStream); - std::string type; - unsigned version; - - jRoot.at("_type").get_to(type); - jRoot.at("_version").get_to(version); - - if (type != "xmodel" || version != 1u) - { - std::cerr << std::format("Tried to load xmodel \"{}\" but did not find expected type material of version 1\n", xmodel.name); - return false; - } - try { + const auto jRoot = nlohmann::json::parse(jsonStream); + std::string type; + unsigned version; + + jRoot.at("_type").get_to(type); + jRoot.at("_version").get_to(version); + + if (type != "xmodel" || version != 1u) + { + std::cerr << std::format("Tried to load xmodel \"{}\" but did not find expected type material of version 1\n", xmodel.name); + return false; + } + const auto jXModel = jRoot.get(); return CreateXModelFromJson(jXModel, xmodel, context, registration); }