Revadike / epicgames-freebies-claimer

Claim available free game promotions from the Epic Games Store.
MIT License
2.23k stars 361 forks source link

Temporary workaround using Autohotkey (AHK) #179

Open chaoscreater opened 2 years ago

chaoscreater commented 2 years ago

Hi all,

As some of you know, currently there's an issue with captcha causing issues: https://github.com/Revadike/epicgames-freebies-claimer/issues/172

There isn't a solution at the moment (yet). For now, I've created a temporary workaround and would like to contribute and share it with you all. Just my way of saying thanks to this project, considering how much it has helped me in the past.

  1. First of all, I think the common problem here with either using Selenium or APIs is the captcha. Most of the projects based on Selenium will instantiate a new browser session (i.e a new incognito window) and that means you'll be required to login and almost always encounter a captcha. So my goal is to find a way to use existing session cookies and greatly reduce the chance of encountering captchas.

  2. Secondly, I want to make this work for multiple accounts. I have 5 Epic Games accounts and I don't want to have to login to each of them.

Before we go any further, I need to briefly explain what session cookies are. Whenever you browse to a website and login to your account, a session cookie containing information about your account for that particular site will be created automatically in the background. The NEXT time you browse to the same site, your account will still be logged in and this is because the site will be able to recognize the existing session cookie. This is great, because as a user, we don't want to be prompted to login everytime we browse to a website. Obviously, since you're already logged into your account, this means that you won't and shouldn't be prompted to enter a captcha.

As long as you are already logged into your account for Epic Games, then a session cookie would have been created and you should still be logged in the next time you browse to Epic Games. If you have only one Epic Games account, then you can skip reading Using Multiple Accounts With Firefox Containers and jump straight to Autohotkey Automation For Game Claiming below.







Using Multiple Accounts With Firefox Containers

What if you have multiple Epic Games account? You can only be logged into one account in your browser, right? Technically, that's not true.

Luckily, there's this thing called session/browser containers and this is used in Firefox. There's actually a 1st party extension called Firefox Containers that we can make use of. We can create containers for different accounts and they are basically their own isolated environments, each with their own session cookies. As long as the container is not deleted, you'll always be able to "reconnect" to the existing session. This works very well even for sites that require MFA. For example, I can access O365 or Azure without being prompted for MFA, assuming I have already logged into my account at some point in the past.

Here's how it works. First, download the extension for Firefox: https://addons.mozilla.org/en-US/firefox/addon/multi-account-containers/

Next, create containers for each Epic Games account you have. I have 5, so I'll be creating 5 containers:

image

Next, go into the extension settings and set a keyboard shortcut # for each of the containers:

image

Next, go into the Firefox addons & settings page, select Extensions and then select the Cog icon -> Manage Extension Shortcuts. This bit is very important, set the shortcut key combination that you want for each of the shortcuts that match the containers from the screenshot above.

image

Now, test the shortcuts and make sure they are able to open the containers. If it works, great.

The next step is to actually login to your Epic Games account in each container. I have 5 accounts, so I'll login to just one account for each container. Now, your Epic Games session cookie will be stored in their respective containers. To test, you can close Firefox and launch it again and then browse to Epic Games website in the containers. You should find that your account is still logged in. This means that we won't run into captcha issues now.







Autohotkey Automation For Game Claiming

The next step is to automate the game claiming process. To achieve this, I use Autohotkey. First, download Autohotkey from here: https://www.autohotkey.com

Next, download the AHK scripts here: EpicGamesClaimer.zip

There are a few AHK scripts in the .zip file. If you have multiple Epic Games accounts, then just extract the scripts that have Multiple_Accounts in the filename, otherwise just extract the Single_Account scripts if you have just one Epic Games account. You'll find a Manual_Run and Scheduled_Run version. The Manual_Run version is used when you want to press a specific hotkey combination (e.g. CTRL+SHIFT+U) to start running the game claiming process and is also a good way to demo/test how the script works. The Scheduled_Run version is exactly the same thing, except that you don't need to press a hotkey to trigger it, as the script will just run on a scheduled basis - which means you can set it to run at e.g. 2am in the morning and it'll claim games for you while you're asleep.


FindText

Extract and copy FindText.ahk into here: C:\Program Files\autohotkey\Lib

If the Lib (library) folder doesn't exist, just create it. If your Autohotkey is installed to C:\Program Files (x86), then obviously copy the file there.

What does FindText do you might ask? Well, it's a function/library that someone wrote. Basically, it scans for a particular image on the screen. When the image is found, you can then tell the script to click on that image, or do something else. You can find the FindText official thread here: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=17834&sid=602416ec55e2834d5f03ed90346556e5

