Update GaCy-GO
This commit is contained in:
1 parent
da8a32f60d
commit
0cbe460e49
345 files changed
+98202
-77559
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// nil resets an override. Merge only the edited item keys, so a simultaneous
|
||||
// game-side gacha grant cannot be erased by an SDK inventory edit.
|
||||
func PatchMaterialOverrides(updates map[uint32]*uint32) (map[uint32]uint32, error) {
|
||||
for id := range updates {
|
||||
if id == 0 {
|
||||
return nil, fmt.Errorf("invalid material ID")
|
||||
}
|
||||
}
|
||||
persistentWriteMu.Lock()
|
||||
defer persistentWriteMu.Unlock()
|
||||
unlock, err := lockPersistentFile()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer unlock()
|
||||
raw, err := readResourceFile("freesr-data.json")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var root map[string]json.RawMessage
|
||||
if err = json.Unmarshal(raw, &root); err != nil || root == nil {
|
||||
return nil, fmt.Errorf("invalid FreeSR import")
|
||||
}
|
||||
materials := map[uint32]uint32{}
|
||||
if value, exists := root["materials"]; exists {
|
||||
if err = json.Unmarshal(value, &materials); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if materials == nil {
|
||||
materials = map[uint32]uint32{}
|
||||
}
|
||||
}
|
||||
for id, count := range updates {
|
||||
if count == nil {
|
||||
delete(materials, id)
|
||||
} else {
|
||||
materials[id] = *count
|
||||
}
|
||||
}
|
||||
root["materials"], err = json.Marshal(materials)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return materials, writeJSONAtomic("freesr-data.json", root)
|
||||
}
|
||||
Reference in new issue
Block a user