Skip to content

Commit

Permalink
custom levels: support vanilla skies and texture remapping tables (#3691
Browse files Browse the repository at this point in the history
)

This adds some new JSON entries to custom levels so they can support
vanilla sky textures and the texture remapping tables, allowing for
proper textures on objects that use `generic`, like dark eco pools or
dying enemies.

The comments explain it in more detail, but the gist is:

For skies:
- `sky` needs to be a vanilla level that has sky textures.
- The alpha tpage (fourth entry in `tpages`) needs to be that vanilla
level's alpha tpage (if `tex_remap` is the same level as `sky`, this
will be handled automatically).
- The tpage needs to be added to the custom level `.gd` and to
`textures` in the JSON.
- In `level-info.gc`, `sky` needs to be `#t`, your level's mood needs to
call `update-mood-sky-texture` (the default mood, `update-mood-default`,
handles this as an example) and `sun-fade` needs to be nonzero for the
sun to show up.

For `generic` textures:
- `tex_remap` needs to be the name of a vanilla level.
- When using a vanilla level's remap table, you need to adhere to the
order of the files in that level's `.gd` in your own level.
  - Code files are first.
- Then the tpages (in the order `tfrag`, `pris`, `shrub`, `alpha`,
`water`).
  - Then the art groups.
  - Lastly, the level file.
- The tpages need to be added to the `textures` in the JSON.
  • Loading branch information
Hat-Kid authored Sep 30, 2024
1 parent fedfb6f commit 614c5a6
Show file tree
Hide file tree
Showing 13 changed files with 415 additions and 93 deletions.
79 changes: 59 additions & 20 deletions custom_assets/jak1/levels/test-zone/test-zone.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,60 @@
"custom_models": ["test-actor"],

// Any textures you want to include in your custom level. This is mainly useful for things such as the zoomer HUD,
// which is not in the common level files and has no art group associated with it.
// sky textures and cases where you want to use objects drawn with the generic renderer,
// which also requires you to set a texture remap table and a list of tpages.
// To get a list of all the textures, you can extract all of the game's textures
// by setting "save_texture_pngs" to true in the decompiler config.
// The format is ["tpage-name", "texture-name1", "texture-name2", ...].
// If you want all textures from a tpage, you can just do ["tpage-name"].
"textures": [
// all textures required for the zoomer HUD
// "zoomerhud",
// "zoomerhud-dial",
// "zoomerhud-main-02",
// "zoomerhud-main-03",
// "zoomerhud-pieslice",
// "zoomerhud-heatbg-01",
// "zoomerhud-main-03arrow",
// "zoomerhud-main-03knob"
// Zoomer HUD textures
// ["zoomerhud"],
// Sandover sky textures
["village1-vis-alpha"]
],

// Which vanilla level's texture remap table to use.
// This is needed if you want to have proper textures for objects that are drawn using generic, such as
// dark eco pools or dying enemies. If you choose to use this,
// the order of art groups and tpages in your level's .gd MUST match the vanilla level's for the textures to work.
"tex_remap": "village1",

// Which sky to use for your custom level. This needs to be the name of a vanilla level with sky textures.
// Your level's mood update needs to be set up to copy the sky texture (update-mood-default already handles this as an example).
// You also need to add a specific tpage to your level .gd depending on the level you chose:
// training: tpage-1308.go
// village1: tpage-401.go
// beach: tpage-215.go
// jungle: tpage-388.go
// misty: tpage-520.go
// firecanyon: tpage-1123.go
// village2: tpage-921.go
// rolling: tpage-925.go
// sunkenb: tpage-162.go
// swamp: tpage-630.go
// ogre: tpage-1117.go
// village3: tpage-1194.go
// snow: tpage-712.go
// finalboss: tpage-1418.go
// The tpage you choose also has to be in the alpha (4th) slot in the "tpages" list below.
"sky": "village1",

// Any texture pages that are added to the level's "texture-ids" array.
// These will be logged in and linked as part of level loading.
// There are five tpage categories, in this order:
// - tfrag
// - pris
// - shrub
// - alpha
// - water
// This is also (with the exception of levels that use the zoomer) the order that the tpages are listed in in the vanilla .gd files.
// You need to also add these to your level .gd as well.
// Sky textures use the alpha slot.
// If this is empty and "tex_remap" and "sky" are the same level, this will be auto-filled with the tpages from the
// corresponding level (check its .gd file for the art group/tpage order to copy over).
"tpages": [],

