Skip to content

Commit

Permalink
[jak3] A bunch of small fixes to get game.cgo to load (#3435)
Browse files Browse the repository at this point in the history
The `test-play` macro is back, though it doesn't call `play` yet. We can
at least load all of `game.cgo`, which involves loading a lot of the
code we've decompiled, loading/linking objects files compiled by
OpenGOAL (like dir-tpages), and loading/linking Jak's art-groups (for
jak 3 they are stored v5 format that I added to the linker).

There were no major issues - just a few forgotten mips2c entries and
minor bugs/functions that needed stubs. Most of the work was updating
the linker. Hopefully I'll never have to touch that code again - I think
it supports everything we need for jak 3!
  • Loading branch information
water111 authored Mar 24, 2024
1 parent 9b4b549 commit ee015e3
Show file tree
Hide file tree
Showing 23 changed files with 2,188 additions and 77 deletions.
28 changes: 10 additions & 18 deletions decompiler/config/jak3/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,7 @@
some, but not all, functions assume that a matrix is an affine transform.
others assume that the rotation has no scale or shear (and that its inverse is its transpose)."
((data float 16 :offset-assert 0 :score -2) ;; guessed by decompiler
(vector vector 4 :offset 0 :score -1) ;; guessed by decompiler
(vector vector 4 :inline :offset 0 :score -1) ;; guessed by decompiler
(quad uint128 4 :offset 0) ;; guessed by decompiler
(rvec vector :inline :offset 0 :score 1)
(uvec vector :inline :offset 16 :score 1)
Expand Down Expand Up @@ -30761,7 +30761,6 @@
;; sparticle-launcher ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#|
(deftype sp-queued-launch-particles (structure)
((sp-system sparticle-system :offset-assert 0) ;; guessed by decompiler
(sp-launcher sparticle-launcher :offset-assert 4) ;; guessed by decompiler
Expand All @@ -30771,34 +30770,28 @@
:size-assert #x20
:flag-assert #x900000020
)
|#

#|
(deftype sp-launch-queue (basic)
((in-use int32 :offset-assert 4)
(queue sp-queued-launch-particles 256 :offset-assert 16) ;; guessed by decompiler
(queue sp-queued-launch-particles 256 :inline :offset-assert 16) ;; guessed by decompiler
)
:method-count-assert 9
:size-assert #x2010
:flag-assert #x900002010
)
|#

#|
(deftype particle-adgif-cache (basic)
((used int32 :offset-assert 4)
(last uint16 :offset-assert 8)
(lastgif adgif-shader :offset-assert 12)
(tidhash uint16 80 :offset-assert 16) ;; guessed by decompiler
(spadgif adgif-shader 80 :offset-assert 176) ;; guessed by decompiler
(spadgif adgif-shader 80 :inline :offset-assert 176) ;; guessed by decompiler
)
:method-count-assert 9
:size-assert #x19b0
:flag-assert #x9000019b0
)
|#

#|
(deftype sp-launch-stack (structure)
((ra basic :offset-assert 0)
(dummy0 basic :offset-assert 4)
Expand All @@ -30822,23 +30815,22 @@
:flag-assert #x900000130
;; field ra uses ~A with a signed load. field dummy0 uses ~A with a signed load. field dummy1 uses ~A with a signed load. field b-spfic uses ~A with a signed load. field l-spfic uses ~A with a signed load.
)
|#

;; sparticle-launcher is already defined!

(define-extern *part-id-table* (array sparticle-launcher))
(define-extern *part-group-id-table* (array sparticle-launch-group))
;; (define-extern *sp-temp* object) ;; float
(define-extern *sp-temp* float)
;; (define-extern lookup-part-group-by-name function) ;; (function string sparticle-launch-group)
(define-extern lookup-part-group-pointer-by-name (function string (pointer object)))
(define-extern part-group-pointer? (function pointer symbol))
(define-extern unlink-part-group-by-heap (function kheap int))
;; (define-extern sp-init-fields! function) ;; (function (pointer float) (inline-array sp-field-init-spec) sp-field-id sp-field-id symbol (inline-array sp-field-init-spec))
;; (define-extern *sp-launcher-lock* object) ;; symbol
;; (define-extern *sp-launch-queue* object) ;; sp-launch-queue
;; (define-extern *sp-launcher-enable* object) ;; symbol
(define-extern *sp-launcher-lock* symbol)
(define-extern *sp-launch-queue* sp-launch-queue)
(define-extern *sp-launcher-enable* symbol)
;; (define-extern particle-setup-adgif function) ;; (function adgif-shader int none)
;; (define-extern *particle-adgif-cache* object) ;; particle-adgif-cache
(define-extern *particle-adgif-cache* particle-adgif-cache)
(define-extern particle-adgif-cache-flush (function none))
;; (define-extern particle-adgif function) ;; (function adgif-shader texture-id none)
;; (define-extern particle-adgif-callback function) ;; (function adgif-shader texture-id none)
Expand All @@ -30847,7 +30839,7 @@
;; (define-extern sp-euler-convert function) ;; (function sparticle-launchinfo sparticle-cpuinfo none)
;; (define-extern sp-rotate-system function) ;; (function sparticle-launchinfo sparticle-cpuinfo transformq none)
(define-extern sp-launch-particles-var (function sparticle-system sparticle-launcher matrix sparticle-launch-state sparticle-launch-control float none))
;; (define-extern *death-adgif* object) ;; adgif-shader
(define-extern *death-adgif* adgif-shader)
;; (define-extern sp-launch-particles-death function) ;; (function sparticle-system sparticle-launcher vector none)
;; (define-extern sp-clear-queue function) ;; (function none)
;; (define-extern sp-relaunch-setup-fields function) ;; (function object sparticle-launcher sparticle-cpuinfo sprite-vec-data-3d none)
Expand All @@ -30865,7 +30857,7 @@
;; (define-extern birth-func-clean function)
;; (define-extern birth-func-process-clock function)
;; (define-extern birth-func-copy-rot-color function) ;; (function sparticle-system sparticle-cpuinfo sprite-vec-data-3d sparticle-launcher sparticle-launch-state none)
;; (define-extern *global-toggle* object) ;; int
(define-extern *global-toggle* int)
;; (define-extern birth-func-copy2-rot-color function) ;; (function sparticle-system sparticle-cpuinfo sprite-vec-data-3d sparticle-launcher sparticle-launch-state none)
;; (define-extern birth-func-copy-omega-to-z function) ;; (function sparticle-system sparticle-cpuinfo sprite-vec-data-3d sparticle-launcher sparticle-launch-state none)
;; (define-extern birth-func-random-next-time function) ;; (function sparticle-system sparticle-cpuinfo sprite-vec-data-3d sparticle-launcher sparticle-launch-state none)
Expand Down
3 changes: 3 additions & 0 deletions game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,13 @@ set(RUNTIME_SOURCE
mips2c/jak3_functions/collide_func.cpp
mips2c/jak3_functions/debug.cpp
mips2c/jak3_functions/font.cpp
mips2c/jak3_functions/foreground.cpp
mips2c/jak3_functions/generic_effect.cpp
mips2c/jak3_functions/joint.cpp
mips2c/jak3_functions/lights.cpp
mips2c/jak3_functions/prim.cpp
mips2c/jak3_functions/sky.cpp
mips2c/jak3_functions/texture.cpp
mips2c/mips2c_table.cpp
overlord/common/dma.cpp
overlord/common/fake_iso.cpp
Expand Down
10 changes: 10 additions & 0 deletions game/kernel/common/klink.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ struct ObjectFileHeader {
uint32_t link_block_length;
};

struct SegmentInfoV5 {
uint32_t relocs; // offset of relocation table
uint32_t data; // offset of segment data
uint32_t size; // segment data size (0 if segment doesn't exist)
uint32_t magic; // always 0
};

void klink_init_globals();
/*!
* Stores the state of the linker. Used for multi-threaded linking, so it can be suspended.
Expand Down Expand Up @@ -65,6 +72,8 @@ struct link_control {
bool m_on_global_heap = false;
LinkHeaderV5Core* m_link_hdr = nullptr;
bool m_moved_link_block = false;
int m_n_segments = 0;
SegmentInfoV5* m_link_segments_table = nullptr;

void jak1_jak2_begin(Ptr<uint8_t> object_file,
const char* name,
Expand All @@ -89,6 +98,7 @@ struct link_control {
uint32_t jak2_work_v3();
uint32_t jak2_work_v2();

uint32_t jak3_work_v2_v4();
uint32_t jak3_work_v5();
uint32_t jak3_work_opengoal();

Expand Down
Loading

0 comments on commit ee015e3

Please sign in to comment.