mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 18:54:05 +02:00
refactor: Simplify early exit in is_l4d2_lump_order
This commit is contained in:
parent
70529b9d15
commit
e6df84889b
1 changed files with 1 additions and 6 deletions
|
|
@ -83,15 +83,13 @@ impl Directories {
|
||||||
// Heuristic 1: Check lump versions (read into `offset` field assuming standard order).
|
// Heuristic 1: Check lump versions (read into `offset` field assuming standard order).
|
||||||
// Real lump versions are small integers (usually 0 or 1).
|
// Real lump versions are small integers (usually 0 or 1).
|
||||||
// Real file offsets are usually large and 4-byte aligned.
|
// Real file offsets are usually large and 4-byte aligned.
|
||||||
let mut definitely_not_l4d2 = false;
|
|
||||||
let mut maybe_l4d2 = false;
|
let mut maybe_l4d2 = false;
|
||||||
|
|
||||||
for lump in self.entries.iter() {
|
for lump in self.entries.iter() {
|
||||||
// If the value read into `offset` is large, it's likely a real offset.
|
// If the value read into `offset` is large, it's likely a real offset.
|
||||||
// Assume any value > 20 is not a lump version. Max known lump version is much lower.
|
// Assume any value > 20 is not a lump version. Max known lump version is much lower.
|
||||||
if lump.offset > 20 {
|
if lump.offset > 20 {
|
||||||
definitely_not_l4d2 = true;
|
return false; // Can confidently say it's standard order.
|
||||||
break; // Can confidently say it's standard order.
|
|
||||||
}
|
}
|
||||||
// If it's a potential version (<= 20) and it's non-zero and not 4-byte aligned,
|
// If it's a potential version (<= 20) and it's non-zero and not 4-byte aligned,
|
||||||
// it strongly suggests it's a real version read into the wrong field (L4D2 order).
|
// it strongly suggests it's a real version read into the wrong field (L4D2 order).
|
||||||
|
|
@ -100,9 +98,6 @@ impl Directories {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if definitely_not_l4d2 {
|
|
||||||
return false; // Found strong evidence against L4D2 order.
|
|
||||||
}
|
|
||||||
if maybe_l4d2 {
|
if maybe_l4d2 {
|
||||||
return true; // Found evidence for L4D2 order and no counter-evidence.
|
return true; // Found evidence for L4D2 order and no counter-evidence.
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue