[FIX] Нормальная сериализация Enum.

This commit is contained in:
Zaxar163 2020-02-10 19:10:08 +01:00
parent bde9fd55f9
commit 0e4502d38f
No known key found for this signature in database
GPG key ID: 1FE4F2E1F053831B
3 changed files with 9 additions and 1 deletions

View file

@ -171,6 +171,8 @@ private static InsnList serializeValue(Object value) {
insnList.add(new LdcInsnNode(value)); insnList.add(new LdcInsnNode(value));
return insnList; return insnList;
} }
if (Enum.class.isInstance(value))
return NodeUtils.makeValueEnumGetter((Enum)value);
for (Map.Entry<Class<?>, Serializer<?>> serializerEntry : serializers.entrySet()) { for (Map.Entry<Class<?>, Serializer<?>> serializerEntry : serializers.entrySet()) {
if (serializerEntry.getKey().isInstance(value)) { if (serializerEntry.getKey().isInstance(value)) {
return ((Serializer) serializerEntry.getValue()).serialize(value); return ((Serializer) serializerEntry.getValue()).serialize(value);

View file

@ -246,4 +246,11 @@ else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
ret.add(new LdcInsnNode(value)); ret.add(new LdcInsnNode(value));
return ret; return ret;
} }
public static InsnList makeValueEnumGetter(@SuppressWarnings("rawtypes") Enum u) {
InsnList ret = new InsnList();
Type e = Type.getType(u.getClass());
ret.add(new FieldInsnNode(Opcodes.GETSTATIC, e.getInternalName(), u.name(), e.getDescriptor()));
return ret;
}
} }

View file

@ -8,7 +8,6 @@
import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.FieldNode;
import pro.gravit.launcher.Launcher; import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.LauncherConfig;
import pro.gravit.launcher.LauncherConfig.LauncherEnvironment;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.asm.ClassMetadataReader; import pro.gravit.launchserver.asm.ClassMetadataReader;
import pro.gravit.launchserver.asm.InjectClassAcceptor; import pro.gravit.launchserver.asm.InjectClassAcceptor;