1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
#pragma once
#include <cstdint>
#include <filesystem>
#include <string>
#include <vector>
#include <yaml-cpp/yaml.h>
namespace BK64 {
// Classification of a >16MB BK ROM.
enum class RomhackKind {
NotRomhack, // vanilla-sized ROM
BBRomhack, // standard Banjo's Backpack build
CustomBuild, // BK boot overlay present, but rebuilt/relocated internals
UnknownRom, // extended ROM with no recognizable BK boot overlay
};
// Binary aGameConfig format: 'BKCF' header + typed sections
constexpr uint32_t GAMECONFIG_MAGIC = 0x46434B42;
constexpr uint16_t GAMECONFIG_VERSION = 1;
// Its entry in modding.yml, and with .yaml its file in the modding folder.
constexpr const char* GAMECONFIG_MODDING_NAME = "assets/aGameConfig";
enum class ConfigSectionType : uint16_t {
CODE_CONSTANTS = 1,
SCENE_REMAP = 2,
RETURN_TO_LAIR = 3,
MUSIC = 4,
SKYBOX = 5,
SCENE_DEF = 6,
NOTE_DOORS = 7,
JIGGY_PUZZLES = 8,
LEVEL_NAMES = 9,
WARP_DESTINATIONS = 10,
CUSTOM_CODE = 11,
ROM_HASH = 12,
CUSTOM_CODE_INFO = 13,
};
enum class CustomCodeKind : uint16_t {
NONE = 0,
BB_GLOBALIZATION = 1,
BB_INJECTED = 2,
};
// CODE_CONSTANTS key IDs - they index into the sBBConfigs table.
enum class CodeConstantKey : uint16_t {
NEW_GAME_MAP = 0,
START_LEVEL_1,
START_LEVEL_2,
KNOW_ALL_MOVES,
MUMBO_COST_TERMITE,
MUMBO_COST_CROC,
MUMBO_COST_WALRUS,
MUMBO_COST_PUMPKIN,
MUMBO_COST_BEE,
EGGS_NORMAL_MAX,
RED_FEATHERS_NORMAL_MAX,
GOLD_FEATHERS_NORMAL_MAX,
EGGS_CHEATO_MAX,
RED_FEATHERS_CHEATO_MAX,
GOLD_FEATHERS_CHEATO_MAX,
NOTES_MAX,
JIGGIES_PER_WORLD,
HONEYCOMBS_PER_WORLD,
EXTRA_HC_START,
WARP_EXIT_BANJOS_HOUSE,
WARP_ENTER_LAIR,
SPECIAL_LEVEL,
HIDE_JIGGIES_LEVEL,
HIDE_COLLECTIBLES_LEVEL,
COUNT
};
// Vanilla BK is exactly 16MB. Anything bigger has been through Banjo's Backpack.
inline bool IsRomhack(const std::vector<uint8_t>& rom) {
return rom.size() > 0x1000000;
}
// The aGameConfig blob read back out. Each table keeps its entries in blob order, so writing one back
// gives the same bytes.
struct GameConfigData {
struct Constant {
uint16_t key;
uint16_t value;
};
struct WorldMap {
uint16_t map;
uint16_t level;
};
struct LairReturn {
uint8_t world;
uint16_t map;
uint16_t exit;
};
struct Music {
uint16_t map;
uint16_t track;
uint16_t alternate;
};
struct SkyLayer {
int16_t model;
float scale;
float spin; // degrees per second
};
struct Sky {
uint16_t map;
SkyLayer layers[3];
};
struct LevelModels {
uint16_t map;
int16_t opaque;
int16_t translucent;
int16_t cubeMin[3];
int16_t cubeMax[3];
float scale;
};
struct Title {
uint8_t index;
std::string text;
};
struct Warp {
uint16_t warp;
uint16_t dest; // map << 8 | entrance
};
struct NoteDoor {
uint8_t door;
uint16_t notes;
};
struct Puzzle {
uint8_t picture;
uint8_t cost;
uint8_t size;
uint16_t flag;
};
std::string romName;
std::vector<Constant> constants;
std::vector<WorldMap> worldByMap;
std::vector<LairReturn> returnToLair;
std::vector<Music> music;
std::vector<Sky> skybox;
std::vector<LevelModels> levelModels;
std::vector<Title> titles;
std::vector<Warp> warps;
std::vector<NoteDoor> noteDoors;
std::vector<Puzzle> puzzles;
bool hasCustomCode = false;
uint32_t customCodeRamBase = 0;
uint8_t customCodeSha1[20] = {};
CustomCodeKind customCodeKind = CustomCodeKind::NONE;
bool hasRomHash = false;
uint8_t romHash[20] = {};
};
bool ReadGameConfig(const std::vector<char>& blob, GameConfigData& out, std::string& error);
std::vector<char> WriteGameConfig(const GameConfigData& config);
std::string GameConfigToYaml(const GameConfigData& config);
bool GameConfigFromYaml(const std::string& text, GameConfigData& out, std::string& error);
const char* CodeConstantName(uint16_t key);
RomhackKind ClassifyRomhack(const std::vector<uint8_t>& rom);
// When a romhack, generate a config for it based on us v1.0.
bool TrySynthesizeRomConfig(YAML::Node& config, const std::string& cartHash, const std::filesystem::path& romPath,
const std::vector<uint8_t>& rom);
// Build the binary aGameConfig blob from a BB romhack ROM.
std::vector<char> BuildGameConfigBlob(const std::vector<uint8_t>& rom, const std::string& romName);
// True for injected custom-code blobs and for CustomBuild ROMs.
bool HasCustomCodeBlob(const std::vector<uint8_t>& rom);
// Pre-extraction probe for callers that decide the warning policy themselves
// (e.g. the extraction UI checks RomhackTable for ported hashes): reports
// the detected blob's kind and its SHA1 as 40 lowercase hex chars + NUL.
// Returns false (kind NONE, empty hash) when no blob is found.
bool GetCustomCodeBlobInfo(const std::vector<uint8_t>& rom, CustomCodeKind& outKind, char outSha1Hex[41]);
// Maintainer tool, creates a hashes.yml.
void EmitAssetHashes(const std::filesystem::path& romPath, const std::filesystem::path& outputPath);
// How many slots differ from the baseline hashes - a missing baseline entry counts as
// changed. The port-side extractor uses it to size its progress bar to the real romhack
// delta instead of every vanilla slot.
size_t CountModifiedSlots(const std::vector<uint8_t>& rom, const std::filesystem::path& hashesYamlPath);
// Baseline SHA-1 for one slot, or empty if there's no hashes.yaml or no entry for it.
// Loaded lazily from gAssetPath/hashes.yaml on the first call, then held for the run.
const std::string& GetBaselineAssetHash(uint32_t assetId);
// Vanilla warp destination (MAP << 8 | ENTRY) for a warp-table index, from the
// `warps:` section of hashes.yaml. Returns -1 if unknown. Loaded lazily like the
// baseline hashes.
int GetVanillaWarpDest(uint32_t warpIndex);
} // namespace BK64
|