diff --git a/PanoPainter.vcxproj b/PanoPainter.vcxproj index 5afadfe..2f9c14a 100644 --- a/PanoPainter.vcxproj +++ b/PanoPainter.vcxproj @@ -77,7 +77,7 @@ true - libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;libs\sqlite3;libs\openvr\headers;libs\nanort;libs\hash-library;$(IncludePath) + libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;libs\sqlite3;libs\openvr\headers;libs\nanort;libs\hash-library;libs\fmt\include;$(IncludePath) libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);libs\bugtrap-client\lib;libs\openvr\lib\win64;$(LibraryPath) @@ -87,7 +87,7 @@ false - libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;libs\sqlite3;libs\openvr\headers;libs\nanort;libs\hash-library;$(IncludePath) + libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;libs\sqlite3;libs\openvr\headers;libs\nanort;libs\hash-library;libs\fmt\include;$(IncludePath) libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);libs\bugtrap-client\lib;libs\openvr\lib\win64;$(LibraryPath) @@ -169,6 +169,14 @@ + + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing NotUsing diff --git a/PanoPainter.vcxproj.filters b/PanoPainter.vcxproj.filters index accaeb7..308fe48 100644 --- a/PanoPainter.vcxproj.filters +++ b/PanoPainter.vcxproj.filters @@ -49,6 +49,9 @@ {2a784067-6741-47a3-b668-cc45f2224286} + + {7b4f5b47-7a8b-4e4c-9e82-399bb5047ffc} + @@ -291,6 +294,12 @@ Source Files + + libs\fmt + + + libs\fmt + diff --git a/src/abr.cpp b/src/abr.cpp index a7a6970..37c40bd 100644 --- a/src/abr.cpp +++ b/src/abr.cpp @@ -45,6 +45,8 @@ bool ABR::section_desc() auto name = rkey_or_string(); auto list = rstring(4); auto list_val = call(list); + auto out = list_val->str(0, ""); + std::cout << out; return true; } @@ -66,14 +68,14 @@ std::shared_ptr ABR::parse_vlls() { auto ret = std::make_shared(); auto count = ru32(); - printf("list: %d\n", count); + //printf("list: %d\n", count); for (int i = 0; i < count; i++) { auto type = rstring(4); auto item = call(type); if (!item) return nullptr; - ret->children.push_back(item); + ret->items.push_back(item); } return ret; } @@ -82,7 +84,7 @@ std::shared_ptr ABR::parse_text() { auto ret = std::make_shared(); ret->value = rwstring(); - wprintf(L"text: %s\n", ret->value.c_str()); + //wprintf(L"text: %s\n", ret->value.c_str()); return ret; } @@ -100,7 +102,7 @@ std::shared_ptr ABR::parse_objc() ret->name = rwstring(); ret->class_id = rkey_or_string(); auto count = ru32(); - printf("objc type %s, %d props\n", ret->class_id.c_str(), count); + //printf("objc type %s, %d props\n", ret->class_id.c_str(), count); for (int i = 0; i < count; i++) { auto key = rkey_or_string(); @@ -121,7 +123,7 @@ std::shared_ptr ABR::parse_untf() auto ret = std::make_shared(); ret->unit = rstring(4); ret->value = rdbl(); - printf("float %s: %f\n", ret->unit.c_str(), ret->value); + //printf("float %s: %f\n", ret->unit.c_str(), ret->value); return ret; } @@ -129,7 +131,7 @@ std::shared_ptr ABR::parse_bool() { auto ret = std::make_shared(); ret->value = ru8(); - printf("bool: %s\n", ret->value ? "true" : "false"); + //printf("bool: %s\n", ret->value ? "true" : "false"); return ret; } @@ -137,7 +139,7 @@ std::shared_ptr ABR::parse_long() { auto ret = std::make_shared(); ret->value = ru32(); - printf("long: %d\n", ret->value); + //printf("long: %d\n", ret->value); return ret; } @@ -145,7 +147,7 @@ std::shared_ptr ABR::parse_doub() { auto ret = std::make_shared(); ret->value = rdbl(); - printf("double: %d\n", ret->value); + //printf("double: %d\n", ret->value); return ret; } @@ -154,7 +156,7 @@ std::shared_ptr ABR::parse_enum() auto ret = std::make_shared(); auto t = rkey_or_string(); auto e = rkey_or_string(); - printf("enum: %s %s\n", t.c_str(), e.c_str()); + //printf("enum: %s %s\n", t.c_str(), e.c_str()); return ret; } diff --git a/src/abr.h b/src/abr.h index 3f44f4c..aee157d 100644 --- a/src/abr.h +++ b/src/abr.h @@ -1,6 +1,8 @@ #pragma once #include "asset.h" #include +#include +#include "util.h" class BinaryStream { @@ -31,9 +33,9 @@ public: m_byte_order = byte_order; m_swap = byte_order == ByteOrder::Host ? false : byte_order != sys_order(); } - inline void skip(size_t bytes) { m_cur += bytes; } - inline bool eof() { return std::distance(m_ptr, m_cur) >= m_size; } - inline bool has_data(size_t sz) { return std::distance(m_ptr, m_cur + sz) < m_size; } + void skip(size_t bytes) { m_cur += bytes; } + bool eof() { return std::distance(m_ptr, m_cur) >= m_size; } + bool has_data(size_t sz) { return std::distance(m_ptr, m_cur + sz) < m_size; } uint8_t ru8() { return read(); } uint16_t ru16() { return m_swap ? swap(read()) : read(); } uint32_t ru32() { return m_swap ? swap(read()) : read(); } @@ -45,21 +47,23 @@ public: float rflt() { return read(); } double rdbl() { return read(); } std::string pick(size_t chars) { return { (char*)m_cur, chars }; } - std::string rstring() { auto len = ru32(); return { advance(len), len }; } + std::string rstring() + { + auto len = ru32(); + return { advance(len), len }; + } std::string rstring(size_t len) { return { advance(len), len }; } - std::wstring rwstring() { auto len = ru32(); return rwstring(len); } - std::wstring rwstring(size_t len) { - //std::wstring_convert> conv; - char* ptr = advance(len * 2); + std::wstring rwstring() + { + auto len = ru32(); + return rwstring(len); + } + std::wstring rwstring(size_t len) + { + auto ptr = advance(len * 2); for (int i = 0; i < len; i++) std::swap(ptr[i * 2], ptr[i * 2 + 1]); - //auto s = conv.from_bytes(ptr, ptr + len); - wchar_t* wptr = (wchar_t*)ptr; - //std::wstring_convert> convert; - //std::string utf8 = convert.to_bytes(wptr, wptr + len); - //std::wstring ws(len, 0); - //mbsrtowcs((wchar_t*)ws.data(), (const char**)&ptr, len, nullptr); - return std::wstring(wptr, len); + return std::wstring((wchar_t*)ptr, len); } protected: template inline T align4(T x) { return ((x - T{1}) & (~(T{3}))) + T{4}; } @@ -127,43 +131,56 @@ private: ByteOrder m_byte_order = ByteOrder::Host; }; -static constexpr const uint32_t abr_s2sig(const char s[4]) -{ - return (uint32_t)(s[0]) << 0 - | (uint32_t)(s[1]) << 8 - | (uint32_t)(s[2]) << 16 - | (uint32_t)(s[3]) << 24; -} - -static constexpr const std::array abr_sig2sz(uint32_t x) -{ - return { - (char)(x >> 0 ), - (char)(x >> 8 ), - (char)(x >> 16), - (char)(x >> 24), - 0 - }; -} - class ABR : public BinaryStream { - struct Type { + struct Type + { using Vec = std::vector>; using Map = std::map>; using Ref = std::shared_ptr; - virtual std::string str() const { return "type"; } + virtual std::string str(int indent, const std::string& prefix) const + { + return "type"; + } }; struct Class : public Type { }; struct Property : public Type { }; struct Reference : public Type { }; - struct List : public Type{ - Type::Vec children; + struct List : public Type + { + Type::Vec items; + virtual std::string str(int indent, const std::string& prefix) const override + { + //return std::string(indent, '-') + prefix + fmt::format("list: {} items", items.size()); + auto ret = std::string(indent, '-') + fmt::format("list: {} props:\n", items.size()); + for (int i = 0; i < items.size(); i++) + ret += items[i]->str(indent + 1, fmt::format("{}) ", i) + "\n"); + return ret; + } + }; + struct Double : public Type + { + double value; + virtual std::string str(int indent, const std::string& prefix) const override + { return std::string(indent, '-') + prefix + fmt::format("double: {}", value); } + }; + struct UnitFloat : public Type + { + std::string unit; + double value; + virtual std::string str(int indent, const std::string& prefix) const override + { return std::string(indent, '-') + prefix + fmt::format("float: {} ({})", value, unit); } + }; + struct String : public Type + { + std::wstring value; + virtual std::string str(int indent, const std::string& prefix) const override + { return std::string(indent, '-') + prefix + fmt::format("string: {}", wstr2str(value)); } + }; + struct Enum : public Type + { + }; - struct Double : public Type { double value; }; - struct UnitFloat : public Type { std::string unit; double value; }; - struct String : public Type { std::wstring value; }; - struct Enum : public Type { }; struct EnumRef : public Type { }; struct Offset : public Type { }; struct Identifier : public Type { }; @@ -172,12 +189,15 @@ class ABR : public BinaryStream struct Integer : public Type { int32_t value; + virtual std::string str(int indent, const std::string& prefix) const override + { return std::string(indent, '-') + prefix + fmt::format("int: {}", value); } }; struct LargeInteger : public Type { }; struct Boolean : public Type { bool value; - virtual std::string str() const override { return "Boolean: " + ; } + virtual std::string str(int indent, const std::string& prefix) const override + { return std::string(indent, '-') + prefix + fmt::format("bool: {}", value); } }; struct Alias : public Type { }; struct Descriptor : public Type @@ -185,6 +205,13 @@ class ABR : public BinaryStream std::wstring name; std::string class_id; Type::Map props; + virtual std::string str(int indent, const std::string& prefix) const override + { + auto ret = std::string(indent, '-') + fmt::format("objc: {} props:", props.size()); + for (const auto& p : props) + ret += "\n" + p.second->str(indent + 1, fmt::format("'{}' ", p.first)); + return ret; + } }; public: