diff --git a/Source/Utility/JsonCppLoader.cpp b/Source/Utility/JsonCppLoader.cpp index a7a7479c1..c10625f14 100644 --- a/Source/Utility/JsonCppLoader.cpp +++ b/Source/Utility/JsonCppLoader.cpp @@ -44,3 +44,100 @@ bool JsonCppLoader::GetMapStringBoolValue(const JsonValue& node, const std::stri return true; } + +// OFFSET: 0x00508570 +// FUNCTION: fn_00886 +bool JsonCppLoader::GetIntValue(const JsonValue& node, const std::string& key, int* out) { + JsonValue value; + this->GetValue(value, key, node, JsonValue::INT64_VALUE); + if (value.IsNull()) { + this->Fail("key 에 해당하는 데이터를 찾지 못했습니다. (keyName : %s)", key.c_str()); + return false; + } + + *out = value.AsInt(); + return true; +} + +// OFFSET: 0x005086D0 +// FUNCTION: fn_00887 +bool JsonCppLoader::GetStringValue(const JsonValue& node, const std::string& key, std::string* out) { + JsonValue value; + this->GetValue(value, key, node, JsonValue::STRING_VALUE); + if (value.IsNull()) { + this->Fail("key 에 해당하는 데이터를 찾지 못했습니다. (keyName : %s)", key.c_str()); + return false; + } + + *out = value.AsString(); + return true; +} + +// OFFSET: 0x005087D0 +// FUNCTION: fn_00888 +bool JsonCppLoader::GetMapStringIntValue(const JsonValue& node, const std::string& key, std::map* out) { + JsonValue value; + this->GetValue(value, key, node, JsonValue::OBJECT_VALUE); + if (value.IsNull()) { + this->Fail("key 에 해당하는 데이터를 찾지 못했습니다. (keyName : %s)", key.c_str()); + return false; + } + + const JsonObject& members = value.GetObject(); + for (JsonObject::const_iterator member = members.begin(); member != members.end(); ++member) { + std::string name = member->first; + JsonValue element = member->second; + if (element.GetType() != JsonValue::INT64_VALUE) { + this->Fail("잘못된 데이터가 입력되었습니다. intValue 가 입력되어야 합니다. (keyName : %s)", key.c_str()); + return false; + } + + if (!out->insert(std::make_pair(name, element.AsInt())).second) { + this->Fail("중복키가 입력되었습니다. (keyName : %s)", key.c_str()); + return false; + } + } + + return true; +} + +// OFFSET: 0x00508BD0 + +// OFFSET: 0x00509130 + +// OFFSET: 0x00509D40 +// FUNCTION: fn_00892 +bool JsonCppLoader::GetIntVectorValue(const JsonValue& node, const std::string& key, std::vector* out) { + JsonValue value; + this->GetValue(value, key, node, JsonValue::ARRAY_VALUE); + if (value.IsNull()) { + this->Fail("key 에 해당하는 데이터를 찾지 못했습니다. (keyName : %s)", key.c_str()); + return false; + } + + const JsonArray& items = value.ArrayRange(); + for (JsonArray::const_iterator item = items.begin(); item != items.end(); ++item) { + if (item->GetType() != JsonValue::INT64_VALUE) { + this->Fail("잘못된 데이터가 입력되었습니다. intValue 가 입력되어야 합니다. (keyName : %s)", key.c_str()); + return false; + } + + out->push_back(item->AsInt()); + } + + return true; +} + +// OFFSET: 0x00509F70 +// FUNCTION: fn_00893 +bool JsonCppLoader::GetBoolValue(const JsonValue& node, const std::string& key, bool* out) { + JsonValue value; + this->GetValue(value, key, node, JsonValue::BOOL_VALUE); + if (value.IsNull()) { + this->Fail("key 에 해당하는 데이터를 찾지 못했습니다. (keyName : %s)", key.c_str()); + return false; + } + + *out = value.AsBool(); + return true; +} diff --git a/Source/Utility/JsonCppLoader.h b/Source/Utility/JsonCppLoader.h index e8a3fe38b..73bf3d1f7 100644 --- a/Source/Utility/JsonCppLoader.h +++ b/Source/Utility/JsonCppLoader.h @@ -42,6 +42,7 @@ public: std::string AsString() const; const JsonObject& GetObject() const; const JsonArray& GetArray() const; + const JsonArray& ArrayRange() const; /* 0000 */ unsigned char type; /* 0001 */ unsigned char unknown_0001; @@ -157,12 +158,27 @@ inline const JsonArray& JsonValue::GetArray() const { return *static_cast(this->Dereference()->pointer); } +inline const JsonArray& JsonValue::ArrayRange() const { + if ((this->type & 0x0f) != 9) { + throw std::domain_error("Not an array"); + } + + return *static_cast(this->pointer); +} + class JsonCppLoader { public: JsonValue& GetValue(JsonValue& out, const std::string& key, const JsonValue& node, int expectedType); void Fail(const char* format, ...); + bool GetIntValue(const JsonValue& node, const std::string& key, int* out); + bool GetStringValue(const JsonValue& node, const std::string& key, std::string* out); + bool GetMapStringIntValue(const JsonValue& node, const std::string& key, std::map* out); + bool GetMapStringStringValue(const JsonValue& node, const std::string& key, std::map* out); + bool GetMapStringIntVectorValue(const JsonValue& node, const std::string& key, std::map >* out); bool GetMapStringBoolValue(const JsonValue& node, const std::string& key, std::map* out); + bool GetIntVectorValue(const JsonValue& node, const std::string& key, std::vector* out); + bool GetBoolValue(const JsonValue& node, const std::string& key, bool* out); bool sub_4F3C70(std::vector& buffer, bool bson); bool sub_50C2A0(std::map* out); bool sub_50AE30(std::map* out);