Torch
Loading...
Searching...
No Matches
MapFactory.h
1#pragma once
2
3#include <factories/BaseFactory.h>
4#include <vector>
5
6namespace BK64 {
7
32typedef struct NodeProp {
33 int16_t position[3]; // X, Y, Z world position (s16)
34 uint16_t radius : 9; // selector_or_radius: trigger/volume radius
35 uint16_t bit6 : 6; // category (6=actor, 7=warp, 9=trigger, 0xA=event)
36 uint16_t bit0 : 1; // active/enabled
37 uint16_t unk8; // actorId — meaning depends on category
38 uint8_t unkA; // markerId: index into the ActorMarker lookup table
39 uint8_t padB; // padding
40 uint32_t yaw : 9; // spawn Y rotation; *2 for degrees (0-511 → 0-1022°)
41 uint32_t scale : 23; // spawn scale, fixed point (/1000.0 for the real value)
42 uint32_t unk10_31 : 12; // secondary ID or overlay-specific param
43 uint32_t unk10_19 : 12; // more params (animation phase, variant, ...)
44 uint32_t pad10_7 : 1; // padding
45 uint32_t unk10_6 : 1; // "initialized" flag, set at runtime
46 uint32_t pad10_5 : 4; // padding
47 uint32_t unk10_0 : 2; // param passed to func_803303B8
48} NodeProp;
49
64typedef struct ModelProp {
65 uint16_t unk0; // modelId:12, pad0_19:4
66 uint8_t yaw; // Y-axis rotation
67 uint8_t roll; // roll
68 int16_t position[3]; // X, Y, Z world position
69 uint8_t scale; // scale
70 uint8_t flags; // discriminator (isModelProp=1, isActorProp=0)
71} ModelProp;
72
101typedef struct SpriteProp {
102 uint32_t word0;
103 int16_t unk4[3];
104 uint16_t wordA;
105} SpriteProp;
106
122typedef struct ActorProp {
123 uint32_t marker; // ActorMarker* — runtime only
124 int16_t position[3]; // X, Y, Z position cache
125 uint16_t flags; // discriminator (isActorProp=1)
126} ActorProp;
127
138typedef union Prop {
139 ModelProp model;
140 SpriteProp sprite;
141 ActorProp actor;
142 struct {
143 uint32_t pad0;
144 int16_t unk4[3];
145 uint16_t padA_15 : 10;
146 uint16_t unkA_5 : 1;
147 uint16_t unkA_4 : 1;
148 uint16_t unkA_3 : 1;
149 uint16_t unkA_2 : 1;
150 uint16_t is_3d : 1;
151 uint16_t is_actor : 1;
152 };
153 uint8_t raw[12];
154} Prop;
155
163typedef struct CubeData {
164 int32_t x : 5;
165 int32_t y : 5;
166 int32_t z : 5;
167 uint32_t prop1Cnt : 6;
168 uint32_t prop2Cnt : 6;
169 uint32_t unk0_4 : 5; // split point: [0..unk0_4)=spawns, [unk0_4..prop1Cnt)=events
170 std::vector<NodeProp> nodeProps;
171 std::vector<Prop> props;
172} CubeData;
173
183typedef struct CameraNodeType1 {
184 float position[3]; // camera position
185 float horizontalSpeed; // horizontal speed
186 float verticalSpeed; // vertical speed
187 float rotation; // rotation speed
188 float accelaration; // acceleration
189 float pitchYawRoll[3]; // orientation (pitch, yaw, roll)
190 int32_t unknownFlag; // unknown; tested against 1, 2, 4
192
198typedef struct CameraNodeType2 {
199 float position[3]; // camera position
200 float pitchYawRoll[3]; // orientation (pitch, yaw, roll)
202
208typedef struct CameraNodeType3 {
209 float position[3]; // camera position
210 float horizontalSpeed; // horizontal speed
211 float verticalSpeed; // vertical speed
212 float rotation; // rotation speed
213 float accelaration; // acceleration
214 float closeDistance; // near clip distance
215 float farDistance; // far clip distance
216 float pitchYawRoll[3]; // orientation (pitch, yaw, roll)
217 int32_t unknownFlag; // unknown
219
225typedef struct CameraNodeType4 {
226 int32_t unknownFlag; // unknown
228
241typedef struct CameraNode {
242 int16_t index; // node index
243 uint8_t type; // 1=Scripted, 2=Dynamic, 3=Static, 4=Random
244 union {
245 CameraNodeType1 type1;
246 CameraNodeType2 type2;
247 CameraNodeType3 type3;
248 CameraNodeType4 type4;
249 } data;
250} CameraNode;
251
257typedef struct LightingVector {
258 float position[3]; // X, Y, Z light position
259 float fadeRadii[2]; // inner/outer fade distances
260 int32_t rgb[3]; // R, G, B
262
263class MapData : public IParsedData {
264 public:
265 // Cube data section (chunk type 0x01)
266 int32_t mCubeMin[3]; // grid min bounds
267 int32_t mCubeMax[3]; // grid max bounds
268 std::vector<CubeData> mCubes;
269
270 // Camera nodes section (chunk type 0x03)
271 std::vector<CameraNode> mCameraNodes;
272
273 // Lighting section (chunk type 0x04)
274 std::vector<LightingVector> mLightingVectors;
275
276 MapData() {
277 mCubeMin[0] = mCubeMin[1] = mCubeMin[2] = 0;
278 mCubeMax[0] = mCubeMax[1] = mCubeMax[2] = 0;
279 }
280};
281
283 ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName,
284 YAML::Node& node, std::string* replacement) override;
285};
286
288 ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName,
289 YAML::Node& node, std::string* replacement) override;
290};
291
293 ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName,
294 YAML::Node& node, std::string* replacement) override;
295};
296
298 ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName,
299 YAML::Node& node, std::string* replacement) override;
300};
301
302class MapFactory : public BaseFactory {
303 public:
304 std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
305 inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
306 return { REGISTER(Code, MapCodeExporter) REGISTER(Header, MapHeaderExporter) REGISTER(Binary, MapBinaryExporter)
307 REGISTER(Modding, MapModdingExporter) };
308 }
309
310 bool HasModdedDependencies() override {
311 return true;
312 }
313};
314} // namespace BK64
Definition MapFactory.h:287
Definition MapFactory.h:292
Definition MapFactory.h:302
Definition MapFactory.h:282
Definition MapFactory.h:297
Definition BaseFactory.h:96
Definition BaseFactory.h:102
Definition BaseFactory.h:88
Definition MapFactory.h:122
Definition MapFactory.h:183
Definition MapFactory.h:198
Definition MapFactory.h:208
Definition MapFactory.h:225
Definition MapFactory.h:241
Definition MapFactory.h:163
Definition MapFactory.h:257
Definition MapFactory.h:64
Definition MapFactory.h:32
Definition MapFactory.h:101
Definition MapFactory.h:138