[General] Adjust shader structures
This commit is contained in:
parent
6d8f93c470
commit
a830fcde97
@ -173,17 +173,17 @@ namespace Components
|
|||||||
{
|
{
|
||||||
if (asset.techniqueSet->techniques[i])
|
if (asset.techniqueSet->techniques[i])
|
||||||
{
|
{
|
||||||
for (int j = 0; j < asset.techniqueSet->techniques[i]->numPasses; ++j)
|
for (int j = 0; j < asset.techniqueSet->techniques[i]->passCount; ++j)
|
||||||
{
|
{
|
||||||
Game::MaterialPass* pass = &asset.techniqueSet->techniques[i]->passes[j];
|
Game::MaterialPass* pass = &asset.techniqueSet->techniques[i]->passArray[j];
|
||||||
|
|
||||||
for (int k = 0; k < (pass->argCount1 + pass->argCount2 + pass->argCount3); ++k)
|
for (int k = 0; k < (pass->perPrimArgCount + pass->perObjArgCount + pass->stableArgCount); ++k)
|
||||||
{
|
{
|
||||||
if (pass->argumentDef[k].type == D3DSHADER_PARAM_REGISTER_TYPE::D3DSPR_CONSTINT)
|
if (pass->args[k].type == D3DSHADER_PARAM_REGISTER_TYPE::D3DSPR_CONSTINT)
|
||||||
{
|
{
|
||||||
if (pass->argumentDef[k].paramID == -28132)
|
if (pass->args[k].u.codeConst.index == -28132)
|
||||||
{
|
{
|
||||||
pass->argumentDef[k].paramID = 2644;
|
pass->args[k].u.codeConst.index = 2644;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ namespace Assets
|
|||||||
Utils::Stream::ClearPointer(&dest->name);
|
Utils::Stream::ClearPointer(&dest->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset->loadDef.physicalPart)
|
if (asset->prog.loadDef.program)
|
||||||
{
|
{
|
||||||
buffer->align(Utils::Stream::ALIGN_4);
|
buffer->align(Utils::Stream::ALIGN_4);
|
||||||
buffer->save(asset->loadDef.physicalPart, 4, asset->loadDef.cachedPartSize & 0xFFFF);
|
buffer->saveArray(asset->prog.loadDef.program, asset->prog.loadDef.programSize);
|
||||||
Utils::Stream::ClearPointer(&dest->loadDef.physicalPart);
|
Utils::Stream::ClearPointer(&dest->prog.loadDef.program);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->popBlock();
|
buffer->popBlock();
|
||||||
|
@ -12,9 +12,9 @@ namespace Assets
|
|||||||
|
|
||||||
if (!technique) continue;
|
if (!technique) continue;
|
||||||
|
|
||||||
for (short j = 0; j < technique->numPasses; ++j)
|
for (short j = 0; j < technique->passCount; ++j)
|
||||||
{
|
{
|
||||||
Game::MaterialPass* pass = &technique->passes[j];
|
Game::MaterialPass* pass = &technique->passArray[j];
|
||||||
|
|
||||||
if (pass->vertexDecl)
|
if (pass->vertexDecl)
|
||||||
{
|
{
|
||||||
@ -75,14 +75,14 @@ namespace Assets
|
|||||||
|
|
||||||
// Save_MaterialPassArray
|
// Save_MaterialPassArray
|
||||||
Game::MaterialPass* destPasses = buffer->dest<Game::MaterialPass>();
|
Game::MaterialPass* destPasses = buffer->dest<Game::MaterialPass>();
|
||||||
buffer->saveArray(technique->passes, technique->numPasses);
|
buffer->saveArray(technique->passArray, technique->passCount);
|
||||||
|
|
||||||
for (short j = 0; j < technique->numPasses; ++j)
|
for (short j = 0; j < technique->passCount; ++j)
|
||||||
{
|
{
|
||||||
AssertSize(Game::MaterialPass, 20);
|
AssertSize(Game::MaterialPass, 20);
|
||||||
|
|
||||||
Game::MaterialPass* destPass = &destPasses[j];
|
Game::MaterialPass* destPass = &destPasses[j];
|
||||||
Game::MaterialPass* pass = &technique->passes[j];
|
Game::MaterialPass* pass = &technique->passArray[j];
|
||||||
|
|
||||||
if (pass->vertexDecl)
|
if (pass->vertexDecl)
|
||||||
{
|
{
|
||||||
@ -99,11 +99,11 @@ namespace Assets
|
|||||||
destPass->pixelShader = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader).pixelShader;
|
destPass->pixelShader = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader).pixelShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pass->argumentDef)
|
if (pass->args)
|
||||||
{
|
{
|
||||||
buffer->align(Utils::Stream::ALIGN_4);
|
buffer->align(Utils::Stream::ALIGN_4);
|
||||||
buffer->saveArray(pass->argumentDef, pass->argCount1 + pass->argCount2 + pass->argCount3);
|
buffer->saveArray(pass->args, pass->perPrimArgCount + pass->perObjArgCount + pass->stableArgCount);
|
||||||
Utils::Stream::ClearPointer(&destPass->argumentDef);
|
Utils::Stream::ClearPointer(&destPass->args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ namespace Assets
|
|||||||
Utils::Stream::ClearPointer(&dest->name);
|
Utils::Stream::ClearPointer(&dest->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AssertSize(Game::MaterialVertexStreamRouting, 92);
|
||||||
|
|
||||||
buffer->popBlock();
|
buffer->popBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ namespace Assets
|
|||||||
Utils::Stream::ClearPointer(&dest->name);
|
Utils::Stream::ClearPointer(&dest->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset->loadDef.physicalPart)
|
if (asset->prog.loadDef.program)
|
||||||
{
|
{
|
||||||
buffer->align(Utils::Stream::ALIGN_4);
|
buffer->align(Utils::Stream::ALIGN_4);
|
||||||
buffer->save(asset->loadDef.physicalPart, 4, asset->loadDef.cachedPartSize & 0xFFFF);
|
buffer->saveArray(asset->prog.loadDef.program, asset->prog.loadDef.programSize);
|
||||||
Utils::Stream::ClearPointer(&dest->loadDef.physicalPart);
|
Utils::Stream::ClearPointer(&dest->prog.loadDef.program);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->popBlock();
|
buffer->popBlock();
|
||||||
|
@ -514,17 +514,17 @@ namespace Components
|
|||||||
|
|
||||||
if (Utils::IO::FileExists(Utils::String::VA(formatString, name))) return;
|
if (Utils::IO::FileExists(Utils::String::VA(formatString, name))) return;
|
||||||
|
|
||||||
Utils::Stream* buffer = new Utils::Stream(0x1000);
|
Utils::Stream buffer(0x1000);
|
||||||
Game::MaterialPixelShader* dest = buffer->dest<Game::MaterialPixelShader>();
|
Game::MaterialPixelShader* dest = buffer.dest<Game::MaterialPixelShader>();
|
||||||
buffer->save(asset.pixelShader);
|
buffer.save(asset.pixelShader);
|
||||||
|
|
||||||
if (asset.pixelShader->loadDef.physicalPart)
|
if (asset.pixelShader->prog.loadDef.program)
|
||||||
{
|
{
|
||||||
buffer->save(asset.pixelShader->loadDef.physicalPart, 4, asset.pixelShader->loadDef.cachedPartSize & 0xFFFF);
|
buffer.saveArray(asset.pixelShader->prog.loadDef.program, asset.pixelShader->prog.loadDef.programSize);
|
||||||
Utils::Stream::ClearPointer(&dest->loadDef.physicalPart);
|
Utils::Stream::ClearPointer(&dest->prog.loadDef.program);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::IO::WriteFile(Utils::String::VA(formatString, name), buffer->toBuffer());
|
Utils::IO::WriteFile(Utils::String::VA(formatString, name), buffer.toBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::map<const void*, unsigned int> pointerMap;
|
static std::map<const void*, unsigned int> pointerMap;
|
||||||
@ -583,25 +583,25 @@ namespace Components
|
|||||||
|
|
||||||
// Save_MaterialPassArray
|
// Save_MaterialPassArray
|
||||||
Game::MaterialPass* destPasses = buffer->dest<Game::MaterialPass>();
|
Game::MaterialPass* destPasses = buffer->dest<Game::MaterialPass>();
|
||||||
buffer->saveArray(technique->passes, technique->numPasses);
|
buffer->saveArray(technique->passArray, technique->passCount);
|
||||||
|
|
||||||
for (short j = 0; j < technique->numPasses; ++j)
|
for (short j = 0; j < technique->passCount; ++j)
|
||||||
{
|
{
|
||||||
AssertSize(Game::MaterialPass, 20);
|
AssertSize(Game::MaterialPass, 20);
|
||||||
|
|
||||||
Game::MaterialPass* destPass = &destPasses[j];
|
Game::MaterialPass* destPass = &destPasses[j];
|
||||||
Game::MaterialPass* pass = &technique->passes[j];
|
Game::MaterialPass* pass = &technique->passArray[j];
|
||||||
|
|
||||||
if (pass->vertexDecl)
|
if (pass->vertexDecl)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pass->argumentDef)
|
if (pass->args)
|
||||||
{
|
{
|
||||||
buffer->align(Utils::Stream::ALIGN_4);
|
buffer->align(Utils::Stream::ALIGN_4);
|
||||||
buffer->saveArray(pass->argumentDef, pass->argCount1 + pass->argCount2 + pass->argCount3);
|
buffer->saveArray(pass->args, pass->perPrimArgCount + pass->perObjArgCount + pass->stableArgCount);
|
||||||
Utils::Stream::ClearPointer(&destPass->argumentDef);
|
Utils::Stream::ClearPointer(&destPass->args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1069,7 +1069,7 @@ namespace Components
|
|||||||
bool result = Game::Load_Stream(atStreamStart, argument, size);
|
bool result = Game::Load_Stream(atStreamStart, argument, size);
|
||||||
|
|
||||||
Game::MaterialPass* curPass = *Game::varMaterialPass;
|
Game::MaterialPass* curPass = *Game::varMaterialPass;
|
||||||
int count = curPass->argCount1 + curPass->argCount2 + curPass->argCount3;
|
int count = curPass->perPrimArgCount + curPass->perObjArgCount + curPass->stableArgCount;
|
||||||
|
|
||||||
for (int i = 0; i < count && (Zones::ZoneVersion >= VERSION_ALPHA2); ++i)
|
for (int i = 0; i < count && (Zones::ZoneVersion >= VERSION_ALPHA2); ++i)
|
||||||
{
|
{
|
||||||
@ -1084,40 +1084,40 @@ namespace Components
|
|||||||
// >= 58 fixes foliage without bad side effects
|
// >= 58 fixes foliage without bad side effects
|
||||||
// >= 53 still has broken shadow mapping
|
// >= 53 still has broken shadow mapping
|
||||||
// >= 23 is still broken somehow
|
// >= 23 is still broken somehow
|
||||||
if (arg->paramID >= 58 && arg->paramID <= 135) // >= 34 would be 31 in iw4 terms
|
if (arg->u.codeConst.index >= 58 && arg->u.codeConst.index <= 135) // >= 34 would be 31 in iw4 terms
|
||||||
{
|
{
|
||||||
arg->paramID -= 3;
|
arg->u.codeConst.index -= 3;
|
||||||
|
|
||||||
if (Zones::Version() >= 359/* && arg->paramID <= 113*/)
|
if (Zones::Version() >= 359/* && arg->paramID <= 113*/)
|
||||||
{
|
{
|
||||||
arg->paramID -= 7;
|
arg->u.codeConst.index -= 7;
|
||||||
|
|
||||||
if (arg->paramID <= 53)
|
if (arg->u.codeConst.index <= 53)
|
||||||
{
|
{
|
||||||
arg->paramID += 1;
|
arg->u.codeConst.index += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// >= 21 works fine for specular, but breaks trees
|
// >= 21 works fine for specular, but breaks trees
|
||||||
// >= 4 is too low, breaks specular
|
// >= 4 is too low, breaks specular
|
||||||
else if (arg->paramID >= 11 && arg->paramID < 58)
|
else if (arg->u.codeConst.index >= 11 && arg->u.codeConst.index < 58)
|
||||||
{
|
{
|
||||||
arg->paramID -= 2;
|
arg->u.codeConst.index -= 2;
|
||||||
|
|
||||||
if (Zones::Version() >= 359)
|
if (Zones::Version() >= 359)
|
||||||
{
|
{
|
||||||
if (arg->paramID > 15 && arg->paramID < 30)
|
if (arg->u.codeConst.index > 15 && arg->u.codeConst.index < 30)
|
||||||
{
|
{
|
||||||
arg->paramID -= 1;
|
arg->u.codeConst.index -= 1;
|
||||||
|
|
||||||
if (arg->paramID == 19)
|
if (arg->u.codeConst.index == 19)
|
||||||
{
|
{
|
||||||
arg->paramID = 21;
|
arg->u.codeConst.index = 21;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (arg->paramID >= 50)
|
else if (arg->u.codeConst.index >= 50)
|
||||||
{
|
{
|
||||||
arg->paramID += 6;
|
arg->u.codeConst.index += 6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,11 @@
|
|||||||
#define NUM_CUSTOM_CLASSES 15
|
#define NUM_CUSTOM_CLASSES 15
|
||||||
|
|
||||||
// This allows us to compile our structures in IDA, for easier reversing :3
|
// This allows us to compile our structures in IDA, for easier reversing :3
|
||||||
#ifdef __cplusplus
|
#ifndef __cplusplus
|
||||||
|
#define IDA
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef IDA
|
||||||
namespace Game
|
namespace Game
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
@ -336,7 +340,7 @@ namespace Game
|
|||||||
union
|
union
|
||||||
{
|
{
|
||||||
GfxImageLoadDef* loadDef;
|
GfxImageLoadDef* loadDef;
|
||||||
#ifdef __cplusplus
|
#ifndef IDA
|
||||||
IDirect3DBaseTexture9 *basemap;
|
IDirect3DBaseTexture9 *basemap;
|
||||||
IDirect3DTexture9 *map;
|
IDirect3DTexture9 *map;
|
||||||
IDirect3DVolumeTexture9 *volmap;
|
IDirect3DVolumeTexture9 *volmap;
|
||||||
@ -405,48 +409,107 @@ namespace Game
|
|||||||
MaterialTextureDefInfo info;
|
MaterialTextureDefInfo info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct GfxShaderConstantBlock
|
||||||
|
{
|
||||||
|
unsigned int count;
|
||||||
|
unsigned __int16 dest[16];
|
||||||
|
const float *value[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MaterialArgumentCodeConst
|
||||||
|
{
|
||||||
|
unsigned __int16 index;
|
||||||
|
char firstRow;
|
||||||
|
char rowCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
union MaterialArgumentDef
|
||||||
|
{
|
||||||
|
const float *literalConst;
|
||||||
|
MaterialArgumentCodeConst codeConst;
|
||||||
|
unsigned int codeSampler;
|
||||||
|
unsigned int nameHash;
|
||||||
|
};
|
||||||
|
|
||||||
struct MaterialShaderArgument
|
struct MaterialShaderArgument
|
||||||
{
|
{
|
||||||
short type;
|
unsigned __int16 type;
|
||||||
short dest;
|
unsigned __int16 dest;
|
||||||
short paramID;
|
MaterialArgumentDef u;
|
||||||
short more;
|
};
|
||||||
|
|
||||||
|
struct MaterialStreamRouting
|
||||||
|
{
|
||||||
|
char source;
|
||||||
|
char dest;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MaterialVertexStreamRouting
|
||||||
|
{
|
||||||
|
MaterialStreamRouting data[14];
|
||||||
|
#ifdef IDA
|
||||||
|
void
|
||||||
|
#else
|
||||||
|
IDirect3DVertexDeclaration9
|
||||||
|
#endif
|
||||||
|
*decl[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MaterialVertexDeclaration
|
struct MaterialVertexDeclaration
|
||||||
{
|
{
|
||||||
const char* name;
|
const char* name;
|
||||||
int unknown;
|
char streamCount;
|
||||||
char pad[28];
|
bool hasOptionalSource;
|
||||||
/*IDirect3DVertexDeclaration9**/void* declarations[16];
|
bool isLoaded;
|
||||||
|
MaterialVertexStreamRouting routing;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GfxPixelShaderLoadDef
|
struct GfxPixelShaderLoadDef
|
||||||
{
|
{
|
||||||
char *cachedPart;
|
unsigned int *program;
|
||||||
char *physicalPart;
|
unsigned __int16 programSize;
|
||||||
unsigned __int16 cachedPartSize;
|
unsigned __int16 loadForRenderer;
|
||||||
unsigned __int16 physicalPartSize;
|
};
|
||||||
|
|
||||||
|
struct MaterialPixelShaderProgram
|
||||||
|
{
|
||||||
|
#ifdef IDA
|
||||||
|
void
|
||||||
|
#else
|
||||||
|
IDirect3DPixelShader9
|
||||||
|
#endif
|
||||||
|
*ps;
|
||||||
|
GfxPixelShaderLoadDef loadDef;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MaterialPixelShader
|
struct MaterialPixelShader
|
||||||
{
|
{
|
||||||
const char* name;
|
const char* name;
|
||||||
GfxPixelShaderLoadDef loadDef;
|
MaterialPixelShaderProgram prog;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GfxVertexShaderLoadDef
|
struct GfxVertexShaderLoadDef
|
||||||
{
|
{
|
||||||
char *cachedPart;
|
unsigned int *program;
|
||||||
char *physicalPart;
|
unsigned __int16 programSize;
|
||||||
unsigned __int16 cachedPartSize;
|
unsigned __int16 loadForRenderer;
|
||||||
unsigned __int16 physicalPartSize;
|
};
|
||||||
|
|
||||||
|
struct MaterialVertexShaderProgram
|
||||||
|
{
|
||||||
|
#ifdef IDA
|
||||||
|
void
|
||||||
|
#else
|
||||||
|
IDirect3DVertexShader9
|
||||||
|
#endif
|
||||||
|
*vs;
|
||||||
|
GfxVertexShaderLoadDef loadDef;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MaterialVertexShader
|
struct MaterialVertexShader
|
||||||
{
|
{
|
||||||
const char* name;
|
const char *name;
|
||||||
GfxVertexShaderLoadDef loadDef;
|
MaterialVertexShaderProgram prog;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MaterialPass
|
struct MaterialPass
|
||||||
@ -454,19 +517,19 @@ namespace Game
|
|||||||
MaterialVertexDeclaration* vertexDecl;
|
MaterialVertexDeclaration* vertexDecl;
|
||||||
MaterialVertexShader* vertexShader;
|
MaterialVertexShader* vertexShader;
|
||||||
MaterialPixelShader* pixelShader;
|
MaterialPixelShader* pixelShader;
|
||||||
char argCount1;
|
char perPrimArgCount;
|
||||||
char argCount2;
|
char perObjArgCount;
|
||||||
char argCount3;
|
char stableArgCount;
|
||||||
char unk;
|
char customSamplerFlags;
|
||||||
MaterialShaderArgument* argumentDef;
|
MaterialShaderArgument* args;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MaterialTechnique
|
struct MaterialTechnique
|
||||||
{
|
{
|
||||||
char* name;
|
const char *name;
|
||||||
short pad2;
|
unsigned __int16 flags;
|
||||||
short numPasses;
|
unsigned __int16 passCount;
|
||||||
MaterialPass passes[1];
|
MaterialPass passArray[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
enum MaterialTechniqueType
|
enum MaterialTechniqueType
|
||||||
@ -3773,7 +3836,7 @@ namespace Game
|
|||||||
fileInIwd_s *buildBuffer;
|
fileInIwd_s *buildBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifdef IDA
|
||||||
typedef void _iobuf;
|
typedef void _iobuf;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -3884,6 +3947,6 @@ namespace Game
|
|||||||
int dataCount;
|
int dataCount;
|
||||||
} gameState;
|
} gameState;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifndef IDA
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user