Skip to content

Instantly share code, notes, and snippets.

@berichan
Last active July 22, 2024 16:02
Show Gist options
  • Save berichan/23c5025589db6954d182bb3ee97bab13 to your computer and use it in GitHub Desktop.
Save berichan/23c5025589db6954d182bb3ee97bab13 to your computer and use it in GitHub Desktop.
How to compile SysBot.NET for linux-arm64 and run it on a raspberry pi

Preface

My Pokemon shiny raid seed checker https://cute.berichan.net/ which is essentially a dudu bot clone runs on a Raspberry Pi 4 so I thought I'd write down how I compiled an arm-64 optimized version of SysBot.NET/Pokemon.

This guide assumes you have a working and 64-bit compatible Raspberry Pi with the 64-bit version of Raspbian installed and have at least a basic understanding of how to use Raspbian/Linux. If you can't get this set up, you should ask for help in the official Raspberry Pi forums. Note, the 64-bit OS is only installable on the Pi 3 and Pi 4 (and onwards) devices. 32-bit compilation (not covered) is easier but significantly slower for a variety of things SysBot.NET uses, so I don't recommend it.

Make sure your pi is up-to-date by running sudo apt-get update then sudo apt-get dist-upgrade.

Note, This guide also assumes you have already used (with success) SysBot.NET at least once and are able to copy over your config.json from the Windows application. We will only be compiling the Console Application where you get no control to run as an "always on" bot.

You will need to install the following development tools and runtimes:

  1. You should have the lastest version of Visual Studio and the .NET Core SDK installed on your desktop where you will be compiling SysBot.NET.
  2. You will also need the ARM64 runtime (or instead, I recommend to install the SDK) of .NET Core installed on your Raspberry Pi. At the time of writing, this is dotnet7.0 but will eventually change.
  3. You will need Python installed on your desktop (with unchanged/correct environment variables)

These all have a significant number of guides on the internet so won't be covered here.

Building Z3 for dotnet and arm64

On your desktop

  1. Download and unzip the SysBot.NET source
  2. Download and unzip the latest version of Z3
  3. In the SysBot.NET-master folder, open SysBot.Net.sln with Visual Studio.
  4. Click on the SysBot.Pokemon.Z3 project to open SysBot.Pokemon.Z3.csproj, or alternatively search for this file in your file explorer and open it with whatever IDE you'd like, or even notepad.
  5. Delete everything between the <Choose> ... </Choose> tags, including the tags themselves. These are the Z3 libs that only work with intel CPUs, we'll be compiling Z3 for dotnet-safe execution.
  6. Open a command prompt window. On Windows this is cmd and on Mac this is terminal, unless you are using another CLI.
  7. cd to wherever you've downloaded and unzipped Z3. On my device, I entered cd C:\Users\Berichan\Downloads\z3-master but this will be different for you unless you are also berichan.
  8. Run python scripts\mk_make.py --dotnet or *path/to/python.exe* scripts\mk_make.py --dotnet depending on how you've set up python. Wait for it to generate the makefile.
  9. The output window will end with something like this.

To build Z3, open a [Visual Studio Command Prompt], then type 'cd C:\Users\Berichan\Downloads\z3-master\build && nmake'

  1. Go back to Visual Studio, open the Developer CLI by going to Tools > Command Line > Developer Command Prompt and enter the command the Z3 output window asked you to enter. In my case, I entered cd C:\Users\Berichan\Downloads\z3-master\build && nmake. Do the next step while you are waiting for Z3 to compile on your desktop.

On your Raspberry Pi

  1. Download and install git and Python if you haven't already done so. My Raspbian already had these installed but I don't know if it will change one day.
  2. Clone the Z3 source to your pi git clone https://github.com/Z3Prover/z3.git then cd into the newly made folder where the z3 source resides.
  3. Follow the steps on the Z3 page to compile and install Z3 using gcc (gcc comes with Raspbian but is easily installed with apt if not). Make sure you also run sudo make install at the end! It's only 4 commands so I haven't bothered going into detail or copying the guide here.

Building Z3 on your pi will take a while so do the next few steps while this is happening.

On your desktop again

  1. Once Z3 has finished building the dotnet version on your desktop, close the Visual Studio Command Prompt.
  2. Right-click the SysBot.Pokemon.Z3 project and Select "Manage NuGet Packages"
  3. In the top-right corner of the NuGet Package Manager, select the gear to open NuGet options, click the green "+" button to add a new package source, click the ... button and select the folder where z3 was built, for me this was C:\Users\Berichan\Downloads\z3-master\build then click Update in the options window, followed by OK.
  4. In the NuGet window again, in the top-right dropdown where it says "Package source" select the new Package source we just created (should just be called Package source in the dropdown if this in your only one)
  5. Hit Browse in the top left. You should see "Microsoft.Z3", click it, then in the right window hit "Install" and press OK on any warnings.
  6. Right-click the SysBot.Pokemon.Z3 project and Select "build". It should build the SysBot.Pokemon.Z3 library without any issues.