I've already taken multiple image scans of various buttons and text that you will encounter during the game claiming process. For example, the "Free Now" button will be shown for games that are free. The "Get" button will be found when you're trying to claim/purchase the game.

One very important thing to note is that while I have scanned those images and included them in the script, I obviously did all this from my PC. The screen resolution I'm using is 1920x1080 at 100% scaling. If your monitor has a different screen resolution or scaling, then the scanned images I included in the script will NOT work for you. This is because FindText will scan the image based on what is on the screen and based on the screen's scaling and resolution. You'll have a better chance of testing it out and seeing how it works if you temporarily set your screen resolution and scaling to match what I'm using. The other resolution you could try testing is 2048 x 1080 at 100% scaling.

The other important thing to note is that if the images on the actual website is changed (e.g. different colour, different font size or different font, etc), then obviously the script will not find them. FindText will scan the images and store them as code (which you will see later). They are static and so if there are new changes on the website, you'll need to scan for the new images. However, this process is very simple and quick to update.

So, chances are you will need to scan your own images. To do this, just double click the "FindText.ahk" file and it should open up a window like this:

image

To capture an image, just click on capture and then you should see a blue/red rectangle around your mouse cursor. Right click once to set the rectangle on the image you're trying to capture and then right click a 2nd time to make the capture. So let's say I'm trying to capture the "Free Games" text:

image

Then when I do the capture, it'll look something like this (notice the rectangle around the Free Text button):

image

Next, set the image to black and white by using the "Gray2Two" button (don't worry about the threshold number, it'll generate for you):

image

Click OK and it should generate a bunch of code for you. The only code we care about is the "TEXT" part. You can click on that line and get a preview of your image in ASCII (?) format and you can copy any other TEXT code into here to preview it:

image

You can also click on the TEST button to make sure that it works. It should output a message saying Successful.

Here's the TEXT code for the image I scanned: Text:="|<>*140$71.zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzkA3UA3wss6TzUM30M7slU4zzDnaTnzlXC8zyTbAzbzV6SNzw3CM70z0Awnzs60kC1yENtXznw3bwzwUnn7zbtXDtztVb6DzDn60kDnX0CTyTbA1UTb70wzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

Next, open your favourite file editor such as Notepad++ or VSCode and open the EpicGamesClaimer_xxxxxxxx.ahk script. Do this for both the Manual_Run and Scheduled_Run scripts.

Browse to the "FindText" section and paste your TEXT code there and rename accordingly. So for example, this TEXT code here:

EpicGames_FreeNow_Text_FluxOff:="|<>*166$41.zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy1UQ1UTw30M30ztyQnyTznwtbwzzUNn0s7z0kC1kDyTUQzbzwzANzDztyMk61znwtUA3zzzzzzzzzzzzzzzzzzzzzU"

Will become this:

EpicGames_FreeNow_Text_FluxOff:="|<>*140$71.zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzkA3UA3wss6TzUM30M7slU4zzDnaTnzlXC8zyTbAzbzV6SNzw3CM70z0Awnzs60kC1yENtXznw3bwzwUnn7zbtXDtztVb6DzDn60kDnX0CTyTbA1UTb70wzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

The reason we're doing this is because "EpicGames_FreeNow_Text_FluxOff" is hardcoded in the script, which you can see in the IF statement line right below it.

In the script, there are lots of other TEXT codes. They should be pretty self-explanatory, based on the name. If you're unsure of what the TEXT code is for, just copy it and put it into the FindText app and preview it (as per instructions mentioned above). You can also just run the claiming process and check what buttons need to be clicked on, to get an idea of what TEXT codes correspond to what buttons.

Once you've gone through and updated the TEXT code to the new images that you've scanned, you should be all good. Simply double click EpicGamesClaimer_xxxxxxxx.ahk to run it.


Scheduled_Run version

Basically, here's how the Scheduled_Run script works.

SetTimer, Claim_EpicGames_Trigger, 300000 is basically a timer. It is set to run the "Claim_EpicGames_Trigger" function every 300000ms, i.e every 5 minutes.

If TimeString between 10:30 and 10:34 basically checks if the current time is between 10:30am and 10:34am. This means that even when the timer runs this function every 5 minutes, it will only execute when the time is between 10:30am and 10:34am. Of course, change this to time to whatever you want, just make sure that the time is between 00:00 (12am) and 23:59 (11:59PM) and not something like 20:00 and 01:00, where the time cross over to the next day.


Mutliple Accounts Scheduled Run

For those with multiple Epic Games accounts, change the hotkeys to match what you've configured in Firefox previously. For example:

Send, !+{6}
Send, !+{7}
Send, !+{8}
Send, !+{9}
Send, !+{0}

This mens that Autohotkey will send the key combination ALT+SHIFT+X - where X is the number.

