Torch
Loading...
Searching...
No Matches
ConfigFactory.h
1#pragma once
2
3#include <cstdint>
4#include <filesystem>
5#include <string>
6#include <vector>
7#include <yaml-cpp/yaml.h>
8
9namespace BK64 {
10
11// Classification of a >16MB BK ROM.
12enum class RomhackKind {
13 NotRomhack, // vanilla-sized ROM
14 BBRomhack, // standard Banjo's Backpack build
15 CustomBuild, // BK boot overlay present, but rebuilt/relocated internals
16 UnknownRom, // extended ROM with no recognizable BK boot overlay
17};
18
19// Binary aGameConfig format: 'BKCF' header + typed sections
20
21constexpr uint32_t GAMECONFIG_MAGIC = 0x46434B42;
22constexpr uint16_t GAMECONFIG_VERSION = 1;
23
24enum class ConfigSectionType : uint16_t {
25 CODE_CONSTANTS = 1,
26 SCENE_REMAP = 2,
27 RETURN_TO_LAIR = 3,
28 MUSIC = 4,
29 SKYBOX = 5,
30 SCENE_DEF = 6,
31 NOTE_DOORS = 7,
32 JIGGY_PUZZLES = 8,
33 LEVEL_NAMES = 9,
34 WARP_DESTINATIONS = 10,
35 CUSTOM_CODE = 11,
36 ROM_HASH = 12,
37 CUSTOM_CODE_INFO = 13,
38};
39
40enum class CustomCodeKind : uint16_t {
41 NONE = 0,
42 BB_GLOBALIZATION = 1,
43 BB_INJECTED = 2,
44};
45
46// CODE_CONSTANTS key IDs - they index into the sBBConfigs table.
47enum class CodeConstantKey : uint16_t {
48 NEW_GAME_MAP = 0,
49 START_LEVEL_1,
50 START_LEVEL_2,
51 KNOW_ALL_MOVES,
52 MUMBO_COST_TERMITE,
53 MUMBO_COST_CROC,
54 MUMBO_COST_WALRUS,
55 MUMBO_COST_PUMPKIN,
56 MUMBO_COST_BEE,
57 EGGS_NORMAL_MAX,
58 RED_FEATHERS_NORMAL_MAX,
59 GOLD_FEATHERS_NORMAL_MAX,
60 EGGS_CHEATO_MAX,
61 RED_FEATHERS_CHEATO_MAX,
62 GOLD_FEATHERS_CHEATO_MAX,
63 NOTES_MAX,
64 JIGGIES_PER_WORLD,
65 HONEYCOMBS_PER_WORLD,
66 EXTRA_HC_START,
67 WARP_EXIT_BANJOS_HOUSE,
68 WARP_ENTER_LAIR,
69 SPECIAL_LEVEL,
70 HIDE_JIGGIES_LEVEL,
71 HIDE_COLLECTIBLES_LEVEL,
72 COUNT
73};
74
75// Vanilla BK is exactly 16MB. Anything bigger has been through Banjo's Backpack.
76inline bool IsRomhack(const std::vector<uint8_t>& rom) {
77 return rom.size() > 0x1000000;
78}
79
80RomhackKind ClassifyRomhack(const std::vector<uint8_t>& rom);
81
82// When a romhack, generate a config for it based on us v1.0.
83bool TrySynthesizeRomConfig(YAML::Node& config, const std::string& cartHash, const std::filesystem::path& romPath,
84 const std::vector<uint8_t>& rom);
85
86// Build the binary aGameConfig blob from a BB romhack ROM.
87std::vector<char> BuildGameConfigBlob(const std::vector<uint8_t>& rom, const std::string& romName);
88
89// True for injected custom-code blobs and for CustomBuild ROMs.
90bool HasCustomCodeBlob(const std::vector<uint8_t>& rom);
91
92// Pre-extraction probe for callers that decide the warning policy themselves
93// (e.g. the extraction UI checks RomhackTable for ported hashes): reports
94// the detected blob's kind and its SHA1 as 40 lowercase hex chars + NUL.
95// Returns false (kind NONE, empty hash) when no blob is found.
96bool GetCustomCodeBlobInfo(const std::vector<uint8_t>& rom, CustomCodeKind& outKind, char outSha1Hex[41]);
97
98// Maintainer tool, creates a hashes.yml.
99void EmitAssetHashes(const std::filesystem::path& romPath, const std::filesystem::path& outputPath);
100
101// How many slots differ from the baseline hashes - a missing baseline entry counts as
102// changed. The port-side extractor uses it to size its progress bar to the real romhack
103// delta instead of every vanilla slot.
104size_t CountModifiedSlots(const std::vector<uint8_t>& rom, const std::filesystem::path& hashesYamlPath);
105
106// Baseline SHA-1 for one slot, or empty if there's no hashes.yaml or no entry for it.
107// Loaded lazily from gAssetPath/hashes.yaml on the first call, then held for the run.
108const std::string& GetBaselineAssetHash(uint32_t assetId);
109
110// Vanilla warp destination (MAP << 8 | ENTRY) for a warp-table index, from the
111// `warps:` section of hashes.yaml. Returns -1 if unknown. Loaded lazily like the
112// baseline hashes.
113int GetVanillaWarpDest(uint32_t warpIndex);
114
115} // namespace BK64