Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
removed a lot of redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
John committed Nov 16, 2018
1 parent b1f1506 commit 65ce764
Showing 1 changed file with 28 additions and 204 deletions.
232 changes: 28 additions & 204 deletions D3Edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,6 @@ def encrypt_save(data: (bytes, bytearray)) -> (bytes, bytearray):
return bytes(data)

if __name__ == "__main__":
# parse arguments
parser = ArgumentParser(description="A script to encrypt/decrypt and modify Diablo III saves")
parser.add_argument("-i", "--in-file", type=str, required=True, help="The account file you want to work with")
parser.add_argument("-o", "--out-file", type=str, required=True, help="The account file you want to output to")
select_group = parser.add_argument_group("selection")
select_group.add_argument("-s", "--slot", type=int, default=0, help="The slot ID you want to work with")
mod_group = parser.add_argument_group("modifications")
mod_group.add_argument("--gold", type=int, help="The amount of gold you want your characters to have")
mod_group.add_argument("--blood-shards", type=int, help="The amount of blood shards you want your characters to have")
mod_group.add_argument("--reusable-parts", type=int, help="The amount of reusable parts you want your characters to have")
mod_group.add_argument("--arcane-dust", type=int, help="The amount of arcane dust you want your characters to have")
mod_group.add_argument("--veiled-crystals", type=int, help="The amount of veiled crystals you want your characters to have")
mod_group.add_argument("--deaths-breath", type=int, help="The amount of deaths breath you want your characters to have")
mod_group.add_argument("--forgotten-souls", type=int, help="The amount of forgotten souls you want your characters to have")
mod_group.add_argument("--khanduran-runes", type=int, help="The amount of Khanduran runes you want your characters to have")
mod_group.add_argument("--caldeum-nightshade", type=int, help="The amount of Caldeum nightshade you want your characters to have")
mod_group.add_argument("--arreat-war-tapestries", type=int, help="The amount of Arret War tapestries you want your characters to have")
mod_group.add_argument("--corrupted-angel-flesh", type=int, help="The amount of corrupted angel flesh you want your characters to have")
mod_group.add_argument("--westmarch-holy-water", type=int, help="The amount of Westmarch holy water you want your characters to have")
mod_group.add_argument("--hearts-of-fright", type=int, help="The amount of hearts of fright you want your characters to have")
mod_group.add_argument("--vials-of-putridness", type=int, help="The amount of vials of putridness you want your characters to have")
mod_group.add_argument("--idols-of-terror", type=int, help="The amount of idols of terror you want your characters to have")
mod_group.add_argument("--leorics-regrets", type=int, help="The amount of Leoric's regrets you want your characters to have")
mod_group.add_argument("--vengeful-eyes", type=int, help="The amount of vengeful eyes you want your characters to have")
mod_group.add_argument("--writhing-spines", type=int, help="The amount of writhing spines you want your characters to have")
mod_group.add_argument("--devils-fangs", type=int, help="The amount of devil's fangs you want your characters to have")
mod_group.add_argument("--all-currencies", type=int, help="Set all currencies to the given value")
args = parser.parse_args()

# make sure the input file exists
assert isfile(args.in_file), "input file doesn't exist"

# make sure assets exist
assert isfile(join(ASSET_DIR, GBIDS_FILE)), "%s doesn't exist" % (GBIDS_FILE)
assert isfile(join(ASSET_DIR, AFFIXES_FILE)), "%s doesn't exist" % (AFFIXES_FILE)
Expand All @@ -124,6 +92,21 @@ def encrypt_save(data: (bytes, bytearray)) -> (bytes, bytearray):
with open(join(ASSET_DIR, SLOTS_FILE), "r") as f:
slot_list = load(f)

# parse arguments
parser = ArgumentParser(description="A script to encrypt/decrypt and modify Diablo III saves")
parser.add_argument("-i", "--in-file", type=str, required=True, help="The account file you want to work with")
parser.add_argument("-o", "--out-file", type=str, default="account_modified.dat", help="The account file you want to output to")
select_group = parser.add_argument_group("selection")
select_group.add_argument("-s", "--slot", type=int, default=0, help="The slot ID you want to work with")
mod_group = parser.add_argument_group("modifications")
for single in currency_list:
mod_group.add_argument("--" + single.lower().replace("'", "").replace(" ", "-"), type=int, help="Set the amount of %s" % (single))
mod_group.add_argument("--all-currencies", type=int, help="Set all currencies to the given value")
args = parser.parse_args()

