read the save, the seed and the worldgen assets
The engine's save classes are closed, so the protobuf field numbers were read off the data and matched to the map sizes TerraGenConfig gives. vsmv dump renders what the save stored, as the reference the generator will be diffed against. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
88
src/pb.sex
Normal file
88
src/pb.sex
Normal file
@@ -0,0 +1,88 @@
|
||||
;;; Protobuf wire reader for the blobs in a .vcdbs save. The engine's
|
||||
;;; message classes are closed, so callers walk fields by number and
|
||||
;;; keep only what they know; everything else is skipped.
|
||||
;;;
|
||||
;;; A reader is a window over borrowed bytes. A malformed blob sets
|
||||
;;; `err' and empties the window, so a loop on `more' always ends.
|
||||
|
||||
(pub include stddef.h)
|
||||
(include string.h)
|
||||
|
||||
(pub define WIRE-VARINT 0)
|
||||
(pub define WIRE-FIXED64 1)
|
||||
(pub define WIRE-BYTES 2)
|
||||
(pub define WIRE-FIXED32 5)
|
||||
|
||||
(pub record pb ((p (* const u8)) (end (* const u8)) (err bool)))
|
||||
|
||||
(ops pb
|
||||
(pub fn of ((data (* const void)) (len size-t)) pb
|
||||
(var p (* const u8) data)
|
||||
(return #(pb : p (+ p len) false)))
|
||||
|
||||
(fn fail ((self (* pb))) void
|
||||
(= (. self err) true)
|
||||
(= (. self p) (. self end)))
|
||||
|
||||
(pub fn more ((self (* const pb))) bool
|
||||
(return (< (. self p) (. self end))))
|
||||
|
||||
(pub fn len ((self (* const pb))) size-t
|
||||
(return (cast (- (. self end) (. self p)) size-t)))
|
||||
|
||||
(pub fn varint ((self (* pb))) u64
|
||||
(var v u64 0)
|
||||
(for (var shift int 0) (< shift 64) (+= shift 7)
|
||||
(if (>= (. self p) (. self end))
|
||||
(break))
|
||||
(var b u8 (* (. self p)))
|
||||
(++ (. self p))
|
||||
(c-bit-or= v (<< (cast (& b 127) u64) shift))
|
||||
(if (< b 128)
|
||||
(return v)))
|
||||
(.fail self)
|
||||
(return 0))
|
||||
|
||||
;; A packed or repeated `int' field: negative values arrive as ten
|
||||
;; byte varints and keep their meaning when truncated.
|
||||
(pub fn int32 ((self (* pb))) i32
|
||||
(return (cast (.varint self) i32)))
|
||||
|
||||
;; The next field's number, or 0 at the end. WIRE gets its wire type.
|
||||
(pub fn field ((self (* pb)) (wire (* int))) u32
|
||||
(if (! (.more self))
|
||||
(return 0))
|
||||
(var key u64 (.varint self))
|
||||
(= (* wire) (cast (& key 7) int))
|
||||
(return (cast (>> key 3) u32)))
|
||||
|
||||
;; A length-delimited field as a reader of its own: a submessage, a
|
||||
;; string, or a packed array.
|
||||
(pub fn bytes ((self (* pb))) pb
|
||||
(var len u64 (.varint self))
|
||||
(var p (* const u8) (. self p))
|
||||
(if (> len (.len self))
|
||||
(do
|
||||
(.fail self)
|
||||
(return #(pb : p p true))))
|
||||
(+= (. self p) len)
|
||||
(return #(pb : p (+ p len) false)))
|
||||
|
||||
;; True when the rest of the window spells exactly S, e.g. a map
|
||||
;; entry's key against "riverDistance".
|
||||
(pub fn equals ((self (* const pb)) (s (* const char))) bool
|
||||
(var n size-t (.len self))
|
||||
(return (&& (== (strlen s) n) (== (memcmp (. self p) s n) 0))))
|
||||
|
||||
(fn advance ((self (* pb)) (n size-t)) void
|
||||
(if (> n (.len self))
|
||||
(.fail self)
|
||||
(+= (. self p) n)))
|
||||
|
||||
(pub fn skip ((self (* pb)) (wire int)) void
|
||||
(switch wire
|
||||
(case WIRE-VARINT (.varint self) (break))
|
||||
(case WIRE-BYTES (.bytes self) (break))
|
||||
(case WIRE-FIXED64 (.advance self 8) (break))
|
||||
(case WIRE-FIXED32 (.advance self 4) (break))
|
||||
(default (.fail self)))))
|
||||
Reference in New Issue
Block a user