PowerShell - Lethal Company BepInEx one-click mods synchronizer powered by S3 buckets (Cloudflare R2) and RClone

PowerShell - Lethal Company BepInEx one-click mods synchronizer powered by S3 buckets (Cloudflare R2) and RClone

· json · rss
Watch:
Subscribe:

A few months ago, I was very active in playing Lethal Company with my peers. With the introduction of the mods from the modding community, it enhanced gameplay tremendously and me and my friends had a lot of fun.

However, my friends are not very tech-savvy, and I did not want them to go through the trouble of installing r2modman, traversing the UI, typing the export UUID and getting my mods every single time I update. But I would like to continue to manage my mods using r2modman as it makes updating mods a breeze.

I had a few friends who, unfortunately, were working with data limits as well and could not keep downloading a zip file containing hundreds of megabytes worth of all my mods.

Most of my friends are on Windows as well, so I had to cater for that fact.

Solution

A PowerShell script that allows a one-click automatic mod update that also does delta downloads (only downloads changed files).

Said PowerShell script is powered by an S3 bucket, in my case Cloudflare R2, and RClone.

Prerequisites

  1. A Cloudflare account
  2. A payment method to enable the use of R2 (pay-per-usage)
  3. r2modman installed with a few Lethal Company mods already added

Instructions

Add the Cloudflare R2 subscription on your Cloudflare dashboard

Make sure to take note of the limits and keep it below that to stay on the free tier. Unless you have a lot of mods or a lot of friends, it's unlikely to hit the free-tier limits with just this.

Create an R2 bucket

After subscribing, you can now go ahead and create an R2 bucket, it is recommended to select a location hint to a region near yourself and your friends.

In this case, we are calling the bucket `lethalcompany`.

Generating a read-only and a read-write API tokens for the bucket

In our case, we would want 2 types of keys, a read-only one that will be sent to your friends and the other for you to upload mods.

You can manage your API tokens here on the right side of the R2 overview page as of the time of posting:

Note: Make sure to note down the Access ID here for later.

You would want to create a read-only token similar to the following:

Note: Make sure to note down the Access Key ID and Secret Access Key after creating and note down this is for read-only!

And a read-write token as follows:

Note: Make sure to note down the Access Key ID and Secret Access Key after creating and note down this is for read-write!

Find your Lethal Company r2modman profile folder

Open r2modman to Lethal Company and open the Settings section

From there you would want to click on `Browse profile folder` and it would open up your profile folder in Windows Explorer

Download RClone

You have a choice of downloading from 2 official places:

  1. Official website
  2. Github

In most cases, you should be downloading the Windows Intel/AMD - 64 Bit build.

After downloading, open up the zip archive and traverse into the folder until you see `rclone.exe`

Drag and drop `rclone.exe` onto the Lethal Company r2modman profile folder you've found above

Create RClone configuration for uploading

In your Lethal Company r2modman profile folder, beside the new `rclone.exe`, create a file named: `z_rclone.conf`

Copy and paste the following into `z_rclone.conf`:

[r2]
type = s3
provider = Cloudflare
access_key_id = PASTE_OVER_YOUR_READ_WRITE_ACCESS_KEY_HERE
secret_access_key = PASTE_OVER_YOUR_READ_WRITE_SECRET_ACCESS_KEY_HERE
endpoint = https://PASTE_OVER_YOUR_R2_ID_HERE.r2.cloudflarestorage.com

Make sure to replace the PASTE_OVER values according to your read-write R2 token and Account ID.

Note: The `z_` prefix is important to set up ignore rules, but can be customized later on.

Create mods uploader script

In the same folder, create a file named: `z_upload.bat`

Copy and paste the following into `z_upload.bat`:

# 2>NUL & @CLS & PUSHD "%~dp0" & "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -nol -nop -ep bypass "[IO.File]::ReadAllText('%~f0')|iex" & POPD & EXIT /B

if (Test-Path -Path '.\Lethal Company.exe') {
    Write-Host "Error: Lethal Company.exe detected! Do not run the uploader here!"
    cmd /c pause
    Exit
}

$ErrorActionPreference = "Inquire"

Write-Host 'Uploading...'
./rclone --config ./z_rclone.conf -v sync --checkers 12 --transfers 12 --update --checksum --use-server-modtime --fast-list --delete-excluded . r2:lethalcompany --exclude z_rclone.conf --exclude-from z_exclude.txt