// Ambients you want to use in your custom level. Ambients can be used for various things like changing the music variation (flava),
// adding ambient sounds, level name hints, etc.
"ambients": [
Expand All @@ -97,10 +136,10 @@
}
],

"actors" : [
"actors": [
{
"trans": [-21.6238, 20.0496, 17.1191], // translation
"etype": "fuel-cell", // actor type
"etype": "fuel-cell", // actor type
"game_task": "(game-task none)", // associated game task (for powercells, etc)
"quat": [0, 0, 0, 1], // quaternion
"bsphere": [-21.6238, 19.3496, 17.1191, 10], // bounding sphere
Expand All @@ -111,11 +150,11 @@
},

{
"trans": [-15.2818, 15.2461, 17.1360], // translation
"etype": "crate", // actor type
"trans": [-15.2818, 15.2461, 17.136], // translation
"etype": "crate", // actor type
"game_task": "(game-task none)", // associated game task (for powercells, etc)
"quat": [0, 0, 0, 1], // quaternion
"bsphere": [-15.2818, 15.2461, 17.1360, 10], // bounding sphere
"bsphere": [-15.2818, 15.2461, 17.136, 10], // bounding sphere
"lump": {
"name": "test-crate",
"crate-type": "'steel",
Expand All @@ -124,18 +163,18 @@
},

{
"trans": [-5.4630, 17.4553, 1.6169], // translation
"etype": "eco-yellow", // actor type
"trans": [-5.463, 17.4553, 1.6169], // translation
"etype": "eco-yellow", // actor type
"game_task": "(game-task none)", // associated game task (for powercells, etc)
"quat": [0, 0, 0, 1], // quaternion
"bsphere": [-5.4630, 17.4553, 1.6169, 10], // bounding sphere
"bsphere": [-5.463, 17.4553, 1.6169, 10], // bounding sphere
"lump": {
"name": "test-eco"
}
},
{
"trans": [-5.41, 3.5, 28.42], // translation
"etype": "test-actor", // actor type
"etype": "test-actor", // actor type
"game_task": 0, // associated game task (for powercells, etc)
"quat": [0, 0, 0, 1], // quaternion
"bsphere": [-7.41, 3.5, 28.42, 10], // bounding sphere
Expand All @@ -154,4 +193,4 @@
// }
// }
]
}
}
11 changes: 8 additions & 3 deletions custom_assets/jak1/levels/test-zone/testzone.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

;; the actual file name still needs to be 8.3
("TSZ.DGO"
("static-screen.o"
"test-zone-obs.o"
("test-zone-obs.o"
"tpage-398.go"
"tpage-400.go"
"tpage-399.go"
"tpage-401.go"
"tpage-1470.go"
"plat-ag.go"
"test-actor-ag.go"
"test-zone.go"
))
)
)
34 changes: 18 additions & 16 deletions custom_assets/jak2/levels/test-zone/test-zone.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -49,48 +49,50 @@
// adds a 'type' tag (using the "symbol" and "string" lump types works the same way):
// "spawn-types": ["type", "spyder", "juicer"]

// The base actor id for your custom level. If you have multiple levels, this should be unique!
"base_id": 100,
// The base actor id for your custom level. If you have multiple levels, this should be unique!
"base_id": 100,

// All art groups you want to use in your custom level. Will add their models and corresponding textures to the FR3 file.
// Removed so that the release builds don't have to double-decompile the game
// "art_groups": ["prsn-torture-ag"],

// Any textures you want to include in your custom level.
// This is mainly useful for textures which are not in the common level files and have no art group associated with them.
// To get a list of all the textures, you can extract all of the game's textures
// by setting "save_texture_pngs" to true in the decompiler config.
"textures": [],
// Any textures you want to include in your custom level.
// This is mainly useful for textures which are not in the common level files and have no art group associated with them.
// To get a list of all the textures, you can extract all of the game's textures
// by setting "save_texture_pngs" to true in the decompiler config.
// The format is ["tpage-name", "texture-name1", "texture-name2", ...].
// If you want all textures from a tpage, you can just do ["tpage-name"].
"textures": [],

