;;-*-Lisp-*-
(in-package goal)

;; name: game-save.gc
;; name in dgo: game-save
;; dgos: GAME

;; +++game-save-elt
(defenum game-save-elt
  :type uint16
  (name 100)
  (base-time 101)
  (real-time 102)
  (game-time 103)
  (frame-time 104)
  (real-frame-time 105)
  (session-time 106)
  (bg-time 107)
  (total-game-time 108)

  (continue 200)
  (life 201)
  (money 202)
  (money-total 203)
  (money-per-level 204)
  (buzzer-total 205)
  (fuel-cell 206)
  (death-movie-tick 207)
  (skill 208)
  (skill-total 209)
  (karma 210)
  (eco-pill-dark 211)
  (eco-pill-dark-total 212)
  (shield 213)
  (features 214)
  (gun-type 215)
  (gun-ammo 216)
  (gem 218)
  (gem-total 219)
  (secrets 220)
  (scores 221)
  (purchase-secrets 222)
  (eco-pill-light 223)
  (eco-pill-light-total 224)
  (vehicles 225)
  (vehicle 226)
  (resetter-node 227)
  (items 228)
  (skill-high-watermark 229)

  (task-list 300)
  (perm-list 301)
  (level-open-list 305)
  (task-node-list 306)
  (talker-state 307)
  (bigmap-data 308)
  (bigmap-offsets 309)

  (total-deaths 400)
  (continue-deaths 401)
  (task-deaths 402)
  (game-start-time 403)
  (death-time 405)
  (hit-time 406)
  (task-pickup-time 407)
  (continue-time 408)
  (task-complete-time 409)
  (enter-level-time 410)
  (deaths-per-level 411)
  (death-pos 412)
  (auto-save-count 413)
  (in-level-time 414)
  (task-start-time 415)
  (node-death-count 416)
  (node-gem-count 417)
  (node-skill-count 418)
  (node-close-time 419)
  (node-name 420)
  (total-trys 421)
  (enemies-killed 422)
  (civilians-killed 423)
  (marauders-killed 424)
  (shot-info 425)
  (crates-opened 426)
  (health-collected 427)
  (board-time 428)

  (sfx-volume 500)
  (music-volume 501)
  (dialog-volume 502)
  (language 503)
  (screenx 504)
  (screeny 505)
  (vibration 506)
  (play-hints 507)
  (video-mode 508)
  (aspect-ratio 509)
  (camera-stick-dir 510)
  (subtitle 511)
  (subtitle-language 512)
  (stereo-mode 513)
  (audio-language 516)
  (brightness 514)
  (contrast 515)
  (flip-horizontal 517)
  (flip-vertical 518)

  (disk-tester 600)
  )
;; ---game-save-elt


;; DECOMP BEGINS

(defun-debug game-save-elt->string ((arg0 game-save-elt))
  (case arg0
    (((game-save-elt video-mode))
     "video-mode"
     )
    (((game-save-elt game-start-time))
     "game-start-time"
     )
    (((game-save-elt total-deaths))
     "total-deaths"
     )
    (((game-save-elt total-game-time))
     "total-game-time"
     )
    (((game-save-elt aspect-ratio))
     "aspect-ratio"
     )
    (((game-save-elt crates-opened))
     "crates-opened"
     )
    (((game-save-elt audio-language))
     "audio-language"
     )
    (((game-save-elt contrast))
     "contrast"
     )
    (((game-save-elt karma))
     "karma"
     )
    (((game-save-elt task-list))
     "task-list"
     )
    (((game-save-elt music-volume))
     "music-volume"
     )
    (((game-save-elt brightness))
     "brightness"
     )
    (((game-save-elt screeny))
     "screeny"
     )
    (((game-save-elt node-close-time))
     "node-close-time"
     )
    (((game-save-elt continue-deaths))
     "continue-deaths"
     )
    (((game-save-elt language))
     "language"
     )
    (((game-save-elt money))
     "money"
     )
    (((game-save-elt real-frame-time))
     "real-frame-time"
     )
    (((game-save-elt task-complete-time))
     "task-complete-time"
     )
    (((game-save-elt base-time))
     "base-time"
     )
    (((game-save-elt in-level-time))
     "in-level-time"
     )
    (((game-save-elt death-pos))
     "death-pos"
     )
    (((game-save-elt flip-horizontal))
     "flip-horizontal"
     )
    (((game-save-elt shot-info))
     "shot-info"
     )
    (((game-save-elt frame-time))
     "frame-time"
     )
    (((game-save-elt death-movie-tick))
     "death-movie-tick"
     )
    (((game-save-elt features))
     "features"
     )
    (((game-save-elt items))
     "items"
     )
    (((game-save-elt enemies-killed))
     "enemies-killed"
     )
    (((game-save-elt gem-total))
     "gem-total"
     )
    (((game-save-elt bigmap-offsets))
     "bigmap-offsets"
     )
    (((game-save-elt death-time))
     "death-time"
     )
    (((game-save-elt secrets))
     "secrets"
     )
    (((game-save-elt play-hints))
     "play-hints"
     )
    (((game-save-elt camera-stick-dir))
     "camera-stick-dir"
     )
    (((game-save-elt task-start-time))
     "task-start-time"
     )
    (((game-save-elt board-time))
     "board-time"
     )
    (((game-save-elt money-total))
     "money-total"
     )
    (((game-save-elt sfx-volume))
     "sfx-volume"
     )
    (((game-save-elt task-pickup-time))
     "task-pickup-time"
     )
    (((game-save-elt node-gem-count))
     "node-gem-count"
     )
    (((game-save-elt subtitle-language))
     "subtitle-language"
     )
    (((game-save-elt task-node-list))
     "task-node-list"
     )
    (((game-save-elt continue-time))
     "continue-time"
     )
    (((game-save-elt eco-pill-dark))
     "eco-pill-dark"
     )
    (((game-save-elt health-collected))
     "health-collected"
     )
    (((game-save-elt life))
     "life"
     )
    (((game-save-elt skill-high-watermark))
     "skill-high-watermark"
     )
    (((game-save-elt vehicle))
     "vehicle"
     )
    (((game-save-elt skill))
     "skill"
     )
    (((game-save-elt node-skill-count))
     "node-skill-count"
     )
    (((game-save-elt shield))
     "shield"
     )
    (((game-save-elt scores))
     "scores"
     )
    (((game-save-elt marauders-killed))
     "marauders-killed"
     )
    (((game-save-elt gun-type))
     "gun-type"
     )
    (((game-save-elt node-death-count))
     "node-death-count"
     )
    (((game-save-elt perm-list))
     "perm-list"
     )
    (((game-save-elt skill-total))
     "skill-total"
     )
    (((game-save-elt node-name))
     "node-name"
     )
    (((game-save-elt eco-pill-light-total))
     "eco-pill-light-total"
     )
    (((game-save-elt level-open-list))
     "level-open-list"
     )
    (((game-save-elt subtitle))
     "subtitle"
     )
    (((game-save-elt eco-pill-dark-total))
     "eco-pill-dark-total"
     )
    (((game-save-elt enter-level-time))
     "enter-level-time"
     )
    (((game-save-elt gem))
     "gem"
     )
    (((game-save-elt bigmap-data))
     "bigmap-data"
     )
    (((game-save-elt session-time))
     "session-time"
     )
    (((game-save-elt bg-time))
     "bg-time"
     )
    (((game-save-elt fuel-cell))
     "fuel-cell"
     )
    (((game-save-elt real-time))
     "real-time"
     )
    (((game-save-elt disk-tester))
     "disk-tester"
     )
    (((game-save-elt eco-pill-light))
     "eco-pill-light"
     )
    (((game-save-elt vibration))
     "vibration"
     )
    (((game-save-elt gun-ammo))
     "gun-ammo"
     )
    (((game-save-elt stereo-mode))
     "stereo-mode"
     )
    (((game-save-elt buzzer-total))
     "buzzer-total"
     )
    (((game-save-elt name))
     "name"
     )
    (((game-save-elt game-time))
     "game-time"
     )
    (((game-save-elt continue))
     "continue"
     )
    (((game-save-elt deaths-per-level))
     "deaths-per-level"
     )
    (((game-save-elt purchase-secrets))
     "purchase-secrets"
     )
    (((game-save-elt vehicles))
     "vehicles"
     )
    (((game-save-elt resetter-node))
     "resetter-node"
     )
    (((game-save-elt task-deaths))
     "task-deaths"
     )
    (((game-save-elt flip-vertical))
     "flip-vertical"
     )
    (((game-save-elt auto-save-count))
     "auto-save-count"
     )
    (((game-save-elt civilians-killed))
     "civilians-killed"
     )
    (((game-save-elt total-trys))
     "total-trys"
     )
    (((game-save-elt talker-state))
     "talker-state"
     )
    (((game-save-elt money-per-level))
     "money-per-level"
     )
    (((game-save-elt dialog-volume))
     "dialog-volume"
     )
    (((game-save-elt screenx))
     "screenx"
     )
    (((game-save-elt hit-time))
     "hit-time"
     )
    (else
      "*unknown*"
      )
    )
  )

(deftype game-save-tag (structure)
  ((user-object  object  2)
   (user-uint64  uint64    :overlay-at (-> user-object 0))
   (user-float0  float     :overlay-at (-> user-object 0))
   (user-float   float   2 :overlay-at (-> user-object 0))
   (user-int32   int32   2 :overlay-at (-> user-object 0))
   (user-uint32  uint32  2 :overlay-at (-> user-object 0))
   (user-int16   int16   4 :overlay-at (-> user-object 0))
   (user-uint16  uint16  4 :overlay-at (-> user-object 0))
   (user-int8    int8    8 :overlay-at (-> user-object 0))
   (user-int80   int8      :overlay-at (-> user-object 0))
   (user-int81   int8      :overlay-at (-> user-int8 1))
   (user-uint8   uint8   8 :overlay-at (-> user-object 0))
   (elt-count    int32)
   (elt-size     uint16)
   (elt-type     game-save-elt)
   )
  )


(deftype game-save (basic)
  ((version                int32)
   (allocated-length       int32)
   (length                 int32)
   (info-int32             int32          16)
   (info-int8              int8           64 :overlay-at (-> info-int32 0))
   (level-index            int32             :overlay-at (-> info-int32 0))
   (gem-count              float             :overlay-at (-> info-int32 1))
   (skill-count            float             :overlay-at (-> info-int32 2))
   (completion-percentage  float             :overlay-at (-> info-int32 3))
   (minute                 uint8             :overlay-at (-> info-int32 5))
   (hour                   uint8             :overlay-at (-> info-int8 21))
   (week                   uint8             :overlay-at (-> info-int8 22))
   (day                    uint8             :overlay-at (-> info-int8 23))
   (month                  uint8             :overlay-at (-> info-int32 6))
   (year                   uint8             :overlay-at (-> info-int8 25))
   (language               language-enum     :overlay-at (-> info-int8 26))
   (new-game               int32             :overlay-at (-> info-int32 7))
   (game-time              time-frame        :overlay-at (-> info-int32 8))
   (secrets                uint32         2  :overlay-at (-> info-int32 10))
   (purchase-secrets       uint32         2  :overlay-at (-> info-int32 12))
   (features               uint32         2  :overlay-at (-> info-int32 14))
   (tag                    game-save-tag  :inline :dynamic)
   )
  (:methods
    (new (symbol type int) _type_)
    (save-to-file (_type_ string) _type_)
    (load-from-file (_type_ string) _type_)
    (debug-inspect (_type_ symbol) _type_)
    )
  )


;; WARN: Return type mismatch uint vs int.
(defmethod asize-of ((this game-save))
  (the-as int (+ (-> game-save size) (-> this allocated-length)))
  )

(defmethod new game-save ((allocation symbol) (type-to-make type) (arg0 int))
  (let ((v0-0 (object-new allocation type-to-make (the-as int (+ (-> type-to-make size) arg0)))))
    (set! (-> v0-0 version) 4)
    (set! (-> v0-0 allocated-length) arg0)
    v0-0
    )
  )

