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