summaryrefslogtreecommitdiff
path: root/src/factories/fzerox/CourseFactory.h
blob: 28b0ab4c432039274d1c862b4a45e2ce10057fef (plain)
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
#pragma once

#include <factories/BaseFactory.h>

namespace FZX {

// In-Game Structs
typedef struct Vec3fStruct {
    float x, y, z;
} Vec3fStruct;

typedef struct ControlPoint {
    Vec3fStruct pos;
    int16_t radiusLeft;
    int16_t radiusRight;
    int32_t trackSegmentInfo;
} ControlPoint; // size = 0x14

typedef struct CourseRawData {
    int8_t creatorId;
    int8_t controlPointCount;
    int8_t venue;
    int8_t skybox;
    uint32_t checksum;
    int8_t flag;
    char fileName[23];
    ControlPoint controlPoint[64];
    int16_t bankAngle[64];
    int8_t pit[64];
    int8_t dash[64];
    int8_t dirt[64];
    int8_t ice[64];
    int8_t jump[64];
    int8_t landmine[64];
    int8_t gate[64];
    int8_t building[64];
    int8_t sign[64];
} CourseRawData; // size = 0x7E0

// Factory Structs
typedef struct ControlPointInfo {
    ControlPoint controlPoint;
    int16_t bankAngle;
    int8_t pit;
    int8_t dash;
    int8_t dirt;
    int8_t ice;
    int8_t jump;
    int8_t landmine;
    int8_t gate;
    int8_t building;
    int8_t sign;
} ControlPointInfo;

class CourseData : public IParsedData {
public:
    int8_t mCreatorId;
    int8_t mVenue;
    int8_t mSkybox;
    int8_t mFlag;
    std::vector<char> mFileName;
    int8_t mBgm;
    std::vector<ControlPointInfo> mControlPointInfos;

    CourseData(int8_t creatorId, int8_t venue, int8_t skybox, int8_t flag, std::vector<char> fileName, int8_t bgm, std::vector<ControlPointInfo> controlPointInfos) :
        mCreatorId(creatorId),
        mVenue(venue),
        mSkybox(skybox),
        mFlag(flag),
        mFileName(std::move(fileName)),
        mBgm(bgm),
        mControlPointInfos(std::move(controlPointInfos)) {}

    uint32_t CalculateChecksum(void);
};

class CourseHeaderExporter : public BaseExporter {
    ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};

class CourseBinaryExporter : public BaseExporter {
    ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};

class CourseCodeExporter : public BaseExporter {
    ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};

class CourseModdingExporter : public BaseExporter {
    ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};

class CourseFactory : public BaseFactory {
public:
    std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
    std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override;
    inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
        return {
            REGISTER(Code, CourseCodeExporter)
            REGISTER(Header, CourseHeaderExporter)
            REGISTER(Binary, CourseBinaryExporter)
            REGISTER(Modding, CourseModdingExporter)
        };
    }
    bool SupportModdedAssets() override { return true; }
};
} // namespace FZX