Files
yugioh-legacy-engine/README.md
T

133 lines
8.4 KiB
Markdown

# yugioh-legacy-engine
The duel engine of Yu-Gi-Oh! Legacy: the rules core and the duel server, built as ONE native
library per platform, `ygol-engine`, behind a written contract. Proposal 47 in the Unity repo
(`Docs/Proposals/GameArchitecture/47-engine-repo.md`) is the decision; this repo carries it out.
## Layout
| Path | What |
|---|---|
| `core/` | The rules core (C++, Lua 5.4 inside). Plain directory, no submodule. |
| `server/` | The duel server (C++, libevent) with its third-party sources vendored inside. Its premake builds the core from `../core`. |
| `build/windows.ps1` | Builds `out/win64/ygol-engine.dll` (+ `engine.json`), checks the contract header, runs the export gate. |
| `build/Dockerfile` | The Linux x64 and Android arm64 builds, targets `linux` and `android`, same checks and gates. |
| `build/linux.sh`, `build/android.sh` | Run the Docker targets into `out/linux-x64/` and `out/android-arm64/`. Need Docker and nothing else. |
| `contract/` | The contract: `engine-contract.md` (the one spec), `ocgapi.h` (the public header), `probe-feature-messages.py` (the wire gate), `lua-reference/` (the generated Lua API). |
| `CHANGELOG.md` | One row per contract change; the replayed patches 0001-0024 first. |
There is exactly one copy of the core in this repo. The server's old `ocgcore/` submodule is gone;
`server/premake5.lua` includes `../core`, and the six `gframe` sources that named `../ocgcore/`
now name `../../core/`.
## Sources (upstream is cut)
`core/` and `server/` start from two pinned upstream commits and carry our commits on top. There is
no upstream remote, subtree or submodule; a wanted upstream fix is copied in by hand as a normal commit.
| Directory | Upstream | Commit |
|---|---|---|
| `core/` | `nanahira/ygopro-core` (as vendored in the Unity repo, `Tools/YGOLegacy/ocgcore`) | `973672dc9ce7cb49f47173277ab1ad0e318b7593` |
| `server/` | `https://code.moenext.com/nanahira/ygopro.git`, branch `server` | `52c868ce071ea0f2fcb0cf39bf2fb4151d12b90c` |
The server import is the build-relevant part of that tree only: `gframe/`, `premake5.lua`, `.ci/`,
`LICENSE`, and `gframe/ygopro.rc` + `.ico` (upstream keeps them in `resource/` and copies them in
before building). No game assets, no card scripts.
Vendored third-party sources (the ones upstream's Windows CI downloads), at the positions its
premake expects, each with its premake fragment from upstream's `premake/` folder inside it:
| Dir | Source | Trimmed |
|---|---|---|
| `server/lua/` | lua 5.4.8 | no |
| `server/sqlite3/` | sqlite-autoconf 3.53.3 | no |
| `server/event/` | libevent 2.1.13-stable | tests, samples, autotools helpers; the files its Windows prebuild copies into `include/` (gitignored) |
| `server/zlib/` | zlib 1.3.2 | contrib, examples, platform folders |
| `server/lzma/` | xz 5.8.3 | `src/liblzma` + `src/common` only |
| `server/irrlicht/` | mycard irrlicht-1.9 `20f86d251624334d53585a1809ea4c7178f72a34` | `include/` plus the `source/Irrlicht` headers and the 11 `.cpp` files the server's zip reader project compiles (`premake5-only-zipreader.lua`). The pro3 server build turns zip support on, so this is source, not headers alone. |
## Fork changes as commits
The Unity repo's 24 patch files (`Tools/YGOLegacy/patches/`) are replayed here once as ordinary
commits and retire. Six core patches (0001, 0004, 0008, 0015, 0022, 0024) were already in the
vendored core when it was imported, so they are part of the `core:` import commit. The 16 server
patches are one commit each, in the order the old build script applied them:
0002, 0003, 0005, 0006, 0009, 0011, 0012, 0013, 0014, 0016, 0017, 0018, 0019, 0020, 0021, 0023.
Their `[YGOL]` markers are kept. `git log --oneline -- server/gframe` lists them.
## Build (Windows)
```powershell
git clone https://gitea.dev.blueoceanswim.com/donny/yugioh-legacy-engine.git C:\ygol-engine
pwsh C:\ygol-engine\build\windows.ps1 -Version v0.0.1
```
- The repo path must have NO spaces: libevent's premake emits an unquoted `xcopy` prebuild step. The
script refuses otherwise.
- Needs premake 5.0.0-beta8 (`-Premake`, default `C:\premake\premake5.exe`), VS 2022 Build Tools with
the C++ workload and a Windows 10 SDK.
- The script wipes `server/obj`, `server/bin` and `server/build` first (an incremental MSBuild once
reused a stale object and the DLL still built), runs `premake5 vs2022` in `server/` with
`SERVER_PRO3_SUPPORT=1 LOG_IN_CHAT=1 USE_SIMD=best`, then MSBuild on `build\YGOPro.sln`, target
`ygoserver`, Release x64.
- `-Version <tag>` is what `ygol_engine_version()` returns (`local` when not given).
- Before building, the script checks `contract/ocgapi.h` against `core/ocgapi.h` + the server's
`YGOSERVER_API` lines in `gframe/serverapi.h`; a drift fails the build.
- Output: `out/win64/ygol-engine.dll` (+ `.pdb`) and `out/win64/engine.json`
(`{ version, exports, protocol, capabilities }`; protocol and capabilities are read from
`gframe/network.h` and the `cap.flags` line of `single_duel.cpp` / `tag_duel.cpp`, never typed in).
### The export gate is the truth
The script FAILS unless the DLL exports exactly **334** symbols: `start_server`, `stop_server`,
`ygol_engine_version`, and the core's whole C API re-exported, including the six `ygol_sb_*` Sandbox
exports and `ygol_preview_attack` (45 contract exports + 289 `sqlite3_*`; see the contract). A different count means the wrong tree, not "a small difference". For the
record: the Unity repo's old `ygoserver.dll` exported 327 because its build applied patch 0008
(the `ygol_sb_*` six) only to `ocgcore.dll`, never to the server's own core copy; with one core they
are in the one library.
The wire probe (`python contract/probe-feature-messages.py --dll out/win64/ygol-engine.dll`, run from
the Unity repo root because the library reads `./expansions`) checks the fork's messages and
capability bits against a running server.
## Build (Linux and Android)
Both run in Docker from `build/Dockerfile`; the host needs Docker and nothing else (not this
Windows VM: it has no nested virtualisation). From a clean clone on any Linux box:
```bash
./build/linux.sh v0.0.1 # out/linux-x64/libygol-engine.so, ygoserver, engine.json
./build/android.sh v0.0.1 # out/android-arm64/libygol-engine.so, engine.json
```
- The argument is the version `ygol_engine_version()` returns (`local` when not given).
- Base image: Ubuntu 22.04 pinned by digest. Its glibc (2.35) is the floor of the outputs: they
run on Ubuntu 22.04, Debian bookworm and anything newer, not on Ubuntu 20.04 (a bookworm build
would need 2.36; bullseye, 2.31, is end of life and its package pool is gone); premake
5.0.0-beta8 bootstrapped from its tag; every dependency built from the vendored
sources (`BUILD_ALL`), libevent configured by its own generated `configure`
(`.ci/configure-libevent.sh`; `server/event/build-aux/` is the tarball's, put back for it).
`obj/`, `bin/`, `build/` are wiped before every compile.
- Linux builds the tree twice: the library (`SERVER_PRO3_SUPPORT`, `libygol-engine.so`) and the
plain server executable (project `ygopro`, with the zip support and tag surrender confirm PRO3
turns on, so it carries the same rules), renamed `ygoserver`; it is what the server repo's
`duel-server` runs. `-static-libstdc++ -static-libgcc`, AVX2 like the Windows build.
- Android: NDK r23b (`23.1.7779620`, the build id in the shipped `.so`, pinned by sha1), API
level 26, arm64 only, upstream's `exec_android_pro3` job. One library; `libocgcore.so` is not
built any more.
- The same contract-header check runs first, and the same export gate runs last, with the plain C
export count (`nm --dynamic --defined-only --extern-only`, names without a leading underscore; C++
symbols are `_Z`-mangled) and every name in `contract/ocgapi.h` present. Expected: **Linux 855**,
**Android 849** (the shipped Android server had 842: 841 + `ygol_preview_attack`; one core adds
the six `ygol_sb_*` and `ygol_engine_version`; `lua_*`, `event_*`, `z*`, ... count on these
platforms, unlike on Windows, so the numbers differ from 334; Linux has one more than Android,
`evutil_secure_rng_add_bytes`, which libevent only builds where glibc has no `arc4random`, so the
number belongs to the pinned base image). `engine.json` is written the same way as on Windows. A
`docker build` that fails the gate leaves nothing in `out/`.
## Line endings
The repo stores LF (`core.autocrlf=false` when importing; `git archive` on a machine with
`autocrlf=true` converts, so pass `-c core.autocrlf=false`). Irrlicht is CRLF because its upstream
stores CRLF.