nickworonekin / puyotools

Puyo Tools is a collection of tools and libraries used to access the contents of various game files. Although it was initially built to handle files used in Puyo Puyo games, it can handle files used in other games as well.
MIT License
99 stars 24 forks source link

Palette bank switching support for VrTexture.SetPalette #33

Open PiKeyAr opened 3 years ago

PiKeyAr commented 3 years ago

Sorry, please bear with me, here's another feature request related to textures with external palettes.

According to the documentation in Sega SDKs, a palette file can contain up to 1024 color entries, which can be used as up to 4 palette sets for Index8 textures or 64 palette sets for Index4 textures. Some games use multiple palette sets in one PVP file to switch between different palettes. For example, Chao in Sonic Adventure DX and Sonic Adventure 2(B) use Index4 textures with 48-color palettes, and they switch between three 16-color palette banks in code. Some textures are only meant to be used with the second or the third bank. The intended bank ID can be specified in texture data (possibly the value at 0xA in the PVRT header), but the games just set the bank ID in code. The Gamecube version of SA2B and the PC version of SA2 have the same setup so it applies to GVP files too.

Since VrSharp's SetPalette always sets the first bank that begins at offset 0x10 in the PVP/GVP file, there is currently no way to preview other palette banks without manually altering the palette to remove the first bank. My simple suggestion is to add an optional parameter to SetPalette that would take in Bank ID, and offset the starting color in the palette by 16 * bankID for Index4 textures, and by 256 * bankID for Index8 textures before applying the colors to the texture. I think it would be a nice addition to allow more flexibility while working with indexed textures.

We also found this infomation below in the SDK. It isn't too critical to support and I haven't been able to find any games that use it that way, but I thought I should share it for research purposes. Apparently PVP and GVP files can also have "offset bank" (short at 0xA) and "offset entry" (short at 0xC) values. Offset bank is probably irrelevant as far as texture editing goes, but offset entry indicates how many colors are skipped in the palette bank before the data begins. So if the offset entry is set to 50, for example, the palette's first 50 colors should be blank, and first color in the PVP file becomes the 51st in the actual palette. If the PVP/GVP contains multiple banks, this applies to all banks (e.g. the colors in all banks fill the palettes starting with the 51st color).

Hope this helps!