Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: replace atomic models with clump models #3003

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0173302
b
CrosRoad95 May 11, 2023
c0e3998
next
CrosRoad95 May 12, 2023
f93bb59
first working version
CrosRoad95 May 12, 2023
59e636d
cleanup
CrosRoad95 May 12, 2023
12d49f7
improvments, cleanup
CrosRoad95 May 12, 2023
2677719
cleanup
CrosRoad95 May 12, 2023
f279e81
cleanup
CrosRoad95 May 12, 2023
7952e9b
Merge branch 'master' into feature/clump-models
CrosRoad95 May 13, 2023
f16fbc4
Merge branch 'master' into feature/clump-models
CrosRoad95 May 19, 2023
022140d
Merge branch 'master' into feature/clump-models
CrosRoad95 Jun 18, 2023
f83483a
Merge branch 'master' into feature/clump-models
CrosRoad95 Jun 27, 2023
bd76dea
improvments
CrosRoad95 Jun 27, 2023
1ef7796
add test function to get atomics count
CrosRoad95 Jun 29, 2023
b6ac5d0
Merge branch 'master' into feature/clump-models
CrosRoad95 Jun 30, 2023
144e08b
refactor it, improve
CrosRoad95 Jul 1, 2023
cb5b47a
cleanup
CrosRoad95 Jul 1, 2023
e92a9d8
cleanup
CrosRoad95 Jul 1, 2023
ea38ccf
Merge branch 'master' into feature/clump-models
CrosRoad95 Jul 4, 2023
16d3874
Merge branch 'master' into feature/clump-models
CrosRoad95 Jul 9, 2023
afe3871
Merge branch 'master' into feature/clump-models
CrosRoad95 Jul 9, 2023
4da3cbc
Merge branch 'master' into feature/clump-models
CrosRoad95 Jul 25, 2023
52852e9
fixes acording to tederis suggestions
CrosRoad95 Jul 25, 2023
cddc15e
Merge branch 'master' into feature/clump-models
CrosRoad95 Jul 26, 2023
b868886
merge master
CrosRoad95 Aug 18, 2023
1346cb1
Merge branch 'feature/clump-models' of https://github.com/CrosRoad95/…
CrosRoad95 Aug 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Client/game_sa/CAtomicModelInfoSAInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CAtomicModelInfoSAInterface.cpp
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/

#pragma once

class CAtomicModelInfo_SA_VTBL : public CBaseModelInfo_SA_VTBL
{
public:
DWORD SetAtomic; // (RpAtomic*)
};

class CAtomicModelInfoSAInterface : public CBaseModelInfoSAInterface
{
};
138 changes: 138 additions & 0 deletions Client/game_sa/CBaseModelInfoSAInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CBaseModelInfoSAInterface.h
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/

#pragma once

class CColModelSAInterface;
class RwObject;

enum class eModelSpecialType : unsigned char
{
NONE = 0,
TREE = 1,
PALM = 2,
GLASS_1 = 4,
GLASS_2 = 5,
TAG = 6,
GARAGE_DOOR = 7,
CRANE = 9, // Not present in IDE but used in gta
UNKNOW_1 = 10, // Read only
BREAKABLE_STATUE = 11,
};

/**
* \todo Fill this class with info from R*
*/
class CBaseModelInfo_SA_VTBL
{
public:
DWORD Destructor;
DWORD AsAtomicModelInfoPtr; // ()
DWORD AsDamageAtomicModelInfoPtr; // ()
DWORD AsLodAtomicModelInfoPtr; // ()
DWORD GetModelType; // () - Not defined in the base
DWORD GetTimeInfo; // ()
DWORD Init; // ()
DWORD Shutdown; // ()
DWORD DeleteRwObject; // () - Not defined in the base
DWORD GetRwModelType; // () - Not defined in the base
DWORD CreateInstance_; // (RwMatrix*) - Not defined in the base
DWORD CreateInstance; // () - Not defined in the base
DWORD SetAnimFile; // (char const*)
DWORD ConvertAnimFileIndex; // ()
DWORD GetAnimFileIndex; // ()
};

