Skip to content

Commit 0c9b0cf

Browse files
authored
Merge branch 'master' into bugfix/heli_rotor_speed
2 parents 182816a + 808ddf0 commit 0c9b0cf

38 files changed

+442
-220
lines changed

Client/core/CScreenShot.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ static bool ms_bIsSaving = false;
3535
static uint ms_uiWidth = 0;
3636
static uint ms_uiHeight = 0;
3737

38+
// whether we want to actually save photo in documents folder
39+
static bool savePhotoInDocuments = false;
40+
3841
void CScreenShot::InitiateScreenShot(bool bIsCameraShot)
3942
{
4043
if (ms_bScreenShot || ms_bIsSaving || IsRateLimited(bIsCameraShot))
@@ -48,8 +51,11 @@ void CScreenShot::InitiateScreenShot(bool bIsCameraShot)
4851

4952
if (bIsCameraShot)
5053
{
51-
// Set the screenshot path to camera gallery path
52-
ms_strScreenDirectoryPath = PathJoin(GetSystemPersonalPath(), "GTA San Andreas User Files", "Gallery");
54+
if (savePhotoInDocuments)
55+
{
56+
// Set the screenshot path to camera gallery path
57+
ms_strScreenDirectoryPath = PathJoin(GetSystemPersonalPath(), "GTA San Andreas User Files", "Gallery");
58+
}
5359
}
5460
else
5561
{
@@ -82,6 +88,13 @@ void CScreenShot::CheckForScreenShot(bool bBeforeGUI)
8288
// Update last time of taken screenshot of given type
8389
ms_lLastSaveTime[ms_bIsCameraShot] = GetTickCount64_();
8490

91+
if (ms_bIsCameraShot && !savePhotoInDocuments)
92+
{
93+
ClearBuffer();
94+
ms_bScreenShot = false;
95+
return;
96+
}
97+
8598
ms_strScreenShotPath = GetScreenshotPath();
8699
ms_uiWidth = CDirect3DData::GetSingleton().GetViewportWidth();
87100
ms_uiHeight = CDirect3DData::GetSingleton().GetViewportHeight();
@@ -205,3 +218,8 @@ void CScreenShot::ClearBuffer()
205218
{
206219
ms_ScreenShotBuffer.Clear();
207220
}
221+
222+
void CScreenShot::SetPhotoSavingInsideDocuments(bool savePhoto) noexcept
223+
{
224+
savePhotoInDocuments = savePhoto;
225+
}

Client/core/CScreenShot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class CScreenShot
1919
public:
2020
static void InitiateScreenShot(bool bIsCameraShot);
2121
static void CheckForScreenShot(bool bBeforeGUI);
22+
static void SetPhotoSavingInsideDocuments(bool bSavePhoto) noexcept;
2223

2324
protected:
2425
static void StartSaveThread();

Client/core/CSettings.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,12 @@ void CSettings::CreateGUI()
12011201
m_pCachePathValue->AutoSize();
12021202
vecTemp.fY += fLineHeight;
12031203

1204+
// Enable camera photos getting saved to documents folder
1205+
m_pPhotoSavingCheckbox = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabAdvanced, _("Save photos taken by camera weapon to GTA San Andreas User Files folder"), true));
1206+
m_pPhotoSavingCheckbox->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY));
1207+
m_pPhotoSavingCheckbox->AutoSize(NULL, 20.0f);
1208+
vecTemp.fY += fLineHeight;
1209+
12041210
// Auto updater section label
12051211
m_pAdvancedUpdaterLabel = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabAdvanced, _("Auto updater")));
12061212
m_pAdvancedUpdaterLabel->SetPosition(CVector2D(vecTemp.fX - 10.0f, vecTemp.fY));
@@ -3218,6 +3224,10 @@ void CSettings::LoadData()
32183224
iVar = GetApplicationSettingInt("Win8MouseFix");
32193225
m_pWin8MouseCheckBox->SetSelected(iVar != 0);
32203226

3227+
// Save camera photos inside user documents folder
3228+
CVARS_GET("photosaving", bVar);
3229+
m_pPhotoSavingCheckbox->SetSelected(bVar);
3230+
32213231
// Update build type
32223232
CVARS_GET("update_build_type", iVar);
32233233
if (iVar == 0 || iVar == 1)
@@ -3609,6 +3619,11 @@ void CSettings::SaveData()
36093619
// Windows 8 mouse fix
36103620
SetApplicationSettingInt("Win8MouseFix", m_pWin8MouseCheckBox->GetSelected());
36113621

