Skip to content

Commit dc0c335

Browse files
committed
feat: improve REL::ID not found fail message
1 parent b5ad8b8 commit dc0c335

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

CommonLibF4/include/REL/IDDB.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,7 @@ namespace REL
2424
return singleton;
2525
}
2626

27-
[[nodiscard]] std::size_t id2offset(std::uint64_t a_id) const
28-
{
29-
if (_id2offset.empty()) {
30-
stl::report_and_fail("data is empty"sv);
31-
}
32-
33-
const mapping_t elem{ a_id, 0 };
34-
const auto it = std::lower_bound(
35-
_id2offset.begin(),
36-
_id2offset.end(),
37-
elem,
38-
[](auto&& a_lhs, auto&& a_rhs) {
39-
return a_lhs.id < a_rhs.id;
40-
});
41-
if (it == _id2offset.end()) {
42-
stl::report_and_fail("id not found"sv);
43-
}
44-
45-
return static_cast<std::size_t>(it->offset);
46-
}
27+
[[nodiscard]] std::size_t id2offset(std::uint64_t a_id) const;
4728

4829
protected:
4930
friend class Offset2ID;

CommonLibF4/src/REL/IDDB.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "REL/IDDB.h"
2+
#include "REL/Module.h"
23
#include "REL/Version.h"
34

45
#include "REX/W32/BCRYPT.h"
@@ -105,4 +106,27 @@ namespace REL
105106
*reinterpret_cast<const std::uint64_t*>(_mmap.data())
106107
};
107108
}
109+
110+
std::size_t IDDB::id2offset(std::uint64_t a_id) const
111+
{
112+
if (_id2offset.empty()) {
113+
stl::report_and_fail("data is empty"sv);
114+
}
115+
116+
const mapping_t elem{ a_id, 0 };
117+
const auto it = std::lower_bound(
118+
_id2offset.begin(),
119+
_id2offset.end(),
120+
elem,
121+
[](auto&& a_lhs, auto&& a_rhs) {
122+
return a_lhs.id < a_rhs.id;
123+
});
124+
if (it == _id2offset.end()) {
125+
const auto version = Module::get().version();
126+
const auto str = std::format("id {} not found!\ngame version: {}"sv, a_id, version.string());
127+
stl::report_and_fail(str);
128+
}
129+
130+
return static_cast<std::size_t>(it->offset);
131+
}
108132
}

0 commit comments

Comments
 (0)