Scrap Mechanic

Scrap Mechanic

Not enough ratings
FIxing the multiplayer (very wacky way)
By [WFF] oNixu
A very go around way to fix issues with desync in multiplayer in Scrap Mechanic
   
Award
Favorite
Favorited
Unfavorite
DEV FIXED IT <3
I WILL LEAVE THIS GUIDE FOR THE FUTURE GENERATIONS, BUT DEVS FIXED THE ISSUE! :3
STEP 1 - Setup
Directories
Before we start anything we need to find our files!

Save fiels
C:\Users\XX\AppData\Roaming\Axolot Games\Scrap Mechanic\User\User_XXXX\Save\Survival
x's denotes where you will have personal data
To access the appdata folder press windows + R and type in appdata, I think you will easly navigate from there

Game files
Right click on the game in your game libary > browse local files. File we are interested in this dir:
X:\SteamLibrary\steamapps\common\Scrap Mechanic\Survival\Scripts\game

we are looking for a script named: survival_spawns.lua

!!!CREATE BACKUP OF THIS FILE!!!

TOOLS
Any sqlite viewer, for this guide I use DBeaver
DBbeaver download link[dbeaver.io]
STEP 2 - Reset the tick counter
Now on to the hard part, where my fellow mechanics will enjoy screenshots in language they do not understand but will surley recognise

Backup your save file

create copy of your file, it will be needed if we mess up big time. As you can see in the image above, you can do it in a messy way, we do not care at this point. You can copy the db file to some location you can easly access

Open save in Dbeaver
As said you can use any SQLite viewer, but images below are for DBeaver.

  • New connection

  • Select sqlite


  • Select save that you want to edit


Editing the save value
Now that we have our save opened, we have to change just one thing. In Game table change the Gametick to 1

Press ctrl+s to save the file. Put the file back into your saves folder so we can launch it.
DONT LAUNCH THE FILE JUST YET
STEP 3 - the wacky time :3
Now that we ruined our save file synchronization issues it will work in multiplayer without any desync
BUT WAVES WILL NOT SPAWN - let's fix that!

Editing the core game lua files (very safe)

This step will reset the spawn timers of creats and creatures, will not remove the ones you already have, but just FYI

Now we need to edit the LUA file we have located earlier. Please please just do backup of it just in case. Copy it somewhere or rename it, idc, just do a copy of it.

If you feel lazy you can just replace contents of your script with this pastebin: Feet pics[pastebin.com]

You can open it in notepad if you are a masochist, notepad++ if you fill fancy or any other text editor. I recommend any editor with line counter, as I will provide the line no. for ease of navigation.

We will need to copy the sweet script below (without the lines at the start and end):
----------------------------------------------------------------------------------
for x = -64, 63 do
for y = -48, 47 do
-- Create a cell object for the current (x, y)
local cell = { x = x, y = y, worldId = 1 } -- Add the appropriate worldId if necessary
local cellKey = CellKey(cell.x, cell.y)
local spawnDesc = SpawnDescriptions[tag]

-- Assert the existence of the spawn description
assert(spawnDesc, "No spawn description attached to this tag!")

-- Skip processing if respawn is nil
if spawnDesc.respawn == nil then
goto continue
end

-- Get the current tick
local currentTick = sm.game.getCurrentTick()
local loaded = { tick = currentTick } -- Replace this with the actual loaded logic if necessary

-- Ensure currentTick is valid
assert(spawnDesc.ticksBetweenRespawns, "Missing ticksBetweenRespawns in spawnDesc!")

-- Save the spawn state in storage
sm.storage.save({ spawnDesc.channel, cell.worldId, cellKey }, { tick = currentTick, storage = storage })
print('cell ', x, y, ' reloaded')

::continue::
end
end
--------------------------------------------------------------
We paste it in two places (overkill but it makes sure the things are done):
LINE 477

LINE ~540
FROM RESPAWN FUNCTION ALSO REMOVE LINES TO MATCH SCREENSHOTS ABOVE PLESE

Now save your file




STEP 4 - Scawy time :O
Executing the script
Now that we have made those changes we can launch the game.

THIS STEP IS THE WORST, JUST BEARE WITH ME

Before we launch our save, just a disclaimer. Chat GPT script My script will cause your game to crash. That is expected. Just embrace the junk.

Launch the edited save
Now we need to launch the save we just edited and do nothing. Wait for game to finish loading - you will see your normal screen but the game will be frozen due to the loop we have injected running over and over again. When you reach that state just close the game. Script did its thing, trust me.

STEP 5 - Clean up
Restore the files
Now that we have rendered our game unplayable let's fix that. Only thing we need to do is remove our edited script (the respawn one) and replace it with the original file. Now our file is fixed and we should be able to play normal multiplayer.

CHECKSUM PROBLEM
If during other players joning game throws out a error with checksum of our file, just reinstall the game.

It is recommended that you reinstall anyways. Just to be sure.
Why all that?
For some reason the game after around 7hr becomes unplayable in multiplayer. It might be because of the high tick counter reaching the limit of a 32 bit integer (just a wild guess). So we reset that.
HOWEVER the spawn rates are hard stored in the game and are storred in the sql database in a format I cannot be bothered to decode. Because how the code handles things, any cell that is loaded with low tick value in place that was previously looted with high tick value will cause the cell to become "corrupt". The game uses dict to store all the loaeded cell, and code that is responsible for that just trhows exception and does not add our cell to the dict. This dict is being used by other parts of code, mainly the Wave spawn calculations. Beacuse of that we need to fix that ourselves, so the script resets the saved tick value for every cell on the map just to be sure .
KNOWN ISSUES
  • My day counter is stuck at 0
    Yeah that is the problem. Maybe somebody less burned out from trying to figure out this game can fix that
13 Comments
xcallumnicx 18 Aug @ 12:51am 
:P
HellsxFire 9 Dec, 2024 @ 11:10am 
for stuck at 20fps check step 5 or deleted the file and let steam re download it.
flosslikeaboss73 9 Dec, 2024 @ 8:29am 
my fps is also at 20 after doing this, what can i do
Butterscotch! 9 Dec, 2024 @ 1:56am 
I've written my own script so it's less jank and doesn't make the save massive
https://gist.github.com/ButterscotchV/eca8bec04eb50956735da1158b0c43e7
bionic≽^•⩊•^≼ 8 Dec, 2024 @ 11:23pm 
thanks cuh
RelaxedDragon65 8 Dec, 2024 @ 8:23pm 
hi just did your fix im now running at 20fps instead of my average of 80 any idea why?
cpu is at 30% usage gpu is at 30% as well
Retro 8 Dec, 2024 @ 6:23pm 
i found that setting it to 1 works but you have to reset it every 7 hours
Rikunie 8 Dec, 2024 @ 5:33pm 
When I go to open the 'file' in the SQLite I cannot get to the graph section. What am I doing incorrectly? I cannot get to the section of "Editing the Save Value" Please help I have operator error illness.
>Misilia< 8 Dec, 2024 @ 12:06pm 
Very good tutorial, i cried and almost broke my computer to fix this game, and then i found this and my life got good again.

Thank you oNixu for your service.
[WFF] oNixu  [author] 8 Dec, 2024 @ 11:57am 
As said in the guide, if you do ALL the steps it will not stop crates and creatures from spawning as the STEP 4 resets the spawn counters to synch it with the 'new' tickrate