From 7d6931155271bee7ab23dee644c7190d2a0cbd72 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Thu, 13 May 2021 02:45:36 +0100 Subject: [PATCH] [decomp] some of `fact-h` (#473) * update scripts * decomp some of `fact-h` --- decompiler/config/all-types.gc | 17 ++-- .../jak1_ntsc_black_label/label_types.jsonc | 10 +++ .../jak1_ntsc_black_label/type_casts.jsonc | 8 ++ .../jak1_ntsc_black_label/var_names.jsonc | 5 ++ goal_src/engine/data/res-h.gc | 2 +- goal_src/engine/game/fact-h.gc | 85 ++++++++++--------- goal_src/engine/physics/dynamics-h.gc | 13 +-- goal_src/engine/util/types-h.gc | 14 ++- scripts/batch/repo-settings-mark.bat | 2 +- scripts/batch/repo-settings-unmark.bat | 2 +- 10 files changed, 98 insertions(+), 60 deletions(-) diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 6f43de4820..ed7d4fb192 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -326,7 +326,7 @@ (pid int32 :offset-assert #x28) (main-thread cpu-thread :offset-assert #x2c) (top-thread thread :offset-assert #x30) - (entity basic :offset-assert #x34) + (entity basic :offset-assert #x34) ;; entity (state state :offset-assert #x38) (trans-hook function :offset-assert #x3c) (post-hook function :offset-assert #x40) @@ -8520,7 +8520,7 @@ (dummy-9 (_type_ symbol symbol int symbol (pointer res-tag) pointer) symbol 9) (dummy-10 (_type_ symbol symbol int symbol symbol pointer) int 10) (dummy-11 (_type_ symbol symbol int int symbol pointer) int 11) - (dummy-12 (_type_ symbol symbol int int symbol pointer) float 12) + (dummy-12 (_type_ symbol symbol float float symbol pointer) float 12) (dummy-13 (_type_ int) pointer 13) ;; advance tag pointer (dummy-14 (_type_ uint) pointer 14) (dummy-15 (_type_) none 15) @@ -8777,8 +8777,8 @@ (:methods (new (symbol type process pickup-type float) _type_ 0) (dummy-9 () none 9) - (dummy-10 () none 10) - (dummy-11 (_type_) none 11) + (dummy-10 (_type_ symbol) none 10) + (dummy-11 (_type_) float 11) ) ) @@ -8805,6 +8805,9 @@ :method-count-assert 12 :size-assert #x90 :flag-assert #xc00000090 + (:methods + (new (symbol type process pickup-type float) _type_ 0) + ) ) ;; fact-h @@ -8820,6 +8823,9 @@ :method-count-assert 12 :size-assert #x44 :flag-assert #xc00000044 + (:methods + (new (symbol type process pickup-type float) _type_ 0) + ) ) ;; aligner-h @@ -33640,7 +33646,7 @@ ;;(define-extern notice-top object) ;; unknown type ;;(define-extern speed object) ;; unknown type ;;(define-extern cam-notice-dist object) ;; unknown type -;;(define-extern process-drawable-art-error object) ;; unknown type +(define-extern process-drawable-art-error symbol) ;; unknown type ;;(define-extern notice-bottom object) ;; unknown type ;;(define-extern eco-info object) ;; unknown type ;;(define-extern cam-horz object) ;; unknown type @@ -33711,7 +33717,6 @@ ;;(define-extern collide-frag-vertex object) ;; unknown type (define-extern drawable-tree-collide-fragment type) ;;(define-extern projectile-blue object) ;; unknown type -;;(define-extern *sidekick* object) ;; unknown type (define-extern bsp-header type) (define-extern inspect-bsp-tree function) (define-extern map-bsp-tree function) diff --git a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc index 57a41b39ff..428f42dc8d 100644 --- a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc @@ -275,6 +275,16 @@ ["L373", "uint64", true], ["L371", "uint64", true] ], + + "fact-h": [ + ["L36", "float", true], + ["L37", "float", true], + ["L38", "float", true], + ["L39", "float", true], + ["L40", "float", true], + ["L41", "float", true], + ["L42", "float", true] + ], "lights": [ ["L8", "float", true], diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index c99bd51d7d..da756dcddb 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -393,5 +393,13 @@ // SHADOW-CPU-H "(method 10 shadow-control)": [ [1, "v1", "int"] + ], + + // FACT-H + "(method 0 fact-info-enemy)": [ + [3, "v0", "fact-info-enemy"] + ], + "(method 0 fact-info-target)": [ + [3, "v0", "fact-info-target"] ] } diff --git a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc index fd884a7601..e695aa97af 100644 --- a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc @@ -1561,5 +1561,10 @@ "(method 0 shadow-control)": { "args": ["allocation", "type-to-make", "bottom-offset", "top-offset", "dir", "center", "fade"], "vars": { "v0-0": "obj" } + }, + + // FACT-H + "(method 0 fact-info-target)": { + "vars": { "gp-0": "obj" } } } diff --git a/goal_src/engine/data/res-h.gc b/goal_src/engine/data/res-h.gc index 2681bc7367..dfde629266 100644 --- a/goal_src/engine/data/res-h.gc +++ b/goal_src/engine/data/res-h.gc @@ -31,7 +31,7 @@ (dummy-9 (_type_ symbol symbol int symbol (pointer res-tag) pointer) symbol 9) (dummy-10 (_type_ symbol symbol int symbol symbol pointer) int 10) (dummy-11 (_type_ symbol symbol int int symbol pointer) int 11) - (dummy-12 (_type_ symbol symbol int int symbol pointer) float 12) + (dummy-12 (_type_ symbol symbol float float symbol pointer) float 12) (dummy-13 (_type_ int) pointer 13) ;; advance tag pointer (dummy-14 (_type_ uint) pointer 14) (dummy-15 (_type_) none 15) diff --git a/goal_src/engine/game/fact-h.gc b/goal_src/engine/game/fact-h.gc index 815f1baa4e..293fa7870c 100644 --- a/goal_src/engine/game/fact-h.gc +++ b/goal_src/engine/game/fact-h.gc @@ -8,44 +8,43 @@ ;; NOT FINISHED (deftype fact-bank (basic) - ((eco-level-max float :offset-assert 4) - (eco-single-inc float :offset-assert 8) - (eco-full-inc float :offset-assert 12) + ((eco-level-max float :offset-assert 4) + (eco-single-inc float :offset-assert 8) + (eco-full-inc float :offset-assert 12) (eco-single-timeout uint64 :offset-assert 16) ; usec (eco-full-timeout uint64 :offset-assert 24) ; usec (dummy uint64 :offset-assert 32) ; usec - (health-max-default float :offset-assert 40) - (health-single-inc float :offset-assert 44) - (eco-pill-max-default float :offset-assert 48) - (health-small-inc float :offset-assert 52) - (buzzer-max-default float :offset-assert 56) - (buzzer-single-inc float :offset-assert 60) - (suck-bounce-dist float :offset-assert 64) ; meters - (suck-suck-dist float :offset-assert 68) ; meters - (default-pill-inc float :offset-assert 72) + (health-max-default float :offset-assert 40) + (health-single-inc float :offset-assert 44) + (eco-pill-max-default float :offset-assert 48) + (health-small-inc float :offset-assert 52) + (buzzer-max-default float :offset-assert 56) + (buzzer-single-inc float :offset-assert 60) + (suck-bounce-dist float :offset-assert 64) ; meters + (suck-suck-dist float :offset-assert 68) ; meters + (default-pill-inc float :offset-assert 72) ) :method-count-assert 9 :size-assert #x4c :flag-assert #x90000004c ) -(define *FACT-bank* - (new 'static 'fact-bank - :eco-level-max 2.000000 - :eco-single-inc 1.000000 - :eco-full-inc 5.000000 - :eco-single-timeout #x5dc - :eco-full-timeout #x1770 - :dummy #x1194 - :health-max-default 3.000000 - :health-single-inc 1.000000 - :eco-pill-max-default 50.000000 - :health-small-inc 1.000000 - :buzzer-max-default 7.000000 - :buzzer-single-inc 1.000000 - :suck-bounce-dist 73728.000000 - :suck-suck-dist 30720.000000 - ) +(define *FACT-bank* (new 'static 'fact-bank + :eco-level-max 2.0 + :eco-single-inc 1.0 + :eco-full-inc 5.0 + :eco-single-timeout (seconds 5) + :eco-full-timeout (seconds 20) + :dummy (seconds 15) + :health-max-default 3.0 + :health-single-inc 1.0 + :eco-pill-max-default 50.0 + :health-small-inc 1.0 + :buzzer-max-default 7.0 + :buzzer-single-inc 1.0 + :suck-bounce-dist (meters 18) + :suck-suck-dist (meters 7.5) + ) ) (defenum pickup-type @@ -91,8 +90,8 @@ (:methods (new (symbol type process pickup-type float) _type_ 0) (dummy-9 () none 9) - (dummy-10 () none 10) - (dummy-11 (_type_) none 11) + (dummy-10 (_type_ symbol) none 10) + (dummy-11 (_type_) float 11) ) ) @@ -100,7 +99,7 @@ ((eco-type int32 :offset-assert 40) (eco-level float :offset-assert 44) (eco-pickup-time uint64 :offset-assert 48) - (eco-timeout uint64 :offset-assert 56) ;; usec + (eco-timeout uint64 :offset-assert 56) ;; usec (health float :offset-assert 64) (health-max float :offset-assert 68) (buzzer float :offset-assert 72) @@ -118,18 +117,28 @@ :method-count-assert 12 :size-assert #x90 :flag-assert #xc00000090 + (:methods + (new (symbol type process pickup-type float) _type_ 0) + ) ) (deftype fact-info-enemy (fact-info) ((speed float :offset-assert 40) - (idle-distance float :offset-assert 44) ; meters - (notice-top float :offset-assert 48) ; meters - (notice-bottom float :offset-assert 52) ; meters - (cam-horz float :offset-assert 56) ; meters - (cam-vert float :offset-assert 60) ; meters - (cam-notice-dist float :offset-assert 64) ; meters + (idle-distance float :offset-assert 44) ; meters + (notice-top float :offset-assert 48) ; meters + (notice-bottom float :offset-assert 52) ; meters + (cam-horz float :offset-assert 56) ; meters + (cam-vert float :offset-assert 60) ; meters + (cam-notice-dist float :offset-assert 64) ; meters ) :method-count-assert 12 :size-assert #x44 :flag-assert #xc00000044 + (:methods + (new (symbol type process pickup-type float) _type_ 0) + ) + ) + +(defmethod dummy-11 fact-info ((obj fact-info)) + 0.0 ) diff --git a/goal_src/engine/physics/dynamics-h.gc b/goal_src/engine/physics/dynamics-h.gc index 7b654a739a..699c67f43c 100644 --- a/goal_src/engine/physics/dynamics-h.gc +++ b/goal_src/engine/physics/dynamics-h.gc @@ -5,13 +5,6 @@ ;; name in dgo: dynamics-h ;; dgos: GAME, ENGINE -;; TODO move these elsewhere -(defglobalconstant TICKS_TO_SECONDS (/ 1.0 300)) ;; #x3b5a740e - 0.0033333333... -(defmacro vel-to-tick (vel) - "turn a velocity value into a per-tick value" - `(* ,TICKS_TO_SECONDS ,vel) - ) - (deftype dynamics (basic) ((name basic :offset-assert 4) (gravity-max float :offset-assert 8) ;; meters @@ -27,7 +20,7 @@ ) (defun time-to-apex ((arg0 float) (arg1 float)) - (the int (/ arg0 (- (vel-to-tick arg1)))) + (the int (/ arg0 (- (vel-tick arg1)))) ) (defun time-to-ground ((velocity float) (gravity float) (height float)) @@ -36,8 +29,8 @@ (ticks 0)) ;; loop in ticks until we reach the ground (while (< (- height) height-checked) - (let ((velocity (- velocity (vel-to-tick gravity)))) - (+! height-checked (vel-to-tick velocity)) + (let ((velocity (- velocity (vel-tick gravity)))) + (+! height-checked (vel-tick velocity)) ) (+! ticks 1) ) diff --git a/goal_src/engine/util/types-h.gc b/goal_src/engine/util/types-h.gc index 89b60d27a7..a90a42b000 100644 --- a/goal_src/engine/util/types-h.gc +++ b/goal_src/engine/util/types-h.gc @@ -54,17 +54,25 @@ ) ) +(defglobalconstant TICKS_PER_SECOND 300) ;; 5 t/frame @ 60fps, 6 t/frame @ 50fps + (defmacro seconds (x) "Convert number to seconds unit." (cond ((float? x) - (* 300.0 x) + (* (* 1.0 TICKS_PER_SECOND) x) ) ((integer? x) - (* 300 x) + (* TICKS_PER_SECOND x) ) (#t - `(* 300.0 ,x) + `(* (* 1.0 TICKS_PER_SECOND) ,x) ) ) + ) + +;; maybe rename to "velocity"? +(defmacro vel-tick (vel) + "turn a velocity value into a per-tick value" + `(* (/ 1.0 ,TICKS_PER_SECOND) ,vel) ) \ No newline at end of file diff --git a/scripts/batch/repo-settings-mark.bat b/scripts/batch/repo-settings-mark.bat index b112fa806b..d44608d553 100644 --- a/scripts/batch/repo-settings-mark.bat +++ b/scripts/batch/repo-settings-mark.bat @@ -1,2 +1,2 @@ cd ..\.. -git update-index --assume-unchanged decompiler\config\jak1_ntsc_black_label.jsonc +git update-index --assume-unchanged decompiler\config\jak1_ntsc_black_label.jsonc decompiler\config\jak1_ntsc_black_label\inputs.jsonc diff --git a/scripts/batch/repo-settings-unmark.bat b/scripts/batch/repo-settings-unmark.bat index 75b2a4777c..bf3eee7899 100644 --- a/scripts/batch/repo-settings-unmark.bat +++ b/scripts/batch/repo-settings-unmark.bat @@ -1,2 +1,2 @@ cd ..\.. -git update-index --no-assume-unchanged decompiler\config\jak1_ntsc_black_label.jsonc +git update-index --no-assume-unchanged decompiler\config\jak1_ntsc_black_label.jsonc decompiler\config\jak1_ntsc_black_label\inputs.jsonc