Skip to content

Commit

Permalink
workaround gearbox' messy inf behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
cfi2017 committed Apr 9, 2020
1 parent 92ef37e commit 8e06fc3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion internal/server/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"io/ioutil"
"math"
"os"
"regexp"
"strconv"
Expand Down Expand Up @@ -47,7 +48,15 @@ func getCharacter(c *gin.Context) {
}
defer f.Close()
s, char := character.Deserialize(f)
c.JSON(200, struct {

// workaround for invalid json parsing values
for _, d := range char.GbxZoneMapFodSaveGameData.LevelData {
if *d.DiscoveryPercentage > math.MaxFloat32 {
*d.DiscoveryPercentage = -1
}
}

c.JSON(200, &struct {
Save shared.SavFile `json:"save"`
Character pb.Character `json:"character"`
}{Save: s, Character: char})
Expand All @@ -66,6 +75,12 @@ func updateCharacter(c *gin.Context) {
c.AbortWithStatus(500)
return
}
// workaround for invalid json parsing values
for _, d := range d.Character.GbxZoneMapFodSaveGameData.LevelData {
if *d.DiscoveryPercentage == -1 {
*d.DiscoveryPercentage = math.Float32frombits(0x7F800000) // inf
}
}
f, err := os.Create(pwd + "/" + id + ".sav")
if err != nil {
c.AbortWithStatus(500)
Expand Down

0 comments on commit 8e06fc3

Please sign in to comment.