"actors" : [
"actors": [
{
"trans": [-15.2818, 15.2461, 17.1360], // translation
"etype": "crate", // actor type
"trans": [-15.2818, 15.2461, 17.136], // translation
"etype": "crate", // actor type
"game_task": 0, // associated game task (for powercells, etc)
"kill_mask": 0,
"quat": [0, 0, 0, 1], // quaternion
"bsphere": [-15.2818, 15.2461, 17.1360, 10], // bounding sphere
"bsphere": [-15.2818, 15.2461, 17.136, 10], // bounding sphere
"lump": {
"name": "test-crate",
"eco-info": ["eco-info", "(pickup-type health)", 2]
}
},

{
"trans": [-5.4630, 17.4553, 1.6169], // translation
"etype": "eco-yellow", // actor type
"trans": [-5.463, 17.4553, 1.6169], // translation
"etype": "eco-yellow", // actor type
"game_task": "(game-task none)", // associated game task (for powercells, etc)
"kill_mask": 0,
"quat": [0, 0, 0, 1], // quaternion
"bsphere": [-5.4630, 17.4553, 1.6169, 10], // bounding sphere
"bsphere": [-5.463, 17.4553, 1.6169, 10], // bounding sphere
"lump": {
"name": "test-eco"
}
},

{
"trans": [-7.41, 13.5, 28.42], // translation
"etype": "prsn-torture", // actor type
"etype": "prsn-torture", // actor type
"game_task": "(game-task none)", // associated game task (for powercells, etc)
"quat": [0, 0, 0, 1], // quaternion
"bsphere": [-7.41, 13.5, 28.42, 10], // bounding sphere
Expand All @@ -99,4 +101,4 @@
}
}
]
}
}
32 changes: 17 additions & 15 deletions custom_assets/jak3/levels/test-zone/test-zone.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,44 @@
// adds a 'type' tag (using the "symbol" and "string" lump types works the same way):
// "spawn-types": ["type", "spyder", "juicer"]

// The base actor id for your custom level. If you have multiple levels, this should be unique!
"base_id": 100,
// The base actor id for your custom level. If you have multiple levels, this should be unique!
"base_id": 100,

// All art groups you want to use in your custom level. Will add their models and corresponding textures to the FR3 file.
// "art_groups": [],

// Any textures you want to include in your custom level.
// This is mainly useful for textures which are not in the common level files and have no art group associated with them.
// To get a list of all the textures, you can extract all of the game's textures
// by setting "save_texture_pngs" to true in the decompiler config.
// "textures": [],
// Any textures you want to include in your custom level.
// This is mainly useful for textures which are not in the common level files and have no art group associated with them.
// To get a list of all the textures, you can extract all of the game's textures
// by setting "save_texture_pngs" to true in the decompiler config.
// The format is ["tpage-name", "texture-name1", "texture-name2", ...].
// If you want all textures from a tpage, you can just do ["tpage-name"].
"textures": [],

"actors" : [
"actors": [
{
"trans": [-15.2818, 15.2461, 17.1360], // translation
"etype": "crate", // actor type
"trans": [-15.2818, 15.2461, 17.136], // translation
"etype": "crate", // actor type
"game_task": "(game-task none)", // associated game task (for powercells, etc)
"kill_mask": 0,
"quat": [0, 0, 0, 1], // quaternion
"bsphere": [-15.2818, 15.2461, 17.1360, 10], // bounding sphere
"bsphere": [-15.2818, 15.2461, 17.136, 10], // bounding sphere
"lump": {
"name": "test-crate",
"eco-info": ["eco-info", "(pickup-type gem)", 1]
}
},

{
"trans": [-5.4630, 17.4553, 1.6169], // translation
"etype": "eco-yellow", // actor type
"trans": [-5.463, 17.4553, 1.6169], // translation
"etype": "eco-yellow", // actor type
"game_task": "(game-task none)", // associated game task (for powercells, etc)
"kill_mask": 0,
"quat": [0, 0, 0, 1], // quaternion
"bsphere": [-5.4630, 17.4553, 1.6169, 10], // bounding sphere
"bsphere": [-5.463, 17.4553, 1.6169, 10], // bounding sphere
"lump": {
"name": "test-eco"
}
}
]
}
}
51 changes: 51 additions & 0 deletions decompiler/config/jak1/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -19628,6 +19628,57 @@
(wt31)
)

