/*
 * Copyright (c) 2016 acmi
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package acmi.l2.clientmod.unreal.core;

import acmi.l2.clientmod.io.annotation.Custom;
import acmi.l2.clientmod.unreal.UUIDSerializer;
import acmi.l2.clientmod.unreal.annotation.NameRef;
import acmi.l2.clientmod.unreal.annotation.ObjectRef;

import java.util.UUID;

public class Class extends State {
    public int classFlags;
    @Custom(UUIDSerializer.class)
    public UUID classUuid;
    public Dependency[] dependencies;
    @NameRef
    public String[] packageImports;
    @ObjectRef
    public Object classWithin;
    @NameRef
    public String classConfigName;
    @NameRef
    public String[] hideCategories;

    public static class Dependency {
        @ObjectRef
        public acmi.l2.clientmod.unreal.core.Class clazz;
        public int deep;
        public int scriptTextCRC;
    }
}

@@ -1142,16 +1142,58 @@
 .core;%0A%0A
+import acmi.l2.clientmod.io.ObjectOutput;%0A
 import a
@@ -1231,16 +1231,68 @@
 Custom;%0A
+import acmi.l2.clientmod.io.annotation.WriteMethod;%0A
 import a
@@ -1331,16 +1331,70 @@
 alizer;%0A
+import acmi.l2.clientmod.unreal.UnrealRuntimeContext;%0A
 import a
@@ -1495,30 +1495,199 @@
 ef;%0A
-%0Aimport java.util.UUID
+import acmi.l2.clientmod.unreal.properties.PropertiesUtil;%0A%0Aimport java.util.Arrays;%0Aimport java.util.Optional;%0Aimport java.util.UUID;%0A%0Aimport static acmi.l2.clientmod.io.ByteUtil.uuidToBytes
 ;%0A%0Ap
@@ -2217,11 +2217,1400 @@
 C;%0A    %7D
+%0A%0A    @WriteMethod%0A    public final void writeClass(ObjectOutput%3CUnrealRuntimeContext%3E output) %7B%0A        output.writeInt(classFlags);%0A        output.writeBytes(uuidToBytes(classUuid));%0A        Dependency%5B%5D dependencies = Optional.ofNullable(this.dependencies).orElse(new Dependency%5B0%5D);%0A        output.writeCompactInt(dependencies.length);%0A        Arrays.stream(dependencies).forEach(output::write);%0A        String%5B%5D packageImports = Optional.ofNullable(this.packageImports).orElse(new String%5B0%5D);%0A        output.writeCompactInt(packageImports.length);%0A        Arrays.stream(packageImports).mapToInt(n -%3E output.getContext().getUnrealPackage().nameReference(n)).forEach(output::writeCompactInt);%0A        output.writeCompactInt(Optional.ofNullable(classWithin).map(o -%3E output.getContext().getUnrealPackage().objectReferenceByName(o.entry.getObjectFullName(), c -%3E c.equalsIgnoreCase(o.entry.getFullClassName()))).orElse(0));%0A        output.writeCompactInt(output.getContext().getUnrealPackage().nameReference(classConfigName));%0A        String%5B%5D hideCategories = Optional.ofNullable(this.hideCategories).orElse(new String%5B0%5D);%0A        output.writeCompactInt(hideCategories.length);%0A        Arrays.stream(hideCategories).mapToInt(n -%3E output.getContext().getUnrealPackage().nameReference(n)).forEach(output::writeCompactInt);%0A        PropertiesUtil.writeProperties(output, properties);%0A    %7D
 %0A%7D%0A

Fix #22