@@ -43,11 +43,9 @@ namespace javaobject {
4343
4444 // Check if descriptor is object or array
4545 if (type == TYPE_OBJECT || type == TYPE_ARRAY) {
46- char typeCode = strm.readByte ();
47- if (typeCode == TYPE_ARRAY) {
46+ if (const char typeCode = strm.readByte (); typeCode == TYPE_ARRAY) {
4847 // Read primitive array
49- const char arrayType = strm.readByte ();
50- if (arrayType != TYPE_OBJECT) {
48+ if (const char arrayType = strm.readByte (); arrayType != TYPE_OBJECT) {
5149 descriptor += arrayType;
5250 } else {
5351 descriptor += parseSignature (clazz, arrayType, strm);
@@ -75,7 +73,7 @@ namespace javaobject {
7573 }
7674
7775 JavaValue SerializedField::readFieldValue (JavaSerializedClassParser &parser,
78- const SerializedField &field,
76+ SerializedField &field,
7977 bio::stream::BinaryInputStream &
8078 strm) {
8179 const auto descriptor = field.desc ;
@@ -100,34 +98,75 @@ namespace javaobject {
10098 // which means we need to shift this down to get the
10199 // correct sign and value.
102100 return JavaValue
103- {static_cast <int32_t >(strm.readBE <uint32_t >() >> 8 )};
101+ {static_cast <int32_t >(strm.readBE <uint32_t >() >> 8 )};
104102 }
105103 if (field.type == TYPE_LONG) {
106104 return JavaValue
107- {static_cast <int64_t >(strm.readBE <uint64_t >() >> 8 )};
105+ {static_cast <int64_t >(strm.readBE <uint64_t >() >> 8 )};
108106 }
109107 if (field.type == TYPE_OBJECT) {
110108 if (descriptor == " Ljava/lang/String;" ) {
111109 return JavaValue{
112110 std::string (strm.readStringWithLength <char >(
113111 bio::util::ByteOrder::BIG,
114- bio::util::string::StringLengthEncoding::LENGTH_PREFIX))};
112+ bio::util::string::StringLengthEncoding::LENGTH_PREFIX))
113+ };
115114 }
116115 strm.seekRelative (-1 );
117- int offset = strm. getOffset ();
118- // Object!
116+
117+ // Parse object
119118 SerializedClass clazz = parser.parseEntry ();
120119 return JavaValue{std::make_shared<JavaObject>(clazz)};
121120 }
122121 if (field.type == TYPE_ARRAY) {
123- // Array!
124- return readFieldValue (parser, field, strm);
122+ // Read TCBlockData as a Java Array is an Object (Block-Like)
123+ strm.seekRelative (1 );
124+ auto desc = strm.readStringWithLength <char >(bio::util::ByteOrder::BIG,
125+ bio::util::string::StringLengthEncoding::LENGTH_PREFIX);
126+
127+ JavaArray result;
128+ auto modifiedDesc = std::string (desc);
129+ if (modifiedDesc.starts_with (" [" )) {
130+ modifiedDesc = modifiedDesc.substr (1 );
131+ }
132+ std::ranges::replace (modifiedDesc, ' .' , ' /' );
133+ auto originalType = field.type ;
134+ auto modifiedType = static_cast <EJavaFieldDescriptorType>(modifiedDesc[0 ]);
135+
136+ const int64_t uuid = strm.readBE <int64_t >();
137+ int padding = strm.readSignedByte ();
138+ strm.seekRelative (padding);
139+
140+ if (const uint16_t tcBlockData = strm.readBE <uint16_t >(); tcBlockData != 0x7870 ) {
141+ // LOG_ERROR("TCBlockData could not be found after array value was defined.");
142+ std::cout << tcBlockData << std::endl;
143+ }
144+ int32_t fieldCount = strm.readBE <int32_t >();
145+
146+ field.setDescriptor (modifiedDesc);
147+ field.type = modifiedType;
148+ strm.seekRelative (1 );
149+ for (int i = 0 ; i < fieldCount; i++) {
150+ int offset = strm.getOffset ();
151+ JavaValue value = readFieldValue (parser, field, strm);
152+ offset = strm.getOffset ();
153+ result.push_back (value);
154+ strm.seekRelative (1 );
155+ }
156+ field.setDescriptor (desc);
157+ field.type = originalType;
158+
159+ return result;
125160 }
126161
127162 // LOG_DEBUG("Descriptor not yet implemented!");
128163 return {};
129164 }
130165
166+ void SerializedField::setDescriptor (const std::string &desc) {
167+ this ->desc = desc;
168+ }
169+
131170 std::vector<SerializedClass> JavaSerializedClassParser::parseAllEntries () {
132171 std::vector<SerializedClass> result;
133172 if (!this ->m_stream .getStream ().eof ()) {
@@ -202,4 +241,4 @@ namespace javaobject {
202241 this ->m_serializedClasses .push_back (result);
203242 return result;
204243 }
205- } // lodestone::minecraft::common::java::classic::minev3
244+ } // lodestone::minecraft::common::java::classic::minev3
0 commit comments