mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Added support for assets with vram offsets
This commit is contained in:
+15
-3
@@ -288,6 +288,13 @@ void Companion::ParseCurrentFileConfig(YAML::Node node) {
|
||||
this->gTables.push_back({name, start, end, tMode});
|
||||
}
|
||||
}
|
||||
|
||||
if(node["vram"]){
|
||||
auto vram = node["vram"];
|
||||
const auto addr = GetSafeNode<uint32_t>(vram, "addr");
|
||||
const auto offset = GetSafeNode<uint32_t>(vram, "offset");
|
||||
this->gCurrentVram = { addr, offset };
|
||||
}
|
||||
}
|
||||
|
||||
void Companion::Process() {
|
||||
@@ -512,6 +519,8 @@ void Companion::Process() {
|
||||
this->gConfig.segment.local.clear();
|
||||
this->gFileHeader.clear();
|
||||
this->gCurrentPad = 0;
|
||||
this->gCurrentVram = std::nullopt;
|
||||
this->gCurrentSegmentNumber = 0;
|
||||
this->gTables.clear();
|
||||
GFXDOverride::ClearVtx();
|
||||
|
||||
@@ -555,9 +564,10 @@ void Companion::Process() {
|
||||
this->ExtractNode(node, output, wrapper);
|
||||
}
|
||||
} else {
|
||||
const auto offset = assetNode["offset"].as<uint32_t>();
|
||||
if(gCurrentFileOffset) {
|
||||
if (IS_SEGMENTED(assetNode["offset"].as<uint32_t>()) == false) {
|
||||
assetNode["offset"] = (gCurrentSegmentNumber << 24) | assetNode["offset"].as<uint32_t>();
|
||||
if (IS_SEGMENTED(offset) == false) {
|
||||
assetNode["offset"] = (gCurrentSegmentNumber << 24) | offset;
|
||||
}
|
||||
}
|
||||
std::string output = (this->gCurrentDirectory / entryName).string();
|
||||
@@ -735,7 +745,9 @@ void Companion::Pack(const std::string& folder, const std::string& output) {
|
||||
}
|
||||
|
||||
std::optional<std::tuple<std::string, YAML::Node>> Companion::RegisterAsset(const std::string& name, YAML::Node& node) {
|
||||
if(!node["offset"]) return std::nullopt;
|
||||
if(!node["offset"]) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
this->gAssetDependencies[this->gCurrentFile][name] = std::make_pair(node, false);
|
||||
|
||||
|
||||
@@ -46,6 +46,11 @@ struct Table {
|
||||
TableMode mode;
|
||||
};
|
||||
|
||||
struct VRAMEntry {
|
||||
uint32_t addr;
|
||||
uint32_t offset;
|
||||
};
|
||||
|
||||
struct GBIConfig {
|
||||
GBIVersion version = GBIVersion::f3d;
|
||||
GBIMinorVersion subversion = GBIMinorVersion::None;
|
||||
@@ -94,6 +99,7 @@ public:
|
||||
std::optional<std::uint32_t> GetCurrSegmentNumber(void) const { return this->gCurrentSegmentNumber; };
|
||||
CompressionType GetCurrCompressionType(void) const { return this->gCurrentCompressionType; };
|
||||
CompressionType GetCompressionType(std::vector<uint8_t>& buffer, const uint32_t offset);
|
||||
std::optional<VRAMEntry> GetCurrentVRAM(void) const { return this->gCurrentVram; };
|
||||
std::optional<Table> SearchTable(uint32_t addr);
|
||||
|
||||
static std::string CalculateHash(const std::vector<uint8_t>& data);
|
||||
@@ -117,6 +123,7 @@ private:
|
||||
uint32_t gCurrentPad = 0;
|
||||
uint32_t gCurrentFileOffset;
|
||||
uint32_t gCurrentSegmentNumber;
|
||||
std::optional<VRAMEntry> gCurrentVram;
|
||||
CompressionType gCurrentCompressionType;
|
||||
std::vector<Table> gTables;
|
||||
std::variant<std::vector<std::string>, std::string> gWriteOrder;
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
|
||||
#define SEGMENT_OFFSET(a) ((uint32_t)(a) & 0x00FFFFFF)
|
||||
#define SEGMENT_NUMBER(x) (((uint32_t)(x) >> 24) & 0xFF)
|
||||
#define IS_SEGMENTED(x) (((uint32_t)(x) > 0x01000000) && (SEGMENT_NUMBER(x) < 0x20))
|
||||
// I would love to use 0x01000000, but the stupid compiler takes it as 0x01
|
||||
#define IS_SEGMENTED(x) (((uint32_t)(x) > 16777216) && (SEGMENT_NUMBER(x) < 0x20))
|
||||
|
||||
#define tab "\t"
|
||||
#define fourSpaceTab " "
|
||||
|
||||
@@ -91,6 +91,16 @@ uint32_t Decompressor::TranslateAddr(uint32_t addr, bool baseAddress){
|
||||
return segment.value() + (!baseAddress ? SEGMENT_OFFSET(addr) : 0);
|
||||
}
|
||||
|
||||
const auto vramEntry = Companion::Instance->GetCurrentVRAM();
|
||||
|
||||
if(vramEntry.has_value()){
|
||||
const auto vram = vramEntry.value();
|
||||
|
||||
if(addr >= vram.addr){
|
||||
return vram.offset + (addr - vram.addr);
|
||||
}
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user