! = Alt
+ = Shift

For more info on AHK key modifiers, see here: https://www.autohotkey.com/docs/Hotkeys.htm



That's about it. So the general flow of the whole process goes like this:

Lastly, if you need to reset/stop the script urgently, press Shift+F7 on your keyboard. You can change this key combination trigger as well, just scroll to the bottom of the script.




chaoscreater commented 2 years ago

Had a few bugs in the script, updated it slightly in OP.

Bobu5 commented 2 years ago

i dont know why but for me, instead of Alt + Shift + [number], its Ctrl + Shift + [Number]

i havent tried the script yet but imma give it a try once im done with school stuff, pretty curious with this workaround

chaoscreater commented 2 years ago

You can set any key combination as hotkey trigger in the AHK script itself. I presume you were referring to setting Alt + Shift + [number] in Firefox. You'll need to check what key combinations are used in your Firefox extension shortcuts, as you could have multiple extensions with preset shortcuts that already are already using Ctrl + Shift + [number]. I always go through all the extension shortcuts and remove any that I don't actually use. This will allow me to use shortcut combinations without having conflicts and also will help me avoid accidentally triggering key combinations that will do something that I never intended.

Anyway, if you're using Ctrl+Shift+[number] in your Firefox, then in AHK script, instead of using this:

Alt + Shift + 6 !+{6}

you can use this:

Ctrl + Shift + 6 ^+{6}

chaoscreater commented 2 years ago

Updated script in OP again. Came across a different order flow today. If the game is 18+, it'll prompt for more questions and the original script was created specific for this. For a non 18+ game, the order flow is much simpler. Script should now cover both scenarios.

chaoscreater commented 2 years ago

Today, I just came across a new issue. Even though I'm not using Selenium or APIs to query the backend and I'm literally just using my browser with container tabs, I somehow was prompted for the hCaptcha in one of my logins. I wasn't logged out and didn't have to login (because I'm using Firefox containers), but I was still prompted at the very end of the checkout process (the part where you click Place Order). Seems like they are potentially looking at how many logins are coming from the same IP address....

chaoscreater commented 2 years ago

Updated instructions and added scripts for users with just a single Epic Games account. If you just have a single account, you don't need Firefox Containers. Just stay logged into your Epic Games account in your browser (Firefox) and it should be all good. Firefox Containers is mainly for people with multiple accounts.

Download the updated scripts in OP.

AndersWJ commented 2 years ago

I'm not trying to sell you on AHK or anything, but your arguments are confusing.

You've said a few times that you don't want to keep your PC running for AHK, yet your PC will be running Docker and most likely other things in the background. Ironically, Docker actually use more resource than AHK. Here's a screenshot of my AHK resource usage and it never uses more than 1% CPU and more than 1MB of RAM:

image

You seem to have the misconception that AHK take up a lot of system resources. You could run AHK on a super low spec machine and it would still be more efficient than running Docker. Regardless if you're running a VM or a container, you'd still have to have certain dependencies running in an isolated environment, in an additional layer above OS level. Probably even need Docker Swarm to manage multiple Docker containers if you want to run this for multiple Epic Games accounts. Not to mention keeping the image up to date with the Docker registry, etc. How are doing those things not more complicated, compared to just double clicking on a script to run it?

With AHK, you just have a single script. Double click script to run, done. Uses 0% CPU and 1MB of RAM. You need to update the script to fix something? Easy, done within 5 minutes and you're back working again. There's no messing about with updating your Docker image, no waiting on developers to release a new image update, etc. That's the complexity difference that I'm talking about.

I'm literally running a working solution atm, while you are still working for a Docker solution.

It's your choice and I'm not trying to persuade you or anything, but some of your points are rather contradicting. The only point I get is that you don't want to run Windows and want to run Linux, but everything else is literally just sandboxing an app (and dependencies) in an additional layer, whether that layer be a Docker container or a VM. Those in itself add complexity. They're great for work production environments with a lot of moving pieces, but sometimes people over-engineer and over-complicate things unnecessary and they don't see that.

I would be all for Docker, if the project is something that will always be supported by 1st party. For example, I use the NGINX Docker image and there is no cat and mouse game involved here. I don't have to worry about my NGINX breaking randomly one day, so it makes sense to use Docker for that. With projects created by 3rd parties, you're relying on the developers coming up with a fix. This hCaptcha thing has already been broken for at least 2 weeks now and you're still waiting for a Docker solution.

Compared to Heroku, Docker isn't even a good solution. There was a project that uses Heroku to claim Epic Games for you and it was working great, I was using Heroku free tier plans and didn't have to pay for any compute resources and didn't have to run anything on my PC. It was also self-updated as well, because the Heroku apps were deployed via Github Actions (i.e DevOps) and so any changes pushed to the author's master repo will automatically be updated in my forked repo, which then pushes the change to Heroku. It's all done automatically. Well guess what? Epic Games released an update and broke that and the project was still running into issues (also captcha related).

Lastly, just get a thin client and run Windows on it. I've used both Linux and Windows and they each have their Pros and Cons, which is why I still use both. I'm running most of my Windows specific apps on my laptop, which averages about 10-15W when I'm using it. When I'm playing games on it, it uses slightly more up to around 20-25W. Maximum wattage it'll go up to is 45W, but I never reach above 25W anyway. Undervolt the CPU using Throttlestop (or whatever tool of your choice) and you should be all good. I'm able to run a lot of stuff on my machines at home and I don't have to worry about power cost. Everything is running on low power and super efficient and my power bill has always been a low usage one. If you're too concerned about this, then you really need to measure how much power you're using vs how much you're acutally paying. If at the end of the day, using Windows somehow makes you pay $5 more every month, so what?

I have a dedicated Linux server running 24/7, which does a lot of things for me including running docker containers. This system is setup to run docker very nicely. And maintaining docker here, is super simple.

Its a NAS server (UnRaid) which have native support for this, and a gui to control everyting. It also does have support for VM. But this takes up too much cpu and memory to have up and running, as Windows itself consumes a lot of ressources without even doing anything in particular.

This is where dockers are super slim and trimmed down to ONLY do a single thing and every other thing is removed from the docker. It only uses a fraction of the ressources that a VM does.

Furthermore, is can be scheduled to run at a given time, and when the dokcer has done its job, it will automatically close down again, releasing all cpu, ram and disk ressources.

I am well aware of how both Linux and Window (and any other system) works, as I work with these things and have done so for 20+ years. So no need to lecture about this. - This is also the reason why I would prefer a docker solution over a Windows approach.

You keep mentioning complexity of dockers - I recon you havent work with dockers that much since you say this, as these are super simple and base foundation of most dockers are supported by millions of users worldwide? Should a simple thing be broken og need an update. This will be fixed faster than lightning, as the whole world run dockers on practically everything nowadays. So I am at no point worried for a docker container to break.

My gaming pc is consuming 200-300w when running. So this is not an option.

So, unless you are able to dockerize your AHK approach, let me know ;)