class CBaseModelInfoSAInterface
{
public:
CBaseModelInfo_SA_VTBL* VFTBL; // +0

unsigned long ulHashKey; // +4 Generated by CKeyGen::GetUppercaseKey(char const *) called by CBaseModelInfo::SetModelName(char const *)
unsigned short usNumberOfRefs : 16; // +8
unsigned short usTextureDictionary : 16; // +10
unsigned char ucAlpha : 8; // +12

unsigned char ucNumOf2DEffects : 8; // +13
unsigned short usUnknown : 16; // +14 Something with 2d effects

unsigned short usDynamicIndex : 16; // +16

// Flags used by CBaseModelInfo
union
{
struct
{
unsigned char bHasBeenPreRendered : 1; // we use this because we need to apply changes only once
unsigned char bAlphaTransparency : 1; // bDrawLast
unsigned char bAdditiveRender : 1;
unsigned char bDontWriteZBuffer : 1;
unsigned char bDontCastShadowsOn : 1;
unsigned char bDoWeOwnTheColModel : 1;
unsigned char bIsBackfaceCulled : 1;
unsigned char bIsColLoaded : 1;
unsigned char bIsRoad : 1;
unsigned char bHasComplexHierarchy : 1;
unsigned char bDontCollideWithFlyer : 1;
eModelSpecialType eSpecialModelType : 4;
unsigned char bWetRoadReflection : 1; // Used for tags
};

unsigned short usFlags;
};

CColModelSAInterface* pColModel; // +20 CColModel: public CBoundingBox

float fLodDistanceUnscaled; // +24 Scaled is this value multiplied with flt_B6F118
RwObject* pRwObject; // +28

// CWeaponModelInfo:
// +36 = Weapon info as int

// CPedModelInfo:
// +36 = Motion anim group (AssocGroupID, long)
// +40 = Default ped type (long)
// +44 = Default ped stats (ePedStats)
// +48 = Can drive cars (byte)
// +50 = Ped flags (short)
// +52 = Hit col model (CColModel*)
// +56 = First radio station
// +57 = Second radio station
// +58 = Race (byte)
// +60 = Audio ped type (short)
// +62 = First voice
// +64 = Last voice
// +66 = Next voice (short)

// CVehicleModelInfo:
// +36 = Custom plate material (RpMaterial*)
// +49 = Custom plate design (byte)
// +50 = Pointer to game name (const char*)
// +60 = Vehicle type (enum, int)
// +64 = Wheel scale (float). Front/rear?
// +68 = Wheel scale (float). Front/rear?
// +72 = Wheel model id
// +74 = Vehicle handling ID (word)
// +76 = Number of doors (byte)
// +77 = Vehicle list (byte)
// +78 = Vehicle flags (byte)
// +79 = Wheel upgrade class (byte)
// +80 = Number of times used (byte)
// +82 = Vehicle freq (short)
// +84 = Component rules mask (long)
// +88 = Steer angle
// +92 = Pointer to some class containing back seat position @ +60 probably dummy storage.
// +180 = Vehicle upgrade position descriptors array (32 bytes each)
// +720 = Number of possible colors
// +726 = Word array as referenced in CVehicleModelInfo::GetVehicleUpgrade(int)
// +762 = Array of WORD containing something relative to paintjobs
// +772 = Anim file index
};
static_assert(sizeof(CBaseModelInfoSAInterface) == 0x20, "Invalid size for CBaseModelInfoSAInterface");
28 changes: 28 additions & 0 deletions Client/game_sa/CClumpModelInfoSAInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CClumpModelInfoSAInterface.cpp
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/

#pragma once

class CClumpModelInfo_SA_VTBL : public CBaseModelInfo_SA_VTBL
{
public:
DWORD GetBoundingBox;
DWORD SetClump; // (RpClump*)
};

class CClumpModelInfoSAInterface : public CBaseModelInfoSAInterface
{
public:
union
{
char* m_animFileName;
uint32 m_nAnimFileIndex;
};
};
71 changes: 71 additions & 0 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include "CPedSA.h"
#include "CWorldSA.h"
#include "gamesa_renderware.h"
#include "CBaseModelInfoSAInterface.h"
#include "CAtomicModelInfoSAInterface.h"
#include "CClumpModelInfoSAInterface.h"

extern CCoreInterface* g_pCore;
extern CGameSA* pGame;
Expand Down Expand Up @@ -72,6 +75,8 @@ union tIdeFlags
};

