Every source file in ui, app, game, formats, cli, audio and launch that had none now starts with a short English comment: what it implements, what state it owns and how it relates to its neighbours (request/acknowledge flow, pairs of files, random generator use). Comment lines only; the full build and the runnable tests are unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
43 lines
1.9 KiB
C++
43 lines
1.9 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Decides which club badge tokens the original draws as a fallback instead of an individual
|
|
// crest. The cut-off for foreign clubs differs between game editions, so it is read from one
|
|
// instruction in the loaded executable (layout::ForeignBadgeGateInstruction) and stored in the
|
|
// process-wide original_foreign_badge_end by install_original_badge_policy(). An executable
|
|
// that does not match the verified pattern falls back to 138. Header-only; the club
|
|
// selectors themselves stay in the database and savegame data.
|
|
#pragma once
|
|
|
|
#include "formats/executable_layout.hpp"
|
|
#include "formats/le.hpp"
|
|
|
|
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 int original_badge_gate(const LeImage& exe) {
|
|
constexpr auto instruction = layout::ForeignBadgeGateInstruction;
|
|
if (exe.contains(instruction) && exe.contains(instruction + 6) &&
|
|
exe.u8(instruction) == 0x66 && exe.u8(instruction + 1) == 0x81 &&
|
|
exe.u8(instruction + 2) == 0xfb && exe.u8(instruction + 5) == 0x7c &&
|
|
exe.u8(instruction + 6) == 7) {
|
|
const int end = exe.u16(instruction + 3);
|
|
if (end == 90 || end == 138) return end;
|
|
}
|
|
// Never invent individual foreign crests for an unverified drawing routine.
|
|
return 138;
|
|
}
|
|
|
|
inline void install_original_badge_policy(const LeImage& exe) {
|
|
original_foreign_badge_end = original_badge_gate(exe);
|
|
}
|
|
|
|
inline bool original_badge_fallback(int token, const LeImage* exe = nullptr) {
|
|
const int team = token & 0xfff;
|
|
const int end = exe ? original_badge_gate(*exe) : original_foreign_badge_end;
|
|
return team == 0xfff || (team >= 90 && team < end) || (team >= 168 && team < 357);
|
|
}
|
|
|
|
} // namespace bmh
|