Skip to content

Commit

Permalink
Decompile level (#3433)
Browse files Browse the repository at this point in the history
  • Loading branch information
water111 authored Mar 23, 2024
1 parent 99866ce commit ffe01a3
Show file tree
Hide file tree
Showing 43 changed files with 9,416 additions and 330 deletions.
253 changes: 152 additions & 101 deletions decompiler/config/jak3/all-types.gc

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,6 @@
[78, "(function part-tracker vector)"]
],
"trajectory": [[15, "(function trajectory none)"]],
"progress": [[3, "(function int none :behavior process)"]]
"progress": [[3, "(function int none :behavior process)"]],
"level": [[25, "(function level-group int symbol)"], [7, "(function none)"], [4, "(function load-state sound-bank-state symbol)"]]
}
31 changes: 26 additions & 5 deletions decompiler/config/jak3/ntsc_v1/hacks.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@
"(anon-function 4 gun-states)",
"(method 10 manipulator)",
"(method 46 ff-squad-control)",
"borrow-city-expansion",
"(method 26 level-group)",
"(anon-function 65 temple-obs)",
"(method 33 task-manager-nest-cocoons)",
"(method 33 rub-tower)",
Expand Down Expand Up @@ -213,7 +211,18 @@
"(method 22 fort-floor-spike-c)",
"(method 11 sew-catwalk)",
"(method 11 mtn-aval-rocks)",
"(method 11 gar-curtain)"
"(method 11 gar-curtain)",
"(method 10 level-load-info)",
"(method 29 level-group)",
"(method 26 level-group)",
"(method 19 level)",
"(method 10 level)",
"update-sound-banks",
"level-base-level-name",
"borrow-city-expansion",
"add-want-level",
"level-find-borrow-slot",
"(method 18 level)"
],

// If format is used with the wrong number of arguments,
Expand Down Expand Up @@ -249,7 +258,17 @@
"~33L~S ~35L~S~1L": 2,
"~33L~C": 1,
"~33L~S~44L ~S": 2,
"~44L~S ~33L~S": 2
"~44L~S ~33L~S": 2,
"~10Htfrag: ~8,,0m": 1,
"~140Hshrub: ~8,,0m": 1,
"~272Halpha: ~8,,0m~%": 1,
"~27Htie: ~8,,0m": 1,
"~140Hfg-tf: ~8,,0m": 1,
"~270Hfg-pr: ~8,,0m~%": 1,
"~10Hfg-wa: ~8,,0m": 1,
"~140Hfg-sh: ~8,,0m": 1,
"~267Hfg-p2: ~8,,0m~%": 1,
"~30Hp2: ~8D~131Hhf: ~8D~%~1K": 2
},

"blocks_ending_in_asm_branch": {
Expand Down Expand Up @@ -319,7 +338,9 @@
"set-background-regs!": [4, 3],
"draw-drawable-tree-instance-shrub": [5, 7, 9, 11],
"draw-drawable-tree-instance-tie": [21, 23, 31, 33],
"(method 12 flow-control)": [3, 9, 22]
"(method 12 flow-control)": [3, 9, 22],
"(method 26 level-group)": [40, 41, 67],
"borrow-city-expansion": [0, 9, 13, 15, 17]
},