(defmethod debug-inspect ((this game-save) (arg0 symbol))
  (local-vars (sv-16 int) (sv-32 string) (sv-48 string))
  (format #t "[~8x] ~A~%" this (-> this type))
  (format #t "~Tversion: ~D~%" (-> this version))
  (format #t "~Tallocated-length: ~D~%" (-> this allocated-length))
  (format #t "~Tlength: ~D~%" (-> this length))
  (format #t "~Tlevel-index: ~D~%" (-> this level-index))
  (format #t "~Tgem-count: ~f~%" (-> this gem-count))
  (format #t "~Tskill-count: ~f~%" (-> this skill-count))
  (format #t "~Tcompletion-percentage: ~f~%" (-> this completion-percentage))
  (format
    #t
    "~Tsave-time: ~x:~x ~x/~x/~x~%"
    (-> this hour)
    (-> this minute)
    (-> this day)
    (-> this month)
    (-> this year)
    )
  (format #t "~Tgame-time: ~E~%" (-> this game-time))
  (format #t "~Tsecrets: #x~x #x~x~%" (-> this purchase-secrets 0) (-> this purchase-secrets 1))
  (format #t "~Tfeatures: #x~x #x~x~%" (-> this features 0) (-> this features 1))
  (format #t "~Ttag[]: @ #x~X~%" (-> this tag))
  (let ((s4-0 (the-as object (-> this tag)))
        (s3-0 0)
        )
    (while (< (the-as int s4-0) (the-as int (&-> this tag 0 user-int8 (-> this length))))
      (let ((s2-0 format)
            (s1-0 #t)
            (s0-0 "~T  [~3D] ~-32S [~3D/~3D]  ~12D ~8f    ")
            )
        (set! sv-16 s3-0)
        (let ((a3-4 (game-save-elt->string (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-type)))
              (t0-1 (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-count))
              (t1-1 (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-size))
              (t2-1 (-> (the-as (inline-array game-save-tag) s4-0) 0 user-uint64))
              (t3-0 (-> (the-as (inline-array game-save-tag) s4-0) 0 user-float0))
              )
          (s2-0 s1-0 s0-0 sv-16 a3-4 t0-1 t1-1 t2-1 t3-0)
          )
        )
      (let ((v1-0 (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-type)))
        (if (or (= v1-0 (game-save-elt name)) (= v1-0 (game-save-elt continue)))
            (format #t "= \"~G\"~%" (-> (the-as (inline-array game-save-tag) s4-0) 1))
            (format #t "~%")
            )
        )
      (when arg0
        (case (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-type)
          (((game-save-elt node-death-count) (game-save-elt node-skill-count) (game-save-elt node-gem-count))
           (dotimes (s2-1 (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-count))
             (let ((s1-1 format)
                   (s0-1 #t)
                   )
               (set! sv-32 "                 ~-32S: ~D~%")
               (let ((a2-15 (game-task-node->string (the-as game-task-node s2-1)))
                     (a3-5 (-> (the-as (inline-array game-save-tag) s4-0) 1 user-uint16 s2-1))
                     )
                 (s1-1 s0-1 sv-32 a2-15 a3-5)
                 )
               )
             )
           )
          (((game-save-elt node-close-time))
           (dotimes (s2-2 (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-count))
             (let ((s1-2 format)
                   (s0-2 #t)
                   )
               (set! sv-48 "                 ~-32S: ~D~%")
               (let ((a2-16 (game-task-node->string (the-as game-task-node s2-2)))
                     (a3-6
                       (-> (the-as (pointer uint64) (+ (the-as uint (-> (the-as (inline-array game-save-tag) s4-0) 1)) (* s2-2 8))))
                       )
                     )
                 (s1-2 s0-2 sv-48 a2-16 a3-6)
                 )
               )
             )
           )
          (((game-save-elt enter-level-time))
           (dotimes (s2-3 (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-count))
             (when (< s2-3 (-> *task-level* length))
               (let ((a2-17 (task-level->string s2-3)))
                 (if a2-17
                     (format
                       #t
                       "                 ~-32S: ~D~%"
                       a2-17
                       (-> (the-as (pointer uint64) (+ (the-as uint (-> (the-as (inline-array game-save-tag) s4-0) 1)) (* s2-3 8))))
                       )
                     )
                 )
               )
             )
           )
          (((game-save-elt in-level-time))
           (dotimes (s2-4 (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-count))
             (when (< s2-4 (-> *task-level* length))
               (let ((a2-18 (task-level->string s2-4)))
                 (if a2-18
                     (format
                       #t
                       "                 ~-32S: ~D~%"
                       a2-18
                       (-> (the-as (pointer uint64) (+ (the-as uint (-> (the-as (inline-array game-save-tag) s4-0) 1)) (* s2-4 8))))
                       )
                     )
                 )
               )
             )
           )
          (((game-save-elt task-complete-time) (game-save-elt task-start-time))
           (dotimes (s2-5 (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-count))
             (let ((a2-19 (game-task->string (the-as game-task s2-5))))
               (if a2-19
                   (format
                     #t
                     "                 ~-32S: ~D~%"
                     a2-19
                     (-> (the-as (pointer uint64) (+ (the-as uint (-> (the-as (inline-array game-save-tag) s4-0) 1)) (* s2-5 8))))
                     )
                   )
               )
             )
           )
          (((game-save-elt disk-tester))
           0
           )
          )
        )
      (set! s4-0 (&+
                   (the-as pointer s4-0)
                   (logand -16 (+ (* (the-as int (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-size))
                                     (-> (the-as (inline-array game-save-tag) s4-0) 0 elt-count)
                                     )
                                  31
                                  )
                           )
                   )
            )
      (+! s3-0 1)
      )
    )
  this
  )


(defmethod save-game ((this game-info) (save game-save) (name string))
  (with-pp
    (dotimes (s4-0 (-> *level* length))
      (let ((a1-1 (-> *level* level s4-0)))
        (if (= (-> a1-1 status) 'active)
            (copy-perms-from-level! this a1-1)
            )
        )
      )
    (set! (-> save length) 0)
    (set! (-> save version) 4)
    (let ((s3-0 (get-continue-by-name this (-> this current-continue name)))
          (s4-1 0)
          )
      (when (not s3-0)
        (format
          0
          "ERROR: SAVE: attempting to save continue ~A which is not in level-info~%"
          (-> this current-continue name)
          )
        (set! s3-0 (get-continue-by-name this "title-start"))
        )
      (let ((v1-19 (-> *task-manager-engine* alive-list next0)))
        *task-manager-engine*
        (let ((s1-0 (-> v1-19 next0)))
          (while (!= v1-19 (-> *task-manager-engine* alive-list-end))
            (let ((a1-5 (new 'stack-no-clear 'event-message-block)))
              (set! (-> a1-5 from) (process->ppointer pp))
              (set! (-> a1-5 num-params) 0)
              (set! (-> a1-5 message) 'fail-continue)
              (let ((s0-0
                      (the-as resetter-spec (send-event-function (the-as process-tree (-> (the-as connection v1-19) param1)) a1-5))
                      )
                    )
                (when s0-0
                  (let ((v1-22 (get-continue-by-name this (-> s0-0 continue))))
                    (if v1-22
                        (set! s3-0 v1-22)
                        )
                    )
                  (if (nonzero? (-> s0-0 node))
                      (set! s4-1 (the-as int (-> s0-0 node)))
                      )
                  )
                )
              )
            (set! v1-19 s1-0)
            *task-manager-engine*
            (set! s1-0 (-> s1-0 next0))
            )
          )
        )
      (set! (-> save level-index) (the-as int (-> (lookup-level-info (-> s3-0 level)) task-level)))
      (set! (-> save gem-count) (-> this gem))
      (set! (-> save skill-count) (-> this skill))
      (set! (-> save language) (-> *setting-control* user-default language))
      (set! (-> save completion-percentage) (calculate-percentage this))
      (set! (-> save game-time) (+ -300000 (-> *display* total-game-clock frame-counter)))
      (set! (-> save info-int32 12) (the-as int (logand (game-secrets
                                                          hero-mode
                                                          scene-player-1
                                                          scene-player-2
                                                          scene-player-3
                                                          title-commentary
                                                          level-select-1
                                                          level-select-2
                                                          level-select-3
                                                          scrap-book-1
                                                          scrap-book-2
                                                          scrap-book-3
                                                          model-viewer-1
                                                          model-viewer-2
                                                          model-viewer-3
                                                          toggle-beard
                                                          hflip-screen
                                                          endless-ammo
                                                          invulnerable
                                                          endless-dark
                                                          endless-light
                                                          gs20
                                                          gs21
                                                          gungame-ratchet
                                                          big-head
                                                          little-head
                                                          fast-movie
                                                          slow-movie
                                                          unlimited-turbos
                                                          vehicle-hit-points
                                                          board-fast
                                                          vehicle-fox
                                                          vehicle-mirage
                                                          )
                                                        (-> this secrets)
                                                        )
                                            )
            )
      (set! (-> save info-int32 13) (the-as int (shr (the-as int (-> this secrets)) 32)))
      (set! (-> save info-int32 10) (the-as int (logand (game-secrets
                                                          hero-mode
                                                          scene-player-1
                                                          scene-player-2
                                                          scene-player-3
                                                          title-commentary
                                                          level-select-1
                                                          level-select-2
                                                          level-select-3
                                                          scrap-book-1
                                                          scrap-book-2
                                                          scrap-book-3
                                                          model-viewer-1
                                                          model-viewer-2
                                                          model-viewer-3
                                                          toggle-beard
                                                          hflip-screen
                                                          endless-ammo
                                                          invulnerable
                                                          endless-dark
                                                          endless-light
                                                          gs20
                                                          gs21
                                                          gungame-ratchet
                                                          big-head
                                                          little-head
                                                          fast-movie
                                                          slow-movie
                                                          unlimited-turbos
                                                          vehicle-hit-points
                                                          board-fast
                                                          vehicle-fox
                                                          vehicle-mirage
                                                          )
                                                        (-> this purchase-secrets)
                                                        )
                                            )
            )
      (set! (-> save info-int32 11) (the-as int (shr (the-as int (-> this purchase-secrets)) 32)))
      (set! (-> save info-int32 14) (the-as int (logand (game-feature
                                                          feature0
                                                          feature1
                                                          feature2
                                                          feature3
                                                          feature4
                                                          gun
                                                          gun-red-1
                                                          gun-red-2
                                                          gun-red-3
                                                          gun-yellow-1
                                                          gun-yellow-2
                                                          gun-yellow-3
                                                          gun-blue-1
                                                          gun-blue-2
                                                          gun-blue-3
                                                          gun-dark-1
                                                          gun-dark-2
                                                          gun-dark-3
                                                          board
                                                          feature19
                                                          sidekick
                                                          feature21
                                                          feature22
                                                          gun-upgrade-yellow-ammo-1
                                                          gun-upgrade-yellow-ammo-2
                                                          gun-upgrade-red-ammo-1
                                                          gun-upgrade-red-ammo-2
                                                          gun-upgrade-blue-ammo-1
                                                          gun-upgrade-blue-ammo-2
                                                          gun-upgrade-dark-ammo-1
                                                          gun-upgrade-dark-ammo-2
                                                          feature31
                                                          )
                                                        (-> this features)
                                                        )
                                            )
            )
      (set! (-> save info-int32 15) (the-as int (shr (the-as int (-> this features)) 32)))
      (cond
        ((string= (-> s3-0 name) "title-start")
         (set! (-> save new-game) 1)
         (set! (-> save level-index) 0)
         (set! (-> save gem-count) 0.0)
         (set! (-> save skill-count) 0.0)
         (set! (-> save completion-percentage) 0.0)
         (set! (-> save game-time) 0)
         (set! (-> save info-int32 14) 0)
         (set! (-> save info-int32 15) 0)
         (set! (-> save info-int32 12) 0)
         (set! (-> save info-int32 13) 0)
         (set! (-> save info-int32 10) 0)
         (set! (-> save info-int32 11) 0)
         (when (or (logtest? (-> *game-info* secrets) (game-secrets hero-mode)) (-> *progress-work* hero-mode-save))
           (set! (-> save new-game) 2)
           (set! (-> save info-int32 12) 1)
           (set! (-> save info-int32 10) 1)
           )
         )
        ((-> *progress-work* hero-mode-save)
         (set! (-> save new-game) 2)
         (set! (-> save level-index) 0)
         (set! (-> save completion-percentage) 0.0)
         (set! (-> save game-time) 0)
         (set! (-> save info-int32 14) 0)
         (set! (-> save info-int32 15) 0)
         (set! (-> save info-int32 12) (the-as int (logior (-> save purchase-secrets 0) 1)))
         (set! (-> save info-int32 10) (the-as int (logior (-> save secrets 0) 1)))
         )
        )
      (let ((s1-1 (new 'stack 'scf-time)))
        (scf-get-time s1-1)
        (when (zero? (-> s1-1 stat))
          (set! (-> save minute) (-> s1-1 minute))
          (set! (-> save hour) (-> s1-1 hour))
          (set! (-> save day) (-> s1-1 day))
          (set! (-> save week) (-> s1-1 week))
          (set! (-> save month) (-> s1-1 month))
          (set! (-> save year) (-> s1-1 year))
          )
        )
      (let ((s1-2 (the-as object (-> save tag))))
        (let ((s0-1 (-> (the-as (inline-array game-save-tag) s1-2) 0)))
          (set! (-> s0-1 elt-type) (game-save-elt name))
          (set! (-> s0-1 elt-count) (+ (length name) 1))
          (set! (-> s0-1 elt-size) (the-as uint 1))
          )
        (copy-charp<-charp (-> (the-as (inline-array game-save-tag) s1-2) 1 user-uint8) (-> name data))
        (let ((v1-85
                (+ (the-as int s1-2) (logand -16 (+ (-> (the-as (inline-array game-save-tag) s1-2) 0 elt-count) 15)) 16)
                )
              )
          (let ((a0-34 (the-as (inline-array game-save-tag) (+ v1-85 0))))
            (set! (-> a0-34 0 elt-type) (game-save-elt base-time))
            (set! (-> a0-34 0 elt-count) 2)
            (set! (-> a0-34 0 elt-size) (the-as uint 8))
            )
          (let ((s2-1 (+ v1-85 16)))
            (save! (-> *display* base-clock) (the-as (pointer uint64) s2-1))
            (let ((v1-89 (+ s2-1 16)))
              (let ((a0-36 (the-as object (+ v1-89 0))))
                (set! (-> (the-as (inline-array game-save-tag) a0-36) 0 elt-type) (game-save-elt game-time))
                (set! (-> (the-as (inline-array game-save-tag) a0-36) 0 elt-count) 2)
                (set! (-> (the-as (inline-array game-save-tag) a0-36) 0 elt-size) (the-as uint 8))
                )
              (let ((s2-2 (+ v1-89 16)))
                (save! (-> *display* game-clock) (the-as (pointer uint64) s2-2))
                (let ((v1-93 (+ s2-2 16)))
                  (let ((a0-38 (the-as object (+ v1-93 0))))
                    (set! (-> (the-as (inline-array game-save-tag) a0-38) 0 elt-type) (game-save-elt total-game-time))
                    (set! (-> (the-as (inline-array game-save-tag) a0-38) 0 elt-count) 2)
                    (set! (-> (the-as (inline-array game-save-tag) a0-38) 0 elt-size) (the-as uint 8))
                    )
                  (let ((s2-3 (+ v1-93 16)))
                    (save! (-> *display* total-game-clock) (the-as (pointer uint64) s2-3))
                    (let ((v1-97 (+ s2-3 16)))
                      (let ((a0-40 (the-as object (+ v1-97 0))))
                        (set! (-> (the-as (inline-array game-save-tag) a0-40) 0 elt-type) (game-save-elt real-time))
                        (set! (-> (the-as (inline-array game-save-tag) a0-40) 0 elt-count) 2)
                        (set! (-> (the-as (inline-array game-save-tag) a0-40) 0 elt-size) (the-as uint 8))
                        )
                      (let ((s2-4 (+ v1-97 16)))
                        (save! (-> *display* real-clock) (the-as (pointer uint64) s2-4))
                        (let ((v1-101 (+ s2-4 16)))
                          (let ((a0-42 (the-as object (+ v1-101 0))))
                            (set! (-> (the-as (inline-array game-save-tag) a0-42) 0 elt-type) (game-save-elt frame-time))
                            (set! (-> (the-as (inline-array game-save-tag) a0-42) 0 elt-count) 2)
                            (set! (-> (the-as (inline-array game-save-tag) a0-42) 0 elt-size) (the-as uint 8))
                            )
                          (let ((s2-5 (+ v1-101 16)))
                            (save! (-> *display* frame-clock) (the-as (pointer uint64) s2-5))
                            (let ((v1-105 (+ s2-5 16)))
                              (let ((a0-44 (the-as object (+ v1-105 0))))
                                (set! (-> (the-as (inline-array game-save-tag) a0-44) 0 elt-type) (game-save-elt real-frame-time))
                                (set! (-> (the-as (inline-array game-save-tag) a0-44) 0 elt-count) 2)
                                (set! (-> (the-as (inline-array game-save-tag) a0-44) 0 elt-size) (the-as uint 8))
                                )
                              (let ((s2-6 (+ v1-105 16)))
                                (save! (-> *display* real-frame-clock) (the-as (pointer uint64) s2-6))
                                (let ((v1-109 (+ s2-6 16)))
                                  (let ((a0-46 (the-as object (+ v1-109 0))))
                                    (set! (-> (the-as (inline-array game-save-tag) a0-46) 0 elt-type) (game-save-elt session-time))
                                    (set! (-> (the-as (inline-array game-save-tag) a0-46) 0 elt-count) 2)
                                    (set! (-> (the-as (inline-array game-save-tag) a0-46) 0 elt-size) (the-as uint 8))
                                    )
                                  (let ((s2-7 (+ v1-109 16)))
                                    (save! (-> *display* session-clock) (the-as (pointer uint64) s2-7))
                                    (let ((v1-113 (+ s2-7 16)))
                                      (let ((a0-48 (the-as object (+ v1-113 0))))
                                        (set! (-> (the-as (inline-array game-save-tag) a0-48) 0 elt-type) (game-save-elt bg-time))
                                        (set! (-> (the-as (inline-array game-save-tag) a0-48) 0 elt-count) 2)
                                        (set! (-> (the-as (inline-array game-save-tag) a0-48) 0 elt-size) (the-as uint 8))
                                        )
                                      (let ((s2-8 (+ v1-113 16)))
                                        (save! (-> *display* bg-clock) (the-as (pointer uint64) s2-8))
                                        (let ((s2-9 (the-as object (+ s2-8 16))))
                                          (let ((s3-1 (-> s3-0 name)))
                                            (let ((s1-3 (the-as object (+ (the-as int s2-9) 0))))
                                              (set! (-> (the-as (inline-array game-save-tag) s1-3) 0 elt-type) (game-save-elt continue))
                                              (set! (-> (the-as (inline-array game-save-tag) s1-3) 0 elt-count) (+ (length s3-1) 1))
                                              (set! (-> (the-as (inline-array game-save-tag) s1-3) 0 elt-size) (the-as uint 1))
                                              )
                                            (copy-charp<-charp (the-as (pointer uint8) (+ (the-as int s2-9) 16)) (-> s3-1 data))
                                            )
                                          (let ((v1-125 (+ (the-as int s2-9) (logand -16 (+ (-> (the-as game-save-tag s2-9) elt-count) 15)) 16)))
                                            (let ((a0-55 (the-as object (+ v1-125 0))))
                                              (set! (-> (the-as (inline-array game-save-tag) a0-55) 0 elt-type) (game-save-elt life))
                                              (set! (-> (the-as (inline-array game-save-tag) a0-55) 0 elt-count) 0)
                                              (set! (-> (the-as (inline-array game-save-tag) a0-55) 0 user-float0) (-> this life))
                                              )
                                            (let ((v1-126 (+ v1-125 16)))
                                              (let ((a0-56 (the-as object (+ v1-126 0))))
                                                (set! (-> (the-as (inline-array game-save-tag) a0-56) 0 elt-type) (game-save-elt buzzer-total))
                                                (set! (-> (the-as (inline-array game-save-tag) a0-56) 0 elt-count) 0)
                                                (set! (-> (the-as (inline-array game-save-tag) a0-56) 0 user-float0) (-> this buzzer-total))
                                                )
                                              (let ((v1-127 (+ v1-126 16)))
                                                (let ((a0-57 (the-as object (+ v1-127 0))))
                                                  (set! (-> (the-as (inline-array game-save-tag) a0-57) 0 elt-type) (game-save-elt fuel-cell))
                                                  (set! (-> (the-as (inline-array game-save-tag) a0-57) 0 elt-count) 0)
                                                  (set! (-> (the-as (inline-array game-save-tag) a0-57) 0 user-float0) (-> this fuel))
                                                  )
                                                (let ((v1-128 (+ v1-127 16)))
                                                  (let ((a0-58 (the-as object (+ v1-128 0))))
                                                    (set! (-> (the-as (inline-array game-save-tag) a0-58) 0 elt-type) (game-save-elt death-movie-tick))
                                                    (set! (-> (the-as (inline-array game-save-tag) a0-58) 0 elt-count) 0)
                                                    (set! (-> (the-as (inline-array game-save-tag) a0-58) 0 user-uint64) (the-as uint (-> this death-movie-tick)))
                                                    )
                                                  (let ((v1-129 (+ v1-128 16)))
                                                    (let ((a0-59 (the-as object (+ v1-129 0))))
                                                      (set! (-> (the-as (inline-array game-save-tag) a0-59) 0 elt-type) (game-save-elt money))
                                                      (set! (-> (the-as (inline-array game-save-tag) a0-59) 0 elt-count) 0)
                                                      (set! (-> (the-as (inline-array game-save-tag) a0-59) 0 user-float0) (-> this money))
                                                      )
                                                    (let ((v1-130 (+ v1-129 16)))
                                                      (let ((a0-60 (the-as object (+ v1-130 0))))
                                                        (set! (-> (the-as (inline-array game-save-tag) a0-60) 0 elt-type) (game-save-elt money-total))
                                                        (set! (-> (the-as (inline-array game-save-tag) a0-60) 0 elt-count) 0)
                                                        (set! (-> (the-as (inline-array game-save-tag) a0-60) 0 user-float0) (-> this money-total))
                                                        )
                                                      (let ((v1-132 (+ v1-130 16 32)))
                                                        (let ((a0-61 (the-as object (+ v1-132 0))))
                                                          (set! (-> (the-as (inline-array game-save-tag) a0-61) 0 elt-type) (game-save-elt skill))
                                                          (set! (-> (the-as (inline-array game-save-tag) a0-61) 0 elt-count) 0)
                                                          (set! (-> (the-as (inline-array game-save-tag) a0-61) 0 user-float0) (-> this skill))
                                                          )
                                                        (let ((v1-133 (+ v1-132 16)))
                                                          (let ((a0-62 (the-as object (+ v1-133 0))))
                                                            (set! (-> (the-as (inline-array game-save-tag) a0-62) 0 elt-type) (game-save-elt skill-total))
                                                            (set! (-> (the-as (inline-array game-save-tag) a0-62) 0 elt-count) 0)
                                                            (set! (-> (the-as (inline-array game-save-tag) a0-62) 0 user-float0) (-> this skill-total))
                                                            )
                                                          (let ((v1-134 (+ v1-133 16)))
                                                            (let ((a0-63 (the-as object (+ v1-134 0))))
                                                              (set! (-> (the-as (inline-array game-save-tag) a0-63) 0 elt-type) (game-save-elt skill-high-watermark))
                                                              (set! (-> (the-as (inline-array game-save-tag) a0-63) 0 elt-count) 0)
                                                              (set! (-> (the-as (inline-array game-save-tag) a0-63) 0 user-float0) (-> this skill-high-watermark))
                                                              )
                                                            (let ((v1-135 (+ v1-134 16)))
                                                              (let ((a0-64 (the-as object (+ v1-135 0))))
                                                                (set! (-> (the-as (inline-array game-save-tag) a0-64) 0 elt-type) (game-save-elt gem))
                                                                (set! (-> (the-as (inline-array game-save-tag) a0-64) 0 elt-count) 0)
                                                                (set! (-> (the-as (inline-array game-save-tag) a0-64) 0 user-float0) (-> this gem))
                                                                )
                                                              (let ((v1-136 (+ v1-135 16)))
                                                                (let ((a0-65 (the-as object (+ v1-136 0))))
                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-65) 0 elt-type) (game-save-elt gem-total))
                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-65) 0 elt-count) 0)
                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-65) 0 user-float0) (-> this gem-total))
                                                                  )
                                                                (let ((v1-137 (+ v1-136 16)))
                                                                  (let ((a0-66 (the-as object (+ v1-137 0))))
                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-66) 0 elt-type) (game-save-elt karma))
                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-66) 0 elt-count) 0)
                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-66) 0 user-float0) (-> this karma))
                                                                    )
                                                                  (let ((v1-138 (+ v1-137 16)))
                                                                    (let ((a0-67 (the-as object (+ v1-138 0))))
                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-67) 0 elt-type) (game-save-elt eco-pill-dark))
                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-67) 0 elt-count) 0)
                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-67) 0 user-float0) (-> this eco-pill-dark))
                                                                      )
                                                                    (let ((v1-139 (+ v1-138 16)))
                                                                      (let ((a0-68 (the-as object (+ v1-139 0))))
                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-68) 0 elt-type) (game-save-elt eco-pill-dark-total))
                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-68) 0 elt-count) 0)
                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-68) 0 user-float0) (-> this eco-pill-dark-total))
                                                                        )
                                                                      (let ((v1-140 (+ v1-139 16)))
                                                                        (let ((a0-69 (the-as object (+ v1-140 0))))
                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-69) 0 elt-type) (game-save-elt eco-pill-light))
                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-69) 0 elt-count) 0)
                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-69) 0 user-float0) (-> this eco-pill-light))
                                                                          )
                                                                        (let ((v1-141 (+ v1-140 16)))
                                                                          (let ((a0-70 (the-as object (+ v1-141 0))))
                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-70) 0 elt-type) (game-save-elt eco-pill-light-total))
                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-70) 0 elt-count) 0)
                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-70) 0 user-float0) (-> this eco-pill-light-total))
                                                                            )
                                                                          (let ((v1-142 (+ v1-141 16)))
                                                                            (let ((a0-71 (the-as object (+ v1-142 0))))
                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-71) 0 elt-type) (game-save-elt shield))
                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-71) 0 elt-count) 0)
                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-71) 0 user-float0) (-> this shield))
                                                                              )
                                                                            (let ((v1-143 (+ v1-142 16)))
                                                                              (let ((a0-72 (the-as object (+ v1-143 0))))
                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-72) 0 elt-type) (game-save-elt features))
                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-72) 0 elt-count) 0)
                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-72) 0 user-uint64) (the-as uint (-> this features)))
                                                                                )
                                                                              (let ((v1-144 (+ v1-143 16)))
                                                                                (let ((a0-73 (the-as object (+ v1-144 0))))
                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-73) 0 elt-type) (game-save-elt secrets))
                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-73) 0 elt-count) 0)
                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-73) 0 user-uint64) (the-as uint (-> this secrets)))
                                                                                  )
                                                                                (let ((v1-145 (+ v1-144 16)))
                                                                                  (let ((a0-74 (the-as object (+ v1-145 0))))
                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-74) 0 elt-type) (game-save-elt vehicles))
                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-74) 0 elt-count) 0)
                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-74) 0 user-uint64) (the-as uint (-> this vehicles)))
                                                                                    )
                                                                                  (let ((v1-146 (+ v1-145 16)))
                                                                                    (let ((a0-75 (the-as object (+ v1-146 0))))
                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-75) 0 elt-type) (game-save-elt vehicle))
                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-75) 0 elt-count) 0)
                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-75) 0 user-int80) (the-as int (-> this current-vehicle)))
                                                                                      )
                                                                                    (let ((v1-147 (+ v1-146 16)))
                                                                                      (let ((a0-76 (the-as object (+ v1-147 0))))
                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-76) 0 elt-type) (game-save-elt items))
                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-76) 0 elt-count) 0)
                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-76) 0 user-uint64) (the-as uint (-> this items)))
                                                                                        )
                                                                                      (let ((v1-148 (+ v1-147 16)))
                                                                                        (let ((a0-77 (the-as object (+ v1-148 0))))
                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-77) 0 elt-type) (game-save-elt purchase-secrets))
                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-77) 0 elt-count) 0)
                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-77) 0 user-uint64) (the-as uint (-> this purchase-secrets)))
                                                                                          )
                                                                                        (let ((v1-149 (+ v1-148 16)))
                                                                                          (let ((a0-78 (the-as object (+ v1-149 0))))
                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-78) 0 elt-type) (game-save-elt gun-type))
                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-78) 0 elt-count) 0)
                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-78) 0 user-uint64) (the-as uint (-> this gun-type)))
                                                                                            )
                                                                                          (let ((v1-150 (+ v1-149 16)))
                                                                                            (let ((a0-79 (the-as object (+ v1-150 0))))
                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-79) 0 elt-type) (game-save-elt gun-ammo))
                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-79) 0 elt-count) 4)
                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-79) 0 elt-size) (the-as uint 4))
                                                                                              )
                                                                                            (let ((v1-151 (+ v1-150 16)))
                                                                                              (dotimes (a0-80 4)
                                                                                                (set! (-> (the-as (pointer float) (+ v1-151 (* a0-80 4))) 0) (-> this gun-ammo a0-80))
                                                                                                )
                                                                                              (let ((v1-152 (+ v1-151 16)))
                                                                                                (let ((a0-83 (the-as object (+ v1-152 0))))
                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-83) 0 elt-type) (game-save-elt enemies-killed))
                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-83) 0 elt-count) 0)
                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-83) 0 user-float0) (-> this enemies-killed))
                                                                                                  )
                                                                                                (let ((v1-153 (+ v1-152 16)))
                                                                                                  (let ((a0-84 (the-as object (+ v1-153 0))))
                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-84) 0 elt-type) (game-save-elt civilians-killed))
                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-84) 0 elt-count) 0)
                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-84) 0 user-float0) (-> this civilians-killed))
                                                                                                    )
                                                                                                  (let ((v1-154 (+ v1-153 16)))
                                                                                                    (let ((a0-85 (the-as object (+ v1-154 0))))
                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-85) 0 elt-type) (game-save-elt marauders-killed))
                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-85) 0 elt-count) 0)
                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-85) 0 user-float0) (-> this marauders-killed))
                                                                                                      )
                                                                                                    (let ((v1-155 (+ v1-154 16)))
                                                                                                      (let ((a0-86 (the-as object (+ v1-155 0))))
                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-86) 0 elt-type) (game-save-elt crates-opened))
                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-86) 0 elt-count) 0)
                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-86) 0 user-float0) (-> this crates-opened))
                                                                                                        )
                                                                                                      (let ((v1-156 (+ v1-155 16)))
                                                                                                        (let ((a0-87 (the-as object (+ v1-156 0))))
                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-87) 0 elt-type) (game-save-elt health-collected))
                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-87) 0 elt-count) 0)
                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-87) 0 user-float0) (-> this health-collected))
                                                                                                          )
                                                                                                        (let ((v1-157 (+ v1-156 16)))
                                                                                                          (let ((a0-88 (the-as object (+ v1-157 0))))
                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-88) 0 elt-type) (game-save-elt board-time))
                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-88) 0 elt-count) 0)
                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-88) 0 user-uint64) (the-as uint (-> this board-time)))
                                                                                                            )
                                                                                                          (let ((v1-158 (+ v1-157 16)))
                                                                                                            (let ((a0-89 (the-as object (+ v1-158 0))))
                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-89) 0 elt-type) (game-save-elt shot-info))
                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-89) 0 elt-count) 8)
                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-89) 0 elt-size) (the-as uint 4))
                                                                                                              )
                                                                                                            (let ((v1-159 (+ v1-158 16)))
                                                                                                              (dotimes (a0-90 8)
                                                                                                                (set! (-> (the-as (pointer float) (+ v1-159 (* (* a0-90 2) 4))) 0) (-> this shots-fired a0-90))
                                                                                                                (set! (-> (the-as (pointer float) (+ v1-159 (* (+ (* a0-90 2) 1) 4))) 0) (-> this shots-hit a0-90))
                                                                                                                )
                                                                                                              (let ((v1-160 (+ v1-159 32)))
                                                                                                                (let ((a0-93 (the-as object (+ v1-160 0))))
                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-93) 0 elt-type) (game-save-elt level-open-list))
                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-93) 0 elt-count) 32)
                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-93) 0 elt-size) (the-as uint 1))
                                                                                                                  )
                                                                                                                (let ((v1-161 (+ v1-160 16)))
                                                                                                                  (dotimes (a0-94 32)
                                                                                                                    (set! (-> (the-as (pointer uint8) (+ v1-161 a0-94)) 0) (-> this level-opened a0-94))
                                                                                                                    )
                                                                                                                  (let ((v1-162 (+ v1-161 32))
                                                                                                                        (s2-10 (-> this sub-task-list length))
                                                                                                                        )
                                                                                                                    (let ((a0-98 (the-as object (+ v1-162 0))))
                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-98) 0 elt-type) (game-save-elt node-name))
                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-98) 0 elt-count) s2-10)
                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-98) 0 elt-size) (the-as uint 64))
                                                                                                                      )
                                                                                                                    (let ((s3-2 (+ v1-162 16)))
                                                                                                                      (dotimes (s1-4 s2-10)
                                                                                                                        (copyn-charp<-string (the-as (pointer uint8) s3-2) (-> this sub-task-list s1-4 name) 64)
                                                                                                                        (+! s3-2 64)
                                                                                                                        )
                                                                                                                      (let ((s2-11 (-> this perm-list length)))
                                                                                                                        (let ((v1-169 (the-as object (+ s3-2 0))))
                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) v1-169) 0 elt-type) (game-save-elt perm-list))
                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) v1-169) 0 elt-count) s2-11)
                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) v1-169) 0 elt-size) (the-as uint 16))
                                                                                                                          )
                                                                                                                        (let ((s3-3 (+ s3-2 16)))
                                                                                                                          (dotimes (s1-5 s2-11)
                                                                                                                            (mem-copy! (the-as pointer (+ s3-3 (* s1-5 16))) (the-as pointer (-> this perm-list data s1-5)) 16)
                                                                                                                            )
                                                                                                                          (let ((v1-177 (+ s3-3 (logand -16 (+ (* s2-11 16) 15))))
                                                                                                                                (s3-4 (-> this task-perm-list length))
                                                                                                                                )
                                                                                                                            (let ((a0-107 (the-as object (+ v1-177 0))))
                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-107) 0 elt-type) (game-save-elt task-list))
                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-107) 0 elt-count) s3-4)
                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-107) 0 elt-size) (the-as uint 16))
                                                                                                                              )
                                                                                                                            (let ((s2-12 (+ v1-177 16)))
                                                                                                                              (dotimes (s1-6 s3-4)
                                                                                                                                (mem-copy! (the-as pointer (+ s2-12 (* s1-6 16))) (the-as pointer (-> this task-perm-list data s1-6)) 16)
                                                                                                                                )
                                                                                                                              (let ((a0-111 (+ s2-12 (logand -16 (+ (* s3-4 16) 15))))
                                                                                                                                    (v1-187 (-> this talker-state allocated-length))
                                                                                                                                    )
                                                                                                                                (let ((a1-118 (the-as object (+ a0-111 0))))
                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a1-118) 0 elt-type) (game-save-elt talker-state))
                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a1-118) 0 elt-count) v1-187)
                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a1-118) 0 elt-size) (the-as uint 2))
                                                                                                                                  )
                                                                                                                                (let ((a0-112 (+ a0-111 16)))
                                                                                                                                  (dotimes (a1-119 v1-187)
                                                                                                                                    (set! (-> (the-as (pointer uint16) (+ a0-112 (* a1-119 2))) 0) (-> this talker-state a1-119))
                                                                                                                                    )
                                                                                                                                  (let ((a0-113 (+ a0-112 (logand -16 (+ (* v1-187 2) 15))))
                                                                                                                                        (v1-193 (-> this game-score allocated-length))
                                                                                                                                        )
                                                                                                                                    (let ((a1-123 (the-as object (+ a0-113 0))))
                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a1-123) 0 elt-type) (game-save-elt scores))
                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a1-123) 0 elt-count) v1-193)
                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a1-123) 0 elt-size) (the-as uint 4))
                                                                                                                                      )
                                                                                                                                    (let ((a0-114 (+ a0-113 16)))
                                                                                                                                      (dotimes (a1-124 v1-193)
                                                                                                                                        (set! (-> (the-as (pointer float) (+ a0-114 (* a1-124 4))) 0) (-> this game-score a1-124))
                                                                                                                                        )
                                                                                                                                      (let ((v1-197 (+ a0-114 (logand -16 (+ (* v1-193 4) 15)))))
                                                                                                                                        (let ((a0-116 (the-as object (+ v1-197 0))))
                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-116) 0 elt-type) (game-save-elt auto-save-count))
                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-116) 0 elt-count) 0)
                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-116) 0 user-uint64) (the-as uint (-> this auto-save-count)))
                                                                                                                                          )
                                                                                                                                        (let ((v1-198 (+ v1-197 16)))
                                                                                                                                          (let ((a0-117 (the-as object (+ v1-198 0))))
                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-117) 0 elt-type) (game-save-elt total-deaths))
                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-117) 0 elt-count) 0)
                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-117) 0 user-uint64) (the-as uint (-> this total-deaths)))
                                                                                                                                            )
                                                                                                                                          (let ((v1-199 (+ v1-198 16)))
                                                                                                                                            (let ((a0-118 (the-as object (+ v1-199 0))))
                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-118) 0 elt-type) (game-save-elt total-trys))
                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-118) 0 elt-count) 0)
                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-118) 0 user-uint64) (the-as uint (-> this total-trys)))
                                                                                                                                              )
                                                                                                                                            (let ((v1-200 (+ v1-199 16)))
                                                                                                                                              (let ((a0-119 (the-as object (+ v1-200 0))))
                                                                                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-119) 0 elt-type) (game-save-elt continue-deaths))
                                                                                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-119) 0 elt-count) 0)
                                                                                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-119) 0 user-uint64) (the-as uint (-> this continue-deaths)))
                                                                                                                                                )
                                                                                                                                              (let ((v1-201 (+ v1-200 16)))
                                                                                                                                                (let ((a0-120 (the-as object (+ v1-201 0))))
                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-120) 0 elt-type) (game-save-elt task-deaths))
                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-120) 0 elt-count) 0)
                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-120) 0 user-uint64) (the-as uint (-> this task-deaths)))
                                                                                                                                                  )
                                                                                                                                                (let ((v1-202 (+ v1-201 16)))
                                                                                                                                                  (let ((a0-121 (the-as object (+ v1-202 0))))
                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-121) 0 elt-type) (game-save-elt game-start-time))
                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-121) 0 elt-count) 0)
                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-121) 0 user-uint64) (the-as uint (-> this game-start-time)))
                                                                                                                                                    )
                                                                                                                                                  (let ((v1-203 (+ v1-202 16)))
                                                                                                                                                    (let ((a0-122 (the-as object (+ v1-203 0))))
                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-122) 0 elt-type) (game-save-elt continue-time))
                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-122) 0 elt-count) 0)
                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-122) 0 user-uint64) (the-as uint (-> this continue-time)))
                                                                                                                                                      )
                                                                                                                                                    (let ((v1-204 (+ v1-203 16)))
                                                                                                                                                      (let ((a0-123 (the-as object (+ v1-204 0))))
                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-123) 0 elt-type) (game-save-elt death-time))
                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-123) 0 elt-count) 0)
                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-123) 0 user-uint64) (the-as uint (-> this death-time)))
                                                                                                                                                        )
                                                                                                                                                      (let ((v1-205 (+ v1-204 16)))
                                                                                                                                                        (let ((a0-124 (the-as object (+ v1-205 0))))
                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-124) 0 elt-type) (game-save-elt hit-time))
                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-124) 0 elt-count) 0)
                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-124) 0 user-uint64) (the-as uint (-> this hit-time)))
                                                                                                                                                          )
                                                                                                                                                        (let ((v1-206 (+ v1-205 16)))
                                                                                                                                                          (let ((a0-125 (the-as object (+ v1-206 0))))
                                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-125) 0 elt-type) (game-save-elt task-pickup-time))
                                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-125) 0 elt-count) 0)
                                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-125) 0 user-uint64)
                                                                                                                                                                  (the-as uint (-> this task-pickup-time))
                                                                                                                                                                  )
                                                                                                                                                            )
                                                                                                                                                          (let ((v1-207 (+ v1-206 16)))
                                                                                                                                                            (let ((a0-126 (the-as object (+ v1-207 0))))
                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-126) 0 elt-type) (game-save-elt task-complete-time))
                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-126) 0 elt-count) 138)
                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-126) 0 elt-size) (the-as uint 8))
                                                                                                                                                              )
                                                                                                                                                            (let ((v1-208 (+ v1-207 16)))
                                                                                                                                                              (dotimes (a0-127 138)
                                                                                                                                                                (set! (-> (the-as (pointer time-frame) (+ v1-208 (* a0-127 8))) 0) (-> this task-complete-time a0-127))
                                                                                                                                                                )
                                                                                                                                                              (let ((v1-209 (+ v1-208 1104)))
                                                                                                                                                                (let ((a0-130 (the-as object (+ v1-209 0))))
                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-130) 0 elt-type) (game-save-elt task-start-time))
                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-130) 0 elt-count) 138)
                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-130) 0 elt-size) (the-as uint 8))
                                                                                                                                                                  )
                                                                                                                                                                (let ((v1-210 (+ v1-209 16)))
                                                                                                                                                                  (dotimes (a0-131 138)
                                                                                                                                                                    (set! (-> (the-as (pointer time-frame) (+ v1-210 (* a0-131 8))) 0) (-> this task-start-time a0-131))
                                                                                                                                                                    )
                                                                                                                                                                  (let ((v1-211 (+ v1-210 1104)))
                                                                                                                                                                    (let ((a0-134 (the-as object (+ v1-211 0))))
                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-134) 0 elt-type) (game-save-elt enter-level-time))
                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-134) 0 elt-count) 32)
                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-134) 0 elt-size) (the-as uint 8))
                                                                                                                                                                      )
                                                                                                                                                                    (let ((v1-212 (+ v1-211 16)))
                                                                                                                                                                      (dotimes (a0-135 32)
                                                                                                                                                                        (set! (-> (the-as (pointer time-frame) (+ v1-212 (* a0-135 8))) 0) (-> this task-enter-times a0-135))
                                                                                                                                                                        )
                                                                                                                                                                      (let ((v1-213 (+ v1-212 256)))
                                                                                                                                                                        (let ((a0-138 (the-as object (+ v1-213 0))))
                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-138) 0 elt-type) (game-save-elt in-level-time))
                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-138) 0 elt-count) 32)
                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-138) 0 elt-size) (the-as uint 8))
                                                                                                                                                                          )
                                                                                                                                                                        (let ((v1-214 (+ v1-213 16)))
                                                                                                                                                                          (dotimes (a0-139 32)
                                                                                                                                                                            (set! (-> (the-as (pointer time-frame) (+ v1-214 (* a0-139 8))) 0) (-> this task-in-times a0-139))
                                                                                                                                                                            )
                                                                                                                                                                          (let ((a0-142 (+ v1-214 256))
                                                                                                                                                                                (v1-216 (-> this sub-task-list length))
                                                                                                                                                                                )
                                                                                                                                                                            (let ((a1-172 (the-as object (+ a0-142 0))))
                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a1-172) 0 elt-type) (game-save-elt node-death-count))
                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a1-172) 0 elt-count) v1-216)
                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a1-172) 0 elt-size) (the-as uint 2))
                                                                                                                                                                              )
                                                                                                                                                                            (let ((a0-143 (+ a0-142 16)))
                                                                                                                                                                              (dotimes (a1-173 v1-216)
                                                                                                                                                                                (set! (-> (the-as (pointer uint16) (+ a0-143 (* a1-173 2))) 0) (-> this sub-task-list a1-173 death-count))
                                                                                                                                                                                )
                                                                                                                                                                              (let ((a0-144 (+ a0-143 (logand -16 (+ (* v1-216 2) 15)))))
                                                                                                                                                                                (let ((a1-178 (the-as object (+ a0-144 0))))
                                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a1-178) 0 elt-type) (game-save-elt node-gem-count))
                                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a1-178) 0 elt-count) v1-216)
                                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a1-178) 0 elt-size) (the-as uint 2))
                                                                                                                                                                                  )
                                                                                                                                                                                (let ((a0-145 (+ a0-144 16)))
                                                                                                                                                                                  (dotimes (a1-179 v1-216)
                                                                                                                                                                                    (set! (-> (the-as (pointer uint16) (+ a0-145 (* a1-179 2))) 0) (-> this sub-task-list a1-179 gem-count))
                                                                                                                                                                                    )
                                                                                                                                                                                  (let ((a0-146 (+ a0-145 (logand -16 (+ (* v1-216 2) 15)))))
                                                                                                                                                                                    (let ((a1-184 (the-as object (+ a0-146 0))))
                                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a1-184) 0 elt-type) (game-save-elt node-skill-count))
                                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a1-184) 0 elt-count) v1-216)
                                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a1-184) 0 elt-size) (the-as uint 2))
                                                                                                                                                                                      )
                                                                                                                                                                                    (let ((a0-147 (+ a0-146 16)))
                                                                                                                                                                                      (dotimes (a1-185 v1-216)
                                                                                                                                                                                        (set! (-> (the-as (pointer uint16) (+ a0-147 (* a1-185 2))) 0) (-> this sub-task-list a1-185 skill-count))
                                                                                                                                                                                        )
                                                                                                                                                                                      (let ((a0-148 (+ a0-147 (logand -16 (+ (* v1-216 2) 15)))))
                                                                                                                                                                                        (let ((a1-190 (the-as object (+ a0-148 0))))
                                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a1-190) 0 elt-type) (game-save-elt node-close-time))
                                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a1-190) 0 elt-count) v1-216)
                                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a1-190) 0 elt-size) (the-as uint 8))
                                                                                                                                                                                          )
                                                                                                                                                                                        (let ((a0-149 (+ a0-148 16)))
                                                                                                                                                                                          (dotimes (a1-191 v1-216)
                                                                                                                                                                                            (set! (-> (the-as (pointer time-frame) (+ a0-149 (* a1-191 8))) 0)
                                                                                                                                                                                                  (the-as time-frame (-> this sub-task-list a1-191 close-time))
                                                                                                                                                                                                  )
                                                                                                                                                                                            )
                                                                                                                                                                                          (let ((a0-150 (+ a0-149 (logand -16 (+ (* v1-216 8) 15))))
                                                                                                                                                                                                (v1-222 (-> this sub-task-list length))
                                                                                                                                                                                                )
                                                                                                                                                                                            (let ((a1-195 (the-as object (+ a0-150 0))))
                                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a1-195) 0 elt-type) (game-save-elt task-node-list))
                                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a1-195) 0 elt-count) v1-222)
                                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a1-195) 0 elt-size) (the-as uint 1))
                                                                                                                                                                                              )
                                                                                                                                                                                            (let ((a0-151 (+ a0-150 16)))
                                                                                                                                                                                              (dotimes (a1-196 v1-222)
                                                                                                                                                                                                (set! (-> (the-as (pointer uint8) (+ a0-151 a1-196)) 0)
                                                                                                                                                                                                      (the-as uint (if (logtest? (-> this sub-task-list a1-196 flags) (game-task-node-flag closed))
                                                                                                                                                                                                                       1
                                                                                                                                                                                                                       0
                                                                                                                                                                                                                       )
                                                                                                                                                                                                              )
                                                                                                                                                                                                      )
                                                                                                                                                                                                )
                                                                                                                                                                                              (let ((s5-1 (the-as object (+ a0-151 (logand -16 (+ v1-222 15))))))
                                                                                                                                                                                                (let ((s4-2 (-> *game-info* sub-task-list s4-1 name)))
                                                                                                                                                                                                  (let ((s3-5 (the-as object (+ (the-as int s5-1) 0))))
                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) s3-5) 0 elt-type) (game-save-elt resetter-node))
                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) s3-5) 0 elt-count) (+ (length s4-2) 1))
                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) s3-5) 0 elt-size) (the-as uint 1))
                                                                                                                                                                                                    )
                                                                                                                                                                                                  (copy-charp<-charp (the-as (pointer uint8) (+ (the-as int s5-1) 16)) (-> s4-2 data))
                                                                                                                                                                                                  )
                                                                                                                                                                                                (let ((v1-237 (+ (the-as int s5-1) (logand -16 (+ (-> (the-as game-save-tag s5-1) elt-count) 15)) 16)))
                                                                                                                                                                                                  (let ((a0-159 (the-as object (+ v1-237 0))))
                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-159) 0 elt-type) (game-save-elt sfx-volume))
                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-159) 0 elt-count) 0)
                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-159) 0 user-float0)
                                                                                                                                                                                                          (-> *setting-control* user-default sfx-volume)
                                                                                                                                                                                                          )
                                                                                                                                                                                                    )
                                                                                                                                                                                                  (let ((v1-238 (+ v1-237 16)))
                                                                                                                                                                                                    (let ((a0-160 (the-as object (+ v1-238 0))))
                                                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-160) 0 elt-type) (game-save-elt music-volume))
                                                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-160) 0 elt-count) 0)
                                                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-160) 0 user-float0)
                                                                                                                                                                                                            (-> *setting-control* user-default music-volume)
                                                                                                                                                                                                            )
                                                                                                                                                                                                      )
                                                                                                                                                                                                    (let ((v1-239 (+ v1-238 16)))
                                                                                                                                                                                                      (let ((a0-161 (the-as object (+ v1-239 0))))
                                                                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-161) 0 elt-type) (game-save-elt dialog-volume))
                                                                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-161) 0 elt-count) 0)
                                                                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-161) 0 user-float0)
                                                                                                                                                                                                              (-> *setting-control* user-default dialog-volume)
                                                                                                                                                                                                              )
                                                                                                                                                                                                        )
                                                                                                                                                                                                      (let ((v1-240 (+ v1-239 16)))
                                                                                                                                                                                                        (let ((a0-162 (the-as object (+ v1-240 0))))
                                                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-162) 0 elt-type) (game-save-elt language))
                                                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-162) 0 elt-count) 0)
                                                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-162) 0 user-uint64)
                                                                                                                                                                                                                (the-as uint (-> *setting-control* user-default language))
                                                                                                                                                                                                                )
                                                                                                                                                                                                          )
                                                                                                                                                                                                        (let ((v1-241 (+ v1-240 16)))
                                                                                                                                                                                                          (let ((a0-163 (the-as object (+ v1-241 0))))
                                                                                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-163) 0 elt-type) (game-save-elt subtitle-language))
                                                                                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-163) 0 elt-count) 0)
                                                                                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-163) 0 user-uint64)
                                                                                                                                                                                                                  (the-as uint (-> *setting-control* user-default subtitle-language))
                                                                                                                                                                                                                  )
                                                                                                                                                                                                            )
                                                                                                                                                                                                          (let ((v1-242 (+ v1-241 16)))
                                                                                                                                                                                                            (let ((a0-164 (the-as object (+ v1-242 0))))
                                                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-164) 0 elt-type) (game-save-elt audio-language))
                                                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-164) 0 elt-count) 0)
                                                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-164) 0 user-uint64)
                                                                                                                                                                                                                    (the-as uint (-> *setting-control* user-default audio-language))
                                                                                                                                                                                                                    )
                                                                                                                                                                                                              )
                                                                                                                                                                                                            (let ((v1-243 (+ v1-242 16)))
                                                                                                                                                                                                              (let ((a0-165 (the-as object (+ v1-243 0))))
                                                                                                                                                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-165) 0 elt-type) (game-save-elt stereo-mode))
                                                                                                                                                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-165) 0 elt-count) 0)
                                                                                                                                                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-165) 0 user-uint64)
                                                                                                                                                                                                                      (the-as uint (-> *setting-control* user-default stereo-mode))
                                                                                                                                                                                                                      )
                                                                                                                                                                                                                )
                                                                                                                                                                                                              (let ((v1-244 (+ v1-243 16)))
                                                                                                                                                                                                                (let ((a0-166 (the-as object (+ v1-244 0))))
                                                                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-166) 0 elt-type) (game-save-elt screenx))
                                                                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-166) 0 elt-count) 0)
                                                                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-166) 0 user-float0)
                                                                                                                                                                                                                        (the float (-> *setting-control* user-default screenx))
                                                                                                                                                                                                                        )
                                                                                                                                                                                                                  )
                                                                                                                                                                                                                (let ((v1-245 (+ v1-244 16)))
                                                                                                                                                                                                                  (let ((a0-167 (the-as object (+ v1-245 0))))
                                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-167) 0 elt-type) (game-save-elt screeny))
                                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-167) 0 elt-count) 0)
                                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-167) 0 user-float0)
                                                                                                                                                                                                                          (the float (-> *setting-control* user-default screeny))
                                                                                                                                                                                                                          )
                                                                                                                                                                                                                    )
                                                                                                                                                                                                                  (let ((v1-246 (+ v1-245 16)))
                                                                                                                                                                                                                    (let ((a0-168 (the-as object (+ v1-246 0))))
                                                                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-168) 0 elt-type) (game-save-elt brightness))
                                                                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-168) 0 elt-count) 0)
                                                                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-168) 0 user-float0)
                                                                                                                                                                                                                            (-> *setting-control* user-default brightness)
                                                                                                                                                                                                                            )
                                                                                                                                                                                                                      )
                                                                                                                                                                                                                    (let ((v1-247 (+ v1-246 16)))
                                                                                                                                                                                                                      (let ((a0-169 (the-as object (+ v1-247 0))))
                                                                                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-169) 0 elt-type) (game-save-elt contrast))
                                                                                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-169) 0 elt-count) 0)
                                                                                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-169) 0 user-float0)
                                                                                                                                                                                                                              (-> *setting-control* user-default contrast)
                                                                                                                                                                                                                              )
                                                                                                                                                                                                                        )
                                                                                                                                                                                                                      (let ((v1-248 (+ v1-247 16)))
                                                                                                                                                                                                                        (let ((a0-170 (the-as object (+ v1-248 0))))
                                                                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-170) 0 elt-type) (game-save-elt vibration))
                                                                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-170) 0 elt-count) 0)
                                                                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-170) 0 user-uint64)
                                                                                                                                                                                                                                (the-as uint (if (-> *setting-control* user-default vibration)
                                                                                                                                                                                                                                                 1
                                                                                                                                                                                                                                                 0
                                                                                                                                                                                                                                                 )
                                                                                                                                                                                                                                        )
                                                                                                                                                                                                                                )
                                                                                                                                                                                                                          )
                                                                                                                                                                                                                        (let ((v1-249 (+ v1-248 16)))
                                                                                                                                                                                                                          (let ((a0-171 (the-as object (+ v1-249 0))))
                                                                                                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-171) 0 elt-type) (game-save-elt subtitle))
                                                                                                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-171) 0 elt-count) 0)
                                                                                                                                                                                                                            (set! (-> (the-as (inline-array game-save-tag) a0-171) 0 user-uint64)
                                                                                                                                                                                                                                  (the-as uint (if (-> *setting-control* user-default subtitle)
                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                   0
                                                                                                                                                                                                                                                   )
                                                                                                                                                                                                                                          )
                                                                                                                                                                                                                                  )
                                                                                                                                                                                                                            )
                                                                                                                                                                                                                          (let ((v1-250 (+ v1-249 16)))
                                                                                                                                                                                                                            (let ((a0-172 (the-as object (+ v1-250 0))))
                                                                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-172) 0 elt-type) (game-save-elt flip-horizontal))
                                                                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-172) 0 elt-count) 0)
                                                                                                                                                                                                                              (set! (-> (the-as (inline-array game-save-tag) a0-172) 0 user-uint64)
                                                                                                                                                                                                                                    (the-as uint (if (-> *setting-control* cam-default flip-horizontal)
                                                                                                                                                                                                                                                     1
                                                                                                                                                                                                                                                     0
                                                                                                                                                                                                                                                     )
                                                                                                                                                                                                                                            )
                                                                                                                                                                                                                                    )
                                                                                                                                                                                                                              )
                                                                                                                                                                                                                            (let ((v1-251 (+ v1-250 16)))
                                                                                                                                                                                                                              (let ((a0-173 (the-as object (+ v1-251 0))))
                                                                                                                                                                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-173) 0 elt-type) (game-save-elt flip-vertical))
                                                                                                                                                                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-173) 0 elt-count) 0)
                                                                                                                                                                                                                                (set! (-> (the-as (inline-array game-save-tag) a0-173) 0 user-uint64)
                                                                                                                                                                                                                                      (the-as uint (if (-> *setting-control* cam-default flip-vertical)
                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                       0
                                                                                                                                                                                                                                                       )
                                                                                                                                                                                                                                              )
                                                                                                                                                                                                                                      )
                                                                                                                                                                                                                                )
                                                                                                                                                                                                                              (let ((v1-252 (+ v1-251 16)))
                                                                                                                                                                                                                                (let ((a0-174 (the-as object (+ v1-252 0))))
                                                                                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-174) 0 elt-type) (game-save-elt camera-stick-dir))
                                                                                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-174) 0 elt-count) 0)
                                                                                                                                                                                                                                  (set! (-> (the-as (inline-array game-save-tag) a0-174) 0 user-uint64)
                                                                                                                                                                                                                                        (the-as uint (if (-> *setting-control* user-default camera-stick-dir)
                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                         0
                                                                                                                                                                                                                                                         )
                                                                                                                                                                                                                                                )
                                                                                                                                                                                                                                        )
                                                                                                                                                                                                                                  )
                                                                                                                                                                                                                                (let ((v1-253 (+ v1-252 16)))
                                                                                                                                                                                                                                  (let ((a0-175 (the-as object (+ v1-253 0))))
                                                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-175) 0 elt-type) (game-save-elt play-hints))
                                                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-175) 0 elt-count) 0)
                                                                                                                                                                                                                                    (set! (-> (the-as (inline-array game-save-tag) a0-175) 0 user-uint64)
                                                                                                                                                                                                                                          (the-as uint (if (-> *setting-control* user-default play-hints)
                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                           0
                                                                                                                                                                                                                                                           )
                                                                                                                                                                                                                                                  )
                                                                                                                                                                                                                                          )
                                                                                                                                                                                                                                    )
                                                                                                                                                                                                                                  (let ((v1-254 (+ v1-253 16)))
                                                                                                                                                                                                                                    (let ((a0-176 (the-as object (+ v1-254 0))))
                                                                                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-176) 0 elt-type) (game-save-elt video-mode))
                                                                                                                                                                                                                                      (set! (-> (the-as (inline-array game-save-tag) a0-176) 0 elt-count) 0)
                                                                                                                                                                                                                                      (let ((a1-255 (-> *setting-control* user-default video-mode)))
                                                                                                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-176) 0 user-uint64) (the-as uint (cond
                                                                                                                                                                                                                                                                                                                             ((= a1-255 'ntsc)
                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                              )
                                                                                                                                                                                                                                                                                                                             ((= a1-255 'pal)
                                                                                                                                                                                                                                                                                                                              2
                                                                                                                                                                                                                                                                                                                              )
                                                                                                                                                                                                                                                                                                                             (else
                                                                                                                                                                                                                                                                                                                               0
                                                                                                                                                                                                                                                                                                                               )
                                                                                                                                                                                                                                                                                                                             )
                                                                                                                                                                                                                                                                                                                      )
                                                                                                                                                                                                                                              )
                                                                                                                                                                                                                                        )
                                                                                                                                                                                                                                      )
                                                                                                                                                                                                                                    (let ((v1-255 (+ v1-254 16)))
                                                                                                                                                                                                                                      (let ((a0-177 (the-as object (+ v1-255 0))))
                                                                                                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-177) 0 elt-type) (game-save-elt aspect-ratio))
                                                                                                                                                                                                                                        (set! (-> (the-as (inline-array game-save-tag) a0-177) 0 elt-count) 0)
                                                                                                                                                                                                                                        (let ((a1-259 (-> *setting-control* user-default aspect-ratio)))
                                                                                                                                                                                                                                          (set! (-> (the-as (inline-array game-save-tag) a0-177) 0 user-uint64) (the-as uint (cond
                                                                                                                                                                                                                                                                                                                               ((= a1-259 'aspect4x3)
                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                )
                                                                                                                                                                                                                                                                                                                               ((= a1-259 'aspect16x9)
                                                                                                                                                                                                                                                                                                                                2
                                                                                                                                                                                                                                                                                                                                )
                                                                                                                                                                                                                                                                                                                               (else
                                                                                                                                                                                                                                                                                                                                 0
                                                                                                                                                                                                                                                                                                                                 )
                                                                                                                                                                                                                                                                                                                               )
                                                                                                                                                                                                                                                                                                                        )
                                                                                                                                                                                                                                                )
                                                                                                                                                                                                                                          )
                                                                                                                                                                                                                                        )
                                                                                                                                                                                                                                      (set! (-> save length) (- (+ v1-255 16) (the-as int (the-as pointer (-> save tag)))))
                                                                                                                                                                                                                                      )
                                                                                                                                                                                                                                    )
                                                                                                                                                                                                                                  )
                                                                                                                                                                                                                                )
                                                                                                                                                                                                                              )
                                                                                                                                                                                                                            )
                                                                                                                                                                                                                          )
                                                                                                                                                                                                                        )
                                                                                                                                                                                                                      )
                                                                                                                                                                                                                    )
                                                                                                                                                                                                                  )
                                                                                                                                                                                                                )
                                                                                                                                                                                                              )
                                                                                                                                                                                                            )
                                                                                                                                                                                                          )
                                                                                                                                                                                                        )
                                                                                                                                                                                                      )
                                                                                                                                                                                                    )
                                                                                                                                                                                                  )
                                                                                                                                                                                                )
                                                                                                                                                                                              )
                                                                                                                                                                                            )
                                                                                                                                                                                          )
                                                                                                                                                                                        )
                                                                                                                                                                                      )
                                                                                                                                                                                    )
                                                                                                                                                                                  )
                                                                                                                                                                                )
                                                                                                                                                                              )
                                                                                                                                                                            )
                                                                                                                                                                          )
                                                                                                                                                                        )
                                                                                                                                                                      )
                                                                                                                                                                    )
                                                                                                                                                                  )
                                                                                                                                                                )
                                                                                                                                                              )
                                                                                                                                                            )
                                                                                                                                                          )
                                                                                                                                                        )
                                                                                                                                                      )
                                                                                                                                                    )
                                                                                                                                                  )
                                                                                                                                                )
                                                                                                                                              )
                                                                                                                                            )
                                                                                                                                          )
                                                                                                                                        )
                                                                                                                                      )
                                                                                                                                    )
                                                                                                                                  )
                                                                                                                                )
                                                                                                                              )
                                                                                                                            )
                                                                                                                          )
                                                                                                                        )
                                                                                                                      )
                                                                                                                    )
                                                                                                                  )
                                                                                                                )
                                                                                                              )
                                                                                                            )
                                                                                                          )
                                                                                                        )
                                                                                                      )
                                                                                                    )
                                                                                                  )
                                                                                                )
                                                                                              )
                                                                                            )
                                                                                          )
                                                                                        )
                                                                                      )
                                                                                    )
                                                                                  )
                                                                                )
                                                                              )
                                                                            )
                                                                          )
                                                                        )
                                                                      )
                                                                    )
                                                                  )
                                                                )
                                                              )
                                                            )
                                                          )
                                                        )
                                                      )
                                                    )
                                                  )
                                                )
                                              )
                                            )
                                          )
                                        )
                                      )
                                    )
                                  )
                                )
                              )
                            )
                          )
                        )
                      )
                    )
                  )
                )
              )
            )
          )
        )
      )
    (if (< (-> save allocated-length) (-> save length))
        (format
          0
          "ERROR: SAVEGAME: fatal error, save is using ~D of ~D bytes."
          (-> save length)
          (-> save allocated-length)
          )
        )
    save
    )
  )

