Skip to content

Commit 09234de

Browse files
feat: super classes are included in classData parsing, now it properly reads a Minecraft Classic 0.30 world.
1 parent 7bbcb6f commit 09234de

File tree

6 files changed

+83
-38
lines changed

6 files changed

+83
-38
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION VERSION 3.30)
2-
project(JavaObjectStreams VERSION 1.3.2)
2+
project(JavaObjectStreams VERSION 1.3.3)
33

44
set(CMAKE_CXX_STANDARD 20)
55

src/type/object/parsers/ClassDataParser.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616

1717
#include <assert.h>
1818

19+
#include "JavaObject/type/object/types/AnnotationObject.h"
1920
#include "JavaObject/type/object/types/EndBlockDataObject.h"
21+
#include "JavaObject/type/object/types/descriptor/NewClassDescriptorObject.h"
2022
#include "JavaObject/type/primitive/PrimitiveTypeCodeParser.h"
21-
#include "JavaObject/type/object/types/AnnotationObject.h"
23+
24+
#include <stack>
2225

2326
namespace javaobject::type::object::parsers {
2427
ClassDataParser::ClassDataParser(const std::shared_ptr<object::descriptor::ClassDescriptorInfoObject> &classDescInfo) : m_classDescInfo(classDescInfo) {
@@ -52,17 +55,32 @@ namespace javaobject::type::object::parsers {
5255

5356
auto primitiveParser = parser.parserStorage().primitiveParser;
5457

55-
// BUG WORKAROUND, REMOVE AFTER WE FIND THE FIX
56-
// parser.stream().seekRelative(-2);
57-
for (auto &[name, value] : this->m_classDescInfo->fields) {
58-
const auto typeCode = value->primitiveDescriptor->typeCode;
58+
std::deque<std::shared_ptr<descriptor::ClassDescriptorInfoObject>> tree;
5959

60-
//todo check this out since I can't easily see whats going on when using codewithme
61-
std::shared_ptr<primitive::types::IPrimitiveObject> obj = primitiveParser->readUsingParser(*primitiveParser->getParser(typeCode));
60+
std::shared_ptr<IObject> super = this->m_classDescInfo;
61+
while (typeid(*super) != typeid(NullObject)) {
62+
auto sp = std::static_pointer_cast<descriptor::ClassDescriptorInfoObject>(super);
63+
tree.push_front(sp);
64+
65+
auto nsp = std::dynamic_pointer_cast<descriptor::NewClassDescriptorObject>(sp->superClassDescriptor);
66+
if (nsp == nullptr) {
67+
break;
68+
}
6269

63-
d->values.emplace(name, obj);
70+
super = nsp->info;
6471
}
6572

73+
std::ranges::for_each(tree, [primitiveParser, &d](const std::shared_ptr<descriptor::ClassDescriptorInfoObject> &c) {
74+
for (auto &[name, value] : c->fields) {
75+
const auto typeCode = value->primitiveDescriptor->typeCode;
76+
77+
//todo check this out since I can't easily see whats going on when using codewithme
78+
std::shared_ptr<primitive::types::IPrimitiveObject> obj = primitiveParser->readUsingParser(*primitiveParser->getParser(typeCode));
79+
80+
d->values.emplace(name, obj);
81+
}
82+
});
83+
6684
return d;
6785
}
6886

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package me.dexrn.jos.common.test;
2+
3+
import java.io.Serial;
4+
import java.io.Serializable;
5+
6+
public class JOSEmptyClass implements Serializable {
7+
@Serial
8+
private static final long serialVersionUID = 0x1234567890123456L;
9+
}

tests/java/modules/Common/src/main/java/me/dexrn/jos/common/test/JOSTestClass.java

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,43 @@
1010
*/
1111
package me.dexrn.jos.common.test;
1212

13+
import me.dexrn.jos.common.test.polymorphism.JOSPolymorphicClass;
14+
1315
import java.io.Serializable;
1416
import java.util.ArrayList;
1517
import java.util.List;
1618

1719
public class JOSTestClass implements Serializable {
18-
public class Subclass implements Serializable {
19-
boolean b = true;
20-
char c = 'b';
21-
byte bt = 7;
22-
short s = 8;
23-
int i = 9;
24-
long l = 10;
25-
float f = 11.0f;
26-
double d = 12.0;
27-
}
20+
// public class Subclass implements Serializable {
21+
// boolean b = true;
22+
// char c = 'b';
23+
// byte bt = 7;
24+
// short s = 8;
25+
// int i = 9;
26+
// long l = 10;
27+
// float f = 11.0f;
28+
// double d = 12.0;
29+
// }
2830

29-
Subclass sc = new Subclass();
30-
JOSDataClass dc = new JOSDataClass();
31-
JOSArrayClass ac = new JOSArrayClass();
32-
JOSNestedArrayClass nac = new JOSNestedArrayClass();
33-
34-
boolean b = false;
35-
char c = 'a';
36-
byte bt = 1;
37-
short s = 2;
38-
int i = 3;
39-
long l = 4;
40-
float f = 5.0f;
41-
double d = 6.0;
42-
String str = "Hello, world!";
43-
44-
List<Character> carr = new ArrayList<Character>();
45-
{
46-
str.chars().forEach(c -> carr.add((char) c));
47-
}
31+
// Subclass sc = new Subclass();
32+
// JOSDataClass dc = new JOSDataClass();
33+
// JOSArrayClass ac = new JOSArrayClass();
34+
// JOSNestedArrayClass nac = new JOSNestedArrayClass();
35+
// JOSEmptyClass ec = new JOSEmptyClass();
36+
JOSPolymorphicClass pc = new JOSPolymorphicClass();
37+
38+
// boolean b = false;
39+
// char c = 'a';
40+
// byte bt = 1;
41+
// short s = 2;
42+
// int i = 3;
43+
// long l = 4;
44+
// float f = 5.0f;
45+
// double d = 6.0;
46+
// String str = "Hello, world!";
47+
//
48+
// List<Character> carr = new ArrayList<Character>();
49+
// {
50+
// str.chars().forEach(c -> carr.add((char) c));
51+
// }
4852
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package me.dexrn.jos.common.test.polymorphism;
2+
3+
import java.io.Serializable;
4+
5+
public abstract class JOSPolymorphicBase implements Serializable {
6+
int i = 0;
7+
long hfdiukjhsdjfihsdkjihjukosfsfkjhbsjdhkfbsjhknfbhjuisdfbhjksdbfhjkisbdfhjbsdfhjkbsdfhshdjfghjsdfghjsdgfhjgsdhfjgsdhjfgshjdfhfdiukjhsdjfihsdkjihjukosfsfkjhbsjdhkfbsjhknfbhjuisdfbhjksdbfhjkisbdfhjbsdfhjkbsdfhshdjfghjsdfghjsdgfhjgsdhfjgsdhjfgshjdfhfdiukjhsdjfihsdkjihjukosfsfkjhbsjdhkfbsjhknfbhjuisdfbhjksdbfhjkisbdfhjbsdfhjkbsdfhshdjfghjsdfghjsdgfhjgsdhfjgsdhjfgshjdfhfdiukjhsdjfihsdkjihjukosfsfkjhbsjdhkfbsjhknfbhjuisdfbhjksdbfhjkisbdfhjbsdfhjkbsdfhshdjfghjsdfghjsdgfhjgsdhfjgsdhjfgshjdf = 5;
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package me.dexrn.jos.common.test.polymorphism;
2+
3+
import java.io.Serializable;
4+
5+
public class JOSPolymorphicClass extends JOSPolymorphicBase implements Serializable {
6+
}

0 commit comments

Comments
 (0)