Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.

Commit 3b1a1e3

Browse files
authored
Update CrabChampionSaveManager.py
the cache for the current save now updates when their is version difference between the program and the cache health and damage multiplier along with challenges and blessings are now cached and are also now dispalyed in the backup details menu and are in presets negitive numbers in the backup details screen are now displayed such that they should display what they should mean , will make a wiki page at some point to better explain this
1 parent 8533aba commit 3b1a1e3

1 file changed

Lines changed: 133 additions & 24 deletions

File tree

CrabChampionSaveManager.py

Lines changed: 133 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
isExe = False
2323
isLinux = False
2424

25-
Version = "3.4.0"
25+
Version = "3.5.0"
2626

2727
if platform.system() == "Linux":
2828
isLinux = True
@@ -1632,7 +1632,9 @@ def loadCache():
16321632
CurrentSaveCacheCS = cacheJSON["BackupData"]["Current Save"]["CheckSum"]
16331633
except BaseException:
16341634
CurrentSaveCacheCS = ""
1635-
if CurrentSaveCS != CurrentSaveCacheCS:
1635+
if CurrentSaveCS != CurrentSaveCacheCS or versionToValue(
1636+
cacheVersion
1637+
) < versionToValue(Version):
16361638
t = threading.Thread(target=genBackupData, args=("SaveGames",))
16371639
t.start()
16381640
threads.append(t)
@@ -1931,28 +1933,36 @@ def genBackupData(backupName):
19311933
except BaseException:
19321934
backupJSON[backupName]["DiffMods"] = []
19331935
try:
1934-
backupJSON[backupName]["Elimns"] = saveJSON["Eliminations"]["Int"]["value"]
1936+
backupJSON[backupName]["Elimns"] = toUInt32(
1937+
saveJSON["Eliminations"]["Int"]["value"]
1938+
)
19351939
except BaseException:
19361940
backupJSON[backupName]["Elimns"] = 0
19371941
try:
1938-
backupJSON[backupName]["ShotsFired"] = saveJSON["ShotsFired"]["Int"]["value"]
1942+
backupJSON[backupName]["ShotsFired"] = toUInt32(
1943+
saveJSON["ShotsFired"]["Int"]["value"]
1944+
)
19391945
except BaseException:
19401946
backupJSON[backupName]["ShotsFired"] = 0
19411947

19421948
try:
1943-
backupJSON[backupName]["DmgDealt"] = saveJSON["DamageDealt"]["Int"]["value"]
1949+
backupJSON[backupName]["DmgDealt"] = toUInt32(
1950+
saveJSON["DamageDealt"]["Int"]["value"]
1951+
)
19441952
except BaseException:
19451953
backupJSON[backupName]["DmgDealt"] = 0
19461954

19471955
try:
1948-
backupJSON[backupName]["MostDmgDealt"] = saveJSON["HighestDamageDealt"]["Int"][
1949-
"value"
1950-
]
1956+
backupJSON[backupName]["MostDmgDealt"] = toUInt32(
1957+
saveJSON["HighestDamageDealt"]["Int"]["value"]
1958+
)
19511959
except BaseException:
19521960
backupJSON[backupName]["MostDmgDealt"] = 0
19531961

19541962
try:
1955-
backupJSON[backupName]["DmgTaken"] = saveJSON["DamageTaken"]["Int"]["value"]
1963+
backupJSON[backupName]["DmgTaken"] = toUInt32(
1964+
saveJSON["DamageTaken"]["Int"]["value"]
1965+
)
19561966
except BaseException:
19571967
backupJSON[backupName]["DmgTaken"] = 0
19581968

@@ -1993,18 +2003,21 @@ def genBackupData(backupName):
19932003
]
19942004

19952005
try:
1996-
backupJSON[backupName]["Blessings"] = saveJSON["NextIslandInfo"]["Struct"][
1997-
"value"
1998-
]["Struct"]["Blessing"]["Enum"]["value"][len("ECrabBlessing::") :]
2006+
backupJSON[backupName]["Blessings"] = [
2007+
saveJSON["NextIslandInfo"]["Struct"]["value"]["Struct"]["Blessing"]["Enum"][
2008+
"value"
2009+
][len("ECrabBlessing::") :]
2010+
]
19992011
except BaseException:
2000-
backupJSON[backupName]["Blessings"] = "None"
2012+
backupJSON[backupName]["Blessings"] = []
20012013

