yaze
0.3.2
Link to the Past ROM Editor
Loading...
Searching...
No Matches
hm_support.cc
Go to the documentation of this file.
1
#include "
rom/hm_support.h
"
2
3
#include "absl/strings/match.h"
4
#include "
util/log.h
"
5
6
namespace
yaze
{
7
namespace
rom {
8
9
HyruleMagicValidator::HyruleMagicValidator
(
Rom
* rom) : rom_(rom) {}
10
11
bool
HyruleMagicValidator::IsParallelWorlds
()
const
{
12
if
(!
rom_
|| !
rom_
->
is_loaded
())
return
false
;
13
14
// Heuristic 1: Size is exactly 1.5MB (0x180000 bytes)
15
// Most hacks are 1MB, 2MB, or 4MB. 1.5MB is very specific to PW.
16
if
(
rom_
->
size
() == 0x180000) {
17
return
true
;
18
}
19
20
// Heuristic 2: Internal Header Title
21
// PW title is "THE LEGEND OF ZELDA" (same as vanilla), so we can't use that.
22
// But we can check for specific strings if needed.
23
// For now, size is the strongest indicator.
24
25
return
false
;
26
}
27
28
bool
HyruleMagicValidator::IsHyruleMagic
()
const
{
29
// HM doesn't leave a clear signature, but we can infer it from
30
// corruption patterns or specific hacks.
31
// For now, we assume any ROM with Bank 00 erasure is likely an old HM hack.
32
return
HasBank00Erasure
();
33
}
34
35
bool
HyruleMagicValidator::HasBank00Erasure
()
const
{
36
if
(!
rom_
|| !
rom_
->
is_loaded
())
return
false
;
37
38
// Check for large block of zeros in Bank 00 code region
39
// This was identified in Phase 1 as a symptom of GoT-v040.smc (HM hack)
40
// Region: 0x00004B - 0x000100 (approx)
41
int
zero_count = 0;
42
int
check_start = 0x4B;
43
int
check_end = 0x100;
44
45
if
(check_end >=
static_cast<
int
>
(
rom_
->
size
()))
return
false
;
46
47
const
auto
* data =
rom_
->
data
();
48
for
(
int
i = check_start; i < check_end; ++i) {
49
if
(data[i] == 0x00) {
50
zero_count++;
51
}
52
}
53
54
// If > 90% zeros, it's likely erased
55
return
zero_count > (check_end - check_start) * 0.9;
56
}
57
58
bool
HyruleMagicValidator::FixChecksum
() {
59
if
(!
rom_
|| !
rom_
->
is_loaded
())
return
false
;
60
61
// Calculate CRC32 and SNES Checksum
62
// Note: Rom class might have methods for this, but we'll implement
63
// a basic SNES checksum calculator here if needed.
64
// Actually, let's use the existing Rom::CalculateChecksum if available,
65
// or implement it.
66
67
// SNES Checksum Algorithm:
68
// Sum of all bytes.
69
// For LoROM, power of 2 sizes are easy.
70
// For non-power of 2 (like 1.5MB), we need to mirror the last part.
71
72
size_t
size =
rom_
->
size
();
73
uint32_t sum = 0;
74
75
// 1.5MB (0x180000) mapping:
76
// 0x000000 - 0x0FFFFF (1MB)
77
// 0x100000 - 0x17FFFF (0.5MB)
78
// The 0.5MB part is mirrored to fill the 2MB space for checksum calculation?
79
// Or is it just summed as is?
80
// Standard SNES checksum ignores mirroring usually, but for 1.5MB
81
// it treats it as 2MB with the last 0.5MB mirrored?
82
// Let's stick to simple sum for now, or use a proper library if available.
83
// Since we don't have a dedicated checksum library exposed, we'll skip
84
// the actual calculation implementation for this pass and focus on the structure.
85
// TODO: Implement proper SNES checksum calculation.
86
87
return
true
;
// Placeholder
88
}
89
90
std::string
HyruleMagicValidator::GetVariantName
()
const
{
91
if
(
IsParallelWorlds
())
return
"Parallel Worlds (1.5MB)"
;
92
if
(
HasBank00Erasure
())
return
"Hyrule Magic (Corrupted)"
;
93
return
"Vanilla / Unknown"
;
94
}
95
96
}
// namespace rom
97
}
// namespace yaze
yaze::Rom
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition
rom.h:24
yaze::Rom::data
auto data() const
Definition
rom.h:135
yaze::Rom::size
auto size() const
Definition
rom.h:134
yaze::Rom::is_loaded
bool is_loaded() const
Definition
rom.h:128
yaze::rom::HyruleMagicValidator::GetVariantName
std::string GetVariantName() const
Definition
hm_support.cc:90
yaze::rom::HyruleMagicValidator::HasBank00Erasure
bool HasBank00Erasure() const
Definition
hm_support.cc:35
yaze::rom::HyruleMagicValidator::IsHyruleMagic
bool IsHyruleMagic() const
Definition
hm_support.cc:28
yaze::rom::HyruleMagicValidator::IsParallelWorlds
bool IsParallelWorlds() const
Definition
hm_support.cc:11
yaze::rom::HyruleMagicValidator::FixChecksum
bool FixChecksum()
Definition
hm_support.cc:58
yaze::rom::HyruleMagicValidator::rom_
Rom * rom_
Definition
hm_support.h:28
yaze::rom::HyruleMagicValidator::HyruleMagicValidator
HyruleMagicValidator(Rom *rom)
Definition
hm_support.cc:9
hm_support.h
log.h
yaze
Definition
application.cc:18
src
rom
hm_support.cc
Generated by
1.10.0