Scheduled system upgrade on Sunday 21 April 2024 15:00-16:00 UTC - On that day, the wiki and other services might go down for 5-15 minutes.

ResourceSizeTable.product.rsizetable and Module:AocUtils: Difference between pages

From ZeldaMods (Breath of the Wild)
(Difference between pages)
Jump to navigation Jump to search
imported>Leoetlino
m (→‎Name table (optional): fix new line)
 
imported>Leoetlino
No edit summary
 
Line 1: Line 1:
{{Resloc|path=System/Resource/ResourceSizeTable.product.rsizetable}}
local pack = {}
'''ResourceSizeTable.product.rsizetable''' is the file where the [[resource size table]] is stored.


== Structure ==
aoc_resource_prefixes = {
Sections are listed in the order they appear in the file.
  "^Terrain/A/AocField",
  "^UI/StaffRollDLC/",
  "^Map/MainField/",
  "^Map/MainFieldDungeon/",
  "^Map/AocField/",
  "^Physics/StaticCompound/AocField/",
  "^Physics/StaticCompound/MainFieldDungeon/",
  "^Movie/Demo6",
  "^Game/AocField/",
  "^NavMesh/AocField/",
  "^NavMesh/MainFieldDungeon/",
  "^Physics/TeraMeshRigidBody/AocField/",
  "^Voice/.+/Stream_Demo6.+/.+\.bfstm$",
  "^System/AocVersion\.txt$",
  "^Pack/RemainsWind.pack$",
  "^Pack/RemainsElectric.pack$",
  "^Pack/RemainsWater.pack$",
  "^Pack/RemainsFire.pack$",
  "^Pack/FinalTrial.pack$",
}


=== Header (optional) ===
function should_use_aoc_path(path)
<syntaxhighlight lang="c++">
  for i, p in ipairs(aoc_resource_prefixes) do
struct RstbHeader {
    if string.find(path, p) then
  u32 magic;          // 'RSTB'
      return true
   u32 crc32TableSize;  // number of entries - can be 0 to indicate there is no crc32 table
    end
   u32 nameTableSize;  // number of entries - can be 0 to indicate there is no name table
   end
}; // sizeof() = 12
   return false
</syntaxhighlight>
end


If the header is missing or if the magic is not correct, the game will assume there is simply no header. In that case, the game will use the size of the RSTB file, divide it by 8 to get the number of crc32 table entries and assume the whole file is a crc32 table.  
return pack
 
=== CRC32 table (optional) ===
This is a mapping of CRC32 values to resource sizes. The table must be sorted; otherwise the game will not be able to search for entries properly.
 
<syntaxhighlight lang="c++">
struct RstbCrc32TableEntry {
  u32 crc32;
  u32 size;
};  // sizeof() = 8
</syntaxhighlight>
 
=== Name table (optional) ===
This is a mapping of resource paths (strings) to resource sizes. This table is optional and is used whenever there would be conflicts in the crc32 table. Only usable if there is a RSTB header.
 
<syntaxhighlight lang="c++">
struct RstbCrc32NameEntry {
  char name[128];
  u32 size;
};  // sizeof() = 132
</syntaxhighlight>
 
== Game usage ==
The table is loaded very early in the app init process by ResourceInfoContainer (part of [[res::ResourceMgrTask]]) when the resource task starts and queried by the resource system and several other [[subsystems]] afterwards.
 
=== Lookup logic ===
<code>ResourceInfoContainer::getResourceSize</code> (non official name) starts by computing the CRC32 for the resource name/path.
 
Note: Resources that are ''explicitly'' loaded from the add-on content file device will have <code>Aoc/0010/</code> prepended to their resource path on Switch and Wii U as explained in the [[resource system]] article.
 
If a CRC32 table is present, the game will perform a binary search to find an entry for the calculated hash. If an entry is found, <code>entry.size</code> is returned.
 
Otherwise, if a name table is present, the game will go down the table until an entry that matches the specified resource name is found. If an entry is found, <code>entry.size</code> is returned.
 
Otherwise, the game returns 0.
 
=== Checks ===
The RSTB is queried by several subsystems:
* TipsMgr and EventResource use it only to check if the file they want to load exists (by checking if ret != 0).
* EffectResource, when loading Effect/Game.esetlist: must not be zero.
* VfxResourceMgr, when loading Effect/%s.esetlist files: must not be zero.
* bfres loading code at 0x7100FE3978 (v1.5.0): unclear, but must not be zero. It appears to check whether the file size listed in the RSTB is larger than the heap size.
* res::ResourceMgrTask::getHeapSizeForResLoad (0x710120BDE0 in v1.5.0): called during resource load.<syntaxhighlight lang="c++">
constant = 0x128 + 0x40;
if (auto* entry_factory = dynamic_cast<res::EntryFactoryBase*>(factory))
  resSize2 = entry_factory->getResourceSize(param->factory) + constant;
else
  resSize2 = sizeof(sead::DirectResource) + constant; // 0x20 + 0x168 = 0x188
 
totalSize = in->allocSize + resSize2;  // in this branch, in->allocSize seems to be always zero...
if (totalSize <= sizeInTable)
  out->readHeapSize = loadDataAlignment + sizeInTable + sizeof(void*);
else
  out->readHeapSize = (unsigned int)(float)(loadDataAlignment + totalSize + sizeof(void*));
</syntaxhighlight>
* 0x7100FE1630 (v1.5.0): unclear. If the file is loaded by the resource memory or loading thread, or if the file size listed in the RSTB is larger than a TempResourceLoader field, the game prints: "Texture archive size: %u MB" (translated from Japanese).
 
[[Category:Content (BotW)]]
[[Category:File formats]]

Revision as of 18:56, 8 September 2018

Documentation for this module may be created at Module:AocUtils/doc

local pack = {}

aoc_resource_prefixes = {
  "^Terrain/A/AocField",
  "^UI/StaffRollDLC/",
  "^Map/MainField/",
  "^Map/MainFieldDungeon/",
  "^Map/AocField/",
  "^Physics/StaticCompound/AocField/",
  "^Physics/StaticCompound/MainFieldDungeon/",
  "^Movie/Demo6",
  "^Game/AocField/",
  "^NavMesh/AocField/",
  "^NavMesh/MainFieldDungeon/",
  "^Physics/TeraMeshRigidBody/AocField/",
  "^Voice/.+/Stream_Demo6.+/.+\.bfstm$",
  "^System/AocVersion\.txt$",
  "^Pack/RemainsWind.pack$",
  "^Pack/RemainsElectric.pack$",
  "^Pack/RemainsWater.pack$",
  "^Pack/RemainsFire.pack$",
  "^Pack/FinalTrial.pack$",
}

function should_use_aoc_path(path)
  for i, p in ipairs(aoc_resource_prefixes) do
    if string.find(path, p) then
      return true
    end
  end
  return false
end

return pack