From 43e270d58b6bf03d352ba740ee6f71a016f7ee2d Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 10 Nov 2019 13:59:37 +0100 Subject: [PATCH] Add missing types for player block Signed-off-by: Knut Ahlers --- .gitignore | 1 + block_player.go | 2 +- genericMarshaller.go | 47 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4ba68a6..06402c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ cmd/sii-decrypt/sii-decrypt +game.sii diff --git a/block_player.go b/block_player.go index e3e904a..69092d6 100644 --- a/block_player.go +++ b/block_player.go @@ -32,7 +32,7 @@ type Player struct { DrivingTime int64 `sii:"driving_time"` SleepingCount int `sii:"sleeping_count"` FreeRoamDistance int64 `sii:"free_roam_distance"` - DiscoveryDistance float64 `sii:"discovary_distance"` // Typo is intended and copied from real save-game + DiscoveryDistance float32 `sii:"discovary_distance"` // Typo is intended and copied from real save-game DismissedDrivers int `sii:"dismissed_drivers"` Trucks []Ptr `sii:"trucks"` TruckProfitLogs []Ptr `sii:"truck_profit_logs"` diff --git a/genericMarshaller.go b/genericMarshaller.go index a6e6636..6bc4263 100644 --- a/genericMarshaller.go +++ b/genericMarshaller.go @@ -49,6 +49,7 @@ func genericUnmarshal(in []byte, out interface{}) error { if err := v.UnmarshalSII(data); err != nil { return errors.Wrapf(err, "Unable to parse Ptr for attribute %q", attributeName) } + valField.Set(reflect.ValueOf(v)) continue case reflect.TypeOf(Placement{}): @@ -57,6 +58,7 @@ func genericUnmarshal(in []byte, out interface{}) error { if err := v.UnmarshalSII(data); err != nil { return errors.Wrapf(err, "Unable to parse Placement for attribute %q", attributeName) } + valField.Set(reflect.ValueOf(v)) continue } @@ -69,12 +71,12 @@ func genericUnmarshal(in []byte, out interface{}) error { } valField.SetBool(v) - case reflect.Float64: - v, err := strconv.ParseFloat(string(getSingleValue(in, attributeName)), 64) + case reflect.Float32: + v, err := sii2float(getSingleValue(in, attributeName)) if err != nil { return errors.Wrapf(err, "Unable to parse float for attribute %q", attributeName) } - valField.SetFloat(v) + valField.Set(reflect.ValueOf(v)) case reflect.Int, reflect.Int64: v, err := strconv.ParseInt(string(getSingleValue(in, attributeName)), 10, 64) @@ -100,6 +102,34 @@ func genericUnmarshal(in []byte, out interface{}) error { return errors.Wrapf(err, "Unable to fetch array values for attribute %q", attributeName) } + switch typeField.Type.Elem() { + + case reflect.TypeOf(Ptr{}): + var v []Ptr + for _, bv := range ba { + e := Ptr{} + if err := e.UnmarshalSII(bv); err != nil { + return errors.Wrapf(err, "Unable to parse Ptr for attribute %q", attributeName) + } + v = append(v, e) + } + valField.Set(reflect.ValueOf(v)) + continue + + case reflect.TypeOf(Placement{}): + var v []Placement + for _, bv := range ba { + e := Placement{} + if err := e.UnmarshalSII(bv); err != nil { + return errors.Wrapf(err, "Unable to parse Ptr for attribute %q", attributeName) + } + v = append(v, e) + } + valField.Set(reflect.ValueOf(v)) + continue + + } + switch typeField.Type.Elem().Kind() { case reflect.Bool: var v []bool @@ -123,6 +153,17 @@ func genericUnmarshal(in []byte, out interface{}) error { } valField.Set(reflect.ValueOf(v)) + case reflect.Int64: + var v []int64 + for _, bv := range ba { + pbv, err := strconv.ParseInt(string(bv), 10, 64) + if err != nil { + return errors.Wrapf(err, "Unable to parse int for attribute %q", attributeName) + } + v = append(v, pbv) + } + valField.Set(reflect.ValueOf(v)) + case reflect.String: var v []string for _, bv := range ba {