Building SysBot.Pokemon.ConsoleApp

  1. Open a command prompt window again and cd to wherever SysBot.Pokemon.ConsoleApp is located. On my pc this is cd C:\Users\Berichan\Downloads\SysBot.NET-master\SysBot.NET-master\SysBot.Pokemon.ConsoleApp
  2. Run the following commands: dotnet clean followed by dotnet restore followed by dotnet publish --configuration release --framework net7.0 --runtime linux-arm64 The "net7.0" runtime can be changed if a later version of the SDK has been released and you are using that instead.
  3. Navigate to the newly created publish folder, on my pc this is C:\Users\Berichan\Downloads\SysBot.NET-master\SysBot.NET-master\SysBot.Pokemon.ConsoleApp\bin\release\net7.0\linux-arm64\publish
  4. Copy the config.json for your bot(s) setup from your usual SysBot.NET application folder into the publish folder, then copy over the entire publish folder to your Raspberry Pi. I usually use vsftpd to transfer things via ftp to my Pi but do whatever you usually do.
  5. Open a terminal, cd to wherever your publish folder is located and run dotnet SysBot.Pokemon.ConsoleApp.dll. It should now be running!
@enlighten1self
Copy link

Can you tell me what the line item will be for using dotnet for sdk 5.0?

@berichan
Copy link
Author

Can you tell me what the line item will be for using dotnet for sdk 5.0?

SysBot.NET doesn't have the TargetFramework for it yet so it'll probably need a manual update, once that happens it should be as simple as changing the build command to dotnet publish --configuration release --framework netcoreapp5.0 --runtime linux-arm64

@enlighten1self
Copy link

great! Thank you!! You mention building a 32-bit version of this. I have been attempting this with no luck. Everything works but the seedchecker. Any recommendations/tips?

@berichan
Copy link
Author

berichan commented Dec 7, 2020

great! Thank you!! You mention building a 32-bit version of this. I have been attempting this with no luck. Everything works but the seedchecker. Any recommendations/tips?

The current z3 source doesn't compile to armeabi/v7a correctly (idk why, you can maybe ask the z3 devs). Same issue on the one I tried to make for mobile https://github.com/berichan/SysBot.NET-Mobile but that now works with 64-bit arch targets (same as here)

@espioragney18
Copy link

espioragney18 commented Jan 18, 2021

I can never get it to build on windows idk what I'm doing wrong oh well gave up on it was on the last steps too. If I had a zip file with the compiled exe and stuff I had the pie ready to go. Sad day

@berichan
Copy link
Author

I can never get it to build on windows idk what I'm doing wrong oh well gave up on it was on the last steps too. If I had a zip file with the compiled exe and stuff I had the pie ready to go. Sad day

It was just updated to include .net5.0. Make sure net5.0 is installed on the windows machine and try again

@espioragney18
Copy link

Ok net 5 in addition to the .net core?

@leighton3890
Copy link

What is your discord link everyone one I have found it says expired

@enlighten1self
Copy link

What is your discord link everyone one I have found it says expired

Check out the link above to his website, there is a discord link there that worked for me!

Copy link

ghost commented Feb 20, 2022

Is there a way to add a dump and distribute folder directory that the json.config file can interpret?

@berichan
Copy link
Author

Is there a way to add a dump and distribute folder directory that the json.config file can interpret?

local directories named "distribute" and "dump" in the json (no folder structure required), then make these directories in the same folder as the executable on the pi

Copy link

ghost commented Feb 22, 2022

That's so easy ugh! Thank you!!

@satomi-1224
Copy link

hi! Is it possible to use the same method for linux other than arm?

@berichan
Copy link
Author

hi! Is it possible to use the same method for linux other than arm?

Yes, switch the commands to linux-x64 instead of linux-arm64

@satomi-1224
Copy link

hi! Is it possible to use the same method for linux other than arm?

Yes, switch the commands to linux-x64 instead of linux-arm64

OK! Thank u: D

@Dougiebona
Copy link

Hey, good night.
first thanks for all the help with the game.
I am playing Pokémon violet at the minute I would like to know what is the item to be held for a shiny swap in this game if is possible. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment