2020-04-09 18:50:24 +00:00
|
|
|
#include "common.h"
|
2020-04-17 13:31:11 +00:00
|
|
|
|
2020-04-09 18:50:24 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "PlayerSkin.h"
|
|
|
|
#include "TxdStore.h"
|
|
|
|
#include "rtbmp.h"
|
|
|
|
#include "ClumpModelInfo.h"
|
|
|
|
#include "VisibilityPlugins.h"
|
|
|
|
#include "World.h"
|
|
|
|
#include "PlayerInfo.h"
|
|
|
|
#include "CdStream.h"
|
|
|
|
#include "FileMgr.h"
|
|
|
|
#include "Directory.h"
|
|
|
|
#include "RwHelper.h"
|
|
|
|
#include "Timer.h"
|
|
|
|
#include "Lights.h"
|
|
|
|
|
2020-08-24 19:37:38 +00:00
|
|
|
//--MIAMI: file done
|
|
|
|
|
2020-04-10 08:41:48 +00:00
|
|
|
RpClump *gpPlayerClump;
|
|
|
|
float gOldFov;
|
|
|
|
|
2020-04-09 18:50:24 +00:00
|
|
|
int CPlayerSkin::m_txdSlot;
|
|
|
|
|
|
|
|
void
|
|
|
|
FindPlayerDff(uint32 &offset, uint32 &size)
|
|
|
|
{
|
|
|
|
int file;
|
|
|
|
CDirectory::DirectoryInfo info;
|
|
|
|
|
|
|
|
file = CFileMgr::OpenFile("models\\gta3.dir", "rb");
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (!CFileMgr::Read(file, (char*)&info, sizeof(CDirectory::DirectoryInfo)))
|
|
|
|
return;
|
|
|
|
} while (strcasecmp("player.dff", info.name) != 0);
|
|
|
|
|
|
|
|
offset = info.offset;
|
|
|
|
size = info.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LoadPlayerDff(void)
|
|
|
|
{
|
|
|
|
RwStream *stream;
|
|
|
|
RwMemory mem;
|
|
|
|
uint32 offset, size;
|
|
|
|
uint8 *buffer;
|
|
|
|
bool streamWasAdded = false;
|
|
|
|
|
|
|
|
if (CdStreamGetNumImages() == 0) {
|
|
|
|
CdStreamAddImage("models\\gta3.img");
|
|
|
|
streamWasAdded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
FindPlayerDff(offset, size);
|
|
|
|
buffer = (uint8*)RwMallocAlign(size << 11, 2048);
|
|
|
|
CdStreamRead(0, buffer, offset, size);
|
|
|
|
CdStreamSync(0);
|
|
|
|
|
|
|
|
mem.start = buffer;
|
|
|
|
mem.length = size << 11;
|
|
|
|
stream = RwStreamOpen(rwSTREAMMEMORY, rwSTREAMREAD, &mem);
|
|
|
|
|
|
|
|
if (RwStreamFindChunk(stream, rwID_CLUMP, nil, nil))
|
|
|
|
gpPlayerClump = RpClumpStreamRead(stream);
|
|
|
|
|
|
|
|
RwStreamClose(stream, &mem);
|
|
|
|
RwFreeAlign(buffer);
|
|
|
|
|
|
|
|
if (streamWasAdded)
|
|
|
|
CdStreamRemoveImages();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPlayerSkin::Initialise(void)
|
|
|
|
{
|
|
|
|
m_txdSlot = CTxdStore::AddTxdSlot("skin");
|
|
|
|
CTxdStore::Create(m_txdSlot);
|
|
|
|
CTxdStore::AddRef(m_txdSlot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPlayerSkin::Shutdown(void)
|
|
|
|
{
|
|
|
|
CTxdStore::RemoveTxdSlot(m_txdSlot);
|
|
|
|
}
|
|
|
|
|
|
|
|
RwTexture *
|
|
|
|
CPlayerSkin::GetSkinTexture(const char *texName)
|
|
|
|
{
|
|
|
|
RwTexture *tex;
|
|
|
|
RwRaster *raster;
|
|
|
|
int32 width, height, depth, format;
|
|
|
|
|
|
|
|
CTxdStore::PushCurrentTxd();
|
|
|
|
CTxdStore::SetCurrentTxd(m_txdSlot);
|
|
|
|
tex = RwTextureRead(texName, NULL);
|
|
|
|
CTxdStore::PopCurrentTxd();
|
2020-04-10 08:41:48 +00:00
|
|
|
if (tex != nil) return tex;
|
2020-04-09 18:50:24 +00:00
|
|
|
|
2020-08-29 16:22:25 +00:00
|
|
|
if (strcmp(DEFAULT_SKIN_NAME, texName) == 0 || texName[0] == '\0')
|
2020-04-09 18:50:24 +00:00
|
|
|
sprintf(gString, "models\\generic\\player.bmp");
|
|
|
|
else
|
|
|
|
sprintf(gString, "skins\\%s.bmp", texName);
|
|
|
|
|
|
|
|
if (RwImage *image = RtBMPImageRead(gString)) {
|
|
|
|
RwImageFindRasterFormat(image, rwRASTERTYPETEXTURE, &width, &height, &depth, &format);
|
|
|
|
raster = RwRasterCreate(width, height, depth, format);
|
|
|
|
RwRasterSetFromImage(raster, image);
|
|
|
|
|
|
|
|
tex = RwTextureCreate(raster);
|
|
|
|
RwTextureSetName(tex, texName);
|
2020-08-24 19:37:38 +00:00
|
|
|
RwTextureSetFilterMode(tex, rwFILTERLINEAR);
|
2020-04-09 18:50:24 +00:00
|
|
|
RwTexDictionaryAddTexture(CTxdStore::GetSlot(m_txdSlot)->texDict, tex);
|
|
|
|
|
|
|
|
RwImageDestroy(image);
|
|
|
|
}
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPlayerSkin::BeginFrontendSkinEdit(void)
|
|
|
|
{
|
|
|
|
LoadPlayerDff();
|
2020-05-11 02:55:57 +00:00
|
|
|
RpClumpForAllAtomics(gpPlayerClump, CClumpModelInfo::SetAtomicRendererCB, (void*)CVisibilityPlugins::RenderPlayerCB);
|
2020-04-09 18:50:24 +00:00
|
|
|
CWorld::Players[0].LoadPlayerSkin();
|
|
|
|
gOldFov = CDraw::GetFOV();
|
|
|
|
CDraw::SetFOV(30.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPlayerSkin::EndFrontendSkinEdit(void)
|
|
|
|
{
|
|
|
|
RpClumpDestroy(gpPlayerClump);
|
|
|
|
gpPlayerClump = NULL;
|
|
|
|
CDraw::SetFOV(gOldFov);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPlayerSkin::RenderFrontendSkinEdit(void)
|
|
|
|
{
|
|
|
|
static float rotation = 0.0f;
|
|
|
|
RwRGBAReal AmbientColor = { 0.65f, 0.65f, 0.65f, 1.0f };
|
2020-04-10 08:41:48 +00:00
|
|
|
const RwV3d pos = { 1.35f, 0.35f, 7.725f };
|
2020-08-24 19:37:38 +00:00
|
|
|
const RwV3d axis = { 0.0f, 1.0f, 0.0f };
|
2020-04-09 18:50:24 +00:00
|
|
|
static uint32 LastFlash = 0;
|
|
|
|
|
|
|
|
RwFrame *frame = RpClumpGetFrame(gpPlayerClump);
|
|
|
|
|
|
|
|
if (CTimer::GetTimeInMillisecondsPauseMode() - LastFlash > 7) {
|
|
|
|
rotation += 2.0f;
|
|
|
|
if (rotation > 360.0f)
|
|
|
|
rotation -= 360.0f;
|
|
|
|
LastFlash = CTimer::GetTimeInMillisecondsPauseMode();
|
|
|
|
}
|
|
|
|
RwFrameTransform(frame, RwFrameGetMatrix(RwCameraGetFrame(Scene.camera)), rwCOMBINEREPLACE);
|
|
|
|
RwFrameTranslate(frame, &pos, rwCOMBINEPRECONCAT);
|
2020-08-24 19:37:38 +00:00
|
|
|
RwFrameRotate(frame, &axis, rotation, rwCOMBINEPRECONCAT);
|
2020-04-09 18:50:24 +00:00
|
|
|
RwFrameUpdateObjects(frame);
|
|
|
|
SetAmbientColours(&AmbientColor);
|
|
|
|
RpClumpRender(gpPlayerClump);
|
|
|
|
}
|