summaryrefslogtreecommitdiff
path: root/src/KingSystem/Resource/resInfoContainer.h
blob: 0370ed5d4b1aa24dcd08c289f0d0140148f03561 (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
#pragma once

#include <basis/seadTypes.h>
#include <container/seadBuffer.h>
#include <prim/seadSafeString.h>
#include "KingSystem/Resource/resHandle.h"
#include "KingSystem/Utils/Types.h"

namespace ksys::res {

class ResourceInfoContainer {
public:
    ResourceInfoContainer();
    virtual ~ResourceInfoContainer();

    bool loadResourceSizeTable();

    u32 getResourceSize(const sead::SafeString& name) const;

    u32 getResourceSize(const sead::SafeString& prefix, const sead::SafeString& name) const {
        sead::FormatFixedSafeString<128> canonical_name{"%s%s", prefix.cstr(), name.cstr()};
        return getResourceSize(canonical_name);
    }

private:
    struct ResEntry {
        static s32 compareT(const ResEntry* lhs, const ResEntry* rhs) {
            if (*lhs > *rhs)
                return 1;
            if (*lhs < *rhs)
                return -1;
            return 0;
        }

        bool operator<(const ResEntry& other) const { return res_name_hash < other.res_name_hash; }
        bool operator>(const ResEntry& other) const { return res_name_hash > other.res_name_hash; }
        u32 res_name_hash;
        s32 res_size;
    };

    struct ResStringEntry {
        s32 compare(const sead::SafeString& name) const;

        char res_name[128];
        s32 res_size;
    };

    Handle mRstbHandle;
    sead::Buffer<const ResEntry> mEntries;
    sead::Buffer<const ResStringEntry> mStringEntries;
};
KSYS_CHECK_SIZE_NX150(ResourceInfoContainer, 0x78);

}  // namespace ksys::res