Skip to content

Commit

Permalink
remove legacy code from when using proto2
Browse files Browse the repository at this point in the history
  • Loading branch information
cfi2017 committed Apr 14, 2020
1 parent 8c63d91 commit 5a28760
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 9,861 deletions.
57 changes: 57 additions & 0 deletions cmd/convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cmd

import (
"encoding/base64"
"encoding/json"
"log"

"github.com/cfi2017/bl3-save/internal/item"
"github.com/spf13/cobra"
)

type DigitalMarineItem struct {
CopyType string `json:"copyType"`
Level int `json:"level"`
Blueprint string `json:"blueprint"`
Balance string `json:"balance"`
Manufacturer string `json:"manufacturer"`
ComponentNames []string `json:"componentNames"`
Components []int `json:"components"`
}

// deserializeCmd represents the deserialize command
var convertCmd = &cobra.Command{
Use: "convert",
Short: "Convert an item from gibbed to digital_marine or vice versa",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
bs, err := base64.StdEncoding.DecodeString(args[0])
if err != nil {
panic(err)
}
var dmi DigitalMarineItem
err = json.Unmarshal(bs, &dmi)
if err != nil {
// try deserializing item
item, err := item.Deserialize(bs)
if err != nil {
panic(err)
}
log.Println(item)
// convert to dm item
}
},
}

func init() {
rootCmd.AddCommand(convertCmd)
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// deserializeCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// deserializeCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
30 changes: 13 additions & 17 deletions internal/server/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/base64"
"io/ioutil"
"log"
"math"
"os"
"regexp"
"strconv"
Expand Down Expand Up @@ -56,13 +55,6 @@ func getCharacterRequest(c *gin.Context) {
defer f.Close()
s, char := character.Deserialize(f)

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

c.JSON(200, &struct {
Save shared.SavFile `json:"save"`
Character pb.Character `json:"character"`
Expand All @@ -82,12 +74,7 @@ func updateCharacterRequest(c *gin.Context) {
c.AbortWithStatus(500)
return
}
// workaround for invalid json parsing values
for _, d := range d.Character.GbxZoneMapFodSaveGameData.LevelData {
if d.DiscoveryPercentage != nil && *d.DiscoveryPercentage == -1 {
*d.DiscoveryPercentage = math.Float32frombits(0x7F800000) // inf
}
}

backup(pwd, id)
f, err := getSaveById(id)
if err != nil {
Expand Down Expand Up @@ -117,8 +104,8 @@ func listChar(id string) (char CharInfo, err error) {
}
defer f.Close()
_, c := character.Deserialize(f)
char.Name = *c.PreferredCharacterName
char.Experience = *c.ExperiencePoints
char.Name = c.PreferredCharacterName
char.Experience = c.ExperiencePoints
return
}

Expand Down Expand Up @@ -155,8 +142,12 @@ func updateItemsRequest(c *gin.Context) {
c.AbortWithStatus(500)
return
}
defer f.Close()
s, char := character.Deserialize(f)
err = f.Close()
if err != nil {
c.AbortWithStatus(500)
return
}
var items []item.Item
err = c.BindJSON(&items)
if err != nil {
Expand All @@ -169,6 +160,11 @@ func updateItemsRequest(c *gin.Context) {
c.AbortWithStatus(500)
return
}
f, err = os.Create(pwd + "/" + id + ".sav")
if err != nil {
c.AbortWithStatus(500)
return
}
character.Serialize(f, s, char)
c.Status(204)
return
Expand Down
2 changes: 1 addition & 1 deletion internal/shared/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ func ReadNBytes(r io.Reader, n int) []byte {

func WriteBytes(w io.Writer, bs []byte) {
if _, err := w.Write(bs); err != nil {
panic("failed to write")
panic(err)
}
}
Loading

0 comments on commit 5a28760

Please sign in to comment.