Compare commits
13
Commits
v1.0.0
...
v1.1.0-poc.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1771cb5599 | ||
|
|
3044b95b44 | ||
|
|
7628a7454e | ||
|
|
be8a8c43e5 | ||
|
|
b5d60ef8a7 | ||
|
|
aae6556708 | ||
|
|
ff05d4f28a | ||
|
|
b2a6300aad | ||
|
|
12e3e52537 | ||
|
|
6d97b60ebc | ||
|
|
e3e2262e37 | ||
|
|
184a421512 | ||
|
|
998b037d3d |
No files matched your search
@@ -3,7 +3,7 @@ name: Build without game data
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, release/1.0]
|
||||
branches: [main, release/1.0, poc/1.1-international]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
workflow_call:
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
platform: linux-x64
|
||||
- runner: windows-2022
|
||||
platform: windows-x64
|
||||
- runner: macos-14
|
||||
- runner: macos-15
|
||||
platform: macos-arm64
|
||||
runs-on: ${{ matrix.runner }}
|
||||
timeout-minutes: 90
|
||||
@@ -43,6 +43,7 @@ jobs:
|
||||
python3 tools/public_release/check_public_tree.py --root .
|
||||
python3 tools/ci/test_build_runnable_tests.py
|
||||
python3 tools/package/test_verify_ci_release.py
|
||||
python3 -m unittest discover -s tools/poc -p "test_*.py"
|
||||
- name: Set up MSVC x64
|
||||
if: runner.os == 'Windows'
|
||||
uses: ilammy/msvc-dev-cmd@a102174a2b586eec2ea151a69e6fd14404a8ce7c # v1.13.0
|
||||
|
||||
+37
-2
@@ -1,7 +1,11 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(OpenBMH VERSION 1.0.0 LANGUAGES CXX C)
|
||||
set(OPENBMH_PRERELEASE "" CACHE STRING "Prerelease identifier; empty for final release")
|
||||
project(OpenBMH VERSION 1.1.0 LANGUAGES CXX C)
|
||||
if(APPLE)
|
||||
# Enable native languages before dependencies/subdirectories inherit rules.
|
||||
enable_language(OBJC OBJCXX)
|
||||
endif()
|
||||
set(OPENBMH_PRERELEASE "poc.2" CACHE STRING "Prerelease identifier; empty for final release")
|
||||
set(OPENBMH_PRODUCT_VERSION "${PROJECT_VERSION}")
|
||||
if(OPENBMH_PRERELEASE)
|
||||
string(APPEND OPENBMH_PRODUCT_VERSION "-${OPENBMH_PRERELEASE}")
|
||||
@@ -203,18 +207,21 @@ bmh_add_data_test(NAME highscore_tests REQUIRED_OPTIONS BMH_TEST_HIGHSCORE_TESTS
|
||||
# Engine core: file formats and game logic, no platform dependencies
|
||||
add_library(bmhcore STATIC
|
||||
src/formats/binary.cpp
|
||||
src/formats/resource_bundle.cpp
|
||||
src/formats/palette.cpp
|
||||
src/formats/vga.cpp
|
||||
src/formats/font.cpp
|
||||
src/formats/textd.cpp
|
||||
src/formats/fbm.cpp
|
||||
src/formats/le.cpp
|
||||
src/formats/data_profile.cpp
|
||||
src/formats/m3d.cpp
|
||||
src/formats/savestate.cpp
|
||||
src/game/schedule.cpp
|
||||
src/game/league_pairings.cpp
|
||||
src/game/source_tip.cpp
|
||||
src/game/table_forecast.cpp
|
||||
src/game/profile_runtime.cpp
|
||||
src/game/state.cpp
|
||||
src/game/rating.cpp
|
||||
src/game/match.cpp
|
||||
@@ -299,6 +306,7 @@ FetchContent_MakeAvailable(miniz lzma_sdk nfd)
|
||||
|
||||
add_library(bmh_miniz STATIC ${miniz_SOURCE_DIR}/miniz.c)
|
||||
target_include_directories(bmh_miniz PUBLIC ${miniz_SOURCE_DIR})
|
||||
target_link_libraries(bmhcore PRIVATE bmh_miniz)
|
||||
set(BMH_LZMA_C ${lzma_sdk_SOURCE_DIR}/C)
|
||||
add_library(bmh_7z STATIC
|
||||
${BMH_LZMA_C}/7zAlloc.c ${BMH_LZMA_C}/7zArcIn.c ${BMH_LZMA_C}/7zBuf.c ${BMH_LZMA_C}/7zCrc.c
|
||||
@@ -1132,3 +1140,30 @@ add_test(NAME lineup_foreign_limit_tests COMMAND lineup_foreign_limit_tests)
|
||||
add_executable(calendar_epoch_tests tests/calendar_epoch_tests.cpp)
|
||||
target_link_libraries(calendar_epoch_tests PRIVATE bmhui)
|
||||
add_test(NAME calendar_epoch_tests COMMAND calendar_epoch_tests)
|
||||
|
||||
add_executable(video_session_tests tests/video_session_tests.cpp)
|
||||
target_include_directories(video_session_tests PRIVATE src)
|
||||
target_link_libraries(video_session_tests PRIVATE ${BMH_SDL_TARGET})
|
||||
add_test(NAME video_session_tests COMMAND video_session_tests)
|
||||
if(APPLE)
|
||||
add_executable(mac_video_picker_tests tests/mac_video_picker_tests.mm)
|
||||
set_target_properties(mac_video_picker_tests PROPERTIES OBJCXX_STANDARD 20 OBJCXX_STANDARD_REQUIRED YES)
|
||||
target_include_directories(mac_video_picker_tests PRIVATE src)
|
||||
target_link_libraries(mac_video_picker_tests PRIVATE ${BMH_SDL_TARGET} nfd::nfd "-framework Cocoa")
|
||||
add_test(NAME mac_video_picker_tests COMMAND mac_video_picker_tests)
|
||||
endif()
|
||||
|
||||
add_executable(desktop_feedback_tests tests/desktop_feedback_tests.cpp)
|
||||
target_link_libraries(desktop_feedback_tests PRIVATE bmhui)
|
||||
bmh_add_data_test(NAME desktop_feedback_tests COMMAND desktop_feedback_tests "${BMH_DATA}")
|
||||
|
||||
add_executable(data_profile_tests tests/data_profile_tests.cpp)
|
||||
target_link_libraries(data_profile_tests PRIVATE bmhcore)
|
||||
add_test(NAME data_profile_tests COMMAND data_profile_tests)
|
||||
|
||||
# Offline private package preparation; never installs Original data.
|
||||
add_executable(export_community_runtime tools/poc/export_runtime.cpp)
|
||||
target_link_libraries(export_community_runtime PRIVATE bmhcore)
|
||||
add_executable(resource_bundle_tests tests/resource_bundle_tests.cpp)
|
||||
target_link_libraries(resource_bundle_tests PRIVATE bmhcore bmh_miniz)
|
||||
add_test(NAME resource_bundle_tests COMMAND resource_bundle_tests)
|
||||
@@ -1,5 +1,7 @@
|
||||
# OpenBMH
|
||||
|
||||
This is the **1.1 community development branch**. A prepared community package starts directly from `COMMUNITY.OBD`, without BMH.exe or a DOS installation. Original loose Classic installations remain supported. The stable 1.0 line stays on main. See [standalone community data](docs/poc-1.1/STANDALONE.md).
|
||||
|
||||
A faithful, standalone community reconstruction of *Bundesliga Manager Hattrick*, using the player's original installation and SDL2 interface.
|
||||
|
||||
OpenBMH 1.0 builds on v0.1.2 with reviewed bug fixes and starts directly with the original game data. Original game files, graphics, audio and manuals are not distributed. German CD-compatible BMH and verified Diamond editions are the primary release targets. Football Limited remains experimental; the older floppy executable is not supported.
|
||||
@@ -14,13 +16,15 @@ Check the [releases page](https://github.com/Weyoune/openbmh/releases) for avail
|
||||
2. Extract the OpenBMH package into a separate directory, or alongside the game files.
|
||||
3. Start `OpenBMH` (`OpenBMH.exe` on Windows). Select the game directory or executable when prompted. A ZIP or 7z containing one game installation can also be selected.
|
||||
|
||||
From a terminal:
|
||||
From a terminal in the extracted package on Linux or macOS:
|
||||
|
||||
```sh
|
||||
OpenBMH --data "path/to/game" --save-directory "path/to/saves"
|
||||
openbmh_cli --console --data "path/to/game" --saves "path/to/saves"
|
||||
./OpenBMH --data "path/to/game" --save-directory "path/to/saves"
|
||||
./openbmh_cli --console --data "path/to/game" --saves "path/to/saves"
|
||||
```
|
||||
|
||||
In Windows PowerShell, use `.\OpenBMH.exe` and `.\openbmh_cli.exe` instead.
|
||||
|
||||
Use a writable save directory and keep backups of existing games. German editions are the primary compatibility target. **Football Limited / English data support is experimental**; original V2.20 save import and some edition-specific behaviour remain limited. See the [release notes](docs/release/1.0/RELEASE_NOTES.md).
|
||||
|
||||
## Features and direction
|
||||
@@ -31,7 +35,7 @@ OpenBMH focuses on original-game compatibility, stability and community contribu
|
||||
|
||||
## Build from source
|
||||
|
||||
The following recipes target OpenBMH 1.0 release candidates. They require Git, CMake 3.24 or newer and a C++20 compiler. The first configure fetches pinned open-source dependencies. Native build and package results are documented for each release; these instructions do not claim an untested platform result.
|
||||
The following recipes build OpenBMH 1.0. They require Git, CMake 3.24 or newer and a C++20 compiler. The first configure fetches pinned open-source dependencies. Native build and package results are documented for each release; these instructions do not claim an untested platform result.
|
||||
|
||||
Clone the public repository, then run the commands for your system:
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
# Classic-plus-1 profile
|
||||
|
||||
This opt-in experimental profile keeps the Classic competition types and indexed artwork formats. It is not a DOS patch. The original executable is read only; verified dimension data and the expanded calendar are prepared in memory. Unmarked installations retain Classic dimensions and save identity.
|
||||
|
||||
## Discovery and dimensions
|
||||
|
||||
`OBMHPROF.INI` contains exactly:
|
||||
|
||||
```ini
|
||||
[OpenBMH]
|
||||
profile=classic-plus-1
|
||||
```
|
||||
|
||||
Unknown keys/profiles are rejected. The German executable and calendar are required.
|
||||
|
||||
| Table | Classic | Classic-plus-1 |
|
||||
| --- | ---: | ---: |
|
||||
| League sizes, German divisions | 18/18/18/18/18 | 18/18/18/18/18 |
|
||||
| Spain/England/France/Italy | 12/12/12/12 | 18/20/18/18 |
|
||||
| League clubs | 138 | 164 |
|
||||
| Cup-only clubs | 30 | 30 |
|
||||
| League and cup records | 168 | 194 |
|
||||
| Other foreign clubs | 189 | 189 |
|
||||
| National teams | 62 | 62 |
|
||||
| All club/country entries | 419 | 445 |
|
||||
| Players | 2,574 | 3,334 |
|
||||
| Clubs with 24 roster slots | 90 | 164 |
|
||||
| First market slot | 2,928 | 3,936 |
|
||||
| First national roster slot | 3,072 | 4,080 |
|
||||
| First extra-player slot | 3,096 | 4,104 |
|
||||
| Total runtime slots | 3,150 | 4,158 |
|
||||
|
||||
Player identifiers still use twelve bits, with 4,095 reserved for empty. **An absolute roster slot is not a player identifier**: extended auxiliary slots exceed 4,095 and must not be masked. Club identifiers fit existing packed club fields and crest selectors fit nine bits.
|
||||
|
||||
## Master database and artwork
|
||||
|
||||
The M3D table order and encoding remain unchanged. Kit selectors scale with all club/country entries; short-name offsets and auxiliary words scale with league-plus-cup entries. The squad master has four fewer rows than runtime, because temporary transfer rows are inserted during career initialization. String pools retain unsigned 16-bit offsets. Imported names use ISO 646-DE, with explicit transliteration of unsupported letters.
|
||||
|
||||
The preparation script keeps original player words and original IDs, appends supplemental players and records the source-to-runtime club mapping. Existing twelve-club foreign cores are retained; additional clubs are ranked by donor mean player strength. Missing-person data are not silently fetched or invented. Every supplied provenance/fictional-field note is retained in the private import report.
|
||||
|
||||
Crests are fitted into 38-by-38 cells of 304-by-38 VGA sheets, using the supplied VGA palette. No PNG/SVG decoder is needed at runtime. Transparency is index zero for these generated crest cells. Existing protected crest cells remain intact. Repeated Original placeholder images are rejected rather than counted as real club crests. Missing crests use explicitly fictional vector monograms, and dark monochrome logos can use a light contrast variant; both are recorded per club. Asset source and rights notes remain separate from the application's GPL license.
|
||||
|
||||
The offline preparation utility accepts local paths:
|
||||
|
||||
```sh
|
||||
python3 -m venv asset-tools
|
||||
asset-tools/bin/pip install Pillow CairoSVG
|
||||
asset-tools/bin/python tools/poc/prepare_international.py \
|
||||
--source /path/to/supplied/german-game \
|
||||
--supplement /path/to/supplied/season.obw \
|
||||
--output /path/to/new/private-data
|
||||
```
|
||||
|
||||
The destination must not exist. Inputs are never overwritten. Original content and private import reports must stay outside public source trees, issues and CI artifacts.
|
||||
|
||||
## Save and memory boundaries
|
||||
|
||||
Classic containers retain `V2.24`. Extended containers use `O1.1`, checked against the selected installation before state decoding. The table sequence remains familiar, with count-derived sizes for club records, manager/opponent histories, crests, kits and short-name offsets. Extended typed tables must not grow into adjacent globals in the guest-memory compatibility representation.
|
||||
|
||||
The result store already reserves nine leagues with 38 rounds and ten matches per round. Expanded scheduling uses each league's own fixture size. The shared foreign calendar supplies 38 dates; each league stops at its own 34 or 38 rounds. Domestic/cup/national flags are preserved. Dates are an experimental calendar policy, not a claim about real-world fixtures.
|
||||
|
||||
## Distribution
|
||||
|
||||
Public artifacts contain the implementation, build information and corresponding sources. The community data ZIP is prepared privately and separately; existing content provenance and rights are unchanged. The stable 1.0 release line is not replaced by this POC.
|
||||
@@ -0,0 +1,21 @@
|
||||
# Standalone community data
|
||||
|
||||
The 1.1 community edition can start from `COMMUNITY.OBD` without an installed DOS game. The stable main line and loose Classic installation support remain separate.
|
||||
|
||||
`COMMUNITY.OBD` is a compressed read-only resource bundle. It contains the master database, text, palette, formations, desktop layout, fonts, indexed pictures/crests and audio containers required by OpenBMH. These are game content, not application code. Saves, highscores and user layouts remain normal writable files outside the bundle.
|
||||
|
||||
The bundle's `RUNTIME.DAT` uses the `OBMHDAT1` schema: data-segment base/length, calendar epoch, resolved badge/environment policies, data-segment bytes and explicitly named auxiliary labels. The exporter discards the DOS header, DOS/4GW loader and machine-code objects. Calendar and verified edition policies are values, rather than retained code fingerprints. This is not a renamed or embedded BMH executable.
|
||||
|
||||
The Classic address-view adapter still supplies the existing engine/UI table readers. It reads resource entries directly from the compressed bundle, without unpacking original executables or a cached DOS installation. Bundle paths are case-insensitive and reject duplicate/path-traversal entries; compressed/uncompressed limits bound allocations. Original loose installations retain their loading path.
|
||||
|
||||
Offline preparation from privately supplied resources:
|
||||
|
||||
```sh
|
||||
cmake --build build --target export_community_runtime
|
||||
python3 tools/poc/bundle_community.py --source /path/to/prepared-data \
|
||||
--exporter /path/to/build/export_community_runtime --out /path/to/new/community-data
|
||||
```
|
||||
|
||||
Only required resource types are included. DOS programs, installers, editor executables, original saves, backup directories, manuals and unused picture formats are excluded. Import provenance stays in `IMPORT-REPORT.json`; `PACKAGE.json` records the hashes of the bundled resources. A bundled `OBMHPROF.INI` selects the expanded league profile, so no additional loose Original files are needed.
|
||||
|
||||
Generated foreign crests now use the supplied Original domestic crest background texture. Transparent edges are composited onto that bright texture before palette reduction; actual black logo details remain black. The previous black rectangles and the light-on-dark monochrome workaround are removed.
|
||||
@@ -0,0 +1,22 @@
|
||||
# International-league POC
|
||||
|
||||
Working branch: `poc/1.1-international`, based on `v1.0.2`. Stable main remains separate.
|
||||
|
||||
Implemented:
|
||||
|
||||
- Explicit `OBMHPROF.INI` metadata; unmarked installations retain Classic dimensions.
|
||||
- Five German divisions unchanged; international sizes 18/20/18/18, 164 league clubs.
|
||||
- Twenty starting players and 24 slots per league club; 4,158 runtime roster/auxiliary slots.
|
||||
- Profile-aware master-database and executable-data views, preserving executable bytes on disk.
|
||||
- Count-derived club records, opponent histories, kit/short-name and fair-play tables.
|
||||
- Per-league fixtures and 38 foreign calendar dates, with smaller leagues stopping at 34 rounds.
|
||||
- Extended save identity `O1.1`; Classic retains `V2.24` and its existing dimensions.
|
||||
- Offline private data preparation, provenance, crest fitting and Original-format VGA output.
|
||||
|
||||
Local integration evidence so far: the expanded career completed 180 turns with seed 1 (three season ends), and another 180 with seed 11 (two season ends). No simulator invariant violations or contract-policy errors were reported. These are automated manager-policy runs, not claims of complete human gameplay QA or validation of all editions/platforms.
|
||||
|
||||
The prepared private dataset has 445 club/country entries, 3,334 players and 263 individual foreign club crests. Original German rosters and all 2,574 Original player word records are preserved by assertions during preparation. The visual review identified 175 usable supplied foreign crests and 88 missing/shared Original placeholders. Those 88 now have explicit fictional club-specific monograms instead of the computer symbol; the updated crest preparation uses the bright Original background texture and preserves black logo details. Donor fields retain their real/fictional provenance. No original game content is committed here.
|
||||
|
||||
Validation: 37 configured synthetic tests executed successfully, with 158 external-input tests explicitly skipped; four offline preparation tests passed. Extended save/reload and both cross-profile rejection paths passed. Two separate season-end snapshots each contain every fixture in all nine leagues. A Classic 80-turn run produces a byte-identical save to stable 1.0.2. Screenshots and saves are archived privately. Native platform CI also builds and tests Windows x64, macOS ARM64 and Linux x64; release QA receipts identify the exact successful revision. See [FORMAT.md](FORMAT.md) for dimensions, preparation and distribution boundaries. A development commit is not a completed release claim.
|
||||
|
||||
The next community package uses a data-only `COMMUNITY.OBD` bundle and no DOS executables. See [STANDALONE.md](STANDALONE.md). The Windows community ZIP omits source archives and loose PNG/JPEG studies; corresponding sources remain available separately.
|
||||
@@ -1,3 +1,21 @@
|
||||
# OpenBMH 1.0.2
|
||||
|
||||
A left click on an open desktop widget's upper-left close button now hides that widget through the normal validated layout transaction. The close button no longer starts a drag or shows the moving outline. Moving an element with the right mouse button remains available.
|
||||
|
||||
The close action consumes its matching mouse release even if the engine has already removed the widget, preventing an accidental click on an icon underneath. The automation and macOS keyboard fixes from 1.0.1 remain unchanged.
|
||||
|
||||
---
|
||||
|
||||
# OpenBMH 1.0.1
|
||||
|
||||
The automatic-lineup monitor now draws the selected formation from the actual manager formation table. Outdoor, indoor and custom formation slots retain their original coordinates and palette. Dragging a desktop element shows the original yellow outline, which disappears when the drag ends.
|
||||
|
||||
SDL video initialization now precedes the initial native file picker. On macOS this lets SDL establish the Cocoa application and keyboard activation policy before the picker creates or modifies NSApp. It addresses keyboard input missing throughout the game, including entering the manager name. A native macOS regression checks the activation policy after the picker initialization/shutdown lifecycle.
|
||||
|
||||
Native interactive Mac keyboard acceptance remains human QA; automated checks do not represent physical typing on a user's Mac.
|
||||
|
||||
---
|
||||
|
||||
# OpenBMH 1.0.0
|
||||
|
||||
Classic direct-installation runtime restored from v0.1.2. The game executable is OpenBMH / OpenBMH.exe; openbmh_cli remains available.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# Classic 1.0 candidate validation
|
||||
# OpenBMH 1.0 validation
|
||||
|
||||
Scope: recorded automated/original-data checks. Exact final source revision and native platform build records accompany the published release.
|
||||
|
||||
- Linux x64 Release build: all targets compiled.
|
||||
- CTest: 35 passed, 157 skipped, zero failures (192 registered tests). Skips require separately configured original-data or save fixtures; they are not acceptance passes.
|
||||
- Local Linux CTest: 35 passed, 157 skipped, zero failures (192 registered tests). Skips require separately configured original-data or save fixtures; they are not acceptance passes.
|
||||
- Synthetic tests cover unchanged executable image loading, nine original strength ranges, atomic rejection of malformed ranges, unsupported environment guards, and legacy/extended/truncated crest gates.
|
||||
- Public source scan: zero findings; generated differences catalogue matches source markers.
|
||||
- Version output: both GUI and console identify 1.0.0-rc.1.
|
||||
@@ -33,3 +33,13 @@ After the final lineup, qualification and once-per-player season-reset correctio
|
||||
The duplicate-player defect was reproduced and captured before correction: a temporary offer referenced a player already owned by a club, then the extended market-retirement pass regenerated that player a second time. Frozen private before/after saves and a cached-reference regression support the correction. Save-envelope diagnostics use a separate RNG and do not consume either gameplay stream.
|
||||
|
||||
Calendar epoch regression covers the original CD and Diamond parameters, engine weekdays, desktop dates, save-header dates, year rollover and atomic rejection of invalid/unknown setup instructions. The original and checked Diamond date routines differ only in their weekday/year operands. After installing the original CD calendar parameters, the 600-turn run with contract and advertising policies completed eleven season-end desks without invariant failures.
|
||||
|
||||
## 1.0.1 desktop and macOS regressions
|
||||
|
||||
The desktop feedback test checks selected saved formations against their original table, compares changed miniature pixels, and checks the original yellow outline during a drag and its removal afterward. Private CD and Diamond render captures use the original assets. The SDL lifetime test checks initialization before the picker scope, normal destruction and failed initialization cleanup.
|
||||
|
||||
A macOS-only native Cocoa test initializes SDL before the native picker lifecycle, checks regular activation, creates a keyboard-focused window and verifies that a Cocoa key event produces both SDL key and text events. This automated native event test supplements human keyboard QA; it is not a claim of physical typing on the user's machine.
|
||||
|
||||
## 1.0.2 close-button regression
|
||||
|
||||
The desktop feedback test checks that the left corner requests removal instead of entering drag mode, that the remaining layout chain is intact, and that the release after acknowledgement does not activate an underlying icon. A subsequent independent click remains usable. Right-button movement and its temporary yellow outline remain covered. The user confirmed the 1.0.1 automation and Mac keyboard corrections.
|
||||
+35
-29
@@ -2,6 +2,7 @@
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "game/calendar.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "formats/data_profile.hpp"
|
||||
#include "app/career_session.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
@@ -71,7 +72,7 @@ int national_opportunities_rank(const GameState& game,int team,std::array<uint8_
|
||||
ranks.fill(1);
|
||||
const int rounds=game.league_rounds.empty()?0:int8_t(game.league_rounds.at(0));
|
||||
if(rounds<2||rounds>=league_matchdays(0))return 0;
|
||||
return team>=138?9:0;
|
||||
return team>=runtime_dimensions.league_teams?9:0;
|
||||
}
|
||||
|
||||
uint8_t source_runtime_byte(const GameState& state,const std::map<uint32_t,uint8_t>& runtime,
|
||||
@@ -548,8 +549,13 @@ static void install_league_sizes(const LeImage& exe) {
|
||||
install_calendar_rules(exe);
|
||||
}
|
||||
|
||||
static std::filesystem::path install_session_profile(const std::filesystem::path& data) {
|
||||
install_runtime_profile(load_data_profile(data));
|
||||
return data;
|
||||
}
|
||||
|
||||
CareerSession::CareerSession(const std::filesystem::path& data, uint32_t watcom_seed)
|
||||
: data_directory_(data), exe_(load_le(data / "BMH.exe")),
|
||||
: data_directory_(install_session_profile(data)), exe_(load_le(data / "BMH.exe")),
|
||||
db_(load_database(data / "M3D.MAN")),
|
||||
texts_(load_textd(data / "TEXTD.BLK")),
|
||||
rand_(watcom_seed) {
|
||||
@@ -576,7 +582,7 @@ CareerSession::CareerSession(const std::filesystem::path& data, uint32_t watcom_
|
||||
|
||||
CareerSession::CareerSession(const std::filesystem::path& data, uint32_t watcom_seed,
|
||||
const std::filesystem::path& save_path)
|
||||
: data_directory_(data), exe_(load_le(data / "BMH.exe")), db_(load_database(data / "M3D.MAN")),
|
||||
: data_directory_(install_session_profile(data)), exe_(load_le(data / "BMH.exe")), db_(load_database(data / "M3D.MAN")),
|
||||
texts_(load_textd(data / "TEXTD.BLK")), rand_(watcom_seed) {
|
||||
install_league_sizes(exe_);
|
||||
turn_driver_.alternate_match_event_roll = exe_.u8(::bmh::layout::AlternateEventRoll) != 0;
|
||||
@@ -586,8 +592,8 @@ CareerSession::CareerSession(const std::filesystem::path& data, uint32_t watcom_
|
||||
session_id_ = next_session_id.fetch_add(1, std::memory_order_relaxed);
|
||||
initialize_club_modal_runtime();
|
||||
const Savegame file = load_savegame(save_path);
|
||||
if (!file.checksum_ok || file.version != "V2.24") throw std::runtime_error("savegame: unsupported or damaged FBM");
|
||||
const DbCounts counts{exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField), exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3), exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2), exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4)};
|
||||
if (!file.checksum_ok || file.version != (runtime_dimensions.expanded ? "O1.1" : "V2.24")) throw std::runtime_error("savegame: unsupported or damaged FBM");
|
||||
const DbCounts counts{exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField), exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3), exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2), exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4), db_.counts.league_teams, db_.counts.cup_teams};
|
||||
const SaveState save(file.stream, counts);
|
||||
g_ = GameState::from_save(save, counts);
|
||||
// CompetitionPointers2, after DeskDate2: these are process statics, not FBM fields.
|
||||
@@ -1278,7 +1284,7 @@ std::optional<ui::StrengthsIdentity> CareerSession::begin_friendly_opponent_tabl
|
||||
uint64_t revision,std::string& error) {
|
||||
error.clear();
|
||||
const auto request=strengths_open_request(revision);
|
||||
if(!request||request->identity.runtime_club>=168||request->identity.source_param2||
|
||||
if(!request||request->identity.runtime_club>=runtime_dimensions.record_teams||request->identity.source_param2||
|
||||
league_family_owner_||strengths_owner_||league_pairings_draft_) {
|
||||
error="friendly table: unavailable club entry";return {};
|
||||
}
|
||||
@@ -1326,7 +1332,7 @@ std::optional<int> CareerSession::resolve_friendly_table_opponent(
|
||||
if(visible.runtime_team_id!=request.runtime_team||visible.club_identity_key!=request.expected_club_identity||
|
||||
visible.runtime_team_id<0||size_t(visible.runtime_team_id)>=g_.club_ids.size()||
|
||||
visible.club_identity_key!=int(g_.club_ids[size_t(visible.runtime_team_id)])||
|
||||
normal.rank!=row+1||normal.runtime_team_id<0||normal.runtime_team_id>=168||
|
||||
normal.rank!=row+1||normal.runtime_team_id<0||normal.runtime_team_id>=runtime_dimensions.record_teams||
|
||||
size_t(normal.runtime_team_id)>=g_.club_ids.size()||
|
||||
normal.club_identity_key!=int(g_.club_ids[size_t(normal.runtime_team_id)])) {
|
||||
error="friendly table: opponent row identity changed";return {};
|
||||
@@ -1783,13 +1789,13 @@ std::optional<CareerSession::LiveOverviewProjection> CareerSession::open_running
|
||||
// CupGroupOverviewEffects resolves this exact active descriptor through FindCup(selector, ordinal).
|
||||
const int competition_id = int16_t(g_.memory.u16(cup_entry_address(entry_index)+0x18));
|
||||
int stable_team = request.runtime_team;
|
||||
if (stable_team > 0x164) {
|
||||
if (stable_team > (kNoTeam - 1)) {
|
||||
const size_t backup = 4 * 0xb0c + 0x290;
|
||||
if (request.manager_slot != 0 || backup + 2 > g_.manager_records.size())
|
||||
throw FormatError("live overview: unsupported national cup owner");
|
||||
stable_team = int(uint16_t(g_.manager_records[backup] | uint16_t(g_.manager_records[backup+1])<<8));
|
||||
}
|
||||
if (stable_team < 0 || stable_team >= 138 || size_t(stable_team) >= g_.club_ids.size())
|
||||
if (stable_team < 0 || stable_team >= runtime_dimensions.league_teams || size_t(stable_team) >= g_.club_ids.size())
|
||||
throw FormatError("live overview: missing stable cup owner identity");
|
||||
ui::OtherGamesIdentity identity;
|
||||
identity.manager_slot=request.manager_slot; identity.runtime_team=request.runtime_team;
|
||||
@@ -2259,7 +2265,7 @@ std::optional<ui::StrengthsIdentity> CareerSession::dispatch_family_table_team_i
|
||||
if(poach_selection && *poach_selection) {
|
||||
const auto chosen=club_player_detail_context(next,**poach_selection);
|
||||
if(chosen.selection.runtime_team!=selected_team || chosen.source_slot<0 ||
|
||||
chosen.source_slot>=0xb70 || chosen.human_loan)
|
||||
chosen.source_slot>=runtime_dimensions.pool_first || chosen.human_loan)
|
||||
throw FormatError("poach: card returned a different ordinary squad player");
|
||||
refreshed.expected_family_word=next.memory.u16(family_word_at);
|
||||
// A successful param1=1 selection leaves50775 here. Its common
|
||||
@@ -2575,12 +2581,12 @@ std::optional<ui::TopScorersState> CareerSession::open_top_scorers(
|
||||
throw FormatError("top scorers: unsupported national-coach owner");
|
||||
stable_team = int(uint16_t(g_.manager_records[backup] |
|
||||
uint16_t(g_.manager_records[backup + 1]) << 8));
|
||||
} else if (team < 0 || team >= 138) {
|
||||
} else if (team < 0 || team >= runtime_dimensions.league_teams) {
|
||||
throw FormatError("top scorers: manager team is outside Source league scope");
|
||||
}
|
||||
if (stable_team < 0 || stable_team >= 138 || size_t(stable_team) >= g_.club_ids.size())
|
||||
if (stable_team < 0 || stable_team >= runtime_dimensions.league_teams || size_t(stable_team) >= g_.club_ids.size())
|
||||
throw FormatError("top scorers: missing stable club identity");
|
||||
const int league = team > 0x164 ? 0 : team_league(team);
|
||||
const int league = team > (kNoTeam - 1) ? 0 : team_league(team);
|
||||
if (league < 0 || league > 8)
|
||||
throw FormatError("top scorers: manager has no supported Source league");
|
||||
|
||||
@@ -2645,7 +2651,7 @@ std::optional<CareerSession::TopScorersDispatch> CareerSession::dispatch_top_sco
|
||||
(backup + 2 <= g_.manager_records.size() ?
|
||||
int(uint16_t(g_.manager_records[backup] |
|
||||
uint16_t(g_.manager_records[backup + 1]) << 8)) : -1) : identity.runtime_team;
|
||||
if (identity_team < 0 || identity_team >= 138 ||
|
||||
if (identity_team < 0 || identity_team >= runtime_dimensions.league_teams ||
|
||||
size_t(identity_team) >= g_.club_ids.size() ||
|
||||
int(g_.club_ids[size_t(identity_team)]) != identity.club_identity)
|
||||
throw FormatError("top scorers: stable club identity changed");
|
||||
@@ -2748,9 +2754,9 @@ std::optional<ui::OpportunitiesState> CareerSession::open_opportunities(
|
||||
const int manager=request.manager_slot,team=g_.manager_teams[size_t(manager)];
|
||||
const int league=national_source_case?0:team_league(team);
|
||||
if(national_source_case) {
|
||||
if(team!=0x165||league!=0)throw FormatError("opportunities: invalid national menu-6 owner");
|
||||
if(team!=kNoTeam||league!=0)throw FormatError("opportunities: invalid national menu-6 owner");
|
||||
if(stable_identity<0)throw FormatError("opportunities: missing national Desk identity");
|
||||
} else if(team<0||team>=138||size_t(team)>=g_.club_ids.size()||league<0||league>=9)
|
||||
} else if(team<0||team>=runtime_dimensions.league_teams||size_t(team)>=g_.club_ids.size()||league<0||league>=9)
|
||||
throw FormatError("opportunities: unsupported team/league");
|
||||
if(underlay.width!=320||underlay.height!=240)throw FormatError("opportunities: expected captured 320x240 desktop");
|
||||
const uint32_t choice_at=::bmh::layout::CareerSession_FormatError_ExecutableField+uint32_t(manager)*2;
|
||||
@@ -2787,7 +2793,7 @@ std::optional<CareerSession::OpportunitiesDispatch> CareerSession::dispatch_oppo
|
||||
uint32_t(g_.date)!=current.identity.day_counter||
|
||||
size_t(current.identity.runtime_team)>=g_.club_ids.size()||
|
||||
(!national_source_case&&int(g_.club_ids[size_t(current.identity.runtime_team)])!=current.identity.stable_club_identity)||
|
||||
(national_source_case&&(current.identity.runtime_team!=0x165||
|
||||
(national_source_case&&(current.identity.runtime_team!=kNoTeam||
|
||||
current.identity.stable_club_identity<0)))
|
||||
throw FormatError("opportunities: desk owner changed");
|
||||
OpportunitiesDispatch result;result.page=current;
|
||||
@@ -2867,14 +2873,14 @@ std::optional<ui::OtherGamesState> CareerSession::open_other_games(
|
||||
uint16_t(next.manager_records[record + 0x291]) << 8) != uint16_t(team))
|
||||
throw FormatError("other games: manager record does not own the active team");
|
||||
int stable_team = team;
|
||||
if (team > 0x164) {
|
||||
if (team > (kNoTeam - 1)) {
|
||||
const size_t backup = 4 * 0xb0c + 0x290;
|
||||
if (manager != 0 || backup + 2 > next.manager_records.size())
|
||||
throw FormatError("other games: unsupported national-coach owner");
|
||||
stable_team = int(uint16_t(next.manager_records[backup] |
|
||||
uint16_t(next.manager_records[backup + 1]) << 8));
|
||||
}
|
||||
if (stable_team < 0 || stable_team >= 138 || size_t(stable_team) >= next.club_ids.size())
|
||||
if (stable_team < 0 || stable_team >= runtime_dimensions.league_teams || size_t(stable_team) >= next.club_ids.size())
|
||||
throw FormatError("other games: missing stable manager club identity");
|
||||
|
||||
const uint8_t source_view = next.memory.u8(::bmh::layout::CareerSession_DispatchOtherGames_RuntimeField + uint32_t(manager));
|
||||
@@ -2965,13 +2971,13 @@ std::optional<CareerSession::OtherGamesDispatch> CareerSession::dispatch_other_g
|
||||
uint16_t(id.runtime_team))
|
||||
throw FormatError("other games: manager record changed");
|
||||
int stable_team = id.runtime_team;
|
||||
if (id.runtime_team > 0x164) {
|
||||
if (id.runtime_team > (kNoTeam - 1)) {
|
||||
const size_t backup = 4 * 0xb0c + 0x290;
|
||||
if (id.manager_slot != 0 || backup + 2 > g_.manager_records.size())
|
||||
throw FormatError("other games: unsupported national owner");
|
||||
stable_team = int(uint16_t(g_.manager_records[backup] | uint16_t(g_.manager_records[backup + 1]) << 8));
|
||||
}
|
||||
if (stable_team < 0 || stable_team >= 138 || size_t(stable_team) >= g_.club_ids.size() ||
|
||||
if (stable_team < 0 || stable_team >= runtime_dimensions.league_teams || size_t(stable_team) >= g_.club_ids.size() ||
|
||||
int(g_.club_ids[size_t(stable_team)]) != id.club_identity)
|
||||
throw FormatError("other games: stable club identity changed");
|
||||
if (request.action == ui::OtherGamesAction::team_info) {
|
||||
@@ -3020,10 +3026,10 @@ std::optional<CareerSession::OtherGamesDispatch> CareerSession::dispatch_other_g
|
||||
uint16_t(next.manager_records[active_record+0x290]|
|
||||
uint16_t(next.manager_records[active_record+0x291])<<8)!=uint16_t(id.runtime_team))
|
||||
throw FormatError("other games: TeamInfo changed the active manager record");
|
||||
const int retained_team=id.runtime_team>0x164
|
||||
const int retained_team=id.runtime_team>(kNoTeam - 1)
|
||||
? int(uint16_t(next.manager_records[4*0xb0c+0x290]|
|
||||
uint16_t(next.manager_records[4*0xb0c+0x291])<<8)) : id.runtime_team;
|
||||
if(retained_team<0||retained_team>=138||size_t(retained_team)>=next.club_ids.size()||
|
||||
if(retained_team<0||retained_team>=runtime_dimensions.league_teams||size_t(retained_team)>=next.club_ids.size()||
|
||||
int(next.club_ids[size_t(retained_team)])!=id.club_identity)
|
||||
throw FormatError("other games: TeamInfo changed the stable desk club identity");
|
||||
|
||||
@@ -3576,7 +3582,7 @@ std::optional<CareerSession::TransferOfferEditorDispatch> CareerSession::open_tr
|
||||
!g_.memory.has(::bmh::layout::ActiveManager) || g_.memory.u8(::bmh::layout::ActiveManager) != request.manager_slot ||
|
||||
request.runtime_club != g_.manager_teams[size_t(request.manager_slot)] ||
|
||||
request.bid.manager != request.manager_slot || request.bid.list_entry < 0 || request.bid.list_entry >= 40 ||
|
||||
request.bid.source_slot != 2928 + request.bid.list_entry || request.selected_players.size() > 1) {
|
||||
request.bid.source_slot != runtime_dimensions.pool_first + request.bid.list_entry || request.selected_players.size() > 1) {
|
||||
error = "transfer offer: stale, nested or unsupported marked opening";
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -3638,7 +3644,7 @@ std::optional<CareerSession::PoachDispatch> CareerSession::open_poach(
|
||||
result.start = start_poach(next_state, manager_slot, squad_slot, next_rand);
|
||||
if (result.start.status == PoachStatus::ready) {
|
||||
const int row = 0x28 + result.start.offer_row;
|
||||
const TransferOfferEditorRequest input{manager_slot, g_.manager_teams[size_t(manager_slot)], row, 2928 + row,
|
||||
const TransferOfferEditorRequest input{manager_slot, g_.manager_teams[size_t(manager_slot)], row, runtime_dimensions.pool_first + row,
|
||||
result.start.player, next_state.memory.u16(::bmh::layout::EditorList + uint32_t(row) * 0x58 + 8), 0, false, true};
|
||||
auto owner = open_transfer_offer_editor_source(next_state, input, next_game, next_rand);
|
||||
if (!owner.supported) { error = owner.reason; return std::nullopt; }
|
||||
@@ -3761,7 +3767,7 @@ bool CareerSession::dispatch_poach_ui(const ui::TransferMarketRequest& request,
|
||||
throw FormatError("poach: selection is not an ordinary squad row");
|
||||
const auto player=club_player_detail_context(next,*selection);
|
||||
slot=player.source_slot;
|
||||
if(slot<0 || slot>=0xb70 || slot_team(slot)!=selection->runtime_team ||
|
||||
if(slot<0 || slot>=runtime_dimensions.pool_first || slot_team(slot)!=selection->runtime_team ||
|
||||
(next.squad_slots.at(size_t(slot))&0xfff)!=selection->player_id)
|
||||
throw FormatError("poach: stale player selection");
|
||||
}
|
||||
@@ -3926,7 +3932,7 @@ std::optional<CareerSession::TransferMarketPreviewDispatch> CareerSession::previ
|
||||
if (request.preview_snapshot_index != -1 || request.squad_row != -1 || request.bid.manager != request.manager_slot ||
|
||||
request.bid.list_entry < 0 || request.bid.list_entry >= 40 ||
|
||||
request.bid.source_slot != request.preview_source_slot ||
|
||||
request.preview_source_slot != 0xb70 + request.bid.list_entry ||
|
||||
request.preview_source_slot != runtime_dimensions.pool_first + request.bid.list_entry ||
|
||||
request.bid.player != request.expected_player) {
|
||||
error = "transfer market: mismatched preview listing identity";
|
||||
return std::nullopt;
|
||||
@@ -7203,7 +7209,7 @@ ui::PreparationState CareerSession::preparation_projection(const GameState& stat
|
||||
uint16_t(state.manager_records.at(size_t(stadium.manager_slot) * 0xb0c + 0x2ad)) << 8;
|
||||
const int source_team = int16_t(uint16_t(state.manager_records.at(size_t(stadium.manager_slot) * 0xb0c + 0x290)) |
|
||||
uint16_t(state.manager_records.at(size_t(stadium.manager_slot) * 0xb0c + 0x291)) << 8);
|
||||
const int source_league = source_team > 0x164 ? 0 : team_league(source_team);
|
||||
const int source_league = source_team > (kNoTeam - 1) ? 0 : team_league(source_team);
|
||||
if (source_league < 0 || size_t(source_league) >= state.league_rounds.size())
|
||||
throw FormatError("stadium source league is outside the live league table");
|
||||
stadium.live_league_round = state.league_rounds.at(size_t(source_league));
|
||||
@@ -7947,7 +7953,7 @@ bool CareerSession::dispatch_stadium(const ui::StadiumRequest& supplied_request,
|
||||
}
|
||||
if (request.manager_slot != active || active < 0 || active > 3 ||
|
||||
size_t(active) >= g_.manager_teams.size() || request.runtime_club != g_.manager_teams[size_t(active)] ||
|
||||
request.runtime_club < 0 || request.runtime_club >= 357 ||
|
||||
request.runtime_club < 0 || request.runtime_club >= kNoTeam ||
|
||||
size_t(request.runtime_club) >= g_.club_ids.size() ||
|
||||
request.stable_club_identity != std::optional<int>(int(g_.club_ids[size_t(request.runtime_club)])) ||
|
||||
request.revision != revision || revision == UINT64_MAX || !g_.memory.has(::bmh::layout::GameMode)) {
|
||||
|
||||
+14
-14
@@ -145,12 +145,12 @@ void serve_friendly_action(ui::StartupFlow& flow, CareerSession& session,
|
||||
const auto& national=*request.national_booking;
|
||||
const auto expected=FriendlyActions::national_owner(request);
|
||||
if(request.kind!=ui::FriendlyRequestKind::book||!request.quote_id||
|
||||
request.runtime_team!=0x165||request.opponent<0x166||request.opponent>0x1a2||
|
||||
request.runtime_team!=kNoTeam||request.opponent<(kNoTeam + 1)||request.opponent>(kNoTeam + 61)||
|
||||
request.season_day<0||request.season_day>365||request.planner_count<0||
|
||||
request.planner_count>253||request.revision!=revision||
|
||||
national.owner!=expected||national.quote.owner!=expected||
|
||||
national.season_day!=request.season_day||national.quote.terms.manager!=manager||
|
||||
national.quote.terms.manager_team!=0x165||national.quote.terms.opponent!=request.opponent||
|
||||
national.quote.terms.manager_team!=kNoTeam||national.quote.terms.opponent!=request.opponent||
|
||||
national.quote.terms.planner_count!=request.planner_count||
|
||||
national.quote.terms.home_team!=request.home_team||national.quote.terms.away_team!=request.away_team||
|
||||
national.quote.terms.payer_manager!=request.payer_manager||
|
||||
@@ -232,7 +232,7 @@ void serve_friendly_action(ui::StartupFlow& flow, CareerSession& session,
|
||||
|
||||
if (request.kind != ui::FriendlyRequestKind::book || request.quote_id == 0 ||
|
||||
request.season_day < 0 || request.season_day > 365 || request.opponent < 0 ||
|
||||
request.opponent >= 168 || request.cost < 0 || request.planner_count > 253) {
|
||||
request.opponent >= runtime_dimensions.record_teams || request.cost < 0 || request.planner_count > 253) {
|
||||
flow.reject_friendly_action("Die Angaben zum Spieltermin sind ungültig.");
|
||||
return;
|
||||
}
|
||||
@@ -257,13 +257,13 @@ bool valid_national_friendly_family(const ui::StartupFlow& flow,const GameState&
|
||||
const auto* origin=flow.national_friendly_desk_owner();
|
||||
const auto* menu=flow.statistics_menu();
|
||||
const auto* desk=flow.desktop();
|
||||
if(!owner||!origin||!menu||!desk||owner->desk_menu!=6||owner->runtime_team!=0x165||
|
||||
if(!owner||!origin||!menu||!desk||owner->desk_menu!=6||owner->runtime_team!=kNoTeam||
|
||||
owner->manager<0||owner->revision!=revision||origin->kind!=ui::DeskRequestKind::open_menu||
|
||||
origin->menu_kind!=6||origin->manager_slot!=owner->manager||origin->revision!=revision||
|
||||
desk->state().revision!=revision||desk->state().manager_slot!=owner->manager||
|
||||
menu->state().owner.kind!=ui::DeskRequestKind::open_menu||menu->state().owner.menu_kind!=23||
|
||||
menu->state().owner.manager_slot!=owner->manager||menu->state().owner.revision!=revision||
|
||||
size_t(owner->manager)>=game.manager_teams.size()||game.manager_teams[size_t(owner->manager)]!=0x165||
|
||||
size_t(owner->manager)>=game.manager_teams.size()||game.manager_teams[size_t(owner->manager)]!=kNoTeam||
|
||||
!game.memory.has(::bmh::layout::ActiveManager)||int(game.memory.u8(::bmh::layout::ActiveManager))!=owner->manager)return false;
|
||||
return true;
|
||||
}
|
||||
@@ -278,17 +278,17 @@ void serve_national_friendly_selection(ui::StartupFlow& flow,CareerSession& sess
|
||||
const auto& game=session.state();
|
||||
const auto& desk=flow.desktop()->state();
|
||||
const int manager=owner->manager;
|
||||
if(owner->desk_menu!=6||owner->runtime_team!=0x165||owner->revision!=revision||
|
||||
if(owner->desk_menu!=6||owner->runtime_team!=kNoTeam||owner->revision!=revision||
|
||||
desk_request->kind!=ui::DeskRequestKind::open_menu||desk_request->menu_kind!=6||
|
||||
desk_request->revision!=revision||desk_request->manager_slot!=manager||
|
||||
desk.revision!=revision||desk.manager_slot!=manager||manager<0||
|
||||
size_t(manager)>=game.manager_teams.size()||game.manager_teams[size_t(manager)]!=0x165||
|
||||
int(game.memory.u8(::bmh::layout::ActiveManager))!=manager||selected_team<0x166||selected_team>0x1a2) {
|
||||
size_t(manager)>=game.manager_teams.size()||game.manager_teams[size_t(manager)]!=kNoTeam||
|
||||
int(game.memory.u8(::bmh::layout::ActiveManager))!=manager||selected_team<(kNoTeam + 1)||selected_team>(kNoTeam + 61)) {
|
||||
flow.close_national_friendly_picker();
|
||||
return;
|
||||
}
|
||||
if(!presenter) { flow.close_national_friendly_picker(); return; }
|
||||
ui::NationalFriendlyUi dialog_flow(*owner,national_friendly_identity(game,manager,0x165));
|
||||
ui::NationalFriendlyUi dialog_flow(*owner,national_friendly_identity(game,manager,kNoTeam));
|
||||
auto venue=dialog_flow.select_opponent(game,selected_team);
|
||||
if(venue.kind!=ui::NationalFriendlyUiActionKind::show_question||!venue.question) {
|
||||
flow.close_national_friendly_picker();return;
|
||||
@@ -321,7 +321,7 @@ void serve_national_friendly_selection(ui::StartupFlow& flow,CareerSession& sess
|
||||
}
|
||||
ui::FriendlyQuoteProjection projection;
|
||||
projection.request_id=quote_request.engine_owner->request_id;
|
||||
projection.revision=revision;projection.manager_slot=manager;projection.runtime_team=0x165;
|
||||
projection.revision=revision;projection.manager_slot=manager;projection.runtime_team=kNoTeam;
|
||||
projection.opponent=selected_team;projection.opponent_manager=quote.terms.opponent_manager;
|
||||
projection.payer_manager=quote.terms.payer_manager;projection.home_team=quote.terms.home_team;
|
||||
projection.away_team=quote.terms.away_team;projection.cost=quote.terms.cost;
|
||||
@@ -336,7 +336,7 @@ void serve_national_friendly_selection(ui::StartupFlow& flow,CareerSession& sess
|
||||
projection.dates.push_back({day,mark});
|
||||
}
|
||||
ui::FriendlyMatchState calendar;
|
||||
calendar.revision=revision;calendar.manager_slot=manager;calendar.runtime_team=0x165;
|
||||
calendar.revision=revision;calendar.manager_slot=manager;calendar.runtime_team=kNoTeam;
|
||||
calendar.current_day=game.season_day();calendar.planner_count=quote.terms.planner_count;
|
||||
calendar.season_start_counter=game.season_start;calendar.mode_three=desk.options.mode==3;
|
||||
calendar.national_team=true;calendar.manager_name=ui::original_to_utf8(desk.manager_name);
|
||||
@@ -957,7 +957,7 @@ std::string serve_flow_request(ui::StartupFlow& flow, const ui::FlowResult& resu
|
||||
const int team=game.manager_teams[size_t(manager)];
|
||||
if(team!=kNoTeam&&(team<0||size_t(team)>=game.team_flags.size()))
|
||||
throw FormatError("fair play: active manager has no Source roster");
|
||||
const int league=team>0x164?0:team_league(team);
|
||||
const int league=team>(kNoTeam - 1)?0:team_league(team);
|
||||
page=ui::fair_play_state_from_game(game,league,underlay,manager);
|
||||
} else {
|
||||
page.kind=ui::DeskRecordKind::highscore;
|
||||
@@ -2110,11 +2110,11 @@ std::string serve_flow_request(ui::StartupFlow& flow, const ui::FlowResult& resu
|
||||
const auto& desk = flow.desktop()->state();
|
||||
const int manager=request.manager_slot;
|
||||
if(manager>=0&&size_t(manager)<game.manager_teams.size()&&
|
||||
game.manager_teams[size_t(manager)]==0x165) {
|
||||
game.manager_teams[size_t(manager)]==kNoTeam) {
|
||||
const auto projection=ui::world_cup_statistics_from_game(game,
|
||||
load_le(ui::asset_path(data,"BMH.exe")),
|
||||
ui::WorldCupStatisticsOwner::friendly_match_nation_picker);
|
||||
flow.show_national_friendly_picker(projection,request,0x165);
|
||||
flow.show_national_friendly_picker(projection,request,kNoTeam);
|
||||
return {};
|
||||
}
|
||||
LeagueFamilyActions(*session).apply(revision, [&] {
|
||||
|
||||
+8
-4
@@ -1,6 +1,8 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "formats/data_profile.hpp"
|
||||
#include "game/profile_runtime.hpp"
|
||||
#include "ui/live_timing.hpp"
|
||||
// openbmh_play - the UI of src/ui connected to the engine: options, manager dialogs, a new
|
||||
// career initialised by the engine (app/career_session.hpp) and its desk.
|
||||
@@ -31,6 +33,7 @@
|
||||
#include "launch/file_dialog.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
#include "version.hpp"
|
||||
#include "app/video_session.hpp"
|
||||
#include "app/live_matchday_events.hpp"
|
||||
#include "audio/playback.hpp"
|
||||
#include "app/audio.hpp"
|
||||
@@ -151,6 +154,9 @@ int main(int argc, char** argv) {
|
||||
data = launch::path_from_utf8(args[i]);
|
||||
}
|
||||
}
|
||||
std::optional<app::VideoSession> video;
|
||||
try { video.emplace(); }
|
||||
catch (const std::exception& error) { show_start_error(error.what()); return 1; }
|
||||
// the game: as given (directory, EXE or archive); else the directory OpenBMH itself lies in,
|
||||
// when it holds a playable game (the simplest install: openbmh next to BMH.EXE); else
|
||||
// chosen in the file dialog
|
||||
@@ -190,11 +196,11 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
if (save_directory.empty()) save_directory = data;
|
||||
try {
|
||||
install_runtime_profile(load_data_profile(data));
|
||||
const Palette palette = load_palette(ui::asset_path(data, "M3PC.COL"));
|
||||
ui::StartupFlow flow(data, save_directory);
|
||||
std::unique_ptr<app::CareerSession> session;
|
||||
uint64_t revision = 0;
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) throw FormatError(SDL_GetError());
|
||||
openbmh::audio::Playback playback;
|
||||
std::string audio_error;
|
||||
playback.initialize(audio_error); // Audio is optional; the game continues without a device.
|
||||
@@ -942,7 +948,7 @@ int main(int argc, char** argv) {
|
||||
int manager, int source_slot, int list_entry,
|
||||
const HumanBuyerSaleHooks& sale_hooks) -> int {
|
||||
if (!running || manager < 0 || manager >= 4 || list_entry < 40 || list_entry >= 44 ||
|
||||
source_slot != 2928 + list_entry || !staged.memory.has(::bmh::layout::EditorList + uint32_t(list_entry) * 0x58 + 0x57))
|
||||
source_slot != runtime_dimensions.pool_first + list_entry || !staged.memory.has(::bmh::layout::EditorList + uint32_t(list_entry) * 0x58 + 0x57))
|
||||
return -1;
|
||||
const uint32_t row = ::bmh::layout::EditorList + uint32_t(list_entry) * 0x58;
|
||||
const int player = staged.squad_slots.at(size_t(source_slot)) & 0x0fff;
|
||||
@@ -3903,11 +3909,9 @@ int main(int argc, char** argv) {
|
||||
SDL_DestroyWindow(window);
|
||||
mouse_sound.detach(); // Remove event producers before closing the audio device.
|
||||
playback.shutdown();
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::fprintf(stderr, "error: %s\n", e.what());
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include <SDL.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
namespace bmh::app {
|
||||
// Establish SDL's native application before any file picker can create NSApp.
|
||||
// Cocoa otherwise retains the picker's non-keyboard activation policy.
|
||||
class VideoSession {
|
||||
public:
|
||||
VideoSession() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
const std::string error = SDL_GetError();
|
||||
SDL_Quit();
|
||||
throw std::runtime_error(error);
|
||||
}
|
||||
}
|
||||
~VideoSession() { SDL_Quit(); }
|
||||
VideoSession(const VideoSession&) = delete;
|
||||
VideoSession& operator=(const VideoSession&) = delete;
|
||||
};
|
||||
}
|
||||
@@ -420,7 +420,7 @@ void Console::register_transfer_commands() {
|
||||
Arg a;
|
||||
a.text = number;
|
||||
const auto id = to_int(a);
|
||||
if (!id || *id < 0 || *id >= 138) fail("E_BAD_ARGUMENT", "club is club:<n> (ListPoachClubs)");
|
||||
if (!id || *id < 0 || *id >= runtime_dimensions.league_teams) fail("E_BAD_ARGUMENT", "club is club:<n> (ListPoachClubs)");
|
||||
return int(*id);
|
||||
};
|
||||
Param club = detail::text("club");
|
||||
|
||||
@@ -9,8 +9,10 @@ namespace bmh {
|
||||
// Installed alongside the loaded edition's other runtime tables. Club selectors
|
||||
// remain database/savegame data; this only reproduces the original drawing gate.
|
||||
inline int original_foreign_badge_end = 138;
|
||||
inline bool expanded_badges = false;
|
||||
|
||||
inline int original_badge_gate(const LeImage& exe) {
|
||||
if(const auto* policy=exe.runtime_policy())return int(policy->badge_end);
|
||||
constexpr auto instruction = layout::ForeignBadgeGateInstruction;
|
||||
if (exe.contains(instruction) && exe.contains(instruction + 6) &&
|
||||
exe.u8(instruction) == 0x66 && exe.u8(instruction + 1) == 0x81 &&
|
||||
@@ -25,10 +27,12 @@ inline int original_badge_gate(const LeImage& exe) {
|
||||
|
||||
inline void install_original_badge_policy(const LeImage& exe) {
|
||||
original_foreign_badge_end = original_badge_gate(exe);
|
||||
expanded_badges = exe.expanded_profile();
|
||||
}
|
||||
|
||||
inline bool original_badge_fallback(int token, const LeImage* exe = nullptr) {
|
||||
const int team = token & 0xfff;
|
||||
if (exe ? exe->expanded_profile() : expanded_badges) return team == 0xfff;
|
||||
const int end = exe ? original_badge_gate(*exe) : original_foreign_badge_end;
|
||||
return team == 0xfff || (team >= 90 && team < end) || (team >= 168 && team < 357);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/binary.hpp"
|
||||
#include "formats/resource_bundle.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
@@ -7,6 +8,8 @@
|
||||
namespace bmh {
|
||||
|
||||
Bytes read_file(const std::filesystem::path& path) {
|
||||
if (!std::filesystem::exists(path))
|
||||
if (auto bytes=bundled_resource(path)) return std::move(*bytes);
|
||||
std::ifstream in(path, std::ios::binary);
|
||||
if (!in) throw FormatError("cannot open " + path.string());
|
||||
return Bytes(std::istreambuf_iterator<char>(in), {});
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/data_profile.hpp"
|
||||
#include "formats/resource_bundle.hpp"
|
||||
#include <fstream>
|
||||
#include <numeric>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
namespace bmh {
|
||||
DataProfile DataProfile::international_11() {
|
||||
DataProfile p;
|
||||
p.id="classic-plus-1";
|
||||
p.leagues={18,18,18,18,18,18,20,18,18};
|
||||
p.counts={445,3334,194,4104,164,30};
|
||||
p.big_squad_teams=164;
|
||||
p.national_first=383;
|
||||
return p;
|
||||
}
|
||||
void DataProfile::validate() const {
|
||||
const auto total=std::accumulate(leagues.begin(),leagues.end(),uint32_t(0));
|
||||
if(total!=counts.league_teams || big_squad_teams>total || counts.n42!=total+counts.cup_teams ||
|
||||
counts.n66!=extra_slots_first() || counts.clubs!=national_first+62 ||
|
||||
national_first!=total+counts.cup_teams+189 || counts.clubs>512 || counts.players>=4095 || total_slots()>65535)
|
||||
throw FormatError("profile: inconsistent counts or packed identifier overflow");
|
||||
for(auto size:leagues)if(size!=12 && size!=18 && size!=20)throw FormatError("profile: unsupported league size");
|
||||
}
|
||||
DataProfile load_data_profile(const std::filesystem::path& directory) {
|
||||
const auto file=directory/"OBMHPROF.INI";
|
||||
if(!resource_exists(file))return {};
|
||||
const auto raw=read_file(file);
|
||||
std::istringstream input(std::string(raw.begin(),raw.end()));
|
||||
std::string line,id;bool section=false,seen=false;
|
||||
while(std::getline(input,line)) {
|
||||
if(!line.empty()&&line.back()=='\r')line.pop_back();
|
||||
const auto first=line.find_first_not_of(" \t");if(first==std::string::npos||line[first]==';'||line[first]=='#')continue;
|
||||
const auto last=line.find_last_not_of(" \t");line=line.substr(first,last-first+1);
|
||||
if(line=="[OpenBMH]"){if(section)throw FormatError("profile: duplicate section");section=true;continue;}
|
||||
if(!section||line.rfind("profile=",0)!=0||seen)throw FormatError("profile: unknown or duplicate metadata key");
|
||||
id=line.substr(8);seen=true;
|
||||
}
|
||||
if(id!="classic-plus-1")throw FormatError("profile: unsupported data profile");
|
||||
auto p=DataProfile::international_11();p.validate();return p;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include "formats/m3d.hpp"
|
||||
namespace bmh {
|
||||
// Installation metadata; original files retain their implicit Classic profile.
|
||||
struct DataProfile {
|
||||
std::string id = "classic";
|
||||
std::array<uint8_t,9> leagues{18,18,18,18,18,12,12,12,12};
|
||||
DbCounts counts{};
|
||||
uint32_t big_squad_teams = 90;
|
||||
uint32_t national_first = 357;
|
||||
uint32_t pool_first() const { return big_squad_teams*24+(counts.league_teams-big_squad_teams)*16; }
|
||||
uint32_t national_slots_first() const { return pool_first()+144; }
|
||||
uint32_t extra_slots_first() const { return national_slots_first()+24; }
|
||||
uint32_t total_slots() const { return extra_slots_first()+54; }
|
||||
bool extended() const { return id != "classic"; }
|
||||
void validate() const;
|
||||
static DataProfile international_11();
|
||||
};
|
||||
DataProfile load_data_profile(const std::filesystem::path& directory);
|
||||
}
|
||||
@@ -1412,7 +1412,13 @@ inline constexpr auto NationalFriendlyPayerPrefixText = 0xa000f;
|
||||
inline constexpr auto NextDeskManager = 0xbd6cc;
|
||||
inline constexpr auto NoClubText = 0xaec74;
|
||||
inline constexpr auto NoPlayerText = 0xaec78;
|
||||
// Legacy symbol name: this is the league+cup team count, NOT a squad slot offset.
|
||||
inline constexpr auto NoTeamSquadStart = 0xa2c38;
|
||||
inline constexpr auto ProfileSmallSquadClubs = 0xa2c32;
|
||||
inline constexpr auto ProfilePoolFirst = 0xa2c56;
|
||||
inline constexpr auto ProfileFreeFirst = 0xa2c5a;
|
||||
inline constexpr auto ProfileForeignFreeFirst = 0xa2c5e;
|
||||
inline constexpr auto ProfileNationalSlotsFirst = 0xa2c62;
|
||||
inline constexpr auto OfferSlots = 0xbb844;
|
||||
inline constexpr auto Opportunities_FormatError_RuntimeField = 0xa3a6e;
|
||||
inline constexpr auto Opportunities_FormatError_RuntimeField2 = 0xa3a80;
|
||||
|
||||
+97
-2
@@ -1,5 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/le.hpp"
|
||||
#include "formats/data_profile.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
@@ -16,6 +18,10 @@ struct Object {
|
||||
} // namespace
|
||||
|
||||
std::string LeImage::cstring(uint32_t address) const {
|
||||
if (runtime_policy_) {
|
||||
const auto label=runtime_policy_->labels.find(address);
|
||||
if(label!=runtime_policy_->labels.end())return label->second;
|
||||
}
|
||||
std::string s;
|
||||
while (contains(address) && u8(address) != 0) s.push_back(char(u8(address++)));
|
||||
return s;
|
||||
@@ -35,14 +41,103 @@ void save_image(const LeImage& image, const std::filesystem::path& path) {
|
||||
if (!file) throw FormatError("cannot write the OpenBMH image");
|
||||
}
|
||||
|
||||
void save_runtime_image(const LeImage& image, const RuntimePolicy& policy, const std::filesystem::path& path) {
|
||||
constexpr uint32_t start=layout::GermanDataSegmentBegin;
|
||||
if(!image.contains(start) || policy.year<1600 || policy.year>9999 || policy.weekday>6 ||
|
||||
(policy.badge_end!=90 && policy.badge_end!=138) || policy.environment_verified>1 || policy.labels.size()>16)
|
||||
throw FormatError("runtime data: unsupported source policies");
|
||||
const uint32_t size=image.base()+image.size()-start;
|
||||
if(size>1024*1024)throw FormatError("runtime data: data segment too large");
|
||||
Bytes out{'O','B','M','H','D','A','T','1'};
|
||||
const auto put=[&](uint32_t value){for(int b=0;b<4;++b)out.push_back(uint8_t(value>>(8*b)));};
|
||||
for(uint32_t value:{start,size,policy.year,policy.weekday,policy.badge_end,policy.environment_verified,uint32_t(policy.labels.size())})put(value);
|
||||
out.insert(out.end(),image.data(start),image.data(start)+size);
|
||||
for(const auto& [address,text]:policy.labels) {
|
||||
if(text.size()>1024)throw FormatError("runtime data: label too long");
|
||||
put(address);put(uint32_t(text.size()));out.insert(out.end(),text.begin(),text.end());
|
||||
}
|
||||
std::ofstream file(path,std::ios::binary|std::ios::trunc);file.write(reinterpret_cast<const char*>(out.data()),std::streamsize(out.size()));
|
||||
if(!file)throw FormatError("cannot write runtime data");
|
||||
}
|
||||
|
||||
LeImage load_le(const std::filesystem::path& path) {
|
||||
const auto profile = load_data_profile(path.parent_path());
|
||||
const auto apply_profile = [&](LeImage img) {
|
||||
if (!profile.extended()) return img;
|
||||
const auto put = [&](uint32_t address, uint32_t value, int width) {
|
||||
if (!img.contains(address) || !img.contains(address + uint32_t(width - 1)))
|
||||
throw FormatError("profile: executable lacks verified data dimensions");
|
||||
for (int b = 0; b < width; ++b) img.bytes_.at(address - img.base_ + uint32_t(b)) = uint8_t(value >> (8 * b));
|
||||
};
|
||||
if (img.u8(layout::LeagueSizes) != 18)
|
||||
throw FormatError("profile: classic-plus-1 requires a German installation");
|
||||
put(layout::CareerSession_DataDirectory_RuntimeField, profile.counts.clubs, 4);
|
||||
put(layout::CareerSession_DataDirectory_RuntimeField3, profile.counts.players, 4);
|
||||
put(layout::CareerSession_DataDirectory_RuntimeField2, profile.counts.n42, 4);
|
||||
put(layout::CareerSession_DataDirectory_RuntimeField4, profile.counts.n66, 4);
|
||||
put(layout::CareerSession_DispatchLineup_RuntimeField, profile.counts.league_teams, 2);
|
||||
put(layout::TeamsWithSquads, profile.big_squad_teams, 2);
|
||||
put(layout::NoTeamSquadStart, profile.counts.n42, 2);
|
||||
put(layout::ProfileSmallSquadClubs, profile.counts.league_teams - profile.big_squad_teams, 2);
|
||||
put(layout::ClubPlayerDetail_ClubPlayerDetailRedraw_RuntimeField, profile.counts.players, 4);
|
||||
put(layout::ProfilePoolFirst, profile.pool_first(), 4);
|
||||
put(layout::ProfileFreeFirst, profile.pool_first() + 44, 4);
|
||||
put(layout::ProfileForeignFreeFirst, profile.pool_first() + 124, 4);
|
||||
put(layout::ProfileNationalSlotsFirst, profile.national_slots_first(), 4);
|
||||
for (size_t league = 0; league < profile.leagues.size(); ++league)
|
||||
put(layout::LeagueSizes + uint32_t(league), profile.leagues[league], 1);
|
||||
std::vector<int> foreign_days;
|
||||
for (int day = 0; day < 365; ++day) {
|
||||
const auto at = layout::CompetitionCalendar + uint32_t(day * 2);
|
||||
const uint16_t flags = img.u16(at);
|
||||
if ((flags & 0x4001) == 1 && day + 1 < 365) foreign_days.push_back(day + 1);
|
||||
put(at, flags & ~0x10u, 2);
|
||||
}
|
||||
if (foreign_days.size() != 34) throw FormatError("profile: unsupported domestic calendar");
|
||||
for (int target : {60, 110, 250, 290}) {
|
||||
int chosen = -1;
|
||||
for (int delta = 0; delta < 7 && chosen < 0; ++delta) {
|
||||
const int day = target + delta;
|
||||
if (img.u16(layout::CompetitionCalendar + uint32_t(day * 2)) == 0 &&
|
||||
std::find(foreign_days.begin(), foreign_days.end(), day) == foreign_days.end()) chosen = day;
|
||||
}
|
||||
if (chosen < 0) throw FormatError("profile: no calendar space for extra English fixtures");
|
||||
foreign_days.push_back(chosen);
|
||||
}
|
||||
for (int day : foreign_days) {
|
||||
const auto at = layout::CompetitionCalendar + uint32_t(day * 2);
|
||||
put(at, img.u16(at) | 0x10, 2);
|
||||
}
|
||||
img.expanded_profile_ = true;
|
||||
return img;
|
||||
};
|
||||
const Bytes raw = read_file(path);
|
||||
if(raw.size()>=8 && std::string(raw.begin(),raw.begin()+8)=="OBMHDAT1") {
|
||||
if(raw.size()<36)throw FormatError("runtime data: truncated header");
|
||||
const uint32_t base=le32(raw,8),size=le32(raw,12),labels=le32(raw,32);
|
||||
RuntimePolicy policy{le32(raw,16),le32(raw,20),le32(raw,24),le32(raw,28),{}};
|
||||
if(base!=layout::GermanDataSegmentBegin || size>1024*1024 || size_t(size)+36>raw.size() || labels>16 ||
|
||||
policy.year<1600 || policy.year>9999 || policy.weekday>6 || (policy.badge_end!=90 && policy.badge_end!=138) || policy.environment_verified>1)
|
||||
throw FormatError("runtime data: invalid dimensions or policies");
|
||||
auto image=LeImage::from_bytes(base,Bytes(raw.begin()+36,raw.begin()+36+size));
|
||||
size_t at=36+size;
|
||||
for(uint32_t i=0;i<labels;++i) {
|
||||
if(at+8>raw.size())throw FormatError("runtime data: truncated label");
|
||||
const auto address=le32(raw,at),length=le32(raw,at+4);at+=8;
|
||||
if(length>1024 || at+length>raw.size() || !policy.labels.emplace(address,std::string(raw.begin()+at,raw.begin()+at+length)).second)
|
||||
throw FormatError("runtime data: invalid label");
|
||||
at+=length;
|
||||
}
|
||||
if(at!=raw.size())throw FormatError("runtime data: trailing bytes");
|
||||
image.runtime_policy_=std::move(policy);
|
||||
return apply_profile(std::move(image));
|
||||
}
|
||||
if (raw.size() >= sizeof kImageMagic + 8 && std::equal(kImageMagic, kImageMagic + sizeof kImageMagic, raw.begin())) {
|
||||
const auto word = [&](size_t at) { return uint32_t(raw[at] | raw[at + 1] << 8 | raw[at + 2] << 16) | uint32_t(raw[at + 3]) << 24; };
|
||||
const uint32_t base = word(sizeof kImageMagic), size = word(sizeof kImageMagic + 4);
|
||||
if (raw.size() != sizeof kImageMagic + 8 + size_t(size)) throw FormatError("OpenBMH image: wrong size");
|
||||
LeImage img = LeImage::from_bytes(base, Bytes(raw.begin() + sizeof kImageMagic + 8, raw.end()));
|
||||
return img;
|
||||
return apply_profile(std::move(img));
|
||||
}
|
||||
auto u8 = [&](size_t o) -> uint32_t {
|
||||
if (o >= raw.size()) throw FormatError("LE: read beyond the file");
|
||||
@@ -131,7 +226,7 @@ LeImage load_le(const std::filesystem::path& path) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return img;
|
||||
return apply_profile(std::move(img));
|
||||
}
|
||||
|
||||
} // namespace bmh
|
||||
@@ -11,11 +11,18 @@
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
||||
#include "formats/binary.hpp"
|
||||
|
||||
namespace bmh {
|
||||
|
||||
// Resolved edition policies, not copied machine instructions.
|
||||
struct RuntimePolicy {
|
||||
uint32_t year=0, weekday=0, badge_end=0, environment_verified=0;
|
||||
std::map<uint32_t,std::string> labels;
|
||||
};
|
||||
class LeImage {
|
||||
public:
|
||||
uint32_t base() const { return base_; }
|
||||
@@ -43,10 +50,14 @@ public:
|
||||
return img;
|
||||
}
|
||||
const Bytes& bytes() const { return bytes_; }
|
||||
bool expanded_profile() const { return expanded_profile_; }
|
||||
const RuntimePolicy* runtime_policy() const { return runtime_policy_ ? &*runtime_policy_ : nullptr; }
|
||||
|
||||
friend LeImage load_le(const std::filesystem::path& path);
|
||||
|
||||
private:
|
||||
std::optional<RuntimePolicy> runtime_policy_;
|
||||
bool expanded_profile_ = false;
|
||||
uint32_t base_ = 0;
|
||||
Bytes bytes_;
|
||||
};
|
||||
@@ -58,5 +69,7 @@ LeImage load_le(const std::filesystem::path& path);
|
||||
// The OpenBMH image format: "OPENBMH-IMAGE" NUL, u32 base, u32 size, the bytes. load_le()
|
||||
// reads it as well, so a translated image can stand in for BMH.exe in a data directory.
|
||||
void save_image(const LeImage& image, const std::filesystem::path& path);
|
||||
// Exports only the data segment and resolved policy values, never DOS/LE/code objects.
|
||||
void save_runtime_image(const LeImage&, const RuntimePolicy&, const std::filesystem::path&);
|
||||
|
||||
} // namespace bmh
|
||||
+8
-3
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/m3d.hpp"
|
||||
#include "formats/data_profile.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@@ -34,13 +35,17 @@ std::string pool_string(const Bytes& pool, size_t offset) {
|
||||
|
||||
} // namespace
|
||||
|
||||
Database load_database(const std::filesystem::path& path) {
|
||||
return load_database(path, load_data_profile(path.parent_path()).counts);
|
||||
}
|
||||
|
||||
Database load_database(const std::filesystem::path& path, const DbCounts& c) {
|
||||
Bytes d = read_file(path);
|
||||
Reader r{d};
|
||||
Bytes lens = r.take(8);
|
||||
size_t len_clubs = le16(lens, 0), len_players = le16(lens, 2), len_refs = le16(lens, 4), len_stadiums = le16(lens, 6);
|
||||
|
||||
Database db;
|
||||
Database db; db.counts=c;
|
||||
db.raw_player_bonus_values = r.take(c.n66 + 0x32);
|
||||
Bytes club_pool = r.take(len_clubs);
|
||||
Bytes player_pool = r.take(len_players);
|
||||
@@ -57,8 +62,8 @@ Database load_database(const std::filesystem::path& path, const DbCounts& c) {
|
||||
db.raw_foreign_club_strength = r.take(0xFB);
|
||||
db.raw_league_auxiliary_bytes = r.take(0xBD);
|
||||
db.raw_referee_properties = r.take(0x32);
|
||||
db.raw_club_kit_selectors = r.take(0x1A3);
|
||||
db.raw_club_short_name_offsets = r.take(0xA8);
|
||||
db.raw_club_kit_selectors = r.take(c.clubs);
|
||||
db.raw_club_short_name_offsets = r.take(c.n42);
|
||||
db.squad_list = r.take((c.n66 - 4) * 2 + 0x6C);
|
||||
Bytes w35c = r.take(c.players * 4), w368 = r.take(c.players * 4), w364 = r.take(c.players * 4);
|
||||
if (r.pos != d.size()) throw FormatError("M3D: trailing data, table sizes do not match");
|
||||
|
||||
+5
-1
@@ -16,6 +16,8 @@ struct DbCounts {
|
||||
uint32_t players = 2574;
|
||||
uint32_t n42 = 168;
|
||||
uint32_t n66 = 3096;
|
||||
uint32_t league_teams = 138;
|
||||
uint32_t cup_teams = 30;
|
||||
};
|
||||
|
||||
// A player as stored in the three parallel u32 tables of the database/savegame
|
||||
@@ -61,6 +63,7 @@ struct Player {
|
||||
};
|
||||
|
||||
struct Database {
|
||||
DbCounts counts{};
|
||||
std::vector<std::string> club_names;
|
||||
std::vector<std::string> referees;
|
||||
std::vector<std::string> stadiums;
|
||||
@@ -73,6 +76,7 @@ struct Database {
|
||||
Bytes raw_player_bonus_values, raw_database_metadata, raw_club_auxiliary_words, raw_club_badge_selectors, raw_foreign_club_strength, raw_league_auxiliary_bytes, raw_referee_properties, raw_club_kit_selectors, raw_club_short_name_offsets;
|
||||
};
|
||||
|
||||
Database load_database(const std::filesystem::path& path, const DbCounts& counts = {});
|
||||
Database load_database(const std::filesystem::path& path, const DbCounts& counts);
|
||||
Database load_database(const std::filesystem::path& path);
|
||||
|
||||
} // namespace bmh
|
||||
@@ -0,0 +1,92 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/resource_bundle.hpp"
|
||||
#include "miniz.h"
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
namespace bmh {
|
||||
namespace {
|
||||
std::string folded(std::string name) {
|
||||
std::transform(name.begin(),name.end(),name.begin(),[](unsigned char ch){return char(std::toupper(ch));});
|
||||
return name;
|
||||
}
|
||||
struct Bundle {
|
||||
Bytes file;
|
||||
mz_zip_archive zip{};
|
||||
std::map<std::string,mz_uint> entries;
|
||||
explicit Bundle(const std::filesystem::path& path) {
|
||||
const auto size=std::filesystem::file_size(path);
|
||||
if(size>64*1024*1024)throw FormatError("community bundle exceeds size limit");
|
||||
std::ifstream input(path,std::ios::binary);
|
||||
file.assign(std::istreambuf_iterator<char>(input),{});
|
||||
if(!input.is_open() || file.size()!=size || !mz_zip_reader_init_mem(&zip,file.data(),file.size(),0))
|
||||
throw FormatError("cannot read community bundle");
|
||||
try {
|
||||
uint64_t total=0;
|
||||
const auto count=mz_zip_reader_get_num_files(&zip);
|
||||
if(count>4096)throw FormatError("community bundle has too many entries");
|
||||
for(mz_uint i=0;i<count;++i) {
|
||||
mz_zip_archive_file_stat st{};
|
||||
if(!mz_zip_reader_file_stat(&zip,i,&st))throw FormatError("invalid community directory");
|
||||
if(st.m_is_directory)continue;
|
||||
const std::string name=st.m_filename;
|
||||
const std::filesystem::path relative(name);
|
||||
if(name.empty()||name.find('\\')!=std::string::npos||name.find(':')!=std::string::npos||relative.is_absolute())
|
||||
throw FormatError("unsafe community resource name");
|
||||
for(const auto& part:relative)if(part==".."||part==".")throw FormatError("unsafe community resource path");
|
||||
total+=st.m_uncomp_size;
|
||||
if(st.m_uncomp_size>32*1024*1024 || total>128*1024*1024 ||
|
||||
!entries.emplace(folded(name),i).second)throw FormatError("ambiguous or oversized community resources");
|
||||
}
|
||||
}catch(...){mz_zip_reader_end(&zip);throw;}
|
||||
}
|
||||
~Bundle(){mz_zip_reader_end(&zip);}
|
||||
};
|
||||
std::mutex bundle_mutex;
|
||||
struct Cached { std::filesystem::file_time_type modified; uintmax_t size; std::shared_ptr<Bundle> bundle; };
|
||||
std::map<std::filesystem::path,Cached> cache;
|
||||
std::pair<std::shared_ptr<Bundle>,std::string> locate(const std::filesystem::path& requested) {
|
||||
auto path=std::filesystem::absolute(requested).lexically_normal();
|
||||
auto root=path.parent_path();
|
||||
for(int depth=0;depth<4 && !root.empty();++depth) {
|
||||
const auto archive=root/kCommunityBundle;
|
||||
std::error_code ec;
|
||||
if(std::filesystem::is_regular_file(archive,ec)) {
|
||||
const auto modified=std::filesystem::last_write_time(archive);
|
||||
const auto size=std::filesystem::file_size(archive);
|
||||
auto found=cache.find(archive);
|
||||
if(found==cache.end()||found->second.modified!=modified||found->second.size!=size) {
|
||||
auto bundle=std::make_shared<Bundle>(archive);
|
||||
if(cache.size()>=4)cache.clear();
|
||||
found=cache.insert_or_assign(archive,Cached{modified,size,std::move(bundle)}).first;
|
||||
}
|
||||
auto name=folded(path.lexically_relative(root).generic_string());
|
||||
// Compatibility address-view API; the archive contains no EXE image.
|
||||
if(name=="BMH.EXE")name="RUNTIME.DAT";
|
||||
return {found->second.bundle,std::move(name)};
|
||||
}
|
||||
const auto parent=root.parent_path();if(parent==root)break;root=parent;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
std::optional<Bytes> bundled_resource(const std::filesystem::path& path) {
|
||||
std::lock_guard lock(bundle_mutex);
|
||||
auto [bundle,name]=locate(path);if(!bundle)return std::nullopt;
|
||||
const auto found=bundle->entries.find(name);if(found==bundle->entries.end())return std::nullopt;
|
||||
mz_zip_archive_file_stat st{};mz_zip_reader_file_stat(&bundle->zip,found->second,&st);
|
||||
Bytes result(size_t(st.m_uncomp_size));
|
||||
if(!mz_zip_reader_extract_to_mem(&bundle->zip,found->second,result.data(),result.size(),0))
|
||||
throw FormatError("damaged community resource: "+name);
|
||||
return result;
|
||||
}
|
||||
bool resource_exists(const std::filesystem::path& path) {
|
||||
std::error_code ec;if(std::filesystem::is_regular_file(path,ec))return true;
|
||||
std::lock_guard lock(bundle_mutex);auto [bundle,name]=locate(path);
|
||||
return bundle && bundle->entries.count(name)!=0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "formats/binary.hpp"
|
||||
#include <optional>
|
||||
namespace bmh {
|
||||
inline constexpr const char* kCommunityBundle = "COMMUNITY.OBD";
|
||||
// Read-only package lookup. Loose user saves always remain outside the bundle.
|
||||
std::optional<Bytes> bundled_resource(const std::filesystem::path& path);
|
||||
bool resource_exists(const std::filesystem::path& path);
|
||||
}
|
||||
@@ -31,7 +31,7 @@ constexpr BlockDef kBlocks[] = {
|
||||
{::bmh::layout::Cup_AdvanceCup_RuntimeField3, false, 1, Count::None, 0, false}, {::bmh::layout::LiveMatchday_FormatError_RuntimeField14, false, 6, Count::None, 0, false},
|
||||
{::bmh::layout::ManagerRecords, false, 0x373c, Count::None, 0, false}, // 5 manager records of 0xB0C bytes
|
||||
{::bmh::layout::Loans, false, 0x1e0, Count::None, 0, false},
|
||||
{::bmh::layout::ManagerMatchHistory, false, 0x20d0, Count::None, 0, false}, // form history: 5 managers x 168 teams x 10
|
||||
{::bmh::layout::ManagerMatchHistory, false, 0, Count::N42, 50, false}, // form history: 5 managers x 168 teams x 10
|
||||
{::bmh::layout::MatchdayGroupDescriptors, false, 0x4e0, Count::None, 0, false}, {::bmh::layout::ManagerAutomation, false, 0x14, Count::None, 0, false},
|
||||
{::bmh::layout::Desktops, false, 0x10e0, Count::None, 0, false}, // desktop layouts (.MEN), 5 x 0x360
|
||||
{::bmh::layout::CareerSession_DispatchToto_RuntimeField, false, 1, Count::None, 0, false}, {::bmh::layout::Cup_AdvanceCup_RuntimeField4, false, 1, Count::None, 0, false},
|
||||
@@ -43,7 +43,7 @@ constexpr BlockDef kBlocks[] = {
|
||||
{::bmh::layout::Placements, false, 0x50, Count::None, 0, false}, {::bmh::layout::ActiveSelectors, false, 8, Count::None, 0, false},
|
||||
{::bmh::layout::Career_CareerAddManager_RuntimeField2, false, 0x90, Count::None, 0, false}, {::bmh::layout::DeskActions_SubmitPoolsCoupon_RuntimeField, false, 0x2c, Count::None, 0, false},
|
||||
{::bmh::layout::NextDeskManager, false, 8, Count::None, 0, false}, {::bmh::layout::Savestate_Layout_ExecutableField8, false, 10, Count::None, 0, false},
|
||||
{::bmh::layout::DeskPosition, false, 1, Count::None, 0, false}, {::bmh::layout::DeskRecords_Teams_RuntimeField, false, 0x114, Count::None, 0, false},
|
||||
{::bmh::layout::DeskPosition, false, 1, Count::None, 0, false}, {::bmh::layout::DeskRecords_Teams_RuntimeField, false, 0, Count::Teams, 2, false},
|
||||
{::bmh::layout::CareerSession_FormatError_RuntimeField7, false, 2, Count::None, 0, false}, {::bmh::layout::Cup_AdvanceCup_RuntimeField6, false, 6, Count::None, 0, false},
|
||||
{::bmh::layout::CurrentMatchday, false, 4, Count::None, 0, false}, // seed of the game RNG (GameRandom)
|
||||
{::bmh::layout::ClubPlayerDetail_InvalidArgument_RuntimeField3, false, 1, Count::None, 0, false}, {::bmh::layout::CoachActive, false, 1, Count::None, 0, false},
|
||||
@@ -51,12 +51,12 @@ constexpr BlockDef kBlocks[] = {
|
||||
{::bmh::layout::CareerDuration, false, 1, Count::None, 0, false}, {::bmh::layout::GameMode, false, 1, Count::None, 0, false},
|
||||
{::bmh::layout::CompetitionSelection, false, 4, Count::None, 0, false}, {::bmh::layout::ManagerCount, false, 1, Count::None, 0, false}, // number of managers
|
||||
{::bmh::layout::SavedCompetition, false, 4, Count::None, 0, false}, {::bmh::layout::Difficulty, false, 1, Count::None, 0, false},
|
||||
{::bmh::layout::StockExchange, false, 0x450, Count::None, 0, false}, {::bmh::layout::FundBlock, false, 0xa8, Count::None, 0, false},
|
||||
{::bmh::layout::StockExchange, false, 0x450, Count::None, 0, false}, {::bmh::layout::FundBlock, false, 0, Count::N42, 1, false},
|
||||
{::bmh::layout::Coupon, false, 100, Count::None, 0, false}, {::bmh::layout::Savestate_Layout_ExecutableField2, false, 3, Count::None, 0, false},
|
||||
{::bmh::layout::Savestate_Layout_ExecutableField, false, 1, Count::None, 0, false}, {::bmh::layout::AdGroupId, false, 1, Count::None, 0, false},
|
||||
{::bmh::layout::OfferSlots, false, 0x10, Count::None, 0, false}, {::bmh::layout::ForeignClubStrength, false, 0xfb, Count::None, 0, false},
|
||||
{::bmh::layout::Career_Put_ExecutableField3, false, 0xbd, Count::None, 0, false}, {::bmh::layout::ClubShortNameOffsets, false, 0xa8, Count::None, 0, false},
|
||||
{::bmh::layout::ClubKitSelectors, false, 0x1a3, Count::None, 0, false}, {::bmh::layout::Savestate_Layout_ExecutableField7, false, 0x18, Count::None, 0, false},
|
||||
{::bmh::layout::Career_Put_ExecutableField3, false, 0xbd, Count::None, 0, false}, {::bmh::layout::ClubShortNameOffsets, false, 0, Count::N42, 1, false},
|
||||
{::bmh::layout::ClubKitSelectors, false, 0, Count::Clubs, 1, false}, {::bmh::layout::Savestate_Layout_ExecutableField7, false, 0x18, Count::None, 0, false},
|
||||
{::bmh::layout::ClubInfo_FormatError_RuntimeField, false, 0x420, Count::None, 0, false}, {::bmh::layout::Career_CareerManagersEnd_RuntimeField, false, 0x18, Count::None, 0, false},
|
||||
{::bmh::layout::ClubInfo_FormatError_RuntimeField2, false, 0xc, Count::None, 0, false}, {::bmh::layout::DeskActions_Unsupported_RuntimeField, false, 4, Count::None, 0, false},
|
||||
{::bmh::layout::Career_RemoveJoinLoans_RuntimeField, false, 800, Count::None, 0, false}, {::bmh::layout::ClubPlayerDetail_InvalidArgument_RuntimeField, false, 200, Count::None, 0, false},
|
||||
@@ -98,7 +98,7 @@ constexpr BlockDef kBlocks[] = {
|
||||
{::bmh::layout::Career_EuropeanClub_ExecutableField, false, 1, Count::None, 0, false}, {::bmh::layout::Career_EuropeanClub_ExecutableField2, false, 1, Count::None, 0, false},
|
||||
{::bmh::layout::Career_EuropeanClub_ExecutableField3, false, 1, Count::None, 0, false}, {::bmh::layout::Career_CompetitionPointersEnglish_ExecutableField24, false, 0x28, Count::None, 0, false},
|
||||
{::bmh::layout::Career_CompetitionPointersEnglish_ExecutableField29, false, 0x14, Count::None, 0, false}, {::bmh::layout::ClubSeasonRecords, false, 4, Count::None, 0, false},
|
||||
{::bmh::layout::ClubSeasonRecords, true, 0x3090, Count::None, 0, true}, // club records (168 x 74), only if pointer != 0
|
||||
{::bmh::layout::ClubSeasonRecords, true, 0, Count::N42, 74, true}, // club records (168 x 74), only if pointer != 0
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -106,7 +106,7 @@ constexpr BlockDef kBlocks[] = {
|
||||
SaveState::SaveState(const Bytes& stream, const DbCounts& c) : stream_(stream) {
|
||||
// Teams in league play and cup-only teams are not part of DbCounts yet;
|
||||
// these are the V2.24 values (CareerSession_DispatchLineup_RuntimeField, CareerSession_InstallLeagueSizes_RuntimeField6).
|
||||
constexpr uint32_t kTeams = 138, kCupTeams = 30;
|
||||
const uint32_t kTeams = c.league_teams, kCupTeams = c.cup_teams;
|
||||
size_t pos = 0;
|
||||
uint32_t last_pointer = 0;
|
||||
for (const BlockDef& d : kBlocks) {
|
||||
@@ -177,7 +177,7 @@ const SaveBlock& SaveState::block(uint32_t address) const {
|
||||
namespace bmh {
|
||||
|
||||
std::vector<SaveBlock> save_layout(const DbCounts& c, bool club_records) {
|
||||
constexpr uint32_t kTeams = 138, kCupTeams = 30;
|
||||
const uint32_t kTeams = c.league_teams, kCupTeams = c.cup_teams;
|
||||
std::vector<SaveBlock> out;
|
||||
size_t pos = 0;
|
||||
for (const BlockDef& d : kBlocks) {
|
||||
|
||||
@@ -261,7 +261,7 @@ int32_t stadium_required_attendance(const GameState& source, int manager) {
|
||||
if (manager < 0 || manager > 4) throw FormatError("stadium attendance: invalid manager");
|
||||
GameState g = source;
|
||||
const int team = g.manager_teams.at(size_t(manager));
|
||||
const int league = team > 0x164 ? 0 : team_league(team);
|
||||
const int league = team > (kNoTeam - 1) ? 0 : team_league(team);
|
||||
if (league < 0 || league >= kLeagueCount)
|
||||
throw FormatError("stadium attendance: manager has no Source league");
|
||||
const int home_games = league_matchdays(league) / 2;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
namespace bmh {
|
||||
namespace { CalendarEpoch installed_epoch{2026, 2}; }
|
||||
CalendarEpoch calendar_epoch_from_executable(const LeImage& exe) {
|
||||
if(const auto* policy=exe.runtime_policy())return {int(policy->year),int(policy->weekday)};
|
||||
constexpr auto setup = layout::CalendarDateSetup;
|
||||
constexpr uint8_t weekday_prefix[] = {0xc6,0x44,0x24,0x04};
|
||||
constexpr uint8_t month_and_year_prefix[] = {0xc6,0x44,0x24,0x0c,0x07,0xc7,0x04,0x24};
|
||||
|
||||
+19
-19
@@ -12,12 +12,12 @@ namespace bmh {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr size_t kPoolSlots = 2928; // CareerRuntimeField: the clubs' squads end here
|
||||
constexpr size_t kTailFrom = 2928 + 40;
|
||||
constexpr size_t kTailTo = 2972; // CareerRuntimeField2
|
||||
constexpr size_t kExtraSlots = 3096; // CareerSession_DataDirectory_RuntimeField4: 54 extra players from here
|
||||
constexpr size_t kSquadSlots = 3096 + 54;
|
||||
constexpr int kLeagueTeams = 138; // CareerSession_DispatchLineup_RuntimeField
|
||||
const int& kPoolSlots = runtime_dimensions.pool_first; // CareerRuntimeField: the clubs' squads end here
|
||||
const int& kTailFrom = runtime_dimensions.market_special_first;
|
||||
const int& kTailTo = runtime_dimensions.free_first; // CareerRuntimeField2
|
||||
const int& kExtraSlots = runtime_dimensions.extra_slots_first; // CareerSession_DataDirectory_RuntimeField4: 54 extra players from here
|
||||
const int& kSquadSlots = runtime_dimensions.total_slots;
|
||||
const int& kLeagueTeams = runtime_dimensions.league_teams; // CareerSession_DispatchLineup_RuntimeField
|
||||
|
||||
// LeagueSizes: clubs per league; LeagueStrengthRanges: (minimum, maximum) strength per league.
|
||||
// (the clubs per league are kLeagueSizes, schedule.hpp)
|
||||
@@ -101,7 +101,7 @@ void startup_players(GameState& g, GameRandom& game, WatcomRandom& rand) {
|
||||
namespace bmh {
|
||||
|
||||
GameState startup_state(const LeImage& exe, const Database& db, const Bytes& m3_men, const Bytes& m3_dat) {
|
||||
const DbCounts counts;
|
||||
const DbCounts counts=db.counts;
|
||||
const std::vector<SaveBlock> layout = save_layout(counts, true);
|
||||
Bytes stream;
|
||||
for (const SaveBlock& b : layout) {
|
||||
@@ -154,7 +154,7 @@ GameState startup_state(const LeImage& exe, const Database& db, const Bytes& m3_
|
||||
if (b.heap) {
|
||||
for (size_t i = 0; i < db.players.size() && 4 * i + 3 < data.size(); i++) {
|
||||
uint32_t w = b.address == ::bmh::layout::PlayerConditionTechniqueForm ? db.players[i].w35c : b.address == ::bmh::layout::PlayerSkillWords ? db.players[i].w368 : db.players[i].w364;
|
||||
if (b.address == ::bmh::layout::PlayerSkillWords && i + 32 >= db.players.size())
|
||||
if (b.address == ::bmh::layout::PlayerSkillWords && !runtime_dimensions.expanded && i + 32 >= db.players.size())
|
||||
w = (w & 0x07ffffffu) | uint32_t(exe.u8(::bmh::layout::Career_BuildStadium_RuntimeField4 - uint32_t(db.players.size() - i))) << 27;
|
||||
for (int k = 0; k < 4; k++) data[4 * i + size_t(k)] = uint8_t(w >> (8 * k));
|
||||
}
|
||||
@@ -213,14 +213,14 @@ void new_career_markets_and_moods(GameState& g, GameRandom& game, WatcomRandom&
|
||||
}
|
||||
|
||||
bool new_career_players(GameState& g, GameRandom& game, WatcomRandom& rand, MinuteReport& report) {
|
||||
for (size_t slot = 0; slot < 2928; slot++) {
|
||||
for (size_t slot = 0; slot < runtime_dimensions.pool_first; slot++) {
|
||||
const int id = g.squad_slots.at(slot) & 0x0fff;
|
||||
if (id == 0x0fff) continue;
|
||||
Player& p = g.players.at(size_t(id));
|
||||
p.w364 |= uint32_t(rand.range(4, 0x10)) << 21;
|
||||
p.w368 = (p.w368 & 0xffffc000u) + uint32_t(rand.range(0, 0x3fff));
|
||||
}
|
||||
for (int slot = 3096; slot < 3096 + 0x36; slot++)
|
||||
for (int slot = runtime_dimensions.extra_slots_first; slot < runtime_dimensions.extra_slots_first + 0x36; slot++)
|
||||
if (!release_player(g, slot, game, rand, report)) return false;
|
||||
return !report.unsupported;
|
||||
}
|
||||
@@ -258,7 +258,7 @@ bool human_club(const GameState& g, int team) {
|
||||
const int managers = g.memory.u8(::bmh::layout::ManagerCount);
|
||||
for (int m = 0; m < managers; m++)
|
||||
if (team_of(g, m) == uint16_t(team)) return true;
|
||||
return team_of(g, 0) == 0x165 && team_of(g, 4) == uint16_t(team);
|
||||
return team_of(g, 0) == kNoTeam && team_of(g, 4) == uint16_t(team);
|
||||
}
|
||||
|
||||
// OpenBMH deviates from the original: skips reserved calendar positions when assigning a joining manager to a club.
|
||||
@@ -431,17 +431,17 @@ bool career_add_manager(GameState& g, const LeImage& exe, int m, const CareerMan
|
||||
if (!g.memory.has(::bmh::layout::ManagerCount) || m < 0 || m >= 4 ||
|
||||
g.memory.u8(::bmh::layout::ManagerCount) > 4 || m >= g.memory.u8(::bmh::layout::ManagerCount) ||
|
||||
size_t(m) >= g.manager_teams.size() || g.manager_records.size() < 5 * kRecord ||
|
||||
choice.team < 0 || choice.team >= 168 || size_t(choice.team) >= g.club_ids.size() ||
|
||||
choice.team < 0 || choice.team >= runtime_dimensions.record_teams || size_t(choice.team) >= g.club_ids.size() ||
|
||||
choice.league < 0 || choice.league > 4 || choice.strength < 0 || choice.strength > 2 ||
|
||||
choice.portrait < 0 || choice.portrait > 11 || choice.name.size() > 24 ||
|
||||
g.tactics.size() < size_t(m + 1) * 0x840 ||
|
||||
g.manager_ratings.size() < size_t(m + 1) * 0x3c ||
|
||||
g.manager_results.size() < g.manager_teams.size() * 0x690 ||
|
||||
g.squad_slots.size() < kSquadSlots || g.club_ids.size() < 168 ||
|
||||
g.team_morale.size() < 168 || g.team_flags.size() < 168 ||
|
||||
g.club_heap_bc.size() < 168 * 2 || g.club_heap_78.size() < 168 * 2 ||
|
||||
g.club_heap_b8.size() < 168 || g.position_history.size() < 138 * 0x1a ||
|
||||
(!g.club_table.empty() && g.club_table.size() < 168 * 0x4a) ||
|
||||
g.manager_results.size() < g.manager_teams.size() * (runtime_dimensions.record_teams * 10) ||
|
||||
g.squad_slots.size() < kSquadSlots || g.club_ids.size() < runtime_dimensions.record_teams ||
|
||||
g.team_morale.size() < runtime_dimensions.record_teams || g.team_flags.size() < runtime_dimensions.record_teams ||
|
||||
g.club_heap_bc.size() < runtime_dimensions.record_teams * 2 || g.club_heap_78.size() < runtime_dimensions.record_teams * 2 ||
|
||||
g.club_heap_b8.size() < runtime_dimensions.record_teams || g.position_history.size() < runtime_dimensions.league_teams * 0x1a ||
|
||||
(!g.club_table.empty() && g.club_table.size() < runtime_dimensions.record_teams * 0x4a) ||
|
||||
g.player_bonus.size() < g.players.size() || g.player_cards.size() < g.players.size() ||
|
||||
!exe.contains(::bmh::layout::Career_CareerAddManager_ExecutableField) || !exe.contains(::bmh::layout::Career_BuildStadium_RuntimeField3 + 0x15 * 5) ||
|
||||
!exe.contains(::bmh::layout::Career_BuildStadium_RuntimeField + 4 * 0x17 + 0x15)) {
|
||||
@@ -554,7 +554,7 @@ bool career_add_manager(GameState& g, const LeImage& exe, int m, const CareerMan
|
||||
new_board_entry(g, m, int(i), int(slot), rand);
|
||||
g.tactics.at(size_t(m) * 0x840 + i * 0x58 + 0xd) = 100;
|
||||
}
|
||||
for (size_t i = 0; i < 0x690; i++) g.manager_results.at(size_t(m) * 0x690 + i) = 0xff;
|
||||
for (size_t i = 0; i < (runtime_dimensions.record_teams * 10); i++) g.manager_results.at(size_t(m) * (runtime_dimensions.record_teams * 10) + i) = 0xff;
|
||||
const uint8_t level = mem.u8(::bmh::layout::Difficulty);
|
||||
const uint32_t money = level == 0 ? 50000000u : 4000000u - level * 200000u;
|
||||
put32(r, rec + 0x314, money);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <stdexcept>
|
||||
namespace bmh {
|
||||
ClubInfoEntry prepare_club_info_entry(GameState& g, int team) {
|
||||
if (team < 0 || (team >= 138 && team != kNoTeam))
|
||||
if (team < 0 || (team >= runtime_dimensions.league_teams && team != kNoTeam))
|
||||
throw std::invalid_argument("club info: team has no squad");
|
||||
const SquadRange range = squad_range(team);
|
||||
if (range.first > g.squad_slots.size() || range.count > g.squad_slots.size() - range.first)
|
||||
|
||||
@@ -31,9 +31,9 @@ int source_manager(const GameState& g, int club) {
|
||||
|
||||
int club_of_slot(int slot) {
|
||||
if (slot < 0) return -1;
|
||||
if (slot < 90 * 24) return slot / 24;
|
||||
if (slot < 90 * 24 + 48 * 16) return (slot - 90 * 8) / 16;
|
||||
if (slot >= 3072 && slot < 3096) return kNoTeam;
|
||||
if (slot < runtime_dimensions.big_squad_teams * 24) return slot / 24;
|
||||
if (slot < runtime_dimensions.pool_first) return (slot - runtime_dimensions.big_squad_teams * 8) / 16;
|
||||
if (slot >= runtime_dimensions.national_slots_first && slot < runtime_dimensions.extra_slots_first) return kNoTeam;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ ClubPlayerDetailContext club_player_detail_context(const GameState& g, const Clu
|
||||
out.primary_club = -1;
|
||||
} else {
|
||||
if (s.rendered_row < 0 || s.rendered_row >= 24 || s.runtime_team < 0 ||
|
||||
(s.runtime_team >= 138 && s.runtime_team != kNoTeam))
|
||||
(s.runtime_team >= runtime_dimensions.league_teams && s.runtime_team != kNoTeam))
|
||||
throw std::invalid_argument("player detail: invalid runtime club");
|
||||
const auto range = squad_range(s.runtime_team);
|
||||
if (range.first + range.count > g.squad_slots.size()) throw std::invalid_argument("player detail: truncated squad");
|
||||
|
||||
@@ -53,7 +53,7 @@ struct ClubPlayerDetailContext {
|
||||
|
||||
// OpenTransferEditor passes actual slots CareerRuntimeField + entry (0..39) for ordinary
|
||||
// transfer-market pool cards. It never turns the entry into a squad row.
|
||||
constexpr int kClubPlayerDetailMarketPoolFirst = 0xb70;
|
||||
inline const int& kClubPlayerDetailMarketPoolFirst = runtime_dimensions.pool_first;
|
||||
constexpr int kClubPlayerDetailMarketPoolCount = 40;
|
||||
|
||||
// Resolves runtime club, explicit row and Source loan/national ownership without
|
||||
|
||||
+1
-1
@@ -482,7 +482,7 @@ void order_national_cup_ties(GameState& g, int teams, int offset) {
|
||||
for (int i = 0; i < teams; i += 2) {
|
||||
if (lower <= team(i + 1) && team(i) < lower)
|
||||
swap16(mem, list + uint32_t(i) * 2, list + uint32_t(i + 1) * 2);
|
||||
auto league = [](int t) { return t > 0x164 ? 0 : team_league(t); };
|
||||
auto league = [](int t) { return t > (kNoTeam - 1) ? 0 : team_league(t); };
|
||||
const int la = league(team(i)), lb = league(team(i + 1));
|
||||
weights.push_back(uint8_t(kWeight[la < 10 ? la : 9] + kWeight[lb < 10 ? lb : 9]));
|
||||
}
|
||||
|
||||
+12
-12
@@ -69,7 +69,7 @@ FriendlyBookingQuote make_friendly_quote(const GameState& g, int manager, int op
|
||||
return out;
|
||||
}
|
||||
const int own_team = g.manager_teams[size_t(manager)];
|
||||
if (own_team < 0 || own_team >= 168 || opponent < 0 || opponent >= 168 || opponent == own_team) {
|
||||
if (own_team < 0 || own_team >= runtime_dimensions.record_teams || opponent < 0 || opponent >= runtime_dimensions.record_teams || opponent == own_team) {
|
||||
out.status = FriendlyQuoteStatus::invalid_opponent;
|
||||
return out;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ NationalFriendlyQuote make_national_friendly_quote(const GameState& g,
|
||||
return out;
|
||||
}
|
||||
// Page 4 cannot return Germany (0); the engine boundary repeats that gate.
|
||||
if (opponent <= kNoTeam || opponent > 0x1a2 || opponent == kNoTeam) {
|
||||
if (opponent <= kNoTeam || opponent > (kNoTeam + 61) || opponent == kNoTeam) {
|
||||
out.terms.status = FriendlyQuoteStatus::invalid_opponent;
|
||||
return out;
|
||||
}
|
||||
@@ -624,7 +624,7 @@ TransferActionResult submit_transfer_bid_impl(GameState& g, const TransferBidReq
|
||||
const bool source_direct_candidate = source_hooks && seller_manager < 0 &&
|
||||
fee_pct >= 110 && salary_pct >= g.memory.u8(entry + 0x55);
|
||||
if (source_direct_candidate) {
|
||||
if (request.list_entry >= 40 || seller < 0 || (seller >= 0x8a && seller != 0x0fff) || seller == buyer ||
|
||||
if (request.list_entry >= 40 || seller < 0 || (seller >= runtime_dimensions.league_teams && seller != 0x0fff) || seller == buyer ||
|
||||
request.manager < 0 || size_t(request.manager) >= g.manager_teams.size() ||
|
||||
!g.memory.has(::bmh::layout::ActiveManager) || g.memory.u8(::bmh::layout::ActiveManager) != request.manager ||
|
||||
source_hooks->direct_mode != HumanBuyerSaleDirectMode::ordinary_ai_purchase ||
|
||||
@@ -790,7 +790,7 @@ TransferActionResult submit_transfer_bid_source_impl(GameState& g, const Transfe
|
||||
// ordinary settlement already removes players using that actual range.
|
||||
// Higher club IDs have no ordinary squad; do not invent their settlement
|
||||
// or let ReleasePlayer reach its missing-player/internal-error21 boundary.
|
||||
if (seller != 0x0fff && seller >= 138) {
|
||||
if (seller != 0x0fff && seller >= runtime_dimensions.league_teams) {
|
||||
report.fail(kOrdinarySellerBoundary);
|
||||
out.status = TransferActionStatus::unsupported;
|
||||
out.player = player; out.list_entry = request.list_entry;
|
||||
@@ -1009,7 +1009,7 @@ TransferActionResult submit_transfer_bid_source_impl(GameState& g, const Transfe
|
||||
std::optional<TransferMarketSnapshotPreview> transfer_market_snapshot_preview(
|
||||
const GameState& g,int manager,int runtime_club,int index) {
|
||||
if(manager<0||manager>=4||size_t(manager)>=g.manager_teams.size()||
|
||||
g.manager_teams[size_t(manager)]!=runtime_club||runtime_club<0||runtime_club>=138||index<0||index>=12)
|
||||
g.manager_teams[size_t(manager)]!=runtime_club||runtime_club<0||runtime_club>=runtime_dimensions.league_teams||index<0||index>=12)
|
||||
return std::nullopt;
|
||||
const auto owner=squad_range(runtime_club);
|
||||
int count=0,ordinal=-1;
|
||||
@@ -1036,7 +1036,7 @@ std::optional<TransferMarketSnapshotPreview> transfer_market_snapshot_preview(
|
||||
// Require exactly one genuine ledger and its authenticated owner.
|
||||
if(borrower!=-1||int(loan>>12&0x3ff)!=runtime_club)return std::nullopt;
|
||||
borrower=int(loan>>22&0x3ff);
|
||||
if(borrower<0||borrower>=138||borrower==runtime_club)return std::nullopt;
|
||||
if(borrower<0||borrower>=runtime_dimensions.league_teams||borrower==runtime_club)return std::nullopt;
|
||||
}
|
||||
if(borrower<0)return std::nullopt;
|
||||
const auto range=squad_range(borrower);
|
||||
@@ -1072,9 +1072,9 @@ TransferMarketPreviewResult quote_transfer_market_preview_source(
|
||||
return unsupported("market preview: stale Source player/slot");
|
||||
if(request.purchase) {
|
||||
if(request.snapshot_index!=-1)return unsupported("market preview: snapshot is not a purchase row");
|
||||
if(request.source_slot<2928||request.source_slot>=2928+40)
|
||||
if(request.source_slot<runtime_dimensions.pool_first||request.source_slot>=runtime_dimensions.pool_first+40)
|
||||
return unsupported("market preview: purchase is not an ordinary market row");
|
||||
const uint32_t seller_at=::bmh::layout::EditorList+uint32_t(request.source_slot-2928)*0x58+8;
|
||||
const uint32_t seller_at=::bmh::layout::EditorList+uint32_t(request.source_slot-runtime_dimensions.pool_first)*0x58+8;
|
||||
if(!g.memory.has(seller_at)||!g.memory.has(seller_at+1))
|
||||
return unsupported("market preview: missing Source seller word");
|
||||
const uint16_t raw=g.memory.u16(seller_at);
|
||||
@@ -1091,7 +1091,7 @@ TransferMarketPreviewResult quote_transfer_market_preview_source(
|
||||
// with the unchanged42307 formula; do not synthesize a Native slot.
|
||||
} else {
|
||||
if(request.snapshot_index!=-1)return unsupported("market preview: invalid snapshot index");
|
||||
if(request.seller!=request.runtime_club||request.runtime_club>=138)
|
||||
if(request.seller!=request.runtime_club||request.runtime_club>=runtime_dimensions.league_teams)
|
||||
return unsupported("market preview: outgoing club is not an ordinary owned squad");
|
||||
const auto range=squad_range(request.runtime_club);
|
||||
if(range.count==0||range.first+range.count>g.squad_slots.size()||
|
||||
@@ -1133,7 +1133,7 @@ int editor_slot(const GameState& g,const TransferOfferEditorRequest& r) {
|
||||
std::string editor_identity(const GameState& g,const TransferOfferEditorRequest& r) {
|
||||
if(r.manager<0||r.manager>=4||size_t(r.manager)>=g.manager_teams.size()||
|
||||
!g.memory.has(::bmh::layout::ActiveManager)||g.memory.u8(::bmh::layout::ActiveManager)!=r.manager||
|
||||
g.manager_teams[size_t(r.manager)]!=r.runtime_club||r.runtime_club<0||r.runtime_club>=138)
|
||||
g.manager_teams[size_t(r.manager)]!=r.runtime_club||r.runtime_club<0||r.runtime_club>=runtime_dimensions.league_teams)
|
||||
return "OpenTransferEditor: stale ordinary manager/team";
|
||||
const size_t record=size_t(r.manager)*kRecordSize;
|
||||
if(record+kRecordSize>g.manager_records.size()||
|
||||
@@ -1143,7 +1143,7 @@ std::string editor_identity(const GameState& g,const TransferOfferEditorRequest&
|
||||
const bool ordinary_entry = r.list_entry >= 0 && r.list_entry < 40 && !r.poach && !r.loan_return_entry;
|
||||
const bool poach_entry = r.list_entry >= 40 && r.list_entry < 44 && r.poach && !r.loan_return_entry;
|
||||
const bool return_entry = r.list_entry >= 40 && r.list_entry < 44 && r.loan_return_entry && !r.poach;
|
||||
if((!ordinary_entry&&!poach_entry&&!return_entry)||r.source_slot!=2928+r.list_entry||
|
||||
if((!ordinary_entry&&!poach_entry&&!return_entry)||r.source_slot!=runtime_dimensions.pool_first+r.list_entry||
|
||||
size_t(r.source_slot)>=g.squad_slots.size()||r.expected_player<0||r.expected_player>=0x0fff||
|
||||
size_t(r.expected_player)>=g.players.size()||
|
||||
int(g.squad_slots[size_t(r.source_slot)]&0x0fff)!=r.expected_player)
|
||||
@@ -1159,7 +1159,7 @@ std::string editor_identity(const GameState& g,const TransferOfferEditorRequest&
|
||||
const int seller=int(r.expected_seller_word&0x7fff);
|
||||
if(r.expected_seller_word==0xffff||seller==r.runtime_club)
|
||||
return "OpenTransferEditor: targeted/invalid seller is outside ordinary editor";
|
||||
if(seller!=0x0fff&&seller>=138)return kOrdinarySellerBoundary;
|
||||
if(seller!=0x0fff&&seller>=runtime_dimensions.league_teams)return kOrdinarySellerBoundary;
|
||||
// OpenTransferEditor: the original refuses a loan from a free agent (seller 0x0fff) with the message
|
||||
// DeskActionsRuntimeField6 (SDLFlushEvents3) - a rule of the game, not a gap: the code names it
|
||||
if(r.loan&&r.expected_seller_word==0x0fff)return "free_agent_loan_refused";
|
||||
|
||||
@@ -38,6 +38,7 @@ void install_environment_rules(const LeImage& exe) {
|
||||
if (!exe.contains(at) || exe.u8(at)==0) { supported_environment=false; return; }
|
||||
kEnvironmentStep[i]=int32_t(exe.u8(at))*1000;
|
||||
}
|
||||
if(const auto* policy=exe.runtime_policy()) { supported_environment=policy->environment_verified!=0;return; }
|
||||
uint64_t fingerprint = 14695981039346656037ull;
|
||||
for (const auto [first,last] : {std::pair{layout::EnvironmentVerifiedCodeBegin,layout::EnvironmentVerifiedCodeEnd},std::pair{layout::EnvironmentVerifiedHookBegin,layout::EnvironmentVerifiedHookEnd}}) {
|
||||
if (!exe.contains(first) || !exe.contains(last-1)) { supported_environment=false; return; }
|
||||
|
||||
@@ -108,7 +108,7 @@ void validate(const GameState& g,const LeaguePairingsOwner& o) {
|
||||
require(o.supported&&!o.closed&&o.manager>=0&&o.manager<4&&
|
||||
size_t(o.manager)<g.manager_teams.size()&&g.memory.has(::bmh::layout::ActiveManager)&&
|
||||
g.memory.u8(::bmh::layout::ActiveManager)==o.manager&&g.manager_teams[size_t(o.manager)]==o.runtime_club&&
|
||||
(national||(o.runtime_club>=0&&o.runtime_club<138))&&
|
||||
(national||(o.runtime_club>=0&&o.runtime_club<runtime_dimensions.league_teams))&&
|
||||
size_t(o.runtime_club)<g.club_ids.size()&&
|
||||
g.club_ids[size_t(o.runtime_club)]==o.club_identity,
|
||||
"pairings: stale or unsupported manager identity");
|
||||
@@ -124,12 +124,12 @@ void validate(const GameState& g,const LeaguePairingsOwner& o) {
|
||||
(g.memory.u8(::bmh::layout::CareerSession_CloseLeagueFamily_ExecutableField+uint32_t(o.manager))&0x0f)==8)&&
|
||||
g.memory.has(::bmh::layout::LeagueTableDisplayModes+uint32_t(o.manager)*2+1),
|
||||
"pairings: missing preferences or unsupported saved list mode");
|
||||
require(g.results.size()>=kResultsSize&&g.club_ids.size()>=138&&g.league_rounds.size()>=9&&
|
||||
require(g.results.size()>=kResultsSize&&g.club_ids.size()>=runtime_dimensions.league_teams&&g.league_rounds.size()>=9&&
|
||||
g.memory.has(::bmh::layout::Postponed+0xef)&&g.memory.has(::bmh::layout::CompetitionCalendar+365*2+1),
|
||||
"pairings: incomplete Native schedule");
|
||||
const auto selection_valid=[&](int team,int identity) {
|
||||
return team<0 ? team>=-2&&identity==-1 :
|
||||
team<138&&team_league(team)==o.league&&g.club_ids.at(size_t(team))==identity;
|
||||
team<runtime_dimensions.league_teams&&team_league(team)==o.league&&g.club_ids.at(size_t(team))==identity;
|
||||
};
|
||||
require(selection_valid(o.search_first,o.search_first_identity)&&
|
||||
selection_valid(o.search_second,o.search_second_identity)&&
|
||||
@@ -181,7 +181,7 @@ void validate(const GameState& g,const LeaguePairingsOwner& o) {
|
||||
o.filter_offset>=0&&o.filter_offset%10==0&&o.filter_team>=-2,
|
||||
"pairings: invalid Source club-filter mode");
|
||||
if(o.filter_team>=0) {
|
||||
require(o.filter_team<138&&team_league(o.filter_team)==o.league&&
|
||||
require(o.filter_team<runtime_dimensions.league_teams&&team_league(o.filter_team)==o.league&&
|
||||
g.club_ids.at(size_t(o.filter_team))==o.filter_identity&&
|
||||
(o.filter_offset==0||o.filter_offset<filtered_fixture_count(o.league,o.filter_team)),
|
||||
"pairings: stale or out-of-range filtered club");
|
||||
@@ -315,7 +315,7 @@ LeaguePairingsOwner open_league_pairings_source(GameState& g,int manager,const L
|
||||
require(manager>=0&&manager<4&&size_t(manager)<g.manager_teams.size(),"pairings: unsupported manager");
|
||||
LeaguePairingsOwner out;out.manager=manager;out.runtime_club=g.manager_teams[size_t(manager)];
|
||||
const bool national=out.runtime_club==kNoTeam;
|
||||
require((national||(out.runtime_club>=0&&out.runtime_club<138))&&
|
||||
require((national||(out.runtime_club>=0&&out.runtime_club<runtime_dimensions.league_teams))&&
|
||||
size_t(out.runtime_club)<g.club_ids.size(),"pairings: unsupported or unowned manager");
|
||||
out.club_identity=g.club_ids[size_t(out.runtime_club)];
|
||||
// TeamLeague2 maps the Original national runtime team 0x165 to league 0.
|
||||
|
||||
+4
-4
@@ -37,7 +37,7 @@ uint8_t formation_byte(const GameState& g, size_t index) {
|
||||
}
|
||||
|
||||
bool pitch_context_valid(const GameState& g, int manager, int team) {
|
||||
if (manager < 0 || manager > 3 || team < 0 || team >= 138 || g.lineups_frozen ||
|
||||
if (manager < 0 || manager > 3 || team < 0 || team >= runtime_dimensions.league_teams || g.lineups_frozen ||
|
||||
!g.memory.has(::bmh::layout::ActiveManager) || !g.memory.has(::bmh::layout::GameMode) ||
|
||||
g.memory.u8(::bmh::layout::ActiveManager) != manager || g.memory.u8(::bmh::layout::GameMode) < 1 || g.memory.u8(::bmh::layout::GameMode) > 3 ||
|
||||
size_t(manager) >= g.manager_teams.size() || g.manager_teams[size_t(manager)] != team ||
|
||||
@@ -326,7 +326,7 @@ void install_lineup_rules(const LeImage& exe) {
|
||||
}
|
||||
|
||||
static void auto_lineup_impl(GameState& g, int team, int mode, int manager) {
|
||||
if (team >= 138 && team != kNoTeam) return; // teams without squads
|
||||
if (team >= runtime_dimensions.league_teams && team != kNoTeam) return; // teams without squads
|
||||
if (g.lineups_frozen) return; // LineupRuntimeField (the season change)
|
||||
const bool improve_from_reserves = (mode & 0x80) != 0;
|
||||
mode &= 0x7F;
|
||||
@@ -646,7 +646,7 @@ void auto_lineup(GameState& g, int team, int mode) {
|
||||
|
||||
void auto_lineup_parked_club_source(GameState& g, int team, int mode) {
|
||||
constexpr size_t record = 4*0xb0c+0x290;
|
||||
if (team<0 || team>=138 || g.manager_teams.size()!=1 || g.manager_teams[0]!=kNoTeam ||
|
||||
if (team<0 || team>=runtime_dimensions.league_teams || g.manager_teams.size()!=1 || g.manager_teams[0]!=kNoTeam ||
|
||||
!g.memory.has(::bmh::layout::CoachActive) || g.memory.u8(::bmh::layout::CoachActive)==0 ||
|
||||
!g.memory.has(::bmh::layout::ManagerCount) || g.memory.u8(::bmh::layout::ManagerCount)!=1 ||
|
||||
!g.memory.has(::bmh::layout::OriginalManagerCount) || g.memory.u8(::bmh::layout::OriginalManagerCount)<1 || g.memory.u8(::bmh::layout::OriginalManagerCount)>4 ||
|
||||
@@ -682,7 +682,7 @@ void quicksort_by_key(int16_t* items, uint32_t* keys, int count, bool ascending)
|
||||
}
|
||||
|
||||
bool substitute(GameState& g, int team, int off, int mode, WatcomRandom& rand) {
|
||||
if (!(team < 138 || team == kNoTeam)) return false;
|
||||
if (!(team < runtime_dimensions.league_teams || team == kNoTeam)) return false;
|
||||
const int manager = g.manager_of(team);
|
||||
int used = g.team_flags.at(team) >> 5 & 7; // substitutions so far
|
||||
if (mode == 10) {
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ void rate_side(GameState& g, const MatchSetup& m, int side, int previous6, Watco
|
||||
}
|
||||
}
|
||||
if (side == 0) {
|
||||
int league = team > 0x164 ? 0 : team_league(team); // TeamLeague2
|
||||
int league = team > (kNoTeam - 1) ? 0 : team_league(team); // TeamLeague2
|
||||
int base = kLeagueCrowd[league < 10 ? league : 9] * 1000;
|
||||
if (unsigned(rand.range(base + 3000, base + 6000)) < unsigned(m.spectators)) {
|
||||
// a human manager's side with record +0x289 set suffers more from a full house
|
||||
|
||||
@@ -78,7 +78,7 @@ MinuteReport MatchEngine::minute(int minute, int last_minute, int stoppage) {
|
||||
// Human teams use the places on their tactics board, also for the player's value.
|
||||
int MatchEngine::pick_player(int team, int mode, int exclude, MinuteReport& report, int preset) {
|
||||
mode &= 0x7F; // 0x80 = reuse the squad of the previous call, same team here
|
||||
if (team >= 138 && team != kNoTeam) return 0xFFF; // clubs without squad: nobody, no draws
|
||||
if (team >= runtime_dimensions.league_teams && team != kNoTeam) return 0xFFF; // clubs without squad: nobody, no draws
|
||||
SquadRange range = squad_range(team);
|
||||
if (range.count == 0) return 0xFFF;
|
||||
RatingContext ctx{state.chance_rain, state.chance_temperature};
|
||||
@@ -522,8 +522,8 @@ ForcedMatchEvent MatchEngine::event_impl(MatchGroup& g, int m, int s, int minute
|
||||
// Small-squad teams (id >= 90) only half of the time; teams without squads never. The
|
||||
// national team (0x165, squad nominated on the national team days) only while manager
|
||||
// slot 0 holds it (CupDraw_FormatError_RuntimeField2 == 0x165: a Bundestrainer's match).
|
||||
if (!(team < 90 || rand.range(0, 1) == 0)) return result;
|
||||
if (!(team < 138 || team == kNoTeam)) return result;
|
||||
if (!(team < runtime_dimensions.big_squad_teams || rand.range(0, 1) == 0)) return result;
|
||||
if (!(team < runtime_dimensions.league_teams || team == kNoTeam)) return result;
|
||||
if (team == kNoTeam && (state.manager_teams.empty() || state.manager_teams[0] != kNoTeam)) return result;
|
||||
const int manager = state.manager_of(team); // FindManagerForClub, local_6c
|
||||
const bool human = manager >= 0;
|
||||
@@ -944,7 +944,7 @@ void MatchEngine::side(MatchGroup& g, int m, int& s, int minute, int& own_att, i
|
||||
}
|
||||
|
||||
// Goalkeeper of the opponent: the player in squad slot 0 if the formation puts it in goal.
|
||||
if (!reality_played && (opp_team < 168 || opp_team == kNoTeam)) {
|
||||
if (!reality_played && (opp_team < runtime_dimensions.record_teams || opp_team == kNoTeam)) {
|
||||
int x = 0, y = 0;
|
||||
state.formation_position(opp_team, 0, x, y);
|
||||
if (x == 0 && y == 4) keeper = state.squad_slots.at(squad_range(opp_team).first) & 0x0FFF;
|
||||
@@ -979,7 +979,7 @@ void MatchEngine::side(MatchGroup& g, int m, int& s, int minute, int& own_att, i
|
||||
deflected = game.range(0, 5) == 0;
|
||||
}
|
||||
if (kind == 0) {
|
||||
if (team >= 168 && team != kNoTeam) {
|
||||
if (team >= runtime_dimensions.record_teams && team != kNoTeam) {
|
||||
// clubs without squad: the attack rating (TeamRating, profile 3), drawn
|
||||
RatingContext drawn;
|
||||
drawn.rand = &rand;
|
||||
@@ -989,7 +989,7 @@ void MatchEngine::side(MatchGroup& g, int m, int& s, int minute, int& own_att, i
|
||||
}
|
||||
}
|
||||
if (keeper == 0xFFF) {
|
||||
if (opp_team >= 168 && opp_team != kNoTeam) {
|
||||
if (opp_team >= runtime_dimensions.record_teams && opp_team != kNoTeam) {
|
||||
// clubs without squad: the goalkeeping rating (profile 0), drawn
|
||||
RatingContext drawn;
|
||||
drawn.rand = &rand;
|
||||
@@ -1196,7 +1196,7 @@ void MatchEngine::penalty_shootout(MatchGroup& g, int m, MinuteReport& report) {
|
||||
const int side = order[k];
|
||||
const int team = pair[side];
|
||||
int player = 0xFFF;
|
||||
if (team < 138 || team == kNoTeam) {
|
||||
if (team < runtime_dimensions.league_teams || team == kNoTeam) {
|
||||
// a player who has not taken a penalty yet (after 100 tries the list restarts)
|
||||
int tries = 0;
|
||||
bool fresh;
|
||||
|
||||
@@ -46,7 +46,7 @@ int competition_class(int type) { return type >= 0 && type < 24 ? kCompetitionCl
|
||||
|
||||
// TeamLeague2: league (0-8) of a club id, 9 for clubs outside the leagues.
|
||||
int league_of(int team) {
|
||||
if (team > 0x164) return 0;
|
||||
if (team > (kNoTeam - 1)) return 0;
|
||||
int end = 0;
|
||||
for (int l = 0; l < 9; l++) {
|
||||
end += kLeagueSizes[l];
|
||||
@@ -129,10 +129,10 @@ SportschauFixtureView sportschau_fixture_view(const GameState& state, const Matc
|
||||
if (team >= 0 && size_t(team) * 2 + 1 < state.club_heap_78.size())
|
||||
badge_word = uint16_t(state.club_heap_78[size_t(team) * 2] |
|
||||
uint16_t(state.club_heap_78[size_t(team) * 2 + 1]) << 8);
|
||||
if (team >= 0 && team < 0xa8) {
|
||||
if (team >= 0 && team < runtime_dimensions.record_teams) {
|
||||
requires_font_fit = true;
|
||||
if (state.memory.has(::bmh::layout::ClubShortNameOffsets + uint32_t(team))) {
|
||||
const uint8_t source = state.memory.u8(::bmh::layout::ClubShortNameOffsets + uint32_t(team));
|
||||
const uint8_t source = state.club_short_offset(team);
|
||||
const size_t offset = source >> 4;
|
||||
const size_t length = (source & 0x0f) + 1;
|
||||
if (offset <= full.size()) {
|
||||
@@ -302,7 +302,7 @@ void update_club_table(GameState& g, int home, int away, int hg, int ag) {
|
||||
auto add16 = [&](size_t o, int v) { wr16(g.club_table, o, uint16_t(rd16(g.club_table, o) + v)); };
|
||||
// Only the first league and the regional leagues keep points in this table (the
|
||||
// condition tests the home club only).
|
||||
const bool league = home < kLeagueSizes[0] || (home >= 90 && home < 138);
|
||||
const bool league = home < kLeagueSizes[0] || (home >= 90 && home < runtime_dimensions.league_teams);
|
||||
const int win_points = kThreePoints[league_of(home)] ? 3 : 2;
|
||||
if (league) {
|
||||
add16(H + 0x20, hg);
|
||||
@@ -404,7 +404,7 @@ void develop_players(GameState& g, const MatchGroup& grp, int m, GameRandom& gam
|
||||
const int type = grp.desc.at(0);
|
||||
for (int side = 0; side < 2; side++) {
|
||||
const int team = grp.fixtures.at(m * 2 + side);
|
||||
if (!(team < 168 || team == kNoTeam)) continue;
|
||||
if (!(team < runtime_dimensions.record_teams || team == kNoTeam)) continue;
|
||||
const uint8_t cls = (type == 0xb && team == kNoTeam) ? 3 : uint8_t(competition_class(type));
|
||||
const int manager = g.manager_of(team);
|
||||
const SquadRange range = squad_range(team);
|
||||
@@ -586,7 +586,7 @@ bool league_screen_shown(const std::vector<uint8_t>& buttons, int param_1, int p
|
||||
|
||||
|
||||
int table_position(const GameState& g, int team) {
|
||||
if (team >= 138) return 2;
|
||||
if (team >= runtime_dimensions.league_teams) return 2;
|
||||
int league = league_of(team);
|
||||
int rounds = league < int(g.league_rounds.size()) ? g.league_rounds[league] : 0;
|
||||
if (rounds == 0) return -1;
|
||||
@@ -667,8 +667,8 @@ void manager_match_record(GameState& g, const MatchGroup& grp, int m, int home_g
|
||||
rating = std::clamp(int16_t(rating), int16_t(0), int16_t(200));
|
||||
rate_manager(g, int(k), rating, 0);
|
||||
}
|
||||
if (opp < 0xa8) {
|
||||
size_t at = k * 0x690 + size_t(opp) * 10 + (side == 1 ? 5 : 0);
|
||||
if (opp < runtime_dimensions.record_teams) {
|
||||
size_t at = k * (runtime_dimensions.record_teams * 10) + size_t(opp) * 10 + (side == 1 ? 5 : 0);
|
||||
std::copy_backward(g.manager_results.begin() + at, g.manager_results.begin() + at + 4,
|
||||
g.manager_results.begin() + at + 5);
|
||||
g.manager_results.at(at) = uint8_t(own + (against << 4));
|
||||
@@ -717,6 +717,7 @@ void advance_league_rounds(GameState& g, uint32_t competitions, WatcomRandom& ra
|
||||
const int end = bit < 4 ? bit + 1 : 8;
|
||||
for (int c = bit; c < end; c++) {
|
||||
for (int league = kFirst[c]; league < kFirst[c] + kCount[c]; league++) {
|
||||
if (runtime_dimensions.expanded && g.league_rounds.at(size_t(league)) >= 2 * (kLeagueSizes[league] - 1)) continue;
|
||||
if (league == 0) {
|
||||
for (size_t m = 0; m < g.manager_teams.size(); m++) {
|
||||
advance_youth_teams(g, int(m), rand);
|
||||
|
||||
@@ -35,9 +35,9 @@ constexpr uint8_t kCompetitionClass[24] = {0, 1, 2, 2, 2, 3, 3, 3, 3, 255, 0, 25
|
||||
// Crowd interest per descriptor type (MatchdaySetupRuntimeField).
|
||||
constexpr uint8_t kTypeInterest[24] = {5, 5, 10, 15, 12, 10, 5, 10, 5, 10, 5, 31, 10, 10, 10, 0, 0, 1, 0, 0, 0, 12, 0, 0};
|
||||
// Number of clubs taking part in league play (CareerSession_DispatchLineup_RuntimeField).
|
||||
constexpr int kLeagueClubCount = 0x8a;
|
||||
const int& kLeagueClubCount = runtime_dimensions.league_teams;
|
||||
// Squad slots checked by the driver (CareerRuntimeField).
|
||||
constexpr size_t kSquadSlotCount = 0xb70;
|
||||
const int& kSquadSlotCount = runtime_dimensions.pool_first;
|
||||
|
||||
// The attendance tables MatchdaySetup_Attendance_ExecutableField .. MatchdaySetupRuntimeField2 as one block, because the original
|
||||
// indexes them with league classes 0-7 although they only have four entries: classes 4-7
|
||||
@@ -76,7 +76,7 @@ void wr16(Bytes& b, size_t o, uint16_t v) { b.at(o) = uint8_t(v), b.at(o + 1) =
|
||||
|
||||
// TeamLeague2: league of a club, 0 for the special ids above 0x164, 9 outside the leagues.
|
||||
int league_of(int team) {
|
||||
if (team > 0x164) return 0;
|
||||
if (team > (kNoTeam - 1)) return 0;
|
||||
return team_league(team);
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ void indoor_tournament_draw(GameState& g, GameRandom& game, WatcomRandom& rand)
|
||||
indoor_tournament_reset(g);
|
||||
uint8_t attempts = 0;
|
||||
const int guest = rand.range(0, 1);
|
||||
if (guest != 0) mem.set16(kTeams, uint16_t(rand.range(90, 137)));
|
||||
if (guest != 0) mem.set16(kTeams, uint16_t(rand.range(runtime_dimensions.domestic_teams, runtime_dimensions.league_teams - 1)));
|
||||
int count = guest != 0;
|
||||
int n = rand.range(5, 7);
|
||||
uint8_t lo = 0, hi = uint8_t(kLeagueSizes[0]);
|
||||
@@ -431,7 +431,7 @@ void indoor_tournament_draw(GameState& g, GameRandom& game, WatcomRandom& rand)
|
||||
int sum = 0; // IndoorTournamentReset
|
||||
for (uint32_t k = 0; k < 8; k++) {
|
||||
const int t = mem.u16(kTeams + k * 2);
|
||||
const int league = t > 0x164 ? 0 : team_league(t); // TeamLeague2
|
||||
const int league = t > (kNoTeam - 1) ? 0 : team_league(t); // TeamLeague2
|
||||
if (league < 2) sum += (0x26 - table_position(g, t)) - kLeagueSizes[0] * league;
|
||||
else if (league < 5) sum += 1;
|
||||
else sum += 0x19;
|
||||
@@ -563,6 +563,7 @@ std::vector<MatchGroup> setup_matchday(GameState& g, uint32_t competitions, cons
|
||||
for (int k = from; k < to; k++) {
|
||||
// FixturesFromGenerateFixtures(k)
|
||||
for (int league = kGroupLeague[k]; league < kGroupLeague[k] + kGroupLeagues[k]; league++) {
|
||||
if (runtime_dimensions.expanded && g.league_rounds.at(size_t(league)) >= 2 * (kLeagueSizes[league] - 1)) continue;
|
||||
turn_step = "setup: winter postponements";
|
||||
winter_postponements(g, ctx.season_day, league, game, rand);
|
||||
const int round = g.league_rounds.at(size_t(league));
|
||||
@@ -886,7 +887,7 @@ bool select_live_match(GameState& g, int home, int away) {
|
||||
// record +0x8ac / 16 + 40.
|
||||
void man_marking(GameState& g, int own_manager, int own, int other_manager, int other, int chance, int rate,
|
||||
WatcomRandom& rand) {
|
||||
constexpr int kLeagueTeams = 138; // CareerSession_DispatchLineup_RuntimeField
|
||||
const int kLeagueTeams = runtime_dimensions.league_teams; // CareerSession_DispatchLineup_RuntimeField
|
||||
if (g.indoor || own >= kLeagueTeams || other >= kLeagueTeams || (own_manager < 0 && other_manager < 0)) return;
|
||||
if (other_manager >= 0)
|
||||
for (size_t s = 0; s < 24; s++) {
|
||||
|
||||
+10
-1
@@ -20,6 +20,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "formats/savestate.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
|
||||
namespace bmh {
|
||||
|
||||
@@ -34,7 +35,15 @@ public:
|
||||
explicit StaticMemory(const SaveState& save) {
|
||||
for (const SaveBlock& b : save.blocks())
|
||||
if (!b.heap && b.size != 0 && !blocks_.count(b.address))
|
||||
blocks_[b.address].assign(save.stream().begin() + b.offset, save.stream().begin() + b.offset + b.size);
|
||||
{
|
||||
// Expanded tails live in typed GameState vectors. Keep guest
|
||||
// memory at Original extents to avoid aliasing adjacent globals.
|
||||
size_t size = b.size;
|
||||
if (b.address == layout::ClubKitSelectors) size = std::min(size, size_t(419));
|
||||
if (b.address == layout::ClubShortNameOffsets) size = std::min(size, size_t(168));
|
||||
if (b.address == layout::ManagerMatchHistory) size = std::min(size, size_t(8400));
|
||||
blocks_[b.address].assign(save.stream().begin() + b.offset, save.stream().begin() + b.offset + size);
|
||||
}
|
||||
}
|
||||
|
||||
// A global the savegame does not store (e.g. a work list the original rebuilds before
|
||||
|
||||
+11
-11
@@ -30,12 +30,12 @@ constexpr size_t kBoard = 0x840; // tactics board of a manager
|
||||
constexpr size_t kBoardSlot = 0x58;
|
||||
constexpr uint32_t kTransferList = ::bmh::layout::EditorList;
|
||||
constexpr uint32_t kListEntry = 0x58;
|
||||
constexpr int kPoolFirst = 0xb70; // CareerRuntimeField: the transfer list (40 slots + 4)
|
||||
constexpr int kFreeAgents = 0xb9c; // CareerRuntimeField2: free agents (80 slots)
|
||||
constexpr int kForeignAgents = 0xbec; // MonthRuntimeField: foreign free agents (20 slots)
|
||||
constexpr int kPoolEnd = 0xc00; // LargeSquadClubCount
|
||||
constexpr int kBigSquadClubs = 90; // TeamsWithSquads
|
||||
constexpr int kLeagueClubs = 0x8a; // CareerSession_DispatchLineup_RuntimeField
|
||||
const int& kPoolFirst = runtime_dimensions.pool_first; // CareerRuntimeField: the transfer list (40 slots + 4)
|
||||
const int& kFreeAgents = runtime_dimensions.free_first; // CareerRuntimeField2: free agents (80 slots)
|
||||
const int& kForeignAgents = runtime_dimensions.foreign_free_first; // MonthRuntimeField: foreign free agents (20 slots)
|
||||
const int& kPoolEnd = runtime_dimensions.national_slots_first; // LargeSquadClubCount
|
||||
const int& kBigSquadClubs = runtime_dimensions.big_squad_teams; // TeamsWithSquads
|
||||
const int& kLeagueClubs = runtime_dimensions.league_teams; // CareerSession_DispatchLineup_RuntimeField
|
||||
|
||||
// MonthRuntimeField2: development steps by strength / 10; the ten bytes after it (PlayerCard_PlayerCardMarketValue_RuntimeField)
|
||||
// are the extra value above 500 points.
|
||||
@@ -162,8 +162,8 @@ bool in_pseudo_squad(const GameState& g, int slot) {
|
||||
void list_club_player(GameState& g, int first, int last, WatcomRandom& rand, MinuteReport& report) {
|
||||
const int8_t* wanted = first < kBigSquadClubs ? kWantedBig : kWantedSmall; // Attempt
|
||||
for (;;) {
|
||||
int16_t teams[138];
|
||||
uint32_t keys[138];
|
||||
std::vector<int16_t> teams(size_t(kLeagueClubs), 0);
|
||||
std::vector<uint32_t> keys(size_t(kLeagueClubs), 0);
|
||||
int n = 0; // local_14
|
||||
g.list_toggle = g.list_toggle + 1 == 2 ? 0 : g.list_toggle + 1;
|
||||
int best_line = 0; // local_1c, keeps its value between the clubs
|
||||
@@ -207,10 +207,10 @@ void list_club_player(GameState& g, int first, int last, WatcomRandom& rand, Min
|
||||
n++;
|
||||
}
|
||||
}
|
||||
int pick = 0x8a; // sVar11
|
||||
int pick = runtime_dimensions.league_teams; // sVar11
|
||||
int slot = -1; // unaff_EDI: the slot tried last
|
||||
if (n != 0) {
|
||||
quicksort_by_key(teams, keys, n);
|
||||
quicksort_by_key(teams.data(), keys.data(), n);
|
||||
for (pick = 0; pick < n; pick++) {
|
||||
const int team = teams[pick];
|
||||
const SquadRange range = squad_range(team);
|
||||
@@ -229,7 +229,7 @@ void list_club_player(GameState& g, int first, int last, WatcomRandom& rand, Min
|
||||
}
|
||||
// (when no club had a fitting player the slot tried last is listed all the same)
|
||||
}
|
||||
if (pick < 0x8a) {
|
||||
if (pick < runtime_dimensions.league_teams) {
|
||||
list_player(g, slot, rand, report);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ constexpr size_t kBoard = 0x840; // one manager's tactics board (24 x 0
|
||||
constexpr size_t kBoardSlot = 0x58;
|
||||
constexpr uint32_t kDesktops = ::bmh::layout::Desktops; // desktop layouts, 0x360 per manager slot
|
||||
constexpr size_t kDesktop = 0x360;
|
||||
constexpr size_t kPoolSlots = 0xb70; // CareerRuntimeField: the clubs' squads end here
|
||||
const int& kPoolSlots = runtime_dimensions.pool_first; // CareerRuntimeField: the clubs' squads end here
|
||||
constexpr uint8_t kNominated[4] = {3, 5, 7, 5}; // NationalRuntimeField: keepers, defence, midfield, attack
|
||||
|
||||
// the manager's team (record +0x290) as the port caches it
|
||||
|
||||
@@ -156,13 +156,13 @@ OtherGamesClubMetadata source_metadata(const GameState& game, int team) {
|
||||
uint16_t(game.manager_records[kNationalOriginalClub + 1]) << 8));
|
||||
manager_owned = original_club == team;
|
||||
}
|
||||
if (team >= 168 && !manager_owned) {
|
||||
const size_t at = size_t(team - 168);
|
||||
if (team >= runtime_dimensions.record_teams && !manager_owned) {
|
||||
const size_t at = size_t(team - runtime_dimensions.record_teams);
|
||||
if (at >= game.foreign_strength.size()) invalid("missing Source foreign-strength byte");
|
||||
out.foreign_strength = game.foreign_strength[at];
|
||||
return out;
|
||||
}
|
||||
if (team >= 168 && team != kNoTeam)
|
||||
if (team >= runtime_dimensions.record_teams && team != kNoTeam)
|
||||
invalid("manager-controlled foreign-club row needs live TeamRating W-generator context");
|
||||
constexpr std::array<uint16_t, 5> kFlags{0x0f1, 0x0f2, 0x0f4, 0x0f8, 0x0ff};
|
||||
for (size_t i = 0; i < kFlags.size(); ++i)
|
||||
|
||||
+2
-2
@@ -16,9 +16,9 @@ constexpr size_t kRecordSize = 0xb0c;
|
||||
constexpr size_t kAttempts = 0x8b6; // five player ids, 0xffff free
|
||||
constexpr uint32_t kTransferList = ::bmh::layout::EditorList; // 44 rows of 0x58 bytes
|
||||
constexpr uint32_t kListRow = 0x58;
|
||||
constexpr size_t kPoolFirst = 0xb70; // CareerRuntimeField: squad slot of list row 0
|
||||
const int& kPoolFirst = runtime_dimensions.pool_first; // CareerRuntimeField: squad slot of list row 0
|
||||
constexpr uint32_t kOfferSlots = ::bmh::layout::OfferSlots; // OfferSlots: 4 words, -1 free
|
||||
constexpr int kBigSquadClubs = 90; // TeamsWithSquads
|
||||
const int& kBigSquadClubs = runtime_dimensions.big_squad_teams; // TeamsWithSquads
|
||||
// Attempt: how many players of each position a club wants (MonthRuntimeField4 / MonthRuntimeField5)
|
||||
constexpr int8_t kWantedBig[4] = {2, 6, 7, 5}, kWantedSmall[4] = {2, 4, 5, 4};
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ constexpr size_t kBoardSlot = 0x58; // one slot of the board
|
||||
// Static league tables of V2.24 (not part of the savegame):
|
||||
// (European places per league, CareerSession_InstallLeagueSizes_RuntimeField, are kLeagueEurope of the loaded game; league 0 uses 4)
|
||||
// (the relegation places per league, CareerSession_InstallLeagueSizes_RuntimeField2, are kLeagueRelegation of the loaded game)
|
||||
constexpr int kLeagueTeams = 138; // CareerSession_DispatchLineup_RuntimeField: clubs in the league system
|
||||
const int& kLeagueTeams = runtime_dimensions.league_teams; // CareerSession_DispatchLineup_RuntimeField: clubs in the league system
|
||||
|
||||
// Text of a pointer variable of the text table TextPointerTable.
|
||||
} // namespace
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/profile_runtime.hpp"
|
||||
#include "formats/data_profile.hpp"
|
||||
namespace bmh {
|
||||
void install_runtime_profile(const DataProfile& profile) {
|
||||
profile.validate();
|
||||
RuntimeDimensions next;
|
||||
next.league_teams=int(profile.counts.league_teams);
|
||||
next.cup_teams=int(profile.counts.cup_teams);
|
||||
next.big_squad_teams=int(profile.big_squad_teams);
|
||||
next.record_teams=int(profile.counts.n42);
|
||||
next.national_first=int(profile.national_first);
|
||||
next.pool_first=int(profile.pool_first());
|
||||
next.market_special_first=next.pool_first+40;
|
||||
next.free_first=next.pool_first+44;
|
||||
next.foreign_free_first=next.pool_first+124;
|
||||
next.national_slots_first=int(profile.national_slots_first());
|
||||
next.extra_slots_first=int(profile.extra_slots_first());
|
||||
next.total_slots=int(profile.total_slots());
|
||||
next.expanded=profile.extended();
|
||||
runtime_dimensions=next;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
namespace bmh {
|
||||
struct DataProfile;
|
||||
// Explicitly distinct concepts: German clubs, league clubs and large rosters.
|
||||
// One installation is active per process, like the existing fixture/rule tables.
|
||||
struct RuntimeDimensions {
|
||||
int domestic_teams=90, league_teams=138, cup_teams=30, big_squad_teams=90;
|
||||
int record_teams=168;
|
||||
int national_first=357, pool_first=2928, market_special_first=2968;
|
||||
int free_first=2972, foreign_free_first=3052, national_slots_first=3072;
|
||||
int extra_slots_first=3096, total_slots=3150;
|
||||
bool expanded=false;
|
||||
};
|
||||
inline RuntimeDimensions runtime_dimensions{};
|
||||
void install_runtime_profile(const DataProfile& profile);
|
||||
}
|
||||
+2
-2
@@ -121,7 +121,7 @@ int human_correction(GameState& g, RatingContext& ctx, int manager, int rank, in
|
||||
} // namespace
|
||||
|
||||
int team_rating(GameState& g, int team, const RatingProfile& profile, RatingContext& ctx, int* keeper) {
|
||||
if (team >= 168 && team != kNoTeam) {
|
||||
if (team >= runtime_dimensions.record_teams && team != kNoTeam) {
|
||||
// Clubs without squad: per group a random value around the level of the club
|
||||
// (ForeignClubStrength bits 5-7 -> RatingRuntimeField2), +2 if the group's strength bit is set
|
||||
// (bit 3, 3, 2, 1 for goal, defence, midfield, attack: RatingRuntimeField3) and a style
|
||||
@@ -130,7 +130,7 @@ int team_rating(GameState& g, int team, const RatingProfile& profile, RatingCont
|
||||
static const uint8_t kStrongBit[4] = {3, 3, 2, 1};
|
||||
static const int8_t kStyle[8] = {0, 6, 0, -6, 0, -6, 0, 6};
|
||||
if (!ctx.rand) throw std::invalid_argument("team_rating: a team without squad needs the Watcom generator");
|
||||
const uint8_t s = g.foreign_strength.at(size_t(team - 168));
|
||||
const uint8_t s = g.foreign_strength.at(size_t(team - runtime_dimensions.record_teams));
|
||||
int16_t total = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const int level = kLevel[s >> 5];
|
||||
|
||||
+9
-3
@@ -59,7 +59,7 @@ Bytes save_stream(const GameState& live) {
|
||||
const GameState& g = coach ? swapped : live;
|
||||
const bool records = g.memory.has(::bmh::layout::ClubSeasonRecords) && g.memory.u32(::bmh::layout::ClubSeasonRecords) != 0;
|
||||
Bytes stream;
|
||||
for (const SaveBlock& b : save_layout(DbCounts{}, records)) {
|
||||
for (const SaveBlock& b : save_layout(g.counts, records)) {
|
||||
Bytes d(b.size, 0);
|
||||
if (b.heap) {
|
||||
switch (b.address) {
|
||||
@@ -94,6 +94,12 @@ Bytes save_stream(const GameState& live) {
|
||||
// the blocks GameState keeps in typed fields
|
||||
switch (b.address) {
|
||||
case ::bmh::layout::ManagerRecords: put(d, g.manager_records); break;
|
||||
case ::bmh::layout::ClubKitSelectors:
|
||||
if (g.counts.league_teams == 164) put(d, g.club_kits);
|
||||
break;
|
||||
case ::bmh::layout::ClubShortNameOffsets:
|
||||
if (g.counts.league_teams == 164) put(d, g.club_short_offsets);
|
||||
break;
|
||||
case ::bmh::layout::ManagerMatchHistory: put(d, g.manager_results); break;
|
||||
case ::bmh::layout::ManagerRatings: put(d, g.manager_ratings); break;
|
||||
case ::bmh::layout::LeagueResults: put(d, g.results); break;
|
||||
@@ -140,7 +146,7 @@ Bytes save_header(const GameState& g) {
|
||||
for (int m = 0; m < managers && m < 4; m++) {
|
||||
const size_t rec = size_t(m) * 0xb0c;
|
||||
const int team = int16_t(g.manager_records.at(rec + 0x290) | g.manager_records.at(rec + 0x291) << 8);
|
||||
const bool national = team == 0x165;
|
||||
const bool national = team == kNoTeam;
|
||||
const size_t at = size_t(m) * 0x28;
|
||||
list[at] = national ? 0x1e : g.manager_records.at(rec + 0x210); // (0x1e: high byte of the loop word)
|
||||
list[at + 1] = national ? 1 : 0;
|
||||
@@ -156,7 +162,7 @@ Savegame make_savegame(const GameState& g, WatcomRandom& rand) {
|
||||
Savegame s;
|
||||
s.plain_header = save_header(g);
|
||||
s.id1 = 0;
|
||||
s.version = "V2.24";
|
||||
s.version = g.counts.league_teams == 164 ? "O1.1" : "V2.24";
|
||||
const uint32_t hi = uint32_t(rand.range(0, 0x8fff)), lo = uint32_t(rand.range(0, 0x8fff));
|
||||
s.id2 = lo + hi * 0x10000 + 1;
|
||||
s.key = uint8_t(rand.range(0, 0xff) + 'n');
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/schedule.hpp"
|
||||
#include "game/profile_runtime.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "formats/le.hpp"
|
||||
|
||||
@@ -123,16 +124,16 @@ std::vector<Fixture> generate_fixtures(int teams, int matchday, int rounds, int
|
||||
return out;
|
||||
}
|
||||
|
||||
int league_table_teams(int league) { return league < 5 ? kLeagueSizes[0] : kLeagueSizes[5]; }
|
||||
int league_table_teams(int league) { return runtime_dimensions.expanded ? kLeagueSizes[league] : (league < 5 ? kLeagueSizes[0] : kLeagueSizes[5]); }
|
||||
|
||||
void set_league_sizes(const uint8_t (&sizes)[kLeagueCount]) {
|
||||
int total = 0;
|
||||
for (int l = 0; l < kLeagueCount; l++) total += sizes[l];
|
||||
const auto has_table = [](int teams) { return teams == 20 || teams == 18 || teams == 16 || teams == 12; };
|
||||
if (total != 138 || !has_table(sizes[0]) || !has_table(sizes[5]))
|
||||
throw std::invalid_argument("league sizes do not describe 138 league teams with fixture tables");
|
||||
if (total != runtime_dimensions.league_teams || !has_table(sizes[0]) || !has_table(sizes[5]))
|
||||
throw std::invalid_argument("league sizes do not match the installed profile and fixture tables");
|
||||
for (int l = 0; l < kLeagueCount; l++)
|
||||
if (sizes[l] < 2 || sizes[l] > (l < 5 ? sizes[0] : sizes[5]))
|
||||
if (sizes[l] < 2 || (!runtime_dimensions.expanded && sizes[l] > (l < 5 ? sizes[0] : sizes[5])) || (runtime_dimensions.expanded && !has_table(sizes[l])))
|
||||
throw std::invalid_argument("a league is larger than its fixture table");
|
||||
for (int l = 0; l < kLeagueCount; l++) kLeagueSizes[l] = sizes[l];
|
||||
}
|
||||
|
||||
+34
-27
@@ -28,7 +28,7 @@ namespace {
|
||||
|
||||
constexpr uint32_t kTransferList = ::bmh::layout::EditorList; // 44 entries of 0x58 bytes
|
||||
constexpr uint32_t kListEntry = 0x58;
|
||||
constexpr size_t kPoolSlots = 0xb70; // CareerRuntimeField
|
||||
const int& kPoolSlots = runtime_dimensions.pool_first; // CareerRuntimeField
|
||||
constexpr uint32_t kOffers = ::bmh::layout::OfferSlots; // OfferSlots: 4 offers, -1 = free
|
||||
constexpr size_t kBoard = 0x840; // tactics board of a manager
|
||||
constexpr size_t kBoardSlot = 0x58;
|
||||
@@ -173,7 +173,7 @@ void club_balance(GameState& g, int team, WatcomRandom& rand) {
|
||||
namespace {
|
||||
|
||||
// TeamLeague2: the league of a club; ids above 0x164 (national teams) count as league 0
|
||||
int club_league(int team) { return team > 0x164 ? 0 : team_league(team); }
|
||||
int club_league(int team) { return team > (kNoTeam - 1) ? 0 : team_league(team); }
|
||||
|
||||
// The European entrants (Career_CompetitionPointersEnglish_ExecutableField25 UEFA Cup, Career_CompetitionPointersEnglish_RuntimeField14 Champions League,
|
||||
// Career_CompetitionPointersEnglish_ExecutableField19 Cup Winners' Cup) and their counts (Career_EuropeanClub_ExecutableField / Career_EuropeanClub_ExecutableField2 / Career_EuropeanClub_ExecutableField3).
|
||||
@@ -279,9 +279,9 @@ void observe_initial_international_groups(GameState& g, WatcomRandom& rand, int
|
||||
for(int position:{fixture.home,fixture.away}) {
|
||||
const int team=mem.u16(teams+uint32_t(position)*2);
|
||||
const bool manager_national=mem.has(::bmh::layout::CupDraw_FormatError_RuntimeField2)&&mem.has(::bmh::layout::CupDraw_FormatError_RuntimeField3)&&
|
||||
mem.u16(::bmh::layout::CupDraw_FormatError_RuntimeField2)==0x165&&mem.u16(::bmh::layout::CupDraw_FormatError_RuntimeField3)==team;
|
||||
mem.u16(::bmh::layout::CupDraw_FormatError_RuntimeField2)==kNoTeam&&mem.u16(::bmh::layout::CupDraw_FormatError_RuntimeField3)==team;
|
||||
const bool human_owned=g.manager_of(team)>=0||manager_national;
|
||||
if(team<168||team==kNoTeam||!human_owned)continue;
|
||||
if(team<runtime_dimensions.record_teams||team==kNoTeam||!human_owned)continue;
|
||||
SeasonCupDrawEvent::GroupAverageSnapshot snapshot;
|
||||
snapshot.runtime_id=uint16_t(team);
|
||||
snapshot.values={team_average(g,team,0x0f1,&rand).value,
|
||||
@@ -320,7 +320,7 @@ void european_setup(GameState& g, GameRandom& game, WatcomRandom& rand, const Se
|
||||
constexpr uint32_t kField0 = ::bmh::layout::Field0;
|
||||
if (!mem.has(kField0)) mem.add_block(kField0, 0x30);
|
||||
const int s = g.season % 4;
|
||||
const int base = 0xbd + 0x8a + 0x1e; // ClubPlayerDetail_ClubPlayerDetailFromGame_RuntimeField3 + CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6
|
||||
const int base = 0xbd + runtime_dimensions.league_teams + 0x1e; // ClubPlayerDetail_ClubPlayerDetailFromGame_RuntimeField3 + CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6
|
||||
int n = 1;
|
||||
std::vector<uint16_t> last;
|
||||
if (s % 2 == 0) {
|
||||
@@ -390,7 +390,7 @@ void european_setup(GameState& g, GameRandom& game, WatcomRandom& rand, const Se
|
||||
void european_fields(GameState& g, GameRandom& game, WatcomRandom& rand) {
|
||||
StaticMemory& mem = g.memory;
|
||||
Entrants en{mem};
|
||||
const int pool = 0x8a + 0x1e; // CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6: the first foreign club
|
||||
const int pool = runtime_dimensions.league_teams + 0x1e; // CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6: the first foreign club
|
||||
auto pick = [&](int from) {
|
||||
int t;
|
||||
do t = rand.range(from, from + 6); while (en.find(t) != 0);
|
||||
@@ -759,7 +759,7 @@ void season_accounts(GameState& g, int m, GameRandom& game, WatcomRandom& rand,
|
||||
// swaps twice for them (no change), once otherwise.
|
||||
void change_places(GameState& g, int a, int b) {
|
||||
StaticMemory& mem = g.memory;
|
||||
if (a >= 0x8a + 0x1e || b >= 0x8a + 0x1e) return;
|
||||
if (a >= runtime_dimensions.league_teams + 0x1e || b >= runtime_dimensions.league_teams + 0x1e) return;
|
||||
auto swap_bytes = [](std::vector<uint8_t>& v, size_t x, size_t y, size_t n) {
|
||||
for (size_t i = 0; i < n; i++)
|
||||
if (x + i < v.size() && y + i < v.size()) std::swap(v[x + i], v[y + i]);
|
||||
@@ -776,7 +776,7 @@ void change_places(GameState& g, int a, int b) {
|
||||
else if (v == uint16_t(b)) mem.set16(at + uint32_t(i) * 2, uint16_t(a));
|
||||
}
|
||||
};
|
||||
const bool league_clubs = a < 0x8a && b < 0x8a;
|
||||
const bool league_clubs = a < runtime_dimensions.league_teams && b < runtime_dimensions.league_teams;
|
||||
if (league_clubs)
|
||||
for (uint32_t k = 0; k < 200; k++) { // loans: seller and buyer
|
||||
const uint32_t e = mem.u32(::bmh::layout::Career_RemoveJoinLoans_RuntimeField + k * 4);
|
||||
@@ -786,21 +786,28 @@ void change_places(GameState& g, int a, int b) {
|
||||
buyer = buyer == a ? b : buyer == b ? a : buyer;
|
||||
mem.set32(::bmh::layout::Career_RemoveJoinLoans_RuntimeField + k * 4, (e & 0xfff) | uint32_t(seller) << 12 | uint32_t(buyer) << 22);
|
||||
}
|
||||
if (!g.club_table.empty() && a < 0xa8 && b < 0xa8) swap_bytes(g.club_table, size_t(a) * 0x4a, size_t(b) * 0x4a, 0x4a);
|
||||
if (!g.club_table.empty() && a < runtime_dimensions.record_teams && b < runtime_dimensions.record_teams) swap_bytes(g.club_table, size_t(a) * 0x4a, size_t(b) * 0x4a, 0x4a);
|
||||
std::swap(g.club_ids.at(size_t(a)), g.club_ids.at(size_t(b)));
|
||||
swap_bytes(g.club_heap_bc, size_t(a) * 2, size_t(b) * 2, 2);
|
||||
std::swap(g.team_morale.at(size_t(a)), g.team_morale.at(size_t(b)));
|
||||
swap_mem8(::bmh::layout::ClubShortNameOffsets);
|
||||
swap_mem8(::bmh::layout::ClubKitSelectors);
|
||||
if (runtime_dimensions.expanded) {
|
||||
std::swap(g.club_short_offsets.at(size_t(a)), g.club_short_offsets.at(size_t(b)));
|
||||
std::swap(g.club_kits.at(size_t(a)), g.club_kits.at(size_t(b)));
|
||||
} else {
|
||||
swap_mem8(::bmh::layout::ClubShortNameOffsets);
|
||||
swap_mem8(::bmh::layout::ClubKitSelectors);
|
||||
}
|
||||
swap_bytes(g.club_heap_78, size_t(a) * 2, size_t(b) * 2, 2);
|
||||
std::swap(g.team_flags.at(size_t(a)), g.team_flags.at(size_t(b)));
|
||||
if (league_clubs) {
|
||||
swap_bytes(g.club_heap_b8, size_t(a) * 2, size_t(b) * 2, 2);
|
||||
if (runtime_dimensions.expanded) std::swap(g.club_heap_b8.at(size_t(a)), g.club_heap_b8.at(size_t(b)));
|
||||
else swap_bytes(g.club_heap_b8, size_t(a) * 2, size_t(b) * 2, 2);
|
||||
swap_bytes(g.position_history, size_t(a) * 0x1a, size_t(b) * 0x1a, 0x1a);
|
||||
const SquadRange ra = squad_range(a), rb = squad_range(b);
|
||||
for (size_t i = 0; i < ra.count; i++) std::swap(g.squad_slots.at(ra.first + i), g.squad_slots.at(rb.first + i));
|
||||
}
|
||||
swap_bytes(g.club_heap_b8, size_t(a) * 2, size_t(b) * 2, 2);
|
||||
if (runtime_dimensions.expanded) std::swap(g.club_heap_b8.at(size_t(a)), g.club_heap_b8.at(size_t(b)));
|
||||
else swap_bytes(g.club_heap_b8, size_t(a) * 2, size_t(b) * 2, 2);
|
||||
replace(::bmh::layout::Titles, 0x1c2); // title holders
|
||||
replace(::bmh::layout::Career_CompetitionPointersEnglish_ExecutableField28, 2);
|
||||
if (!mem.has(::bmh::layout::CareerSession_FormatError_RuntimeField6) || mem.u8(::bmh::layout::CareerSession_FormatError_RuntimeField6) == 0) {
|
||||
@@ -830,7 +837,7 @@ void change_places(GameState& g, int a, int b) {
|
||||
const uint16_t w = v == uint16_t(a) ? uint16_t(b) : v == uint16_t(b) ? uint16_t(a) : v;
|
||||
g.manager_records.at(at) = uint8_t(w), g.manager_records.at(at + 1) = uint8_t(w >> 8);
|
||||
}
|
||||
swap_bytes(g.manager_results, size_t(a) * 10 + m * 0x690, size_t(b) * 10 + m * 0x690, 10);
|
||||
swap_bytes(g.manager_results, size_t(a) * 10 + m * (runtime_dimensions.record_teams * 10), size_t(b) * 10 + m * (runtime_dimensions.record_teams * 10), 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1080,7 +1087,7 @@ bool release_player(GameState& g, int slot, GameRandom& game, WatcomRandom& rand
|
||||
}
|
||||
const int team = slot_team(slot);
|
||||
const bool foreign = nationality(g, player) != 0;
|
||||
const int start = foreign ? 0xbec : 0xb9c, count = foreign ? 0x14 : 0x50; // FirstFreeSlotSquad
|
||||
const int start = foreign ? runtime_dimensions.foreign_free_first : runtime_dimensions.free_first, count = foreign ? 0x14 : 0x50; // FirstFreeSlotSquad
|
||||
int free = -1;
|
||||
for (int s = start; s < start + count && free < 0; s++)
|
||||
if (g.squad_slots.at(size_t(s)) == 0x0FFF) free = s;
|
||||
@@ -1168,7 +1175,7 @@ void season_players(GameState& g, GameRandom& game, WatcomRandom& rand, MinuteRe
|
||||
int8_t owner = -1; // local_24: the club's human manager
|
||||
size_t board_first = 0; // local_3c
|
||||
std::vector<bool> processed(g.players.size(), false);
|
||||
for (int s = 0; s < 0xc00 && !report.unsupported; s++) {
|
||||
for (int s = 0; s < runtime_dimensions.national_slots_first && !report.unsupported; s++) {
|
||||
for (;;) {
|
||||
const int player = g.squad_slots.at(size_t(s)) & 0xFFF;
|
||||
if (player == 0xFFF) break;
|
||||
@@ -1186,7 +1193,7 @@ void season_players(GameState& g, GameRandom& game, WatcomRandom& rand, MinuteRe
|
||||
}
|
||||
Player& p = g.players.at(size_t(player));
|
||||
bool leaves = false;
|
||||
if (s < 0xb70 && (p.w35c >> 27) == 0x1f) {
|
||||
if (s < runtime_dimensions.pool_first && (p.w35c >> 27) == 0x1f) {
|
||||
// out for his career
|
||||
bool gone = true;
|
||||
if (owner != -1) {
|
||||
@@ -1267,8 +1274,8 @@ void season_players(GameState& g, GameRandom& game, WatcomRandom& rand, MinuteRe
|
||||
g.lineups_frozen = false;
|
||||
}
|
||||
for (size_t l = 0; l < g.league_rounds.size() && l < 9; l++) g.league_rounds[l] = 0;
|
||||
fill8(::bmh::layout::DeskRecords_Teams_RuntimeField, 0x114, 0);
|
||||
for (size_t i = 0; i < size_t(0x8a) * 0x1a && i < g.position_history.size(); i++) g.position_history[i] = 0;
|
||||
fill8(::bmh::layout::DeskRecords_Teams_RuntimeField, uint32_t(g.counts.league_teams * 2), 0);
|
||||
for (size_t i = 0; i < size_t(runtime_dimensions.league_teams) * 0x1a && i < g.position_history.size(); i++) g.position_history[i] = 0;
|
||||
std::fill(g.results.begin(), g.results.end(), uint8_t(0xcc));
|
||||
}
|
||||
|
||||
@@ -1654,8 +1661,8 @@ void initialize_european_qualification_seed(GameState& g) {
|
||||
if (g.memory.u16(entry + 0x22) == 0 && g.memory.u16(entry + 0x24) == 0) {
|
||||
// OpenBMH deviates from the original: initializes the empty EM qualifier
|
||||
// seeds with national teams, preventing club zero from entering the EM.
|
||||
g.memory.set16(entry + 0x22, 357);
|
||||
g.memory.set16(entry + 0x24, 358);
|
||||
g.memory.set16(entry + 0x22, kNoTeam);
|
||||
g.memory.set16(entry + 0x24, (kNoTeam + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1663,20 +1670,20 @@ bool career_season_setup(GameState& g, GameRandom& game, WatcomRandom& rand, Min
|
||||
const std::function<void(const char*)>& pause,
|
||||
const SeasonCupDrawHook& cup_draw) {
|
||||
StaticMemory& mem = g.memory;
|
||||
g.team_morale.at(0x165) |= 0x80;
|
||||
for (int team = 0; team < 0x8a; team++) {
|
||||
g.team_morale.at(kNoTeam) |= 0x80;
|
||||
for (int team = 0; team < runtime_dimensions.league_teams; team++) {
|
||||
club_balance(g, team, rand);
|
||||
auto_lineup(g, team, g.manager_of(team) >= 0 ? 0xe4 : 100); // (byte 100 - 0x80 for humans)
|
||||
}
|
||||
// the title holders of the cup entries (+0x22): none yet, the placeholder clubs
|
||||
const uint16_t first_small = 90; // TeamsWithSquads
|
||||
const uint16_t foreign = 189 + 138 + 30; // ClubPlayerDetail_ClubPlayerDetailFromGame_RuntimeField3 + CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6 (0x165)
|
||||
const uint16_t first_small = uint16_t(league_first_team(5)); // TeamsWithSquads
|
||||
const uint16_t foreign = 189 + runtime_dimensions.league_teams + 30; // ClubPlayerDetail_ClubPlayerDetailFromGame_RuntimeField3 + CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6 (0x165)
|
||||
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField2, foreign);
|
||||
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField6, uint16_t(first_small + 7));
|
||||
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField, 7);
|
||||
if (kEnglishCompetitions) mem.set16(::bmh::layout::CupTable + 28 * 0x28 + 0x22, 7); // (EN: the FA Cup proper, SeasonRuntimeField8)
|
||||
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField5, uint16_t(first_small + 0x1f));
|
||||
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField4, uint16_t(first_small + 0x13));
|
||||
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField5, uint16_t(league_first_team(7) + 7));
|
||||
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField4, uint16_t(league_first_team(6) + 7));
|
||||
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField3, uint16_t(foreign + 1));
|
||||
initialize_european_qualification_seed(g);
|
||||
mem.set16(::bmh::layout::Career_CompetitionPointersEnglish_ExecutableField28, 0);
|
||||
|
||||
@@ -25,7 +25,7 @@ std::optional<MatchdayIntroView> matchday_intro_view(const GameState& state,
|
||||
if (league >= 9) throw FormatError("matchday intro: invalid Source league");
|
||||
// LeagueName with TeamStatistics_SourceLeagueName_RuntimeField=1 includes the secondary-league prefix.
|
||||
name = league < 5 ? league_name(state, int(league)) :
|
||||
message_text(state, ::bmh::layout::SportschauAwards_MatchdayIntroView_TextPointer) + state.club_name(0x165 + int(league) - 4);
|
||||
message_text(state, ::bmh::layout::SportschauAwards_MatchdayIntroView_TextPointer) + state.club_name(kNoTeam + int(league) - 4);
|
||||
} else {
|
||||
if (type > 14) throw FormatError("matchday intro: invalid Source competition type");
|
||||
name = message_text(state, ::bmh::layout::DeskState_FormatError_ExecutableField3 + uint32_t(type) * 4);
|
||||
@@ -43,7 +43,7 @@ std::string sportschau_competition_title(const GameState& state, const MatchGrou
|
||||
if (id > 20) index = state.memory.u8(id + 0x18) + 9;
|
||||
else if (index >= 9) index = std::min(index + 12, 19);
|
||||
if (index < 5) return league_name(state, index);
|
||||
if (index < 9) return state.club_name(0x165 + index - 4);
|
||||
if (index < 9) return state.club_name(kNoTeam + index - 4);
|
||||
return message_text(state, ::bmh::layout::CupDraw_FormatError_ExecutableField6 + uint32_t(index - 9) * 4);
|
||||
}
|
||||
|
||||
|
||||
+15
-6
@@ -11,9 +11,9 @@ namespace bmh {
|
||||
namespace {
|
||||
|
||||
// Squad table layout constants of V2.24 (TeamsWithSquads, LargeSquadClubCount, NoTeamSquadStart).
|
||||
constexpr int kBigSquadTeams = 90;
|
||||
constexpr size_t kNoTeamSquadStart = 3072;
|
||||
constexpr int kTeamsWithSquads = 168;
|
||||
const int& kBigSquadTeams = runtime_dimensions.big_squad_teams;
|
||||
const int& kNoTeamSquadStart = runtime_dimensions.national_slots_first;
|
||||
const int& kTeamsWithSquads = runtime_dimensions.record_teams;
|
||||
|
||||
// C-style signed division by 8 as compiled by Watcom (rounds toward zero).
|
||||
int div8(int x) { return x / 8; }
|
||||
@@ -21,7 +21,7 @@ int div8(int x) { return x / 8; }
|
||||
} // namespace
|
||||
|
||||
GameState GameState::from_save(const SaveState& save, const DbCounts& c) {
|
||||
GameState g;
|
||||
GameState g; g.counts=c;
|
||||
const SaveBlock& squads = save.block(::bmh::layout::SquadSlots);
|
||||
for (size_t i = 0; i + 1 < squads.size; i += 2)
|
||||
g.squad_slots.push_back(uint16_t(save.data(::bmh::layout::SquadSlots)[i] | save.data(::bmh::layout::SquadSlots)[i + 1] << 8));
|
||||
@@ -90,6 +90,8 @@ GameState GameState::from_save(const SaveState& save, const DbCounts& c) {
|
||||
auto bytes = [&](uint32_t address) {
|
||||
return std::vector<uint8_t>(save.data(address), save.data(address) + save.block(address).size);
|
||||
};
|
||||
g.club_kits = bytes(layout::ClubKitSelectors);
|
||||
g.club_short_offsets = bytes(layout::ClubShortNameOffsets);
|
||||
g.manager_results = bytes(::bmh::layout::ManagerMatchHistory);
|
||||
g.manager_ratings = bytes(::bmh::layout::ManagerRatings);
|
||||
g.position_history = bytes(::bmh::layout::LeagueRankHistory);
|
||||
@@ -113,6 +115,13 @@ GameState GameState::from_save(const SaveState& save, const DbCounts& c) {
|
||||
return g;
|
||||
}
|
||||
|
||||
uint8_t GameState::club_kit(int team) const {
|
||||
return counts.league_teams == 164 ? club_kits.at(size_t(team)) : memory.u8(layout::ClubKitSelectors + uint32_t(team));
|
||||
}
|
||||
uint8_t GameState::club_short_offset(int team) const {
|
||||
return counts.league_teams == 164 ? club_short_offsets.at(size_t(team)) : memory.u8(layout::ClubShortNameOffsets + uint32_t(team));
|
||||
}
|
||||
|
||||
int GameState::manager_of(int team) const {
|
||||
for (size_t m = 0; m < manager_teams.size(); m++)
|
||||
if (manager_teams[m] == team) return int(m);
|
||||
@@ -156,9 +165,9 @@ void GameState::formation_position(int team, int slot, int& x, int& y) const {
|
||||
}
|
||||
|
||||
SquadRange squad_range(int team) {
|
||||
if (team == kNoTeam) return {kNoTeamSquadStart, 24};
|
||||
if (team == kNoTeam) return {size_t(kNoTeamSquadStart), 24};
|
||||
if (team < kBigSquadTeams) return {size_t(team) * 24, 24};
|
||||
if (team < 138) return {size_t(team) * 16 + kBigSquadTeams * 8, 16};
|
||||
if (team < runtime_dimensions.league_teams) return {size_t(team) * 16 + kBigSquadTeams * 8, 16};
|
||||
return {0, 0};
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -16,6 +16,7 @@
|
||||
#include "formats/savestate.hpp"
|
||||
#include "formats/textd.hpp"
|
||||
#include "game/memory.hpp"
|
||||
#include "game/profile_runtime.hpp"
|
||||
#include "game/random.hpp"
|
||||
#include "game/reality_motion.hpp"
|
||||
|
||||
@@ -26,7 +27,7 @@ struct TransferDecisionEvent;
|
||||
struct HumanBuyerSaleHooks;
|
||||
|
||||
// Special team id used by the original for "no club" / the player pool (0x165).
|
||||
constexpr int kNoTeam = 0x165;
|
||||
inline const int& kNoTeam = runtime_dimensions.national_first;
|
||||
|
||||
// Squad slot values (u16 in table *SquadSlots):
|
||||
// bits 0-11 player id, 0xFFF = empty slot
|
||||
@@ -36,6 +37,10 @@ constexpr uint16_t kEmptySlot = 0x0FFF;
|
||||
constexpr uint16_t kSlotInLineup = 0x8000;
|
||||
|
||||
struct GameState {
|
||||
DbCounts counts{};
|
||||
std::vector<uint8_t> club_kits, club_short_offsets;
|
||||
uint8_t club_kit(int team) const;
|
||||
uint8_t club_short_offset(int team) const;
|
||||
std::vector<uint16_t> squad_slots; // *SquadSlots, all squads back to back (see squad_range)
|
||||
std::vector<Player> players; // *PlayerConditionTechniqueForm / *PlayerSkillWords / *PlayerIdentityWords, names not filled
|
||||
std::vector<uint8_t> team_morale; // *TeamMorale, per team: bits 0-5 morale / 2, bits 6-7 flags
|
||||
|
||||
@@ -70,13 +70,13 @@ TopScorersProjection top_scorers_from_game(const GameState& g, int manager_slot,
|
||||
invalid("manager has no supported domestic league");
|
||||
// TeamLeague2 deliberately maps team IDs above 0x164 (including the
|
||||
// national team 0x165) to league zero; ordinary cup-only teams map to 9.
|
||||
const int league = manager_team > 0x164 ? 0 : team_league(manager_team);
|
||||
const int league = manager_team > (kNoTeam - 1) ? 0 : team_league(manager_team);
|
||||
if (league < 0 || league >= kLeagueCount)
|
||||
invalid("manager team is outside Source's nine domestic leagues");
|
||||
|
||||
const int first_team = league_first_team(league);
|
||||
const int team_count = kLeagueSizes[league];
|
||||
if (first_team < 0 || first_team + team_count > 138 ||
|
||||
if (first_team < 0 || first_team + team_count > runtime_dimensions.league_teams ||
|
||||
g.club_ids.size() < size_t(first_team + team_count) || g.club_names.empty())
|
||||
invalid("incomplete domestic club table");
|
||||
|
||||
|
||||
+13
-12
@@ -32,8 +32,8 @@ constexpr size_t kBoard = 0x840; // tactics board of a manager
|
||||
constexpr size_t kBoardSlot = 0x58;
|
||||
constexpr uint32_t kTransferList = ::bmh::layout::EditorList; // 44 entries of 0x58 bytes, one per pool slot
|
||||
constexpr uint32_t kListEntry = 0x58;
|
||||
constexpr size_t kPoolSlots = 0xb70; // CareerRuntimeField: first squad slot of the transfer pool
|
||||
constexpr int kLeagueClubs = 0x8a; // CareerSession_DispatchLineup_RuntimeField
|
||||
const int& kPoolSlots = runtime_dimensions.pool_first; // CareerRuntimeField: first squad slot of the transfer pool
|
||||
const int& kLeagueClubs = runtime_dimensions.league_teams; // CareerSession_DispatchLineup_RuntimeField
|
||||
constexpr int kBigSquadClubs = 90; // TeamsWithSquads
|
||||
|
||||
// Offers and incidents (Bool): 1 in WeeklyRuntimeField[kind] is only possible while the
|
||||
@@ -125,7 +125,7 @@ bool source_pending_owner_valid(const GameState& g,const SourcePendingOwner& own
|
||||
int((word>>10)&0x0fff)==int(g.squad_slots[slot]&0x0fff);
|
||||
}
|
||||
|
||||
int league_of(int team) { return team > 0x164 ? 0 : team_league(team); } // TeamLeague2
|
||||
int league_of(int team) { return team > (kNoTeam - 1) ? 0 : team_league(team); } // TeamLeague2
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -154,8 +154,9 @@ int squad_count(const GameState& g, int team, int flags) {
|
||||
|
||||
// SlotTeam: club of an absolute squad slot (-1 for the pool).
|
||||
int slot_team(int slot) {
|
||||
if (slot < kBigSquadClubs * 24) return slot / 24;
|
||||
if (slot < int(kPoolSlots)) return (slot - kBigSquadClubs * 24) / 16 + kBigSquadClubs;
|
||||
const int large=runtime_dimensions.big_squad_teams;
|
||||
if (slot < large * 24) return slot / 24;
|
||||
if (slot < int(kPoolSlots)) return (slot - large * 24) / 16 + large;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -605,7 +606,7 @@ void transfer_bid(GameState& g, int slot, uint32_t list, bool high, int months,
|
||||
const int r = rand.range(int16_t(need) + 3, int16_t(need) + 0xd);
|
||||
if (int16_t(diff) < r) score += int(int16_t(need + 0xe - diff)) * 16 + 100;
|
||||
else score -= int16_t(diff) * 8;
|
||||
const int8_t* wanted = team < kBigSquadClubs ? kWantedBig : kWantedSmall;
|
||||
const int8_t* wanted = team < runtime_dimensions.big_squad_teams ? kWantedBig : kWantedSmall;
|
||||
int16_t d = int16_t(wanted[position] - int8_t(count[position]));
|
||||
if (d < 0) {
|
||||
score += int(d) << 8;
|
||||
@@ -958,7 +959,7 @@ static bool remove_from_seller_impl(GameState& g, int seller, int player, Minute
|
||||
bool native_takeover) {
|
||||
player &= 0xFFF;
|
||||
if (seller == 0xFFF || seller == 0xFFFF) {
|
||||
for (size_t s = kPoolSlots; s < 3072; s++) // CareerRuntimeField .. LargeSquadClubCount
|
||||
for (size_t s = kPoolSlots; s < runtime_dimensions.national_slots_first; s++) // CareerRuntimeField .. LargeSquadClubCount
|
||||
if ((g.squad_slots[s] & 0xFFF) == player) g.squad_slots[s] = 0xFFF;
|
||||
return true;
|
||||
}
|
||||
@@ -969,7 +970,7 @@ static bool remove_from_seller_impl(GameState& g, int seller, int player, Minute
|
||||
report.fail("transfer: the player is not in the seller's squad (internal error 0x21)");
|
||||
return false;
|
||||
}
|
||||
for (size_t s = kPoolSlots; s < 2972; s++) // CareerRuntimeField .. CareerRuntimeField2
|
||||
for (size_t s = kPoolSlots; s < runtime_dimensions.free_first; s++) // CareerRuntimeField .. CareerRuntimeField2
|
||||
if ((g.squad_slots[s] & 0xFFF) == player) g.squad_slots[s] = 0xFFF;
|
||||
for (size_t s = at; s + 1 < range.first + range.count; s++) g.squad_slots[s] = g.squad_slots[s + 1];
|
||||
g.squad_slots[range.first + range.count - 1] = 0xFFF;
|
||||
@@ -2150,7 +2151,7 @@ HumanBuyerSaleResult settle_human_buyer_sale(GameState& g, const HumanBuyerSaleR
|
||||
if (free_agent) {
|
||||
// ReleasePlayer's canonical 0FFF seller scans the entire free-player pool,
|
||||
// not a fictitious seller squad. FFFF is not an alias for this seller.
|
||||
if (g.squad_slots.size() < 3072)
|
||||
if (g.squad_slots.size() < runtime_dimensions.national_slots_first)
|
||||
return fail("ReleasePlayer: free-agent pool is outside native squad storage");
|
||||
} else {
|
||||
const auto seller_range = squad_range(seller);
|
||||
@@ -2524,7 +2525,7 @@ PendingOfferResult process_natural_pending_offers_after_desk(GameState& g,
|
||||
};
|
||||
if (record_team(0)!=kNoTeam) return false;
|
||||
const int club=record_team(4*kRecord);
|
||||
if (club<0 || club>=138) return false;
|
||||
if (club<0 || club>=runtime_dimensions.league_teams) return false;
|
||||
const auto squad=squad_range(club);
|
||||
if (squad.first+squad.count>g.squad_slots.size()) return false;
|
||||
for (size_t i=squad.first;i<squad.first+squad.count;++i)
|
||||
@@ -2538,7 +2539,7 @@ PendingOfferResult process_natural_pending_offers_after_desk(GameState& g,
|
||||
if(offer==0xffffffffu || int(offer&31)!=manager)continue;
|
||||
const int team=native_team;
|
||||
const bool national_owner = takeover && team == kNoTeam;
|
||||
if (team<0 || (team>=138 && !national_owner))
|
||||
if (team<0 || (team>=runtime_dimensions.league_teams && !national_owner))
|
||||
return fail("AdvanceTurn: national or unknown owner is unsupported for normal-club offers");
|
||||
// AdvanceTurn scans raw offer words until the first owned player resolves in
|
||||
// an ordinary squad. A missing earlier player requires PresentLoanReturn's error
|
||||
@@ -2661,7 +2662,7 @@ void transfer_list_countdown(GameState& g, GameRandom& game, WatcomRandom& rand,
|
||||
// FindManagerForClub also recognizes the coach's temporarily saved
|
||||
// club as owner 4 while manager 0 runs the national team.
|
||||
return g.manager_of(club) >= 0 || (!g.manager_teams.empty() &&
|
||||
g.manager_teams[0] == 0x165 && mem.has(::bmh::layout::DeskActions_NationalOpponentManager_RuntimeField) &&
|
||||
g.manager_teams[0] == kNoTeam && mem.has(::bmh::layout::DeskActions_NationalOpponentManager_RuntimeField) &&
|
||||
int(mem.u16(::bmh::layout::CupDraw_FormatError_RuntimeField3)) == club);
|
||||
};
|
||||
bool human_involved = human_participant(seller);
|
||||
|
||||
@@ -14,7 +14,7 @@ std::optional<std::filesystem::path> choose_game_file(const std::string& title)
|
||||
NFD::Guard guard;
|
||||
NFD::UniquePathU8 path;
|
||||
// one filter with all accepted kinds; the check after the choice decides
|
||||
const nfdu8filteritem_t filters[] = {{"BMH game (ZIP, 7z, BMH.EXE, FLTD.EXE)", "zip,7z,exe"}};
|
||||
const nfdu8filteritem_t filters[] = {{"BMH game (ZIP, 7z, BMH.EXE, FLTD.EXE)", "zip,7z,exe,obd"}};
|
||||
const nfdresult_t result = NFD::OpenDialog(path, filters, 1);
|
||||
if (result == NFD_CANCEL) return std::nullopt;
|
||||
if (result != NFD_OKAY) throw std::runtime_error(std::string("no file dialog: ") + NFD::GetError());
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <system_error>
|
||||
|
||||
#include "formats/binary.hpp"
|
||||
#include "formats/resource_bundle.hpp"
|
||||
#include "formats/data_profile.hpp"
|
||||
#include "formats/le.hpp"
|
||||
#include "formats/m3d.hpp"
|
||||
#include "formats/textd.hpp"
|
||||
@@ -52,6 +54,7 @@ struct Family {
|
||||
const char* database;
|
||||
};
|
||||
constexpr Family kFamilies[] = {
|
||||
{GameFamily::german, "COMMUNITY.OBD", 0, "TEXTD.BLK", "M3D.MAN"},
|
||||
{GameFamily::german, "BMH.EXE", 602527, "TEXTD.BLK", "M3D.MAN"},
|
||||
{GameFamily::english, "FLTD.EXE", 507925, "TEXTE.BLK", "M3E.MAN"},
|
||||
{GameFamily::disk1994, "M3.EXE", 0, "", "M3PC.MAN"},
|
||||
@@ -82,7 +85,7 @@ void require(GameCheck& c, const fs::path& dir, const std::string& name, uint64_
|
||||
return;
|
||||
}
|
||||
std::error_code ec;
|
||||
const uint64_t actual = fs::file_size(*p, ec);
|
||||
const uint64_t actual = fs::exists(*p,ec) ? fs::file_size(*p, ec) : read_file(*p).size();
|
||||
if (ec || actual == 0) c.problems.push_back(shown + " is empty or unreadable");
|
||||
else if (size != 0 && actual != size)
|
||||
c.problems.push_back(shown + " has " + std::to_string(actual) + " bytes instead of " + std::to_string(size));
|
||||
@@ -90,7 +93,9 @@ void require(GameCheck& c, const fs::path& dir, const std::string& name, uint64_
|
||||
|
||||
// The shared picture/font/sound files of the sub directories KB, W, F and S.
|
||||
void require_media(GameCheck& c) {
|
||||
const bool bundled=fs::is_regular_file(c.directory/kCommunityBundle);
|
||||
const auto sub = [&](const char* name) -> std::optional<fs::path> {
|
||||
if(bundled)return c.directory/name;
|
||||
auto p = find_file(c.directory, name);
|
||||
if (!p || !fs::is_directory(*p)) {
|
||||
c.problems.push_back(std::string("the directory ") + name + " is missing");
|
||||
@@ -142,14 +147,15 @@ std::string text_title(const std::string& raw) {
|
||||
|
||||
void check_german(GameCheck& c) {
|
||||
// (a translated English game has BMH.exe in the OpenBMH image format, launch/fltd.hpp)
|
||||
const bool bundled=fs::is_regular_file(c.directory/kCommunityBundle);
|
||||
bool image = false;
|
||||
if (const auto exe = find_file(c.directory, "BMH.EXE")) {
|
||||
if (const auto exe = find_file(c.directory, "BMH.EXE"); exe && !bundled) {
|
||||
std::ifstream in(*exe, std::ios::binary);
|
||||
char head[13] = {};
|
||||
in.read(head, sizeof head);
|
||||
image = std::string(head, sizeof head) == "OPENBMH-IMAGE";
|
||||
}
|
||||
require(c, c.directory, "BMH.EXE", image ? 0 : 602527, "BMH.EXE");
|
||||
require(c, c.directory, "BMH.EXE", (image || bundled) ? 0 : 602527, bundled ? "RUNTIME.DAT" : "BMH.EXE");
|
||||
require(c, c.directory, "TEXTD.BLK", 0, "TEXTD.BLK");
|
||||
require(c, c.directory, "M3D.MAN", 0, "M3D.MAN");
|
||||
for (const Required& r : kCommon) require(c, c.directory, r.name, r.size, r.name);
|
||||
@@ -158,7 +164,8 @@ void check_german(GameCheck& c) {
|
||||
// the files must also load: the engine reads tables from the EXE, the texts and the
|
||||
// database of clubs and players
|
||||
try {
|
||||
load_le(*find_file(c.directory, "BMH.EXE"));
|
||||
const auto runtime=load_le(*find_file(c.directory, "BMH.EXE"));
|
||||
if(bundled && (!runtime.runtime_policy() || !runtime.expanded_profile()))throw FormatError("unsupported standalone runtime/profile");
|
||||
} catch (const std::exception& e) {
|
||||
c.problems.push_back(std::string("BMH.EXE cannot be read: ") + e.what());
|
||||
}
|
||||
@@ -212,7 +219,7 @@ bool is_game_file(const std::string& relative) {
|
||||
const size_t dot = base.find_last_of('.');
|
||||
if (dot == std::string::npos) return false;
|
||||
const std::string ext = base.substr(dot + 1);
|
||||
for (const char* e : {"EXE", "BLK", "MAN", "DAT", "MEN", "COL", "VGA", "FNT", "LBM", "EIN", "CFG", "FBM", "WAP"})
|
||||
for (const char* e : {"EXE", "BLK", "MAN", "DAT", "MEN", "COL", "VGA", "FNT", "LBM", "EIN", "CFG", "FBM", "WAP", "OBD"})
|
||||
if (ext == e) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -315,6 +322,7 @@ ResolvedGame resolve_game_unchecked(const fs::path& input, const fs::path& cache
|
||||
std::optional<fs::path> find_file(const fs::path& directory, const std::string& name) {
|
||||
std::error_code ec;
|
||||
const fs::path exact = directory / path_from_utf8(name);
|
||||
if(resource_exists(exact))return exact;
|
||||
if (fs::exists(exact, ec)) return exact;
|
||||
const std::string wanted = upper(name);
|
||||
for (const auto& e : fs::directory_iterator(directory, ec))
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "alltime_table.hpp"
|
||||
#include <algorithm>
|
||||
#include "game/table.hpp"
|
||||
#include "game/schedule.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
namespace bmh::ui { namespace {
|
||||
@@ -25,11 +27,15 @@ void button(Image&out,const Image&a,const SpriteFont&spr,const LeImage&exe,int x
|
||||
}
|
||||
AllTimeTableState alltime_table_from_game(const GameState&g,const LeImage&exe,DeskRequest owner,const Image&underlay,int nation,bool relative){
|
||||
if(nation<0||nation>4)throw FormatError("alltime: nation outside 0..4");if(underlay.width!=320||underlay.height!=240)throw FormatError("alltime: parent underlay must be 320x240");AllTimeTableState s;s.owner=owner;s.underlay=underlay;s.nation=nation;s.relative=relative;s.mask=uint8_t((1U<<nation)|(relative?0x20:0));
|
||||
if(g.club_table.size()<168*0x4a)return s;s.has_data=true;s.records.resize(168);
|
||||
for(int t=0;t<168;++t){size_t b=size_t(t)*0x4a+0x1e;auto u=[&](int o){return uint16_t(g.club_table[b+size_t(o)]|uint16_t(g.club_table[b+size_t(o+1)])<<8);};auto&r=s.records[size_t(t)];r.points=u(0);r.goals_for=u(2);r.goals_against=u(4);r.wins=u(6);r.draws=u(8);r.losses=u(10);if(t<int(g.club_ids.size()))s.club_names[size_t(t)]=g.club_name(t);s.club_name_colors[size_t(t)]=team_color(g,t);}
|
||||
for(int n=0;n<5;++n)if(0x165+n<int(g.club_ids.size()))s.nation_names[size_t(n)]=g.club_name(0x165+n);
|
||||
if(g.club_table.size()<runtime_dimensions.record_teams*0x4a)return s;s.has_data=true;s.records.resize(runtime_dimensions.record_teams);
|
||||
for(int t=0;t<runtime_dimensions.record_teams;++t){size_t b=size_t(t)*0x4a+0x1e;auto u=[&](int o){return uint16_t(g.club_table[b+size_t(o)]|uint16_t(g.club_table[b+size_t(o+1)])<<8);};auto&r=s.records[size_t(t)];r.points=u(0);r.goals_for=u(2);r.goals_against=u(4);r.wins=u(6);r.draws=u(8);r.losses=u(10);if(t<int(g.club_ids.size()))s.club_names[size_t(t)]=g.club_name(t);s.club_name_colors[size_t(t)]=team_color(g,t);}
|
||||
for(int n=0;n<5;++n)if(kNoTeam+n<int(g.club_ids.size()))s.nation_names[size_t(n)]=g.club_name(kNoTeam+n);
|
||||
const uint32_t start=kFirst+uint32_t(nation)*8;const int league=exe.u8(kLeague+uint32_t(nation));const uint32_t full=uint32_t(league_matchdays(league));
|
||||
for(int part=0;part<2;++part){int first=exe.u16(start+uint32_t(part)*4),end=exe.u16(::bmh::layout::AlltimeTable_AlltimeTableFromGame_RuntimeField+uint32_t(nation)*8+uint32_t(part)*4);for(int team=first;team<end;++team){if(team<0||team>=168)continue;const auto&r=s.records[size_t(team)];int played=int(r.wins)+r.draws+r.losses;if(!played)continue;uint32_t p=r.points,gf=r.goals_for,ga=r.goals_against;if(relative){p=p*full*10U/uint32_t(played);gf=gf*full*10U/uint32_t(played);ga=ga*full*10U/uint32_t(played);}AllTimeRow row;row.team=team;row.played=played;row.points=p;row.goals_for=gf;row.goals_against=ga;row.points_key=p*0x10001U+0x7d000000U;row.goal_key=gf*0x10001U-ga*0x10000U+0x7d000000U;s.rows.push_back(row);}}
|
||||
for(int part=0;part<2;++part){int first=exe.u16(start+uint32_t(part)*4),end=exe.u16(::bmh::layout::AlltimeTable_AlltimeTableFromGame_RuntimeField+uint32_t(nation)*8+uint32_t(part)*4);if (runtime_dimensions.expanded) {
|
||||
if (nation == 0) { first = part == 0 ? 0 : runtime_dimensions.league_teams; end = part == 0 ? runtime_dimensions.domestic_teams : runtime_dimensions.record_teams; }
|
||||
else { const int selected = nation + 4; first = league_first_team(selected); end = part == 0 ? first + kLeagueSizes[selected] : first; }
|
||||
}
|
||||
for(int team=first;team<end;++team){if(team<0||team>=runtime_dimensions.record_teams)continue;const auto&r=s.records[size_t(team)];int played=int(r.wins)+r.draws+r.losses;if(!played)continue;uint32_t p=r.points,gf=r.goals_for,ga=r.goals_against;if(relative){p=p*full*10U/uint32_t(played);gf=gf*full*10U/uint32_t(played);ga=ga*full*10U/uint32_t(played);}AllTimeRow row;row.team=team;row.played=played;row.points=p;row.goals_for=gf;row.goals_against=ga;row.points_key=p*0x10001U+0x7d000000U;row.goal_key=gf*0x10001U-ga*0x10000U+0x7d000000U;s.rows.push_back(row);}}
|
||||
std::stable_sort(s.rows.begin(),s.rows.end(),[](const auto&a,const auto&b){if(a.points_key!=b.points_key)return a.points_key>b.points_key;return a.goal_key>b.goal_key;});if(s.rows.size()>24)s.rows.resize(24);return s;
|
||||
}
|
||||
AllTimeTableScreen::AllTimeTableScreen(const std::filesystem::path&data,AllTimeTableState s):state_(std::move(s)),data_(data),exe_(load_le(asset_path(data,"BMH.exe"))),font_(load_font(asset_path(data/"F","BMH3.FNT"))),header_(load_font(asset_path(data/"F","BMH2.FNT"))),sprite_(data),window_(load_vga(asset_path(data/"KB","56.VGA"))),buttons_(load_vga(asset_path(data/"KB","0.VGA"))),texts_(load_textd(asset_path(data,"TEXTD.BLK"))){if(state_.underlay.width!=320||state_.underlay.height!=240)throw FormatError("alltime: invalid parent frame");}
|
||||
|
||||
@@ -22,8 +22,8 @@ struct AllTimeTableState {
|
||||
Image underlay;
|
||||
std::vector<AllTimeRecord> records;
|
||||
std::array<std::string,5> nation_names{};
|
||||
std::array<std::string,168> club_names{};
|
||||
std::array<uint8_t,168> club_name_colors{};
|
||||
std::vector<std::string> club_names = std::vector<std::string>(size_t(runtime_dimensions.record_teams));
|
||||
std::vector<uint8_t> club_name_colors = std::vector<uint8_t>(size_t(runtime_dimensions.record_teams));
|
||||
std::vector<AllTimeRow> rows;
|
||||
int nation=0;
|
||||
uint8_t mask=1;
|
||||
|
||||
@@ -47,7 +47,7 @@ int32_t source_asset_mask_1e(const GameState& game, int manager) {
|
||||
}
|
||||
int source_manager_league(const GameState& game, const LeImage& exe, int manager) {
|
||||
const int team = game.manager_teams.at(size_t(manager));
|
||||
if (team > 0x164) return 0; // TeamLeague2 special-team early return.
|
||||
if (team > (kNoTeam - 1)) return 0; // TeamLeague2 special-team early return.
|
||||
int cumulative = 0;
|
||||
for (int league = 0; league < 9; ++league) {
|
||||
cumulative += exe.u8(::bmh::layout::LeagueSizes + uint32_t(league));
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ CalendarScreen::CalendarScreen(const std::filesystem::path& data, CalendarState
|
||||
if (runtime_club >= 0) {
|
||||
// TeamLeague2 returns zero for team handles above0x164 (national included).
|
||||
int league = 0, boundary = 0;
|
||||
if (runtime_club <= 0x164) {
|
||||
if (runtime_club <= (kNoTeam - 1)) {
|
||||
for (; league < 9; ++league) {
|
||||
boundary += exe_.u8(::bmh::layout::LeagueSizes + uint32_t(league));
|
||||
if (runtime_club < boundary) break;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/club_player_detail.hpp"
|
||||
@@ -46,8 +47,8 @@ ClubPlayerDetailProjection club_player_detail_from_game(const GameState& g,
|
||||
for(int i=0;i<2;++i){
|
||||
const int id=i?c.secondary_club:c.primary_club;if(id<0||id==0xffff)continue;
|
||||
ClubPlayerDetailClub club;club.runtime_team=id;club.original_full_name=g.club_name(id);club.original_short_name=club.original_full_name;
|
||||
if(id<168){
|
||||
const uint8_t raw=g.memory.u8(::bmh::layout::ClubShortNameOffsets+uint32_t(id));
|
||||
if(id<runtime_dimensions.record_teams){
|
||||
const uint8_t raw=g.club_short_offset(id);
|
||||
club.original_short_name=club.original_short_name.substr(raw>>4,(raw&15)+1);
|
||||
}
|
||||
// SourceBadgeFallback consults the selector only for real atlas clubs.
|
||||
@@ -98,7 +99,7 @@ ClubPlayerDetailScreen::ClubPlayerDetailScreen(const std::filesystem::path& data
|
||||
}
|
||||
// TextWidth national/foreign names: longest word, then remove two
|
||||
// trailing characters until FNT3 fits57 pixels.
|
||||
if(id>=168 && small_.text_width(club.original_short_name)>57){
|
||||
if(id>=runtime_dimensions.record_teams && small_.text_width(club.original_short_name)>57){
|
||||
std::string longest;size_t at=0;
|
||||
while(at<club.original_short_name.size()){
|
||||
const size_t end=club.original_short_name.find(' ',at);
|
||||
|
||||
+7
-6
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/cup_draw.hpp"
|
||||
@@ -58,7 +59,7 @@ int region_for_team(int id) {
|
||||
if(t-kCupOnlyTeams>=0)return (t-kCupOnlyTeams)/7-5+10;
|
||||
return 0;
|
||||
}
|
||||
int league_for_team(int id) { return id>0x164?0:team_league(id); }
|
||||
int league_for_team(int id) { return id>(kNoTeam - 1)?0:team_league(id); }
|
||||
uint8_t manager_color(const GameState& game,int id,uint8_t base) {
|
||||
const int active=game.memory.has(::bmh::layout::ActiveManager)?game.memory.u8(::bmh::layout::ActiveManager):-1;
|
||||
const int count=game.memory.has(::bmh::layout::ManagerCount)?game.memory.u8(::bmh::layout::ManagerCount):int(game.manager_teams.size());
|
||||
@@ -142,10 +143,10 @@ CupDrawProjection cup_draw_from_game(const GameState& game,const SeasonCupDrawEv
|
||||
std::string context;
|
||||
if(event.group_stage&&event.phase==SeasonCupDrawPhase::overview) {
|
||||
const bool human_national=game.manager_of(id)>=0||
|
||||
(game.memory.has(::bmh::layout::CupDraw_FormatError_RuntimeField2)&&game.memory.has(::bmh::layout::CupDraw_FormatError_RuntimeField3)&&game.memory.u16(::bmh::layout::CupDraw_FormatError_RuntimeField2)==0x165&&game.memory.u16(::bmh::layout::CupDraw_FormatError_RuntimeField3)==id);
|
||||
if(id>=168&&!human_national) {
|
||||
if(size_t(id-168)>=game.foreign_strength.size())throw FormatError("cup draw: missing Source foreign-strength byte");
|
||||
const uint8_t strength=game.foreign_strength[size_t(id-168)];
|
||||
(game.memory.has(::bmh::layout::CupDraw_FormatError_RuntimeField2)&&game.memory.has(::bmh::layout::CupDraw_FormatError_RuntimeField3)&&game.memory.u16(::bmh::layout::CupDraw_FormatError_RuntimeField2)==kNoTeam&&game.memory.u16(::bmh::layout::CupDraw_FormatError_RuntimeField3)==id);
|
||||
if(id>=runtime_dimensions.record_teams&&!human_national) {
|
||||
if(size_t(id-runtime_dimensions.record_teams)>=game.foreign_strength.size())throw FormatError("cup draw: missing Source foreign-strength byte");
|
||||
const uint8_t strength=game.foreign_strength[size_t(id-runtime_dimensions.record_teams)];
|
||||
const unsigned band=strength>>5;
|
||||
context=text_at(texts,size_t((::bmh::layout::CupDraw_FormatError_TextPointer4-::bmh::layout::TextPointerTable)/4)+band)+original_to_utf8(exe.cstring(::bmh::layout::CupDraw_FormatError_TextPointer));
|
||||
for(unsigned bit=0;bit<3;++bit)
|
||||
@@ -153,7 +154,7 @@ CupDrawProjection cup_draw_from_game(const GameState& game,const SeasonCupDrawEv
|
||||
context+=original_to_utf8(exe.cstring(::bmh::layout::CupDraw_FormatError_ExecutableField));
|
||||
} else {
|
||||
std::array<int,5> values{};
|
||||
if(id>=168&&id!=kNoTeam) {
|
||||
if(id>=runtime_dimensions.record_teams&&id!=kNoTeam) {
|
||||
const auto snapshot=std::find_if(event.group_average_snapshots.begin(),event.group_average_snapshots.end(),
|
||||
[&](const auto& v){return v.runtime_id==id;});
|
||||
if(snapshot==event.group_average_snapshots.end())
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/desk_drawers.hpp"
|
||||
|
||||
@@ -54,7 +55,7 @@ std::optional<int> source_drawer_team(const DeskState& state, int local_kind) {
|
||||
// away-side swap. The drawer cases use those retained values: when
|
||||
// both are open, uVar21 is local48; otherwise it is local44.
|
||||
const int local44 = state.next_opponent.value_or(-1);
|
||||
const int local48 = state.national_team ? 0x165 : state.runtime_club;
|
||||
const int local48 = state.national_team ? kNoTeam : state.runtime_club;
|
||||
const int uVar21 = (open_count == 2) ? local48 : local44;
|
||||
const bool first_case = local_kind == pair[0];
|
||||
const int side = first_case ? (uVar21 != local48 ? local48 : local44) : uVar21;
|
||||
@@ -182,7 +183,7 @@ void DeskDrawerRenderer::recent(Image& target, const DeskState& state, const Des
|
||||
}
|
||||
|
||||
void DeskDrawerRenderer::head_to_head(Image& target, const DeskState& state, const DeskItem& item) const {
|
||||
if (!state.next_opponent || *state.next_opponent < 0 || *state.next_opponent > 0xa7) {
|
||||
if (!state.next_opponent || *state.next_opponent < 0 || *state.next_opponent >= runtime_dimensions.record_teams) {
|
||||
text(target, state, item.x + 1, item.y + 13, texts_[1207], 0x6a, item.x + 115); // DeskDrawersRuntimeField
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/desk_records.hpp"
|
||||
|
||||
@@ -43,7 +44,7 @@ uint8_t source_team_color(const GameState& g,int team) {
|
||||
DeskRecordsState fair_play_state_from_game(const GameState& g, int league, const Image& underlay,int manager_slot) {
|
||||
if(league<0||league>=9) throw FormatError("fair play: invalid Source league");
|
||||
const int first=league_first_team(league), count=kLeagueSizes[league];
|
||||
if(first<0||count<=0||first+count>138||g.club_ids.size()<size_t(first+count))
|
||||
if(first<0||count<=0||first+count>runtime_dimensions.league_teams||g.club_ids.size()<size_t(first+count))
|
||||
throw FormatError("fair play: incomplete Source league");
|
||||
std::vector<int16_t> teams(static_cast<size_t>(count)); std::vector<uint32_t> keys(static_cast<size_t>(count));
|
||||
for(int i=0;i<count;++i) {
|
||||
|
||||
+24
-9
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/desk_state.hpp"
|
||||
@@ -40,7 +41,7 @@ std::string pool_name(const Bytes& names, const std::vector<uint16_t>& offsets,
|
||||
}
|
||||
|
||||
int executable_league(const LeImage& exe, int team) {
|
||||
if (team < 0 || team >= 138 || !exe.contains(::bmh::layout::LeagueSizes + 8)) return -1;
|
||||
if (team < 0 || team >= runtime_dimensions.league_teams || !exe.contains(::bmh::layout::LeagueSizes + 8)) return -1;
|
||||
int first = 0;
|
||||
for (int league = 0; league < 9; ++league) {
|
||||
if (!exe.contains(::bmh::layout::LeagueSizes + uint32_t(league))) return -1;
|
||||
@@ -80,7 +81,7 @@ void project_drawer_rows(DeskState& d, const LeImage& exe, const Bytes& managers
|
||||
auto rank_curve = [&](int team, DeskRankCurve& curve) {
|
||||
curve.runtime_team = team;
|
||||
curve.team_name = pool_name(club_names, club_ids, team);
|
||||
if (team == 0x165) {
|
||||
if (team == kNoTeam) {
|
||||
// TablePosition returns rank 2 for this special national row;
|
||||
// QuoteNationalFriendlyMatch uses its native no-team squad (no random rating).
|
||||
curve.current_position = 2;
|
||||
@@ -100,16 +101,16 @@ void project_drawer_rows(DeskState& d, const LeImage& exe, const Bytes& managers
|
||||
curve.samples.push_back({round + 1, int((packed >> ((round % 3) * 5)) & 0x1f)});
|
||||
}
|
||||
if (!curve.samples.empty()) curve.current_position = curve.samples.back().source_rank;
|
||||
if (game && team < 138) curve.strength = team_average(*game, team, 0x1ff).value;
|
||||
if (game && team < runtime_dimensions.league_teams) curve.strength = team_average(*game, team, 0x1ff).value;
|
||||
};
|
||||
rank_curve(d.runtime_club < 0 ? 0x165 : d.runtime_club, d.rank_curves[0]);
|
||||
rank_curve(d.runtime_club < 0 ? kNoTeam : d.runtime_club, d.rank_curves[0]);
|
||||
if (authenticated_rival && *authenticated_rival >= 0 && *authenticated_rival != d.runtime_club)
|
||||
rank_curve(*authenticated_rival, d.rank_curves[1]);
|
||||
|
||||
// SourceDrawerTeam reads only the prepared opponent's venue history. Other
|
||||
// teams' names need not be available to render this manager's current Desk.
|
||||
if (!authenticated_rival || *authenticated_rival < 0 || *authenticated_rival >= 168) return;
|
||||
const size_t at = manager * 0x690 + size_t(*authenticated_rival) * 10;
|
||||
if (!authenticated_rival || *authenticated_rival < 0 || *authenticated_rival >= runtime_dimensions.record_teams) return;
|
||||
const size_t at = manager * (runtime_dimensions.record_teams * 10) + size_t(*authenticated_rival) * 10;
|
||||
if (at + 10 > manager_results.size()) return;
|
||||
const bool present = std::any_of(manager_results.begin() + at,
|
||||
manager_results.begin() + at + 10, [](uint8_t value) { return value != 0xff; });
|
||||
@@ -307,7 +308,7 @@ DeskState project(const StaticMemory& memory, const Tables& t, const LeImage& ex
|
||||
d.warnings[3] = remaining < 4;
|
||||
const int max24 = exe.u16(::bmh::layout::TeamsWithSquads), league_teams = exe.u16(::bmh::layout::CareerSession_DispatchLineup_RuntimeField);
|
||||
if (!d.national_team && d.runtime_club >= league_teams) throw FormatError("desk: cup-only squad projection not supported");
|
||||
const size_t first = d.national_team ? 3072 : size_t(d.runtime_club < max24 ? d.runtime_club * 24 : d.runtime_club * 16 + max24 * 8);
|
||||
const size_t first = d.national_team ? runtime_dimensions.national_slots_first : size_t(d.runtime_club < max24 ? d.runtime_club * 24 : d.runtime_club * 16 + max24 * 8);
|
||||
const size_t count = d.national_team ? 24 : (d.runtime_club < max24 ? 24 : 16);
|
||||
if (t.squads.size() < first + count || t.tactics.size() < size_t(d.manager_slot) * 0x840 + count * 0x58)
|
||||
throw FormatError("desk: truncated squad/tactics");
|
||||
@@ -488,6 +489,18 @@ DeskDate desk_date(uint32_t counter, const LeImage& exe) {
|
||||
return d;
|
||||
}
|
||||
|
||||
namespace {
|
||||
void project_automation_formation(DeskState& desk, const Bytes& formations, bool indoor) {
|
||||
const int selected = desk.automation[0];
|
||||
if (selected == 0) return;
|
||||
if (selected > 8) throw FormatError("desktop: invalid automatic formation");
|
||||
const size_t offset = size_t(desk.manager_slot) * 0x160 + size_t(indoor) * 0xb0 + size_t(selected - 1) * 22;
|
||||
if (offset + 22 > formations.size()) throw FormatError("desktop: missing automatic formation");
|
||||
desk.automation_formation.emplace();
|
||||
std::copy_n(formations.begin() + offset, 22, desk.automation_formation->begin());
|
||||
}
|
||||
}
|
||||
|
||||
DeskState desk_from_save(const SaveState& s, const LeImage& exe, uint64_t revision) {
|
||||
StaticMemory memory(s);
|
||||
auto manager = block_copy(s, ::bmh::layout::ManagerRecords), tactics = block_copy(s, ::bmh::layout::TacticsBoards), options = block_copy(s, ::bmh::layout::ManagerAutomation);
|
||||
@@ -510,6 +523,7 @@ DeskState desk_from_save(const SaveState& s, const LeImage& exe, uint64_t revisi
|
||||
project_table_position(d, table_source);
|
||||
project_drawer_rows(d, exe, manager, s.pool(0), offsets, position_history,
|
||||
results_by_opponent, rounds, std::nullopt);
|
||||
project_automation_formation(d, block_copy(s, layout::Formations), false);
|
||||
d.source = "original_save_read_only"; return d;
|
||||
}
|
||||
|
||||
@@ -520,6 +534,7 @@ DeskState desk_from_game(const GameState& g, const LeImage& exe, uint64_t revisi
|
||||
auto d = project(g.memory, {g.manager_records, g.tactics, g.manager_options, g.stocks, g.club_heap_78, g.club_names,
|
||||
g.club_ids, g.squad_slots, g.players, g.team_morale, g.manager_teams, g.league_rounds},
|
||||
exe, g.level, g.date, g.season_day(), g.season, revision);
|
||||
project_automation_formation(d, g.formations, g.indoor);
|
||||
// DeskDate only auto-opens for an ordinary club manager; the national
|
||||
// runtime (0x165) suppresses this consumer while manual mailbox access remains valid.
|
||||
if (d.runtime_club != kNoTeam && d.manager_slot >= 0 && d.manager_slot < 32 && g.memory.has(::bmh::layout::MailboxRecipientMask))
|
||||
@@ -677,8 +692,8 @@ DeskState desk_from_game(const GameState& g, const LeImage& exe, uint64_t revisi
|
||||
DeskState load_reference_desk(const std::filesystem::path& path, const LeImage& exe) {
|
||||
auto fbm = load_savegame(path);
|
||||
if (!fbm.checksum_ok) throw FormatError("desk: FBM checksum mismatch");
|
||||
if (fbm.version != "V2.24") throw FormatError("desk: unsupported FBM version");
|
||||
DbCounts counts{exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4)};
|
||||
if (fbm.version != (exe.expanded_profile() ? "O1.1" : "V2.24")) throw FormatError("desk: unsupported FBM version");
|
||||
DbCounts counts{exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4), uint32_t(exe.u16(layout::CareerSession_DispatchLineup_RuntimeField)), 30};
|
||||
SaveState save(fbm.stream, counts);
|
||||
auto d = desk_from_save(save, exe);
|
||||
validate_desk_state(d);
|
||||
|
||||
@@ -107,6 +107,7 @@ struct DeskState {
|
||||
bool mailbox_notification_pending = false; // MailboxRecipientMask active-manager bit; transient, non-FBM
|
||||
std::optional<DeskItem> menu_layout_shortcut; // final bar cell returns native record 53/kind 72, then dispatches MEN
|
||||
std::array<uint8_t, 5> automation{};
|
||||
std::optional<std::array<uint8_t, 22>> automation_formation;
|
||||
std::array<std::optional<bool>, 10> warnings{};
|
||||
std::vector<DeskItem> items; // Original linked-list drawing / hit-test order.
|
||||
std::string source;
|
||||
|
||||
+61
-10
@@ -218,7 +218,14 @@ void DesktopScreen::draw_item(Image& out, const DeskItem& item) const {
|
||||
copy(out, icons_, 97, 111, x + 3 + i * 33, y + 2, 32, 30);
|
||||
const auto value = state_.automation[i];
|
||||
if ((i == 4 ? value & 1 : value) != 0) copy(out, icons_, 129 + i * 16, 111, x + i * 33 + 10, y + 4, 17, 11);
|
||||
// Individual automatic-formation dots need a separately verified renderer.
|
||||
if (i == 0 && value != 0 && state_.automation_formation) {
|
||||
const auto& formation = *state_.automation_formation;
|
||||
// The original miniature excludes the keeper and unused positions.
|
||||
for (int row = 1; row < 11; ++row)
|
||||
if (formation[size_t(row)] != 0)
|
||||
rect(out, x + 10 + formation[size_t(row)] * 15 / 18,
|
||||
y + 5 + formation[size_t(row + 11)], 1, 1, 0x27);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
@@ -275,6 +282,20 @@ Image DesktopScreen::render() const {
|
||||
if (shortcut_hover_record_ >= 0)
|
||||
text(out, 0, 235, texts_[text_id(::bmh::layout::Desktop_Render_TextPointer + uint32_t(shortcut_hover_record_) * 4)], 0x5f, 319);
|
||||
}
|
||||
if (layout_drag_ && layout_preview_) {
|
||||
const auto selected = std::find_if(visible.items.begin(), visible.items.end(),
|
||||
[&](const DeskItem& item) { return item.id == layout_drag_->item; });
|
||||
if (selected != visible.items.end()) {
|
||||
draw_item(out, *selected);
|
||||
const auto& item = *selected;
|
||||
const int w = item.width - (item.kind >= 50 && !item.open ? 8 : 0);
|
||||
const int h = item.height - (item.kind >= 50 && !item.open ? 8 : 0);
|
||||
rect(out, item.x, item.y, w, 1, 0x27);
|
||||
rect(out, item.x, item.y + h - 1, w, 1, 0x27);
|
||||
rect(out, item.x, item.y, 1, h, 0x27);
|
||||
rect(out, item.x + w - 1, item.y, 1, h, 0x27);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -306,8 +327,30 @@ std::optional<DeskItem> DesktopScreen::folder_child_at(int x,int y) const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
DeskRequest DesktopScreen::close_drawer(const DeskItem& item) {
|
||||
if (item.id < 1 || item.id >= 54 || item.kind < 50 || item.kind > 71 || !item.open) return {};
|
||||
const auto& record = state_.layout_records[size_t(item.id)];
|
||||
const int previous = record[6], next = record[5];
|
||||
if (previous >= 54 || next >= 54 || record[12] != item.kind ||
|
||||
state_.layout_records[size_t(previous)][5] != item.id ||
|
||||
(next != 0 && state_.layout_records[size_t(next)][6] != item.id)) return {};
|
||||
auto action = request(DeskRequestKind::change_layout, item, 2);
|
||||
action.layout_operation = DeskLayoutOperation::toggle_quickbar_drawer;
|
||||
action.layout_target_item = item.id;
|
||||
for (size_t i = 0; i < 54; ++i)
|
||||
std::copy(state_.layout_records[i].begin(), state_.layout_records[i].end(), action.layout_before.begin() + i * 16);
|
||||
action.layout_after = action.layout_before;
|
||||
action.layout_after[size_t(previous) * 16 + 5] = uint8_t(next);
|
||||
if (next != 0) action.layout_after[size_t(next) * 16 + 6] = uint8_t(previous);
|
||||
action.layout_after[size_t(item.id) * 16 + 5] = 0xff;
|
||||
action.layout_after[size_t(item.id) * 16 + 6] = 0xff;
|
||||
sound_ids_.push_back(12);
|
||||
pending_ = action;
|
||||
return action;
|
||||
}
|
||||
|
||||
DeskRequest DesktopScreen::pointer_down(int x, int y, bool right) {
|
||||
if (pending_) return {};
|
||||
if (pending_ || drawer_close_release_pending_) return {};
|
||||
if (socket_release_pending_) return {}; // DeskDate waits here for the first RMB release.
|
||||
sample_shortcut_pointer(x, y);
|
||||
shortcut_hover_record_ = -1; // DeskDate clears its tooltip on event2/event8 before dispatch.
|
||||
@@ -345,19 +388,22 @@ DeskRequest DesktopScreen::pointer_down(int x, int y, bool right) {
|
||||
const int inset = item.kind >= 50 && !item.open ? 8 : 0;
|
||||
if (item.disabled || x < item.x || y < item.y || x >= item.x + item.width - inset ||
|
||||
y >= item.y + item.height - inset) continue;
|
||||
if (!right && item.kind >= 50 && item.open && state_.drawer_handles &&
|
||||
x <= item.x + 3 && y <= item.y + 3) {
|
||||
auto action = close_drawer(item);
|
||||
drawer_close_release_pending_ = action.kind != DeskRequestKind::none;
|
||||
return action;
|
||||
}
|
||||
if (right && !state_.drawer_handles) return {};
|
||||
if (right && bin_mode_ && item.kind!=12) return {};
|
||||
if (!right && item.kind==55 && item.open && !state_.national_team &&
|
||||
x-item.x-4>34 && x-item.x-4<87) return {}; // Original ticket-price scale.
|
||||
if (!right && item.kind==64 && item.open) return {}; // Source automation controls remain clicks.
|
||||
const bool drawer_handle=item.kind>=50&&state_.drawer_handles&&x<=item.x+3&&y<=item.y+3;
|
||||
if(item.kind>=50&&!drawer_handle&&!right) return {};
|
||||
if(!right&&!drawer_handle) return {}; // Source LMB activates; RMB starts a drag.
|
||||
if (!right) return {}; // LMB closes/activates; RMB alone starts a drag.
|
||||
layout_drag_ = LayoutDrag{item.id, x - item.x, y - item.y, item.x, item.y, -1, false, false, drawer_handle, right};
|
||||
layout_preview_ = state_;
|
||||
// RemovesBinModeIcon/RestoresChildBinMode run at RMB press, even if no motion follows.
|
||||
// The existing LMB handle drag differs from that Source path; do not
|
||||
// invent its sound mapping here.
|
||||
if (right) sound_ids_.insert(sound_ids_.end(), {12, 15});
|
||||
return {};
|
||||
}
|
||||
@@ -365,7 +411,7 @@ DeskRequest DesktopScreen::pointer_down(int x, int y, bool right) {
|
||||
}
|
||||
|
||||
bool DesktopScreen::pointer_move(int x, int y) {
|
||||
if (pending_ || socket_release_pending_) return false;
|
||||
if (pending_ || socket_release_pending_ || drawer_close_release_pending_) return false;
|
||||
if (!layout_drag_ || !layout_preview_) return sample_shortcut_pointer(x, y);
|
||||
auto& drag = *layout_drag_;
|
||||
auto found = std::find_if(layout_preview_->items.begin(), layout_preview_->items.end(),
|
||||
@@ -383,6 +429,10 @@ bool DesktopScreen::pointer_move(int x, int y) {
|
||||
}
|
||||
|
||||
DeskRequest DesktopScreen::pointer_up(int x, int y, bool right) {
|
||||
if (drawer_close_release_pending_) {
|
||||
if (!right) drawer_close_release_pending_ = false;
|
||||
return {}; // The close owns its release even after the widget was removed by ACK.
|
||||
}
|
||||
if (socket_release_pending_) {
|
||||
if (right) socket_release_pending_ = false;
|
||||
return {}; // First socket RMB release is only the Source wait barrier.
|
||||
@@ -600,9 +650,9 @@ DeskRequest DesktopScreen::click(int x, int y, bool right) {
|
||||
}
|
||||
if (item.disabled || right) return {};
|
||||
if (item.kind < 50) return request(item.kind == 12 ? DeskRequestKind::advance_turn : DeskRequestKind::open_menu, item);
|
||||
// DeskDate only handles Ticket/Calendar/Automation body clicks;
|
||||
// drawer open/close is exclusively the compact quickbar operation.
|
||||
if (item.open && state_.drawer_handles && x <= item.x + 3 && y <= item.y + 3) return {};
|
||||
// The corner closes through the same transaction as the quickbar.
|
||||
if (item.open && state_.drawer_handles && x <= item.x + 3 && y <= item.y + 3)
|
||||
return close_drawer(item);
|
||||
if (item.kind == 58 && item.open) return request(DeskRequestKind::advance_turn, item);
|
||||
if (item.kind == 55 && item.open && !state_.national_team && x - item.x - 4 > 34 && x - item.x - 4 < 87)
|
||||
return request(DeskRequestKind::change_ticket_price, item, (x - item.x - 4 - 35) / 3 + 8);
|
||||
@@ -722,6 +772,7 @@ std::string DesktopScreen::state_json() const {
|
||||
",\"shortcut_hover_record\":" + std::to_string(shortcut_hover_record_) +
|
||||
",\"socket_confirmation_armed\":" + std::string(socket_confirmation_armed_ ? "true" : "false") +
|
||||
",\"bin_mode\":" + std::string(bin_mode_ ? "true" : "false") +
|
||||
",\"dragging_item\":" + (layout_drag_ ? std::to_string(layout_drag_->item) : "null") +
|
||||
",\"pending_action\":" + (pending_ ? desk_request_json(*pending_) : "null") +
|
||||
",\"last_rejection\":" + (last_rejection_.empty() ? "null" : json_quote(last_rejection_)) + "}";
|
||||
return out;
|
||||
|
||||
@@ -71,6 +71,8 @@ private:
|
||||
mutable std::vector<uint8_t> sound_ids_;
|
||||
struct LayoutDrag { int item=-1, grab_x=0, grab_y=0, start_x=0, start_y=0, folder=-1; bool moved=false, folder_child=false, drawer_handle=false, right_button=false; };
|
||||
std::optional<LayoutDrag> layout_drag_;
|
||||
bool drawer_close_release_pending_ = false;
|
||||
DeskRequest close_drawer(const DeskItem& item);
|
||||
std::optional<DeskState> layout_preview_;
|
||||
void text(Image&, int x, int baseline, std::string_view, uint8_t color, int right = -1) const;
|
||||
void sprite_text(Image&, int x, int baseline, std::string_view, int font) const;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "ui/friendly_match.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -80,7 +81,7 @@ FriendlyMatchScreen::FriendlyMatchScreen(const std::filesystem::path& data, Frie
|
||||
data_(data), next_request_id_(state_.first_request_id) {
|
||||
const bool valid_national_slot = state_.national_team && state_.runtime_team == bmh::kNoTeam;
|
||||
if (state_.manager_slot < 0 || state_.manager_slot > 3 || state_.runtime_team < 0 ||
|
||||
(state_.runtime_team >= 168 && !valid_national_slot) ||
|
||||
(state_.runtime_team >= runtime_dimensions.record_teams && !valid_national_slot) ||
|
||||
state_.revision == UINT64_MAX || !state_.first_request_id || state_.planner_count < 0 ||
|
||||
state_.planner_count > std::numeric_limits<int>::max() - 2)
|
||||
throw FormatError("friendly screen: invalid manager/request identity");
|
||||
@@ -344,7 +345,7 @@ std::optional<FriendlyMatchRequest> FriendlyMatchScreen::click(int x, int y, boo
|
||||
const int row = (y-0x1d)/7;
|
||||
if (row < 0 || size_t(row) >= rows.size()) return std::nullopt;
|
||||
selected_opponent_ = rows[size_t(row)].runtime_team_id;
|
||||
if (selected_opponent_ == state_.runtime_team || selected_opponent_ < 0 || selected_opponent_ >= 168) {
|
||||
if (selected_opponent_ == state_.runtime_team || selected_opponent_ < 0 || selected_opponent_ >= runtime_dimensions.record_teams) {
|
||||
selected_opponent_ = -1;
|
||||
feedback_ = "Bitte einen anderen Ligaverein waehlen.";
|
||||
return std::nullopt;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/incoming_transfer.hpp"
|
||||
@@ -62,7 +63,7 @@ std::string source_money(uint32_t value, int width, uint32_t numerator, uint32_t
|
||||
}
|
||||
|
||||
int team_badge(const GameState& game, int team) {
|
||||
if (team < 0 || team >= 168 || size_t(team) * 2 + 2 > game.club_heap_78.size()) return -1;
|
||||
if (team < 0 || team >= runtime_dimensions.record_teams || size_t(team) * 2 + 2 > game.club_heap_78.size()) return -1;
|
||||
return (int(game.club_heap_78[size_t(team) * 2]) |
|
||||
int(game.club_heap_78[size_t(team) * 2 + 1]) << 8) & 0x1ff;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/league_pairings.hpp"
|
||||
|
||||
@@ -82,7 +83,7 @@ LeaguePairingsState league_pairings_from_game(const GameState& g,const LeaguePai
|
||||
//51329 ->LeagueName uses the league names prepared by6b98e, including
|
||||
//the shared Regionalliga A/B text and foreign country's Native name.
|
||||
//TeamStatistics_SourceLeagueName_RuntimeField's temporary prefix is only set around other callers, not this Desk.
|
||||
const auto league_title=owner.league<5?league_name(g,owner.league):g.club_name(0x165+owner.league-4);
|
||||
const auto league_title=owner.league<5?league_name(g,owner.league):g.club_name(kNoTeam+owner.league-4);
|
||||
if(owner.postponed_active) {
|
||||
out.title=message_text(g,::bmh::layout::LeaguePairings_FormatError_TextPointer12)+league_title;
|
||||
out.subtitle.clear();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/league_table.hpp"
|
||||
|
||||
@@ -145,7 +146,7 @@ LeagueTableState project_league_table(const bmh::GameState& game, int manager_sl
|
||||
// not a TEXTD entry at the domestic league-title address.
|
||||
state.league_name = league_id < 5
|
||||
? original_to_utf8(bmh::league_name(game, league_id))
|
||||
: original_to_utf8(game.club_name(0x165 + league_id - 4));
|
||||
: original_to_utf8(game.club_name(kNoTeam + league_id - 4));
|
||||
state.header_text = original_to_utf8(bmh::message_text(game, ::bmh::layout::LeagueTable_OriginalToUtf8_TextPointer2));
|
||||
// SelectsOriginalPanelWhenClear selects the original panel when SolidPanelBackground is clear.
|
||||
// Older/minimal saves may not serialize this presentation option.
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/lineup.hpp"
|
||||
|
||||
@@ -44,7 +45,7 @@ LineupState project(const StaticMemory& memory, const LeImage& exe, const std::v
|
||||
if (out.runtime_club < 0 || (out.runtime_club >= limit && !national))
|
||||
throw FormatError("lineup: only domestic league squads are supported");
|
||||
const size_t count = national || out.runtime_club < split ? 24 : 16;
|
||||
const size_t first = national ? 3072 : out.runtime_club < split ? size_t(out.runtime_club) * 24 : size_t(out.runtime_club) * 16 + split * 8;
|
||||
const size_t first = national ? runtime_dimensions.national_slots_first : out.runtime_club < split ? size_t(out.runtime_club) * 24 : size_t(out.runtime_club) * 16 + split * 8;
|
||||
const size_t board_base = size_t(out.manager_slot) * 0x840;
|
||||
if (first + count > squad.size() || board_base + count * 0x58 > tactics.size() || size_t(out.manager_slot) * 5 >= options.size())
|
||||
throw FormatError("lineup: truncated squad/tactics/options");
|
||||
|
||||
@@ -452,9 +452,9 @@ Palette LiveMatchdayScreen::shot_palette(const Palette& base, const LiveShotEven
|
||||
for (int side = 0; side < 2; ++side) {
|
||||
const int team = group.fixtures.at(size_t(shot.match * 2 + side));
|
||||
if (team == -1) continue;
|
||||
if (team < 0 || !state.memory.has(::bmh::layout::ClubKitSelectorsUnsigned + uint32_t(team)))
|
||||
if (team < 0 || size_t(team) >= state.club_ids.size())
|
||||
throw FormatError("live shot: original club colours missing");
|
||||
const int kit = state.memory.u8(::bmh::layout::ClubKitSelectorsUnsigned + uint32_t(team));
|
||||
const int kit = state.club_kit(team);
|
||||
int shirt = kit >> 4, shorts = kit & 15;
|
||||
if (side == 0) { home_shirt = shirt; home_shorts = shorts; }
|
||||
else if (shorts == home_shorts || (shirt == home_shorts && shorts == home_shirt)) {
|
||||
|
||||
+1
-1
@@ -263,7 +263,7 @@ void ManagerScreen::portrait(Image& out, int x, int y, int id) const {
|
||||
}
|
||||
void ManagerScreen::badge(Image& out, int x, int y, int id) const {
|
||||
border(out, x, y);
|
||||
if (id>=90 && id<original_badge_gate(exe_)) { copy(out, widgets_, 8, 0, x, y, 38, 38); return; }
|
||||
if (original_badge_fallback(id, &exe_)) { copy(out, widgets_, 8, 0, x, y, 38, 38); return; }
|
||||
int sprite = le16(db_.raw_club_badge_selectors, size_t(id) * 2) & 0x1ff;
|
||||
auto atlas = load_vga(asset_path(data_ / "W", std::to_string(sprite >> 3) + ".VGA"));
|
||||
copy(out, atlas, (sprite & 7) * 38, 0, x, y, 38, 38);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/matchday_results.hpp"
|
||||
|
||||
@@ -57,7 +58,7 @@ std::string competition_name(const MatchdayResultGroup& group,
|
||||
std::string name;
|
||||
if (group.league_id) {
|
||||
const int league = *group.league_id;
|
||||
name = league < 5 ? league_name(game, league) : game.club_name(0x165 + league - 4);
|
||||
name = league < 5 ? league_name(game, league) : game.club_name(kNoTeam + league - 4);
|
||||
} else if (*group.cup_id == 0xb && !bmh::kEnglishCompetitions) { // (English: the League Cup, named below)
|
||||
// FinishEvent/BuildSideRecords: descriptor type 0x0c reads the runtime
|
||||
// TEXTD slot TournamentName, then appends edition TEXTD suffix MatchdayResults_CompetitionName_TextPointer.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "national_friendly_ui.hpp"
|
||||
|
||||
@@ -6,9 +7,9 @@
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
constexpr int kNationalTeam = 0x165;
|
||||
constexpr int kFirstNationTeam = 0x166; // Nation zero is intentionally not selectable.
|
||||
constexpr int kLastNationTeam = 0x165 + 61;
|
||||
const int& kNationalTeam = kNoTeam;
|
||||
int first_nation_team() { return kNoTeam + 1; } // Nation zero is intentionally not selectable.
|
||||
int last_nation_team() { return kNoTeam + 61; }
|
||||
|
||||
TaxDialogProjection question(const NationalFriendlyIdentity& identity, uint16_t flags,
|
||||
int manager, const GameState& game, std::string body) {
|
||||
@@ -70,14 +71,14 @@ NationalFriendlyUiAction NationalFriendlyUi::show(TaxDialogProjection p) const {
|
||||
|
||||
NationalFriendlyUiAction NationalFriendlyUi::select_opponent(const GameState& g, int team) {
|
||||
if (stage_ != NationalFriendlyUiStage::picker) return {};
|
||||
if (team < kFirstNationTeam || team > kLastNationTeam) return cancel();
|
||||
if (team < first_nation_team() || team > last_nation_team()) return cancel();
|
||||
opponent_ = team;
|
||||
stage_ = NationalFriendlyUiStage::venue_question;
|
||||
return show(question(identity_, 0x606, caller_.manager, g, bmh::message_text(g, ::bmh::layout::Controller_ClubFriendlyState_TextPointer)));
|
||||
}
|
||||
|
||||
NationalFriendlyUiAction NationalFriendlyUi::answer_venue(bool yes) {
|
||||
if (stage_ != NationalFriendlyUiStage::venue_question || opponent_ < kFirstNationTeam) return {};
|
||||
if (stage_ != NationalFriendlyUiStage::venue_question || opponent_ < first_nation_team()) return {};
|
||||
manager_home_ = yes;
|
||||
stage_ = NationalFriendlyUiStage::quote_pending;
|
||||
NationalFriendlyUiAction a;
|
||||
|
||||
@@ -153,7 +153,7 @@ std::string original_literal(const LeImage& exe, uint32_t address) {
|
||||
}
|
||||
|
||||
int source_league(const LeImage& exe, int team) {
|
||||
if (team > 0x164) return 0;
|
||||
if (team > (kNoTeam - 1)) return 0;
|
||||
if (team < 0) invalid("negative team for Source league lookup");
|
||||
int cumulative = 0;
|
||||
for (int league = 0; league < 9; ++league) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/pending_offer.hpp"
|
||||
@@ -35,7 +36,7 @@ int pending_offer_owner_team(const GameState& game, int manager) {
|
||||
throw FormatError("pending offer UI: missing retained Source club");
|
||||
const int team = int(game.manager_records[base + 0x290]) |
|
||||
(int(game.manager_records[base + 0x291]) << 8);
|
||||
if (team >= 138) throw FormatError("pending offer UI: invalid retained Source club");
|
||||
if (team >= runtime_dimensions.league_teams) throw FormatError("pending offer UI: invalid retained Source club");
|
||||
return team;
|
||||
}
|
||||
|
||||
@@ -59,8 +60,8 @@ bool pending_offer_spare_buyer(const GameState& game, int raw_offer_slot, int ex
|
||||
const int buyer = team_at(4);
|
||||
const uint32_t offer = ::bmh::layout::OfferSlots + uint32_t(raw_offer_slot) * 4;
|
||||
const uint32_t list = ::bmh::layout::EditorList + uint32_t(raw_offer_slot + 40) * 0x58;
|
||||
const size_t pool = 0xb70 + size_t(raw_offer_slot + 40);
|
||||
if (team_at(0) != kNoTeam || buyer >= 138 || buyer != expected_team || !game.memory.has(offer + 3) ||
|
||||
const size_t pool = runtime_dimensions.pool_first + size_t(raw_offer_slot + 40);
|
||||
if (team_at(0) != kNoTeam || buyer >= runtime_dimensions.league_teams || buyer != expected_team || !game.memory.has(offer + 3) ||
|
||||
!game.memory.has(list + 0x57) || pool >= game.squad_slots.size())
|
||||
return false;
|
||||
const uint32_t word = game.memory.u32(offer);
|
||||
@@ -69,7 +70,7 @@ bool pending_offer_spare_buyer(const GameState& game, int raw_offer_slot, int ex
|
||||
if (word == 0xffffffffu || int(word & 31) != owner ||
|
||||
player == 0xfff || size_t(player) >= game.players.size() ||
|
||||
(game.squad_slots[pool] & 0xfff) != player || game.memory.u16(list) != buyer ||
|
||||
seller >= 138 || seller == buyer || (owner > 0 && team_at(size_t(owner)) != seller))
|
||||
seller >= runtime_dimensions.league_teams || seller == buyer || (owner > 0 && team_at(size_t(owner)) != seller))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/player_card.hpp"
|
||||
@@ -31,8 +32,8 @@ void validate(const PlayerCardState& s) {
|
||||
const auto& p=s.lineup.players.at(size_t(s.row));
|
||||
if(p.player_id!=(p.slot&0xfff)||p.row!=s.row)throw FormatError("player card: inconsistent player identity");
|
||||
if(s.statistics && s.statistics->months>12)throw FormatError("player statistics: more than twelve monthly samples");
|
||||
if(s.loan&&(s.loan->owner<0||s.loan->owner>=168||s.loan->borrower!=s.lineup.runtime_club||
|
||||
s.loan->borrower>=168||s.loan->months<0||s.loan->months>255||
|
||||
if(s.loan&&(s.loan->owner<0||s.loan->owner>=runtime_dimensions.record_teams||s.loan->borrower!=s.lineup.runtime_club||
|
||||
s.loan->borrower>=runtime_dimensions.record_teams||s.loan->months<0||s.loan->months>255||
|
||||
std::any_of(s.loan->badges.begin(),s.loan->badges.end(),[](int badge){return badge<0||badge>511;})))
|
||||
throw FormatError("player card: inconsistent ordinary loan context");
|
||||
}
|
||||
@@ -67,7 +68,7 @@ void context(PlayerCardState& out,const StaticMemory& memory,const Bytes& club_h
|
||||
// the ordinary borrower row, not the lender's ClubInfo_FormatError_RuntimeField snapshot.
|
||||
PlayerCardLoan detail;
|
||||
detail.owner=int(loan>>12&0x3ff);detail.borrower=int(loan>>22&0x3ff);
|
||||
if(detail.borrower!=out.lineup.runtime_club||detail.owner>=168||detail.borrower>=168||out.loan||!memory.has(::bmh::layout::ClubPlayerDetail_InvalidArgument_RuntimeField+i)){
|
||||
if(detail.borrower!=out.lineup.runtime_club||detail.owner>=runtime_dimensions.record_teams||detail.borrower>=runtime_dimensions.record_teams||out.loan||!memory.has(::bmh::layout::ClubPlayerDetail_InvalidArgument_RuntimeField+i)){
|
||||
out.unsupported_record="loan_record";continue;
|
||||
}
|
||||
detail.months=memory.u8(::bmh::layout::ClubPlayerDetail_InvalidArgument_RuntimeField+i);
|
||||
@@ -125,7 +126,7 @@ PlayerCardState player_card_from_save(const SaveState& s,const LeImage& exe,int
|
||||
}
|
||||
PlayerCardState player_card_from_game(const GameState& g,const LeImage& exe,int row,uint64_t revision) {
|
||||
Bytes short_names;
|
||||
for(int club=0;club<exe.u16(::bmh::layout::CareerSession_DataDirectory_RuntimeField2);++club)short_names.push_back(g.memory.u8(::bmh::layout::ClubShortNameOffsets+club));
|
||||
for(int club=0;club<exe.u16(::bmh::layout::CareerSession_DataDirectory_RuntimeField2);++club)short_names.push_back(g.club_short_offset(club));
|
||||
auto out=project(lineup_from_game(g,exe,revision),exe,row,g.club_heap_78,g.club_ids,g.club_names,short_names);
|
||||
context(out,g.memory,g.club_heap_78,g.club_ids,g.club_names,short_names);
|
||||
const size_t months=size_t(out.lineup.manager_slot)*0xb0c+0x286;
|
||||
|
||||
@@ -93,8 +93,8 @@ PreparationState preparation_from_game(const GameState& game, const LeImage& exe
|
||||
|
||||
PreparationState load_preparation_reference(const std::filesystem::path& path, const LeImage& exe) {
|
||||
const auto fbm = load_savegame(path);
|
||||
if (!fbm.checksum_ok || fbm.version != "V2.24") throw FormatError("preparation: unsupported/damaged FBM");
|
||||
const DbCounts counts{exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4)};
|
||||
if (!fbm.checksum_ok || fbm.version != (exe.expanded_profile() ? "O1.1" : "V2.24")) throw FormatError("preparation: unsupported/damaged FBM");
|
||||
const DbCounts counts{exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4), uint32_t(exe.u16(layout::CareerSession_DispatchLineup_RuntimeField)), 30};
|
||||
const SaveState save(fbm.stream, counts);
|
||||
PreparationState result;
|
||||
result.desktop = desk_from_save(save, exe);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/flow.hpp"
|
||||
|
||||
@@ -1353,7 +1354,7 @@ void StartupFlow::show_transfer_offer(PreparationState preparation, OutgoingTran
|
||||
editor.manager_slot != request->manager_slot || editor.runtime_club != request->runtime_club ||
|
||||
(!poach && (editor.list_entry != request->bid.list_entry || editor.source_slot != request->bid.source_slot ||
|
||||
editor.player != request->bid.player)) ||
|
||||
(poach && (editor.list_entry<40 || editor.list_entry>43 || editor.source_slot!=2928+editor.list_entry ||
|
||||
(poach && (editor.list_entry<40 || editor.list_entry>43 || editor.source_slot!=runtime_dimensions.pool_first+editor.list_entry ||
|
||||
editor.player<0 || editor.initial_action_loan)) || editor.revision != preparation.desktop.revision ||
|
||||
preparation.desktop.revision != request->revision + 1)
|
||||
throw FormatError("transfer offer: invalid opening acknowledgement");
|
||||
|
||||
@@ -185,7 +185,7 @@ bool SaveLoadScreen::info_press(int x, int y) {
|
||||
try {
|
||||
const auto saved = load_savegame(entries_.at(size_t(selected_)).path);
|
||||
const auto& h = saved.plain_header;
|
||||
if (!saved.checksum_ok || saved.version != "V2.24" || h.size() < 172 || h[0] < 1 || h[0] > 4)
|
||||
if (!saved.checksum_ok || (saved.version != "V2.24" && saved.version != "O1.1") || h.size() < 172 || h[0] < 1 || h[0] > 4)
|
||||
throw FormatError("save/load: invalid native information header");
|
||||
const auto field = [&](size_t at, size_t count) {
|
||||
const auto end = h.begin() + at + count;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "series_records.hpp"
|
||||
|
||||
@@ -50,7 +51,7 @@ SeriesRecordsProjection series_records_from_game(const GameState& game, const Le
|
||||
throw FormatError("series records: manager record missing");
|
||||
const size_t manager_at = size_t(manager_slot) * kManagerRecord;
|
||||
const int team = int(read16(game.manager_records, manager_at + 0x290));
|
||||
if (team < 0 || team > 0x165)
|
||||
if (team < 0 || team > kNoTeam)
|
||||
throw FormatError("series records: invalid Source manager club");
|
||||
|
||||
SeriesRecordsProjection out;
|
||||
@@ -58,7 +59,7 @@ SeriesRecordsProjection series_records_from_game(const GameState& game, const Le
|
||||
out.runtime_team = team;
|
||||
out.gradient_text = (!game.memory.has(::bmh::layout::TextGradientDisabled) || game.memory.u8(::bmh::layout::TextGradientDisabled) == 0) &&
|
||||
exe.u8(::bmh::layout::TextGradientMode) == 2;
|
||||
if (team >= 0x5a || game.club_table.size() < 168 * kClubRecord) {
|
||||
if (team >= 0x5a || game.club_table.size() < runtime_dimensions.record_teams * kClubRecord) {
|
||||
out.source_available = false; // TeamLeague shows SeriesRecordsRuntimeField outside its 0..89 table range.
|
||||
return out;
|
||||
}
|
||||
@@ -106,7 +107,7 @@ SeriesRecordsScreen::SeriesRecordsScreen(const std::filesystem::path& data,
|
||||
texts_(load_textd(asset_path(data, "TEXTD.BLK"))),
|
||||
font_(load_font(asset_path(data / "F", "BMH3.FNT"))) {
|
||||
if (projection_.manager_slot < 0 || projection_.manager_slot >= 4 ||
|
||||
projection_.runtime_team < 0 || projection_.runtime_team > 0x165 ||
|
||||
projection_.runtime_team < 0 || projection_.runtime_team > kNoTeam ||
|
||||
(projection_.source_available &&
|
||||
(projection_.league < 0 || projection_.league >= kLeagueCount ||
|
||||
projection_.league_row < 0 || projection_.league_row >= kLeagueSizes[size_t(projection_.league)])) ||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "game/messages.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "formats/resource_bundle.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -30,6 +31,7 @@ void copy_rect(Image& dst, const Image& src, int sx, int sy, int dx, int dy,
|
||||
} // namespace
|
||||
|
||||
std::filesystem::path asset_path(const std::filesystem::path& directory, const std::string& name) {
|
||||
if (!std::filesystem::exists(directory / name) && resource_exists(directory / name)) return directory / name;
|
||||
std::filesystem::path found;
|
||||
for (const auto& e : std::filesystem::directory_iterator(directory)) {
|
||||
if (e.is_regular_file() && folded(e.path().filename().string()) == folded(name)) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/sportschau.hpp"
|
||||
@@ -478,8 +479,8 @@ Image SportschauMatchReport::render_report(size_t visible_log_entries,
|
||||
text(out, heading_, 0, 54, home_name, 0x5f, 156);
|
||||
text(out, heading_, 156, 54, away_name, 0x5f, 312);
|
||||
|
||||
const bool home_domestic = fixture_.home_team < 168;
|
||||
const bool away_domestic = fixture_.away_team < 168;
|
||||
const bool home_domestic = fixture_.home_team < runtime_dimensions.record_teams;
|
||||
const bool away_domestic = fixture_.away_team < runtime_dimensions.record_teams;
|
||||
// Some Original club abbreviation bytes are unavailable because the
|
||||
// source-side temporary buffer was never initialized. Keep the known
|
||||
// header, badge, score and report visible, and omit only that abbreviation.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/strengths_state.hpp"
|
||||
|
||||
@@ -176,7 +177,7 @@ StrengthsProjection strengths_from_game(const GameState& game, int manager_slot,
|
||||
|
||||
const int first = league_first_team(league);
|
||||
const int size = kLeagueSizes[league];
|
||||
if (first < 0 || first + size > 138) invalid("league bounds exceed domestic club table");
|
||||
if (first < 0 || first + size > runtime_dimensions.league_teams) invalid("league bounds exceed domestic club table");
|
||||
if (game.club_ids.size() < size_t(first + size)) invalid("club ID table is truncated");
|
||||
if (game.club_names.empty()) invalid("club name pool is empty");
|
||||
for (int team = first; team < first + size; ++team) {
|
||||
@@ -235,7 +236,7 @@ StrengthsProjection strengths_from_game(const GameState& game, int manager_slot,
|
||||
if (league < 5) {
|
||||
out.league_name = iso646de_to_utf8(league_name(game, league).c_str());
|
||||
} else {
|
||||
const int title_team = 0x165 + league - 4;
|
||||
const int title_team = kNoTeam + league - 4;
|
||||
if (size_t(title_team) >= game.club_ids.size() ||
|
||||
game.club_ids[size_t(title_team)] >= game.club_names.size())
|
||||
invalid("foreign league title is missing from the save name pool");
|
||||
|
||||
+13
-12
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/team_statistics.hpp"
|
||||
@@ -78,7 +79,7 @@ std::string source_league_name(const GameState& game, int league, const TextDb&
|
||||
std::string name;
|
||||
if (game.memory.has(::bmh::layout::TeamStatistics_SourceLeagueName_RuntimeField) && game.memory.u8(::bmh::layout::TeamStatistics_SourceLeagueName_RuntimeField) != 0)
|
||||
name = source_text(texts, ::bmh::layout::SportschauAwards_MatchdayIntroView_TextPointer);
|
||||
name += game.club_name((mapped & 0x7f) + 0x165);
|
||||
name += game.club_name((mapped & 0x7f) + kNoTeam);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -86,17 +87,17 @@ std::string source_league_name(const GameState& game, int league, const TextDb&
|
||||
TeamStatisticsProjection team_statistics_from_game(const GameState& game, int team,
|
||||
TeamStatisticsMode mode,
|
||||
const LeImage& exe, const TextDb& texts) {
|
||||
if (team < 0 || team > 0x165) throw FormatError("team statistics: runtime team outside LeagueCalculations range");
|
||||
if (team < 0 || team > kNoTeam) throw FormatError("team statistics: runtime team outside LeagueCalculations range");
|
||||
const int mode_number = int(mode);
|
||||
if (mode_number < 0 || mode_number > 2) throw FormatError("team statistics: invalid mode");
|
||||
if (team >= 138 && team < 168)
|
||||
if (team >= runtime_dimensions.league_teams && team < runtime_dimensions.record_teams)
|
||||
throw FormatError("team statistics: simulated teams require Source draw-state ratings and are not exposed here");
|
||||
TeamStatisticsProjection out;
|
||||
out.runtime_team = team;
|
||||
out.mode = mode;
|
||||
out.source_badge_fallback = original_badge_fallback(team,&exe);
|
||||
out.badge_heap = game.club_heap_78;
|
||||
if (team != 0x165) {
|
||||
if (team != kNoTeam) {
|
||||
int region_team = team;
|
||||
const int league_gate = exe.u8(::bmh::layout::LeaguePairings_LeaguePairingsConstants_RuntimeField);
|
||||
for (int league = 0; league < 9; ++league) {
|
||||
@@ -109,8 +110,8 @@ TeamStatisticsProjection team_statistics_from_game(const GameState& game, int te
|
||||
out.flag_index = uint8_t((region_team - int(exe.u16(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField6))) / 7 - league_gate + 10);
|
||||
}
|
||||
}
|
||||
out.source_has_league_panel = team < 0xa8;
|
||||
out.league = team > 0x164 ? 0 : team_league(team);
|
||||
out.source_has_league_panel = team < runtime_dimensions.record_teams;
|
||||
out.league = team > (kNoTeam - 1) ? 0 : team_league(team);
|
||||
if (size_t(team) < game.club_ids.size()) out.original_team_name = game.club_name(team);
|
||||
if (out.source_has_league_panel) {
|
||||
if (out.league < 0 || out.league >= kLeagueCount)
|
||||
@@ -135,7 +136,7 @@ TeamStatisticsProjection team_statistics_from_game(const GameState& game, int te
|
||||
out.position_history.size(), out.position_history.begin());
|
||||
out.source_has_position_history = true;
|
||||
}
|
||||
} else if (team == 0x165) {
|
||||
} else if (team == kNoTeam) {
|
||||
// Source 357 maps to league 0 for common labels, but the save does not
|
||||
// contain a position-history row for this national-team pseudo-club.
|
||||
out.source_has_position_history = false;
|
||||
@@ -143,7 +144,7 @@ TeamStatisticsProjection team_statistics_from_game(const GameState& game, int te
|
||||
out.gradient_text = (!game.memory.has(::bmh::layout::TextGradientDisabled) || game.memory.u8(::bmh::layout::TextGradientDisabled) == 0) && exe.u8(::bmh::layout::TextGradientMode) == 2;
|
||||
out.decorated_background = !game.memory.has(::bmh::layout::PlainBackground) || game.memory.u8(::bmh::layout::PlainBackground) == 0;
|
||||
|
||||
if (team < 138) {
|
||||
if (team < runtime_dimensions.league_teams) {
|
||||
constexpr std::array<uint16_t, 5> average_flags{0x1f1, 0x1f2, 0x1f4, 0x1f8, 0x1ff};
|
||||
for (size_t i = 0; i < average_flags.size(); ++i)
|
||||
out.source_averages[i] = uint16_t(team_average(game, team, average_flags[i]).value);
|
||||
@@ -167,7 +168,7 @@ TeamStatisticsProjection team_statistics_from_game(const GameState& game, int te
|
||||
}
|
||||
if (game.memory.has(::bmh::layout::ActiveManager)) {
|
||||
const int manager = game.memory.u8(::bmh::layout::ActiveManager);
|
||||
const size_t start = size_t(manager) * 0x690;
|
||||
const size_t start = size_t(manager) * (runtime_dimensions.record_teams * 10);
|
||||
if (manager < 4 && start + out.active_manager_results.size() <= game.manager_results.size()) {
|
||||
out.active_manager_slot = manager;
|
||||
std::copy_n(game.manager_results.begin() + static_cast<std::ptrdiff_t>(start),
|
||||
@@ -178,7 +179,7 @@ TeamStatisticsProjection team_statistics_from_game(const GameState& game, int te
|
||||
out.active_manager_team = owned;
|
||||
if (owned >= 0 && size_t(owned) < game.club_ids.size())
|
||||
out.active_manager_team_name = game.club_name(owned);
|
||||
out.source_has_head_to_head = team != owned && team < 0xa8 && owned != 0x165;
|
||||
out.source_has_head_to_head = team != owned && team < runtime_dimensions.record_teams && owned != kNoTeam;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,7 +195,7 @@ TeamStatisticsScreen::TeamStatisticsScreen(const std::filesystem::path& data,
|
||||
flags_(load_vga(asset_path(data / "KB", "24.VGA"))), faces_(load_vga(asset_path(data / "KB", "27.VGA"))),
|
||||
ratings_(load_vga(asset_path(data / "KB", "30.VGA"))) {
|
||||
if (backdrop_.width != 320 || backdrop_.height != 240 || projection_.runtime_team < 0 ||
|
||||
projection_.runtime_team > 0x165 ||
|
||||
projection_.runtime_team > kNoTeam ||
|
||||
(projection_.source_has_league_panel && (projection_.league < 0 || projection_.league >= kLeagueCount ||
|
||||
projection_.table.league != projection_.league || projection_.league_row < 0 ||
|
||||
projection_.league_row >= projection_.table.size)))
|
||||
@@ -431,7 +432,7 @@ Image TeamStatisticsScreen::render() const {
|
||||
uint16_t(projection_.badge_heap[size_t(projection_.runtime_team) * 2 + 1]) << 8) & 0x1ff;
|
||||
copy(out, crest_, (selector & 7) * 38, 0, 271, 55, 38, 38);
|
||||
}
|
||||
if (projection_.source_has_league_panel || projection_.runtime_team == 0x165) {
|
||||
if (projection_.source_has_league_panel || projection_.runtime_team == kNoTeam) {
|
||||
const int league = projection_.league;
|
||||
rect(out, 225, 150, 1, 43, 0x6a); rect(out, 225, 192, 81, 1, 0x6a);
|
||||
if (projection_.source_has_position_history && projection_.source_has_league_panel) {
|
||||
|
||||
@@ -45,7 +45,7 @@ struct TeamStatisticsProjection {
|
||||
int active_manager_slot = -1;
|
||||
int active_manager_team = -1;
|
||||
std::string active_manager_team_name;
|
||||
std::array<uint8_t, 0x690> active_manager_results{};
|
||||
std::vector<uint8_t> active_manager_results = std::vector<uint8_t>(size_t(runtime_dimensions.record_teams) * 10);
|
||||
bool has_active_head_to_head = false;
|
||||
bool source_has_league_panel = true;
|
||||
bool source_has_head_to_head = false;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
constexpr size_t kPoolFirst = 0xb70;
|
||||
const int& kPoolFirst = runtime_dimensions.pool_first;
|
||||
constexpr int kMarketEntries = 40;
|
||||
constexpr uint32_t kTransferTable = ::bmh::layout::EditorList;
|
||||
constexpr uint32_t kTransferEntrySize = 0x58;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/state.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "world_cup_statistics.hpp"
|
||||
|
||||
@@ -97,7 +98,7 @@ WorldCupStatisticsProjection world_cup_statistics_from_game(const GameState& gam
|
||||
throw FormatError("World Cup statistics: placement names a nation outside 0..61");
|
||||
out.badge_heap = game.club_heap_78;
|
||||
for (int nation = 0; nation < kNationCount; ++nation) {
|
||||
const int team = 0x165 + nation;
|
||||
const int team = kNoTeam + nation;
|
||||
if (size_t(team) >= game.club_ids.size())
|
||||
throw FormatError("World Cup statistics: national-team identity is unavailable");
|
||||
out.country_names[size_t(nation)] = game.club_name(team);
|
||||
@@ -145,7 +146,7 @@ std::optional<uint8_t> world_cup_nation_at(const WorldCupStatisticsProjection& p
|
||||
WorldCupStatisticsRequest world_cup_selection_request(const WorldCupStatisticsProjection& p,
|
||||
std::optional<uint8_t> nation) {
|
||||
if (!p.can_select_opponent || !nation || *nation == 0 || *nation >= kNationCount) return {};
|
||||
return {WorldCupStatisticsRequestKind::select_opponent, 0x165 + *nation};
|
||||
return {WorldCupStatisticsRequestKind::select_opponent, kNoTeam + *nation};
|
||||
}
|
||||
|
||||
WorldCupStatisticsScreen::WorldCupStatisticsScreen(const std::filesystem::path& data,
|
||||
@@ -169,7 +170,7 @@ void WorldCupStatisticsScreen::draw_flag(Image& out, uint8_t nation, int x, int
|
||||
}
|
||||
|
||||
void WorldCupStatisticsScreen::draw_badge(Image& out, uint8_t nation, int x, int y) const {
|
||||
const int team = 0x165 + nation;
|
||||
const int team = kNoTeam + nation;
|
||||
if (size_t(team) * 2 + 1 >= projection_.badge_heap.size()) return;
|
||||
const uint16_t selector = uint16_t(projection_.badge_heap[size_t(team) * 2] |
|
||||
uint16_t(projection_.badge_heap[size_t(team) * 2 + 1]) << 8) & 0x1ff;
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/data_profile.hpp"
|
||||
#include "formats/savestate.hpp"
|
||||
#include "formats/le.hpp"
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "game/profile_runtime.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "game/weekly.hpp"
|
||||
#include "game/schedule.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
void check(bool condition,const char* message){if(!condition)throw std::runtime_error(message);}
|
||||
int main()try {
|
||||
bmh::DataProfile classic;classic.validate();
|
||||
check(classic.pool_first()==2928 && classic.national_slots_first()==3072 && classic.total_slots()==3150,"Classic roster boundaries changed");
|
||||
auto expanded=bmh::DataProfile::international_11();expanded.validate();
|
||||
check(expanded.counts.league_teams==164 && expanded.pool_first()==3936 && expanded.total_slots()==4158,"Expanded roster boundaries incorrect");
|
||||
check(expanded.leagues[6]==20 && expanded.counts.players<4095 && expanded.counts.clubs<=512,"Expanded profile exceeds compact IDs");
|
||||
for (const auto& profile : {classic, expanded}) {
|
||||
const auto blocks = bmh::save_layout(profile.counts, true);
|
||||
const auto& end = blocks.back();
|
||||
bmh::Bytes stream(end.offset + end.size, 0);
|
||||
for (const auto& block : blocks)
|
||||
if (block.address == bmh::layout::ClubSeasonRecords && !block.heap) stream.at(block.offset) = 1;
|
||||
stream.insert(stream.end(), 8, 0); // Four empty, independent synthetic string pools.
|
||||
bmh::SaveState decoded(stream, profile.counts);
|
||||
check(decoded.block(bmh::layout::SquadSlots).size == profile.total_slots() * 2,
|
||||
"squad block ignored configured profile counts");
|
||||
check(decoded.block(bmh::layout::ManagerMatchHistory).size == profile.counts.n42 * 50,
|
||||
"opponent history truncated in extended saves");
|
||||
check(decoded.block(bmh::layout::ClubKitSelectors).size == profile.counts.clubs &&
|
||||
decoded.block(bmh::layout::ClubShortNameOffsets).size == profile.counts.n42,
|
||||
"extended visual tables truncated");
|
||||
check(decoded.block(bmh::layout::DeskRecords_Teams_RuntimeField).size == profile.counts.league_teams * 2,
|
||||
"last international club has no fair-play counter");
|
||||
bmh::StaticMemory memory(decoded);
|
||||
const auto last = bmh::layout::DeskRecords_Teams_RuntimeField + (profile.counts.league_teams - 1) * 2;
|
||||
memory.set16(last, 0x0102);
|
||||
check(memory.u16(last) == 0x0102, "last club card counters are not addressable");
|
||||
check(decoded.block(bmh::layout::PlayerConditionTechniqueForm).size == profile.counts.players * 4,
|
||||
"player block ignored configured profile counts");
|
||||
}
|
||||
bmh::install_runtime_profile(expanded);
|
||||
check(bmh::squad_range(163).first==3912 && bmh::squad_range(163).count==24,
|
||||
"last international club does not have a full-size squad");
|
||||
check(bmh::squad_range(bmh::kNoTeam).first==4080 && bmh::kNoTeam==383,
|
||||
"national squad overlaps the expanded clubs/pool");
|
||||
check(bmh::slot_team(3935)==163 && bmh::slot_team(3936)==-1,
|
||||
"absolute slot ownership was truncated or misclassified");
|
||||
uint8_t sizes[9];std::copy(expanded.leagues.begin(),expanded.leagues.end(),sizes);
|
||||
bmh::set_league_sizes(sizes);
|
||||
check(bmh::league_table_teams(6)==20 && bmh::league_table_teams(5)==18,
|
||||
"England incorrectly shares the smaller foreign fixture table");
|
||||
bmh::install_runtime_profile(classic);std::copy(classic.leagues.begin(),classic.leagues.end(),sizes);bmh::set_league_sizes(sizes);
|
||||
check(bmh::runtime_dimensions.record_teams==168,"Classic cup-only rating boundary changed");
|
||||
check(bmh::squad_range(90).first==2160 && bmh::squad_range(90).count==16 && bmh::kNoTeam==357,
|
||||
"switching back did not restore original squad conventions");
|
||||
auto invalid=expanded;invalid.counts.players=4095;bool rejected=false;
|
||||
try{invalid.validate();}catch(const bmh::FormatError&){rejected=true;}
|
||||
check(rejected,"Player-ID sentinel collision accepted");
|
||||
const auto dir=std::filesystem::temp_directory_path()/"openbmh-profile-synthetic-test";
|
||||
std::filesystem::create_directories(dir);
|
||||
check(!bmh::load_data_profile(dir).extended(),"Original installation did not select Classic");
|
||||
{std::ofstream f(dir/"OBMHPROF.INI");f<<"[OpenBMH]\nprofile=classic-plus-1\n";}
|
||||
check(bmh::load_data_profile(dir).counts.n66==4104,"Profile marker not recognized");
|
||||
bmh::Bytes image_bytes(0x20000, 0);
|
||||
const auto at = [&](uint32_t address) -> uint8_t& { return image_bytes.at(address - bmh::layout::GermanDataSegmentBegin); };
|
||||
for (int league = 0; league < 9; ++league) at(bmh::layout::LeagueSizes + uint32_t(league)) = classic.leagues[size_t(league)];
|
||||
for (int day = 24; day < 24 + 34 * 8; day += 8) at(bmh::layout::CompetitionCalendar + uint32_t(day * 2)) = 1;
|
||||
bmh::save_image(bmh::LeImage::from_bytes(bmh::layout::GermanDataSegmentBegin, image_bytes), dir / "BMH.exe");
|
||||
const auto before = bmh::read_file(dir / "BMH.exe");
|
||||
const auto image = bmh::load_le(dir / "BMH.exe");
|
||||
check(image.expanded_profile() && image.u16(bmh::layout::NoTeamSquadStart) == 194,
|
||||
"national name base confused with absolute national squad slot");
|
||||
check(image.u32(bmh::layout::ProfileNationalSlotsFirst) == 4080 && image.u32(bmh::layout::ProfilePoolFirst) == 3936,
|
||||
"verified scalar overlay disagrees with runtime profile");
|
||||
check(image.u8(bmh::layout::LeagueSizes + 6) == 20 && image.u16(bmh::layout::TeamsWithSquads) == 164,
|
||||
"UI executable view has stale league/roster dimensions");
|
||||
int domestic_days=0,foreign_days=0;
|
||||
for(int day=0;day<365;++day) {
|
||||
const auto flags=image.u16(bmh::layout::CompetitionCalendar+uint32_t(day*2));
|
||||
domestic_days += (flags & 1) != 0;
|
||||
foreign_days += (flags & 16) != 0;
|
||||
}
|
||||
check(domestic_days==34 && foreign_days==38,"extended calendar changed domestic dates or omitted English fixtures");
|
||||
check(!bmh::original_badge_fallback(300, &image),"foreign cup clubs still use the computer badge");
|
||||
check(bmh::read_file(dir / "BMH.exe") == before,"loading modified the supplied executable");
|
||||
{std::ofstream f(dir/"OBMHPROF.INI");f<<"[OpenBMH]\nprofile=unknown\n";}
|
||||
rejected=false;try{bmh::load_data_profile(dir);}catch(const bmh::FormatError&){rejected=true;}
|
||||
std::filesystem::remove_all(dir);check(rejected,"Unknown profile silently became Classic");
|
||||
std::cout<<"Classic and expanded profile dimensions, discovery and limits passed\n";return 0;
|
||||
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
@@ -0,0 +1,106 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "ui/desktop.hpp"
|
||||
#include "formats/palette.hpp"
|
||||
#include "formats/le.hpp"
|
||||
#include "formats/fbm.hpp"
|
||||
#include "formats/savestate.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace bmh;
|
||||
using namespace bmh::ui;
|
||||
void check(bool ok,const char* message){if(!ok)throw std::runtime_error(message);}
|
||||
void capture(const std::filesystem::path& dir,const char* name,const Image& image,const Palette& palette){
|
||||
if(dir.empty())return;
|
||||
std::filesystem::create_directories(dir);
|
||||
std::ofstream out(dir/name,std::ios::binary);out<<"P6\n"<<image.width<<' '<<image.height<<"\n255\n";
|
||||
for(auto pixel:image.pixels){const auto c=palette.argb[pixel];for(int shift:{16,8,0})out.put(char(c>>shift));}
|
||||
}
|
||||
int main(int argc,char**argv)try{
|
||||
if(argc<2||!*argv[1])return 77;
|
||||
const std::filesystem::path data=argv[1],output=argc>2?argv[2]:"";
|
||||
const auto palette=load_palette(data/"M3PC.COL");
|
||||
if (argc > 3) {
|
||||
const auto file = load_savegame(argv[3]);
|
||||
check(file.checksum_ok,"reference save checksum invalid");
|
||||
const auto exe = load_le(data/"BMH.exe");
|
||||
const SaveState original(file.stream);
|
||||
const auto option_offset = original.block(layout::ManagerAutomation).offset;
|
||||
for (int selected=0; selected<=4; ++selected) {
|
||||
auto stream = file.stream;
|
||||
stream.at(option_offset)=uint8_t(selected);
|
||||
const SaveState saved(stream);
|
||||
auto projected = desk_from_save(saved,exe,1);
|
||||
check(projected.automation_formation.has_value()==(selected!=0),"formation visibility did not follow saved automation option");
|
||||
if(selected)for(size_t i=0;i<22;++i)
|
||||
check(projected.automation_formation->at(i)==saved.data(layout::Formations)[size_t(selected-1)*22+i],
|
||||
"miniature did not use the selected saved formation");
|
||||
projected.items={{1,20,20,173,40,64,0,0,true,false}};
|
||||
const auto rendered = DesktopScreen(data,projected).render();
|
||||
const std::string name="saved-formation-"+std::to_string(selected)+".ppm";
|
||||
capture(output,name.c_str(),rendered,palette);
|
||||
}
|
||||
}
|
||||
DeskState state;state.options.managers=1;state.options.duration=5;state.options.mode=3;state.options.difficulty=2;
|
||||
state.options.league=true;state.options.world=true;
|
||||
state.manager_slot=0;state.runtime_club=0;state.manager_teams={0};state.manager_name="QA";state.club_name="QA";
|
||||
DeskManagerIdentity manager;manager.runtime_club=0;manager.club_identity_key=0;manager.name="QA";manager.league=0;manager.portrait=0;manager.badge=0;
|
||||
state.managers={manager};state.league=0;state.portrait=0;state.badge=0;
|
||||
state.items={{1,20,20,173,40,64,0,0,true,false}};
|
||||
state.automation[0]=1;state.automation_formation.emplace();state.automation_formation->fill(0);
|
||||
(*state.automation_formation)[1]=18;(*state.automation_formation)[12]=3;
|
||||
const auto first=DesktopScreen(data,state).render();
|
||||
check(first.pixels[size_t(32)*320+49]==0x27,"formation player not rendered at the original miniature coordinate");
|
||||
state.automation[0]=2;(*state.automation_formation)[1]=6;(*state.automation_formation)[12]=2;
|
||||
const auto second=DesktopScreen(data,state).render();
|
||||
check(first.pixels!=second.pixels,"changing selected formation left the monitor unchanged");
|
||||
capture(output,"formation-1.ppm",first,palette);capture(output,"formation-2.ppm",second,palette);
|
||||
state.drawer_handles=true;
|
||||
state.items={{2,20,20,32,25,0,0,0,false,false},{1,20,20,173,40,64,0,0,true,false}};
|
||||
state.layout_records[0][5]=2;
|
||||
state.layout_records[2][5]=1; state.layout_records[2][6]=0;
|
||||
state.layout_records[1][5]=0; state.layout_records[1][6]=2;
|
||||
state.layout_records[1][12]=64; state.layout_records[1][13]=0x80;
|
||||
DesktopScreen widget_drag(data,state);
|
||||
widget_drag.pointer_down(21,21,true);
|
||||
widget_drag.pointer_move(61,61);
|
||||
const auto widget_move=widget_drag.pointer_up(61,61,true);
|
||||
check(widget_move.kind==DeskRequestKind::change_layout && widget_move.layout_operation==DeskLayoutOperation::move_item,
|
||||
"right-button widget movement was replaced by closing");
|
||||
DesktopScreen close(data,state);
|
||||
capture(output,"close-before.ppm",close.render(),palette);
|
||||
const auto removal=close.pointer_down(21,21,false);
|
||||
check(removal.kind==DeskRequestKind::change_layout &&
|
||||
removal.layout_operation==DeskLayoutOperation::toggle_quickbar_drawer &&
|
||||
removal.layout_target_item==1,"left corner did not request widget removal");
|
||||
check(removal.layout_after[2*16+5]==0 && removal.layout_after[16+5]==0xff &&
|
||||
removal.layout_after[16+6]==0xff,"corner removal corrupted the remaining layout chain");
|
||||
check(close.state_json().find("\"dragging_item\":null")!=std::string::npos,
|
||||
"close corner incorrectly entered drag mode");
|
||||
check(!close.pointer_move(100,100),"close press turned into movement");
|
||||
auto removed=state; removed.revision=state.revision+1; removed.items.erase(removed.items.begin()+1);
|
||||
for(size_t i=0;i<54;++i)std::copy_n(removal.layout_after.begin()+i*16,16,removed.layout_records[i].begin());
|
||||
close.acknowledge(removed);
|
||||
check(close.pointer_up(21,21,false).kind==DeskRequestKind::none,
|
||||
"close release activated the icon underneath the removed widget");
|
||||
capture(output,"close-after.ppm",close.render(),palette);
|
||||
check(close.pointer_up(21,21,false).kind==DeskRequestKind::open_menu,
|
||||
"close release barrier consumed a subsequent independent click");
|
||||
state.layout_records={}; state.layout_records[0][5]=1;
|
||||
state.items={{1,20,20,32,25,0,0,0,false,false}};state.drawer_handles=true;
|
||||
DesktopScreen drag(data,state);const auto normal=drag.render();
|
||||
const auto idle=drag.state_json();
|
||||
drag.pointer_down(25,25,true);
|
||||
check(drag.state_json()!=idle,"drag press did not invalidate the rendered desktop");
|
||||
drag.pointer_move(65,65);
|
||||
const auto moving=drag.render();
|
||||
check(moving.pixels[size_t(60)*320+60]==0x27 && moving.pixels[size_t(84)*320+91]==0x27,"moving icon lacks inclusive yellow outline");
|
||||
const auto request=drag.pointer_up(65,65,true);
|
||||
check(request.kind==DeskRequestKind::change_layout,"drag did not retain its layout transaction");
|
||||
check(drag.render().pixels==normal.pixels,"yellow preview survived release without acknowledgement");
|
||||
capture(output,"drag-normal.ppm",normal,palette);capture(output,"drag-active.ppm",moving,palette);
|
||||
std::cout<<"Automation formation changes and transient yellow drag border passed\n";return 0;
|
||||
}catch(const std::exception&e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
@@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#include "app/video_session.hpp"
|
||||
#include <SDL_syswm.h>
|
||||
#include <cstring>
|
||||
#include <nfd.h>
|
||||
#include <iostream>
|
||||
int main() { @autoreleasepool {
|
||||
SDL_setenv("SDL_VIDEODRIVER", "cocoa", 1);
|
||||
try {
|
||||
bmh::app::VideoSession video;
|
||||
if ([NSApp activationPolicy] != NSApplicationActivationPolicyRegular) return 1;
|
||||
if (NFD_Init() != NFD_OKAY) return 2;
|
||||
NFD_Quit();
|
||||
if ([NSApp activationPolicy] != NSApplicationActivationPolicyRegular) return 3;
|
||||
SDL_Window* window=SDL_CreateWindow("Keyboard startup QA",0,0,320,240,0);
|
||||
if(!window)return 4;
|
||||
SDL_SysWMinfo info{}; SDL_VERSION(&info.version);
|
||||
if(!SDL_GetWindowWMInfo(window,&info))return 5;
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
[info.info.cocoa.window makeKeyAndOrderFront:nil];
|
||||
for(int i=0;i<100 && SDL_GetKeyboardFocus()!=window;++i){SDL_PumpEvents();SDL_Delay(10);}
|
||||
if(SDL_GetKeyboardFocus()!=window){std::cerr<<"Cocoa window did not acquire keyboard focus\n";return 6;}
|
||||
SDL_StartTextInput();
|
||||
SDL_Event input;while(SDL_PollEvent(&input)){}
|
||||
NSEvent* key=[NSEvent keyEventWithType:NSEventTypeKeyDown location:NSZeroPoint
|
||||
modifierFlags:0 timestamp:[[NSProcessInfo processInfo] systemUptime] windowNumber:[info.info.cocoa.window windowNumber]
|
||||
context:nil characters:@"q" charactersIgnoringModifiers:@"q" isARepeat:NO keyCode:12];
|
||||
[NSApp postEvent:key atStart:NO];
|
||||
bool key_received=false,text_received=false;
|
||||
for(int i=0;i<100 && !(key_received&&text_received);++i){
|
||||
while(SDL_PollEvent(&input)){
|
||||
key_received|=input.type==SDL_KEYDOWN;
|
||||
text_received|=input.type==SDL_TEXTINPUT && std::strcmp(input.text.text,"q")==0;
|
||||
}
|
||||
SDL_Delay(10);
|
||||
}
|
||||
SDL_DestroyWindow(window);
|
||||
if(!key_received||!text_received){std::cerr<<"Native key="<<key_received<<" text="<<text_received<<'\n';return 7;}
|
||||
std::cout<<"Native Cocoa key and text reach SDL after initial picker lifecycle\n";
|
||||
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 6;}
|
||||
return 0;
|
||||
} }
|
||||
@@ -0,0 +1,62 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/resource_bundle.hpp"
|
||||
#include "formats/le.hpp"
|
||||
#include "formats/data_profile.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/calendar.hpp"
|
||||
#include "miniz.h"
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace bmh;
|
||||
void check(bool ok,const char* what){if(!ok)throw std::runtime_error(what);}
|
||||
void bundle(const std::filesystem::path& path,const std::vector<std::pair<std::string,Bytes>>& files) {
|
||||
mz_zip_archive zip{};
|
||||
check(mz_zip_writer_init_heap(&zip,0,0)!=0,"synthetic ZIP initialization");
|
||||
for(const auto& [name,bytes]:files)check(mz_zip_writer_add_mem(&zip,name.c_str(),bytes.data(),bytes.size(),MZ_BEST_COMPRESSION)!=0,"synthetic ZIP entry");
|
||||
void* data=nullptr;size_t size=0;
|
||||
check(mz_zip_writer_finalize_heap_archive(&zip,&data,&size)!=0,"synthetic ZIP finalization");
|
||||
std::ofstream out(path,std::ios::binary);out.write(static_cast<const char*>(data),std::streamsize(size));
|
||||
mz_free(data);mz_zip_writer_end(&zip);check(bool(out),"synthetic ZIP write");
|
||||
}
|
||||
Bytes bytes(std::string text){return Bytes(text.begin(),text.end());}
|
||||
int main()try {
|
||||
const auto root=std::filesystem::temp_directory_path()/("openbmh-bundle-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
std::filesystem::create_directories(root);
|
||||
Bytes data(0x20000,0);
|
||||
const auto put=[&](uint32_t address,uint8_t value){data.at(address-layout::GermanDataSegmentBegin)=value;};
|
||||
for(int league=0;league<9;++league)put(layout::LeagueSizes+uint32_t(league),league<5?18:12);
|
||||
for(int day=24;day<24+34*8;day+=8)put(layout::CompetitionCalendar+uint32_t(day*2),1);
|
||||
RuntimePolicy policy{2030,2,90,1,{{layout::FreeKickTakerLabel,"Test label"}}};
|
||||
save_runtime_image(LeImage::from_bytes(layout::GermanDataSegmentBegin,data),policy,root/"source.dat");
|
||||
const auto runtime=read_file(root/"source.dat");
|
||||
bundle(root/kCommunityBundle,{{"RUNTIME.DAT",runtime},{"OBMHPROF.INI",bytes("[OpenBMH]\nprofile=classic-plus-1\n")},{"KB/20.VGA",bytes("synthetic picture")}});
|
||||
std::filesystem::remove(root/"source.dat");
|
||||
check(!std::filesystem::exists(root/"BMH.exe"),"synthetic bundle accidentally requires an executable");
|
||||
check(resource_exists(root/"kb"/"20.vga") && read_file(root/"kb"/"20.vga")==bytes("synthetic picture"),"case-insensitive resource read");
|
||||
check(load_data_profile(root).extended(),"bundled profile metadata not found");
|
||||
const auto image=load_le(root/"BMH.exe");
|
||||
check(image.expanded_profile() && image.runtime_policy(),"data-only image did not bind the extended profile");
|
||||
check(!image.contains(layout::CalendarDateSetup) && !image.contains(layout::ForeignBadgeGateInstruction),"machine-code segment retained");
|
||||
check(calendar_epoch_from_executable(image).year==2030,"calendar still depends on original instructions");
|
||||
check(image.cstring(layout::FreeKickTakerLabel)=="Test label","resolved auxiliary label lost");
|
||||
check(image.u16(layout::TeamsWithSquads)==164,"standalone runtime roster dimensions differ");
|
||||
// Loose user-created files remain writable and are not replaced by bundle data.
|
||||
{std::ofstream out(root/"user.FBM");out<<"user save";}
|
||||
check(read_file(root/"user.FBM")==bytes("user save"),"bundle swallowed a loose user save");
|
||||
for(int kind=0;kind<2;++kind) {
|
||||
const auto bad=root/("bad-"+std::to_string(kind));std::filesystem::create_directory(bad);
|
||||
bundle(bad/kCommunityBundle,kind==0?std::vector<std::pair<std::string,Bytes>>{{"../escape",{1}}}:
|
||||
std::vector<std::pair<std::string,Bytes>>{{"DUP",{1}},{"dup",{2}}});
|
||||
bool rejected=false;try{resource_exists(bad/"anything");}catch(const FormatError&){rejected=true;}
|
||||
check(rejected,"unsafe or duplicate resource accepted");
|
||||
}
|
||||
auto broken=runtime;broken.pop_back();
|
||||
{std::ofstream out(root/"broken.dat",std::ios::binary);out.write(reinterpret_cast<const char*>(broken.data()),std::streamsize(broken.size()));}
|
||||
bool rejected=false;try{load_le(root/"broken.dat");}catch(const FormatError&){rejected=true;}
|
||||
check(rejected,"truncated runtime labels accepted");
|
||||
std::filesystem::remove_all(root);
|
||||
std::cout<<"Standalone data policies, bundled resources, paths and loose saves passed\n";return 0;
|
||||
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
@@ -55,7 +55,7 @@ void check_state(const GameState& g, const std::string& when, Checks& c) {
|
||||
std::set<int> seen;
|
||||
// (only the clubs' squads up to format field = 0xb70: the national squad and the other
|
||||
// lists behind them hold club players a second time)
|
||||
for (size_t s = 0; s < g.squad_slots.size() && s < 0xb70; s++) {
|
||||
for (size_t s = 0; s < g.squad_slots.size() && s < size_t(runtime_dimensions.pool_first); s++) {
|
||||
const int id = g.squad_slots[s] & 0xfff;
|
||||
if (id == 0xfff) continue;
|
||||
if (!seen.insert(id).second) c.fail("player in two squad slots", when + " player " + std::to_string(id));
|
||||
@@ -81,7 +81,7 @@ bool capture_duplicate(const GameState& before, const GameState& after,
|
||||
const std::filesystem::path& directory) {
|
||||
std::set<int> seen;
|
||||
int duplicate = -1;
|
||||
for (size_t slot = 0; slot < 2928 && slot < after.squad_slots.size(); ++slot) {
|
||||
for (size_t slot = 0; slot < size_t(runtime_dimensions.pool_first) && slot < after.squad_slots.size(); ++slot) {
|
||||
const int id = after.squad_slots[slot] & 0xfff;
|
||||
if (id != 0xfff && !seen.insert(id).second) { duplicate = id; break; }
|
||||
}
|
||||
|
||||
Loaded 100 of 106 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user