Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/heli_rotor_speed
Browse files Browse the repository at this point in the history
  • Loading branch information
botder authored Dec 30, 2024
2 parents 182816a + 808ddf0 commit 0c9b0cf
Show file tree
Hide file tree
Showing 38 changed files with 442 additions and 220 deletions.
22 changes: 20 additions & 2 deletions Client/core/CScreenShot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ static bool ms_bIsSaving = false;
static uint ms_uiWidth = 0;
static uint ms_uiHeight = 0;

// whether we want to actually save photo in documents folder
static bool savePhotoInDocuments = false;

void CScreenShot::InitiateScreenShot(bool bIsCameraShot)
{
if (ms_bScreenShot || ms_bIsSaving || IsRateLimited(bIsCameraShot))
Expand All @@ -48,8 +51,11 @@ void CScreenShot::InitiateScreenShot(bool bIsCameraShot)

if (bIsCameraShot)
{
// Set the screenshot path to camera gallery path
ms_strScreenDirectoryPath = PathJoin(GetSystemPersonalPath(), "GTA San Andreas User Files", "Gallery");
if (savePhotoInDocuments)
{
// Set the screenshot path to camera gallery path
ms_strScreenDirectoryPath = PathJoin(GetSystemPersonalPath(), "GTA San Andreas User Files", "Gallery");
}
}
else
{
Expand Down Expand Up @@ -82,6 +88,13 @@ void CScreenShot::CheckForScreenShot(bool bBeforeGUI)
// Update last time of taken screenshot of given type
ms_lLastSaveTime[ms_bIsCameraShot] = GetTickCount64_();

if (ms_bIsCameraShot && !savePhotoInDocuments)
{
ClearBuffer();
ms_bScreenShot = false;
return;
}

ms_strScreenShotPath = GetScreenshotPath();
ms_uiWidth = CDirect3DData::GetSingleton().GetViewportWidth();
ms_uiHeight = CDirect3DData::GetSingleton().GetViewportHeight();
Expand Down Expand Up @@ -205,3 +218,8 @@ void CScreenShot::ClearBuffer()
{
ms_ScreenShotBuffer.Clear();
}

void CScreenShot::SetPhotoSavingInsideDocuments(bool savePhoto) noexcept
{
savePhotoInDocuments = savePhoto;
}
1 change: 1 addition & 0 deletions Client/core/CScreenShot.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CScreenShot
public:
static void InitiateScreenShot(bool bIsCameraShot);
static void CheckForScreenShot(bool bBeforeGUI);
static void SetPhotoSavingInsideDocuments(bool bSavePhoto) noexcept;

protected:
static void StartSaveThread();
Expand Down
15 changes: 15 additions & 0 deletions Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,12 @@ void CSettings::CreateGUI()
m_pCachePathValue->AutoSize();
vecTemp.fY += fLineHeight;

// Enable camera photos getting saved to documents folder
m_pPhotoSavingCheckbox = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabAdvanced, _("Save photos taken by camera weapon to GTA San Andreas User Files folder"), true));
m_pPhotoSavingCheckbox->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY));
m_pPhotoSavingCheckbox->AutoSize(NULL, 20.0f);
vecTemp.fY += fLineHeight;

// Auto updater section label
m_pAdvancedUpdaterLabel = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabAdvanced, _("Auto updater")));
m_pAdvancedUpdaterLabel->SetPosition(CVector2D(vecTemp.fX - 10.0f, vecTemp.fY));
Expand Down Expand Up @@ -3218,6 +3224,10 @@ void CSettings::LoadData()
iVar = GetApplicationSettingInt("Win8MouseFix");
m_pWin8MouseCheckBox->SetSelected(iVar != 0);

// Save camera photos inside user documents folder
CVARS_GET("photosaving", bVar);
m_pPhotoSavingCheckbox->SetSelected(bVar);

// Update build type
CVARS_GET("update_build_type", iVar);
if (iVar == 0 || iVar == 1)
Expand Down Expand Up @@ -3609,6 +3619,11 @@ void CSettings::SaveData()
// Windows 8 mouse fix
SetApplicationSettingInt("Win8MouseFix", m_pWin8MouseCheckBox->GetSelected());

// Save photos in documents folder
bool photoSaving = m_pPhotoSavingCheckbox->GetSelected();
CVARS_SET("photosaving", photoSaving);
CScreenShot::SetPhotoSavingInsideDocuments(photoSaving);

