FailSpy / humble-steam-key-redeemer

Python script to extract all Humble Bundle keys and redeem them on Steam automagically.
132 stars 28 forks source link

Game depends on base game to be installed #6

Closed OpenSauce closed 1 year ago

OpenSauce commented 3 years ago

One issue that I've ran into a few times, and could affect the redeeming, is that it tries to redeem (a number of) product codes without doing the base code first and I assume creates a lot of failed attempts. I can give some more information later but would be nice to handle this gracefully.

FailSpy commented 3 years ago

It's a little tricky to do this, open to ideas though.

In theory, Humble Bundle should be giving this kind of data to us. Each gamekey returned by has a 'keyindex' attached to it, however I'm not convinced it's always doing the right thing It seems as though keyindex gets dropped to 0 after an individual key has been 'revealed'

If keyindex were accurate, then it's as simple as:

unownedgames = sorted(unownedgames,key=lambda g: (g['gamekey'],g['keyindex']))

However, the order in the order_details array seems to consistently stay in a useful order(base game first, DLC later), so maybe we can add our own value to each game key, e.g. listindex and sort by that

So when going through order details, it might look something like this:

for game in order_details:
    if "tpkd_dict" in game and "all_tpks" in game["tpkd_dict"]:
        listindex= 0
        tpks = []
        for tpk in game["tpkd_dict"]["all_tpks"]:
            if tpk["key_type_human_name"] == "Steam":
                tpk['listindex'] = listindex
                tpks.append(tpk)
                listindex = listindex + 1

        steam_keys.extend(tpks)

And then add 'listindex' to the sorted key tuple above.

EDIT: Thinking about it more, you may want to just keep the listindex across ALL games to keep consistent date-time ordering (user purchases base game in one order, user purchases DLC in another -- presuming user buys DLC sensibly)

OpenSauce commented 3 years ago

So just putting this here for further information, if I get some spare time I will look into it but thought you may find it interesting (I believe this will probably be resolved by the above solution anyway):

In this case "Earth Defense Force 4.1" errors out, saying it needs the base game to be installed for the keys to work, they are then added to the errored.csv:

image

Rerunning the script now says that I no longer have any keys to redeem:

image

However in my humble bundle library there are actually many more of these "Earth Defense" keys that are still left to be redeemed? including the base game.

image

FailSpy commented 3 years ago

Interesting, and thankfully something perfect for a test case. Do you not own EARTH DEFENSE FORCE 4.1?

EDIT: Derp, you already answered including the base game.

FailSpy commented 3 years ago

Would you mind inserting this into the code just before line 741?

not_allowed_cols = ["redeemed_key_val","gamekey"]
anonymize = lambda x: x[1] if x[0] not in not_allowed_cols else ""
steam_keys_filter = [{k:anonymize((k,gamekey[k])) for k in gamekey} for gamekey in steam_keys if "EARTH DEFENSE FORCE" in gamekey["human_name"]]
print(steam_keys_filter)

with open("anonymized_EDF_dump.pickle") as f:
    pickle.dump(steam_keys_filter,f)

Then activate auto-redeem mode (can cancel out once it asks you to reveal) Send me the resulting 'anonymized_EDF_dump.pickle' file. It'll help me get some insight as to what's going on.

I have it set to print the resulting array, so you can review and make sure you feel comfortable with the data you're sending

FailSpy commented 3 years ago

Just an update: I believe your EDF issue should be resolved by the sort suggested.

However wow EDF4.1 packages are a mess. So no keyindex, no steam_app_id, and their titles on Steam are just the worst:

Actual game: "EARTH DEFENSE FORCE 4.1: The Shadow of New Despair" https://store.steampowered.com/app/410320/EARTH_DEFENSE_FORCE_41_The_Shadow_of_New_Despair/

DLCs look different, annoyingly dropping the actual game title: Steam: "Mission Pack 1: Time of the Mutants" vs. Humble: "EARTH DEFENSE FORCE 4.1: Mission Pack 1: Time of the Mutants" https://store.steampowered.com/app/410780/Mission_Pack_1_Time_of_the_Mutants/

Not sure much can be done if the sort doesn't work, sadly -- at least for this case.

seth-rah commented 3 years ago

I have the script running on my end right now as well with about 300 keys to add. (no edits to the script suggested in this thread, noticed the script has been updated since this post so wasn't too sure)

Earth Defense Force came from Humble Monthly 2019. I'll let you know how that plays out when I check on this again in the morning.

OpenSauce commented 3 years ago

I have the script running on my end right now as well with about 300 keys to add. (no edits to the script suggested in this thread, noticed the script has been updated since this post so wasn't too sure)

Earth Defense Force came from Humble Monthly 2019. I'll let you know how that plays out when I check on this again in the morning.

Sounds good!

seth-rah commented 3 years ago

My EDF activated without any issues

FailSpy commented 1 year ago

Closing as seth-rah mentioned it worked for them (post sort fix)