Skip to content

Commit

Permalink
Merge Fixed five -> rdr3 embedded textures crash on unload (pr-2321)
Browse files Browse the repository at this point in the history
- 23770d4 tweak(tool/formats): five -> rdr3 bound poly tweaks
- e53e98d fix(tool/formats): five -> rdr3 embedded textures crash on unload
  • Loading branch information
prikolium-cfx committed May 28, 2024
2 parents 3422b6d + 23770d4 commit 9e7d797
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,9 @@ rdr3::grmShaderGroup* convert(five::grmShaderGroup* shaderGroup)

for (int i = 0; i < textureRefs.size(); i++, idx++)
{
*(uint32_t*)(&firstArg[(idx * 8) + 0]) = std::get<0>(textureRefs[i]);
*(uint32_t*)(&firstArg[(idx * 8) + 4]) = 0; // the game should guess this from hash as we don't match
args[idx].hash = std::get<0>(textureRefs[i]);
args[idx].texture.resourceClass = 0;
args[idx].texture.index = idx;
}

for (int i = 0; i < paramRefs.size(); i++, idx++)
Expand All @@ -770,13 +771,12 @@ rdr3::grmShaderGroup* convert(five::grmShaderGroup* shaderGroup)

size_t paramPtrSize = sizeof(uintptr_t) * 4 * shader->m_parameterData->numCBuffers;
size_t paramDataSize = 4 * (16 * paramRefs.size());
size_t texRefDataSize = (8 * textureRefs.size());
size_t texRefDataSize = 4 * (8 * textureRefs.size());
size_t finalParamSize = (paramPtrSize + paramDataSize + texRefDataSize + shader->m_parameterData->numSamplers);

// we are allocating (final size * 2) so we can account for the game wanting to stuff its corrections in here
shader->m_parameterDataSize = finalParamSize * 2;
shader->m_parameterDataSize = finalParamSize;

auto paramBuffer = (char*)rdr3::pgStreamManager::Allocate(finalParamSize * 2, false, nullptr);
auto paramBuffer = (char*)rdr3::pgStreamManager::Allocate(finalParamSize, false, nullptr);
auto prs = (rdr3::grmShaderParameter*)(paramBuffer);
auto trs = (rdr3::grmShaderParameter*)(paramBuffer + paramPtrSize + paramDataSize); //rdr3::pgStreamManager::Allocate(sizeof(rdr3::grmShaderParameter) * textureRefs.size(), false, nullptr);

Expand All @@ -785,6 +785,12 @@ rdr3::grmShaderGroup* convert(five::grmShaderGroup* shaderGroup)
trs[i].SetValue(std::get<1>(textureRefs[i]));
}

// we like to have 3 copies
for (int i = textureRefs.size(); i < textureRefs.size() * 4; i++)
{
trs[i].SetValue(0);
}

shader->m_textureRefs = trs;

