summaryrefslogtreecommitdiff
path: root/src/input/gc/GameCubeInput.h
blob: 66962ed6b9f44a82474d3b982f137797835b32cb (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
#pragma once

#include "input/InputSource.h"
#include "GcmDisc.h"

#include <filesystem>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

namespace GC {

struct Window {
    uint32_t segment;
    uint32_t imageOffset;
    uint32_t size;
};

class GameCubeInput : public InputSource {
public:
    explicit GameCubeInput(std::shared_ptr<IDiscFileSystem> disc) : mDisc(std::move(disc)) {}

    static std::shared_ptr<GameCubeInput> FromPath(const std::filesystem::path& path);
    static std::shared_ptr<GameCubeInput> FromMemory(std::vector<uint8_t>& data);

    void Open() override;
    void Build(YAML::Node& rom) override;

    std::string GetHash() override { return mDolHash; }
    std::string GetTitle() override { return mTitle; }
    uint32_t GetVersionCRC() override { return mVersionCRC; }
    std::vector<uint8_t>& GetImage() override { return mImage; }
    void LogInfo() override;

    const std::vector<Window>& GetWindows() const { return mWindows; }
    const std::unordered_map<std::string, std::string>& GetRelHashSemantics() const { return mRelHashSemantics; }

private:
    struct Placement {
        uint32_t segment;
        uint32_t offset;
        std::vector<uint8_t> data;
        std::vector<std::string> names;
    };

    void PlaceDol(YAML::Node node, std::vector<Placement>& out);
    void PlaceRel(YAML::Node node, std::vector<Placement>& out);
    void PlaceFile(YAML::Node node, std::vector<Placement>& out);
    void Assemble(std::vector<Placement>& placements);

    std::shared_ptr<IDiscFileSystem> mDisc;
    std::vector<uint8_t> mDol;
    std::string mDolHash;
    std::string mTitle;
    uint8_t mRevision = 0;
    uint32_t mVersionCRC = 0;
    std::vector<uint8_t> mImage;
    std::vector<Window> mWindows;
    std::unordered_map<std::string, std::string> mRelHashSemantics;
};

std::string Sha1Hex(const std::vector<uint8_t>& data);

} // namespace GC