From f438ba4e844161103fb73d4ac882b1786ace5e9b Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 9 Aug 2021 19:07:11 -0400 Subject: [PATCH] decomp: `shadow` (#681) * decomp: Almost finish `shadow` blocked on static inline-array * decomp: Add support for `sparticle-launcher` static data * decomp: finalize `shadow` * add definitions for sparticle related symbols * actually fix the crash --- common/util/print_float.cpp | 3 +- decompiler/config/all-types.gc | 71 ++-- .../jak1_ntsc_black_label/label_types.jsonc | 7 + .../stack_structures.jsonc | 17 +- .../jak1_ntsc_black_label/type_casts.jsonc | 7 +- decompiler/util/data_decompile.cpp | 20 +- goal_src/engine/collide/collide-cache-h.gc | 6 +- goal_src/engine/game/projectiles-h.gc | 46 +-- goal_src/engine/gfx/shadow/shadow.gc | 336 +++++++++++++++++ goal_src/engine/sparticle/sparticle-h.gc | 4 + .../engine/sparticle/sparticle-launcher-h.gc | 28 +- .../engine/sparticle/sparticle-launcher.gc | 3 + .../engine/collide/collide-cache-h_REF.gc | 6 +- .../engine/game/projectiles-h_REF.gc | 2 +- .../reference/engine/gfx/shadow/shadow_REF.gc | 343 ++++++++++++++++++ .../gfx/sparticle/sparticle-launcher-h_REF.gc | 24 +- 16 files changed, 815 insertions(+), 108 deletions(-) create mode 100644 test/decompiler/reference/engine/gfx/shadow/shadow_REF.gc diff --git a/common/util/print_float.cpp b/common/util/print_float.cpp index 5f02ed3e3..679f1288d 100644 --- a/common/util/print_float.cpp +++ b/common/util/print_float.cpp @@ -4,6 +4,7 @@ #include "common/common_types.h" #include "third-party/dragonbox.h" #include "print_float.h" +#include "common/util/assert.h" /*! * Convert a float to a string. The string is _always_ in this format: @@ -127,4 +128,4 @@ int float_to_cstr(float value, char* buffer) { } } return i; -} \ No newline at end of file +} diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 2bf1cd1d2..e4ba043f5 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -11420,7 +11420,7 @@ (projectile-dissipate () none 21) ;; state (projectile-impact () none 22) ;; state (dummy-23 () none 23) - (dummy-24 () none 24) + (dummy-24 (_type_ ) none 24) (dummy-25 () none 25) (dummy-26 () none 26) (dummy-27 () none 27) @@ -11852,15 +11852,15 @@ (dummy-9 () none 9) (dummy-10 () none 10) (dummy-11 () none 11) - (dummy-12 () none 12) + (dummy-12 (_type_ vector float uint process bone uint) float 12) ;; TODO - bone not confirmed (dummy-13 () none 13) (dummy-14 () none 14) (dummy-15 () none 15) - (dummy-16 () none 16) + (dummy-16 (_type_ vector float uint process uint) none 16) (dummy-17 () none 17) (dummy-18 () none 18) (dummy-19 () none 19) - (dummy-20 () none 20) + (dummy-20 (_type_ vector float uint bone uint) none 20) ;; TODO - bone not confirmed (dummy-21 () none 21) (dummy-22 () none 22) (dummy-23 () none 23) @@ -13220,12 +13220,12 @@ (deftype sp-field-init-spec (structure) ((field uint16 :offset-assert 0) (flags uint16 :offset-assert 2) - (initial-valuef float :offset-assert 4) - (random-rangef float :offset-assert 8) - (random-multf float :offset-assert 12) - (initial-value int32 :offset 4) - (random-range int32 :offset 8) - (random-mult int32 :offset 12) + (initial-value int32 :offset-assert 4) + (random-range int32 :offset-assert 8) + (random-mult int32 :offset-assert 12) + (initial-valuef float :offset 4) ;; TODO - floats suck - some of these values end up being NaN - these should come before the int32 fields + (random-rangef float :offset 8) ;; TODO - floats suck - some of these values end up being NaN - these should come before the int32 fields + (random-multf float :offset 12) ;; TODO - floats suck - some of these values end up being NaN - these should come before the int32 fields (func basic :offset 4) (tex uint32 :offset 4) (pntr uint32 :offset 4) @@ -13240,7 +13240,7 @@ (deftype sparticle-launcher (basic) ((birthaccum float :offset-assert 4) (soundaccum float :offset-assert 8) - (init-specs uint32 :offset-assert 12) + (init-specs (inline-array sp-field-init-spec) :offset-assert 12) ) :method-count-assert 9 :size-assert #x10 @@ -18977,7 +18977,7 @@ (define-extern level-setup (function none)) (define-extern target-exit function) (define-extern target-calc-camera-pos function) -(define-extern do-target-shadow function) +(define-extern do-target-shadow (function none :behavior target)) (define-extern target-powerup-process function) (define-extern flag-setup function) (define-extern build-conversions function) @@ -20853,7 +20853,7 @@ (define-extern projectile-collision-reaction function) (define-extern projectile-update-velocity-space-wars function) (define-extern find-nearest-attackable function) -(define-extern find-ground-and-draw-shadow function) +(define-extern find-ground-and-draw-shadow (function vector vector float uint process float float none)) (define-extern spawn-projectile-blue function) ;; - Unknowns @@ -21010,9 +21010,9 @@ ;; - Functions -(define-extern compute-and-draw-shadow function) -(define-extern draw-shadow function) -(define-extern add-fake-shadow-to-buffer function) +(define-extern compute-and-draw-shadow (function vector vector vector vector float float none)) +(define-extern draw-shadow (function vector vector vector float float float none)) +(define-extern add-fake-shadow-to-buffer (function vector vector float int none)) (define-extern swap-fake-shadow-buffers (function none)) @@ -36957,36 +36957,15 @@ ;; - Types -; (deftype mother-spider-proj (projectile) -; ((facing-dir vector :inline :offset-assert 416) -; ) -; :method-count-assert 29 -; :size-assert #x1b0 -; :flag-assert #x1d014001b0 -; ;; inherited inspect of projectile -; (:methods -; (dummy-9 () none 9) -; (dummy-10 () none 10) -; (dummy-11 () none 11) -; (dummy-12 () none 12) -; (dummy-13 () none 13) -; (dummy-14 () none 14) -; (dummy-15 () none 15) -; (dummy-16 () none 16) -; (dummy-17 () none 17) -; (dummy-18 () none 18) -; (dummy-19 () none 19) -; (dummy-20 () none 20) -; (dummy-21 () none 21) -; (dummy-22 () none 22) -; (dummy-23 () none 23) -; (dummy-24 () none 24) -; (dummy-25 () none 25) -; (dummy-26 () none 26) -; (dummy-27 () none 27) -; (dummy-28 () none 28) -; ) -; ) +(deftype mother-spider-proj (projectile) + ((facing-dir vector :inline :offset-assert 416) + ) + :method-count-assert 29 + :heap-base #x140 + :size-assert #x1b0 + :flag-assert #x1d014001b0 + ;; inherited inspect of projectile + ) ;; - Functions diff --git a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc index 538426c8c..719b1fbc9 100644 --- a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc @@ -1413,6 +1413,13 @@ ["L508", "float", true] ], + "shadow": [ + ["L23", "sparticle-launcher", true], + ["L26", "float", true], + ["L27", "float", true], + ["L28", "float", true] + ], + // please do not add things after this entry! git is dumb. "object-file-that-doesnt-actually-exist-and-i-just-put-this-here-to-prevent-merge-conflicts-with-this-file": [] } diff --git a/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc b/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc index 7789fb60a..f2335f18e 100644 --- a/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc @@ -469,7 +469,6 @@ "(anon-function 286 task-control)": [[16, "event-message-block"]], "(anon-function 227 task-control)": [[16, "event-message-block"]], "(anon-function 38 task-control)": [[16, "event-message-block"]], - "(anon-function 28 task-control)": [[16, "event-message-block"]], "(method 10 border-plane)": [[16, "vector"]], "(method 9 game-info)": [[16, "event-message-block"]], "(method 9 continue-point)": [[16, "vector"]], @@ -821,5 +820,21 @@ [16, "sphere"] ], + "compute-and-draw-shadow": [ + [16, "vector"], + [32, "vector"], + [48, "sparticle-cpuinfo"] // kinda a guess + ], + + "find-ground-and-draw-shadow": [ + [16, "vector"], + [32, "vector"], + [48, "bone"] // what a guess! + ], + + "(method 20 collide-cache)": [ + [16, "vector"] + ], + "placeholder-do-not-add-below!": [] } diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index 8ab0548d7..a398d83cb 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -1787,9 +1787,10 @@ "draw-ocean-transition": [[255, "v1", "ocean-mid-mask"]], - // "ocean-trans-mask-ptrs-bit?": [ - // [[32, 41], "a0", "(pointer ocean-trans-mask)"] - // ], + "do-target-shadow": [ + [[0, 999], "s6", "target"], + [46, "v1", "collide-shape-prim"] // `event-other` from collide-shape + ], "placeholder-do-not-add-below": [] } diff --git a/decompiler/util/data_decompile.cpp b/decompiler/util/data_decompile.cpp index bb037e9e0..f36eecc5a 100644 --- a/decompiler/util/data_decompile.cpp +++ b/decompiler/util/data_decompile.cpp @@ -288,7 +288,7 @@ int index_of_closest_following_label_in_segment(int start_byte, for (int i = 0; i < (int)labels.size(); i++) { const auto& label = labels.at(i); if (label.target_segment == seg) { - if (result_idx == -1) { + if (result_idx == -1 && label.offset > start_byte) { result_idx = i; closest_byte = label.offset; } else { @@ -419,6 +419,20 @@ goos::Object ocean_mid_masks_decompile(const std::vector& words, data_field, all_words, file, TypeSpec("ocean-mid-mask"), 8); } + +goos::Object sp_field_init_spec_decompile(const std::vector& words, + const std::vector& labels, + int my_seg, + int field_location, + const TypeSystem& ts, + const Field& data_field, + const std::vector>& all_words, + const LinkedObjectFile* file) { + return decomp_ref_to_inline_array_guess_size(words, labels, my_seg, field_location, ts, + data_field, all_words, file, + TypeSpec("sp-field-init-spec"), 16); +} + } // namespace goos::Object decompile_structure(const TypeSpec& type, @@ -608,6 +622,10 @@ goos::Object decompile_structure(const TypeSpec& type, field_defs_out.emplace_back( field.name(), ocean_mid_masks_decompile(obj_words, labels, label.target_segment, field_start, ts, field, words, file)); + } else if (field.name() == "init-specs" && type.print() == "sparticle-launcher") { + field_defs_out.emplace_back( + field.name(), sp_field_init_spec_decompile(obj_words, labels, label.target_segment, + field_start, ts, field, words, file)); } else { std::vector bytes_out; for (int byte_idx = field_start; byte_idx < field_end; byte_idx++) { diff --git a/goal_src/engine/collide/collide-cache-h.gc b/goal_src/engine/collide/collide-cache-h.gc index 400d49362..ee181d357 100644 --- a/goal_src/engine/collide/collide-cache-h.gc +++ b/goal_src/engine/collide/collide-cache-h.gc @@ -110,15 +110,15 @@ (dummy-9 () none 9) (dummy-10 () none 10) (dummy-11 () none 11) - (dummy-12 () none 12) + (dummy-12 (_type_ vector float uint process bone uint) float 12) ;; TODO - bone not confirmed (dummy-13 () none 13) (dummy-14 () none 14) (dummy-15 () none 15) - (dummy-16 () none 16) + (dummy-16 (_type_ vector float uint process uint) none 16) (dummy-17 () none 17) (dummy-18 () none 18) (dummy-19 () none 19) - (dummy-20 () none 20) + (dummy-20 (_type_ vector float uint bone uint) none 20) ;; TODO - bone not confirmed (dummy-21 () none 21) (dummy-22 () none 22) (dummy-23 () none 23) diff --git a/goal_src/engine/game/projectiles-h.gc b/goal_src/engine/game/projectiles-h.gc index 6f5fa1853..df2a810e0 100644 --- a/goal_src/engine/game/projectiles-h.gc +++ b/goal_src/engine/game/projectiles-h.gc @@ -6,28 +6,28 @@ ;; dgos: GAME, ENGINE (deftype projectile (process-drawable) - ((base-trans vector :inline :offset-assert 176) - (target vector :inline :offset-assert 192) - (target-base vector :inline :offset-assert 208) - (parent-base vector :inline :offset-assert 224) - (parent-quat vector :inline :offset-assert 240) - (base-vector vector :inline :offset-assert 256) - (timeout uint64 :offset-assert 272) - (options uint64 :offset-assert 280) - (last-target uint64 :offset-assert 288) - (notify-handle uint64 :offset-assert 296) - (max-speed float :offset-assert 304) - (max-turn float :offset-assert 308) - (old-dist float 16 :offset-assert 312) - (old-dist-count int32 :offset-assert 376) - (hits int32 :offset-assert 380) - (max-hits int32 :offset-assert 384) - (tween float :offset-assert 388) - (attack-mode basic :offset-assert 392) - (update-velocity basic :offset-assert 396) - (counter int32 :offset-assert 400) - (target-count int32 :offset-assert 404) - (sound-id sound-id :offset-assert 408) + ((base-trans vector :inline :offset-assert 176) + (target vector :inline :offset-assert 192) + (target-base vector :inline :offset-assert 208) + (parent-base vector :inline :offset-assert 224) + (parent-quat vector :inline :offset-assert 240) + (base-vector vector :inline :offset-assert 256) + (timeout uint64 :offset-assert 272) + (options uint64 :offset-assert 280) + (last-target uint64 :offset-assert 288) + (notify-handle uint64 :offset-assert 296) + (max-speed float :offset-assert 304) + (max-turn float :offset-assert 308) + (old-dist float 16 :offset-assert 312) + (old-dist-count int32 :offset-assert 376) + (hits int32 :offset-assert 380) + (max-hits int32 :offset-assert 384) + (tween float :offset-assert 388) + (attack-mode basic :offset-assert 392) + (update-velocity basic :offset-assert 396) + (counter int32 :offset-assert 400) + (target-count int32 :offset-assert 404) + (sound-id sound-id :offset-assert 408) ) :heap-base #x130 :method-count-assert 29 @@ -38,7 +38,7 @@ (projectile-dissipate () none 21) ;; state (projectile-impact () none 22) ;; state (dummy-23 () none 23) - (dummy-24 () none 24) + (dummy-24 (_type_) none 24) (dummy-25 () none 25) (dummy-26 () none 26) (dummy-27 () none 27) diff --git a/goal_src/engine/gfx/shadow/shadow.gc b/goal_src/engine/gfx/shadow/shadow.gc index 939906ead..7255ee29e 100644 --- a/goal_src/engine/gfx/shadow/shadow.gc +++ b/goal_src/engine/gfx/shadow/shadow.gc @@ -5,3 +5,339 @@ ;; name in dgo: shadow ;; dgos: GAME, ENGINE +;; definition for function add-fake-shadow-to-buffer +;; INFO: Return type mismatch int vs none. +(defun + add-fake-shadow-to-buffer + ((arg0 vector) (arg1 vector) (arg2 float) (arg3 int)) + (let ((v1-0 *fake-shadow-buffer*)) + (when (< (-> v1-0 num-shadows) 32) + (let ((t0-5 (-> v1-0 data (-> v1-0 num-shadows)))) + (set! (-> t0-5 px) (-> arg0 x)) + (set! (-> t0-5 py) (-> arg0 y)) + (set! (-> t0-5 pz) (-> arg0 z)) + (set! (-> t0-5 scale) arg2) + (set! (-> t0-5 qx) (-> arg1 x)) + (set! (-> t0-5 qy) (-> arg1 y)) + (set! (-> t0-5 qz) (-> arg1 z)) + (set! (-> t0-5 flags) arg3) + ) + (+! (-> v1-0 num-shadows) 1) + ) + ) + 0 + (none) + ) + +;; definition for function swap-fake-shadow-buffers +;; INFO: Return type mismatch int vs none. +(defun swap-fake-shadow-buffers () + (set! *fake-shadow-buffer* (if (= *fake-shadow-buffer* *fake-shadow-buffer-1*) + *fake-shadow-buffer-2* + *fake-shadow-buffer-1* + ) + ) + (set! (-> *fake-shadow-buffer* num-shadows) 0) + 0 + (none) + ) + +;; definition for function draw-shadow +;; INFO: Return type mismatch int vs none. +(defun + draw-shadow + ((arg0 vector) + (arg1 vector) + (arg2 vector) + (arg3 float) + (arg4 float) + (arg5 float) + ) + (let ((f0-1 (- (-> arg0 y) (-> arg1 y)))) + (if (< f0-1 arg4) + (add-fake-shadow-to-buffer + arg1 + arg2 + (* (- 1.0 (/ f0-1 arg4)) arg3) + (the-as int arg5) + ) + ) + ) + 0 + (none) + ) + +;; definition for function compute-and-draw-shadow +;; INFO: Return type mismatch int vs none. +;; Used lq/sq +(defun + compute-and-draw-shadow + ((arg0 vector) + (arg1 vector) + (arg2 vector) + (arg3 vector) + (arg4 float) + (arg5 float) + ) + (local-vars + (v1-10 float) + (v1-11 float) + (sv-96 vector) + (sv-112 (function quaternion vector float quaternion)) + (sv-128 vector) + (sv-144 vector) + ) + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (set! sv-96 arg2) + (let ((s4-0 arg3) + (s3-0 arg4) + (s2-0 arg5) + ) + (when (< (- (-> arg0 y) (-> arg1 y)) s3-0) + (set! sv-144 (new 'stack-no-clear 'vector)) + (let ((s0-0 (new 'stack-no-clear 'vector)) + (s1-0 (new 'stack-no-clear 'sparticle-cpuinfo)) + ) + (set! (-> arg1 y) (+ 40.96 (-> arg1 y))) + (set! (-> sv-144 x) (-> sv-96 z)) + (set! (-> sv-144 y) 0.0) + (set! (-> sv-144 z) (- (-> sv-96 x))) + (vector-normalize! sv-144 1.0) + (set! sv-112 quaternion-vector-angle!) + (set! sv-128 s0-0) + (let ((a2-1 (acos (-> sv-96 y)))) + (sv-112 (the-as quaternion sv-128) sv-144 a2-1) + ) + (let ((v1-9 s1-0)) + (cond + ((< (-> s0-0 w) 0.0) + (.lvf vf1 (&-> v1-9 vel-sxvel quad)) + (.lvf vf2 (&-> s0-0 quad)) + (.sub.vf vf1 vf0 vf2 :mask #b111) + (.svf (&-> v1-9 vel-sxvel quad) vf1) + (.mov v1-10 vf1) + ) + (else + (.lvf vf1 (&-> v1-9 vel-sxvel quad)) + (.lvf vf2 (&-> s0-0 quad)) + (.add.vf vf1 vf0 vf2 :mask #b111) + (.svf (&-> v1-9 vel-sxvel quad) vf1) + (.mov v1-11 vf1) + ) + ) + ) + (draw-shadow arg0 arg1 (-> s1-0 vel-sxvel) (the-as float s4-0) s3-0 s2-0) + ) + ) + ) + 0 + (none) + ) + ) + +;; definition for function find-ground-and-draw-shadow +;; INFO: Return type mismatch int vs none. +;; Used lq/sq +(defun + find-ground-and-draw-shadow + ((arg0 vector) + (arg1 vector) + (arg2 float) + (arg3 uint) + (arg4 process) + (arg5 float) + (arg6 float) + ) + (let ((s2-0 (new 'stack-no-clear 'vector))) + (set! (-> s2-0 quad) (-> arg0 quad)) + (new 'stack-no-clear 'vector) + (+! (-> s2-0 y) arg5) + (let ((s4-0 (new 'stack-no-clear 'bone))) + (cond + ((>= + (dummy-12 *collide-cache* s2-0 arg6 arg3 arg4 s4-0 (the-as uint 1)) + 0.0 + ) + (if (!= arg2 0.0) + (compute-and-draw-shadow + s2-0 + (-> s4-0 position) + (-> s4-0 scale) + (the-as vector arg2) + arg6 + (the-as float 0) + ) + ) + (if (and arg1 (!= (shr (shl (-> s4-0 cache bone-matrix) 52) 58) 3)) + (set! (-> arg1 quad) (-> s4-0 position quad)) + ) + ) + (else + (if arg1 + (vector+float*! + arg1 + arg0 + (-> *standard-dynamics* gravity-normal) + (- arg6) + ) + ) + ) + ) + ) + ) + 0 + (none) + ) + +;; definition for function do-target-shadow +;; INFO: Return type mismatch int vs none. +;; Used lq/sq +(defbehavior do-target-shadow target () + (if + (and + (logtest? (-> self control status) 1) + (!= (-> self control unknown-surface mode) 'swim) + (!= (-> self control unknown-surface mode) 'dive) + (!= (-> self next-state name) 'target-flop) + (zero? (logand (-> self draw status) 38)) + ) + (set! (-> self control shadow-pos quad) (-> self control trans quad)) + (find-ground-and-draw-shadow + (-> self control trans) + (-> self control shadow-pos) + 0.0 + (-> (the-as collide-shape-prim (-> self control root-prim)) collide-with) + self + 0.0 + 81920.0 + ) + ) + 0 + (none) + ) + +;; failed to figure out what this is: +(set! + (-> *part-id-table* 362) + (new 'static 'sparticle-launcher + :init-specs + (new 'static 'inline-array sp-field-init-spec 20 + (new 'static 'sp-field-init-spec :field #x1 :initial-value #x200000) + (new 'static 'sp-field-init-spec + :field #x6 + :flags #x1 + :initial-value #x41000000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #xd + :flags #x1 + :initial-value #x4499999a + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x10 + :flags #x1 + :initial-value -956301312 + :random-range #x47800000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x11 + :flags #x3 + :initial-value -4 + :random-mult 1 + ) + (new 'static 'sp-field-init-spec + :field #x12 + :flags #x1 + :initial-value #x42b40000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x13 + :flags #x1 + :initial-value #x42b40000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x14 + :flags #x1 + :initial-value #x42b40000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x15 + :flags #x1 + :initial-value #x41a00000 + :random-range #x41a00000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x1a + :flags #x1 + :initial-value #x4103126f + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x1c + :flags #x1 + :initial-value #x41888889 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x20 + :flags #x3 + :initial-value -4 + :random-mult 1 + ) + (new 'static 'sp-field-init-spec + :field #x24 + :flags #x1 + :initial-value -1097229926 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x2e + :initial-value #x138c + :random-mult 1 + ) + (new 'static 'sp-field-init-spec + :field #x2f + :initial-value 12 + :random-mult 1 + ) + (new 'static 'sp-field-init-spec + :field #x36 + :flags #x1 + :initial-value -983331271 + :random-range #x452aaaab + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x3a + :flags #x1 + :initial-value #x46800000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x3b + :flags #x1 + :initial-value -956301312 + :random-range #x47800000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x3e + :flags #x1 + :initial-value #x444ccccd + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec :field #x43) + ) + ) + ) diff --git a/goal_src/engine/sparticle/sparticle-h.gc b/goal_src/engine/sparticle/sparticle-h.gc index c3147920e..997d11788 100644 --- a/goal_src/engine/sparticle/sparticle-h.gc +++ b/goal_src/engine/sparticle/sparticle-h.gc @@ -84,3 +84,7 @@ ) (define-extern part-group-pointer? (function pointer symbol)) + +;; TODO - for shadow +(define-extern *part-id-table* (array sparticle-launcher)) +(define-extern *part-group-id-table* (array sparticle-launch-group)) diff --git a/goal_src/engine/sparticle/sparticle-launcher-h.gc b/goal_src/engine/sparticle/sparticle-launcher-h.gc index 9a322de7d..4bf418916 100644 --- a/goal_src/engine/sparticle/sparticle-launcher-h.gc +++ b/goal_src/engine/sparticle/sparticle-launcher-h.gc @@ -6,19 +6,19 @@ ;; dgos: GAME, ENGINE (deftype sp-field-init-spec (structure) - ((field uint16 :offset-assert 0) - (flags uint16 :offset-assert 2) - (initial-valuef float :offset-assert 4) - (random-rangef float :offset-assert 8) - (random-multf float :offset-assert 12) - (initial-value int32 :offset 4) - (random-range int32 :offset 8) - (random-mult int32 :offset 12) - (func basic :offset 4) - (tex uint32 :offset 4) - (pntr uint32 :offset 4) - (sym basic :offset 4) - (sound basic :offset 4) + ((field uint16 :offset-assert 0) + (flags uint16 :offset-assert 2) + (initial-value int32 :offset-assert 4) + (random-range int32 :offset-assert 8) + (random-mult int32 :offset-assert 12) + (initial-valuef float :offset 4) ;; TODO - floats suck - some of these values end up being NaN - these should come before the int32 fields + (random-rangef float :offset 8) ;; TODO - floats suck - some of these values end up being NaN - these should come before the int32 fields + (random-multf float :offset 12) ;; TODO - floats suck - some of these values end up being NaN - these should come before the int32 fields + (func basic :offset 4) + (tex uint32 :offset 4) + (pntr uint32 :offset 4) + (sym basic :offset 4) + (sound basic :offset 4) ) :method-count-assert 9 :size-assert #x10 @@ -28,7 +28,7 @@ (deftype sparticle-launcher (basic) ((birthaccum float :offset-assert 4) (soundaccum float :offset-assert 8) - (init-specs uint32 :offset-assert 12) + (init-specs (inline-array sp-field-init-spec) :offset-assert 12) ) :method-count-assert 9 :size-assert #x10 diff --git a/goal_src/engine/sparticle/sparticle-launcher.gc b/goal_src/engine/sparticle/sparticle-launcher.gc index c8578aaf5..d77fa113e 100644 --- a/goal_src/engine/sparticle/sparticle-launcher.gc +++ b/goal_src/engine/sparticle/sparticle-launcher.gc @@ -5,3 +5,6 @@ ;; name in dgo: sparticle-launcher ;; dgos: GAME, ENGINE +;; TODO - for shadow +(define *part-id-table* (new 'global 'boxed-array sparticle-launcher 3584)) +(define *part-group-id-table* (new 'global 'boxed-array sparticle-launch-group 1024)) diff --git a/test/decompiler/reference/engine/collide/collide-cache-h_REF.gc b/test/decompiler/reference/engine/collide/collide-cache-h_REF.gc index f005b9da3..a698caaed 100644 --- a/test/decompiler/reference/engine/collide/collide-cache-h_REF.gc +++ b/test/decompiler/reference/engine/collide/collide-cache-h_REF.gc @@ -189,15 +189,15 @@ (dummy-9 () none 9) (dummy-10 () none 10) (dummy-11 () none 11) - (dummy-12 () none 12) + (dummy-12 (_type_ vector float uint process bone uint) float 12) (dummy-13 () none 13) (dummy-14 () none 14) (dummy-15 () none 15) - (dummy-16 () none 16) + (dummy-16 (_type_ vector float uint process uint) none 16) (dummy-17 () none 17) (dummy-18 () none 18) (dummy-19 () none 19) - (dummy-20 () none 20) + (dummy-20 (_type_ vector float uint bone uint) none 20) (dummy-21 () none 21) (dummy-22 () none 22) (dummy-23 () none 23) diff --git a/test/decompiler/reference/engine/game/projectiles-h_REF.gc b/test/decompiler/reference/engine/game/projectiles-h_REF.gc index b33ede732..7bd5f5b90 100644 --- a/test/decompiler/reference/engine/game/projectiles-h_REF.gc +++ b/test/decompiler/reference/engine/game/projectiles-h_REF.gc @@ -35,7 +35,7 @@ (projectile-dissipate () none 21) (projectile-impact () none 22) (dummy-23 () none 23) - (dummy-24 () none 24) + (dummy-24 (_type_) none 24) (dummy-25 () none 25) (dummy-26 () none 26) (dummy-27 () none 27) diff --git a/test/decompiler/reference/engine/gfx/shadow/shadow_REF.gc b/test/decompiler/reference/engine/gfx/shadow/shadow_REF.gc new file mode 100644 index 000000000..b9b012c9f --- /dev/null +++ b/test/decompiler/reference/engine/gfx/shadow/shadow_REF.gc @@ -0,0 +1,343 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function add-fake-shadow-to-buffer +;; INFO: Return type mismatch int vs none. +(defun + add-fake-shadow-to-buffer + ((arg0 vector) (arg1 vector) (arg2 float) (arg3 int)) + (let ((v1-0 *fake-shadow-buffer*)) + (when (< (-> v1-0 num-shadows) 32) + (let ((t0-5 (-> v1-0 data (-> v1-0 num-shadows)))) + (set! (-> t0-5 px) (-> arg0 x)) + (set! (-> t0-5 py) (-> arg0 y)) + (set! (-> t0-5 pz) (-> arg0 z)) + (set! (-> t0-5 scale) arg2) + (set! (-> t0-5 qx) (-> arg1 x)) + (set! (-> t0-5 qy) (-> arg1 y)) + (set! (-> t0-5 qz) (-> arg1 z)) + (set! (-> t0-5 flags) arg3) + ) + (+! (-> v1-0 num-shadows) 1) + ) + ) + 0 + (none) + ) + +;; definition for function swap-fake-shadow-buffers +;; INFO: Return type mismatch int vs none. +(defun swap-fake-shadow-buffers () + (set! *fake-shadow-buffer* (if (= *fake-shadow-buffer* *fake-shadow-buffer-1*) + *fake-shadow-buffer-2* + *fake-shadow-buffer-1* + ) + ) + (set! (-> *fake-shadow-buffer* num-shadows) 0) + 0 + (none) + ) + +;; definition for function draw-shadow +;; INFO: Return type mismatch int vs none. +(defun + draw-shadow + ((arg0 vector) + (arg1 vector) + (arg2 vector) + (arg3 float) + (arg4 float) + (arg5 float) + ) + (let ((f0-1 (- (-> arg0 y) (-> arg1 y)))) + (if (< f0-1 arg4) + (add-fake-shadow-to-buffer + arg1 + arg2 + (* (- 1.0 (/ f0-1 arg4)) arg3) + (the-as int arg5) + ) + ) + ) + 0 + (none) + ) + +;; definition for function compute-and-draw-shadow +;; INFO: Return type mismatch int vs none. +;; Used lq/sq +(defun + compute-and-draw-shadow + ((arg0 vector) + (arg1 vector) + (arg2 vector) + (arg3 vector) + (arg4 float) + (arg5 float) + ) + (local-vars + (v1-10 float) + (v1-11 float) + (sv-96 vector) + (sv-112 (function quaternion vector float quaternion)) + (sv-128 vector) + (sv-144 vector) + ) + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (set! sv-96 arg2) + (let ((s4-0 arg3) + (s3-0 arg4) + (s2-0 arg5) + ) + (when (< (- (-> arg0 y) (-> arg1 y)) s3-0) + (set! sv-144 (new 'stack-no-clear 'vector)) + (let ((s0-0 (new 'stack-no-clear 'vector)) + (s1-0 (new 'stack-no-clear 'sparticle-cpuinfo)) + ) + (set! (-> arg1 y) (+ 40.96 (-> arg1 y))) + (set! (-> sv-144 x) (-> sv-96 z)) + (set! (-> sv-144 y) 0.0) + (set! (-> sv-144 z) (- (-> sv-96 x))) + (vector-normalize! sv-144 1.0) + (set! sv-112 quaternion-vector-angle!) + (set! sv-128 s0-0) + (let ((a2-1 (acos (-> sv-96 y)))) + (sv-112 (the-as quaternion sv-128) sv-144 a2-1) + ) + (let ((v1-9 s1-0)) + (cond + ((< (-> s0-0 w) 0.0) + (.lvf vf1 (&-> v1-9 vel-sxvel quad)) + (.lvf vf2 (&-> s0-0 quad)) + (.sub.vf vf1 vf0 vf2 :mask #b111) + (.svf (&-> v1-9 vel-sxvel quad) vf1) + (.mov v1-10 vf1) + ) + (else + (.lvf vf1 (&-> v1-9 vel-sxvel quad)) + (.lvf vf2 (&-> s0-0 quad)) + (.add.vf vf1 vf0 vf2 :mask #b111) + (.svf (&-> v1-9 vel-sxvel quad) vf1) + (.mov v1-11 vf1) + ) + ) + ) + (draw-shadow arg0 arg1 (-> s1-0 vel-sxvel) (the-as float s4-0) s3-0 s2-0) + ) + ) + ) + 0 + (none) + ) + ) + +;; definition for function find-ground-and-draw-shadow +;; INFO: Return type mismatch int vs none. +;; Used lq/sq +(defun + find-ground-and-draw-shadow + ((arg0 vector) + (arg1 vector) + (arg2 float) + (arg3 uint) + (arg4 process) + (arg5 float) + (arg6 float) + ) + (let ((s2-0 (new 'stack-no-clear 'vector))) + (set! (-> s2-0 quad) (-> arg0 quad)) + (new 'stack-no-clear 'vector) + (+! (-> s2-0 y) arg5) + (let ((s4-0 (new 'stack-no-clear 'bone))) + (cond + ((>= + (dummy-12 *collide-cache* s2-0 arg6 arg3 arg4 s4-0 (the-as uint 1)) + 0.0 + ) + (if (!= arg2 0.0) + (compute-and-draw-shadow + s2-0 + (-> s4-0 position) + (-> s4-0 scale) + (the-as vector arg2) + arg6 + (the-as float 0) + ) + ) + (if (and arg1 (!= (shr (shl (-> s4-0 cache bone-matrix) 52) 58) 3)) + (set! (-> arg1 quad) (-> s4-0 position quad)) + ) + ) + (else + (if arg1 + (vector+float*! + arg1 + arg0 + (-> *standard-dynamics* gravity-normal) + (- arg6) + ) + ) + ) + ) + ) + ) + 0 + (none) + ) + +;; definition for function do-target-shadow +;; INFO: Return type mismatch int vs none. +;; Used lq/sq +(defbehavior do-target-shadow target () + (if + (and + (logtest? (-> self control status) 1) + (!= (-> self control unknown-surface mode) 'swim) + (!= (-> self control unknown-surface mode) 'dive) + (!= (-> self next-state name) 'target-flop) + (zero? (logand (-> self draw status) 38)) + ) + (set! (-> self control shadow-pos quad) (-> self control trans quad)) + (find-ground-and-draw-shadow + (-> self control trans) + (-> self control shadow-pos) + 0.0 + (-> (the-as collide-shape-prim (-> self control root-prim)) collide-with) + self + 0.0 + 81920.0 + ) + ) + 0 + (none) + ) + +;; failed to figure out what this is: +(set! + (-> *part-id-table* 362) + (new 'static 'sparticle-launcher + :init-specs + (new 'static 'inline-array sp-field-init-spec 20 + (new 'static 'sp-field-init-spec :field #x1 :initial-value #x200000) + (new 'static 'sp-field-init-spec + :field #x6 + :flags #x1 + :initial-value #x41000000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #xd + :flags #x1 + :initial-value #x4499999a + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x10 + :flags #x1 + :initial-value -956301312 + :random-range #x47800000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x11 + :flags #x3 + :initial-value -4 + :random-mult 1 + ) + (new 'static 'sp-field-init-spec + :field #x12 + :flags #x1 + :initial-value #x42b40000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x13 + :flags #x1 + :initial-value #x42b40000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x14 + :flags #x1 + :initial-value #x42b40000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x15 + :flags #x1 + :initial-value #x41a00000 + :random-range #x41a00000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x1a + :flags #x1 + :initial-value #x4103126f + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x1c + :flags #x1 + :initial-value #x41888889 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x20 + :flags #x3 + :initial-value -4 + :random-mult 1 + ) + (new 'static 'sp-field-init-spec + :field #x24 + :flags #x1 + :initial-value -1097229926 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x2e + :initial-value #x138c + :random-mult 1 + ) + (new 'static 'sp-field-init-spec + :field #x2f + :initial-value 12 + :random-mult 1 + ) + (new 'static 'sp-field-init-spec + :field #x36 + :flags #x1 + :initial-value -983331271 + :random-range #x452aaaab + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x3a + :flags #x1 + :initial-value #x46800000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x3b + :flags #x1 + :initial-value -956301312 + :random-range #x47800000 + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec + :field #x3e + :flags #x1 + :initial-value #x444ccccd + :random-mult #x3f800000 + ) + (new 'static 'sp-field-init-spec :field #x43) + ) + ) + ) + + + + diff --git a/test/decompiler/reference/engine/gfx/sparticle/sparticle-launcher-h_REF.gc b/test/decompiler/reference/engine/gfx/sparticle/sparticle-launcher-h_REF.gc index 75390ea83..c188f40ef 100644 --- a/test/decompiler/reference/engine/gfx/sparticle/sparticle-launcher-h_REF.gc +++ b/test/decompiler/reference/engine/gfx/sparticle/sparticle-launcher-h_REF.gc @@ -5,12 +5,12 @@ (deftype sp-field-init-spec (structure) ((field uint16 :offset-assert 0) (flags uint16 :offset-assert 2) - (initial-valuef float :offset-assert 4) - (random-rangef float :offset-assert 8) - (random-multf float :offset-assert 12) - (initial-value int32 :offset 4) - (random-range int32 :offset 8) - (random-mult int32 :offset 12) + (initial-value int32 :offset-assert 4) + (random-range int32 :offset-assert 8) + (random-mult int32 :offset-assert 12) + (initial-valuef float :offset 4) + (random-rangef float :offset 8) + (random-multf float :offset 12) (func basic :offset 4) (tex uint32 :offset 4) (pntr uint32 :offset 4) @@ -30,9 +30,9 @@ (format #t "~Tinitial-valuef: ~f~%" (-> obj initial-valuef)) (format #t "~Trandom-rangef: ~f~%" (-> obj random-rangef)) (format #t "~Trandom-multf: ~f~%" (-> obj random-multf)) - (format #t "~Tinitial-value: ~D~%" (-> obj initial-valuef)) - (format #t "~Trandom-range: ~D~%" (-> obj random-rangef)) - (format #t "~Trandom-mult: ~D~%" (-> obj random-multf)) + (format #t "~Tinitial-value: ~D~%" (-> obj initial-value)) + (format #t "~Trandom-range: ~D~%" (-> obj random-range)) + (format #t "~Trandom-mult: ~D~%" (-> obj random-mult)) (format #t "~Tfunc: ~A~%" (-> obj initial-valuef)) (format #t "~Ttex: ~D~%" (-> obj initial-valuef)) (format #t "~Tpntr: #x~X~%" (-> obj initial-valuef)) @@ -43,9 +43,9 @@ ;; definition of type sparticle-launcher (deftype sparticle-launcher (basic) - ((birthaccum float :offset-assert 4) - (soundaccum float :offset-assert 8) - (init-specs uint32 :offset-assert 12) + ((birthaccum float :offset-assert 4) + (soundaccum float :offset-assert 8) + (init-specs (inline-array sp-field-init-spec) :offset-assert 12) ) :method-count-assert 9 :size-assert #x10