Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jak3: fix hud sprite crash + add entity debugger #3516

Merged
merged 13 commits into from
May 13, 2024
3 changes: 3 additions & 0 deletions common/util/Assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

#define ASSERT_NOT_REACHED_MSG(STR) \
(void)((private_assert_failed("not reached", __FILE__, __LINE__, __PRETTY_FUNCTION__, STR), 0))

#define ASSERT_EQ_IMM(EXPR, EXPECTED) \
ASSERT_MSG((EXPR) == (EXPECTED), fmt::format("result was {}, expected {}", (EXPR), (EXPECTED)))
#else

#define ASSERT(EX) ((void)0)
Expand Down
2 changes: 0 additions & 2 deletions decompiler/config/jak3/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -28512,8 +28512,6 @@
(name symbol :offset-assert 8) ;; guessed by decompiler
(process process-drawable :offset-assert 12) ;; guessed by decompiler
(curve curve :inline :offset-assert 16)
(num-cverts int32 :offset 20)
(cverts uint32 :offset 16)
)
:method-count-assert 32
:size-assert #x24
Expand Down
2 changes: 0 additions & 2 deletions decompiler/config/jak3/ntsc_v1/hacks.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -728,11 +728,9 @@
["lcit", 0, 0],
["pow", 0, 0],
["wasintro", 0, 0],
["wasintro-vis", 0, 0],
["lfacctyb", 0, 0],
["intpfall", 0, 0],
["lfaccity", 0, 0],
["lfacctyb-vis", 0, 0],
["ltowcity", 0, 0],
["powergd", 0, 0],
["lcitysml", 0, 0]
Expand Down
24 changes: 12 additions & 12 deletions decompiler/config/jak3/ntsc_v1/inputs.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -183,27 +183,27 @@
"DGO/RAILF.DGO",
"DGO/RAILX.DGO",
// // precursor
// "DGO/PRECA.DGO",
// "DGO/PRECB.DGO",
// "DGO/PRECC.DGO",
"DGO/PRECA.DGO",
"DGO/PRECB.DGO",
"DGO/PRECC.DGO",
// "DGO/PRECD.DGO",
// title/intro
// // title/intro
"DGO/WIN.DGO", // wasintro
"DGO/TITLE.DGO",
"DGO/INTTITLE.DGO",
"DGO/INTPALRF.DGO", // intro-palace-roof
"DGO/IPF.DGO", // intro-palace-fall
"DGO/INTROCST.DGO",
// // outro
// "DGO/OUTCAST3.DGO",
// "DGO/OUTROCST.DGO",
"DGO/OUTCAST3.DGO",
"DGO/OUTROCST.DGO",
// // museum
// "DGO/MUSEUM.DGO",
// "DGO/MUSEUM2.DGO",
// "DGO/MUSEUM3.DGO",
// "DGO/MUSEUM3B.DGO",
// "DGO/MUSEUM4.DGO",
// "DGO/MUSEUM4B.DGO",
"DGO/MUSEUM.DGO",
"DGO/MUSEUM2.DGO",
"DGO/MUSEUM3.DGO",
"DGO/MUSEUM3B.DGO",
"DGO/MUSEUM4.DGO",
"DGO/MUSEUM4B.DGO",
// test
"DGO/HALFPIPE.DGO",
// borrow
Expand Down
22 changes: 3 additions & 19 deletions decompiler/level_extractor/extract_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,9 @@ namespace decompiler {
std::optional<ObjectFileRecord> get_bsp_file(const std::vector<ObjectFileRecord>& records,
const std::string& dgo_name) {
std::optional<ObjectFileRecord> result;
bool found = false;
for (auto& file : records) {
if (file.name.length() > 4 && file.name.substr(file.name.length() - 4) == "-vis") {
ASSERT(!found);
found = true;
result = file;
}
}

if (!result) {
if (str_util::ends_with(dgo_name, ".DGO") || str_util::ends_with(dgo_name, ".CGO")) {
auto expected_name = dgo_name.substr(0, dgo_name.length() - 4);
for (auto& c : expected_name) {
c = tolower(c);
}
if (!records.empty() && expected_name == records.back().name) {
return records.back();
}
}
if (str_util::ends_with(dgo_name, ".DGO")) {
// only DGOs are valid levels, and the last file is the bsp file
result = records.at(records.size() - 1);
}
return result;
}
Expand Down
3 changes: 3 additions & 0 deletions game/graphics/opengl_renderer/sprite/Sprite3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ void Sprite3::render_2d_group1(DmaFollower& dma,
case GameVersion::Jak2:
ASSERT(run.vifcode1().immediate == SpriteProgMem::Sprites2dHud_Jak2);
break;
case GameVersion::Jak3:
ASSERT_EQ_IMM(run.vifcode1().immediate, (int)SpriteProgMem::Sprites2dHud_Jak3);
break;
default:
ASSERT_NOT_REACHED();
}
Expand Down
3 changes: 2 additions & 1 deletion game/graphics/opengl_renderer/sprite/sprite_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ enum SpriteProgMem {
Sprites2dGrp0 = 3, // world space 2d sprites
Sprites2dHud_Jak1 = 109, // hud sprites
Sprites2dHud_Jak2 = 115,
Sprites2dHud_Jak3 = 143,
Sprites3d = 211 // 3d sprites
};

Expand Down Expand Up @@ -241,4 +242,4 @@ struct SpriteGlowConsts {
math::Vector4f clamp_min;
math::Vector4f clamp_max;
};
static_assert(sizeof(SpriteGlowConsts) == 0x180);
static_assert(sizeof(SpriteGlowConsts) == 0x180);
1 change: 1 addition & 0 deletions game/overlord/jak2/overlord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ int start_overlord(int, const char* const*) {
param.initPriority = 0x73;
param.stackSize = 0x1000;
param.option = 0;
strcpy(param.name, "Loader"); // added
SndPlayThread = thread_player;
auto thread_loader = CreateThread(&param);
if (thread_loader <= 0) {
Expand Down
32 changes: 0 additions & 32 deletions goal_src/jak1/pc/pckernel-common.gc
Original file line number Diff line number Diff line change
Expand Up @@ -844,35 +844,6 @@

(when *debug-segment*

(deftype entity-debug-inspect (basic)
(
(scroll-y int16)
(scroll-y-max int16)
(entity entity)
(show-actor-info symbol)
(show-long-info symbol)
)
(:methods
(new (symbol type) _type_)
(set-entity! (_type_ entity) entity)
(update-pad (_type_ int) none)
)
)

(defmethod new entity-debug-inspect ((allocation symbol) (type-to-make type))
"make a new entity-debug-inspect object"

(let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size)))))

(set! (-> obj scroll-y) 0)
(set! (-> obj scroll-y-max) 0)
(set! (-> obj entity) (the entity #f))
(set! (-> obj show-actor-info) #f)
(set! (-> obj show-long-info) #f)
obj
)
)

(defmethod update-pad entity-debug-inspect ((obj entity-debug-inspect) (pad-idx int))
"respond to pad inputs"

Expand All @@ -893,9 +864,6 @@

(none))


(define *entity-debug-inspect* (new 'debug 'entity-debug-inspect))

) ;; when debug_segment


Expand Down
41 changes: 41 additions & 0 deletions goal_src/jak1/pc/pckernel-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,44 @@
(defun-extern real-movie? symbol)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; entity debugging
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(when *debug-segment*

(deftype entity-debug-inspect (basic)
(
(scroll-y int16)
(scroll-y-max int16)
(entity entity)
(show-actor-info symbol)
(show-long-info symbol)
)
(:methods
(new (symbol type) _type_)
(set-entity! (_type_ entity) entity)
(update-pad (_type_ int) none)
)
)

(defmethod new entity-debug-inspect ((allocation symbol) (type-to-make type))
"make a new entity-debug-inspect object"

(let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size)))))

(set! (-> obj scroll-y) 0)
(set! (-> obj scroll-y-max) 0)
(set! (-> obj entity) (the entity #f))
(set! (-> obj show-actor-info) #f)
(set! (-> obj show-long-info) #f)
obj
)
)


(define *entity-debug-inspect* (new 'debug 'entity-debug-inspect))


) ;; when debug_segment
1 change: 1 addition & 0 deletions goal_src/jak3/dgos/game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,5 @@
"ragdoll-test.o"
"debris.o"
"shield-sphere.o"
"entity-debug.o" ;; added
))
6 changes: 2 additions & 4 deletions goal_src/jak3/engine/common-obs/generic-obs.gc
Original file line number Diff line number Diff line change
Expand Up @@ -3879,10 +3879,8 @@
)
)
(set! (-> this is-spooling?) (nonzero? (res-lump-value arg0 'spooling-val uint128 :time -1000000000.0)))
;; og:preserve-this some entities store their path data in the path1 lump
(let ((bad-entity? (symbol-member? (string->symbol (-> this name)) '(sound-on-path-119))))
(set! (-> this path) (new 'process 'path-control this (#if PC_PORT (if bad-entity? 'path1 'path) 'path) 0.0 arg0 #f))
)
;; og:preserve-this
(set! (-> this path) (new 'process 'path-control this (#if PC_PORT (if (string= (-> this name) "sound-on-path-119") 'path1 'path) 'path) 0.0 arg0 #f))
(logior! (-> this path flags) (path-control-flag display draw-line draw-point draw-text))
(logclear! (-> this mask) (process-mask actor-pause))
;; og:preserve-this
Expand Down
58 changes: 58 additions & 0 deletions goal_src/jak3/engine/draw/drawable.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,64 @@
(update-eyes)
)
(when *debug-segment*
;; do all debug drawing.
(#when PC_PORT
(when (and (or (= *master-mode* 'game) (= *master-mode* 'pause)))
(when (-> *entity-debug-inspect* entity)
(define-extern entity-inspect-draw (function entity-debug-inspect object))
(entity-inspect-draw *entity-debug-inspect*)
)
;; go through active levels
(dotimes (lev-i (-> *level* length))
(let ((lev (-> *level* level lev-i)))
(when (= (-> lev status) 'active)
(let ((region-trees (-> lev bsp region-trees)))
(when (nonzero? region-trees)
(let* ((s3-5 (-> region-trees length))
(tree-i 0)
(region-tree (-> region-trees tree-i))
)
(while (< tree-i s3-5)
(let ((tree-name (-> region-tree name)))
(let* ((s0-4 (-> region-tree data2 (+ (-> region-tree length) -1) length))
(i 0)
(region (-> (the-as drawable-inline-array-region-prim (-> region-tree data2 (+ (-> region-tree length) -1))) data i))
)
(while (< i s0-4)
(let ((draw? #f))
(when (and *display-region-inside* (!= tree-name 'water) (point-in-region-debug! (-> region region) (target-pos 0)))
(true! draw?)
(format *stdcon* "~1kinside region-~D [~A] (l: ~A)~%" (-> region region id) tree-name (-> lev name)))
(when (and *region-debug-inspect* (or (= *region-debug-inspect* region) (and *merge-region-prims* (= (-> region region id) (-> *region-debug-inspect* region id)))))
(when (= *region-debug-inspect* region)
(format *stdcon* "~1kinspecting region-~D [~A] (l: ~A)~%" (-> *region-debug-inspect* region id) tree-name (-> lev name))
(format *stdcon* " on-enter: ~A~%" (-> *region-debug-inspect* region on-enter))
(format *stdcon* " on-inside: ~A~%" (-> *region-debug-inspect* region on-inside))
(format *stdcon* " on-exit: ~A~%" (-> *region-debug-inspect* region on-exit))
)
(true! draw?)
)
(when draw?
(set! *debug-region-color-alt* (= tree-name 'camera))
(debug-draw-region region 0)))
(set! i (+ i 1))
(set! region (-> (the-as drawable-inline-array-region-prim (-> region-tree data2 (+ (-> region-tree length) -1))) data i))
)
)
)
(+! tree-i 1)
(set! region-tree (-> region-trees tree-i))
)
)
)
)
)
)
)
)
(if *debug-track-skill*
(debug-track-skill))
)
(with-profiler 'debug *profile-debug-color*
(debug-draw-buffers)
)
Expand Down
10 changes: 4 additions & 6 deletions goal_src/jak3/engine/geometry/path-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ Although it contains a `curve`, the knot part is not populated, so it's just tre
a bunch of line segments from the control points.
The child class curve-control does fill out the knot data and is a proper b-spline.
These path-controls are typically allocated on a process heap."
((flags path-control-flag)
(name symbol)
(process process-drawable)
(curve curve :inline)
(num-cverts int32 :overlay-at (-> curve num-cverts))
(cverts uint32 :overlay-at (-> curve cverts))
((flags path-control-flag)
(name symbol)
(process process-drawable)
(curve curve :inline)
)
(:methods
(new (symbol type process symbol float entity symbol) _type_)
Expand Down
6 changes: 3 additions & 3 deletions goal_src/jak3/engine/gfx/foreground/foreground.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1894,9 +1894,9 @@
)
;;(.lui fg-work 28672)
(set! fg-work (scratchpad-object foreground-work))
;; (with-pc
;; (when (-> *pc-settings* force-envmap?)
;; (set! dist-in 0.0)))
(with-pc
(when (-> *pc-settings* force-envmap?)
(set! dist-in 0.0)))
(let* ((bone-calc (the-as bone-calculation (-> dma-buf base)))
(matrix-mem (the-as object (&+ (the-as pointer bone-calc) 64)))
)
Expand Down
24 changes: 12 additions & 12 deletions goal_src/jak3/game.gp
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@
(cgo-file "railf.gd" common-dep)
(cgo-file "railx.gd" common-dep)
; ;; precursor
; (cgo-file "preca.gd" common-dep)
; (cgo-file "precb.gd" common-dep)
; (cgo-file "precc.gd" common-dep)
; (cgo-file "precd.gd" common-dep)
(cgo-file "preca.gd" common-dep)
(cgo-file "precb.gd" common-dep)
(cgo-file "precc.gd" common-dep)
;; (cgo-file "precd.gd" common-dep)
; ;; title/intro
(cgo-file "win.gd" common-dep) ;; wasintro
(cgo-file "title.gd" common-dep)
Expand All @@ -280,15 +280,15 @@
(cgo-file "ipf.gd" common-dep) ;; intro-palace-fall
(cgo-file "introcst.gd" common-dep)
; ;; outro
; (cgo-file "outcast3.gd" common-dep)
; (cgo-file "outrocst.gd" common-dep)
(cgo-file "outcast3.gd" common-dep)
(cgo-file "outrocst.gd" common-dep)
; ;; museum
; (cgo-file "museum.gd" common-dep)
; (cgo-file "museum2.gd" common-dep)
; (cgo-file "museum3.gd" common-dep)
; (cgo-file "museum3b.gd" common-dep)
; (cgo-file "museum4.gd" common-dep)
; (cgo-file "museum4b.gd" common-dep)
(cgo-file "museum.gd" common-dep)
(cgo-file "museum2.gd" common-dep)
(cgo-file "museum3.gd" common-dep)
(cgo-file "museum3b.gd" common-dep)
(cgo-file "museum4.gd" common-dep)
(cgo-file "museum4b.gd" common-dep)
;; test
(cgo-file "halfpipe.gd" common-dep)
; ;; borrow
Expand Down
11 changes: 0 additions & 11 deletions goal_src/jak3/pc/debug/default-menu-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -879,17 +879,6 @@
(flag "On" #t dm-subtitle-setting)
(flag "Auto" auto dm-subtitle-setting)
)
(menu "Text language"
;; TODO macro
(flag "english" (the binteger (pc-language english)) dm-text-language)
(flag "french" (the binteger (pc-language french)) dm-text-language)
(flag "german" (the binteger (pc-language german)) dm-text-language)
(flag "spanish" (the binteger (pc-language spanish)) dm-text-language)
(flag "italian" (the binteger (pc-language italian)) dm-text-language)
(flag "japanese" (the binteger (pc-language japanese)) dm-text-language)
(flag "korean" (the binteger (pc-language korean)) dm-text-language)
(flag "uk-english" (the binteger (pc-language uk-english)) dm-text-language)
)
(flag "Discord RPC" #t ,(dm-lambda-boolean-flag (-> *pc-settings* discord-rpc?)))
(flag "Speedrunner Mode" #t ,(dm-lambda-boolean-flag (-> *pc-settings* speedrunner-mode?)))
;; (flag "Speedrunner Mode" #t ,(dm-lambda-boolean-flag (-> *pc-settings* speedrunner-mode?)))
Expand Down
Loading
Loading