Skip to content

Commit

Permalink
Fixed lights this time i hope
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoDv committed Aug 17, 2024
1 parent ab4d832 commit 1f3bdf8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
27 changes: 19 additions & 8 deletions src/factories/DisplayListFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/factories/LightsFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}

0 comments on commit 1f3bdf8

Please sign in to comment.