Files
botw/lib/EventFlow/include/ore/ResDic.h
T
Léo Lam 18c60323a9 Switch to subrepos
git subrepo clone https://github.com/open-ead/sead lib/sead

subrepo:
  subdir:   "lib/sead"
  merged:   "1b66e825d"
upstream:
  origin:   "https://github.com/open-ead/sead"
  branch:   "master"
  commit:   "1b66e825d"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"

git subrepo clone (merge) https://github.com/open-ead/nnheaders lib/NintendoSDK

subrepo:
  subdir:   "lib/NintendoSDK"
  merged:   "9ee21399f"
upstream:
  origin:   "https://github.com/open-ead/nnheaders"
  branch:   "master"
  commit:   "9ee21399f"
git-subrepo:
  version:  "0.4.3"
  origin:   "ssh://git@github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"

git subrepo clone https://github.com/open-ead/agl lib/agl

subrepo:
  subdir:   "lib/agl"
  merged:   "7c063271b"
upstream:
  origin:   "https://github.com/open-ead/agl"
  branch:   "master"
  commit:   "7c063271b"
git-subrepo:
  version:  "0.4.3"
  origin:   "ssh://git@github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"

git subrepo clone https://github.com/open-ead/EventFlow lib/EventFlow

subrepo:
  subdir:   "lib/EventFlow"
  merged:   "c35d21b34"
upstream:
  origin:   "https://github.com/open-ead/EventFlow"
  branch:   "master"
  commit:   "c35d21b34"
git-subrepo:
  version:  "0.4.3"
  origin:   "ssh://git@github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"
2022-03-21 21:31:42 +01:00

63 lines
1.8 KiB
C++

#pragma once
#include <ore/BinaryFile.h>
#include <ore/StringView.h>
#include <ore/Types.h>
namespace ore {
struct ResEndian;
struct ResDicEntry {
StringView GetKey() const { return *name.Get(); }
// Bits 3-7: index of the byte that should be checked
// Bits 0-2: index of the bit in that byte
int compact_bit_idx;
u16 next_indices[2];
BinTPtr<BinString> name;
};
struct ResDic {
static int FindRefBit(const StringView& str1, const StringView& str2);
const ResDicEntry* FindEntry(const StringView& key) const {
auto* prev = &entries[0];
auto* entry = &entries[prev->next_indices[0]];
while (prev->compact_bit_idx < entry->compact_bit_idx) {
const int bit_idx = entry->compact_bit_idx;
long bit = 0;
if (u32(key.length()) > u32(bit_idx >> 3))
bit = ((key[key.length() + -((bit_idx >> 3) + 1)] >> (bit_idx & 7))) & 1;
prev = entry;
entry = &entries[prev->next_indices[bit]];
}
return entry;
}
/// Returns the index for the specified key or -1 if it cannot be found.
int FindIndex(const StringView& key) const {
const auto* entry = FindEntry(key);
const auto entry_name = entry->GetKey();
bool ok = [&] { return StringView(key.data(), key.length()) == entry_name; }();
if (!ok)
return -1;
return static_cast<int>(entry - &GetEntries()[1]);
}
/// Entry 0 is the root entry.
ResDicEntry* GetEntries() { return entries; }
/// Entry 0 is the root entry.
const ResDicEntry* GetEntries() const { return entries; }
u32 magic;
int num_entries;
ResDicEntry entries[1];
// Followed by ResDicEntry[num_entries].
};
void SwapEndian(ResEndian* endian, ResDic* dic);
} // namespace ore