3622+
// Save photos in documents folder
3623+
bool photoSaving = m_pPhotoSavingCheckbox->GetSelected();
3624+
CVARS_SET("photosaving", photoSaving);
3625+
CScreenShot::SetPhotoSavingInsideDocuments(photoSaving);
3626+
36123627
// Debug setting
36133628
if (CGUIListItem* pSelected = m_pDebugSettingCombo->GetSelectedItem())
36143629
{

Client/core/CSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ class CSettings
215215
CGUILabel* m_pWin8Label;
216216
CGUICheckBox* m_pWin8ColorCheckBox;
217217
CGUICheckBox* m_pWin8MouseCheckBox;
218+
CGUICheckBox* m_pPhotoSavingCheckbox;
218219
CGUILabel* m_pUpdateBuildTypeLabel;
219220
CGUIComboBox* m_pUpdateBuildTypeCombo;
220221
CGUILabel* m_pUpdateAutoInstallLabel;

Client/core/DXHook/CProxyDirect3D9.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
*****************************************************************************/
1111

1212
#include "StdInc.h"
13+
#include <dwmapi.h>
14+
#include <resource.h>
15+
16+
extern HINSTANCE g_hModule;
17+
1318
HRESULT HandleCreateDeviceResult(HRESULT hResult, IDirect3D9* pDirect3D, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags,
1419
D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface);
1520
std::vector<IDirect3D9*> ms_CreatedDirect3D9List;
@@ -166,6 +171,27 @@ HRESULT CProxyDirect3D9::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND
166171
SetWindowTextW(hFocusWindow, MbUTF8ToUTF16("MTA: San Andreas").c_str());
167172
#endif
168173

174+
// Set dark titlebar if needed
175+
BOOL darkTitleBar = GetSystemRegistryValue((uint)HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme") == "\x0";
176+
DwmSetWindowAttribute(hFocusWindow, DWMWA_USE_IMMERSIVE_DARK_MODE, &darkTitleBar, sizeof(darkTitleBar));
177+
178+
// Update icon
179+
if (HICON icon = LoadIcon(g_hModule, MAKEINTRESOURCE(IDI_ICON1)))
180+
{
181+
const auto paramIcon = reinterpret_cast<LPARAM>(icon);
182+
for (const WPARAM size : {ICON_SMALL, ICON_BIG})
183+
{
184+
SendMessage(hFocusWindow, WM_SETICON, size, paramIcon);
185+
}
186+
187+
// Clean
188+
DestroyIcon(icon);
189+
}
190+
191+
// Redraw, we avoid possible problems with the fact that it won't replace the icon somewhere
192+
InvalidateRect(hFocusWindow, nullptr, TRUE);
193+
UpdateWindow(hFocusWindow);
194+
169195
// Detect if second call to CreateDevice
170196
if (CreateDeviceSecondCallCheck(hResult, m_pDevice, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface))
171197
{

Client/core/premake5.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ project "Client Core"
4646

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

Client/game_sa/CGameSA.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ CGameSA::CGameSA()
253253
error += ": ";
254254
error += e.what();
255255

256-
MessageBoxUTF8(nullptr, error.c_str(), _("Error"), MB_ICONERROR | MB_OK);
256+
MessageBoxUTF8(nullptr, error, _("Error"), MB_ICONERROR | MB_OK);
257257
ExitProcess(EXIT_FAILURE);
258258
}
259259
catch (const std::exception& e)
@@ -1102,6 +1102,33 @@ bool CGameSA::SetBuildingPoolSize(size_t size)
11021102
return status;
11031103
}
11041104

1105+
void CGameSA::UnloadUnusedModels()
1106+
{
1107+
// Unload DFF's
1108+
// CJ should not be unloaded
1109+
const std::size_t baseIdForTxd = GetBaseIDforTXD();
1110+
for (std::size_t id = 1; id < baseIdForTxd; id++)
1111+
{
1112+
CStreamingInfo* streamingInfo = m_pStreaming->GetStreamingInfo(id);
1113+
if (streamingInfo->loadState != eModelLoadState::LOADSTATE_NOT_LOADED && streamingInfo->sizeInBlocks > 0)
1114+
{
1115+
CModelInfoSA& model = ModelInfo[id];
1116+
if (model.GetRefCount() == 0)
1117+
model.UnloadUnused();
1118+
};
1119+
}
1120+
// Unload TXD
1121+
for (std::size_t id = baseIdForTxd; id < GetBaseIDforCOL(); id++)
1122+
{
1123+
CStreamingInfo* streamingInfo = m_pStreaming->GetStreamingInfo(id);
1124+
std::size_t refsCount = GetPools()->GetTxdPool().GetRefsCount(id - baseIdForTxd);
1125+
if (streamingInfo->loadState != eModelLoadState::LOADSTATE_NOT_LOADED && streamingInfo->sizeInBlocks > 0 && refsCount == 0)
1126+
{
1127+
GetStreaming()->RemoveModel(id);
1128+
}
1129+
}
1130+
}
1131+
11051132
// Ensure models have the default lod distances
11061133
void CGameSA::ResetModelLodDistances()
11071134
{

Client/game_sa/CGameSA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ class CGameSA : public CGame
312312

313313
bool SetBuildingPoolSize(size_t size);
314314

315+
void UnloadUnusedModels();
316+
315317
private:
316318
std::unique_ptr<CPools> m_Pools;
317319
CPlayerInfo* m_pPlayerInfo;

Client/game_sa/CModelInfoSA.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ void CModelInfoSA::Remove()
452452

453453
bool CModelInfoSA::UnloadUnused()
454454
{
455+
m_pInterface = ppModelInfo[m_dwModelID];
456+
455457
if (m_pInterface->usNumberOfRefs == 0 && !m_pCustomClump && !m_pCustomColModel)
456458
{
457459
pGame->GetStreaming()->RemoveModel(m_dwModelID);
@@ -1094,11 +1096,6 @@ void CModelInfoSA::ModelAddRef(EModelRequestType requestType, const char* szTag)
10941096
m_dwReferences++;
10951097
}
10961098

1097-
int CModelInfoSA::GetRefCount()
1098-
{
1099-
return static_cast<int>(m_dwReferences);
1100-
}
1101-
11021099
void CModelInfoSA::RemoveRef(bool bRemoveExtraGTARef)
11031100
{
11041101
// Decrement the references

Client/game_sa/CModelInfoSA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ class CModelInfoSA : public CModelInfo
397397
static void StaticResetAlphaTransparencies();
398398

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

0 commit comments

Comments
 (0)