1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-12-22 23:50:00 +00:00

changes to RW layer so loading foreign files works

This commit is contained in:
aap 2020-11-11 09:42:30 +01:00
parent 460f3cea44
commit 546ed0ff07
8 changed files with 143 additions and 22 deletions

View file

@ -332,6 +332,16 @@ CFileLoader::FindRelatedModelInfoCB(RpAtomic *atomic, void *data)
return atomic; return atomic;
} }
#ifdef LIBRW
void
InitClump(RpClump *clump)
{
RpClumpForAllAtomics(clump, ConvertPlatformAtomic, nil);
}
#else
#define InitClump(clump)
#endif
void void
CFileLoader::LoadModelFile(const char *filename) CFileLoader::LoadModelFile(const char *filename)
{ {
@ -343,6 +353,7 @@ CFileLoader::LoadModelFile(const char *filename)
if(RwStreamFindChunk(stream, rwID_CLUMP, nil, nil)){ if(RwStreamFindChunk(stream, rwID_CLUMP, nil, nil)){
clump = RpClumpStreamRead(stream); clump = RpClumpStreamRead(stream);
if(clump){ if(clump){
InitClump(clump);
RpClumpForAllAtomics(clump, FindRelatedModelInfoCB, clump); RpClumpForAllAtomics(clump, FindRelatedModelInfoCB, clump);
RpClumpDestroy(clump); RpClumpDestroy(clump);
} }
@ -368,6 +379,7 @@ CFileLoader::LoadClumpFile(const char *filename)
GetNameAndLOD(nodename, name, &n); GetNameAndLOD(nodename, name, &n);
mi = (CClumpModelInfo*)CModelInfo::GetModelInfo(name, nil); mi = (CClumpModelInfo*)CModelInfo::GetModelInfo(name, nil);
if(mi){ if(mi){
InitClump(clump);
assert(mi->IsClump()); assert(mi->IsClump());
mi->SetClump(clump); mi->SetClump(clump);
}else }else
@ -393,6 +405,7 @@ CFileLoader::LoadClumpFile(RwStream *stream, uint32 id)
if (mi->GetModelType() == MITYPE_PED && id != 0 && RwStreamFindChunk(stream, rwID_CLUMP, nil, nil)) { if (mi->GetModelType() == MITYPE_PED && id != 0 && RwStreamFindChunk(stream, rwID_CLUMP, nil, nil)) {
// Read LOD ped // Read LOD ped
clump = RpClumpStreamRead(stream); clump = RpClumpStreamRead(stream);
InitClump(clump);
if(clump){ if(clump){
((CPedModelInfo*)mi)->SetLowDetailClump(clump); ((CPedModelInfo*)mi)->SetLowDetailClump(clump);
RpClumpDestroy(clump); RpClumpDestroy(clump);
@ -423,6 +436,7 @@ CFileLoader::FinishLoadClumpFile(RwStream *stream, uint32 id)
clump = RpClumpGtaStreamRead2(stream); clump = RpClumpGtaStreamRead2(stream);
if(clump){ if(clump){
InitClump(clump);
mi = (CClumpModelInfo*)CModelInfo::GetModelInfo(id); mi = (CClumpModelInfo*)CModelInfo::GetModelInfo(id);
mi->SetClump(clump); mi->SetClump(clump);
return true; return true;
@ -443,6 +457,7 @@ CFileLoader::LoadAtomicFile(RwStream *stream, uint32 id)
clump = RpClumpStreamRead(stream); clump = RpClumpStreamRead(stream);
if(clump == nil) if(clump == nil)
return false; return false;
InitClump(clump);
gpRelatedModelInfo = (CSimpleModelInfo*)CModelInfo::GetModelInfo(id); gpRelatedModelInfo = (CSimpleModelInfo*)CModelInfo::GetModelInfo(id);
RpClumpForAllAtomics(clump, SetRelatedModelInfoCB, clump); RpClumpForAllAtomics(clump, SetRelatedModelInfoCB, clump);
RpClumpDestroy(clump); RpClumpDestroy(clump);
@ -806,6 +821,8 @@ CFileLoader::LoadAtomicFile2Return(const char *filename)
stream = RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, filename); stream = RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, filename);
if(RwStreamFindChunk(stream, rwID_CLUMP, nil, nil)) if(RwStreamFindChunk(stream, rwID_CLUMP, nil, nil))
clump = RpClumpStreamRead(stream); clump = RpClumpStreamRead(stream);
if(clump)
InitClump(clump);
RwStreamClose(stream, nil); RwStreamClose(stream, nil);
return clump; return clump;
} }

View file

@ -390,6 +390,7 @@ CStreaming::LoadCdDirectory(const char *dirname, int n)
assert(sizeof(direntry) == 32); assert(sizeof(direntry) == 32);
while(CFileMgr::Read(fd, (char*)&direntry, sizeof(direntry))){ while(CFileMgr::Read(fd, (char*)&direntry, sizeof(direntry))){
dot = strchr(direntry.name, '.'); dot = strchr(direntry.name, '.');
assert(dot);
if(dot) *dot = '\0'; if(dot) *dot = '\0';
if(direntry.size > (uint32)ms_streamingBufferSize) if(direntry.size > (uint32)ms_streamingBufferSize)
ms_streamingBufferSize = direntry.size; ms_streamingBufferSize = direntry.size;

View file

@ -89,7 +89,11 @@ RwRGBA gColourTop;
bool gameAlreadyInitialised; bool gameAlreadyInitialised;
float NumberOfChunksLoaded; float NumberOfChunksLoaded;
#ifdef GTA_PS2
#define TOTALNUMCHUNKS 48.0f
#else
#define TOTALNUMCHUNKS 73.0f #define TOTALNUMCHUNKS 73.0f
#endif
bool g_SlowMode = false; bool g_SlowMode = false;
char version_name[64]; char version_name[64];

View file

@ -294,32 +294,12 @@ RwTextureAddressMode RwTextureGetAddressingV(const RwTexture *texture);
// TODO // TODO
void _rwD3D8TexDictionaryEnableRasterFormatConversion(bool enable) { } void _rwD3D8TexDictionaryEnableRasterFormatConversion(bool enable) { }
static rw::Raster*
ConvertTexRaster(rw::Raster *ras)
{
using namespace rw;
if(ras->platform == rw::platform)
return ras;
// compatible platforms
if(ras->platform == PLATFORM_D3D8 && rw::platform == PLATFORM_D3D9 ||
ras->platform == PLATFORM_D3D9 && rw::platform == PLATFORM_D3D8)
return ras;
Image *img = ras->toImage();
ras->destroy();
img->unpalettize();
ras = Raster::createFromImage(img);
img->destroy();
return ras;
}
// hack for reading native textures // hack for reading native textures
RwBool rwNativeTextureHackRead(RwStream *stream, RwTexture **tex, RwInt32 size) RwBool rwNativeTextureHackRead(RwStream *stream, RwTexture **tex, RwInt32 size)
{ {
*tex = Texture::streamReadNative(stream); *tex = Texture::streamReadNative(stream);
#ifdef LIBRW #ifdef LIBRW
(*tex)->raster = ConvertTexRaster((*tex)->raster); (*tex)->raster = rw::Raster::convertTexToCurrentPlatform((*tex)->raster);
#endif #endif
return *tex != nil; return *tex != nil;
} }
@ -796,6 +776,9 @@ RwBool RpWorldPluginAttach(void) {
registerNativeDataPlugin(); registerNativeDataPlugin();
registerAtomicRightsPlugin(); registerAtomicRightsPlugin();
registerMaterialRightsPlugin(); registerMaterialRightsPlugin();
// not sure if this goes here
rw::xbox::registerVertexFormatPlugin();
return true; return true;
} }

View file

@ -12,6 +12,10 @@
#include "CutsceneHead.h" #include "CutsceneHead.h"
#include "CdStream.h" #include "CdStream.h"
#ifdef GTA_PS2_STUFF
// this is a total hack to switch between PC and PS2 code
static bool lastLoadedSKA;
#endif
CCutsceneHead::CCutsceneHead(CObject *obj) CCutsceneHead::CCutsceneHead(CObject *obj)
{ {
@ -87,6 +91,10 @@ CCutsceneHead::ProcessControl(void)
assert(RwObjectGetType(m_rwObject) == rpCLUMP); assert(RwObjectGetType(m_rwObject) == rpCLUMP);
atm = GetFirstAtomic((RpClump*)m_rwObject); atm = GetFirstAtomic((RpClump*)m_rwObject);
hier = RpSkinAtomicGetHAnimHierarchy(atm); hier = RpSkinAtomicGetHAnimHierarchy(atm);
#ifdef GTA_PS2_STUFF
// PS2 only plays anims in cutscene, PC always plays anims
if(!lastLoadedSKA || CCutsceneMgr::IsRunning())
#endif
RpHAnimHierarchyAddAnimTime(hier, CTimer::GetTimeStepNonClipped()/50.0f); RpHAnimHierarchyAddAnimTime(hier, CTimer::GetTimeStepNonClipped()/50.0f);
} }
@ -168,6 +176,10 @@ CCutsceneHead::PlayAnimation(const char *animName)
uint32 offset, size; uint32 offset, size;
RwStream *stream; RwStream *stream;
#ifdef GTA_PS2_STUFF
lastLoadedSKA = false;
#endif
assert(RwObjectGetType(m_rwObject) == rpCLUMP); assert(RwObjectGetType(m_rwObject) == rpCLUMP);
atm = GetFirstAtomic((RpClump*)m_rwObject); atm = GetFirstAtomic((RpClump*)m_rwObject);
hier = RpSkinAtomicGetHAnimHierarchy(atm); hier = RpSkinAtomicGetHAnimHierarchy(atm);
@ -191,4 +203,29 @@ CCutsceneHead::PlayAnimation(const char *animName)
RwStreamClose(stream, nil); RwStreamClose(stream, nil);
} }
#ifdef GTA_PS2_STUFF
#ifdef LIBRW
else{
sprintf(gString, "%s.ska", animName);
if(CCutsceneMgr::ms_pCutsceneDir->FindItem(gString, offset, size)){
stream = RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, "ANIM\\CUTS.IMG");
assert(stream);
CStreaming::MakeSpaceFor(size * CDSTREAM_SECTOR_SIZE);
CStreaming::ImGonnaUseStreamingMemory();
RwStreamSkip(stream, offset*2048);
anim = rw::Animation::streamReadLegacy(stream);
RpHAnimHierarchySetCurrentAnim(hier, anim);
CStreaming::IHaveUsedStreamingMemory();
RwStreamClose(stream, nil);
lastLoadedSKA = true;
}
}
#endif
#endif
} }

View file

@ -649,6 +649,83 @@ WRAPPER void _TexturePoolsInitialise() { EAXJMP(0x598B10); }
WRAPPER void _TexturePoolsShutdown() { EAXJMP(0x598B30); } WRAPPER void _TexturePoolsShutdown() { EAXJMP(0x598B30); }
#endif #endif
#ifdef LIBRW
#include <rpmatfx.h>
#include "VehicleModelInfo.h"
int32
findPlatform(rw::Atomic *a)
{
rw::Geometry *g = a->geometry;
if(g->instData)
return g->instData->platform;
return 0;
}
// in CVehicleModelInfo in VC
static RpMaterial*
GetMatFXEffectMaterialCB(RpMaterial *material, void *data)
{
if(RpMatFXMaterialGetEffects(material) == rpMATFXEFFECTNULL)
return material;
*(int*)data = RpMatFXMaterialGetEffects(material);
return nil;
}
// Game doesn't read atomic extensions so we never get any other than the default pipe,
// but we need it for uninstancing
void
attachPipe(rw::Atomic *atomic)
{
if(RpSkinGeometryGetSkin(RpAtomicGetGeometry(atomic)))
atomic->pipeline = rw::skinGlobals.pipelines[rw::platform];
else{
int fx = rpMATFXEFFECTNULL;
RpGeometryForAllMaterials(RpAtomicGetGeometry(atomic), GetMatFXEffectMaterialCB, &fx);
if(fx != rpMATFXEFFECTNULL)
RpMatFXAtomicEnableEffects(atomic);
}
}
// Attach pipes for the platform we have native data for so we can uninstance
void
switchPipes(rw::Atomic *a, int32 platform)
{
if(a->pipeline && a->pipeline->platform != platform){
uint32 plgid = a->pipeline->pluginID;
switch(plgid){
// assume default pipe won't be attached explicitly
case rw::ID_SKIN:
a->pipeline = rw::skinGlobals.pipelines[platform];
break;
case rw::ID_MATFX:
a->pipeline = rw::matFXGlobals.pipelines[platform];
break;
}
}
}
RpAtomic*
ConvertPlatformAtomic(RpAtomic *atomic, void *data)
{
int32 driver = rw::platform;
int32 platform = findPlatform(atomic);
if(platform != 0 && platform != driver){
attachPipe(atomic); // kludge
rw::ObjPipeline *origPipe = atomic->pipeline;
rw::platform = platform;
switchPipes(atomic, rw::platform);
if(atomic->geometry->flags & rw::Geometry::NATIVE)
atomic->uninstance();
// no ADC in this game
//rw::ps2::unconvertADC(atomic->geometry);
rw::platform = driver;
atomic->pipeline = origPipe;
}
return atomic;
}
#endif
#if defined(FIX_BUGS) && defined(GTA_PC) #if defined(FIX_BUGS) && defined(GTA_PC)
RwUInt32 saved_alphafunc, saved_alpharef; RwUInt32 saved_alphafunc, saved_alpharef;

View file

@ -56,6 +56,8 @@ RwCamera *CameraCreate(RwInt32 width,
void _TexturePoolsInitialise(); void _TexturePoolsInitialise();
void _TexturePoolsShutdown(); void _TexturePoolsShutdown();
RpAtomic *ConvertPlatformAtomic(RpAtomic *atomic, void *data);
#if defined(FIX_BUGS) && defined (GTA_PC) #if defined(FIX_BUGS) && defined (GTA_PC)
void SetAlphaTest(RwUInt32 alpharef); void SetAlphaTest(RwUInt32 alpharef);
void RestoreAlphaTest(); void RestoreAlphaTest();

2
vendor/librw vendored

@ -1 +1 @@
Subproject commit 8c00f787cb8f53781c4335ecbc9d28fb9c664ba7 Subproject commit 7e80d45cdb6663f97d89ed443198ce6e37c4435e