// Sometimes the game might use format strings that are fetched dynamically,
Expand Down
5 changes: 5 additions & 0 deletions decompiler/config/jak3/ntsc_v1/label_types.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -391,5 +391,10 @@
"hud-classes": [
["L205", "(inline-array hud-sprite)", 24],
["L214", "(inline-array vector)", 4]
],
"level": [
["L1004", "uint64", true],
["L1003", "uint64", true]

]
}
14 changes: 13 additions & 1 deletion decompiler/config/jak3/ntsc_v1/stack_structures.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -399,5 +399,17 @@
[128, "vector"]
],
"progress-post": [[176, "hud-box"]],
"(method 15 hud-gun)": [[16, "hud-sprite"]]
"(method 15 hud-gun)": [[16, "hud-sprite"]],
"play": [
[96, ["array", "symbol", 10]]
],
"update-sound-banks": [
[16, ["array", "int8", 36]]
],
"show-level": [[16, ["array", "symbol", 10]]],
"(method 20 load-state)": [
[16, ["inline-array", "level-buffer-state", 10]],
[176, ["inline-array", "level-buffer-state", 10]]

]
}
53 changes: 53 additions & 0 deletions decompiler/config/jak3/ntsc_v1/type_casts.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2938,5 +2938,58 @@
"(method 16 hud)": [
[127, "v1", "int"],
[147, "v1", "int"]
],
"lookup-level-info": [
[11, "v1", "basic"],
[21, "a1", "symbol"],
[[22, 34], "a1", "level-load-info"]
],
"(method 29 level-group)": [
[[2, 53], "v1", "pair"]
],
"level-find-borrow-slot": [
[[204, 211], "a2", "level"]
],
"(method 19 level)": [
[[40, 118], "a3", "symbol"],
[[52, 56], "a0", "texture-anim-array"]
],
"level-update-after-load": [
[[25, 58], "s1", "drawable-tree-tfrag"],
[142, "v1", "drawable-inline-array-tfrag"],
[147, "v1", "drawable-inline-array-tfrag"],
[152, "a0", "drawable-inline-array-tfrag"],
[175, "v1", "drawable-tree-instance-tie"],
[178, "v1", "drawable-tree-instance-tie"],
[393, "a1", "(pointer int32)"],
[398, "a2", "(pointer int32)"]
],
"(method 25 level)": [
[97, "s1", "(function object object)"],
[171, "s0", "(function object object object)"]
],
"(method 9 level)": [
[51, "s5", "(function object object)"],
[[143, 166], "v1", "task-mask"]
],
"(method 10 level)": [
[[214, 217], "v1", "symbol"],
[[216, 220], "a0", "texture-anim-array"],
[137, "s5", "(function level object)"],
[[349, 358], "a1", "type"]
],
"(method 30 level-group)": [
[87, "v0", "level"]
],
"(method 10 load-state)": [
[461, "v1", "level"],
[468, "v1", "level"]
],
"update-sound-banks": [
[131, "a0", "pair"]
],
"borrow-city-expansion": [
[23, "a0", "basic"],
[52, "s5", "basic"]
]
}
11 changes: 11 additions & 0 deletions decompiler/config/jak3/ntsc_v1/var_names.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -1864,5 +1864,16 @@
"vars": {
"s4-0": ["act", "game-task-node-flag"]
}
},
"level-find-borrow-slot": {
"args": ["borrower-level", "mode"],
"vars": {
"v1-0": "host-level-borrow-slot",
"a2-0": "host-level-candidate-idx",
"a3-3": "host-level-candidate",
"t0-7": "mode2",
"t0-10": "found-slot",
"t0-8": "host-level-slot-idx"
}
}
}
2 changes: 1 addition & 1 deletion decompiler/util/data_decompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ goos::Object decompile_structure(const TypeSpec& type,
} else if (word.kind() == LinkedWord::EMPTY_PTR) {
field_defs_out.emplace_back(field.name(), pretty_print::to_symbol("'()"));
} else if (word.kind() == LinkedWord::TYPE_PTR) {
if (field.type() != TypeSpec("type")) {
if (!ts.tc(field.type(), TypeSpec("type"))) {
throw std::runtime_error(
fmt::format("Field {} in type {} offset {} had a reference to type {}, but the "
"type of the field is not type.",
Expand Down
21 changes: 10 additions & 11 deletions goal_src/jak3/engine/game/game-info-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -239,32 +239,31 @@
(command-list pair)
(object-name string 256)
(object-status basic 256)
(update-callback basic)
(update-callback (function load-state object))
)
(:methods
(new (symbol type) _type_)
(load-state-method-9 () none)
(load-state-method-10 () none)
(load-state-method-11 () none)
(reset! (_type_) _type_)
(update! (_type_) int)
(want-levels (_type_ (pointer symbol)) int)
(want-sound-banks (_type_ (pointer symbol)) none)
(load-state-method-13 () none)
(load-state-method-14 () none)
(load-state-method-15 () none)
(load-state-method-16 () none)
(want-display-level (_type_ symbol symbol) int)
(want-vis-level (_type_ symbol) none)
(want-force-vis (_type_ symbol symbol) int)
(want-force-inside (_type_ symbol symbol) none)
(execute-commands-up-to (_type_ float) none)
(backup-load-state-and-set-cmds (_type_ pair) int)
(restore-load-state-and-cleanup (_type_) int)
(restore-load-state (_type_) int)
(load-state-method-21 (_type_) none)
(add-borrow-levels (_type_) none)
)
)


;; WARN: Return type mismatch none vs load-state.
(defmethod new load-state ((allocation symbol) (type-to-make type))
(let ((a0-1 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> a0-1 update-callback) #f)
(the-as load-state ((method-of-object a0-1 load-state-method-9)))
(reset! a0-1)
)
)

Expand Down
4 changes: 2 additions & 2 deletions goal_src/jak3/engine/game/game-info.gc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
(set! (-> continue-rot 8) (the int (* 32767.0 (-> rot fvec z))))
)
)
(load-state-method-21 arg0)
(add-borrow-levels arg0)
this
)

Expand Down Expand Up @@ -382,7 +382,7 @@
(when (or (and (-> subtask manager) (handle->process (-> subtask manager manager)))
(and (-> subtask manager)
(-> subtask manager level)
(= (level-group-method-26 *level* (-> subtask manager level) (the-as int #f)) 'active)
(= (status-of-level-and-borrows *level* (-> subtask manager level) #f) 'active)
)
(and (not (-> subtask manager)) (= (-> level info taskname) (-> subtask level)))
)
Expand Down
1 change: 1 addition & 0 deletions goal_src/jak3/engine/game/main-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
(define-extern kiosk? (function symbol))
(define-extern set-blackout-frames (function time-frame none))
(define-extern set-master-mode (function symbol none))
(define-extern on (function symbol process))

;; +++main-h:collide-spec
(defenum collide-spec
Expand Down
4 changes: 2 additions & 2 deletions goal_src/jak3/engine/game/settings.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@
(set! (-> s5-0 allow-error) (-> s4-0 allow-error))
(set! (-> s5-0 under-water-pitch-mod) (-> s4-0 under-water-pitch-mod))
(set! (-> s5-0 slow-time) (-> s4-0 slow-time))
(if (and (-> s4-0 mirror) (= (level-group-method-26 *level* 'ctywide (the-as int #f)) 'active))
(if (and (-> s4-0 mirror) (= (status-of-level-and-borrows *level* 'ctywide #f) 'active))
(set! (-> s5-0 mirror) #f)
(set! (-> s5-0 mirror) (-> s4-0 mirror))
)
Expand Down Expand Up @@ -1653,7 +1653,7 @@
(when (and (!= (-> s4-0 music) (-> s5-0 music))
(and (zero? (rpc-busy? 1))
(or (not (-> s4-0 music))
(and (< 0.0 (-> s5-0 music-volume)) (not (level-group-method-28 *level*)) (not (-> s5-0 movie)))
(and (< 0.0 (-> s5-0 music-volume)) (not (load-in-progress? *level*)) (not (-> s5-0 movie)))
)
(not *master-exit*)
)
Expand Down
1 change: 1 addition & 0 deletions goal_src/jak3/engine/gfx/generic/lightning/lightning-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
(define-extern *lightning-spec-id-table* (array lightning-spec))

(define-extern process-drawable-art-error (state string process-drawable))
(define-extern unlink-lightning-spec-by-heap (function kheap none))

;; DECOMP BEGINS

Expand Down
3 changes: 3 additions & 0 deletions goal_src/jak3/engine/gfx/mood/mood-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
;; dgos: GAME

(declare-type sky-color-day structure)
(declare-type mood-context structure)

(define-extern movie? (function symbol))

(define-extern clear-mood-context (function mood-context symbol))

;; DECOMP BEGINS

(deftype mood-channel (structure)
Expand Down
2 changes: 2 additions & 0 deletions goal_src/jak3/engine/gfx/mood/time-of-day-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
(declare-type time-of-day-palette structure)
(define-extern time-of-day-interp-colors (function (pointer rgba) uint mood-context none))
(define-extern time-of-day-interp-colors-scratch (function (pointer rgba) time-of-day-palette mood-context none))
(declare-type time-of-day-proc process)
(define-extern *time-of-day* (pointer time-of-day-proc))

;; DECOMP BEGINS

Expand Down
2 changes: 2 additions & 0 deletions goal_src/jak3/engine/gfx/sprite/particles/sparticle-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
)
)

(define-extern kill-all-particles-in-level (function level int))

;; DECOMP BEGINS

(define *sp-60-hz* #t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
(declare-type sparticle-cpuinfo structure)
(declare-type sparticle-system structure)

(define-extern unlink-part-group-by-heap (function kheap int))
(define-extern particle-adgif-cache-flush (function none))

;; +++sp-field-id
(defenum sp-field-id
:type uint16
Expand Down
7 changes: 7 additions & 0 deletions goal_src/jak3/engine/gfx/texture/texture-anim-tables.gc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@
;; name in dgo: texture-anim-tables
;; dgos: GAME

(define-extern *sky-texture-anim-array* (texture-anim-array texture-anim))
(define-extern *darkjak-texture-anim-array* (texture-anim-array texture-anim))
(define-extern *darkjak-highres-texture-anim-array* (texture-anim-array texture-anim))
(define-extern *skull-gem-texture-anim-array* (texture-anim-array texture-anim))
(define-extern *default-water-texture-anim-array* (texture-anim-array texture-anim))
(define-extern *default-warp-texture-anim-array* (texture-anim-array texture-anim))

;; DECOMP BEGINS

27 changes: 19 additions & 8 deletions goal_src/jak3/engine/level/bsp-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
(declare-type bsp-header drawable)
(declare-type bsp-node structure)
(declare-type entity-camera entity)
(declare-type entity-nav-mesh structure)
(declare-type city-level-info structure)

(define-extern inspect-bsp-tree (function bsp-header bsp-node none))
(define-extern map-bsp-tree (function (function bsp-node none) bsp-header bsp-node none))
Expand Down Expand Up @@ -40,33 +42,42 @@ This is used for precomputed visibility, based on the camera position. This is n
"The bsp-header is really an entire level.
This probably started as a very simple structure, but now it is extremely complicated."
((info file-info :overlay-at id)
(all-visible-list (pointer uint8) :offset 32)
(visible-list-length int16 :offset 36)
(all-visible-list (pointer uint8))
(visible-list-length int16)
(extra-vis-list-length int16)
(drawable-trees drawable-tree-array :offset 40)
(pat pointer :offset 44)
(pat-length int32 :offset 48)
(drawable-trees drawable-tree-array)
(pat pointer)
(pat-length int32)
(texture-remap-table (pointer uint64))
(texture-remap-table-len int32)
(texture-ids (pointer texture-id))
(texture-page-count int32)
(unknown-basic basic)
(actors drawable-inline-array-actor :offset 112)
(name symbol)
(nickname symbol)
(vis-info level-vis-info 8)
(actors drawable-inline-array-actor)
(cameras (array entity-camera))
(nodes (inline-array bsp-node) :offset 120)
(nodes (inline-array bsp-node))
(level level)
(current-leaf-idx uint16)
(texture-flags texture-page-flag 10 :offset 130)
(texture-flags texture-page-flag 10)
(cam-outside-bsp uint8 :offset 152)
(cam-using-back uint8)
(cam-box-idx uint16)
(subdivide-close float :offset 160)
(subdivide-far float)
(actor-birth-order (pointer uint32) :offset 172)
(light-hash light-hash)
(nav-meshes (array entity-nav-mesh))
(region-trees (array drawable-tree-region-prim) :offset 188)
(collide-hash collide-hash :offset 196)
(wind-array uint32 :offset 200)
(wind-array-length int32 :offset 204)
(city-level-info city-level-info :offset 208)
(vis-spheres vector-array :offset 216)
(vis-spheres-length uint32 :offset 248)
(region-tree drawable-tree-region-prim :offset 252)
(tfrag-masks texture-masks-array :offset 256)
(tfrag-closest (pointer float))
(tfrag-mask-count uint32 :overlay-at tfrag-closest)
Expand Down
Loading

0 comments on commit ffe01a3

Please sign in to comment.