20022014
try:
20032015
array = saveJSON["NextIslandInfo"]["Struct"]["value"]["Struct"][
20042016
"ChallengeModifiers"
20052017
]["Array"]["value"]["Base"]["Enum"]
20062018
for i in range(len(array)):
2007-
array[i] = spaceBeforeUpper(array[i][len("ECrabChallengeModifier") :])
2019+
array[i] = spaceBeforeUpper(array[i][len("ECrabChallengeModifier") + 2 :])
2020+
backupJSON[backupName]["Challenges"] = array
20082021
except BaseException:
20092022
backupJSON[backupName]["Challenges"] = []
20102023

@@ -2145,6 +2158,27 @@ def genBackupData(backupName):
21452158
# print(backupName+str(" - ")+str(round(stop-start,2))+str(" -ue ")+str(round(ueStop-ueStart,2)))
21462159

21472160

2161+
def toUInt32(value):
2162+
"""
2163+
Converts a signed 32-bit integer to its equivalent unsigned 32-bit integer representation.
2164+
2165+
Args:
2166+
value (int): The signed 32-bit integer value to be converted. It should be in the range of -2147483648 to 2147483647.
2167+
2168+
Returns:
2169+
int: The unsigned 32-bit integer equivalent of the input value.
2170+
2171+
Example:
2172+
>>> toUInt32(123)
2173+
123
2174+
>>> toUInt32(-456)
2175+
4294966840
2176+
"""
2177+
if value < 0:
2178+
return abs(value) + 2147483647
2179+
return value
2180+
2181+
21482182
def formatTime(s):
21492183
if s % 60 < 10:
21502184
z = "0"
@@ -2305,6 +2339,16 @@ def parseWeaponRank(rank):
23052339

23062340

23072341
def formatNumber(num=0, decimal_places=0):
2342+
"""
2343+
Formats a number with the specified number of decimal places and adds comma separators for thousands.
2344+
2345+
Parameters:
2346+
num (float): The number to be formatted (default is 0).
2347+
decimal_places (int): The number of decimal places to display (default is 0).
2348+
2349+
Returns:
2350+
str: A string representation of the formatted number.
2351+
"""
23082352
return "{:,.{}f}".format(num, decimal_places)
23092353

23102354

