From 8e06fc31acc232a223855bb22213c5ee6e81aaed Mon Sep 17 00:00:00 2001 From: Carlo Field Date: Thu, 9 Apr 2020 11:45:57 +0200 Subject: [PATCH] workaround gearbox' messy inf behaviour --- internal/server/character.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/server/character.go b/internal/server/character.go index 3a37de8..046e139 100644 --- a/internal/server/character.go +++ b/internal/server/character.go @@ -2,6 +2,7 @@ package server import ( "io/ioutil" + "math" "os" "regexp" "strconv" @@ -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}) @@ -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)