// Debug setting
if (CGUIListItem* pSelected = m_pDebugSettingCombo->GetSelectedItem())
{
Expand Down
1 change: 1 addition & 0 deletions Client/core/CSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class CSettings
CGUILabel* m_pWin8Label;
CGUICheckBox* m_pWin8ColorCheckBox;
CGUICheckBox* m_pWin8MouseCheckBox;
CGUICheckBox* m_pPhotoSavingCheckbox;
CGUILabel* m_pUpdateBuildTypeLabel;
CGUIComboBox* m_pUpdateBuildTypeCombo;
CGUILabel* m_pUpdateAutoInstallLabel;
Expand Down
26 changes: 26 additions & 0 deletions Client/core/DXHook/CProxyDirect3D9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
*****************************************************************************/

#include "StdInc.h"
#include <dwmapi.h>
#include <resource.h>

extern HINSTANCE g_hModule;

HRESULT HandleCreateDeviceResult(HRESULT hResult, IDirect3D9* pDirect3D, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags,
D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface);
std::vector<IDirect3D9*> ms_CreatedDirect3D9List;
Expand Down Expand Up @@ -166,6 +171,27 @@ HRESULT CProxyDirect3D9::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND
SetWindowTextW(hFocusWindow, MbUTF8ToUTF16("MTA: San Andreas").c_str());
#endif

// Set dark titlebar if needed
BOOL darkTitleBar = GetSystemRegistryValue((uint)HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme") == "\x0";
DwmSetWindowAttribute(hFocusWindow, DWMWA_USE_IMMERSIVE_DARK_MODE, &darkTitleBar, sizeof(darkTitleBar));

// Update icon
if (HICON icon = LoadIcon(g_hModule, MAKEINTRESOURCE(IDI_ICON1)))
{
const auto paramIcon = reinterpret_cast<LPARAM>(icon);
for (const WPARAM size : {ICON_SMALL, ICON_BIG})
{
SendMessage(hFocusWindow, WM_SETICON, size, paramIcon);
}

// Clean
DestroyIcon(icon);
}

// Redraw, we avoid possible problems with the fact that it won't replace the icon somewhere
InvalidateRect(hFocusWindow, nullptr, TRUE);
UpdateWindow(hFocusWindow);

// Detect if second call to CreateDevice
if (CreateDeviceSecondCallCheck(hResult, m_pDevice, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface))
{
Expand Down
2 changes: 1 addition & 1 deletion Client/core/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ project "Client Core"

links {
"ws2_32", "d3dx9", "Userenv", "DbgHelp", "xinput", "Imagehlp", "dxguid", "dinput8",
"strmiids", "odbc32", "odbccp32", "shlwapi", "winmm", "gdi32", "Imm32", "Psapi",
"strmiids", "odbc32", "odbccp32", "shlwapi", "winmm", "gdi32", "Imm32", "Psapi", "dwmapi",
"pthread", "libpng", "jpeg", "zlib", "tinygettext", "discord-rpc",
}

Expand Down
29 changes: 28 additions & 1 deletion Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ CGameSA::CGameSA()
error += ": ";
error += e.what();

MessageBoxUTF8(nullptr, error.c_str(), _("Error"), MB_ICONERROR | MB_OK);
MessageBoxUTF8(nullptr, error, _("Error"), MB_ICONERROR | MB_OK);
ExitProcess(EXIT_FAILURE);
}
catch (const std::exception& e)
Expand Down Expand Up @@ -1102,6 +1102,33 @@ bool CGameSA::SetBuildingPoolSize(size_t size)
return status;
}

void CGameSA::UnloadUnusedModels()
{
// Unload DFF's
// CJ should not be unloaded
const std::size_t baseIdForTxd = GetBaseIDforTXD();
for (std::size_t id = 1; id < baseIdForTxd; id++)
{
CStreamingInfo* streamingInfo = m_pStreaming->GetStreamingInfo(id);
if (streamingInfo->loadState != eModelLoadState::LOADSTATE_NOT_LOADED && streamingInfo->sizeInBlocks > 0)
{
CModelInfoSA& model = ModelInfo[id];
if (model.GetRefCount() == 0)
model.UnloadUnused();
};
}
// Unload TXD
for (std::size_t id = baseIdForTxd; id < GetBaseIDforCOL(); id++)
{
CStreamingInfo* streamingInfo = m_pStreaming->GetStreamingInfo(id);
std::size_t refsCount = GetPools()->GetTxdPool().GetRefsCount(id - baseIdForTxd);
if (streamingInfo->loadState != eModelLoadState::LOADSTATE_NOT_LOADED && streamingInfo->sizeInBlocks > 0 && refsCount == 0)
{
GetStreaming()->RemoveModel(id);
}
}
}

// Ensure models have the default lod distances
void CGameSA::ResetModelLodDistances()
{
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CGameSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ class CGameSA : public CGame

bool SetBuildingPoolSize(size_t size);

void UnloadUnusedModels();

private:
std::unique_ptr<CPools> m_Pools;
CPlayerInfo* m_pPlayerInfo;
Expand Down
7 changes: 2 additions & 5 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ void CModelInfoSA::Remove()

bool CModelInfoSA::UnloadUnused()
{
m_pInterface = ppModelInfo[m_dwModelID];

if (m_pInterface->usNumberOfRefs == 0 && !m_pCustomClump && !m_pCustomColModel)
{
pGame->GetStreaming()->RemoveModel(m_dwModelID);
Expand Down Expand Up @@ -1094,11 +1096,6 @@ void CModelInfoSA::ModelAddRef(EModelRequestType requestType, const char* szTag)
m_dwReferences++;
}

int CModelInfoSA::GetRefCount()
{
return static_cast<int>(m_dwReferences);
}

void CModelInfoSA::RemoveRef(bool bRemoveExtraGTARef)
{
// Decrement the references
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class CModelInfoSA : public CModelInfo
static void StaticResetAlphaTransparencies();

void ModelAddRef(EModelRequestType requestType, const char* szTag);
int GetRefCount();
int GetRefCount() const override { return static_cast<int>(m_dwReferences); };
void RemoveRef(bool bRemoveExtraGTARef = false);
bool ForceUnload();

Expand Down
4 changes: 2 additions & 2 deletions Client/game_sa/CPhysicalSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class CPhysicalSAInterface : public CEntitySAInterface
CVector m_vecUnk; // 280
uint32 m_pad4; // 292
CPtrNodeDoubleLink<void>* m_pControlCodeNodeLink; // 296
float m_fLighting; // 300
float m_fLighting2; // 304
float m_fLighting; // 300 surface brightness
float m_fLighting2; // 304 dynamic lighting (unused, always set to 0 in the GTA code)
class CShadowDataSA* m_pShadowData; // 308

CRect* GetBoundRect_(CRect* pRect);
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CPoolSAInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class CPoolSAInterface
return !IsEmpty(index);
}

B* GetObject(std::int32_t objectIndex) { return &m_pObjects[objectIndex]; }
B* GetObject(std::int32_t objectIndex) const { return &m_pObjects[objectIndex]; }

uint GetObjectIndex(B* pObject) { return ((DWORD)pObject - (DWORD)m_pObjects) / sizeof(B); }

Expand Down
13 changes: 11 additions & 2 deletions Client/game_sa/CRendererSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "CMatrix.h"
#include "gamesa_renderware.h"

#define SetLightColoursForPedsCarsAndObjects(fMult) ((RpLight*(__cdecl*)(float))0x735D90)(fMult)
#define SetAmbientColours() ((RpLight*(__cdecl*)())0x735D30)()

CRendererSA::CRendererSA()
{
}
Expand All @@ -23,7 +26,7 @@ CRendererSA::~CRendererSA()
{
}

void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix)
void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting)
{
CBaseModelInfoSAInterface* pModelInfoSAInterface = pModelInfo->GetInterface();
if (!pModelInfoSAInterface)
Expand All @@ -40,7 +43,10 @@ void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix)
rwMatrix.up = (RwV3d&)matrix.vFront;
rwMatrix.at = (RwV3d&)matrix.vUp;
rwMatrix.pos = (RwV3d&)matrix.vPos;
RwFrameTransform(pFrame, &rwMatrix, rwCOMBINEREPLACE);
RwFrameTransform(pFrame, &rwMatrix, rwCOMBINEREPLACE);

// Setup ambient light multiplier
SetLightColoursForPedsCarsAndObjects(lighting);

if (pRwObject->type == RP_TYPE_ATOMIC)
{
Expand All @@ -52,4 +58,7 @@ void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix)
RpClump* pClump = reinterpret_cast<RpClump*>(pRwObject);
RpClumpRender(pClump);
}

