Skip to content

Resource loading order

yvt edited this page Sep 24, 2020 · 6 revisions

Terminology

  • loose files: files which are not packaged and put directly in a Resources directory or one of its subdirectories are called loose files.
  • packed files: files packaged into .pak are called packed files.
  • pak files: packages including one or more packed files. They have the extension .pak (or .zip, as of 0.0.13).

Resource Search Order

Suppose the program wants to load a texture from the path Textures/SomeTexture.png...

  1. OpenSpades searches loose files in the user-specific Resources directory.
    • C:\Users\myusername\AppData\Roaming\OpenSpades\Resources\Textures\SomeTexture.png
    • /home/myusername/.local/openspades/Resources/Textures/SomeTexture.png FIXME: needs verification
  2. OpenSpades searches loose files in the global Resources directory that is located near the executable file.
    • E:\Downloads\OpenSpades-0.0.42\Resources\Textures\SomeTexture.png
    • /usr/local/share/games/openspades/Resources/Textures/SomeTexture.png
  3. And then OpenSpades searches every pak files in the following order: first, paks whose file name does not look like pak0123456789.pak, in alphabetic order. (note: Pak files are detected using the method of the step one and two.)
    • Textures/SomeTexture.png inside E:\Downloads\OpenSpades-0.0.42\Resources\CupcakesGunMod.pak
    • Textures/SomeTexture.png inside E:\Downloads\OpenSpades-0.0.42\Resources\CupcakesGunMod2.pak (only if the above one wasn't found)
  4. Second, paks whose file name looks like pak0123456789-xxxx.pak, in the reverse order of the number.
    • Textures/SomeTexture.png inside E:\Downloads\OpenSpades-0.0.42\Resources\pak020-NewerDefaultAssets.pak
    • Textures/SomeTexture.png inside E:\Downloads\OpenSpades-0.0.42\Resources\pak010-OlderDefaultAssets.pak (only if the above one wasn't found)
  5. If the file is not found yet at this point, the suffix .weak is appended to the file name, and the steps 1-4 are tried again.

In this way,

  • Users can override the standard behavior just by copying something.pak into one of Resources directories.
  • Patching the official package becomes easier by using the next index number (ex. pak010-0.14.0-patch.pak, pak011-0.14.1-patch.pak).

Pak Format

Pak files are implemented as merely renamed ZIP files. Additional formats (for example, encrypted bundles for IP protection) might be supported in the future.