wow的shader都是放在bls文件中的,前几天对这些文件分析了一下,发现wowdev.org里对bls的解析不大对,这里对bls的文件格式做一下说明。
文件前四个字节肯定是"SVXG"或"SPXG",分别表示这个bls里保存的是vs或ps。
接下来一个uint表示版本号,没什么用。
接下来一个uint是用来表示每个profile里的shader数目,以下检测pc。
接下来是data block的偏移量,如果是vs,会有6个偏移量,如果是ps,会有12个偏移量,其中有些可能会是0。
然后就可以根据这些偏移量,移动到文件中的指定位置,开始读取shader的数据和代码了。
以下是我写的一个解析bls文件的代码,可以把指定的bls里的shader输出到一个文本文件中。
/********************************************************************
filename: Blsparser.cpp
created: 2006/07/29
author: Weiliang Xie (feiyurainy at 163.com)
purpose: To parse the wow shader file(.bls),and log the shader data
a file.
*********************************************************************/
#include <iostream>
#include <fstream>
#include <string>
#include <assert.h>
#include <d3dx9.h>
#include <dxerr9.h>
typedef unsigned int uint32;
struct BlsHeader
{
char shaderType[4]; /// shader type,must be "SPXG" or "SVXG"
uint32 version; /// shader version,useless
uint32 shaderCount; /// shader count in each shader block
};
/// global shader header for the input bls file
BlsHeader gBlsHeader;
/// input bls file stream
std::ifstream gBlsFStream;
/// output log file stream
std::ofstream gOutputFile;
/** read the data from the gBlsFStream
@param count num of byte to read
@return num of byte read
*/
size_t _readData(void* buf, size_t count)
{
gBlsFStream.read( static_cast<char*>(buf), static_cast<std::streamsize>(count) );
return gBlsFStream.gcount();
}
/** parse the b