chaoscreater commented 2 years ago

I never said Docker itself is complicated, I deal with Docker and Kubernetes at work all the time. I have already explained to you that running the AHK solution is just double clicking the file. This takes literally 1 second. Whereas with Docker, it's simple, but not that simple in comparison. This is the complexity I'm talking about.

I've also explained it pretty clearly that there's a difference between 3rd party Docker images created by some random guy like you and me, VS a Docker image created and maintained by large organizations.

As I've said, there is currently no Docker solution and the issue has been going on for more than a week now. Your idea of a "3rd party" project getting fixed faster than lightning is already a misconception. It's always a cat and mouse game and it's never that quick to fix something. People have to spend time to reverse engineer and find workarounds. AHK on the other hand, is literally just getting the new X,Y co-ordinates of whatever button you're trying to press. Anyway can fix it easily without relying on others. This in itself is way less complex in comparison to anything else.

I use Docker for work and personal projects and I'm not against it. It's good for certain things, but there are things it's not good at. If it was so great, it would replace all VM workloads, but clearly it hasn't. Depending on the scenarios, you need certain tools for certain things. Sometimes, people just over-complicate and over-engineer something that does NOT need to be over-engineered. Not everything has to be containerized, not everything needs to be run in a VM, etc.

Anyway, let's just agree to disagree and move on.

UPDATE - June 27th 2022:

I come back here 6 months later to see how the project is going. Still no solution from the dev, unfortunately. My point above is still valid.

AndersWJ commented 2 years ago

I am not saying, that I disagree on using AHK can solve the problem. I never did. I just like to use a different approach than using Windows to solve it with. I respect that you (among others) are using AHK to solve it. Totally fine by me.

For me, docker is as simple as double clicking for me too. So there are no differences here as this is simply setup using a Gui for all dockers. I can setup a new docker container as fast as I can start a program in Windows. Its quite simple if you have the right tools setup for it.

The docker image is not just a "random image". The base image is actually a linux distro. And on top of this, we have the "app" running. So its only the app that can break down, (which is the case here).

Also, I am well aware, that there is no docker solution. And this is the reason why I was waiting for one in the first place. I actually never expected any magic to happend based on a single post on on github. Instead, I simply just wanted to hear if the solution was possible/achievable with the docker/linux setup, armed with the current knowledge at hand.

Before you posted, I got a simple answer from the dev. That was all I needed.