@@ -2392,6 +2436,16 @@ def backupDetailsScreen(backupName):
23922436
+ ensureLength("Armor Plate Health:", leng)
23932437
+ str(formatNumber(backupJSON["ArmorPlatesHealth"], 0))
23942438
)
2439+
info += (
2440+
"\n"
2441+
+ ensureLength("Health Multiplier:", leng)
2442+
+ str(formatNumber(backupJSON["HealthMultiplier"], 3))
2443+
)
2444+
info += (
2445+
"\n"
2446+
+ ensureLength("Damage Multiplier:", leng)
2447+
+ str(formatNumber(backupJSON["DamageMultiplier"], 3))
2448+
)
23952449
info += (
23962450
"\n"
23972451
+ ensureLength("Eliminations:", leng)
@@ -2484,6 +2538,16 @@ def backupDetailsScreen(backupName):
24842538
for diffMod in backupJSON["DiffMods"]:
24852539
info += "\n" + indent + str(diffMod)
24862540
info += "\n"
2541+
if len(backupJSON["Challenges"]) > 0:
2542+
info += "\nChallenges: "
2543+
for diffMod in backupJSON["Challenges"]:
2544+
info += "\n" + indent + str(diffMod)
2545+
info += "\n"
2546+
if len(backupJSON["Blessings"]) > 0:
2547+
info += "\nBlessings: "
2548+
for diffMod in backupJSON["Blessings"]:
2549+
info += "\n" + indent + str(diffMod)
2550+
info += "\n"
24872551
info += "\n" + ensureLength("Weapon:", leng) + str(backupJSON["Inventory"]["Weapon"])
24882552
info += (
24892553
"\n"
@@ -2909,7 +2973,7 @@ def genPlayerData(saveJSON, checksum):
29092973

29102974

29112975
def createPreset():
2912-
defaultPreset = '{"Diff":"Normal","IslandNum":1,"DiffMods":[],"Blessing":[],"Challenges":[],"Crystals":0,"Biome":"Tropical","LootType":"Random Loot Type","IslandName":"Tropical Arena Island","IslandType":"Automatic","Health":100,"MaxHealth":100,"ArmorPlates":0,"ArmorPlatesHealth":0,"HealthMultiplier":1,"DamageMultiplier":1,"keyTotemItem":false,"Inventory":{"Weapon":"Lobby Dependant","WeaponMods":{"Slots":24,"Mods":[]},"GrenadeMods":{"Slots":24,"Mods":[]},"Perks":{"Slots":24,"Perks":[]}}}'
2976+
defaultPreset = '{"Diff":"Normal","IslandNum":1,"DiffMods":[],"Blessings":[],"Challenges":[],"Crystals":0,"Biome":"Tropical","LootType":"Random Loot Type","IslandName":"Tropical Arena Island","IslandType":"Automatic","Health":100,"MaxHealth":100,"ArmorPlates":0,"ArmorPlatesHealth":0,"HealthMultiplier":1,"DamageMultiplier":1,"keyTotemItem":false,"Inventory":{"Weapon":"Lobby Dependant","WeaponMods":{"Slots":24,"Mods":[]},"GrenadeMods":{"Slots":24,"Mods":[]},"Perks":{"Slots":24,"Perks":[]}}}'
29132977
preset = json.loads(defaultPreset)
29142978
prompt = "What should the preset be named?\nEnter nothing to go back"
29152979
name = backupNameMenu(prompt, escape="", escapeReturn="")
@@ -3318,6 +3382,13 @@ def editPreset(preset, name, overriade=False, cancel=True):
33183382
if len(presetJSON["Challenges"]) < len(CHALLENGES):
33193383
info += "\n" + indent + str("Add Challenge")
33203384
info += "\n"
3385+
info += "\nBlessings: "
3386+
if len(presetJSON["Blessings"]) > 0:
3387+
for diffMod in presetJSON["Blessings"]:
3388+
info += "\n" + indent + diffMod + " - " + BlessingsDetails(diffMod)
3389+
if len(presetJSON["Blessings"]) < len("1"):
3390+
info += "\n" + indent + str("Add Blessing")
3391+
info += "\n"
33213392
info += (
33223393
"\n" + ensureLength("Weapon:", leng) + str(presetJSON["Inventory"]["Weapon"])
33233394
)
@@ -3415,6 +3486,7 @@ def editPreset(preset, name, overriade=False, cancel=True):
34153486
"Difficulty Modifiers: ",
34163487
"Items:",
34173488
"Challenges: ",
3489+
"Blessings: ",
34183490
],
34193491
startChoice=choice,
34203492
scrollWindowStart=window,
@@ -3696,6 +3768,15 @@ def editPreset(preset, name, overriade=False, cancel=True):
36963768
)
36973769
presetJSON["Challenges"] = diffmods
36983770

3771+
elif info[choice].replace(indent, "") in BLESSINGS:
3772+
diffmods = presetJSON["Blessings"]
3773+
diffmods.remove(
3774+
info[choice].replace(indent, "")[
3775+
: info[choice].replace(indent, "").index(" - ")
3776+
]
3777+
)
3778+
presetJSON["Blessings"] = diffmods
3779+
36993780
elif "Add Difficulty Modifer" in info[choice]:
37003781
diffmods = DIFFMODS.copy()
37013782
for diffmod in presetJSON["DiffMods"]:
@@ -3725,6 +3806,20 @@ def editPreset(preset, name, overriade=False, cancel=True):
37253806
odiffmods.append(diffmod)
37263807
presetJSON["Challenges"] = odiffmods
37273808

