Skip to content

Commit

Permalink
Allow allocating new objects
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Sep 26, 2020
1 parent d7f42c6 commit bfa404d
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 33 deletions.
14 changes: 14 additions & 0 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,20 @@ void CModelInfoSA::MakePedModel(char* szTexture)
pGame->GetStreaming()->RequestSpecialModel(m_dwModelID, szTexture, 0);
}

void CModelInfoSA::MakeObjectModel(ushort usBaseID)
{
ppModelInfo[m_dwModelID] = ppModelInfo[usBaseID];
CStreamingInfo* pBaseModelStreamigInfo = pGame->GetStreaming()->GetStreamingInfoFromModelId(usBaseID);
CStreamingInfo* pTargetModelStreamigInfo = pGame->GetStreaming()->GetStreamingInfoFromModelId(m_dwModelID);
pTargetModelStreamigInfo->loadState = 0;
pTargetModelStreamigInfo->nextInImg = -1;
pTargetModelStreamigInfo->nextId = -1;
pTargetModelStreamigInfo->prevId = -1;
pTargetModelStreamigInfo->archiveId = pBaseModelStreamigInfo->archiveId;
pTargetModelStreamigInfo->offsetInBlocks = pBaseModelStreamigInfo->offsetInBlocks;
pTargetModelStreamigInfo->sizeInBlocks = pBaseModelStreamigInfo->sizeInBlocks;
}

void CModelInfoSA::DeallocateModel(void)
{
Remove();
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ class CModelInfoSA : public CModelInfo

CBaseModelInfoSAInterface* GetInterface();
CPedModelInfoSAInterface* GetPedModelInfoInterface() { return reinterpret_cast<CPedModelInfoSAInterface*>(GetInterface()); }
CObjectSAInterface* GetObjectInterface() { return reinterpret_cast<CObjectSAInterface*>(GetInterface()); }

DWORD GetModel() { return m_dwModelID; }
eModelInfoType GetModelType();
Expand Down Expand Up @@ -379,6 +380,7 @@ class CModelInfoSA : public CModelInfo

// CModelInfoSA methods
void MakePedModel(char* szTexture);
void MakeObjectModel(ushort usBaseModelID);
void DeallocateModel(void);

SVehicleSupportedUpgrades GetVehicleSupportedUpgrades() { return m_ModelSupportedUpgrades; }
Expand Down
12 changes: 0 additions & 12 deletions Client/game_sa/CStreamingSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@
#define FUNC_CStreaming_RemoveImages 0x4066B3 // Remove all IMG`s from streaming
#define FUNC_CStreaming_RemoveImage 0x4068A0

struct CStreamingInfo
{
WORD prevId;
WORD nextId;
WORD nextInImg;
uchar flg;
uchar archiveId;
DWORD offsetInBlocks;
DWORD sizeInBlocks;
DWORD loadState;
};

struct CStreamHandlerInfo
{
char szName[40];
Expand Down
12 changes: 11 additions & 1 deletion Client/mods/deathmatch/logic/CClientModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ bool CClientModel::Allocate(void)
// Allocate only on free IDs
if (!pModelInfo->IsValid())
{
pModelInfo->MakePedModel("PSYCHO");
switch (m_eModelType)
{
case CCLIENTMODELPED:
pModelInfo->MakePedModel("PSYCHO");
break;
case CCLIENTMODELOBJECT:
pModelInfo->MakeObjectModel(1337);
break;
default:
return false;
}
return true;
}
return false;
Expand Down
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/CClientModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class CClientModel;

enum eClientModelType
{
CCLIENTMODELPED
CCLIENTMODELPED,
CCLIENTMODELOBJECT,
};

class CClientModel
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ int CLuaEngineDefs::EngineRequestModel(lua_State* luaVM)
{
eModelType = CCLIENTMODELPED;
}
else if (strModelType == "object")
eModelType = CCLIENTMODELOBJECT;
else
{
lua_pushboolean(luaVM, false);
Expand Down
21 changes: 2 additions & 19 deletions Client/multiplayer_sa/CMultiplayerSA_CrashFixHacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,23 +998,6 @@ void _declspec(naked) HOOK_CClumpModelInfo_GetFrameFromId()
}
}

struct CStreamingInfo
{
DWORD gta_hash;
WORD chain_next;
uchar flg;
uchar archiveId;
DWORD offsetInBlocks;
DWORD sizeInBlocks;
DWORD reqload;
};

CStreamingInfo* GetStreamingInfoFromModelId(uint id)
{
CStreamingInfo* pItemInfo = (CStreamingInfo*)(0x8E4CC0);
return pItemInfo + id;
}

//////////////////////////////////////////////////////////////////////////////////////////
//
// CEntity::GetBoundRect
Expand All @@ -1041,11 +1024,11 @@ void OnMY_CEntity_GetBoundRect(CEntitySAInterface* pEntity)
if (!pColModel)
{
// Crash will occur at offset 00134134
CStreamingInfo* pStreamingInfo = GetStreamingInfoFromModelId(usModelId);
CStreamingInfo* pStreamingInfo = pGameInterface->GetStreaming()->GetStreamingInfoFromModelId(usModelId);
SString strDetails("refs:%d txd:%d RwObj:%08x bOwn:%d bColStr:%d flg:%d off:%d size:%d reqload:%d", pModelInfo->usNumberOfRefs,
pModelInfo->usTextureDictionary, pModelInfo->pRwObject, pModelInfo->bDoWeOwnTheColModel,
pModelInfo->bCollisionWasStreamedWithModel, pStreamingInfo->flg, pStreamingInfo->offsetInBlocks, pStreamingInfo->sizeInBlocks,
pStreamingInfo->reqload);
pStreamingInfo->loadState);
LogEvent(815, "Model collision missing", "CEntity_GetBoundRect", SString("No collision for model:%d %s", usModelId, *strDetails), 5415);
CArgMap argMap;
argMap.Set("id", usModelId);
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/game/CModelInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class CModelInfo
virtual void MakeCustomModel() = 0;
virtual RwObject* GetRwObject() = 0;
virtual void MakePedModel(char* szTexture) = 0;
virtual void MakeObjectModel(ushort usBaseID) = 0;

virtual SVehicleSupportedUpgrades GetVehicleSupportedUpgrades() = 0;
virtual void ResetSupportedUpgrades() = 0;
Expand Down
13 changes: 13 additions & 0 deletions Client/sdk/game/CStreaming.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@

#pragma once

struct CStreamingInfo
{
WORD prevId;
WORD nextId;
WORD nextInImg;
unsigned char flg;
unsigned char archiveId;
DWORD offsetInBlocks;
DWORD sizeInBlocks;
DWORD loadState;
};

class CStreaming
{
public:
Expand All @@ -20,5 +32,6 @@ class CStreaming
virtual void RequestSpecialModel(DWORD model, const char* szTexture, DWORD channel) = 0;
virtual unsigned char AddStreamHandler(const char* szFilePath) = 0;
//virtual BOOL RemoveStreamHandler(DWORD dwStreamHandler) = 0;
virtual CStreamingInfo* GetStreamingInfoFromModelId(unsigned short id) = 0;
virtual bool SetModelStreamInfo(unsigned short id, unsigned char ucArchiveId, unsigned short usOffestInBlocks, unsigned short usSizeInBlocks) = 0;
};

0 comments on commit bfa404d

Please sign in to comment.