(defmethod load-game ((this game-info) (arg0 game-save))
  (let ((v1-0 (the-as object (-> arg0 tag))))
    (while (< (the-as int v1-0) (the-as int (&-> arg0 tag 0 user-int8 (-> arg0 length))))
      (case (-> (the-as (inline-array game-save-tag) v1-0) 0 elt-type)
        ;; og:preserve-this moved these to pc-settings
        (((game-save-elt sfx-volume) (game-save-elt music-volume) (game-save-elt dialog-volume) (game-save-elt vibration) (game-save-elt subtitle))
         (format 0 "game-info::load-game: skip setting ~S, stored in pc-settings now~%"
           (game-save-elt->string (-> (the (inline-array game-save-tag) v1-0) 0 elt-type))))
        ; (((game-save-elt sfx-volume))
        ;  (set! (-> *setting-control* user-default sfx-volume)
        ;        (-> (the-as (inline-array game-save-tag) v1-0) 0 user-float0)
        ;        )
        ;  )
        ; (((game-save-elt music-volume))
        ;  (set! (-> *setting-control* user-default music-volume)
        ;        (-> (the-as (inline-array game-save-tag) v1-0) 0 user-float0)
        ;        )
        ;  )
        ; (((game-save-elt dialog-volume))
        ;  (set! (-> *setting-control* user-default dialog-volume)
        ;        (-> (the-as (inline-array game-save-tag) v1-0) 0 user-float0)
        ;        )
        ;  )
        (((game-save-elt language))
         (set! (-> *setting-control* user-default language)
               (the-as language-enum (-> (the-as (inline-array game-save-tag) v1-0) 0 user-uint64))
               )
         )
        (((game-save-elt subtitle-language))
         (set! (-> *setting-control* user-default subtitle-language)
               (the-as language-enum (-> (the-as (inline-array game-save-tag) v1-0) 0 user-uint64))
               )
         )
        (((game-save-elt audio-language))
         (set! (-> *setting-control* user-default audio-language)
               (the-as language-enum (-> (the-as (inline-array game-save-tag) v1-0) 0 user-uint64))
               )
         )
        (((game-save-elt stereo-mode))
         (set! (-> *setting-control* user-default stereo-mode)
               (the-as int (-> (the-as (inline-array game-save-tag) v1-0) 0 user-uint64))
               )
         )
        ;; og:preserve-this moved these to pc-settings
        ; (((game-save-elt vibration))
        ;  (set! (-> *setting-control* user-default vibration)
        ;        (= (-> (the-as (inline-array game-save-tag) v1-0) 0 user-uint64) 1)
        ;        )
        ;  )
        ; (((game-save-elt subtitle))
        ;  (set! (-> *setting-control* user-default subtitle)
        ;        (= (-> (the-as (inline-array game-save-tag) v1-0) 0 user-uint64) 1)
        ;        )
        ;  )
        (((game-save-elt flip-horizontal))
         (set! (-> *setting-control* cam-default flip-horizontal)
               (= (-> (the-as (inline-array game-save-tag) v1-0) 0 user-uint64) 1)
               )
         )
        (((game-save-elt flip-vertical))
         (set! (-> *setting-control* cam-default flip-vertical)
               (= (-> (the-as (inline-array game-save-tag) v1-0) 0 user-uint64) 1)
               )
         )
        (((game-save-elt camera-stick-dir))
         (set! (-> *setting-control* user-default camera-stick-dir)
               (= (-> (the-as (inline-array game-save-tag) v1-0) 0 user-uint64) 1)
               )
         )
        (((game-save-elt play-hints))
         (set! (-> *setting-control* user-default play-hints)
               (= (-> (the-as (inline-array game-save-tag) v1-0) 0 user-uint64) 1)
               )
         )
        (((game-save-elt screenx))
         (set! (-> *setting-control* user-default screenx)
               (the int (-> (the-as (inline-array game-save-tag) v1-0) 0 user-float0))
               )
         )
        (((game-save-elt screeny))
         (set! (-> *setting-control* user-default screeny)
               (the int (-> (the-as (inline-array game-save-tag) v1-0) 0 user-float0))
               )
         )
        (((game-save-elt brightness))
         (set! (-> *setting-control* user-default brightness)
               (-> (the-as (inline-array game-save-tag) v1-0) 0 user-float0)
               )
         )
        (((game-save-elt contrast))
         (set! (-> *setting-control* user-default contrast)
               (-> (the-as (inline-array game-save-tag) v1-0) 0 user-float0)
               )
         )
        )
      (set! v1-0 (&+
                   (the-as pointer v1-0)
                   (logand -16 (+ (* (the-as int (-> (the-as (inline-array game-save-tag) v1-0) 0 elt-size))
                                     (-> (the-as (inline-array game-save-tag) v1-0) 0 elt-count)
                                     )
                                  31
                                  )
                           )
                   )
            )
      )
    )
  (when (nonzero? (-> arg0 new-game))
    (case (-> arg0 new-game)
      ((2)
       (set! (-> this gem) (-> arg0 gem-count))
       (set! (-> this skill) (-> arg0 skill-count))
       (set! (-> this purchase-secrets)
             (the-as game-secrets (logior (-> arg0 secrets 0) (shl (-> arg0 secrets 1) 32)))
             )
       (set! (-> this secrets)
             (the-as game-secrets (logior (-> arg0 purchase-secrets 0) (shl (-> arg0 purchase-secrets 1) 32)))
             )
       (logior! (-> this secrets) (game-secrets hero-mode))
       (logior! (-> this purchase-secrets) (game-secrets hero-mode))
       )
      )
    (task-close! "arena-training-1-introduction")
    (set-continue! this "game-start" #f)
    (set! arg0 arg0)
    (goto cfg-257)
    )
  (let ((s4-0 (the-as object (-> arg0 tag)))
        (s3-0 (new 'stack-no-clear 'array 'uint16 512))
        )
    (dotimes (v1-17 512)
      (set! (-> s3-0 v1-17) (the-as uint -1))
      )
    (while (< (the-as int s4-0) (the-as int (&-> arg0 tag 0 user-int8 (-> arg0 length))))
      (case (-> (the-as game-save-tag s4-0) elt-type)
        (((game-save-elt node-name))
         (dotimes (s2-0 (-> (the-as game-save-tag s4-0) elt-count))
           (dotimes (s1-0 (-> this sub-task-list length))
             (let ((v1-23 (-> this sub-task-list s1-0)))
               (when (string-charp= (-> v1-23 name) (the-as (pointer uint8) (+ (+ (* s2-0 64) 16) (the-as int s4-0))))
                 (set! (-> s3-0 s2-0) (the-as uint s1-0))
                 (goto cfg-55)
                 )
               )
             )
           (label cfg-55)
           )
         )
        (((game-save-elt base-time))
         )
        (((game-save-elt game-time))
         (load! (-> *display* game-clock) (&-> (&+ (the-as game-save-tag s4-0) 16) user-uint64))
         (set! (-> *game-info* kiosk-timeout) (-> *display* game-clock frame-counter))
         )
        (((game-save-elt total-game-time))
         (load! (-> *display* total-game-clock) (&-> (&+ (the-as game-save-tag s4-0) 16) user-uint64))
         (set! (-> *game-info* kiosk-timeout) (-> *display* game-clock frame-counter))
         )
        (((game-save-elt continue))
         (format (clear *temp-string*) "~G" (&+ (the-as game-save-tag s4-0) 16))
         (set-continue! this *temp-string* #t)
         )
        (((game-save-elt resetter-node))
         (format (clear *temp-string*) "~G" (&+ (the-as game-save-tag s4-0) 16))
         (let ((a0-70 (task-node-index-by-name *temp-string*)))
           (if (nonzero? a0-70)
               (task-node-open! (the-as game-task-node a0-70) 'life)
               )
           )
         )
        (((game-save-elt life))
         (set! (-> this life) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt buzzer-total))
         (set! (-> this buzzer-total) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt fuel-cell))
         (set! (-> this fuel) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt death-movie-tick))
         (set! (-> this death-movie-tick) (the-as int (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt skill))
         (set! (-> this skill) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt skill-total))
         (set! (-> this skill-total) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt skill-high-watermark))
         (set! (-> this skill-high-watermark) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt gem))
         (set! (-> this gem) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt gem-total))
         (set! (-> this gem-total) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt karma))
         (set! (-> this karma) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt eco-pill-dark))
         (set! (-> this eco-pill-dark) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt eco-pill-dark-total))
         (set! (-> this eco-pill-dark-total) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt eco-pill-light))
         (set! (-> this eco-pill-light) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt eco-pill-light-total))
         (set! (-> this eco-pill-light-total) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt shield))
         (set! (-> this shield) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt features))
         (set! (-> this features) (the-as game-feature (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt vehicles))
         (set! (-> this vehicles) (the-as game-vehicles (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt vehicle))
         (set! (-> this current-vehicle) (the-as vehicle-type-u8 (-> (the-as game-save-tag s4-0) user-uint8 0)))
         )
        (((game-save-elt items))
         (set! (-> this items) (the-as game-items (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt secrets))
         (set! (-> this secrets) (the-as game-secrets (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt purchase-secrets))
         (set! (-> this purchase-secrets) (the-as game-secrets (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt gun-type))
         (set! (-> this gun-type) (the-as pickup-type (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt gun-ammo))
         (let ((v1-78 (min 4 (-> (the-as game-save-tag s4-0) elt-count))))
           (dotimes (a0-118 v1-78)
             (set! (-> this gun-ammo a0-118) (the-as float (-> (&+ (the-as game-save-tag s4-0) 16) user-object a0-118)))
             )
           )
         )
        (((game-save-elt enemies-killed))
         (set! (-> this enemies-killed) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt civilians-killed))
         (set! (-> this civilians-killed) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt marauders-killed))
         (set! (-> this marauders-killed) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt crates-opened))
         (set! (-> this crates-opened) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt health-collected))
         (set! (-> this health-collected) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt board-time))
         (set! (-> this board-time) (the-as time-frame (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt shot-info))
         (let ((v1-88 (min 8 (-> (the-as game-save-tag s4-0) elt-count))))
           (dotimes (a0-134 v1-88)
             (set! (-> this shots-fired a0-134)
                   (the-as float (-> (&+ (the-as game-save-tag s4-0) 16) user-object (* a0-134 2)))
                   )
             (set! (-> this shots-hit a0-134)
                   (the-as float (-> (&+ (the-as game-save-tag s4-0) 16) user-object (+ (* a0-134 2) 1)))
                   )
             )
           )
         )
        (((game-save-elt money))
         (set! (-> this money) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt money-total))
         (set! (-> this money-total) (-> (the-as game-save-tag s4-0) user-float0))
         )
        (((game-save-elt level-open-list))
         (let ((v1-94 (min 32 (-> (the-as game-save-tag s4-0) elt-count))))
           (dotimes (a0-142 v1-94)
             (set! (-> this level-opened a0-142)
                   (-> (the-as (pointer uint8) (&+ (the-as pointer (&+ (the-as game-save-tag s4-0) 16)) a0-142)))
                   )
             )
           )
         )
        (((game-save-elt perm-list))
         (let ((s2-4 (min (-> (the-as game-save-tag s4-0) elt-count) (-> this perm-list allocated-length))))
           (set! (-> this perm-list length) s2-4)
           (dotimes (s1-1 s2-4)
             (mem-copy!
               (the-as pointer (-> this perm-list data s1-1))
               (the-as pointer (+ (the-as uint (&+ (the-as game-save-tag s4-0) 16)) (* s1-1 16)))
               16
               )
             )
           )
         )
        (((game-save-elt task-list))
         (let ((s2-6 (min (-> (the-as game-save-tag s4-0) elt-count) (-> this task-perm-list allocated-length))))
           (set! (-> this task-perm-list length) s2-6)
           (dotimes (s1-2 s2-6)
             (mem-copy!
               (the-as pointer (-> this task-perm-list data s1-2))
               (the-as pointer (+ (the-as uint (&+ (the-as game-save-tag s4-0) 16)) (* s1-2 16)))
               16
               )
             )
           )
         )
        (((game-save-elt talker-state))
         (let ((v1-116 (-> this talker-state allocated-length))
               (a0-153 (-> (the-as game-save-tag s4-0) elt-count))
               )
           (dotimes (a1-82 v1-116)
             (cond
               ((>= a1-82 a0-153)
                (set! (-> this talker-state a1-82) (the-as uint 0))
                0
                )
               (else
                 (set! (-> this talker-state a1-82) (-> (&+ (the-as game-save-tag s4-0) 16) user-uint16 a1-82))
                 )
               )
             )
           )
         )
        (((game-save-elt scores))
         (let ((v1-120 (-> this game-score allocated-length))
               (a0-156 (-> (the-as game-save-tag s4-0) elt-count))
               )
           (dotimes (a1-83 v1-120)
             (if (>= a1-83 a0-156)
                 (set! (-> this game-score a1-83) 0.0)
                 (set! (-> this game-score a1-83) (the-as float (-> (&+ (the-as game-save-tag s4-0) 16) user-object a1-83)))
                 )
             )
           )
         )
        (((game-save-elt auto-save-count))
         (set! (-> this auto-save-count) (the-as int (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt total-deaths))
         (set! (-> this total-deaths) (the-as int (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt total-trys))
         (set! (-> this total-trys) (the-as int (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt continue-deaths))
         (set! (-> this continue-deaths) (the-as int (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt task-deaths))
         (set! (-> this task-deaths) (the-as int (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt game-start-time))
         (set! (-> this game-start-time) (the-as time-frame (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt continue-time))
         (set! (-> this continue-time) (the-as time-frame (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt death-time))
         (set! (-> this death-time) (the-as time-frame (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt hit-time))
         (set! (-> this hit-time) (the-as time-frame (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt task-pickup-time))
         (set! (-> this task-pickup-time) (the-as time-frame (-> (the-as game-save-tag s4-0) user-uint64)))
         )
        (((game-save-elt enter-level-time))
         (let ((v1-134 (min 32 (-> (the-as game-save-tag s4-0) elt-count))))
           (dotimes (a0-180 v1-134)
             (set! (-> this task-enter-times a0-180)
                   (the-as
                     time-frame
                     (-> (the-as (pointer uint64) (+ (the-as uint (&+ (the-as game-save-tag s4-0) 16)) (* a0-180 8))))
                     )
                   )
             )
           )
         )
        (((game-save-elt in-level-time))
         (let ((v1-138 (min 32 (-> (the-as game-save-tag s4-0) elt-count))))
           (dotimes (a0-184 v1-138)
             (set! (-> this task-in-times a0-184)
                   (the-as
                     time-frame
                     (-> (the-as (pointer uint64) (+ (the-as uint (&+ (the-as game-save-tag s4-0) 16)) (* a0-184 8))))
                     )
                   )
             )
           )
         )
        (((game-save-elt task-complete-time))
         (let ((v1-142 (min 32 (-> (the-as game-save-tag s4-0) elt-count))))
           (dotimes (a0-188 v1-142)
             (set! (-> this task-complete-time a0-188)
                   (the-as
                     time-frame
                     (-> (the-as (pointer uint64) (+ (the-as uint (&+ (the-as game-save-tag s4-0) 16)) (* a0-188 8))))
                     )
                   )
             )
           )
         )
        (((game-save-elt task-start-time))
         (let ((v1-146 (min 32 (-> (the-as game-save-tag s4-0) elt-count))))
           (dotimes (a0-192 v1-146)
             (set! (-> this task-start-time a0-192)
                   (the-as
                     time-frame
                     (-> (the-as (pointer uint64) (+ (the-as uint (&+ (the-as game-save-tag s4-0) 16)) (* a0-192 8))))
                     )
                   )
             )
           )
         )
        (((game-save-elt task-node-list))
         (let ((s2-7 (-> (the-as game-save-tag s4-0) elt-count)))
           (dotimes (s1-3 s2-7)
             (if (and (nonzero? (-> (the-as (pointer uint8) (&+ (the-as pointer (&+ (the-as game-save-tag s4-0) 16)) s1-3))))
                      (>= (-> (the-as (pointer int16) (&+ s3-0 (* s1-3 2)))) 0)
                      )
                 (open! (-> this sub-task-list (-> (the-as (pointer int16) (&+ s3-0 (* s1-3 2))))) 'load)
                 )
             )
           )
         )
        (((game-save-elt node-death-count))
         (let ((v1-166 (-> (the-as game-save-tag s4-0) elt-count)))
           (dotimes (a0-199 v1-166)
             (if (>= (-> (the-as (pointer int16) (&+ s3-0 (* a0-199 2)))) 0)
                 (set! (-> this sub-task-list (-> (the-as (pointer int16) (&+ s3-0 (* a0-199 2)))) death-count)
                       (-> (&+ (the-as game-save-tag s4-0) 16) user-uint16 a0-199)
                       )
                 )
             )
           )
         )
        (((game-save-elt node-gem-count))
         (let ((v1-169 (-> (the-as game-save-tag s4-0) elt-count)))
           (dotimes (a0-202 v1-169)
             (if (>= (-> (the-as (pointer int16) (&+ s3-0 (* a0-202 2)))) 0)
                 (set! (-> this sub-task-list (-> (the-as (pointer int16) (&+ s3-0 (* a0-202 2)))) gem-count)
                       (-> (&+ (the-as game-save-tag s4-0) 16) user-uint16 a0-202)
                       )
                 )
             )
           )
         )
        (((game-save-elt node-skill-count))
         (let ((v1-172 (-> (the-as game-save-tag s4-0) elt-count)))
           (dotimes (a0-205 v1-172)
             (if (>= (-> (the-as (pointer int16) (&+ s3-0 (* a0-205 2)))) 0)
                 (set! (-> this sub-task-list (-> (the-as (pointer int16) (&+ s3-0 (* a0-205 2)))) skill-count)
                       (-> (&+ (the-as game-save-tag s4-0) 16) user-uint16 a0-205)
                       )
                 )
             )
           )
         )
        (((game-save-elt node-close-time))
         (let ((v1-176 (-> (the-as game-save-tag s4-0) elt-count)))
           (dotimes (a0-207 v1-176)
             (if (>= (-> (the-as (pointer int16) (&+ s3-0 (* a0-207 2)))) 0)
                 (set! (-> this sub-task-list (-> (the-as (pointer int16) (&+ s3-0 (* a0-207 2)))) close-time)
                       (-> (the-as (pointer uint64) (+ (the-as uint (&+ (the-as game-save-tag s4-0) 16)) (* a0-207 8))))
                       )
                 )
             )
           )
         )
        )
      (set! s4-0
            (&+
              (the-as pointer s4-0)
              (logand -16
                      (+ (* (the-as int (-> (the-as game-save-tag s4-0) elt-size)) (-> (the-as game-save-tag s4-0) elt-count)) 31)
                      )
              )
            )
      )
    )
  (dotimes (s4-1 (-> *level* length))
    (let ((a1-126 (-> *level* level s4-1)))
      (if (= (-> a1-126 status) 'active)
          (copy-perms-to-level! this a1-126)
          )
      )
    )
  (label cfg-257)
  arg0
  )

(defmethod save-to-file ((this game-save) (arg0 string))
  (let ((s5-0 (new 'stack 'file-stream arg0 'write)))
    (file-stream-write s5-0 (&-> this type) (+ (-> this type size) (-> this length)))
    (file-stream-close s5-0)
    )
  this
  )

(defmethod load-from-file ((this game-save) (arg0 string))
  (let ((s5-0 (new 'stack 'file-stream arg0 'read)))
    (let ((s3-0 (file-stream-length s5-0))
          (s4-0 (-> this allocated-length))
          )
      (cond
        ((>= (asize-of this) s3-0)
         (cond
           ((= (file-stream-read s5-0 (&-> this type) s3-0) s3-0)
            (set! (-> this type) game-save)
            )
           (else
             (format 0 "ERROR: SAVEGAME: save file ~A did not read correctly.~%" s5-0)
             (set! (-> this length) 0)
             0
             )
           )
         )
        (else
          (format 0 "ERROR: SAVEGAME: save file ~A is too big~%" s5-0)
          )
        )
      (set! (-> this allocated-length) s4-0)
      )
    (when (!= (-> this version) 4)
      (format
        0
        "ERROR: SAVEGAME: save file ~A was version ~d, but only ~d is supported.~%"
        s5-0
        (-> this version)
        4
        )
      (set! (-> this length) 0)
      0
      )
    (file-stream-close s5-0)
    )
  this
  )

(define *auto-save-info* (new 'global 'mc-slot-info))

(deftype auto-save (process)
  ((card                       int32)
   (slot                       int32)
   (which                      int32)
   (buffer                     kheap)
   (mode                       symbol)
   (starting-auto-save-status  basic)
   (result                     mc-status-code)
   (save                       game-save)
   (info                       mc-slot-info  :inline)
   (notify                     handle)
   (force                      symbol)
   (state-time                 time-frame)
   (icon                       hud-sprite    :inline)
   (icon-gui-id                uint32)
   (message-gui-id             uint32)
   )
  (:state-methods
    get-heap
    get-card
    format-card
    unformat-card
    create-file
    save
    restore
    (error mc-status-code)
    done
    )
  )


(defbehavior auto-save-post auto-save ()
  (when (and (= *cheat-mode* 'debug) (cpad-hold? 0 l3))
    (let ((gp-0
            (new 'stack 'font-context *font-default-matrix* 32 320 0.0 (font-color default) (font-flags shadow kerning))
            )
          )
      (set-width! gp-0 440)
      (set-height! gp-0 80)
      (set! (-> gp-0 flags) (font-flags shadow kerning))
      (format (clear *temp-string*) "~S / ~S ~D~%" (-> self mode) (-> self state name) (-> self which))
      (print-game-text *temp-string* gp-0 #f 44 (bucket-id hud-draw-hud-alpha))
      )
    )
  (when (and (= (-> self mode) 'auto-save) (not (and (-> self next-state) (= (-> self next-state name) 'done))))
    (let ((gp-1
            (new 'stack 'font-context *font-default-matrix* 20 80 0.0 (font-color default) (font-flags shadow kerning))
            )
          )
      (set-scale! gp-1 0.8)
      (set-width! gp-1 432)
      (set-height! gp-1 20)
      (set! (-> gp-1 flags) (font-flags shadow kerning middle middle-vert large))
      (when (and (>= 1 (-> *game-info* auto-save-count))
                 (and (-> self next-state) (= (-> self next-state name) 'save))
                 (begin
                   (if (zero? (-> self message-gui-id))
                       (set! (-> self message-gui-id)
                             (the-as
                               uint
                               (add-process
                                 *gui-control*
                                 self
                                 (gui-channel hud-auto-save-message)
                                 (gui-action play)
                                 (-> self name)
                                 81920.0
                                 0
                                 )
                               )
                             )
                       )
                   (= (get-status *gui-control* (the-as sound-id (-> self message-gui-id))) (gui-status active))
                   )
                 )
        (print-game-text
          (lookup-text! *common-text* (text-id progress-memcard-saving) #f)
          gp-1
          #f
          44
          (bucket-id hud-draw-hud-alpha)
          )
        (set! (-> gp-1 origin x) 20.0)
        (set! (-> gp-1 origin y) 130.0)
        (set-scale! gp-1 0.7)
        (set-height! gp-1 200)
        (let ((s5-2 print-game-text))
          (format (clear *temp-string*) (lookup-text! *common-text* (text-id progress-memcard-remove-warn) #f) 1)
          (s5-2 *temp-string* gp-1 #f 44 (bucket-id hud-draw-hud-alpha))
          )
        )
      )
    (when (and (< (mod (-> *display* real-clock frame-counter) 300) 270)
               (= (get-status *gui-control* (the-as sound-id (-> self icon-gui-id))) (gui-status active))
               )
      (let* ((s5-3 (-> *display* frames (-> *display* on-screen) global-buf))
             (gp-2 (-> s5-3 base))
             )
        (draw (-> self icon) s5-3 (-> self level) #f)
        (let ((a3-8 (-> s5-3 base)))
          (when (!= gp-2 a3-8)
            (let ((v1-55 (the-as object (-> s5-3 base))))
              (set! (-> (the-as dma-packet v1-55) dma) (new 'static 'dma-tag :id (dma-tag-id next)))
              (set! (-> (the-as dma-packet v1-55) vif0) (new 'static 'vif-tag))
              (set! (-> (the-as dma-packet v1-55) vif1) (new 'static 'vif-tag))
              (set! (-> s5-3 base) (&+ (the-as pointer v1-55) 16))
              )
            (dma-bucket-insert-tag
              (-> *display* frames (-> *display* on-screen) bucket-group)
              (bucket-id hud-draw-hud-alpha)
              gp-2
              (the-as (pointer dma-tag) a3-8)
              )
            )
          )
        )
      )
    )
  )

(defbehavior auto-save-init-by-other auto-save ((arg0 symbol) (arg1 process) (arg2 int) (arg3 int) (arg4 symbol))
  (when (handle->process (-> *game-info* auto-save-proc))
    (send-event arg1 'notify 'error (mc-status-code no-process))
    (return #f)
    )
  (set! (-> *game-info* auto-save-proc) (process->handle self))
  (set! (-> *game-info* auto-save-status) (mc-status-code ok))
  (stack-size-set! (-> self main-thread) 512)
  (logclear! (-> self mask) (process-mask freeze pause menu progress))
  (set! (-> self card) arg2)
  (set! (-> self which) arg3)
  (set! (-> self buffer) #f)
  (set! (-> self mode) arg0)
  (set! (-> self result) (mc-status-code ok))
  (set! (-> self save) #f)
  (set! (-> self notify) (process->handle arg1))
  (set! (-> self force) arg4)
  (cond
    ((= arg0 'auto-save)
     (if (not (-> *setting-control* user-current auto-save))
         (go-virtual error (mc-status-code no-auto-save))
         )
     (when (and (zero? (-> self card)) (-> *setting-control* user-current auto-save))
       (set! (-> self card) (-> *game-info* auto-save-card))
       (set! (-> self which) (-> *game-info* auto-save-which))
       )
     (set-setting! 'allow-pause #f 0.0 0)
     (apply-settings *setting-control*)
     )
    ((= arg0 'restore)
     (set-setting! 'music-volume 'abs 0.0 0)
     (set-setting! 'sfx-volume 'abs 0.0 0)
     (set-setting! 'dialog-volume 'abs 0.0 0)
     )
    ((= arg0 'error)
     (set! (-> *setting-control* user-default auto-save) #f)
     (go-virtual error (mc-status-code no-card))
     )
    )
  (set! (-> self starting-auto-save-status) (the-as basic (-> *setting-control* user-default auto-save)))
  (set! (-> *setting-control* user-default auto-save) #f)
  (let ((v1-61 (-> self icon color-ptr)))
    (set! (-> v1-61 0) 128)
    (set! (-> v1-61 1) 128)
    (set! (-> v1-61 2) 128)
    (set! (-> v1-61 3) 128)
    )
  (set! (-> self icon pos x) 440)
  (set! (-> self icon pos y) 210)
  (set! (-> self icon pos z) #xffffff)
  (set! (-> self icon pos w) 0)
  (set! (-> self icon scale-x) 2.0)
  (set! (-> self icon scale-y) 2.0)
  (set! (-> self icon angle) 0.0)
  (set! (-> self icon flags) (hud-sprite-flags))
  (set! (-> self icon tid) (the-as texture-id (get-texture checkpoint level-default-minimap)))
  (go-virtual get-heap)
  )

(defstate get-heap (auto-save)
  :virtual #t
  :code (behavior ()
    (case (-> self mode)
      (('auto-save)
       (when (zero? (-> *game-info* auto-save-count))
         (set! (-> self event-hook) (-> (method-of-object self error) event))
         (set! (-> self post-hook) #f)
         (set! (-> self state-time) (-> *display* real-clock frame-counter))
         (while (< (- (-> *display* real-clock frame-counter) (-> self state-time)) (seconds 0.2))
           (if (not (progress-allowed?))
               (set! (-> self state-time) (-> *display* real-clock frame-counter))
               )
           (suspend)
           )
         ;; og:preserve-this disable auto-save prompt in speedrunner mode
         (when (not (-> *pc-settings* speedrunner-mode?))
          (activate-progress *dproc* 'icon-info))
         (while *progress-process*
           (suspend)
           )
         (set! (-> self event-hook) #f)
         )
       (set! (-> self icon-gui-id)
             (the-as
               uint
               (add-process *gui-control* self (gui-channel hud-auto-save) (gui-action play) (-> self name) 81920.0 0)
               )
             )
       (+! (-> *game-info* auto-save-count) 1)
       )
      )
    (while (or (< (-> *display* base-clock frame-counter) (-> *game-info* blackout-time))
               (!= (-> *setting-control* user-current bg-a) 0.0)
               (!= (-> *setting-control* user-current bg-a-force) 0.0)
               )
      (suspend)
      )
    (set! (-> self state-time) (-> *display* real-clock frame-counter))
    (let ((a0-10 (reserve-alloc *art-control*)))
      (while (not a0-10)
        (if (>= (- (-> *display* real-clock frame-counter) (-> self state-time)) (seconds 60))
            (go-virtual error (mc-status-code no-memory))
            )
        (suspend)
        (set! a0-10 (reserve-alloc *art-control*))
        )
      (set! (-> self buffer) a0-10)
      )
    (format #t "got buffer #x~X~%" (-> self buffer base))
    (go-virtual get-card)
    )
  :post auto-save-post
  )

(defstate get-card (auto-save)
  :virtual #t
  :code (behavior ()
    (label cfg-0)
    (mc-get-slot-info (-> self slot) (-> self info))
    (when (zero? (-> self info known))
      (suspend)
      (goto cfg-0)
      )
    (cond
      ((zero? (-> self info handle))
       (go-virtual error (mc-status-code no-card))
       )
      ((zero? (-> self card))
       (set! (-> self card) (the-as int (-> self info handle)))
       )
      ((!= (-> self info handle) (-> self card))
       (go-virtual error (mc-status-code bad-handle))
       )
      )
    (case (-> self mode)
      (('save 'auto-save)
       (if (-> self force)
           (go-virtual format-card)
           (go-virtual save)
           )
       )
      (('save-last)
       (set! (-> self which) (-> self info last-file))
       (if (= (-> self which) -1)
           (go-virtual error (mc-status-code no-last))
           (go-virtual save)
           )
       )
      (('restore)
       (go-virtual restore)
       )
      (('format-card)
       (go-virtual format-card)
       )
      (('unformat-card)
       (go-virtual unformat-card)
       )
      (('create-file)
       (go-virtual create-file)
       )
      (else
        (go-virtual done)
        )
      )
    )
  :post auto-save-post
  )

(defstate format-card (auto-save)
  :virtual #t
  :code (behavior ()
    (b! (nonzero? (-> self info formatted)) cfg-11 :delay (empty-form))
    (label cfg-1)
    (set! (-> self result) (mc-format (-> self card)))
    (when (!= (-> self result) (mc-status-code ok))
      (suspend)
      (goto cfg-1)
      )
    (until #f
      (set! (-> self result) (mc-check-result))
      (let ((v1-4 (-> self result)))
        (b! (nonzero? v1-4) cfg-5 :delay (nop!))
        (b! #t cfg-10 :delay (nop!))
        (label cfg-5)
        (b! (= v1-4 (mc-status-code format-failed)) cfg-1 :delay (nop!))
        (nop!)
        (if (= v1-4 (mc-status-code ok))
            (goto cfg-11)
            (go-virtual error (-> self result))
            )
        )
      (label cfg-10)
      (suspend)
      )
    #f
    (label cfg-11)
    (case (-> self mode)
      (('create-file 'save 'save-last 'auto-save 'restore)
       (label cfg-21)
       (mc-get-slot-info (-> self slot) (-> self info))
       (when (zero? (-> self info known))
         (suspend)
         (goto cfg-21)
         )
       (go-virtual create-file)
       )
      )
    (go-virtual done)
    )
  :post auto-save-post
  )

(defstate unformat-card (auto-save)
  :virtual #t
  :code (behavior ()
    (when (nonzero? (-> self info formatted))
      (label cfg-1)
      (set! (-> self result) (mc-unformat (-> self card)))
      (when (!= (-> self result) (mc-status-code ok))
        (suspend)
        (goto cfg-1)
        )
      (until #f
        (set! (-> self result) (mc-check-result))
        (case (-> self result)
          (((mc-status-code busy))
           )
          (((mc-status-code ok))
           (goto cfg-10)
           )
          (else
            (go-virtual error (-> self result))
            )
          )
        (suspend)
        )
      #f
      )
    (label cfg-10)
    (go-virtual done)
    )
  :post auto-save-post
  )

(defstate create-file (auto-save)
  :virtual #t
  :code (behavior ()
    (cond
      ((zero? (-> self info formatted))
       (go-virtual error (mc-status-code no-format))
       )
      ((zero? (-> self info inited))
       (if (< (-> self info mem-actual) (-> self info mem-required))
           (go-virtual error (mc-status-code no-space))
           )
       (let ((v1-12 (-> self buffer)))
         (set! (-> v1-12 current) (-> v1-12 base))
         )
       (label cfg-6)
       (set! (-> self result) (mc-create-file (-> self card) (the-as uint (-> self buffer base))))
       (when (!= (-> self result) (mc-status-code ok))
         (suspend)
         (goto cfg-6)
         )
       (until #f
         (set! (-> self result) (mc-check-result))
         (case (-> self result)
           (((mc-status-code busy))
            )
           (((mc-status-code ok))
            (goto cfg-15)
            )
           (else
             (go-virtual error (-> self result))
             )
           )
         (suspend)
         )
       #f
       )
      )
    (label cfg-15)
    (case (-> self mode)
      (('restore)
       (go-virtual restore)
       )
      (('save 'save-last 'auto-save)
       (label cfg-23)
       (mc-get-slot-info (-> self slot) (-> self info))
       (when (zero? (-> self info known))
         (suspend)
         (goto cfg-23)
         )
       (go-virtual save)
       )
      )
    (go-virtual done)
    )
  :post auto-save-post
  )

(defstate save (auto-save)
  :virtual #t
  :code (behavior ()
    (cond
      ((zero? (-> self info formatted))
       (go-virtual error (mc-status-code no-format))
       )
      ((zero? (-> self info inited))
       (go-virtual error (mc-status-code no-file))
       )
      )
    (let ((v1-10 (-> self buffer)))
      (set! (-> v1-10 current) (-> v1-10 base))
      )
    (let ((gp-0 (the-as object loading-level)))
      (set! loading-level (-> self buffer))
      (set! (-> self save) (new 'loading-level 'game-save #x1e000))
      (save-game *game-info* (-> self save) "save")
      (set! loading-level (the-as kheap gp-0))
      0
      (label cfg-5)
      (set! (-> self result)
            (mc-save (-> self card) (-> self which) (&-> self save type) (the-as int (-> self save info-int32)))
            )
      (when (!= (-> self result) (mc-status-code ok))
        (suspend)
        (goto cfg-5)
        )
      (until #f
        (set! (-> self result) (mc-check-result))
        (let ((v1-20 (-> self result)))
          (set! gp-0 (cond
                       ((= v1-20 (mc-status-code busy))
                        #f
                        )
                       ((= v1-20 (mc-status-code ok))
                        (goto cfg-18)
                        gp-0
                        )
                       ((= v1-20 (mc-status-code write-error))
                        (suspend)
                        gp-0
                        )
                       (else
                         (case (-> self mode)
                           (('auto-save)
                            (seekl! (-> *game-info* auto-save-count) 0 1)
                            )
                           )
                         (go-virtual error (-> self result))
                         )
                       )
                )
          )
        (suspend)
        )
      )
    #f
    (label cfg-18)
    (go-virtual done)
    )
  :post auto-save-post
  )

(defstate restore (auto-save)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('progress-allowed?)
       #t
       )
      (('done)
       (go-virtual done)
       )
      )
    )
  :code (behavior ()
    (local-vars (s5-0 object))
    (cond
      ((zero? (-> self info formatted))
       (go-virtual error (mc-status-code no-format))
       )
      ((zero? (-> self info inited))
       (go-virtual error (mc-status-code no-file))
       )
      )
    (let ((v1-10 (-> self buffer)))
      (set! (-> v1-10 current) (-> v1-10 base))
      )
    (if (zero? (-> self info file (-> self which) present))
        (go-virtual error (mc-status-code no-save))
        )
    (label cfg-6)
    (set! (-> self result) (mc-load (-> self card) (-> self which) (-> self buffer base)))
    (when (!= (-> self result) (mc-status-code ok))
      (suspend)
      (goto cfg-6)
      )
    (let ((gp-0 0))
      (until #f
        (set! (-> self result) (mc-check-result))
        (case (-> self result)
          (((mc-status-code busy))
           )
          (((mc-status-code ok))
           (goto cfg-23)
           )
          (((mc-status-code read-error))
           (+! gp-0 (- (-> *display* real-clock frame-counter) (-> *display* real-clock old-frame-counter)))
           (set! s5-0 (cond
                        ((< gp-0 300)
                         (suspend)
                         s5-0
                         )
                        (else
                          (go-virtual error (-> self result))
                          )
                        )
                 )
           )
          (((mc-status-code new-game))
           (go-virtual error (mc-status-code no-save))
           )
          (else
            (go-virtual error (-> self result))
            )
          )
        (suspend)
        )
      )
    #f
    (label cfg-23)
    (set! (-> self save) (the-as game-save (&+ (-> self buffer base) 4)))
    (let ((v1-43 (-> self save)))
      (set! (-> v1-43 type) game-save)
      (if (!= (-> v1-43 version) 4)
          (go-virtual error (mc-status-code bad-version))
          )
      )
    (persist-with-delay *setting-control* 'fail-music-volume (seconds 5) 'music-volume 'abs 0.0 0)
    (persist-with-delay *setting-control* 'fail-sfx-volume (seconds 5) 'sfx-volume 'abs 0.0 0)
    (persist-with-delay *setting-control* 'fail-dialog-volume (seconds 5) 'dialog-volume 'abs 0.0 0)
    (set! (-> *game-info* mode) 'play)
    (initialize! *game-info* 'game (-> self save) (the-as string #f) (the-as resetter-spec #f))
    (set-master-mode 'game)
    (add-setting! 'process-mask 'set 0.0 (process-mask progress))
    (apply-settings *setting-control*)
    (sleep-code)
    (go-virtual done)
    )
  :post auto-save-post
  )

(defstate error (auto-save)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('progress-allowed?)
       #t
       )
      (('die)
       (deactivate self)
       )
      )
    )
  :code (behavior ((arg0 mc-status-code))
    (if (-> self buffer)
        (reserve-free *art-control* (-> self buffer))
        )
    (set! (-> self result) arg0)
    (let ((s5-0 *auto-save-info*))
      (mem-copy! (the-as pointer s5-0) (the-as pointer (-> self info)) 300)
      (send-event (handle->process (-> self notify)) 'notify 'error (-> self result) s5-0)
      )
    (let ((t9-3 format)
          (a0-8 #t)
          (a1-3 "SAVE ERROR: ~A~%")
          (v1-13 (-> self result))
          )
      (t9-3 a0-8 a1-3 (cond
                        ((= v1-13 (mc-status-code bad-version))
                         "bad-version"
                         )
                        ((= v1-13 (mc-status-code no-save))
                         "no-save"
                         )
                        ((= v1-13 (mc-status-code no-last))
                         "no-last"
                         )
                        ((= v1-13 (mc-status-code no-space))
                         "no-space"
                         )
                        ((= v1-13 (mc-status-code internal-error))
                         "internal-error"
                         )
                        ((= v1-13 (mc-status-code no-memory))
                         "no-memory"
                         )
                        ((= v1-13 (mc-status-code bad-handle))
                         "bad-handle"
                         )
                        ((= v1-13 (mc-status-code busy))
                         "busy"
                         )
                        ((= v1-13 (mc-status-code write-error))
                         "write-error"
                         )
                        ((= v1-13 (mc-status-code read-error))
                         "read-error"
                         )
                        ((= v1-13 (mc-status-code no-card))
                         "no-card"
                         )
                        ((= v1-13 (mc-status-code no-format))
                         "no-format"
                         )
                        ((= v1-13 (mc-status-code ok))
                         "ok"
                         )
                        ((= v1-13 (mc-status-code no-process))
                         "no-process"
                         )
                        ((= v1-13 (mc-status-code no-auto-save))
                         "no-auto-save"
                         )
                        ((= v1-13 (mc-status-code no-file))
                         "no-file"
                         )
                        ((= v1-13 (mc-status-code format-failed))
                         "format-failed"
                         )
                        ((= v1-13 (mc-status-code new-game))
                         "new-game"
                         )
                        (else
                          "*unknown*"
                          )
                        )
            )
      )
    (if (= (-> self result) (mc-status-code no-auto-save))
        (return #f)
        )
    (case (-> self mode)
      (('auto-save 'error)
       (set! (-> self state-time) (-> *display* real-clock frame-counter))
       (set! (-> *game-info* auto-save-status) arg0)
       (while (< (- (-> *display* real-clock frame-counter) (-> self state-time)) (seconds 0.2))
         (if (not (progress-allowed?))
             (set! (-> self state-time) (-> *display* real-clock frame-counter))
             )
         (suspend)
         )
       (if (= arg0 (mc-status-code no-card))
           (activate-progress *dproc* 'card-removed)
           (activate-progress *dproc* 'error-auto-saving)
           )
       )
      )
    )
  :post auto-save-post
  )

(defstate done (auto-save)
  :virtual #t
  :code (behavior ()
    (if (and (-> self buffer)
             (or (-> *art-control* reserve-buffer) (nonzero? (-> *art-control* dma-reserve-buffer-count)))
             )
        (reserve-free *art-control* (-> self buffer))
        )
    (set! (-> *game-info* auto-save-status) (mc-status-code ok))
    (case (-> self mode)
      (('save 'save-last 'auto-save 'restore)
       (b! (-> *progress-work* hero-mode-save) cfg-17 :delay (empty-form))
       (set! (-> *setting-control* user-default auto-save) #t)
       (set! (-> *game-info* auto-save-card) (-> self card))
       (set! (-> *game-info* auto-save-which) (-> self which))
       (b! #t cfg-26 :delay (nop!))
       (label cfg-17)
       (if (and (-> self starting-auto-save-status)
                (not (and (= (-> *game-info* auto-save-card) (-> self card)) (= (-> *game-info* auto-save-which) (-> self which)))
                     )
                )
           (set! (-> *setting-control* user-default auto-save) #t)
           )
       )
      )
    (label cfg-26)
    (case (-> self mode)
      (('auto-save)
       )
      (else
        (set! (-> *game-info* auto-save-proc) (the-as handle #f))
        )
      )
    (let ((gp-0 *auto-save-info*))
      (mem-copy! (the-as pointer gp-0) (the-as pointer (-> self info)) 300)
      (send-event (handle->process (-> self notify)) 'notify 'done (mc-status-code ok) gp-0)
      )
    )
  :post auto-save-post
  )

;; WARN: Return type mismatch (pointer process) vs (pointer auto-save).
(defun auto-save-command ((arg0 symbol) (arg1 int) (arg2 int) (arg3 process-tree) (arg4 symbol))
  (format #t "AUTO SAVE COMMAND ~S~%" arg0)
  (process-spawn
    auto-save
    arg0
    arg3
    arg1
    arg2
    arg4
    :name "auto-save"
    :to *target-pool*
    :stack *kernel-dram-stack*
    )
  )

(defun auto-save-check ()
  (when (and (-> *setting-control* user-current auto-save) (not (handle->process (-> *game-info* auto-save-proc))))
    (mc-get-slot-info 0 *auto-save-info*)
    (if (and (nonzero? (-> *auto-save-info* known))
             (or (zero? (-> *auto-save-info* handle)) (!= (-> *auto-save-info* handle) (-> *game-info* auto-save-card)))
             (progress-allowed?)
             )
        (auto-save-command 'error 0 0 *default-pool* #f)
        )
    )
  0
  )

(defun auto-save-user ()
  (cond
    ((and *scene-player*
          (not (and (-> *scene-player* 0 next-state) (= (-> *scene-player* 0 next-state name) 'release)))
          )
     (the-as (pointer auto-save) #f)
     )
    (else
      (case *kernel-boot-message*
        (('play 'preview)
         ;; og:preserve-this
         (#when PC_PORT
             (pc-settings-save))
         (auto-save-command 'auto-save 0 0 *default-pool* #f)
         )
        )
      )
    )
  )