3809+
elif "Add Blessing" in info[choice]:
3810+
diffmods = BLESSINGS.copy()
3811+
for diffmod in presetJSON["Blessings"]:
3812+
diffmods.remove(diffmod + " - " + BlessingsDetails(diffmod))
3813+
prompt = "Select Blessing to add\n"
3814+
odiffmods = diffmods.copy()
3815+
for i in range(len(diffmods)):
3816+
diffmods[i] = diffmods[i]
3817+
diffmod = odiffmods[scrollSelectMenu(prompt, diffmods, defaultDetails=2)]
3818+
diffmod = diffmod[: diffmod.index(" - ")]
3819+
odiffmods = presetJSON["Blessings"]
3820+
odiffmods.append(diffmod)
3821+
presetJSON["Blessings"] = odiffmods
3822+
37283823
elif (
37293824
":" in info[choice]
37303825
and "Weapon" in info[choice][: info[choice].index(":")]
@@ -3931,6 +4026,7 @@ def editPreset(preset, name, overriade=False, cancel=True):
39314026
mods.append(mod)
39324027
presetJSON["Inventory"]["Perks"]["Perks"] = mods
39334028
break
4029+
39344030
elif choice == 0:
39354031
can = False
39364032
if os.path.exists(
@@ -3941,6 +4037,7 @@ def editPreset(preset, name, overriade=False, cancel=True):
39414037
break
39424038
else:
39434039
break
4040+
39444041
elif "Cancel" in info[choice]:
39454042
can = True
39464043
break
@@ -3962,6 +4059,13 @@ def ChallengesDetails(chall):
39624059
return None
39634060

39644061

4062+
def BlessingsDetails(chall):
4063+
for ch in BLESSINGS:
4064+
if chall in ch:
4065+
return ch[ch.index(" - ") + 3 :]
4066+
return None
4067+
4068+
39654069
def usePreset():
39664070
global presetsJSON
39674071
loadPresets()
@@ -4390,12 +4494,17 @@ def convertPresetToGameSave(preset, defaultJSONOverride=""):
43904494
# array.append("ECrabDifficultyModifier:0:"+dif.replace(" ",""))
43914495
# GameJSON["AutoSave"]["Struct"]["value"]["Struct"]["DifficultyModifiers"]["Array"]["value"]["Base"]["Enum"] = array
43924496

4393-
if preset["Blessing"] != "":
4394-
GameJSON["AutoSave"]["Struct"]["value"]["Struct"]["NextIslandInfo"]["Struct"][
4395-
"value"
4396-
]["Struct"]["Blessing"]["Enum"]["value"] = (
4397-
"ECrabBlessing::" + preset["Blessing"]
4398-
)
4497+
if preset["Blessings"] != []:
4498+
if "Flawless" in preset["Blessings"]:
4499+
GameJSON["AutoSave"]["Struct"]["value"]["Struct"]["NextIslandInfo"]["Struct"][
4500+
"value"
4501+
]["Struct"]["Blessing"]["Enum"]["value"] = "ECrabBlessing::Flawless"
4502+
else:
4503+
GameJSON["AutoSave"]["Struct"]["value"]["Struct"]["NextIslandInfo"]["Struct"][
4504+
"value"
4505+
]["Struct"]["Blessing"]["Enum"]["value"] = (
4506+
"ECrabBlessing::" + preset["Blessings"][0]
4507+
)
43994508
else:
44004509
GameJSON["AutoSave"]["Struct"]["value"]["Struct"]["NextIslandInfo"]["Struct"][
44014510
"value"
@@ -4654,9 +4763,9 @@ def updatePreset(preset):
46544763
preset["keyTotemItem"] = False
46554764

46564765
try:
4657-
preset["Blessing"]
4766+
preset["Blessings"]
46584767
except BaseException:
4659-
preset["Blessing"] = ""
4768+
preset["Blessings"] = []
46604769

46614770
try:
46624771
preset["Challenges"]
@@ -4780,7 +4889,7 @@ def makeMainMenuPrompt(Version, LatestVersion, VersionValue, LatestValue, update
47804889
global EPICCOLOR
47814890
global LEGENDARYCOLOR
47824891
global GREEDCOLOR
4783-
BLESSINGS = ["Flawless"]
4892+
BLESSINGS = ["Flawless - Get an extra reward chest if you don't take any damage"]
47844893
CHALLENGES = [
47854894
"One Hit - Enemies can be eliminated in one hit but so can you",
47864895
"Energy Rings - Enemies spawn energy rings when eliminated",

0 commit comments

Comments
 (0)