From e0a15d59908d3d9420976f7b33faf349a452e146 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 7 Jun 2021 21:26:21 +0100 Subject: [PATCH] [decomp] yet even more `res` (#565) --- decompiler/config/all-types.gc | 10 +-- .../stack_structures.jsonc | 5 -- .../jak1_ntsc_black_label/type_casts.jsonc | 7 ++ goal_src/engine/data/res-h.gc | 6 +- goal_src/engine/data/res.gc | 79 ++++++++++++++----- goal_src/engine/geometry/geometry-h.gc | 4 +- .../reference/engine/data/res-h_REF.gc | 2 +- 7 files changed, 77 insertions(+), 36 deletions(-) diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 94ed8a6360..f8aa873335 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -8917,7 +8917,7 @@ ((name symbol :offset 0) (key-frame float :offset 32) (elt-type type :offset 64) - (data-offset uint16 :offset 96) ;; guess. (data-offset is 16-bit in Crash) + (data-offset uint16 :offset 96) (elt-count uint32 :offset 112 :size 15) (inlined? uint8 :offset 127 :size 1) ;; guess. ) @@ -8949,15 +8949,15 @@ (sort! (_type_) _type_ 16) (dummy-17 (_type_ res-tag pointer) res-lump 17) (dummy-18 (_type_ res-tag res-tag) res-lump 18) - (lookup-tag-idx (_type_ symbol symbol float) res-tag-pair 19) + (lookup-tag-idx (_type_ symbol symbol float) res-tag-pair :no-virtual 19) (make-property-data (_type_ float res-tag-pair pointer) pointer 20) - (dummy-21 (_type_ pointer symbol symbol float) symbol 21) + (get-curve-data! (_type_ curve symbol symbol float) symbol 21) ) ) ;; - Symbols -(define-extern *res-key-string* string) ;; unknown type +(define-extern *res-key-string* string) ;; ---------------------- @@ -8968,7 +8968,7 @@ ;; - Symbols -(define-extern *res-static-buf* pointer) ;; unknown type +(define-extern *res-static-buf* pointer) (define-extern uinteger type) (define-extern part-group-pointer? function) diff --git a/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc b/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc index 24d10fd3dd..d46b9bf497 100644 --- a/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc @@ -166,11 +166,6 @@ "draw-sprite2d-xy": [[16, "draw-context"]], "screen-gradient": [[16, "draw-context"]], - //"(method 18 res-lump)": [[16, "res-tag"]], - //"(method 21 res-lump)": [[16, "res-tag"], [32, "res-tag"]], - - //"(method 0 fact-info)": [[16, "res-tag"]], - "(method 10 oscillating-vector)": [[16, "vector"]], "show-mc-info": [[16, "mc-slot-info"]], diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index a0957f873c..d5d8c651ce 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -391,6 +391,13 @@ [22, "t1", "(pointer uint64)"], [29, "t2", "(pointer uint64)"] ], + "(method 18 res-lump)": [ + ["_stack_", 16, "res-tag"] + ], + "(method 21 res-lump)": [ + ["_stack_", 16, "res-tag"], + ["_stack_", 32, "res-tag"] + ], // SHADOW-CPU-H "(method 10 shadow-control)": [[1, "v1", "int"]], diff --git a/goal_src/engine/data/res-h.gc b/goal_src/engine/data/res-h.gc index f601b97209..4723220eb9 100644 --- a/goal_src/engine/data/res-h.gc +++ b/goal_src/engine/data/res-h.gc @@ -11,7 +11,7 @@ ((name symbol :offset 0) (key-frame float :offset 32) (elt-type type :offset 64) - (data-offset uint16 :offset 96) ;; guess. (data-offset is 16-bit in Crash) + (data-offset uint16 :offset 96) ;; guess (elt-count uint32 :offset 112 :size 15) (inlined? uint8 :offset 127 :size 1) ;; guess. ) @@ -51,9 +51,9 @@ (sort! (_type_) _type_ 16) (dummy-17 (_type_ res-tag pointer) res-lump 17) (dummy-18 (_type_ res-tag res-tag) res-lump 18) - (lookup-tag-idx (_type_ symbol symbol float) res-tag-pair 19) + (lookup-tag-idx (_type_ symbol symbol float) res-tag-pair :no-virtual 19) (make-property-data (_type_ float res-tag-pair pointer) pointer 20) - (dummy-21 (_type_ pointer symbol symbol float) symbol 21) + (get-curve-data! (_type_ curve symbol symbol float) symbol 21) ) ) diff --git a/goal_src/engine/data/res.gc b/goal_src/engine/data/res.gc index 39d3bf08ac..ef9a0ef334 100644 --- a/goal_src/engine/data/res.gc +++ b/goal_src/engine/data/res.gc @@ -7,25 +7,30 @@ ;; TODO! Needs a lot of 128-bit type support for res-tag -;; res is a generic storage system for values, used for the game entities. -;; The types of values it can store as follows: int8, int16, int32, int64, uint8, uint16, uint32, uint64, float, vector -;; The data itself can also be sorted as a single value or an array. -;; -;; A res-lump stores and is used to access all of the data for a single "resource". -;; This is similar to a C++ map or C# dictionary. The key is a res-tag and the value is the corresponding binary data. -;; -;; A res-tag is a tag that contains information about a particular property of this resource. -;; For example, information about an array of vectors that make up a path - for a moving platform - or an integer to store its entity ID. -;; -;; Keyframes are used to specify when/where the data is relevant. -;; For example (this is made-up), say you have a camera spline, and you want the FOV to change at three specific points: -;; when it starts, somewhere in the middle, and at the end. -;; You would store an array of three FOV values. The key-frame field could then be used to say at which point in the spline -;; the FOV should be at that value. If the camera is somewhere between those points, the result could then be interpolated. -;; -;; Properties are looked up from a res-lump using their name, stored as a symbol. This can return an index to a tag. -;; -;; This is updated from the entity system used in Crash 2, which had most of these features and worked very similarly! +#| +res is a generic storage system for not very large data, used mostly for the game entities. +These res files store collections of data, which can be as values (int8, int16, int32, int64, uint8, uint16, uint32, uint64, float, vector), or any structure (as references), which are tagged and identified with a res-tag. +The data is stored similar to an unboxed inline-array, the type of the data is stored in the res-tag. + +A res-lump stores and is used to access all of the data for a single "resource", a collection of varying data. +This is similar to a C++ map or C# dictionary. The key is a res-tag and the value is the corresponding binary data. + +A res-tag is a tag that contains information about a particular property of this resource, such as type, name, and amount of elements. +For example, information about an array of vectors that make up a path - for a moving platform - or an integer to store its entity ID. + +Keyframes are used to specify when/where the data is relevant. +For example (this is made-up), say you have a camera spline, and you want the FOV to change at three specific points: +when it starts, somewhere in the middle, and at the end. +You would store an array of three FOV values. The key-frame field could then be used to say at which point in the spline +the FOV should be at that value. If the camera is somewhere between those points, the result could then be interpolated. + +Properties are looked up from a res-lump using their name (a symbol). +You can look up the data of the property you want directly using the various get-property methods. +Curves can be quickly filled in using the get-curve-data! method. + + +This is updated from the entity system used in Crash 2, which had most of these features and worked very similarly! +|# (defmacro res-ref? (tag) "Checks resource tag, and returns #t if resource data is a reference type, #f if it is inlined." @@ -656,10 +661,44 @@ obj ) +(defmethod get-curve-data! res-lump ((obj res-lump) (curve-target curve) (points-name symbol) (knots-name symbol) (time float)) + "Read curve data and write it to curve-target. Return #t if both control points and knots data was succesfully read, #f otherwise." + + (let ((result #f)) + ;; there's some macro here + (let* ((points-tag (new 'static 'res-tag)) + (curve-data (get-property-data obj points-name 'exact time (the pointer #f) (& points-tag) *res-static-buf*))) + + (when curve-data + (set! (-> curve-target cverts) (the uint curve-data)) + (set! (-> curve-target num-cverts) (the int (-> points-tag elt-count))) + + (when (< MAX_CURVE_CONTROL_POINTS (-> curve-target num-cverts)) + (format 0 "ERROR: curve has ~D control points--only ~D are allowed. Increase MAX-CURVE-CONTROL-POINTS or shorten the curve.~%" + (-> curve-target num-cverts) + MAX_CURVE_CONTROL_POINTS + ) + (set! (-> curve-target num-cverts) MAX_CURVE_CONTROL_POINTS) + ) + + (let ((knots-tag (new 'static 'res-tag))) + (set! curve-data (get-property-data obj knots-name 'exact time (the pointer #f) (& knots-tag) *res-static-buf*)) + + (when curve-data + (set! (-> curve-target knots) (the uint curve-data)) + (set! (-> curve-target num-knots) (the int (-> knots-tag elt-count))) + (set! result #t) + ) + ) + ) + ) + result + ) + ) + ;; method 15 res-lump ;; method 17 res-lump ;; method 18 res-lump -;; method 21 res-lump ;; mem-usage res-lump diff --git a/goal_src/engine/geometry/geometry-h.gc b/goal_src/engine/geometry/geometry-h.gc index 9e7ad2eb6a..87e9844256 100644 --- a/goal_src/engine/geometry/geometry-h.gc +++ b/goal_src/engine/geometry/geometry-h.gc @@ -5,7 +5,8 @@ ;; name in dgo: geometry-h ;; dgos: GAME, ENGINE -;; geometry-h +(defconstant MAX_CURVE_CONTROL_POINTS 256) + (deftype curve (structure) ((cverts uint32 :offset-assert 0) (num-cverts int32 :offset-assert 4) @@ -18,7 +19,6 @@ :flag-assert #x900000014 ) -;; geometry-h (deftype border-plane (basic) ((name basic :offset-assert 4) (action basic :offset-assert 8) diff --git a/test/decompiler/reference/engine/data/res-h_REF.gc b/test/decompiler/reference/engine/data/res-h_REF.gc index 851886e39e..7999dc3e92 100644 --- a/test/decompiler/reference/engine/data/res-h_REF.gc +++ b/test/decompiler/reference/engine/data/res-h_REF.gc @@ -42,7 +42,7 @@ (dummy-18 (_type_ res-tag res-tag) res-lump 18) (lookup-tag-idx (_type_ symbol symbol float) res-tag-pair 19) (make-property-data (_type_ float res-tag-pair pointer) pointer 20) - (dummy-21 (_type_ pointer symbol symbol float) symbol 21) + (get-curve-data! (_type_ curve symbol symbol float) symbol 21) ) )