-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62fdf75
commit c92d3e8
Showing
11 changed files
with
194 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[*] | ||
charset = utf-8 | ||
end_of_line = crlf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
tab_width = 4 | ||
ij_continuation_indent_size = 4 | ||
|
||
[*.java] | ||
ij_java_do_while_brace_force = always | ||
ij_java_for_brace_force = always | ||
ij_java_if_brace_force = always | ||
ij_java_while_brace_force = always | ||
ij_java_call_parameters_new_line_after_left_paren = true | ||
ij_java_call_parameters_right_paren_on_new_line = true | ||
ij_java_call_parameters_wrap = off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 43 additions & 32 deletions
75
...ero-dawn-remastered/src/main/java/com/shade/decima/game/hrzr/DirectStorageReaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...zero-dawn-remastered/src/main/java/com/shade/decima/game/hrzr/storage/HorizonAssetId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.shade.decima.game.hrzr.storage; | ||
|
||
import com.shade.decima.game.AssetId; | ||
import com.shade.util.NotNull; | ||
import com.shade.util.hash.Hashing; | ||
|
||
import java.util.Locale; | ||
import java.util.UUID; | ||
|
||
public record HorizonAssetId(long fileHash, @NotNull UUID objectUuid) implements AssetId { | ||
public static HorizonAssetId ofPath(@NotNull String path, @NotNull String uuid) { | ||
var norm = path.toLowerCase(Locale.ROOT) + '\0'; | ||
var hash = Hashing.decimaMurmur3().hashString(norm).asLong(); | ||
return new HorizonAssetId(hash, UUID.fromString(uuid)); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...dawn-remastered/src/main/java/com/shade/decima/game/hrzr/storage/HorizonAssetManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.shade.decima.game.hrzr.storage; | ||
|
||
import com.shade.decima.game.AssetId; | ||
import com.shade.decima.game.AssetManager; | ||
import com.shade.decima.game.hrzr.rtti.HRZRTypeReader; | ||
import com.shade.decima.game.hrzr.rtti.HorizonZeroDawnRemastered.GGUUID; | ||
import com.shade.decima.game.hrzr.rtti.HorizonZeroDawnRemastered.RTTIRefObject; | ||
import com.shade.decima.rtti.factory.TypeFactory; | ||
import com.shade.util.NotNull; | ||
import com.shade.util.io.BinaryReader; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.NoSuchElementException; | ||
import java.util.UUID; | ||
|
||
public class HorizonAssetManager implements AssetManager, Closeable { | ||
private final PackFileManager packFileManager; | ||
private final TypeFactory typeFactory; | ||
|
||
public HorizonAssetManager(@NotNull PackFileManager packFileManager, @NotNull TypeFactory typeFactory) { | ||
this.packFileManager = packFileManager; | ||
this.typeFactory = typeFactory; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public <T> T get(@NotNull AssetId id, @NotNull Class<T> type) throws IOException { | ||
var assetId = (HorizonAssetId) id; | ||
var objectUUID = convertUUID(assetId.objectUuid()); | ||
|
||
var buffer = packFileManager.load(PackFileAssetId.ofHash(assetId.fileHash())); | ||
var objects = new HRZRTypeReader().read(BinaryReader.wrap(buffer), typeFactory); | ||
|
||
var object = objects.stream() | ||
.map(RTTIRefObject.class::cast) | ||
.filter(o -> o.general().objectUUID().equals(objectUUID)) | ||
.findFirst().orElseThrow(() -> new NoSuchElementException("Can't find asset " + id)); | ||
|
||
return type.cast(object); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
packFileManager.close(); | ||
} | ||
|
||
@NotNull | ||
private GGUUID convertUUID(@NotNull UUID uuid) { | ||
var msb = uuid.getMostSignificantBits(); | ||
var lsb = uuid.getLeastSignificantBits(); | ||
|
||
var object = typeFactory.newInstance(GGUUID.class); | ||
object.data0((byte) (msb >>> 56)); | ||
object.data1((byte) (msb >>> 48)); | ||
object.data2((byte) (msb >>> 40)); | ||
object.data3((byte) (msb >>> 32)); | ||
object.data4((byte) (msb >>> 24)); | ||
object.data5((byte) (msb >>> 16)); | ||
object.data6((byte) (msb >>> 8)); | ||
object.data7((byte) (msb)); | ||
object.data8((byte) (lsb >>> 56)); | ||
object.data9((byte) (lsb >>> 48)); | ||
object.data10((byte) (lsb >>> 40)); | ||
object.data11((byte) (lsb >>> 32)); | ||
object.data12((byte) (lsb >>> 24)); | ||
object.data13((byte) (lsb >>> 16)); | ||
object.data14((byte) (lsb >>> 8)); | ||
object.data15((byte) (lsb)); | ||
|
||
return object; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
modules/decima-game/src/main/java/com/shade/decima/game/AssetManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.shade.decima.game; | ||
|
||
import com.shade.util.NotNull; | ||
|
||
import java.io.IOException; | ||
|
||
public interface AssetManager { | ||
@NotNull | ||
<T> T get(@NotNull AssetId id, @NotNull Class<T> type) throws IOException; | ||
} |
4 changes: 2 additions & 2 deletions
4
...ecima/game/hrzr/storage/PathResolver.java → ...ava/com/shade/decima/game/FileSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package com.shade.decima.game.hrzr.storage; | ||
package com.shade.decima.game; | ||
|
||
import com.shade.util.NotNull; | ||
|
||
import java.nio.file.Path; | ||
|
||
public interface PathResolver { | ||
public interface FileSystem { | ||
@NotNull | ||
Path resolve(@NotNull String path); | ||
} |