// Restore ambient light
SetAmbientColours();
}
2 changes: 1 addition & 1 deletion Client/game_sa/CRendererSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ class CRendererSA : public CRenderer
CRendererSA();
~CRendererSA();

void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix) override;
void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) override;
};
9 changes: 9 additions & 0 deletions Client/game_sa/CTxdPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ std::uint16_t CTxdPoolSA::GetFreeTextureDictonarySlot()
{
return (*m_ppTxdPoolInterface)->GetFreeSlot();
}

std::uint16_t CTxdPoolSA::GetRefsCount(std::uint16_t slot) const
{
CTextureDictonarySAInterface* pTxd = (*m_ppTxdPoolInterface)->GetObject(slot);
if (!pTxd)
return -1;

return pTxd->usUsagesCount;
}
1 change: 1 addition & 0 deletions Client/game_sa/CTxdPoolSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CTxdPoolSA final : public CTxdPool
bool IsFreeTextureDictonarySlot(std::uint32_t uiTxdId);

std::uint16_t GetFreeTextureDictonarySlot();
std::uint16_t GetRefsCount(std::uint16_t slot) const;

private:
CPoolSAInterface<CTextureDictonarySAInterface>** m_ppTxdPoolInterface;
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6764,6 +6764,8 @@ void CClientGame::RestreamWorld()