static constexpr uintptr_t vftable_CVehicleModelInfo = 0x85C5C8u;
static constexpr uintptr_t vftable_CAtomicModelModelInfo = 0x85BBF0u;
static constexpr uintptr_t vftable_CClumpModelModelInfo = 0x85BD30u;
static constexpr size_t RESOURCE_ID_COL = 25000;

static void CBaseModelInfo_SetColModel(CBaseModelInfoSAInterface* self, CColModelSAInterface* colModel, bool applyToPairedModel)
Expand Down Expand Up @@ -1457,6 +1462,7 @@ bool CModelInfoSA::SetCustomModel(RpClump* pClump)
case eModelInfoType::ATOMIC:
case eModelInfoType::LOD_ATOMIC:
case eModelInfoType::TIME:
case eModelInfoType::CLUMP:
success = pGame->GetRenderWare()->ReplaceAllAtomicsInModel(pClump, static_cast<unsigned short>(m_dwModelID));
break;
default:
Expand Down Expand Up @@ -1744,6 +1750,71 @@ void CModelInfoSA::MakeVehicleAutomobile(ushort usBaseID)
CopyStreamingInfoFromModel(usBaseID);
}

bool GetFirstAtomic(RpAtomic* atomic, void* data)
{
RpAtomic** firstAtomicPtr = (RpAtomic**)data;

if (*firstAtomicPtr == nullptr)
*firstAtomicPtr = atomic;

return false;
}

bool CModelInfoSA::MakeAtomicModel()
{
if (GetModelType() != eModelInfoType::CLUMP)
return false;

CBaseModelInfoSAInterface* pBaseObjectInfo = (CBaseModelInfoSAInterface*)ppModelInfo[m_dwModelID];
CAtomicModelInfoSAInterface* pInterface = new CAtomicModelInfoSAInterface();
MemCpyFast(pInterface, pBaseObjectInfo, sizeof(CBaseModelInfoSAInterface));

CAtomicModelInfo_SA_VTBL* vfbl = (CAtomicModelInfo_SA_VTBL*)vftable_CAtomicModelModelInfo;
pInterface->VFTBL = vfbl;
RpClump* pClump = (RpClump*)pInterface->pRwObject;
RpAtomic* firstAtomic = nullptr;
RpClumpForAllAtomics(pClump, GetFirstAtomic, &firstAtomic);
RwFrame* pFrame = RwFrameCreate();
RpAtomic* pClonedAtomic = RpAtomicClone(firstAtomic);
RpAtomicSetFrame(pClonedAtomic, pFrame);

pInterface->pRwObject = nullptr;
((void(__thiscall*)(CAtomicModelInfoSAInterface * pThis, RpAtomic * pAtomic)) vfbl->SetAtomic)(pInterface, pClonedAtomic);

delete reinterpret_cast<CClumpModelInfoSAInterface*>(ppModelInfo[m_dwModelID]);
ppModelInfo[m_dwModelID] = pInterface;

RpClumpDestroy(pClump);
m_dwParentID = -1;
return true;
}

bool CModelInfoSA::MakeClumpModel()
{
if (GetModelType() != eModelInfoType::ATOMIC)
return false;

CBaseModelInfoSAInterface* pBaseObjectInfo = (CBaseModelInfoSAInterface*)ppModelInfo[m_dwModelID];
CClumpModelInfoSAInterface* pInterface = new CClumpModelInfoSAInterface();
MemCpyFast(pInterface, pBaseObjectInfo, sizeof(CBaseModelInfoSAInterface));
pInterface->m_nAnimFileIndex = -1;

CClumpModelInfo_SA_VTBL* vfbl = (CClumpModelInfo_SA_VTBL*)vftable_CClumpModelModelInfo;
pInterface->VFTBL = vfbl;
RpClump* pClump = RpClumpCreate();
RpAtomic* pAtomic = (RpAtomic*)pInterface->pRwObject;
RpSetFrame(pClump, RwFrameCreate());
RpClumpAddAtomic(pClump, pAtomic);

((void(__thiscall*)(CClumpModelInfoSAInterface * pThis, RpClump * clump)) vfbl->SetClump)(pInterface, pClump);

delete reinterpret_cast<CBaseModelInfoSAInterface*>(ppModelInfo[m_dwModelID]);
ppModelInfo[m_dwModelID] = pInterface;

m_dwParentID = -1;
return true;
}

void CModelInfoSA::DeallocateModel(void)
{
Remove();
Expand Down
Loading
Loading