Fixed lights this time i hope

This commit is contained in:
KiritoDv
2024-08-17 17:37:48 -06:00
parent ab4d83223f
commit 1f3bdf8a4e
2 changed files with 23 additions and 12 deletions
+19 -8
View File
@@ -328,14 +328,13 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP
}
}
// TODO: Fix this opcode
if(opcode == GBI(G_MOVEMEM)) {
// TODO: Fix this opcode
continue;
auto ptr = w1;
auto dec = Companion::Instance->GetNodeByAddr(ptr);
uint8_t index = 0;
uint8_t offset = 0;
bool hasOffset = false;
switch (gbi) {
case GBIVersion::f3d:
@@ -347,21 +346,33 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP
offset = C0(8, 8) * 8;
break;
}
auto res = Companion::Instance->GetNodeByAddr(ptr);
if(!res.has_value()){
res = Companion::Instance->GetNodeByAddr(ptr - 0x8);
hasOffset = res.has_value();
if(!hasOffset){
SPDLOG_INFO("Could not find light {:X}", ptr);
// throw std::runtime_error("Could not find light");
}
}
w0 &= 0x00FFFFFF;
w0 += G_MOVEMEM_OTR_HASH << 24;
w1 = _SHIFTL(index, 24, 8) | _SHIFTL(offset, 16, 8);
w1 = _SHIFTL(index, 24, 8) | _SHIFTL(offset, 16, 8) | _SHIFTL((uint8_t)(hasOffset ? 1 : 0), 8, 8);
writer.Write(w0);
writer.Write(w1);
if(dec.has_value()){
uint64_t hash = CRC64(std::get<0>(dec.value()).c_str());
SPDLOG_INFO("Found movemem: 0x{:X} Hash: 0x{:X} Path: {}", ptr, hash, std::get<0>(dec.value()));
if(res.has_value()){
uint64_t hash = CRC64(std::get<0>(res.value()).c_str());
SPDLOG_INFO("Found movemem: 0x{:X} Hash: 0x{:X} Path: {}", ptr, hash, std::get<0>(res.value()));
w0 = hash >> 32;
w1 = hash & 0xFFFFFFFF;
} else {
SPDLOG_WARN("Could not find movemem at 0x{:X}", ptr);
SPDLOG_WARN("Could not find light at 0x{:X}", ptr);
}
}
+4 -4
View File
@@ -133,9 +133,9 @@ std::optional<std::shared_ptr<IParsedData>> LightsFactory::parse(std::vector<uin
// Directional light
// Ambient
auto r = (uint8_t)reader.ReadInt8();
auto g = (uint8_t)reader.ReadInt8();
auto b = (uint8_t)reader.ReadInt8();
auto r = reader.ReadUByte();
auto g = reader.ReadUByte();
auto b = reader.ReadUByte();
//auto nil = reader.ReadInt32();
reader.Seek(5, LUS::SeekOffsetType::Current);
@@ -153,7 +153,7 @@ std::optional<std::shared_ptr<IParsedData>> LightsFactory::parse(std::vector<uin
// TODO: This is a hack, but it works for now.
// The struct has several copies/padding. The zeros skip those for gdSPDefLights1.
lights = {r, g, b, 0, 0, 0, 0, 0, r2, g2, b2, 0, 0, 0, 0, 0, x, y, z};
lights = {r, g, b, 0, r, g, b, 0, r2, g2, b2, 0, r2, g2, b2, 0, x, y, z};
return std::make_shared<LightsData>(lights);
}