-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
147 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package item | ||
|
||
import "strings" | ||
|
||
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"` | ||
} | ||
|
||
func DmToGibbed(dmi DigitalMarineItem) Item { | ||
i := Item{} | ||
db := GetDB() | ||
btik := GetBtik() | ||
i.Balance = DmKeyToInvKey(dmi.Balance, db.GetData("InventoryBalanceData").Assets) | ||
i.Manufacturer = DmKeyToInvKey(dmi.Manufacturer, db.GetData("ManufacturerData").Assets) | ||
i.Level = dmi.Level | ||
k := btik[strings.ToLower(i.Balance)] | ||
for _, i2 := range dmi.Components { | ||
i.Parts = append(i.Parts, DmKeyToInvKey(dmi.ComponentNames[i2], db.GetData(k).Assets)) | ||
} | ||
i.Version = 55 | ||
i.InvData = DmKeyToInvKey(strings.Split(dmi.Blueprint, " ")[1], db.GetData("InventoryData").Assets) | ||
return i | ||
} | ||
|
||
func GetBlueprint(key, invdata string) string { | ||
key = strings.Replace(key, "Part", "", 1) | ||
parts := strings.Split(key, "_") | ||
parts[1], parts[2] = parts[2], parts[1] | ||
key = strings.Join(parts, "_") | ||
return key + " " + invdata | ||
} | ||
|
||
func GibbedToDm(i Item) DigitalMarineItem { | ||
m := DigitalMarineItem{} | ||
m.Manufacturer = GetPartSuffix(i.Manufacturer) | ||
m.Level = i.Level | ||
m.CopyType = "item" | ||
m.Balance = GetPartSuffix(i.Balance) | ||
btik := GetBtik() | ||
key := btik[strings.ToLower(i.Balance)] | ||
m.Blueprint = GetBlueprint(key, GetPartSuffix(i.InvData)) | ||
for _, part := range i.Parts { | ||
p := GetPartSuffix(part) | ||
found := false | ||
for i2, name := range m.ComponentNames { | ||
if name == p { | ||
m.Components = append(m.Components, i2) | ||
found = true | ||
} | ||
} | ||
if !found { | ||
m.ComponentNames = append(m.ComponentNames, p) | ||
m.Components = append(m.Components, len(m.ComponentNames)-1) | ||
} | ||
} | ||
return m | ||
} | ||
|
||
func DmKeyToInvKey(key string, assets []string) string { | ||
for _, a := range assets { | ||
if strings.HasSuffix(a, key) { | ||
return a | ||
} | ||
} | ||
return "" | ||
} | ||
|
||
func GetPartSuffix(part string) string { | ||
p := strings.Split(part, "/") | ||
return p[len(p)-1] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package server | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"strings" | ||
|
||
"github.com/cfi2017/bl3-save/internal/item" | ||
"github.com/cfi2017/bl3-save/pkg/pb" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func convertItem(c *gin.Context) { | ||
|
||
var request struct { | ||
Base64 string `json:"base64"` | ||
} | ||
request.Base64 = strings.TrimPrefix(request.Base64, "bl3(") | ||
request.Base64 = strings.TrimSuffix(request.Base64, ")") | ||
err := c.BindJSON(&request) | ||
if err != nil { | ||
c.AbortWithStatusJSON(500, err) | ||
return | ||
} | ||
bs, err := base64.StdEncoding.DecodeString(request.Base64) | ||
if err != nil { | ||
c.AbortWithStatusJSON(500, err) | ||
return | ||
} | ||
var dmi item.DigitalMarineItem | ||
err = json.Unmarshal(bs, &dmi) | ||
if err != nil { | ||
// try deserializing item | ||
i, err := item.Deserialize(bs) | ||
if err != nil { | ||
c.AbortWithStatusJSON(500, err) | ||
return | ||
} | ||
i.Wrapper = &pb.OakInventoryItemSaveGameData{ | ||
ItemSerialNumber: bs, | ||
PickupOrderIndex: 200, | ||
Flags: 3, | ||
WeaponSkinPath: "", | ||
DevelopmentSaveData: nil, | ||
} | ||
c.JSON(200, &i) | ||
return | ||
} | ||
i := item.DmToGibbed(dmi) | ||
bs, err = item.Serialize(i, 0) // encrypt with 0 seed | ||
if err != nil { | ||
c.AbortWithStatusJSON(500, err) | ||
return | ||
} | ||
i.Wrapper = &pb.OakInventoryItemSaveGameData{ | ||
ItemSerialNumber: bs, | ||
PickupOrderIndex: 200, | ||
Flags: 3, | ||
WeaponSkinPath: "", | ||
DevelopmentSaveData: nil, | ||
} | ||
c.JSON(200, &i) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters