Skip to content

Commit

Permalink
Jak 2 controller LED implementation (#3035)
Browse files Browse the repository at this point in the history
Adds controller LED features to Jak 2:
- progressive flickering denoting health
- copies tomb simon says puzzle colors
- unique colors for each gun
- orange color for being indax
- yellow color for being in mech
- purple color for being darkjak
- blue color for being in board
- red flash when wanted.

May add more features later?

Also did some minor clean-up on some types.
  • Loading branch information
ManDude authored Sep 28, 2023
1 parent 170cbd7 commit 1f4044b
Show file tree
Hide file tree
Showing 49 changed files with 656 additions and 385 deletions.
35 changes: 17 additions & 18 deletions decompiler/analysis/insert_lets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ FormElement* rewrite_as_send_event(LetElement* in,
{"'color-effect", {1}},
{"'set-alert-duration", {0}},
};

// enum to cast to.
EnumType* enum_ts = nullptr;

auto float_arg_settings = jak2_float_args.find(msg_str);
auto time_frame_arg_settings = jak2_time_frame_args.find(msg_str);
if ((float_arg_settings != jak2_float_args.end() &&
Expand All @@ -499,39 +503,34 @@ FormElement* rewrite_as_send_event(LetElement* in,
pool.form<ConstantTokenElement>(seconds_to_string(val)));
}
} else if (param_idx == 0 && (msg_str == "'get-pickup" || msg_str == "'test-pickup")) {
auto enum_ts = env.dts->ts.try_enum_lookup("pickup-type");
if (enum_ts) {
param_val = cast_to_int_enum(enum_ts, pool, env, val);
}
enum_ts = env.dts->ts.try_enum_lookup("pickup-type");
} else if (param_idx == 1 &&
(param_values.at(0)->to_string(env) == "'error" ||
param_values.at(0)->to_string(env) == "'done") &&
msg_str == "'notify") {
auto enum_ts = env.dts->ts.try_enum_lookup("mc-status-code");
if (enum_ts) {
param_val = cast_to_int_enum(enum_ts, pool, env, val);
}
enum_ts = env.dts->ts.try_enum_lookup("mc-status-code");
} else if (param_idx == 0 &&
(msg_str == "'deactivate-by-type" || msg_str == "'set-object-reserve-count" ||
msg_str == "'set-object-target-count" ||
msg_str == "'set-object-auto-activate" || msg_str == "'end-pursuit-by-type" ||
msg_str == "'get-object-remaining-count")) {
auto enum_ts = env.dts->ts.try_enum_lookup("traffic-type");
if (enum_ts) {
param_val = cast_to_int_enum(enum_ts, pool, env, val);
}
enum_ts = env.dts->ts.try_enum_lookup("traffic-type");
} else if (param_idx == 0 &&
(msg_str == "'clear-slave-option" || msg_str == "'set-slave-option" ||
msg_str == "'toggle-slave-option")) {
auto enum_ts = env.dts->ts.try_enum_lookup("cam-slave-options");
if (enum_ts) {
param_val = cast_to_bitfield_enum(enum_ts, pool, env, val);
}
enum_ts = env.dts->ts.try_enum_lookup("cam-slave-options");
} else if (param_idx == 2 && param_values.at(0)->to_string(env) == "'darkjak" &&
msg_str == "'change-mode") {
auto enum_ts = env.dts->ts.try_enum_lookup("darkjak-stage");
if (enum_ts) {
enum_ts = env.dts->ts.try_enum_lookup("darkjak-stage");
} else if (param_idx == 2 && param_values.at(0)->to_string(env) == "'gun" &&
msg_str == "'change-mode") {
enum_ts = env.dts->ts.try_enum_lookup("pickup-type");
}
if (enum_ts) {
if (enum_ts->is_bitfield()) {
param_val = cast_to_bitfield_enum(enum_ts, pool, env, val);
} else {
param_val = cast_to_int_enum(enum_ts, pool, env, val);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion decompiler/config/jak1/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,7 @@
(define-extern *listener-function* (function object))
(define-extern reset-and-call (function thread function object))
(define-extern execute-process-tree (function process-tree (function object object) kernel-context object))
(define-extern search-process-tree (function process-tree (function process-tree object) process-tree))
(define-extern search-process-tree (function process-tree (function process-tree object) process))
(define-extern iterate-process-tree (function process-tree (function object object) kernel-context object))
(define-extern process-not-name (function object process-tree process))
(define-extern process-by-name (function object process-tree process))
Expand Down
113 changes: 53 additions & 60 deletions decompiler/config/jak2/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@
(define-extern kill-not-type (function type process-tree symbol))
(define-extern iterate-process-tree (function process-tree (function object object) kernel-context object))
(define-extern execute-process-tree (function process-tree (function object object) kernel-context object))
(define-extern search-process-tree (function process-tree (function process-tree object) process-tree))
(define-extern search-process-tree (function process-tree (function process-tree object) process))
(define-extern kernel-dispatcher (function object))
(define-extern sync-dispatcher (function object))
(define-extern inspect-process-tree (function process-tree int int symbol process-tree))
Expand Down Expand Up @@ -7371,7 +7371,7 @@
(progress-controller-options-analog-deadzone #x1295)
(progress-controller-options-ignore-if-unfocused #x1296)
(progress-controller-options-led-hp #x1297)
(progress-controller-options-led-darkjak #x1298)
(progress-controller-options-led-state #x1298)
(progress-input-options-enable-keyboard #x1299)
(progress-input-options-enable-mouse #x129a)
(progress-menu-mouse-options #x129b)
Expand All @@ -7388,6 +7388,9 @@
(progress-keybinds-waiting-for-bind #x1306)
(progress-keybinds-unset #x1307)
(progress-unknown-option #x1308)
(progress-hires-sky #x1309)
(progress-fast-airlock #x130a)
(progress-fast-elevator #x130b)
)
;; ---text-id-h:text-id

Expand Down Expand Up @@ -13154,6 +13157,45 @@
;; game-info-h ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defenum pickup-type
:bitfield #f
:type int32
(none 0)
(eco-yellow 1)
(eco-red 2)
(eco-blue 3)
(eco-dark 4)
(eco-green 5)
(eco-pill-green 6)
(eco-pill-dark 7)
(eco-pill-random 8)
(money 9)
(fuel-cell 10)
(buzzer 11)
(darkjak 12)
(ammo-yellow 13)
(ammo-red 14)
(ammo-blue 15)
(ammo-dark 16)
(shield 17)
(health 18)
(trick-point 19)
(trick-judge 20)
(gem 21)
(skill 22)
(karma 23)
(gun-red 24)
(gun-yellow 25)
(gun-blue 26)
(gun-dark 27)
(board 28)
(pass-red 29)
(pass-green 30)
(pass-yellow 31)
(pass-blue 32)
(ammo-random 33)
)

(deftype game-bank (basic)
((life-max-default float :offset-assert 4)
(life-start-default float :offset-assert 8)
Expand Down Expand Up @@ -13366,7 +13408,7 @@
(unknown-pad1 uint32)
(purchase-secrets game-secrets :offset-assert 152)
(unknown-pad2 uint32 :offset-assert 156)
(gun-type int32 :offset-assert 160)
(gun-type pickup-type :offset-assert 160)
(gun-ammo float 4 :offset-assert 164)
(shield float :offset-assert 180)
(score float :offset-assert 184)
Expand Down Expand Up @@ -15026,45 +15068,6 @@
;; fact-h ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defenum pickup-type
:bitfield #f
:type int32
(none 0)
(eco-yellow 1)
(eco-red 2)
(eco-blue 3)
(eco-dark 4)
(eco-green 5)
(eco-pill-green 6)
(eco-pill-dark 7)
(eco-pill-random 8)
(money 9)
(fuel-cell 10)
(buzzer 11)
(darkjak 12)
(ammo-yellow 13)
(ammo-red 14)
(ammo-blue 15)
(ammo-dark 16)
(shield 17)
(health 18)
(trick-point 19)
(trick-judge 20)
(gem 21)
(skill 22)
(karma 23)
(gun-red 24)
(gun-yellow 25)
(gun-blue 26)
(gun-dark 27)
(board 28)
(pass-red 29)
(pass-green 30)
(pass-yellow 31)
(pass-blue 32)
(ammo-random 33)
)

(deftype fact-bank (basic)
((eco-level-max float :offset-assert 4)
(eco-single-inc float :offset-assert 8)
Expand Down Expand Up @@ -29728,12 +29731,12 @@
(define-extern *gun-walk-mods* surface)
(define-extern target-gun-event-handler (function process int symbol event-message-block object :behavior target))
(define-extern target-gun-setup (function symbol none :behavior target))
(define-extern target-gun-init (function int none :behavior target))
(define-extern target-gun-init (function pickup-type none :behavior target))
(define-extern target-gun-exit (function symbol))
(define-extern target-gun-end-mode (function symbol symbol :behavior target))
(define-extern quat<-gun! (function quaternion quaternion quaternion))
(define-extern target-gun-ammo-out-pick (function int :behavior target))
(define-extern target-gun-type-set! (function int none :behavior target))
(define-extern target-gun-type-set! (function pickup-type none :behavior target))
(define-extern target-gun-marking-menu (function target none))
(define-extern target-gun-build-track-list (function none :behavior target))
(define-extern target-gun-find-track (function none :behavior target))
Expand Down Expand Up @@ -46529,27 +46532,17 @@
(defenum simon-block-flags
:type uint16
:bitfield #t
(sbf0)
(sbf1)
(sbf2)
(blink)
(blink-on)
(ridden)
(sbf3)
(sbf4)
(sbf5)
(sbf6)
(sbf7)
(sbf8)
(sbf9)
(sbf10)
(sbf11)
(sbf12)
(sbf13)
(sbf14)
(sbf15)
(dangerous)
(up-sound-played)
)
;; ---tomb-water:simon-block-flags

(deftype tomb-simon-block (base-plat)
((sound-show uint128 :offset-assert 272)
((sound-show sound-name :offset-assert 272)
(color vector :inline :offset-assert 288)
(my-idx int32 :offset-assert 304)
(next-idx int32 :offset-assert 308)
Expand Down
11 changes: 7 additions & 4 deletions game/assets/jak2/text/game_custom_text_en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@
"1293": "Controller Options",
"1294": "Select Controller",
"1295": "Analog Deadzone",
"1296": "Ignore If Window Unfocused",
"1297": "Controller Led For HP",
"1298": "Controller Led For Dark Jak",
"1296": "Ignore When Window is Unfocused",
"1297": "Use LED for Health",
"1298": "Use LED for Other States",
"1299": "Enable Keyboard",
"129a": "Enable Mouse",
"129b": "Mouse Options",
Expand All @@ -147,5 +147,8 @@
"1305": "No Options",
"1306": "Waiting",
"1307": "Unset",
"1308": "Unknown"
"1308": "Unknown",
"1309": "High-Resolution Sky",
"130a": "Fast Airlocks and Doors",
"130b": "Fast Elevators"
}
9 changes: 9 additions & 0 deletions goal_src/goal-lib.gc
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,15 @@
)
)

(defmacro eq-any? (val &rest pred)
"is val equal to any of the values in pred? evaluated using or, so it short circuits."
(with-gensyms (val-var)
`(let ((,val-var ,val))
(or ,@(apply (lambda (x) `(= ,val-var ,x)) pred)))
)
)



;;;;;;;;;;;;;;;;;;;
;; Math Macros
Expand Down
15 changes: 15 additions & 0 deletions goal_src/jak1/engine/math/vector-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@
:flag-assert #x900000010
)

(defmacro static-vector (x y z w)
"creates a static vector."
`(new 'static 'vector :x ,x :y ,y :z ,z :w ,w)
)
(defmacro static-vectorm (x y z)
"creates a static vector using meters. w is set to 1.0"
`(new 'static 'vector :x (meters ,x) :y (meters ,y) :z (meters ,z) :w 1.0)
Expand Down Expand Up @@ -535,6 +539,17 @@
))
)

(defmacro set-vector-xyz! (v xv yv zv)
"Set xyz fields in a vector"
(with-gensyms (vec)
`(let ((,vec ,v))
(set! (-> ,vec x) ,xv)
(set! (-> ,vec y) ,yv)
(set! (-> ,vec z) ,zv)
,vec
))
)

(defun vector-dot ((a vector) (b vector))
"Take the dot product of two vectors.
Only does the x, y, z compoments.
Expand Down
16 changes: 7 additions & 9 deletions goal_src/jak1/kernel/gkernel.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1473,22 +1473,20 @@
(define *global-search-name* (the basic #f))
(define *global-search-count* 0)

(define-extern search-process-tree (function process-tree (function process-tree object) process-tree))
(define-extern search-process-tree (function process-tree (function process-tree object) process))
(define-extern iterate-process-tree (function process-tree (function object object) kernel-context object))
(define-extern execute-process-tree (function process-tree (function object object) kernel-context object))

(defun process-by-name (name (pool process-tree))
"Look up a process in the given pool by name"
(set! *global-search-name* (the basic name))
(the process (search-process-tree pool (lambda ((var process))
(name= (-> var name) *global-search-name*))))
(search-process-tree pool (lambda ((var process)) (name= (-> var name) *global-search-name*)))
)

(defun process-not-name (name (pool process-tree))
"Look up a process with not the given name."
(set! *global-search-name* (the basic name))
(the process (search-process-tree pool (lambda ((var process))
(not (name= (-> var name) *global-search-name*)))))
(search-process-tree pool (lambda ((var process)) (not (name= (-> var name) *global-search-name*))))
)

(defun process-count ((this process-tree))
Expand All @@ -1513,7 +1511,7 @@
(defun kill-by-type (type (pool process-tree))
"Call deactivate on all processes with the given type"
(set! *global-search-name* (the basic type))
(let ((proc (the process-tree #f)))
(let ((proc (the process #f)))
(while (set! proc (search-process-tree pool (lambda ((var process))
(= (the type *global-search-name*)
(-> var type)))))
Expand Down Expand Up @@ -1615,7 +1613,7 @@
(unless (process-mask? (-> this mask) process-tree)
;; is this a match?
(when (func this)
(return-from #f this)
(return (the process this))
)
)

Expand All @@ -1625,14 +1623,14 @@
(let ((temp (-> (-> brother) brother)))
(let ((ret (search-process-tree (-> brother) func)))
(when ret
(return-from #f ret)
(return ret)
)
)
(set! brother temp)
)
)
)
(the process-tree #f)
(the process #f)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
6 changes: 3 additions & 3 deletions goal_src/jak1/pc/debug/default-menu-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,9 @@
(flag "x16" 16 dm-msaa-pick-func)
)
(menu "LED"
(flag "hp" #f ,(dm-lambda-boolean-flag (-> *pc-settings* controller-hp-led?)))
(flag "eco" #f ,(dm-lambda-boolean-flag (-> *pc-settings* controller-eco-led?)))
(flag "heat" #f ,(dm-lambda-boolean-flag (-> *pc-settings* controller-heat-led?)))
(flag "hp" #f ,(dm-lambda-boolean-flag (-> *pc-settings* controller-led-hp?)))
(flag "eco" #f ,(dm-lambda-boolean-flag (-> *pc-settings* controller-led-eco?)))
(flag "heat" #f ,(dm-lambda-boolean-flag (-> *pc-settings* controller-led-heat?)))
)
(menu "Territory"
(flag "GAME_TERRITORY_SCEA" (the binteger GAME_TERRITORY_SCEA) dm-territory-pick-func)
Expand Down
Loading

0 comments on commit 1f4044b

Please sign in to comment.