Re-Enable Achievements...

Post all other topics which do not belong to any other category.
Coolshrimp
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sat Oct 30, 2021 7:42 pm
Contact:

Re: Re-Enable Achievements...

Post by Coolshrimp »

feel free to test out the tool it will now patch and enable achievements again thanks for your code it works on my saves hope it works for the rest of you.

https://github.com/coolshrimp/Factorio- ... erver-Tool

Image
jakeroxs
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Oct 28, 2024 11:08 pm
Contact:

Re: Re-Enable Achievements...

Post by jakeroxs »

xrobau wrote: Mon Nov 04, 2024 2:01 am
Pain12345 wrote: Thu Oct 31, 2024 5:22 pm I wrote a small Console application to patch the save game: https://github.com/Rainson12/FactorioSa ... hievements
This doesn't appear to work when purely enabling the editor. There is no 'command-ran' when simply starting a new game and then /editor.
Ha that might be what it wasn't working for me, I have so far only enabled the editor as we had vastly underestimated what was needed to go to a new planet and tp'd myself back to nauvis, RIP first space platform.

Edit:
Definitely why it's not working for me, did the same and started a new game, did a console command to disable achievements, ran tool, achievements re-enabled.

Ran /editor to disable achievements, ran tool, error message I posted before, reloaded game and achievements still disabled (as expected), resaved game, re ran tool and no error, achievements still disabled.

For fun I then tried on the same save to run a command that would have disabled achievements thinking maybe it was a separate flag that could clear up both, reran tool and no error message but achievements still disabled.