g_pGame->GetStreaming()->RemoveBigBuildings();
g_pGame->GetStreaming()->ReinitStreaming();

g_pGame->UnloadUnusedModels();
}

void CClientGame::ReinitMarkers()
Expand Down
8 changes: 4 additions & 4 deletions Client/mods/deathmatch/logic/CModelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include "game\CRenderer.h"
#include "game\CVisibilityPlugins.h"

bool CModelRenderer::EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix)
bool CModelRenderer::EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting)
{
if (g_pCore->IsWindowMinimized())
return false;

if (pModelInfo && pModelInfo->IsLoaded())
{
m_Queue.emplace_back(pModelInfo, matrix);
m_Queue.emplace_back(pModelInfo, matrix, lighting);
return true;
}

Expand Down Expand Up @@ -54,7 +54,7 @@ void CModelRenderer::Render()
for (auto& modelDesc : m_Queue)
{
if (modelDesc.pModelInfo->IsLoaded() && !modelDesc.pModelInfo->GetIdeFlag(eModelIdeFlag::DRAW_LAST))
pRenderer->RenderModel(modelDesc.pModelInfo, modelDesc.matrix);
pRenderer->RenderModel(modelDesc.pModelInfo, modelDesc.matrix, modelDesc.lighting);
}

m_Queue.clear();
Expand All @@ -68,5 +68,5 @@ void CModelRenderer::RenderEntity(SModelToRender* modelDesc, float distance)
CRenderer* pRenderer = g_pGame->GetRenderer();
assert(pRenderer);

pRenderer->RenderModel(modelDesc->pModelInfo, modelDesc->matrix);
pRenderer->RenderModel(modelDesc->pModelInfo, modelDesc->matrix, modelDesc->lighting);
}
8 changes: 5 additions & 3 deletions Client/mods/deathmatch/logic/CModelRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ class CModelRenderer final
{
CModelInfo* pModelInfo;
CMatrix matrix;
float lighting;

SModelToRender(CModelInfo* pModelInfo, const CMatrix& matrix) :
SModelToRender(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting = 0.0f) :
pModelInfo(pModelInfo),
matrix(matrix)
matrix(matrix),
lighting(lighting)
{
}
};

bool EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix);
bool EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting);

void Update();

Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2123,7 +2123,7 @@ bool CLuaDrawingDefs::DxDrawWiredSphere(lua_State* const luaVM, const CVector po
return true;
}

bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional<CVector> scale)
bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional<CVector> scale, const std::optional<float> lighting)
{
CModelInfo* pModelInfo = g_pGame->GetModelInfo(modelID);
if (!pModelInfo)
Expand All @@ -2138,5 +2138,5 @@ bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVe
ConvertDegreesToRadians(rotation);

return g_pClientGame->GetModelRenderer()->EnqueueModel(pModelInfo,
CMatrix{position, rotation, scale.value_or(CVector{1.0f, 1.0f, 1.0f})});
CMatrix{position, rotation, scale.value_or(CVector{1.0f, 1.0f, 1.0f})}, lighting.value_or(0.0f));
}
Loading

0 comments on commit 0c9b0cf

Please sign in to comment.