Fix shader stuff

This commit is contained in:
momo5502 2016-10-23 16:45:21 +02:00
parent 64f80a21be
commit d2c5c45042
5 changed files with 86 additions and 264 deletions

2
deps/mongoose vendored

@ -1 +1 @@
Subproject commit 835af2cae1b731a350ac86003f82183302bd2155
Subproject commit c722cfec18231c6d18ab8a73993b763aa1e0dd7e

View File

@ -132,251 +132,58 @@ namespace Components
}
}
if (type == 20/* && name == "maps/mp/mp_underpass.d3dbsp"s*/)
if (type == 9 && false)
{
char* world = nullptr;
Game::DB_EnumXAssets_Internal(Game::XAssetType::ASSET_TYPE_FX_MAP, [] (Game::XAssetHeader header, void* world)
static Game::MaterialTechniqueSet* technique = nullptr;
auto printTechset = [] (Game::MaterialTechniqueSet* technique, std::string zone)
{
*reinterpret_cast<Game::GfxWorld**>(world) = header.gfxMap;
}, &world, false);
FILE* fp;
fopen_s(&fp, "test.txt", "a");
fprintf(fp, "%s: %s\n", zone.data(), technique->name);
if (world)
{
//std::memcpy(world + 4, &asset->rawfile->sizeCompressed, Game::DB_GetXAssetSizeHandlers[Game::XAssetType::ASSET_TYPE_FX_MAP]() - 4);
}
}
if (type == 22)
{
OutputDebugStringA(Utils::String::VA("%s: %s\n", FastFiles::Current().data(), name));
}
/*
if (type <= 9 && type >= 6 && Zones::Version() >= 359)
{
static Game::XAssetType __type;
static std::string __name;
__name = name;
__type = type;
Game::MaterialTechniqueSet* techset = nullptr;
Game::DB_EnumXAssets_Internal(type, [] (Game::XAssetHeader header, void* _asset)
{
Game::MaterialTechniqueSet** _techset = reinterpret_cast<Game::MaterialTechniqueSet**>(_asset);
if (__name == Game::DB_GetXAssetNameHandlers[__type](&header))
for (int i = 0; i < 48; i++)
{
*_techset = header.materialTechset;
}
}, &techset, false);
if (techset)
{
if(type == 6)
std::memcpy(asset->materialTechset, techset, Game::DB_GetXAssetSizeHandlers[type]());
//return false;
OutputDebugStringA("");
}
}
*/
if (type == 21/* && asset->gfxMap->baseName == "mp_underpass"s*/ && false)
{
//asset->gfxMap->dpvs.smodelCount = 0;
Game::GfxWorld* world = nullptr;
Game::DB_EnumXAssets_Internal(Game::XAssetType::ASSET_TYPE_GFX_MAP, [] (Game::XAssetHeader header, void* world)
{
*reinterpret_cast<Game::GfxWorld**>(world) = header.gfxMap;
}, &world, false);
// int targetId = *world->skies->skyStartSurfs;
// int sourceId = *asset->gfxMap->skies->skyStartSurfs;
// world->dpvs.surfaceVisData[0][targetId] = asset->gfxMap->dpvs.surfaceVisData[0][sourceId];
// world->dpvs.surfaceVisData[1][targetId] = asset->gfxMap->dpvs.surfaceVisData[1][sourceId];
// world->dpvs.surfaceVisData[2][targetId] = asset->gfxMap->dpvs.surfaceVisData[2][sourceId];
//
// world->dpvs.surfaces[targetId].material = asset->gfxMap->dpvs.surfaces[sourceId].material;
// world->dpvs.surfacesBounds[targetId].flags = asset->gfxMap->dpvs.surfacesBounds[sourceId].flags;
//
// world->dpvs.surfaceCastsSunShadow[targetId] = asset->gfxMap->dpvs.surfaceCastsSunShadow[sourceId];
//
// world->skies->skyImage = asset->gfxMap->skies->skyImage;
// std::memcpy(&world->worldDraw.lightmaps[world->dpvs.surfaces[targetId].lightmapIndex], &asset->gfxMap->worldDraw.lightmaps[asset->gfxMap->dpvs.surfaces[sourceId].lightmapIndex], 8);
// DWORD* stuff = reinterpret_cast<DWORD*>(asset->gfxMap->unknown1);
// for (unsigned int i = 0; i < asset->gfxMap->dpvs.staticSurfaceCount; ++i)
// {
// asset->gfxMap->dpvs.surfaces[i].tris.vertexLayerData = 0;
// }
auto replaceMaterial = [] (Game::GfxSurface* surfs, unsigned int count, Game::Material** base)
{
static int _i = 0;
_i++;
for (unsigned int i = 0; i < count; ++i)
{
Game::Material* source = *base;
Game::Material* target = surfs[i].material;
if (source->gameFlags == target->gameFlags)
if (technique->techniques[i])
{
*base = target;
OutputDebugStringA(Utils::String::VA("SUCCESS: replaced %s with %s %d\n", source->name, target->name, _i));
OutputDebugStringA(Utils::String::VA("SortKey: %X\nGameFlags: %X\nStateFlags: %X\nTechset: %s\n\n", source->sortKey & 0xFF, source->gameFlags & 0xFF, source->stateFlags & 0xFF, source->techniqueSet->name));
fprintf(fp, "\t%d: %s\n", i, technique->techniques[i]->name);
source = target;
OutputDebugStringA(Utils::String::VA("SortKey: %X\nGameFlags: %X\nStateFlags: %X\nTechset: %s\n\n", source->sortKey & 0xFF, source->gameFlags & 0xFF, source->stateFlags & 0xFF, source->techniqueSet->name));
return;
}
}
OutputDebugStringA(Utils::String::VA("FAILURE: unable to replace %s %d\n", (*base)->name, _i));
Game::Material* source = *base;
OutputDebugStringA(Utils::String::VA("SortKey: %X\nGameFlags: %X\nStateFlags: %X\nTechset: %s\n\n", source->sortKey & 0xFF, source->gameFlags & 0xFF, source->stateFlags & 0xFF, source->techniqueSet->name));
};
// for (unsigned int i = 0; i < world->dpvs.staticSurfaceCount; ++i)
// {
// replaceMaterial(asset->gfxMap->dpvs.surfaces, asset->gfxMap->dpvs.staticSurfaceCount, &world->dpvs.surfaces[i].material);
// }
// for (int i = 0; i < world->materialMemoryCount; ++i)
// {
// for (int j = 0; j < asset->gfxMap->materialMemoryCount; ++j)
// {
// if (world->materialMemory[i].material->gameFlags == asset->gfxMap->materialMemory[j].material->gameFlags)
// {
// world->materialMemory[i].material = asset->gfxMap->materialMemory[j].material;
// world->materialMemory[i].memory = asset->gfxMap->materialMemory[j].memory;
// }
// }
// }
// //std::memcpy(&world->dpvs, &asset->gfxMap->dpvs, sizeof(Game::GfxWorldDpvsStatic));
// std::memcpy(&world->worldDraw, &asset->gfxMap->worldDraw, sizeof(Game::GfxWorldDraw));
// std::memcpy(&world->lightGrid, &asset->gfxMap->lightGrid, sizeof(Game::GfxLightGrid));
// //std::memcpy(&world->dpvsPlanes, &asset->gfxMap->dpvsPlanes, sizeof(Game::GfxWorldDpvsPlanes));
// world->dpvs.surfaces = asset->gfxMap->dpvs.surfaces;
// world->dpvs.surfacesBounds = asset->gfxMap->dpvs.surfacesBounds;
// world->dpvs.staticSurfaceCount = asset->gfxMap->dpvs.staticSurfaceCount;
// world->dpvs.sortedSurfIndex = asset->gfxMap->dpvs.sortedSurfIndex;
// world->dpvs.surfaceVisData[0] = asset->gfxMap->dpvs.surfaceVisData[0];
// world->dpvs.surfaceVisData[1] = asset->gfxMap->dpvs.surfaceVisData[1];
// world->dpvs.surfaceVisData[2] = asset->gfxMap->dpvs.surfaceVisData[2];
//
// world->cellCasterBits[0] = asset->gfxMap->cellCasterBits[0];
// world->cellCasterBits[1] = asset->gfxMap->cellCasterBits[1];
//
// world->skies = asset->gfxMap->skies;
// world->materialMemory = asset->gfxMap->materialMemory;
// world->materialMemoryCount = asset->gfxMap->materialMemoryCount;
//
// world->dpvs.litSurfsBegin = asset->gfxMap->dpvs.litSurfsBegin;
// world->dpvs.litSurfsEnd = asset->gfxMap->dpvs.litSurfsEnd;
// world->dpvs.surfaceMaterials = asset->gfxMap->dpvs.surfaceMaterials;
//
// std::memcpy(world->pad, asset->gfxMap->pad, 68);
// std::memcpy(world->dpvs.unknown1, asset->gfxMap->dpvs.unknown1, 8);
// std::memcpy(&world->dpvs.unknown1[0x18], &asset->gfxMap->dpvs.unknown1[0x18], 4);
// std::memcpy(&world->sun, &asset->gfxMap->sun, sizeof(Game::sunflare_t));
//world->dpvs.smodelCount = 0;
//std::memcpy(world->dpvsPlanes.planes, asset->gfxMap->dpvsPlanes.planes, 20 * (std::min(world->planeCount, asset->gfxMap->planeCount)));
// for (int i = 0; i < world->planeCount; ++i)
// {
// world->dpvsPlanes.planes[i].type = 0;
// }
//world->cells = asset->gfxMap->cells;
// for(int i = 0; i < std::min(asset->gfxMap->dpvsPlanes.cellCount, world->dpvsPlanes.cellCount); ++i)
// {
// // for (int j = 0; j < std::min(asset->gfxMap->aabbTreeCounts[i].aabbTreeCount, world->aabbTreeCounts[i].aabbTreeCount); ++j)
// // {
// // Game::GfxAabbTree* treeA = &world->aabbTrees[i].aabbTree[j];
// // Game::GfxAabbTree* treeB = &asset->gfxMap->aabbTrees[i].aabbTree[j];
// //
// // treeA->childrenOffset
// // }
//
// for (int j = 0; j < std::min(asset->gfxMap->cells[i].portalCount, world->cells[i].portalCount); ++j)
// {
// Game::GfxPortal* portalA = &world->cells[i].portals[j];
// Game::GfxPortal* portalB = &asset->gfxMap->cells[i].portals[j];
//
// std::memcpy(&portalA->writable, &portalB->writable, sizeof(portalA->writable));
// std::memcpy(&portalA->plane, &portalB->plane, sizeof(portalA->plane));
// //std::memcpy(&portalA->unknown, &portalB->unknown, sizeof(portalA->unknown));
// std::memcpy(&portalA->hullAxis, &portalB->hullAxis, sizeof(portalA->hullAxis));
// }
//
// //std::memcpy(&world->cells[i], &asset->gfxMap->cells[i], sizeof(Game::GfxCell));
// //std::memcpy(&world->cells[i], &asset->gfxMap->cells[i], sizeof(Game::GfxCell));
// }
//std::memcpy(&world->planeCount, &asset->gfxMap->planeCount, 620);
// asset->gfxMap->cells = world->cells;
// asset->gfxMap->aabbTrees = world->aabbTrees;
// asset->gfxMap->aabbTreeCounts = world->aabbTreeCounts;
// std::memcpy(&asset->gfxMap->dpvsPlanes, &world->dpvsPlanes, sizeof(Game::GfxWorldDpvsPlanes));
//std::memcpy(&world->planeCount, &asset->gfxMap->planeCount, 620);
OutputDebugStringA("");
}
static Game::MaterialTechniqueSet* technique = nullptr;
/*if (type == 9)
{
FILE* fp;
fopen_s(&fp, "test.txt", "a");
fprintf(fp, "%s: %s\n", FastFiles::Current().data(), name);
for (int i = 0; i < 48; i++)
{
if (asset->materialTechset->techniques[i])
{
fprintf(fp, "\t%d: %s\n", i, asset->materialTechset->techniques[i]->name);
for (int j = 0; j <asset->materialTechset->techniques[i]->numPasses; j++)
{
Game::MaterialPass* pass = &asset->materialTechset->techniques[i]->passes[j];
for (int k = 0; k < (pass->argCount1 + pass->argCount2 + pass->argCount3); k++)
for (int j = 0; j < technique->techniques[i]->numPasses; j++)
{
fprintf(fp, "\t\t%d.%d.%d:\n", i, j, k);
Game::MaterialPass* pass = &technique->techniques[i]->passes[j];
fprintf(fp, "\t\t\tDest: %d\n", pass->argumentDef[k].dest & 0xFFFF);
fprintf(fp, "\t\t\tMore: %d\n", pass->argumentDef[k].more & 0xFFFF);
fprintf(fp, "\t\t\tType: %d\n", pass->argumentDef[k].type & 0xFFFF);
fprintf(fp, "\t\t\tPara: %d\n", pass->argumentDef[k].paramID & 0xFFFF);
for (int k = 0; k < (pass->argCount1 + pass->argCount2 + pass->argCount3); k++)
{
fprintf(fp, "\t\t%d.%d.%d:\n", i, j, k);
fprintf(fp, "\t\t\tDest: %d\n", pass->argumentDef[k].dest & 0xFFFF);
fprintf(fp, "\t\t\tMore: %d\n", pass->argumentDef[k].more & 0xFFFF);
fprintf(fp, "\t\t\tType: %d\n", pass->argumentDef[k].type & 0xFFFF);
fprintf(fp, "\t\t\tPara: %d\n", pass->argumentDef[k].paramID & 0xFFFF);
}
}
}
}
fprintf(fp, "\n");
fclose(fp);
};
static std::map<std::string, Game::MaterialTechniqueSet*> techs;
if (FastFiles::Current() == "mp_firingrange")
{
techs[name] = asset->materialTechset;
printTechset(asset->materialTechset, "mp_firingrange");
}
fprintf(fp, "\n");
fclose(fp);
}*/
// if (type == 5)
// {
// FILE* fp;
// fopen_s(&fp, "test.txt", "a");
// fprintf(fp, "%s: %s %X %X %X\n", FastFiles::Current().data(), name, asset->material->sortKey & 0xFF, asset->material->gameFlags & 0xFF, asset->material->stateFlags & 0xFF);
// fclose(fp);
// }
else
{
if (techs.find(name) != techs.end())
{
printTechset(asset->materialTechset, FastFiles::Current());
}
}
}
if (type == 5 && name == "wc/codo_ui_viewer_black_decal3"s)
{

View File

@ -415,10 +415,7 @@ namespace Components
Maps::AddDependency("mp_firingrange", "iw4x_dependencies_mp");
Maps::AddDependency("mp_shipment_long", "iw4x_dependencies_mp");
Maps::AddDependency("mp_firingrange", "iw4x_dependencies_mp");
Maps::AddDependency("mp_firingrange", "mp_underpass");
Maps::AddDependency("zm_asylum_sh", "iw4x_dependencies_mp");
Maps::AddDependency("mp_rust_long", "iw4x_dependencies_mp");
Maps::AddDependency("mp_rust_long", "mp_rust");
#if defined(DEBUG) && defined(ENABLE_DXSDK)
Command::Add("dumpmap", [] (Command::Params)

View File

@ -1005,12 +1005,29 @@ namespace Components
if (arg->paramID >= 58 && arg->paramID <= 135) // >= 34 would be 31 in iw4 terms
{
arg->paramID -= 3;
if (Zones::Version() >= 359)
{
arg->paramID -= 7;
}
}
// >= 21 works fine for specular, but breaks trees
// >= 4 is too low, breaks specular
else if (arg->paramID >= 11 && arg->paramID < 58)
{
arg->paramID -= 2;
if (Zones::Version() >= 359)
{
if (arg->paramID > 15 && arg->paramID < 34)
{
arg->paramID -= 1;
}
else if (arg->paramID >= 50)
{
arg->paramID += 6;
}
}
}
}
@ -1145,7 +1162,7 @@ namespace Components
struct material339_s
{
char drawSurfBegin[8]; // 4
//int surfaceTypeBits;
//int surfaceTypeBits;
const char *name;
char drawSurf[6];
@ -1223,30 +1240,6 @@ namespace Components
char* varGfxWorld = *reinterpret_cast<char**>(0x112A7F4);
std::memmove(varGfxWorld + 348, varGfxWorld + 1316, 8);
}
void ModifyShit()
{
//Game::GfxWorldDraw* worldDraw = *reinterpret_cast<Game::GfxWorldDraw**>(0x112A8D4);
//Game::GfxWorldVertexData* vd = *reinterpret_cast<Game::GfxWorldVertexData**>(0x112B078);
//worldDraw->vertexLayerDataSize = 0;
//for (unsigned int i = 0; i < worldDraw->vertexCount; ++i)
{
//vd->vertices[i].normal.packed++;
//vd->vertices[i].tangent.packed++;
//vd->vertices[i].color.packed = Utils::Cryptography::Rand::GenerateInt();
//std::swap(vd->vertices[i].xyz[0], vd->vertices[i].xyz[1]);
}
// for (unsigned int i = 0; i < worldDraw->vertexCount; ++i)
// {
// OutputDebugStringA(Utils::String::VA("%f %f\n", vd->vertices[i].texCoord[0], vd->vertices[i].texCoord[1]));
//
// vd->vertices[i].lmapCoord[0] = 1.0f;
// vd->vertices[i].lmapCoord[1] = 1.0f;
// }
}
void Zones::InstallPatches(int version)
{
@ -1404,8 +1397,6 @@ namespace Components
Zones::Zones()
{
Utils::Hook(0x483876, ModifyShit, HOOK_CALL).Install()->Quick();
Zones::ZoneVersion = 0;
// Ignore missing soundaliases for now

View File

@ -2476,6 +2476,33 @@ namespace Game
GfxColor groundLighting;
};
enum surfaceType_t
{
SF_TRIANGLES = 0x0,
SF_TRIANGLES_NO_SUN_SHADOW = 0x1,
SF_BEGIN_STATICMODEL = 0x2,
SF_STATICMODEL_RIGID = 0x2,
SF_STATICMODEL_INSTANCED = 0x3,
SF_STATICMODEL_RIGID_NO_SUN_SHADOW = 0x4,
SF_STATICMODEL_INSTANCED_NO_SUN_SHADOW = 0x5,
SF_END_STATICMODEL = 0x6,
SF_BMODEL = 0x6,
SF_BEGIN_XMODEL = 0x7,
SF_XMODEL_RIGID = 0x7,
SF_XMODEL_SKINNED = 0x8,
SF_END_XMODEL = 0x9,
SF_BEGIN_FX = 0x9,
SF_CODE = 0x9,
SF_GLASS = 0xA,
SF_MARK = 0xB,
SF_SPARK = 0xC,
SF_PARTICLE_CLOUD = 0xD,
SF_PARTICLE_SPARK_CLOUD = 0xE,
SF_END_FX = 0xF,
SF_NUM_SURFACE_TYPES = 0xF,
SF_FORCE_32_BITS = 0xFFFFFFFF,
};
struct srfTriangles_t
{
int vertexLayerData;