Write-Host "Mod upload complete!"
cmd /c pause
Note: The `z_` prefix is important to set up ignore rules, but can be customized later on.

Create files to exclude list

In the same folder, create a file named: `z_exclude.txt`

Copy and paste the following into `z_exclude.txt`:

z_*
mods.yml
LogOutput.log
*.zip
_state/**
BepInEx/cache/**
BepInEx/plugins/**/*.old
BepInEx/plugins/**/icon.png
BepInEx/plugins/**/manifest.json
BepInEx/plugins/**/README
BepInEx/plugins/**/CHANGELOG
BepInEx/plugins/**/LICENSE
BepInEx/plugins/**/INSTALLING
BepInEx/plugins/**/*.md
BepInEx/plugins/**/*.txt
Note: The `z_` prefix is important to set up ignore rules, but can be customized later on.

Run the upload script

Double-click on `z_upload.bat` and run it to upload your mods, if you have configured your `rclone.conf` file properly, it should get uploaded smoothly.

Note: Your output should be longer than this as you are uploading mods from scratch

Now that your mods are all uploaded, we can set up the mod downloader configuration and script to send to your friends

Create RClone configuration for downloading

In the same folder, create a file named: `rclone.conf`

Copy and paste the following into `rclone.conf`:

[r2]
type = s3
provider = Cloudflare
access_key_id = PASTE_OVER_YOUR_READ_ONLY_ACCESS_KEY_HERE
secret_access_key = PASTE_OVER_YOUR_READ_ONLY_SECRET_ACCESS_KEY_HERE
endpoint = https://PASTE_OVER_YOUR_R2_ID_HERE.r2.cloudflarestorage.com

Make sure to replace the PASTE_OVER values according to your read-only R2 token and Account ID.

Create the mod downloader script

In the same folder, create a file named: `update_mods.bat`

Copy and paste the following into `update_mods.bat`:

# 2>NUL & @CLS & PUSHD "%~dp0" & "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -nol -nop -ep bypass "[IO.File]::ReadAllText('%~f0')|iex" & POPD & EXIT /B

if (-not(Test-Path -Path '.\Lethal Company.exe')) {
    Write-Host "Error: Make sure this file is in the same folder as Lethal Company.exe before running!"
    cmd /c pause
    Exit
}

$ErrorActionPreference = "Inquire"

Write-Host '(1/2) Syncing base files...'
./rclone.exe --config ./rclone.conf -P --stats-one-line copy --checkers 12 --transfers 12 --checksum --use-server-modtime --fast-list r2:lethalcompany . --exclude BepInEx/

Write-Host '(2/2) Syncing mods...'
./rclone.exe --config ./rclone.conf -P --stats-one-line sync --checkers 12 --transfers 12 --checksum --use-server-modtime --fast-list r2:lethalcompany/BepInEx/ ./BepInEx/

Write-Host "Mod update complete!"
cmd /c pause

Test the mod downloader

Open Steam and click on Lethal Company

Click on the gear icon on the right side

Traverse to `Manage` and click on `Browse local files` to open up the Lethal Company game folder on Windows Explorer

Copy `rclone.conf`, `rclone.exe` and `update_mods.bat` from your Lethal Company r2modman profile folder here.

Double click update_mods.bat and run it.

If everything is configured well, the mods should download nicely.

Ship the mod downloader to your friends

Select `rclone.conf`, `rclone.exe` and `update_mods.bat`.

Important: do not select the files starting with `z_`! They are meant to be for you only.

Right click any of the selected files, traverse to `Send to` and click on `Compressed (zipped) folder`

Go ahead and rename the zip file if needed and send it to your friends.

Instruct them to find the Lethal Company folder with the same steps as Test the mod downloader, extract the 3 files there and double-click `update_mods.bat` and run it.

They should observe the same results as you.

After which, the game can be launched and your friends will have the exact same mods as you!

Afterword

Note that a few antiviruses will flag rclone.exe as a virus as a false positive, you may need to add it to your antivirus scan exclusion list or just not use this at all.

Although the setup is lengthy, after everything, the mod update flow is really just a matter of (as seen in the demo video)

  1. updating mods with r2modman
  2. z_upload.bat
  3. get your friends to run update_mods.bat

No need for traversing the r2modman UI at all and pasting UUIDs.

You may notice in my demo, my mod updater has a few more steps, I've excluded them as feel that they are out of scope for this post.

As we are already doing a lot of do-it-yourself, everything above is customizable, and you can add and remove features if you wish to do so, your imagination is the limit!