1
0
Fork 0
mirror of https://github.com/Luzifer/sii.git synced 2024-12-20 16:11:17 +00:00

Add missing types for player block

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-11-10 13:59:37 +01:00
parent 122b4a365c
commit 43e270d58b
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 46 additions and 4 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
cmd/sii-decrypt/sii-decrypt
game.sii

View file

@ -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"`

View file

@ -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 {