Skip to content

Commit

Permalink
Implement some more handlers for HFW types
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Dec 16, 2024
1 parent db337ec commit 777417c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import com.shade.decima.game.hfw.rtti.HFWTypeFactory;
import com.shade.decima.game.hfw.rtti.HFWTypeReader;
import com.shade.decima.game.hfw.rtti.HorizonForbiddenWest;
import com.shade.decima.game.hfw.rtti.HorizonForbiddenWest.EPlatform;
import com.shade.decima.game.hfw.storage.*;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;

import java.io.IOException;
import java.nio.file.Path;

import static com.shade.decima.game.hfw.rtti.HorizonForbiddenWest.EPlatform;

public class ForbiddenWestTest {
public static void main(String[] args) throws IOException {
var source = Path.of("E:/SteamLibrary/steamapps/common/Horizon Forbidden West Complete Edition");
Expand All @@ -33,7 +32,7 @@ public static void main(String[] args) throws IOException {
ObjectStreamingSystem system = new ObjectStreamingSystem(device, graph);
StreamingObjectReader reader = new StreamingObjectReader(system, factory);

HFWTypeReader.ObjectInfo result = reader.readObject("00377119-c8e7-45d7-b37d-0f6e240c3116");
HFWTypeReader.ObjectInfo result = reader.readObject("fc8546a6-d890-4f7a-aa4b-febc111cf96a");
System.out.println(result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
public class HFWTypeReader extends AbstractTypeReader {
public record ObjectInfo(@NotNull RTTIRefObject object, @NotNull ClassTypeInfo info) {}

@NotNull
public static <T> T readCompound(@NotNull Class<T> cls, @NotNull BinaryReader reader, @NotNull TypeFactory factory) throws IOException {
return cls.cast(new HFWTypeReader().readCompound(factory.get(cls), reader, factory));
}

@NotNull
public ObjectInfo readObject(@NotNull BinaryReader reader, @NotNull TypeFactory factory) throws IOException {
var hash = reader.readLong();
Expand Down Expand Up @@ -92,7 +97,17 @@ protected Object readAtom(@NotNull AtomTypeInfo info, @NotNull BinaryReader read
@NotNull
@Override
protected Object readEnum(@NotNull EnumTypeInfo info, @NotNull BinaryReader reader, @NotNull TypeFactory factory) throws IOException {
throw new NotImplementedException();
int value = switch (info.size()) {
case Byte.BYTES -> reader.readByte();
case Short.BYTES -> reader.readShort();
case Integer.BYTES -> reader.readInt();
default -> throw new IllegalArgumentException("Unexpected enum size: " + info.size());
};
if (info.isSet()) {
return info.setOf(value);
} else {
return info.valueOf(value);
}
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.shade.decima.game.hfw.rtti.callbacks;

import com.shade.decima.game.hfw.rtti.HorizonForbiddenWest.ELanguage;
import com.shade.decima.rtti.Attr;
import com.shade.decima.rtti.data.ExtraBinaryDataCallback;
import com.shade.decima.rtti.factory.TypeFactory;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class LocalizedTextResourceCallback implements ExtraBinaryDataCallback<LocalizedTextResourceCallback.TranslationData> {
public interface TranslationData {
@Attr(name = "Translations", type = "Array<String>", position = 0, offset = 0)
List<String> translations();

void translations(List<String> translations);
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull TranslationData object) throws IOException {
var count = ELanguage.values().length - 1; // Excluding "Unknown"
var translations = new ArrayList<String>(count);
for (int i = 0; i < count; i++) {
translations.add(reader.readString(Short.toUnsignedInt(reader.readShort())));
}
object.translations(translations);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.shade.decima.game.hfw.rtti.callbacks;

import com.shade.decima.game.hfw.rtti.HFWTypeReader;
import com.shade.decima.game.hfw.rtti.HorizonForbiddenWest.MurmurHashValue;
import com.shade.decima.rtti.Attr;
import com.shade.decima.rtti.data.ExtraBinaryDataCallback;
import com.shade.decima.rtti.factory.TypeFactory;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;

import java.io.IOException;

public class ShaderResourceCallback implements ExtraBinaryDataCallback<ShaderResourceCallback.ShaderData> {
public interface ShaderData {
@Attr(name = "Hash", type = "MurmurHashValue", position = 0, offset = 0)
MurmurHashValue hash();

void hash(MurmurHashValue hash);

@Attr(name = "Data", type = "uint8", position = 1, offset = 8)
byte[] data();

void data(byte[] data);
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull ShaderData object) throws IOException {
var size = reader.readInt();
object.hash(HFWTypeReader.readCompound(MurmurHashValue.class, reader, factory));
object.data(reader.readBytes(size));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import com.shade.decima.game.hfw.rtti.callbacks.TextureCallback;
import com.shade.decima.game.hfw.rtti.callbacks.UITextureCallback;
import com.shade.decima.game.hfw.rtti.callbacks.UITextureFramesCallback;
import com.shade.decima.game.hfw.rtti.callbacks.*;
import com.shade.decima.rtti.generator.GenerateBindings;
import com.shade.decima.rtti.generator.GenerateBindings.Builtin;
import com.shade.decima.rtti.generator.GenerateBindings.Callback;
Expand Down Expand Up @@ -35,6 +33,8 @@
@Builtin(type = "WString", javaType = String.class),
},
callbacks = {
@Callback(type = "LocalizedTextResource", handler = LocalizedTextResourceCallback.class),
@Callback(type = "ShaderResource", handler = ShaderResourceCallback.class),
@Callback(type = "Texture", handler = TextureCallback.class),
@Callback(type = "UITexture", handler = UITextureCallback.class),
@Callback(type = "UITextureFrames", handler = UITextureFramesCallback.class),
Expand Down

0 comments on commit 777417c

Please sign in to comment.