(defenum water-look
(water-anim-sunken-big-room 0)
(water-anim-sunken-first-room-from-entrance 1)
(water-anim-sunken-qbert-room 2)
(water-anim-sunken-first-right-branch 3)
(water-anim-sunken-circular-with-bullys 4)
(water-anim-sunken-hall-with-one-whirlpool 5)
(water-anim-sunken-hall-with-three-whirlpools 6)
(water-anim-sunken-start-of-helix-slide 7)
(water-anim-sunken-room-above-exit-chamber 8)
(water-anim-sunken-hall-before-big-room 9)
(water-anim-sunken-dark-eco-qbert 10)
(water-anim-sunken-short-piece 11)
(water-anim-sunken-big-room-upper-water 12)
(water-anim-sunken-dark-eco-platform-room 13)
(water-anim-maincave-water-with-crystal 14)
(water-anim-maincave-center-pool 15)
(water-anim-maincave-lower-right-pool 16)
(water-anim-maincave-mid-right-pool 17)
(water-anim-maincave-lower-left-pool 18)
(water-anim-maincave-mid-left-pool 19)
(water-anim-robocave-main-pool 20)
(water-anim-misty-mud-by-arena 21)
(water-anim-misty-mud-above-skeleton 22)
(water-anim-misty-mud-behind-skeleton 23)
(water-anim-misty-mud-above-skull-back 24)
(water-anim-misty-mud-above-skull-front 25)
(water-anim-misty-mud-other-near-skull 26)
(water-anim-misty-mud-near-skull 27)
(water-anim-misty-mud-under-spine 28)
(water-anim-misty-mud-by-dock 29)
(water-anim-misty-mud-island-near-dock 30)
(water-anim-misty-mud-lonely-island 31)
(water-anim-misty-dark-eco-pool 32)
(water-anim-ogre-lava 33)
(water-anim-jungle-river 34)
(water-anim-village3-lava 35)
(water-anim-training-lake 36)
(water-anim-darkcave-water-with-crystal 37)
(water-anim-rolling-water-back 38)
(water-anim-rolling-water-front 39)
(water-anim-sunken-dark-eco-helix-room 40)
(water-anim-finalboss-dark-eco-pool 41)
(water-anim-lavatube-energy-lava 42)
(water-anim-village1-rice-paddy 43)
(water-anim-village1-fountain 44)
(water-anim-village1-rice-paddy-mid 45)
(water-anim-village1-rice-paddy-top 46)
(water-anim-village2-bucket 47)
)

(deftype water-control (basic)
((flags water-flags :offset-assert 4)
(process process-drawable :offset-assert 8)
Expand Down
20 changes: 20 additions & 0 deletions decompiler/level_extractor/BspHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,13 @@ void HFragment::read_from_file(TypedRef ref, const decompiler::DecompilerTypeSys
size = read_plain_data_field<u32>(ref, "size", dts);
}

void AdgifShaderArray::read_from_file(TypedRef ref, const decompiler::DecompilerTypeSystem& dts) {
auto length = read_plain_data_field<s32>(ref, "length", dts);
adgifs.resize(length);
memcpy_plain_data((u8*)adgifs.data(), get_field_ref(ref, "data", dts),
sizeof(AdGifData) * length);
}

void BspHeader::read_from_file(const decompiler::LinkedObjectFile& file,
const decompiler::DecompilerTypeSystem& dts,
GameVersion version,
Expand All @@ -2001,6 +2008,19 @@ void BspHeader::read_from_file(const decompiler::LinkedObjectFile& file,
bsphere.read_from_file(get_field_ref(ref, "bsphere", dts));
name = read_symbol_field(ref, "name", dts);

if (version == GameVersion::Jak1) {
adgifs.read_from_file(get_and_check_ref_to_basic(ref, "adgifs", "adgif-shader-array", dts),
dts);
}

texture_page_count = read_plain_data_field<s32>(ref, "texture-page-count", dts);
if (texture_page_count > 0) {
auto tex_id_ptr = deref_label(get_field_ref(ref, "texture-ids", dts));
for (int i = 0; i < texture_page_count; i++) {
texture_ids.push_back(deref_u32(tex_id_ptr, i));
}
}

texture_remap_table.clear();
s32 tex_remap_len = read_plain_data_field<s32>(ref, "texture-remap-table-len", dts);
if (tex_remap_len > 0) {
Expand Down
Loading

0 comments on commit 614c5a6

Please sign in to comment.