Skip to content

Commit

Permalink
Type representation at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Nov 13, 2024
1 parent c6bb2c1 commit 0b48e99
Show file tree
Hide file tree
Showing 39 changed files with 843 additions and 660 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand All @@ -11,6 +12,6 @@ public interface AnimatedTextureData {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull AnimatedTextureData object) throws IOException {
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull AnimatedTextureData object) throws IOException {
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand All @@ -12,7 +13,7 @@ public interface LuaScript {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull LuaScript object) throws IOException {
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull LuaScript object) throws IOException {
var flags = reader.readInt();
if (flags != 0) {
var name1 = reader.readString(reader.readInt());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand Down Expand Up @@ -30,12 +31,12 @@ public interface ExternalSource {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull ExternalSourceList object) throws IOException {
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull ExternalSourceList object) throws IOException {
var count = reader.readInt();
var sources = new ArrayList<ExternalSource>(count);

for (int i = 0; i < count; i++) {
ExternalSource source = RTTI.newInstance(ExternalSource.class);
ExternalSource source = factory.newInstance(ExternalSource.class);
source.name(reader.readString(reader.readInt()));
source.data(reader.readBytes(reader.readInt()));
sources.add(source);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand All @@ -16,7 +17,7 @@ public interface HavokData {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull HavokData object) throws IOException {
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull HavokData object) throws IOException {
object.havokData(reader.readBytes(reader.readInt()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand Down Expand Up @@ -43,7 +44,7 @@ public interface Indices {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull Indices object) throws IOException {
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull Indices object) throws IOException {
object.count(reader.readInt());
if (object.count() > 0) {
object.flags(reader.readInt());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand All @@ -16,7 +17,7 @@ public interface MorphemeAnimationData {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull MorphemeAnimationData object) throws IOException {
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull MorphemeAnimationData object) throws IOException {
object.data(reader.readBytes(reader.readInt()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand All @@ -19,7 +20,7 @@ public interface NavMeshData {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull NavMeshData object) throws IOException {
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull NavMeshData object) throws IOException {
var start = reader.position();
var navMeshSetMagic = reader.readInt();
var navMeshSetVersion = reader.readInt();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand All @@ -16,7 +17,7 @@ public interface HavokDataBlock {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull HavokDataBlock object) throws IOException {
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull HavokDataBlock object) throws IOException {
object.data(reader.readBytes(reader.readInt()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand All @@ -16,7 +17,7 @@ public interface MovieData {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull MovieData object) throws IOException {
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull MovieData object) throws IOException {
object.data(reader.readBytes(Math.toIntExact(reader.readLong())));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand All @@ -16,7 +17,7 @@ public interface ShaderData {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull ShaderData object) throws IOException {
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull ShaderData object) throws IOException {
object.data(reader.readBytes(reader.readInt()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.data.DataSource;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
Expand Down Expand Up @@ -48,7 +49,7 @@ public interface TextureHeader {
void unk0B(byte[] value);

@NotNull
static TextureHeader read(@NotNull BinaryReader reader) throws IOException {
static TextureHeader read(@NotNull BinaryReader reader, @NotNull TypeFactory factory) throws IOException {
var type = ETextureType.valueOf(reader.readByte());
var width = 1 << reader.readByte();
var height = 1 << reader.readByte();
Expand All @@ -57,7 +58,7 @@ static TextureHeader read(@NotNull BinaryReader reader) throws IOException {
var pixelFormat = EPixelFormat.valueOf(reader.readByte());
var unk0B = reader.readBytes(20 + 16);

var object = RTTI.newInstance(TextureHeader.class);
var object = factory.newInstance(TextureHeader.class);
object.type(type);
object.width(width);
object.height(height);
Expand Down Expand Up @@ -102,7 +103,7 @@ public interface TextureData {
void streamedData(DataSource value);

@NotNull
static TextureData read(@NotNull BinaryReader reader) throws IOException {
static TextureData read(@NotNull BinaryReader reader, @NotNull TypeFactory factory) throws IOException {
var remainingSize = reader.readInt();
var start = reader.position();

Expand All @@ -113,10 +114,10 @@ static TextureData read(@NotNull BinaryReader reader) throws IOException {

var streamedMips = reader.readInt();
var embeddedData = reader.readBytes(embeddedSize);
var streamedData = streamedSize > 0 ? DataSource.read(reader) : null;
var streamedData = streamedSize > 0 ? DataSource.read(reader, factory) : null;
assert reader.position() == start + remainingSize;

var object = RTTI.newInstance(TextureData.class);
var object = factory.newInstance(TextureData.class);
object.totalSize(totalSize);
object.embeddedSize(embeddedSize);
object.streamedSize(streamedSize);
Expand All @@ -141,8 +142,8 @@ public interface TextureInfo {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull TextureInfo object) throws IOException {
object.header(TextureHeader.read(reader));
object.data(TextureData.read(reader));
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull TextureInfo object) throws IOException {
object.header(TextureHeader.read(reader, factory));
object.data(TextureData.read(reader, factory));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand Down Expand Up @@ -33,13 +34,13 @@ public interface VertexStreamElement {
void type(EVertexElement value);

@NotNull
static VertexStreamElement read(@NotNull BinaryReader reader) throws IOException {
static VertexStreamElement read(@NotNull BinaryReader reader, @NotNull TypeFactory factory) throws IOException {
var offset = reader.readByte();
var storageType = EVertexElementStorageType.valueOf(reader.readByte());
var slotsUsed = reader.readByte();
var type = EVertexElement.valueOf(reader.readByte());

var element = RTTI.newInstance(VertexStreamElement.class);
var element = factory.newInstance(VertexStreamElement.class);
element.offset(offset);
element.storageType(storageType);
element.slotsUsed(slotsUsed);
Expand Down Expand Up @@ -76,14 +77,14 @@ public interface VertexStream {
void data(byte[] value);

@NotNull
static VertexStream read(@NotNull BinaryReader reader, int numVertices) throws IOException {
static VertexStream read(@NotNull BinaryReader reader, @NotNull TypeFactory factory, int numVertices) throws IOException {
var flags = reader.readInt();
var stride = reader.readInt();
var elements = reader.readObjects(reader.readInt(), VertexStreamElement::read);
var elements = reader.readObjects(reader.readInt(), r -> VertexStreamElement.read(r, factory));
var hash = reader.readBytes(16);
var data = reader.readBytes(stride * numVertices);

var stream = RTTI.newInstance(VertexStream.class);
var stream = factory.newInstance(VertexStream.class);
stream.flags(flags);
stream.stride(stride);
stream.elements(elements);
Expand All @@ -107,10 +108,10 @@ public interface VertexArrayData {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull VertexArrayData object) throws IOException {
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull VertexArrayData object) throws IOException {
var numVertices = reader.readInt();
var numStreams = reader.readInt();
var streams = reader.readObjects(numStreams, r -> VertexStream.read(r, numVertices));
var streams = reader.readObjects(numStreams, r -> VertexStream.read(r, factory, numVertices));

object.count(numVertices);
object.streams(streams);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.callbacks;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.decima.rtti.serde.ExtraBinaryDataCallback;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;
Expand All @@ -21,8 +22,8 @@ public interface SoundBankData {
void data(byte[] value);

@NotNull
static SoundBankData read(@NotNull BinaryReader reader) throws IOException {
var object = RTTI.newInstance(SoundBankData.class);
static SoundBankData read(@NotNull BinaryReader reader, @NotNull TypeFactory factory) throws IOException {
var object = factory.newInstance(SoundBankData.class);
object.name(reader.readString(reader.readInt()));
object.data(reader.readBytes(reader.readInt()));

Expand All @@ -38,7 +39,7 @@ public interface SoundBankList {
}

@Override
public void deserialize(@NotNull BinaryReader reader, @NotNull SoundBankList object) throws IOException {
object.soundBanks(reader.readObjects(reader.readInt(), SoundBankData::read));
public void deserialize(@NotNull BinaryReader reader, @NotNull TypeFactory factory, @NotNull SoundBankList object) throws IOException {
object.soundBanks(reader.readObjects(reader.readInt(), r -> SoundBankData.read(r, factory)));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.rtti.data;

import com.shade.decima.rtti.RTTI;
import com.shade.decima.rtti.TypeFactory;
import com.shade.util.NotNull;
import com.shade.util.io.BinaryReader;

Expand All @@ -23,8 +24,8 @@ public interface DataSource {
void length(long value);

@NotNull
static DataSource read(@NotNull BinaryReader reader) throws IOException {
DataSource source = RTTI.newInstance(DataSource.class);
static DataSource read(@NotNull BinaryReader reader, @NotNull TypeFactory factory) throws IOException {
DataSource source = factory.newInstance(DataSource.class);
source.location(reader.readString(reader.readInt()));
source.offset(reader.readLong());
source.length(reader.readLong());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.shade.decima.rtti.test;

public class TypeFactoryTest {
public static void main(String[] args) {
//var factory = new UntilDawnTypeFactory();
//var info = factory.get(UntilDawn.Vec3.class);
//var object = factory.newInstance(info);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.shade.decima.rtti.test;

import com.shade.util.io.BinaryReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -15,12 +14,8 @@ public class UntilDawnMain {
private static final Logger log = LoggerFactory.getLogger(UntilDawnMain.class);

public static void main(String[] args) throws IOException {
Path cache = Path.of("D:/PlayStation Games/Until Dawn/localcachepink");
Path lump = cache.resolve("lumps/assets_description.application_concreteasset.core");

try (BinaryReader reader = CompressedBinaryReader.open(lump)) {
Files.write(Path.of("samples/until_dawn/assets_description.application_concreteasset.core"), reader.readBytes(Math.toIntExact(reader.size())));
}
var factory = new UntilDawnTypeFactory();
var cache = Path.of("D:/PlayStation Games/Until Dawn/localcachepink");

Files.walkFileTree(cache.resolve("lumps"), new SimpleFileVisitor<>() {
@Override
Expand All @@ -34,7 +29,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
return FileVisitResult.CONTINUE;
}
log.info("Reading {}", file);
try (UntilDawnReader reader = new UntilDawnReader(CompressedBinaryReader.open(file))) {
try (UntilDawnReader reader = new UntilDawnReader(CompressedBinaryReader.open(file), factory)) {
var objects = reader.read();
log.info("Read {} objects", objects.size());
}
Expand Down
Loading

0 comments on commit 0b48e99

Please sign in to comment.