# Developing BitCraft This guide explains what is in this repository, what is not, and how to run the game on your own machine, both with the free contents of this repository alone and with the paid third-party assets added back in. - [What is in this repository](#what-is-in-this-repository) - [Closed-source dependencies](#closed-source-dependencies) - [Prerequisites](#prerequisites) - [Run the game locally (no third-party assets)](#run-the-game-locally-no-third-party-assets) - [Run the game with the third-party assets](#run-the-game-with-the-third-party-assets) - [What looks different without the third-party assets](#what-looks-different-without-the-third-party-assets) - [Repository layout](#repository-layout) - [Architecture in brief](#architecture-in-brief) - [Troubleshooting](#troubleshooting) ## What is in this repository The complete BitCraft game as it is developed at Clockwork Labs, minus the pieces we are not allowed to redistribute: | Part | Folder | State | |---|---|---| | Unity client (code, art, audio, UI, static data) | `Assets/`, `Packages/`, `ProjectSettings/`, `AudioBanks/` | Complete, except the paid Asset Store packages listed below | | Server (SpacetimeDB modules, Rust) | `BitCraftServer/` | Complete | | Local services started by the editor | `ApiServer/`, `RelayServer/`, `WorldMapClient/`, `MobMonitorClient/`, `BotClient/` | Complete | | Tools | `compilation-check.sh`, `OpenSource/` | Complete | The client builds and runs without any paid packages. Everything that used them either has an open fallback (shaders, textures, a placeholder model) or is switched off with a scripting define (audio, IK, instancing, Discord, height fog, outlines). The game is fully playable; some visuals are simpler. ## Closed-source dependencies These packages are used by the game but are paid or otherwise not redistributable, so they are not in this repository. `OpenSource/publish-exclude.txt` is the authoritative list, and `OpenSource/VendorReferences.md` lists every one of our files that refers to them. | Package | Publisher | Version we use | Goes in | Used for | Without it | |---|---|---|---|---|---| | Odin Inspector and Serializer | Sirenix | 3.3 | `Assets/Plugins/Sirenix` | Editor inspectors, static-data validation | Attribute stubs in `ThirdPartyShims/OdinInspector`; plain inspectors, no validators | | FMOD for Unity | Firelight Technologies | 2.03.08 | `Assets/Plugins/FMOD` | All audio (banks are in `AudioBanks/`) | Silent: `ThirdPartyShims/FMOD` no-op stubs | | GPU Instancer | GurBu Technologies | - | `Assets/GPUInstancer` | Instanced terrain decoration | Built-in `Graphics.RenderMeshInstanced` renderer (slower) | | Final IK | RootMotion | - | `Assets/Plugins/RootMotion` | Player IK (feet, look-at) | No IK pass; animations still play | | Discord Social SDK | Discord | 1.1.8318 | `Assets/DiscordSocialSDK` | Rich presence, Discord login | Disabled | | Atmospheric Height Fog | BOXOPHOBIC | - | `Assets/BOXOPHOBIC` | Height fog | No height fog | | Linework | Alexander Ameye | 1.3.4 | `Packages/dev.ameye.linework` | Outlines and silhouettes | No outlines | | Mesh Combiner | Asset Store | - | `Assets/_Project/Tools/ModelCombiner/MeshCombiner` | Editor tool that combines meshes | Tool disabled (combined meshes are already in the repo) | | Flat Kit | Dustyroom | - | `Assets/FlatKit` | Stylized surface shader (most of the world) | Open fallback shader | | Stylized Grass Shader | Staggart Creations | 1.3.2 | `Assets/_Project/StaticAssets/Staggart Grass` | Grass and foliage shader | Open fallback shader | | Stylized Water 2 | Staggart Creations | 1.1.7 | `Assets/StylizedWater2` | Water | Open fallback water shader | | Stylized Water For URP | Asset Store | - | `Assets/Stylized Water For URP` | Water textures, lighting sub-graph | Open replacement textures and sub-graph | | Amplify Impostors | Amplify Creations | 5.7.2 | `Assets/AmplifyImpostors` | Distant tree/log impostors | Impostors not drawn | | Fake Point Light | LazyEti | - | `Assets/LazyEti` | Fake light glows | Glows not drawn | | Selection Bases FX | Ordoss | - | `Assets/OrdossFX` | Selection/claim effects | Open fallback shader | | VFX (Klaus) | Asset Store | - | `Assets/VFX_Klaus` | Combat hit/slash effects, particles | Effects not drawn | | Kyeoms FX | Asset Store | - | `Assets/Kyeoms_FX` | Particle effects | Effects not drawn | | MOBA Heroes | Asset Store | - | `Assets/MOBA Heroes` | Practice dummy model | Primitive placeholder dummy | "-" means we have not recorded a version; the latest version of the package is the best starting point. Our own changes to some of these packages are kept as patches in `OpenSource/VendorPatches/`. Third-party code that *is* redistributable (MIT and similar) is included; see [THIRD-PARTY-NOTICES.md](./THIRD-PARTY-NOTICES.md). ## Prerequisites - **Unity 2022.3.62f2** (install through Unity Hub), with the Standalone build support module for your OS. - **SpacetimeDB CLI 2.10 or newer**: see . The server modules and the .NET services use SpacetimeDB 2.10.0 (`BitCraftServer/packages/*/Cargo.toml`); the Unity client uses the 2.13 C# SDK (`Packages/manifest.json`). - **Rust** via [rustup](https://rustup.rs), plus the WebAssembly target: `rustup target add wasm32-unknown-unknown` (SpacetimeDB compiles the modules to WebAssembly). - **.NET 8 SDK**, for the API server, relay, world-map clients and mob monitors. - **Python 3**, only for the scripts in `OpenSource/`. - About 25 GB of free disk space for the project and Unity's `Library` folder. The first import takes a while (an hour or more on a laptop). Windows is the platform we use day to day; macOS works too. The editor tools open services in terminal windows (`cmd` on Windows, Terminal on macOS). ## Run the game locally (no third-party assets) Running the game on your own machine for development is allowed under the [BitCraft Community License](./BITCRAFT-COMMUNITY-LICENSE.md). Hosting a server for anyone else is not. 1. **Clone** the repository and **start a local SpacetimeDB server** in a terminal: ```sh spacetime start ``` Leave it running; it listens on `http://localhost:3000`. 2. **Get an auth token** for the editor tools, in another terminal: ```sh spacetime login spacetime login show --token ``` 3. **Open the project** in Unity Hub (*Add > Add project from disk*, then open it with 2022.3.62f2). Wait for the first import to finish. 4. **Set up the world:** menu *BitCraft > Server Setup*. At the top of the window: - *Environment*: `Local`. - *Auth Token*: the token from step 2. - *Host*: `http://localhost:3000`; *Module Prefix*: `bitcraft`; *World Definition*: `Dev1x1` (`Assets/_Project/Tools/WorldGeneration4.0/Definitions/Regions/Dev1x1.asset`). Then, in the **Setup** tab: - Tick **Include mob monitors** if you want NPCs and animals to move (optional, see below). Leave **Place starter towns** ticked. - Click **Reset & set up environment…**. This publishes the global module and one module per region to your local SpacetimeDB, uploads the static data, generates and uploads the world (slow the first time: the world-generation cache is not in the repository) and places starter towns. It then starts the local services below, each in its own terminal window. Expect 5–10 minutes, longer the first time while Rust and .NET build everything. 5. **Check the local services are running.** Setup starts them for you; the **Services** tab has a button for each one, so you can start (or restart) it on its own: | Service | Needed? | What it does | Services tab button | |---|---|---|---| | Relay (`RelayServer/`) | **Required** | Delivers messages between the global module and the region modules | *Relay* | | API server (`ApiServer/`) | **Required** | Signs players in and handles hub inventory, on `http://localhost:8080` (the client's `apiServerUrl`) | *API server* | | World map clients (`WorldMapClient/`) | Optional | Generate the terrain, resource and empire map files the in-game map shows | *Environment Map*, *Empire Map* | | Mob monitors (`MobMonitorClient/`) | Optional | Drive NPC and animal behaviour, one per region | *Mob monitors* | The game does not run without the relay and the API server. Without the map clients the world map stays blank and the console shows "Local map file not found … EmpireMap_v1.gwm"; once they are running they write the map files to Unity's persistent data folder, where the game reads them, and keep them up to date. The first maps take a few minutes. Without mob monitors, NPCs and animals stand still. 6. **Play:** open `Assets/_Project/Scenes/Main.unity`, press Play, press any key on the title screen and choose *Enter BitCraft* on the *Local* world (the default; the client's servers are listed in `Assets/StreamingAssets/Config/development.json`). **Next time**, run `spacetime start` and click **Start services** in the **Develop** tab: it starts the relay, API server and map clients (and the mob monitors, if *Mob monitors* is ticked) without republishing the modules. The Develop tab also republishes modules and uploads static data after you change them. Use **Reset & set up environment…** again for a clean world. **Check that the project compiles** without opening the editor: `./compilation-check.sh` (set `UNITY_PATH` if Unity is not in the default Hub location). ## Run the game with the third-party assets If you own some or all of the packages above, you can put them back for the full-fidelity game. 1. **Close Unity.** 2. **Import the packages** at the paths in the table (import each into an empty Unity project from the Asset Store / Package Manager, then copy its folder into this project at that path). FMOD for Unity and the Discord Social SDK are free downloads from their publishers, but still may not be redistributed here. 3. **Restore the references** that were adjusted for the vendor-free build: ```sh python3 OpenSource/restore_vendor_references.py ``` This applies `OpenSource/RestoreVendorReferences.patch` in reverse: materials go back to the vendor shaders and textures, the URP renderer features come back, the vendor scripting defines are set again (`BITCRAFT_FMOD`, `BITCRAFT_FINALIK`, `BITCRAFT_DISCORD`, `BITCRAFT_HEIGHTFOG`, `BITCRAFT_LINEWORK`, `BITCRAFT_MESHCOMBINER`, plus the ones Odin and GPU Instancer manage), and the practice dummy uses the MOBA Heroes model again. `--undo` switches back. 4. **Open the project** (Unity recompiles with the restored defines and reimports much of the project, which can take an hour), then run *Tools > Vendor Patches > Apply All* to apply our changes to the vendor files (FlatKit, Stylized Water 2, Height Fog, OrdossFX, Amplify Impostors, GPU Instancer), and *Tools > Vendor Patches > Verify* to check them. 5. Start the local services and play as above. **Only some of the packages?** Step 3 is all-or-nothing, so afterwards remove the define of each package you do not have (*Project Settings > Player > Scripting Define Symbols*: `BITCRAFT_FMOD` for FMOD, `BITCRAFT_FINALIK` for Final IK, `BITCRAFT_DISCORD` for Discord, `BITCRAFT_HEIGHTFOG` for Height Fog, `BITCRAFT_LINEWORK` for Linework, `BITCRAFT_MESHCOMBINER` for Mesh Combiner, `GPU_INSTANCER`, `ODIN_INSPECTOR`). Materials of missing shader packages will show as missing shaders; run `restore_vendor_references.py --undo` if that is not what you want. ## What looks different without the third-party assets - **Shaders**: the stylized surface, grass, water and selection shaders are open re-implementations in `Assets/_Project/StaticAssets/Shaders/Fallback/`. They read the same material properties, so the game looks close to the original, but lighting details (rim light, specular, advanced translucency, water foam and refraction) are simpler. - **Textures**: 41 textures that came from paid packages (noise, caustics, foam, smoke, normal maps...) are replaced by procedurally generated ones (`Assets/_Project/StaticAssets/Textures/OpenReplacements/`, made by `OpenSource/generate_replacement_textures.py`). - **Not drawn**: height fog, fake light glows, impostors for distant trees and logs, combat hit/slash effects and a few particle effects. - **Off**: audio (FMOD), IK, outlines/silhouettes, Discord. - **Slower**: terrain decoration is drawn with Unity's built-in instancing instead of GPU Instancer. - **Placeholder**: the practice dummy is built from primitives. - **Fonts**: a few fonts we may not redistribute (Brandon Grotesque, SF Pro Display) are replaced by Lexend, mostly in editor tools and some floating in-world text. ## Repository layout ``` Assets/_Project/ our game: Scripts, StaticAssets (art), StaticData, Scenes, Tools, Settings Assets/_Project/ThirdPartyShims/ stand-ins that let the code compile without Odin and FMOD Assets/_Project/autogen*/ C# bindings generated from the server modules (spacetime generate) BitCraftServer/packages/global_module SpacetimeDB module for global state BitCraftServer/packages/game SpacetimeDB module for one world region ApiServer/ authentication, purchases, hub inventory (ASP.NET) RelayServer/ delivers inter-module messages between the global and region modules WorldMapClient/ builds the world and empire map data MobMonitorClient/ drives NPC/mob behaviour for each region BotClient/ load-testing bots OpenSource/ how this repository is published (see OpenSource/README.md) ``` ## Architecture in brief BitCraft's backend is built on [SpacetimeDB](https://spacetimedb.com) 2.10 in Rust: one **global module** and one **game module per world region**. All state lives in SpacetimeDB tables and all logic runs in reducers. Modules exchange messages through an `inter_module_message` table, which the **Relay Server** subscribes to and delivers. Side services handle authentication and purchases (**API Server**), map generation (**World Map Client**) and NPC behaviour (**Mob Monitor**). All game content is **static data**: ScriptableObjects in `Assets/_Project/StaticData/`, edited in the Unity editor and uploaded to the modules (Server Setup > *Develop* > *Update all modules*). The tables are named `…Desc` and defined in `BitCraftServer/packages/game/src/messages/static_data.rs`. The UI uses **Rish**, our React-style UI framework on top of UI Toolkit (). After changing a module's tables or reducers, regenerate the client bindings from the Server Setup window (*Develop* > *Generate C# bindings* > *All*) or with `spacetime generate`. ## Troubleshooting - **"Local map file not found … EmpireMap_v1.gwm" errors** mean the world map clients are not running (or have not finished their first pass). Start them from *Server Setup > Services* (*Environment Map* and *Empire Map*). (They can also upload the maps to S3 when AWS settings are configured in `WorldMapClient/WorldMapClientCommon/Config`; that is only needed for hosted servers.) - **Magenta materials** usually mean a shader was imported before its includes; reimport the folder. If you restored the vendor references, check that every package is at the path in the table. - **Publishing a module fails**: check `spacetime start` is running, the CLI is 2.10 or newer, and the `wasm32-unknown-unknown` target is installed. - **A service terminal closes immediately**: run it by hand from its folder with `dotnet run` to see the error (the .NET 8 SDK is required).