Skip to content

Commit 4e8093b

Browse files
committed
allow looking up espec entries
1 parent 13a06e2 commit 4e8093b

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

TACTLib/Core/EncodingHandler.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public bool TryGetContentSize(CKey cKey, out uint contentSize) {
162162
return true;
163163
}
164164

165-
public int GetEncodedSize(FullEKey ekey) {
165+
private bool TryGetEKeyESpecEntry(FullEKey ekey, out EKeyESpecEntry foundEntry) {
166166
var searchResult = Array.BinarySearch(EKeyESpecHeaderKeys, ekey);
167167

168168
int pageIndex;
@@ -181,13 +181,33 @@ public int GetEncodedSize(FullEKey ekey) {
181181
var foundIndex = Array.BinarySearch(entries, speculativeEntry);
182182

183183
if (foundIndex >= 0) {
184-
return (int)entries[foundIndex].FileSize.ToInt();
184+
foundEntry = entries[foundIndex];
185+
return true;
185186
}
186-
187+
187188
NOT_FOUND:
188-
Logger.Warn(nameof(EncodingHandler), $"Unable to get ESize for {ekey.ToHexString()}. This should not happen (and will crash static containers)");
189-
//Console.Out.WriteLine($"cant get size for {ekey.ToHexString()}. a o");
190-
return 0;
189+
foundEntry = default;
190+
return false;
191+
}
192+
193+
public int GetEncodedSize(FullEKey ekey) {
194+
if (!TryGetEKeyESpecEntry(ekey, out var foundEntry))
195+
{
196+
Logger.Warn(nameof(EncodingHandler), $"Unable to get ESize for {ekey.ToHexString()}. This should not happen (and will crash static containers)");
197+
//Console.Out.WriteLine($"cant get size for {ekey.ToHexString()}. a o");
198+
return 0;
199+
}
200+
201+
return checked((int)foundEntry.FileSize.ToInt());
202+
}
203+
204+
public int? GetESpecIndex(FullEKey ekey) {
205+
if (!TryGetEKeyESpecEntry(ekey, out var foundEntry))
206+
{
207+
return null;
208+
}
209+
210+
return checked((int)foundEntry.ESpecIndex.ToInt());
191211
}
192212

193213
public IEnumerable<CKey> GetCKeys() {

0 commit comments

Comments
 (0)