{
Expand Down
43 changes: 36 additions & 7 deletions code/components/rage-formats-x/include/convert/phBound_five_rdr3.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ static inline void fillPolyhedronBound(rdr3::phBoundPolyhedron* out, five::phBou
{
if (inPolys[i].type == 0)
{
outPolys[i].poly.v1 = inPolys[i].poly.v1;
outPolys[i].poly.v2 = inPolys[i].poly.v2;
outPolys[i].poly.v3 = inPolys[i].poly.v3;
outPolys[i].poly.v1 = (inPolys[i].poly.v1 & 0x7FFF);
outPolys[i].poly.v2 = (inPolys[i].poly.v2 & 0x7FFF);
outPolys[i].poly.v3 = (inPolys[i].poly.v3 & 0x7FFF);
outPolys[i].poly.e1 = inPolys[i].poly.e1;
outPolys[i].poly.e2 = inPolys[i].poly.e2;
outPolys[i].poly.e3 = inPolys[i].poly.e3;
Expand Down Expand Up @@ -474,6 +474,36 @@ static inline void fillGeometryBound(rdr3::phBoundGeometry* out, five::phBoundGe
out->SetMaterials(materials.size(), &materials[0]);
}

static inline void fillBoundPolyMaterial(rdr3::phBound* out, five::phBound* in)
{
five::phBoundMaterial inMaterial = in->GetMaterial();
rdr3::phBoundMaterial outMaterial = { 0 };

outMaterial.mat1.materialIdx = ConvertMaterialIndexrdr3(inMaterial.mat1.materialIdx);
outMaterial.mat1.roomId = inMaterial.mat1.roomId;

outMaterial.mat2.stairs = inMaterial.mat1.stairs;
outMaterial.mat2.blockClimb = inMaterial.mat1.blockClimb;
outMaterial.mat2.seeThrough = inMaterial.mat1.seeThrough;
outMaterial.mat2.shootThrough = inMaterial.mat1.shootThrough;
outMaterial.mat2.notCover = inMaterial.mat1.notCover;
outMaterial.mat2.walkablePath = inMaterial.mat1.walkablePath;
outMaterial.mat2.noCamCollision = inMaterial.mat1.noCamCollision;
outMaterial.mat2.shootThroughFx = inMaterial.mat1.shootThroughFx;

outMaterial.mat2.noDecal = inMaterial.mat2.noDecal;
outMaterial.mat2.noNavmesh = inMaterial.mat2.noNavmesh;
outMaterial.mat2.noRagdoll = inMaterial.mat2.noRagdoll;
outMaterial.mat2.vehicleWheel = inMaterial.mat2.vehicleWheel;
outMaterial.mat2.noPtfx = inMaterial.mat2.noPtfx;
outMaterial.mat2.tooSteepForPlayer = inMaterial.mat2.tooSteepForPlayer;
outMaterial.mat2.noNetworkSpawn = inMaterial.mat2.noNetworkSpawn;
outMaterial.mat2.noCamCollisionAllowClipping = inMaterial.mat2.noCamCollisionAllowClipping;
outMaterial.mat2.unknown = inMaterial.mat2.unknown;

out->SetMaterial(outMaterial);
}

template<>
rdr3::phBoundGeometry* convert(five::phBoundGeometry* bound)
{
Expand Down Expand Up @@ -523,6 +553,7 @@ rdr3::phBoundSphere* convert(five::phBoundSphere* bound)
auto out = new (false) rdr3::phBoundSphere;

fillBaseBound(out, bound);
fillBoundPolyMaterial(out, bound);

return out;
}
Expand All @@ -533,10 +564,7 @@ rdr3::phBoundBox* convert(five::phBoundBox* bound)
auto out = new (false) rdr3::phBoundBox;

fillBaseBound(out, bound);

//rage::rdr3::phBoundMaterial material = { 0 };
//material.mat1.materialIdx = ConvertMaterialIndex(bound->GetMaterial().mat1.materialIdx);
//out->SetMaterial(material);
fillBoundPolyMaterial(out, bound);

return out;
}
Expand All @@ -547,6 +575,7 @@ rdr3::phBoundCapsule* convert(five::phBoundCapsule* bound)
auto out = new (false) rdr3::phBoundCapsule;

fillBaseBound(out, bound);
fillBoundPolyMaterial(out, bound);

return out;
}
Expand Down
22 changes: 13 additions & 9 deletions code/components/rage-formats-x/include/rmcDrawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace sga
private:
void* m_texturePtr; // filled at runtime

uint8_t m_pad[56];
uint8_t m_pad[64];

public:
ShaderResourceView()
Expand All @@ -176,7 +176,7 @@ namespace sga
0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

memcpy(m_pad, f, sizeof(m_pad));
Expand Down Expand Up @@ -218,8 +218,7 @@ class grcTexture :
#elif defined(RAGE_FORMATS_GAME_RDR3)
// sga::Texture
uint32_t m_blockSize;
uint16_t m_blockCount;
uint16_t m_blockPad;
uint32_t m_blockCount;
union
{
uint32_t m_flags;
Expand All @@ -234,14 +233,17 @@ class grcTexture :
uint8_t m_tileMode; // 0x0D?
uint8_t m_antiAliasType; // 0
uint8_t m_levels;
bool m_unkFlag; // format-related
uint8_t m_unk11; // format-related
uint8_t m_unk12;
uint8_t m_unk13;
// sga::imageParams end
uint16_t m_usageCount; // 1
pgPtr<char> m_name;
pgPtr<sga::ShaderResourceView> m_srv;
pgPtr<void> m_pixelData;
uint32_t m_unk18;
uint32_t m_unk19;
uint64_t m_unk20;
#endif

public:
Expand Down Expand Up @@ -282,11 +284,13 @@ class grcTexture :

m_tileMode = 0xD;
m_antiAliasType = 0;
m_unkFlag = false;
m_unk11 = 0;
m_unk12 = 0;
m_unk13 = 0;
m_usageCount = 1;
m_blockPad = 0;
m_unk18 = 0;
m_unk19 = 0;
m_unk20 = 0;
#endif
}

Expand Down Expand Up @@ -1096,8 +1100,8 @@ class grcTextureRef : public datBase
memset(m_pad, 0, sizeof(m_pad));
memset(m_pad2, 0, sizeof(m_pad2));

m_const1 = 1;
m_const2 = 2;
m_const1 = 0;
m_const2 = 0;
}

inline char* GetName()
Expand Down

0 comments on commit 9e7d797

Please sign in to comment.