Skip to content

Commit

Permalink
BL2Items: Hack in some exploration of mission status
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Jan 24, 2025
1 parent afb664c commit f63a928
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions BL2_find_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ def encode_protobuf(self):
return b"".join(data)

# Stub types that are used by SaveFile
SkillData = ResourceData = ItemData = Weapon = MissionPlaythrough = bytes
SkillData = ResourceData = ItemData = Weapon = bytes
DLCData = RegionGameStage = WorldDiscovery = WeaponMemento = ItemMemento = bytes
Challenge = OneOffChallenge = Lockout = VehicleSkin = bytes

Expand Down Expand Up @@ -1117,6 +1117,29 @@ def order(self): return self.quickslot or 6
def is_equipped(self): return self.quickslot
def is_carried(self): return True

@dataclass
class MissionData(ProtoBuf):
name: bytes
status: bytes # Enumeration - NotStarted = 0, Active = 1, ObjectivesComplete, ReadyToTurnIn, Complete = 4, Failed = 5
isfromdlc: int
dlcpackageid: int
objectives: [bytes] = None
activeobjective: int = 0
subobjectives: [bytes] = None
needsrewards: bool = None
unknown9: int = None
heardkickoff: int = 0
gamestage: int = 0

@dataclass
class MissionPlaythrough(ProtoBuf):
playthrough: int = 0
activemission: bytes = b""
missions: [MissionData] = None
pendingrewards: [bytes] = None
filteredmissions: [bytes] = None
MissionPlaythrough = bytes # Hack: Don't parse them out, they don't roundtrip (all missions end up marked as incomplete)

@dataclass
class SaveFile(ProtoBuf):
playerclass: str
Expand Down Expand Up @@ -1176,14 +1199,17 @@ class SaveFile(ProtoBuf):
awesome_skill_disabled: int = 0
max_bank_slots: int = 0 # Might be useful when looking for a place to put stuff
vehicle_skins: [VehicleSkin] = None
if GAME == "borderlands the pre-sequel":
body_switches: bytes = b""
player_flags: [int] = None
vehicle_steering_mode: int = 0
discovered_compass_icons: [bytes] = None
suppress_oxygen_notifs: int = 0
else:
vehicle_steering_mode: int = 0

#### Conditionals seem to be broken when in Python 3.14 dataclasses ####
# if GAME == "borderlands the pre-sequel":
# body_switches: bytes = b""
# player_flags: [int] = None
# vehicle_steering_mode: int = 0
# discovered_compass_icons: [bytes] = None
# suppress_oxygen_notifs: int = 0
# else:
vehicle_steering_mode: int = 0

has_played_uvhm: int = None
overpower_levels: int = None
last_overpower_choice: int = None
Expand All @@ -1198,6 +1224,8 @@ def add_inventory(self, asset):

class SaveFileFormatError(Exception): pass

mission_stats = collections.Counter()

def parse_savefile(fn):
with open(fn, "rb") as f: data = Consumable(f.read())
# PC builds, presumably including Linux builds, should be
Expand Down Expand Up @@ -1294,6 +1322,13 @@ def parse_savefile(fn):
savefile.preferences.name, len(savefile.packed_weapon_data), len(savefile.packed_item_data) - 2)
items.sort()
ret += "".join("\n" + desc for order, lvl, desc in items if order >= 0)
if MissionPlaythrough is not bytes:
for m in savefile.missions:
# if m.activemission: print("Active:", m.activemission.decode())
for m in m.missions or []:
n = m.name.decode()
if m.status == 4: mission_stats[n] += 1

if args.synth is not None:
# Make changes to the save file before synthesizing
# savefile.preferences.name = "PATCHED" # Easy way to see what's happening
Expand Down Expand Up @@ -1400,3 +1435,4 @@ def compare(id1, id2):
id = base64.b64encode(serial).decode("ascii").strip("=")
if id not in library[args.game]:
print('\t\t"%s": "%s",' % (id, obj.get_title()))
if mission_stats: print(mission_stats)

0 comments on commit f63a928

Please sign in to comment.