<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="/rss/stylesheet/" type="text/xsl"?>
<rss xmlns:content='http://purl.org/rss/1.0/modules/content/' xmlns:taxo='http://purl.org/rss/1.0/modules/taxonomy/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:itunes='http://www.itunes.com/dtds/podcast-1.0.dtd' xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:podbridge='http://www.podbridge.com/podbridge-ad.dtd' version='2.0'>
<channel>
  <title>Jaryl Chng&apos;s Knowledge Base</title>
  <language>en-us</language>
  <generator>microfeed.org</generator>
  <itunes:type>episodic</itunes:type>
  <itunes:explicit>false</itunes:explicit>
  <atom:link rel="self" href="https://kb-jarylchng-com.pages.dev/rss/" type="application/rss+xml"/>
  <link>https://kb.jarylchng.com</link>
  <description>
    <![CDATA[<p>Welcome to the index page of my knowledge base, if you haven't done so, do visit my website at <a href="https://jarylchng.com" rel="noopener noreferrer" target="_blank">https://jarylchng.com</a>.</p><p>I will mainly use this site to document stuff, most of which will likely be in the public domain.</p>]]>
  </description>
  <itunes:author>Jaryl Chng</itunes:author>
  <itunes:image href="https://kb-static.jarylchng.com/kb-jarylchng-com/production/images/channel-c68f1f55f856ab833b4365991609dbec.png"/>
  <image>
    <title>Jaryl Chng&apos;s Knowledge Base</title>
    <url>https://kb-static.jarylchng.com/kb-jarylchng-com/production/images/channel-c68f1f55f856ab833b4365991609dbec.png</url>
    <link>https://kb.jarylchng.com</link>
  </image>
  <copyright>©2024</copyright>
  <itunes:category text="Technology"/>
  <item>
    <title>PowerShell - Lethal Company BepInEx one-click mods synchronizer powered by S3 buckets (Cloudflare R2) and RClone</title>
    <guid>D0SMMNp96yY</guid>
    <pubDate>Sun, 14 Apr 2024 07:55:00 GMT</pubDate>
    <itunes:explicit>false</itunes:explicit>
    <description>
      <![CDATA[<p>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.</p><p>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.</p><p>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.</p><p>Most of my friends are on Windows as well, so I had to cater for that fact.</p><h2>Solution</h2><p>A PowerShell script that allows a one-click automatic mod update that also does delta downloads (only downloads changed files).</p><p>Said PowerShell script is powered by an S3 bucket, in my case Cloudflare R2, and RClone.</p><h2>Prerequisites</h2><ol><li>A Cloudflare account</li><li>A payment method to enable the use of R2 (pay-per-usage)</li><li>r2modman installed with a few Lethal Company mods already added</li></ol><h2>Instructions</h2><h3>Add the Cloudflare R2 subscription on your Cloudflare dashboard</h3><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/D0SMMNp96yY/image-4da53a80abf3b1ab1da81c77e384798b.png"></p><p>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.</p><h3>Create an R2 bucket</h3><p>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.</p><p>In this case, we are calling the bucket `lethalcompany`.</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/D0SMMNp96yY/image-608d29889776dddc5e5314182c03230e.png"></p><h3>Generating a read-only and a read-write API tokens for the bucket</h3><p>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.</p><p>You can manage your API tokens here on the right side of the R2 overview page as of the time of posting:</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/D0SMMNp96yY/image-2d182f34d7d47480bcec57da977ebe32.png"></p><blockquote>Note: Make sure to note down the Access ID here for later.</blockquote><p>You would want to create a read-only token similar to the following:</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/D0SMMNp96yY/image-6d350fed7c5957da5c920f8cca89d2f1.png"></p><blockquote>Note: Make sure to note down the Access Key ID and Secret Access Key after creating and note down this is for read-only!</blockquote><p>And a read-write token as follows:</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/D0SMMNp96yY/image-5e34e92861891186df5e7f9b7a5c2b5f.png"></p><blockquote>Note: Make sure to note down the Access Key ID and Secret Access Key after creating and note down this is for read-write!</blockquote><h3>Find your Lethal Company r2modman profile folder</h3><p>Open r2modman to Lethal Company and open the Settings section</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/D0SMMNp96yY/image-174f2a65940e116bd97dba3c0e3c1a86.png"></p><p>From there you would want to click on `Browse profile folder` and it would open up your profile folder in Windows Explorer</p><h3>Download RClone</h3><p>You have a choice of downloading from 2 official places:</p><ol><li><a href="https://rclone.org/downloads/" rel="noopener noreferrer" target="_blank">Official website</a></li><li><a href="https://github.com/rclone/rclone/releases" rel="noopener noreferrer" target="_blank">Github</a></li></ol><p>In most cases, you should be downloading the Windows Intel/AMD - 64 Bit build.</p><p>After downloading, open up the zip archive and traverse into the folder until you see `rclone.exe`</p><p>Drag and drop `rclone.exe` onto the Lethal Company r2modman profile folder you've found above</p><h3>Create RClone configuration for uploading</h3><p>In your Lethal Company r2modman profile folder, beside the new `rclone.exe`, create a file named: `z_rclone.conf`</p><p>Copy and paste the following into `z_rclone.conf`:</p><pre class="ql-syntax" spellcheck="false">[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
</pre><p>Make sure to replace the PASTE_OVER values according to your <strong>read-write</strong> R2 token and Account ID.</p><blockquote>Note: The `z_` prefix is important to set up ignore rules, but can be customized later on.</blockquote><h3>Create mods uploader script</h3><p>In the same folder, create a file named: `z_upload.bat`</p><p>Copy and paste the following into `z_upload.bat`:</p><pre class="ql-syntax" spellcheck="false"># 2&gt;NUL &amp; @CLS &amp; PUSHD "%~dp0" &amp; "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -nol -nop -ep bypass "[IO.File]::ReadAllText('%~f0')|iex" &amp; POPD &amp; EXIT /B

if (Test-Path -Path '.\Lethal Company.exe') {
&nbsp; &nbsp; Write-Host "Error: Lethal Company.exe detected! Do not run the uploader here!"
&nbsp; &nbsp; cmd /c pause
&nbsp; &nbsp; 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
</pre><blockquote>Note: The `z_` prefix is important to set up ignore rules, but can be customized later on.</blockquote><h3>Create files to exclude list</h3><p>In the same folder, create a file named: `z_exclude.txt`</p><p>Copy and paste the following into `z_exclude.txt`:</p><pre class="ql-syntax" spellcheck="false">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
</pre><blockquote>Note: The `z_` prefix is important to set up ignore rules, but can be customized later on.</blockquote><h3>Run the upload script</h3><p>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.</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/D0SMMNp96yY/image-3a4eb03abdcada6207b8d969551fa4fa.png"></p><blockquote>Note: Your output should be longer than this as you are uploading mods from scratch</blockquote><p>Now that your mods are all uploaded, we can set up the mod downloader configuration and script to send to your friends</p><h3>Create RClone configuration for downloading</h3><p>In the same folder, create a file named: `rclone.conf`</p><p>Copy and paste the following into `rclone.conf`:</p><pre class="ql-syntax" spellcheck="false">[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
</pre><p>Make sure to replace the PASTE_OVER values according to your <strong>read-only </strong>R2 token and Account ID.</p><h3>Create the mod downloader script</h3><p>In the same folder, create a file named: `update_mods.bat`</p><p>Copy and paste the following into `update_mods.bat`:</p><pre class="ql-syntax" spellcheck="false"># 2&gt;NUL &amp; @CLS &amp; PUSHD "%~dp0" &amp; "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -nol -nop -ep bypass "[IO.File]::ReadAllText('%~f0')|iex" &amp; POPD &amp; EXIT /B

if (-not(Test-Path -Path '.\Lethal Company.exe')) {
&nbsp; &nbsp; Write-Host "Error: Make sure this file is in the same folder as Lethal Company.exe before running!"
&nbsp; &nbsp; cmd /c pause
&nbsp; &nbsp; 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
</pre><h3>Test the mod downloader</h3><p>Open Steam and click on Lethal Company</p><p>Click on the gear icon on the right side</p><p>Traverse to `Manage` and click on `Browse local files` to open up the Lethal Company game folder on Windows Explorer</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/D0SMMNp96yY/image-e10b737a15c4294419f4e41bea5b0fdc.png"></p><p>Copy `rclone.conf`, `rclone.exe` and `update_mods.bat` from your Lethal Company r2modman profile folder here.</p><p>Double click update_mods.bat and run it.</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/D0SMMNp96yY/image-5510f829629ebb284d63b7486e50fc7c.png"></p><p>If everything is configured well, the mods should download nicely.</p><h3>Ship the mod downloader to your friends</h3><p>Select `rclone.conf`, `rclone.exe` and `update_mods.bat`.</p><blockquote><strong>Important:</strong> do not select the files starting with `z_`! They are meant to be for you only.</blockquote><p>Right click any of the selected files, traverse to `Send to` and click on `Compressed (zipped) folder`</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/D0SMMNp96yY/image-a61c4c90fa92d5170ab67a27510ae3e0.png"></p><p>Go ahead and rename the zip file if needed and send it to your friends.</p><p>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.</p><p>They should observe the same results as you.</p><p>After which, the game can be launched and your friends will have the exact same mods as you!</p><h2>Afterword</h2><p>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.</p><p>Although the setup is lengthy, after everything, the mod update flow is really just a matter of (as seen in the demo video)</p><ol><li>updating mods with r2modman</li><li>z_upload.bat</li><li>get your friends to run update_mods.bat</li></ol><p>No need for traversing the r2modman UI at all and pasting UUIDs.</p><p>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.</p><p>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!</p>]]>
    </description>
    <link>https://kb.jarylchng.com/i/powershell-lethal-company-bepinex-one-click-mods-D0SMMNp96yY/</link>
    <itunes:episodeType>full</itunes:episodeType>
    <enclosure url="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/video-24bdd7921c9c801e2c88abb528af32c9.mp4" type="video/mp4" length="887187"/>
    <itunes:duration>00:00:12</itunes:duration>
  </item>
</channel>
</rss>