# make sure the input file exists
assert isfile(args.in_file), "input file doesn't exist"

# account
# decrypt
with open(args.in_file, "rb") as f:
Expand All @@ -134,180 +117,21 @@ def encrypt_save(data: (bytes, bytearray)) -> (bytes, bytearray):
asd = Account_pb2.SavedDefinition()
asd.ParseFromString(account_dec)

# I hope you can handle super redundant logic (because I can't)
# modify account here
if len(asd.partitions[args.slot].currency_data.currency) > 0:
# gold
if args.gold or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 1:
if args.gold:
asd.partitions[args.slot].currency_data.currency[0].count = args.gold
print("Set slot %s gold to %s" % (args.slot, args.gold))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[0].count = args.all_currencies
print("Set slot %s gold to %s" % (args.slot, args.all_currencies))
# blood shards
if args.blood_shards or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 2:
if args.blood_shards:
asd.partitions[args.slot].currency_data.currency[1].count = args.blood_shards
print("Set slot %s blood shards to %s" % (args.slot, args.blood_shards))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[1].count = args.all_currencies
print("Set slot %s blood shards to %s" % (args.slot, args.all_currencies))
# reusable parts
if args.reusable_parts or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 3:
if args.reusable_parts:
asd.partitions[args.slot].currency_data.currency[2].count = args.reusable_parts
print("Set slot %s reusable parts to %s" % (args.slot, args.reusable_parts))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[2].count = args.all_currencies
print("Set slot %s reusable parts to %s" % (args.slot, args.all_currencies))
# arcane dust
if args.arcane_dust or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 4:
if args.arcane_dust:
asd.partitions[args.slot].currency_data.currency[3].count = args.arcane_dust
print("Set slot %s arcane dust to %s" % (args.slot, args.arcane_dust))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[3].count = args.all_currencies
print("Set slot %s arcane dust to %s" % (args.slot, args.all_currencies))
# veiled crystals
if args.veiled_crystals or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 5:
if args.veiled_crystals:
asd.partitions[args.slot].currency_data.currency[4].count = args.veiled_crystals
print("Set slot %s veiled crystals to %s" % (args.slot, args.veiled_crystals))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[4].count = args.all_currencies
print("Set slot %s veiled crystals to %s" % (args.slot, args.all_currencies))
# deaths breath
if args.deaths_breath or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 6:
if args.deaths_breath:
asd.partitions[args.slot].currency_data.currency[5].count = args.deaths_breath
print("Set slot %s deaths breath to %s" % (args.slot, args.deaths_breath))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[5].count = args.all_currencies
print("Set slot %s deaths breath to %s" % (args.slot, args.all_currencies))
# forgotten souls
if args.forgotten_souls or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 7:
if args.forgotten_souls:
asd.partitions[args.slot].currency_data.currency[6].count = args.forgotten_souls
print("Set slot %s forgotten souls to %s" % (args.slot, args.forgotten_souls))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[6].count = args.all_currencies
print("Set slot %s forgotten souls to %s" % (args.slot, args.all_currencies))
# khanduran runes
if args.khanduran_runes or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 8:
if args.khanduran_runes:
asd.partitions[args.slot].currency_data.currency[7].count = args.khanduran_runes
print("Set slot %s Khanduran runes to %s" % (args.slot, args.khanduran_runes))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[7].count = args.all_currencies
print("Set slot %s Khanduran runes to %s" % (args.slot, args.all_currencies))
# caldeum nightshade
if args.caldeum_nightshade or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 9:
if args.caldeum_nightshade:
asd.partitions[args.slot].currency_data.currency[8].count = args.caldeum_nightshade
print("Set slot %s Caldeum nightshade to %s" % (args.slot, args.caldeum_nightshade))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[8].count = args.all_currencies
print("Set slot %s Caldeum nightshade to %s" % (args.slot, args.all_currencies))
# arreat war tapestries
if args.arreat_war_tapestries or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 10:
if args.arreat_war_tapestries:
asd.partitions[args.slot].currency_data.currency[9].count = args.arreat_war_tapestries
print("Set slot %s Arreat War tapestries to %s" % (args.slot, args.arreat_war_tapestries))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[9].count = args.all_currencies
print("Set slot %s Arreat War tapestries to %s" % (args.slot, args.all_currencies))
# corrupted angel flesh
if args.corrupted_angel_flesh or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 11:
if args.corrupted_angel_flesh:
asd.partitions[args.slot].currency_data.currency[10].count = args.corrupted_angel_flesh
print("Set slot %s corrupted angel flesh to %s" % (args.slot, args.corrupted_angel_flesh))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[10].count = args.all_currencies
print("Set slot %s corrupted angel flesh to %s" % (args.slot, args.all_currencies))
# westmarch holy water
if args.westmarch_holy_water or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 12:
if args.westmarch_holy_water:
asd.partitions[args.slot].currency_data.currency[11].count = args.westmarch_holy_water
print("Set slot %s Westmarch holy water to %s" % (args.slot, args.westmarch_holy_water))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[11].count = args.all_currencies
print("Set slot %s Westmarch holy water to %s" % (args.slot, args.all_currencies))
# hearts of fright
if args.hearts_of_fright or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 13:
if args.hearts_of_fright:
asd.partitions[args.slot].currency_data.currency[12].count = args.hearts_of_fright
print("Set slot %s hearts of fright to %s" % (args.slot, args.hearts_of_fright))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[12].count = args.all_currencies
print("Set slot %s hearts of fright to %s" % (args.slot, args.all_currencies))
# vials of putridness
if args.vials_of_putridness or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 14:
if args.vials_of_putridness:
asd.partitions[args.slot].currency_data.currency[13].count = args.vials_of_putridness
print("Set slot %s vials of putridness to %s" % (args.slot, args.vials_of_putridness))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[13].count = args.all_currencies
print("Set slot %s vials of putridness to %s" % (args.slot, args.all_currencies))
# idols of terror
if args.idols_of_terror or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 15:
if args.idols_of_terror:
asd.partitions[args.slot].currency_data.currency[14].count = args.idols_of_terror
print("Set slot %s idols of terror to %s" % (args.slot, args.idols_of_terror))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[14].count = args.all_currencies
print("Set slot %s idols of terror to %s" % (args.slot, args.all_currencies))
# leoric's regrets
if args.leorics_regrets or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 16:
if args.leorics_regrets:
asd.partitions[args.slot].currency_data.currency[15].count = args.leorics_regrets
print("Set slot %s Leoric's regrets to %s" % (args.slot, args.leorics_regrets))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[15].count = args.all_currencies
print("Set slot %s Leoric's regrets to %s" % (args.slot, args.all_currencies))
# vengeful eyes
if args.vengeful_eyes or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 17:
if args.vengeful_eyes:
asd.partitions[args.slot].currency_data.currency[16].count = args.vengeful_eyes
print("Set slot %s vengeful eyes to %s" % (args.slot, args.vengeful_eyes))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[16].count = args.all_currencies
print("Set slot %s vengeful eyes to %s" % (args.slot, args.all_currencies))
# writhing spines
if args.writhing_spines or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 18:
if args.writhing_spines:
asd.partitions[args.slot].currency_data.currency[17].count = args.writhing_spines
print("Set slot %s writhing spines to %s" % (args.slot, args.writhing_spines))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[17].count = args.all_currencies
print("Set slot %s writhing spines to %s" % (args.slot, args.all_currencies))
# devil's fangs
if args.devils_fangs or args.all_currencies:
if len(asd.partitions[args.slot].currency_data.currency) >= 19:
if args.devils_fangs:
asd.partitions[args.slot].currency_data.currency[18].count = args.devils_fangs
print("Set slot %s devils's fangs to %s" % (args.slot, args.devils_fangs))
elif args.all_currencies:
asd.partitions[args.slot].currency_data.currency[18].count = args.all_currencies
print("Set slot %s devils's fangs to %s" % (args.slot, args.all_currencies))
for currency_id in range(len(currency_list)):
currency_name = currency_list[currency_id]
if len(asd.partitions[args.slot].currency_data.currency) >= (currency_id + 1):
amt = None
try:
amt = getattr(args, currency_name.lower().replace("'", "").replace(" ", "_"))
if not amt and args.all_currencies:
amt = args.all_currencies
except AttributeError:
pass
if amt:
print("Set slot %s %s to %s" % (args.slot, currency_name.lower(), amt))
asd.partitions[args.slot].currency_data.currency[currency_id].count = amt

# end account modifications
account_mod_dec = asd.SerializeToString()
Expand Down

0 comments on commit 65ce764

Please sign in to comment.