So it definitely appears that /editor is somehow differently stored in the save for achievement disabling :(
sneednman
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sat Nov 16, 2024 6:00 pm
Contact:

Re: Re-Enable Achievements...

Post by sneednman »

I just wanted to say Pain12345's tool still works for patching, however I had to re-run a command in order for it to work. If it's not working for any of you, try re-running a new command, saving your world, and then running the tool as this fixed my issue.
xevioni
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sat Aug 03, 2024 5:48 am
Contact:

Re: Re-Enable Achievements...

Post by xevioni »

I'm far from an expert in this stuff, but the above replies were immensely helpful in building my solution.

I hold a 25MB save with 120 or so hours in it, so I was kinda desperate to re-enable achievements.

Here's what I've found so far:
- The marker is a set of 1 byte booleans that are either 0x00 or 0x01 depending on their state. The command marker comes before the map editor marker, but they are always together it seems.
- After a certain amount of bytes (16 or less, roughly), two pairs of 8 byte sequences of just 0xFF occur. In older saves, they probably won't be right next to each other, but in newer saves, they likely WILL be.
- You can enable the map editor flag while disabling the command flag.

Image

Here's a little printout from a program I was making to try and automate this process (especially the ZLib decoding/ZIP repackaging).
Most of the above images don't have a 0x01 0x00 0x01 sequence like this (I think). My program latched onto the Red byte, but it's irrelevant.
The green byte is the critical 'Command' flag that needs to be disabled. I just hardcoded the offset from the Red in my program, and it re-enables achievements just fine.
The blue byte, of course, is the map editor flag. And yeah, I set it to 0x01 and it changed the achievements disabled message to fit.

You can also see the 'command-run' text near the bottom of the range, which is the first thing my program latches onto.
- It first searches for the ASCII pattern 'command-ran' (although 'horizontal_flow' works too, it's just farther away, about 1,100 to 1,200 bytes away, this seems to be useful in the case of Map Editor).
- Then, it searches backward TWICE to find the 8-byte 0xFF sequences. It accounts for the possibility that they might be touching each other (like in the case above).
- Then, it looks for the first 0x01 byte. I don't know enough about it's possible offset or patterns, so this is where me hardcoding in the behavior came in handy.

I hope this comes in a little handy; I don't know whether I'd want to publish a specific program or anything as the critical section is really case-by-case. If you know what you're doing, it would be a shortcut for a solution, but if you don't know what you're doing - the above text is more helpful than my code.
This message will be edited later on IF I end up publishing something. Assuming I can edit my posts...
jakeroxs
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Oct 28, 2024 11:08 pm
Contact:

Re: Re-Enable Achievements...

Post by jakeroxs »

xevioni wrote: Fri Nov 22, 2024 12:25 pm I'm far from an expert in this stuff, but the above replies were immensely helpful in building my solution.

I hold a 25MB save with 120 or so hours in it, so I was kinda desperate to re-enable achievements.

Here's what I've found so far:
- The marker is a set of 1 byte booleans that are either 0x00 or 0x01 depending on their state. The command marker comes before the map editor marker, but they are always together it seems.
- After a certain amount of bytes (16 or less, roughly), two pairs of 8 byte sequences of just 0xFF occur. In older saves, they probably won't be right next to each other, but in newer saves, they likely WILL be.
- You can enable the map editor flag while disabling the command flag.

Image

Here's a little printout from a program I was making to try and automate this process (especially the ZLib decoding/ZIP repackaging).
Most of the above images don't have a 0x01 0x00 0x01 sequence like this (I think). My program latched onto the Red byte, but it's irrelevant.
The green byte is the critical 'Command' flag that needs to be disabled. I just hardcoded the offset from the Red in my program, and it re-enables achievements just fine.
The blue byte, of course, is the map editor flag. And yeah, I set it to 0x01 and it changed the achievements disabled message to fit.

You can also see the 'command-run' text near the bottom of the range, which is the first thing my program latches onto.
- It first searches for the ASCII pattern 'command-ran' (although 'horizontal_flow' works too, it's just farther away, about 1,100 to 1,200 bytes away, this seems to be useful in the case of Map Editor).
- Then, it searches backward TWICE to find the 8-byte 0xFF sequences. It accounts for the possibility that they might be touching each other (like in the case above).
- Then, it looks for the first 0x01 byte. I don't know enough about it's possible offset or patterns, so this is where me hardcoding in the behavior came in handy.

I hope this comes in a little handy; I don't know whether I'd want to publish a specific program or anything as the critical section is really case-by-case. If you know what you're doing, it would be a shortcut for a solution, but if you don't know what you're doing - the above text is more helpful than my code.
This message will be edited later on IF I end up publishing something. Assuming I can edit my posts...
Nice, I will see if I can get this working, I resigned myself to just using CE to re-enable the achievements every time I launch the game, which works a bit oddly sometimes.

Edit: With lots of trial and error, and some modifications to the program Rainson12 wrote, I was able to find which .dat file I needed to hexedit to get this working.

Ultimately I found that because I ran /editor before running any other commands, command-ran was not found in my save so it couldn't find the right place, so I adjusted it to look for 'horizontal_flow' per your comment, then searched backwards for the hex string FFFFFFFFFFFFFFFF, found what looked to be the right section per your screenshot, adjusted the values to 00 and seems like achievements are enabled in the save!
TheCherry
Burner Inserter
Burner Inserter
Posts: 13
Joined: Fri Jan 18, 2019 10:00 am
Contact:

Re: Re-Enable Achievements...

Post by TheCherry »

I made a patcher too. Its catch the cases with editor, cheat and command.
Works for 2.0.21

https://github.com/dakiba/factorio_achi ... _space_age

EDIT: Sadly its seems to catch only local save games. We play on a dedicated server and use forces (the pvp scenario, but just for teams and bases). Chat messages are not recorded in the level.dat files there ... I see no way to find that important byte ....
KnightDemons
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Dec 05, 2024 10:52 am
Contact:

Re: Re-Enable Achievements...

Post by KnightDemons »

Pain12345 wrote: Thu Oct 31, 2024 5:22 pm I wrote a small Console application to patch the save game: https://github.com/Rainson12/FactorioSa ... hievements
It will
1. unzip the savegame
2. decompress all .dat files
3. screen the unzipped files for occurrence of "command-ran"
4. patch the 01 closest to the found occurrence by searching for "00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF" binary pattern
5. pack the dat file again
6. Backing up original save file
7. Creating new save file by zipping everything again
8. Cleaning up the temporary folder
Thank you for this. I kept trying to fix the files on my own but it wasn't undoing anything in the save. (I just was using /c game.player.force.rechart() to update map for Solid Ore Colors in Map View mod but I guess that's a 'cheat' command.) Ran the console app and Boom Boom Boom Boom. Like I never disabled achievements. 8-)
User avatar
louanbastos
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Dec 24, 2024 9:31 pm
Contact:

Re: Re-Enable Achievements...

Post by louanbastos »

Image
Image
Image
Image
Image

There are some achievements that are locked by time or with other requirements, it would be interesting to have a way to reactivate these achievements and if possible set a longer time or remove that time.

Is there any mod/program/script that fixes and resets this?
naibudeshinu
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Jan 16, 2025 8:17 pm
Contact:

Re: Re-Enable Achievements...

Post by naibudeshinu »

xrobau wrote: Mon Nov 04, 2024 2:01 am
Pain12345 wrote: Thu Oct 31, 2024 5:22 pm I wrote a small Console application to patch the save game: https://github.com/Rainson12/FactorioSa ... hievements
This doesn't appear to work when purely enabling the editor. There is no 'command-ran' when simply starting a new game and then /editor.

There IS 'editor-will-disable-achievements', which has '00000001000100000000000a0a00000000ffffffffffff' a fair way back from it, but that's not the 6/7 byte offset you have in your script. Where did you get those numbers from, out of curiosity?
So after some digging I was able to re-enable my achievements after using both commands and running /editor

As discussed above, you are suppose to find 16 consecutive F's and flip the 1 to a zero but for me, I had a different line of code as shown here. What I found out was that the leftmost "1" was for the editor flag and the right-most "1" was for command flag. I tested this by flipping them and saw that my achievements were either disabled because "commands were used" or "map editor was used". So if you have used both like me, you will have to flip the first two one's in that sequence.

Image

I tried this on two fresh saves and the sequence was the same.This might be different for others but it took a little bit of testing to finally restore my save. Hope this helps.
Attachments
yo.png
yo.png (64.58 KiB) Viewed 655 times
hraukr
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sat Jan 25, 2025 7:36 am
Contact:

Re: Re-Enable Achievements...

Post by hraukr »

Guide for Windows 11 users that have trouble with the previously mentioned tools.

To summarise above, in my understanding, you are looking for a string in the level.dat files that contains 8 hexadecimal "FF"s followed closely (within 8 to 16 hex bytes) by another set of 8 "FF"s. Immediately preceeding the first set of "FF"s are the two (three?) sets that determine whether achievements have been disabled and why.

EX.

Code: Select all

01 84 04 00 00 00 00 00 00 01 01 ff ff ff ff ff 
ff ff ff f9 23 12 04 20 20 20 20 ff ff ff ff ff 
ff ff ff 50 46 00 00 00 00 00 00 00 00 01 00 00
See on line 1, the two "01"s before the first "FF". Those represent the map editor and command line use, respectively. When either is set to "01", achievements are disabled. When both are set to "00", achievements are re-enabled for that save only. Global/Steam achievements are still disabled as far as I can tell.

To disable these bits on Windows 11 :

Step 1. Install the latest Python from the microsoft store - https://apps.microsoft.com/detail/9PNRBTZXMB4Z

Step 2. Copy a save file that you wish to edit to a new temporary folder on your desktop or elsewhere unimportant

Step 3. Using 7zip or another archive tool, open the save zip file in copy the level.dat# files from to a new folder within the temp folder

Step 4. Using a text editor, create the following file in the new folder with the level.dat files. Name it something like 'inflate.py'

Code: Select all

import os
import zlib

def inflate_files():
    current_dir = os.getcwd()
    output_dir = os.path.join(current_dir, "inflated_files")
    os.makedirs(output_dir, exist_ok=True)
    
    # Iterate through files matching level.dat# pattern
    for file in sorted(os.listdir(current_dir)):
        if file.startswith("level.dat") and file[len("level.dat"):].isdigit():
            input_path = os.path.join(current_dir, file)
            output_path = os.path.join(output_dir, f"{file}.inflated")
            
            try:
                with open(input_path, "rb") as f:
                    compressed_data = f.read()
                    inflated_data = zlib.decompress(compressed_data)
                    
                with open(output_path, "wb") as f:
                    f.write(inflated_data)
                    
                print(f"Inflated {file} -> {output_path}")
            except Exception as e:
                print(f"Failed to inflate {file}: {e}")

if __name__ == "__main__":
    inflate_files()
Step 5. Right click in a blank area of the folder with the .dat files and choose Open in Terminal

Step 6. Run the command: python .\inflate.py

Step 7. Using a text editor, create the following file in the new inflated_files folder with the level.dat.inflated files. Name it something like 'search.py'

Code: Select all

import os

def search_word(term):
    current_dir = os.getcwd()
    search_bytes = term.encode("utf-8")
    
    # Iterate through all files in the current directory
    for file in sorted(os.listdir(current_dir)):
        file_path = os.path.join(current_dir, file)
        
        if os.path.isfile(file_path):
            try:
                with open(file_path, "rb") as f:
                    data = f.read()
                    
                # Search for the given term in the binary data
                if search_bytes in data:
                    print(f"Found '{term}' in {file}")
            except Exception as e:
                print(f"Failed to process {file}: {e}")

if __name__ == "__main__":
    search_term = input("Enter the search term: ")
    search_word(search_term)
Step 8. Right click in a blank area of the inflated_files folder and choose Open in Terminal

Step 9. Run the command: python .\search.py and enter a search term to try and find the terms mentioned above, either 'editor', 'achievement', 'command', or others I may not have mentioned.

The results should hopefully find a mention of one of these words in one of the .dat files that is relatively at the point in your playtime that achievements were disabled. IE. If achievements were disabled recently, expect to find it in the highest numbered .dat files. If achievements were disabled roughly halfway through your saves play time, and you have 50 level.dat files, expect it to be around file 25.

Step 10. Open one/all of the found dat files with a hex editor (Notepad ++ with Hex editor plugin, or a freeware hex editor called HxD) and run a search for "FF FF FF FF FF FF FF FF". There may be quite a few, find the one that is almost immediately followed by another set of "FF FF FF FF FF FF FF FF", within 8 to 16 bytes.

If you have found it, you should see the two bytes preceding the first set of "FF"s with at least one of them being "01". Change both to "00". Save the file.

Step 11. Using a text editor, create the following file in the inflated_files folder with the level.dat.inflated files. Name it something like 'deflate.py'

Code: Select all

import os
import re
import zlib

def deflate_files():
    # Define input pattern and output directory
    pattern = re.compile(r"level\.dat(\d+)\.inflated$")
    output_dir = "deflated_files"
    os.makedirs(output_dir, exist_ok=True)
    
    # Iterate through files in the current directory
    for filename in sorted(os.listdir()):
        match = pattern.match(filename)
        if match:
            file_number = match.group(1)
            input_path = filename
            output_path = os.path.join(output_dir, f"level.dat{file_number}")
            
            try:
                with open(input_path, "rb") as f_in:
                    inflated_data = f_in.read()
                    deflated_data = zlib.compress(inflated_data)
                    
                with open(output_path, "wb") as f_out:
                    f_out.write(deflated_data)
                
                print(f"Deflated: {input_path} -> {output_path}")
            except Exception as e:
                print(f"Error processing {input_path}: {e}")

if __name__ == "__main__":
    deflate_files()
Step 12. Right click in a blank area of the inflated_files folder and choose Open in Terminal (Or use the already open terminal window if you didn't close it)

Step 13. Run the command: python .\deflate.py

Step 14. Go back to/re-open the save.zip in the temp folder. And delete the respective level.dat# files that you edited and copy the edited one from inflated_files back into the save.

Step 15. To avoid deleting your good save, rename the edited save file in the temp folder, maintaining the .zip filename. Copy the edited save to the Factorio save game folder.

If everything worked, you should have a save game with achievements enabled!

Sorry Wube :? But I had to use the editor to delete Aquilo to get the Dredgeworks: Frozen Reaches mod to work. 30 hours later I realised no achivements! ;)
Post Reply

Return to “General discussion”