Skip to content

Commit 071ad8b

Browse files
committed
Merge remote-tracking branch 'origin/master' into xml-memleak
2 parents 2b13b09 + cf3608d commit 071ad8b

27 files changed

+3520
-1981
lines changed

Client/core/CVersionUpdater.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,6 +3190,7 @@ int CVersionUpdater::DoSendDownloadRequestToNextServer()
31903190
strQueryURL = strQueryURL.Replace("_USAGE_", strConnectUsage);
31913191
strQueryURL = strQueryURL.Replace("_SCUT_", strSoundCut);
31923192
strQueryURL = strQueryURL.Replace("_OPTIMUS_", strOptimusInfo);
3193+
strQueryURL = strQueryURL.Replace("_GTAMD5_", GetApplicationSetting("gta-exe-md5"));
31933194

31943195
// See if this download qualifies for using a resumable file
31953196
if (!m_JobInfo.strFilename.empty() && strQueryURL.EndsWith(m_JobInfo.strFilename))

Client/core/Graphics/CGraphics.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,7 @@ void CGraphics::OnDeviceCreate(IDirect3DDevice9* pDevice)
15171517
m_pMaterialLine3DBatcherPreGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
15181518
m_pMaterialLine3DBatcherPostGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
15191519
m_pPrimitiveBatcher->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
1520+
m_pPrimitiveMaterialBatcher->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
15201521
m_pPrimitive3DBatcherPreGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
15211522
m_pPrimitive3DBatcherPostGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
15221523
m_pMaterialPrimitive3DBatcherPreGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());

Client/game_sa/CModelInfoSA.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ void CModelInfoSA::SetVehicleDummyPosition(eVehicleDummies eDummy, const CVector
10251025
pVehicleModel->pVisualInfo->vecDummies[eDummy] = vecPosition;
10261026
}
10271027

1028-
void CModelInfoSA::ResetVehicleDummies()
1028+
void CModelInfoSA::ResetVehicleDummies(bool bRemoveFromDummiesMap)
10291029
{
10301030
if (!IsVehicle())
10311031
return;
@@ -1040,9 +1040,11 @@ void CModelInfoSA::ResetVehicleDummies()
10401040
if (pVehicleModel->pVisualInfo != nullptr)
10411041
pVehicleModel->pVisualInfo->vecDummies[dummy.first] = dummy.second;
10421042
}
1043-
ms_ModelDefaultDummiesPosition.erase(m_dwModelID);
10441043
// Decrement reference counter, since we reverted all position changes, the model can be safely unloaded
10451044
pVehicleModel->usNumberOfRefs--;
1045+
1046+
if (bRemoveFromDummiesMap)
1047+
ms_ModelDefaultDummiesPosition.erase(m_dwModelID);
10461048
}
10471049

10481050
void CModelInfoSA::ResetAllVehicleDummies()
@@ -1051,7 +1053,7 @@ void CModelInfoSA::ResetAllVehicleDummies()
10511053
for (auto& info : ms_ModelDefaultDummiesPosition) {
10521054
CModelInfo* modelInfo = game->GetModelInfo(info.first);
10531055
if (modelInfo)
1054-
modelInfo->ResetVehicleDummies();
1056+
modelInfo->ResetVehicleDummies(false);
10551057
}
10561058

10571059
ms_ModelDefaultDummiesPosition.clear();

Client/game_sa/CModelInfoSA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class CModelInfoSA : public CModelInfo
345345
void SetVehicleExhaustFumesPosition(const CVector& vecPosition) override;
346346
CVector GetVehicleDummyPosition(eVehicleDummies eDummy) override;
347347
void SetVehicleDummyPosition(eVehicleDummies eDummy, const CVector& vecPosition) override;
348-
void ResetVehicleDummies();
348+
void ResetVehicleDummies(bool bRemoveFromDummiesMap);
349349
static void ResetAllVehicleDummies();
350350

351351
// ONLY use for peds

Client/game_sa/premake5.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ project "Game SA"
44
targetname "game_sa"
55
targetdir(buildpath("mta"))
66

7-
cppdialect "C++14" -- HACK(Jusonex): Temp fix for ebp not being set in naked functions
7+
-- HACK(Jusonex): Temp fix for ebp not being set in naked functions
8+
-- More information on this in multiplayer_sa's premake5.lua
9+
cppdialect "C++14"
810

911
pchheader "StdInc.h"
1012
pchsource "StdInc.cpp"

Client/loader/CFileGenerator.cpp

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
#include "StdInc.h"
1212
#include "../../vendor/unrar/dll.hpp"
1313

14-
CFileGenerator::CFileGenerator(const SString& strTarget, const SString& strTargetMd5, const std::vector<CFileGenerator::SResetItem>& targetResetList,
14+
CFileGenerator::CFileGenerator(const SString& strTarget, const SString& strRequiredTargetMd5, const std::vector<CFileGenerator::SResetItem>& targetResetList,
1515
const SString& strPatchBase, const SString& strPatchDiff)
16-
: m_strTarget(strTarget), m_strTargetMd5(strTargetMd5), m_targetResetList(targetResetList), m_strPatchBase(strPatchBase), m_strPatchDiff(strPatchDiff)
16+
: m_strTarget(strTarget),
17+
m_strRequiredTargetMd5(strRequiredTargetMd5),
18+
m_targetResetList(targetResetList),
19+
m_strPatchBase(strPatchBase),
20+
m_strPatchDiff(strPatchDiff)
1721
{
1822
}
1923

@@ -33,7 +37,7 @@ CFileGenerator::EResult CFileGenerator::CheckTarget(const SString& strTarget)
3337
// Load into a buffer
3438
CBuffer buffer;
3539
if (!buffer.LoadFromFile(strTarget))
36-
return EResult::TargetLoadError;
40+
return RecordError(EResult::TargetLoadError, strTarget);
3741

3842
// List of pokes to restore
3943
CBufferWriteStream stream(buffer);
@@ -47,16 +51,26 @@ CFileGenerator::EResult CFileGenerator::CheckTarget(const SString& strTarget)
4751
}
4852
}
4953

50-
if (GenerateHashHexString(EHashFunctionType::MD5, buffer.GetData(), buffer.GetSize()) != m_strTargetMd5)
51-
return EResult::TargetHashIncorrect;
54+
m_strCurrentTargetMd5 = GenerateHashHexString(EHashFunctionType::MD5, buffer.GetData(), buffer.GetSize());
55+
if (m_strCurrentTargetMd5 != m_strRequiredTargetMd5)
56+
return RecordError(EResult::TargetHashIncorrect, strTarget);
5257
return EResult::Success;
5358
}
5459

60+
//////////////////////////////////////////////////////////
61+
// Return actual MD5 of target file
62+
//////////////////////////////////////////////////////////
63+
SString CFileGenerator::GetCurrentTargetMd5()
64+
{
65+
return m_strCurrentTargetMd5;
66+
}
67+
5568
//////////////////////////////////////////////////////////
5669
// Generate target file
5770
//////////////////////////////////////////////////////////
5871
CFileGenerator::EResult CFileGenerator::GenerateFile()
5972
{
73+
ClearErrorRecords();
6074
// Base + Diff => rar archive containing new target file
6175
SString strTmpArchive = m_strPatchDiff + ".tmp";
6276
EResult result = ApplyPatchFile(m_strPatchBase, m_strPatchDiff, strTmpArchive);
@@ -79,7 +93,7 @@ CFileGenerator::EResult CFileGenerator::GenerateFile()
7993
}
8094
else
8195
{
82-
result = EResult::TargetMoveError;
96+
result = RecordError(EResult::TargetMoveError, strTmpNewTarget, m_strTarget);
8397
}
8498
}
8599
}
@@ -98,8 +112,10 @@ CFileGenerator::EResult CFileGenerator::ApplyPatchFile(const SString& strPatchBa
98112
std::vector<char> diffData;
99113
FileLoad(strPatchBase, baseData);
100114
FileLoad(strPatchDiff, diffData);
101-
if (baseData.empty() || diffData.empty())
102-
return EResult::PatchInputError;
115+
if (baseData.empty())
116+
return RecordError(EResult::PatchInputError, strPatchBase);
117+
if (diffData.empty())
118+
return RecordError(EResult::PatchInputError, strPatchDiff);
103119

104120
// Reuncompression using future delta system
105121
uint uiPos = 0;
@@ -110,7 +126,7 @@ CFileGenerator::EResult CFileGenerator::ApplyPatchFile(const SString& strPatchBa
110126
}
111127

112128
if (!FileSave(strOutputFile, &diffData[0], diffData.size()))
113-
return EResult::PatchOutputError;
129+
return RecordError(EResult::PatchOutputError, strOutputFile);
114130
return EResult::Success;
115131
}
116132

@@ -119,24 +135,60 @@ CFileGenerator::EResult CFileGenerator::ApplyPatchFile(const SString& strPatchBa
119135
//////////////////////////////////////////////////////////
120136
CFileGenerator::EResult CFileGenerator::UnrarFile(const SString& strArchive, const SString& strOutputFile)
121137
{
138+
WString wstrArchive = FromUTF8(strArchive);
139+
WString wstrOutputFile = FromUTF8(strOutputFile);
122140
// Open archive
123-
RAROpenArchiveData archiveData = {};
124-
archiveData.ArcName = (char*)*strArchive;
141+
RAROpenArchiveDataEx archiveData = {};
142+
archiveData.ArcNameW = (wchar_t*)*wstrArchive;
125143
archiveData.OpenMode = RAR_OM_EXTRACT;
126-
HANDLE hArcData = RAROpenArchive(&archiveData);
144+
HANDLE hArcData = RAROpenArchiveEx(&archiveData);
127145
if (!hArcData)
128-
return EResult::ArchiveOpenError;
146+
return RecordError(EResult::ArchiveOpenError, strArchive);
129147

130148
// Extract first file
131149
EResult result = EResult::ArchiveExtractError;
132150
RARHeaderData headerData = {};
133151
if (RARReadHeader(hArcData, &headerData) == 0)
134152
{
135-
if (RARProcessFile(hArcData, RAR_EXTRACT, nullptr, (char*)*strOutputFile) == 0)
153+
if (RARProcessFileW(hArcData, RAR_EXTRACT, nullptr, (wchar_t*)*wstrOutputFile) == 0)
136154
{
137155
result = EResult::Success;
138156
}
139157
}
140158
RARCloseArchive(hArcData);
159+
160+
if (result != EResult::Success)
161+
return RecordError(result, strArchive, strOutputFile);
141162
return result;
142163
}
164+
165+
//////////////////////////////////////////////////////////
166+
// Save error info for later
167+
//////////////////////////////////////////////////////////
168+
CFileGenerator::EResult CFileGenerator::RecordError(CFileGenerator::EResult code, const SString& strContext, const SString& strContext2)
169+
{
170+
m_errorInfoList.push_back({code, strContext, strContext2});
171+
return code;
172+
}
173+
174+
//////////////////////////////////////////////////////////
175+
// Remove all error records
176+
//////////////////////////////////////////////////////////
177+
void CFileGenerator::ClearErrorRecords()
178+
{
179+
m_errorInfoList.clear();
180+
}
181+
182+
//////////////////////////////////////////////////////////
183+
// Return all error records as a string
184+
//////////////////////////////////////////////////////////
185+
SString CFileGenerator::GetErrorRecords()
186+
{
187+
SString strStatus;
188+
for (const auto& item : m_errorInfoList)
189+
{
190+
strStatus += SString("[%d-%s-%s]", item.code, *item.strContext, *item.strContext2);
191+
}
192+
ClearErrorRecords();
193+
return strStatus;
194+
}

Client/loader/CFileGenerator.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,32 @@ class CFileGenerator
3030
std::vector<uchar> data;
3131
};
3232

33-
CFileGenerator(const SString& strTarget, const SString& strTargetMd5, const std::vector<SResetItem>& targetResetList, const SString& strPatchBase,
33+
CFileGenerator(const SString& strTarget, const SString& strRequiredTargetMd5, const std::vector<SResetItem>& targetResetList, const SString& strPatchBase,
3434
const SString& strPatchDiff);
35-
bool IsGenerationRequired();
36-
EResult GenerateFile();
35+
bool IsGenerationRequired();
36+
EResult GenerateFile();
37+
SString GetCurrentTargetMd5();
38+
SString GetErrorRecords();
39+
void ClearErrorRecords();
3740

3841
protected:
39-
EResult CheckTarget(const SString& strTarget);
40-
static EResult ApplyPatchFile(const SString& strPatchBase, const SString& strPatchDiff, const SString& strOutputFile);
41-
static EResult UnrarFile(const SString& strArchive, const SString& strOutputFile);
42+
EResult CheckTarget(const SString& strTarget);
43+
EResult ApplyPatchFile(const SString& strPatchBase, const SString& strPatchDiff, const SString& strOutputFile);
44+
EResult UnrarFile(const SString& strArchive, const SString& strOutputFile);
45+
EResult RecordError(CFileGenerator::EResult code, const SString& strContext = "", const SString& strContext2 = "");
46+
47+
struct SErrorInfo
48+
{
49+
EResult code;
50+
SString strContext;
51+
SString strContext2;
52+
};
4253

4354
SString m_strTarget;
44-
SString m_strTargetMd5;
55+
SString m_strRequiredTargetMd5;
56+
SString m_strCurrentTargetMd5;
4557
std::vector<SResetItem> m_targetResetList;
4658
SString m_strPatchBase;
4759
SString m_strPatchDiff;
60+
std::vector<SErrorInfo> m_errorInfoList;
4861
};

Client/loader/CInstallManager.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,15 +568,19 @@ SString CInstallManager::_ProcessGtaVersionCheck()
568568
CFileGenerator fileGenerator(strGtaExe, strGtaExeMd5, gtaExeResetList, strPatchBase, strPatchDiff);
569569

570570
// Need to fix gta_sa.exe?
571-
if (!fileGenerator.IsGenerationRequired())
571+
bool bGenerationRequired = fileGenerator.IsGenerationRequired();
572+
SetApplicationSetting("gta-exe-md5", fileGenerator.GetCurrentTargetMd5());
573+
if (!bGenerationRequired)
572574
{
575+
AddReportLog(2053, "_ProcessGtaVersionCheck: No action required");
573576
return "ok";
574577
}
575578

576579
// Check required GTA file is correct
577-
if (GenerateHashHexStringFromFile(EHashFunctionType::MD5, strPatchBase) != strPatchBaseMd5)
580+
SString strPatchBaseCurrentMd5 = GenerateHashHexStringFromFile(EHashFunctionType::MD5, strPatchBase);
581+
if (strPatchBaseCurrentMd5 != strPatchBaseMd5)
578582
{
579-
AddReportLog(5053, SString("_ProcessGtaVersionCheck: Incorrect file '%s'", *strPatchBase));
583+
AddReportLog(5053, SString("_ProcessGtaVersionCheck: Incorrect file '%s' %d %s", *strPatchBase, (int)FileSize(strPatchBase), *strPatchBaseCurrentMd5));
580584
SString strMessage(_("MTA:SA cannot continue because the following files are incorrect:"));
581585
strMessage += "\n\n" + strPatchBase;
582586
#ifdef TO_DO
@@ -587,6 +591,9 @@ SString CInstallManager::_ProcessGtaVersionCheck()
587591
#endif
588592
}
589593

594+
// Ensure GTA exe is not running
595+
TerminateGTAIfRunning();
596+
590597
// Backup current gta_sa.exe
591598
SString strGTAExeBak = strGtaExe + ".bak";
592599
if (!FileExists(strGTAExeBak))
@@ -602,13 +609,13 @@ SString CInstallManager::_ProcessGtaVersionCheck()
602609
{
603610
if (!IsUserAdmin())
604611
{
605-
AddReportLog(3052, SString("_ProcessGtaVersionCheck: GenerateFile failed (%d) - trying as admin", result));
612+
AddReportLog(3052, SString("_ProcessGtaVersionCheck: GenerateFile failed (%d) - trying as admin %s", result, *fileGenerator.GetErrorRecords()));
606613
m_strAdminReason = _("Patch GTA");
607614
return "fail";
608615
}
609616
else
610617
{
611-
AddReportLog(5052, SString("_ProcessGtaVersionCheck: GenerateFile failed (%d) to generate '%s'", result, *strGtaExe));
618+
AddReportLog(5052, SString("_ProcessGtaVersionCheck: GenerateFile failed (%d) to generate '%s' %s", result, *strGtaExe, *fileGenerator.GetErrorRecords()));
612619
SString strMessage(_("MTA:SA cannot continue because the following files are incorrect:"));
613620
strMessage += "\n\n" + strGtaExe;
614621
strMessage += "\n\n" + _("Error") + SString(" %d", result);
@@ -621,6 +628,7 @@ SString CInstallManager::_ProcessGtaVersionCheck()
621628
}
622629
}
623630

631+
SetApplicationSetting("gta-exe-md5", fileGenerator.GetCurrentTargetMd5());
624632
AddReportLog(2052, "_ProcessGtaVersionCheck: success");
625633
return "ok";
626634
}

Client/loader/Main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ MTAEXPORT int DoWinMain(HINSTANCE hLauncherInstance, HINSTANCE hPrevInstance, LP
5959
// Other init stuff
6060
ClearPendingBrowseToSolution();
6161

62+
// Find GTA path to use
63+
ValidateGTAPath();
64+
6265
//
6366
// Update
6467
//
@@ -88,9 +91,6 @@ MTAEXPORT int DoWinMain(HINSTANCE hLauncherInstance, HINSTANCE hPrevInstance, LP
8891
// Make sure GTA is not running
8992
HandleIfGTAIsAlreadyRunning();
9093

91-
// Find GTA path to use
92-
ValidateGTAPath();
93-
9494
// Maybe warn user if no anti-virus running
9595
CheckAntiVirusStatus();
9696

Client/loader/MainFunctions.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,7 @@ void ValidateGTAPath()
640640
return ExitProcess(EXIT_ERROR);
641641
}
642642

643-
SString strGTAPath = GetGTAPath();
644-
645-
// We can now set this
646-
SetCurrentDirectory(strGTAPath);
647-
643+
const SString strGTAPath = GetGTAPath();
648644
const SString strMTASAPath = GetMTASAPath();
649645
if (strGTAPath.Contains(";") || strMTASAPath.Contains(";"))
650646
{
@@ -844,13 +840,13 @@ void CheckDataFiles()
844840
{
845841
const char* szMd5;
846842
const char* szFilename;
847-
} integrityCheckList[] = {{"805F59F0B433ECEB7BFBD2522B07E623", "bass.dll"},
848-
{"853933A2518EBF8E966C04C2EAA95391", "bass_aac.dll"},
843+
} integrityCheckList[] = {{"5B94D8E034A90032062ABEE2F6F8C2B9", "bass.dll"},
844+
{"1427B642B1E10B15E84C10FF43B1D8A5", "bass_aac.dll"},
849845
{"BD43C88917D6234FF962B6E88B648B8C", "bass_ac3.dll"},
850-
{"C176D670BF5440A6C704B55A21B01FEF", "bass_fx.dll"},
846+
{"27D2069B89AA55C21DB23C835AA90730", "bass_fx.dll"},
851847
{"FFC2CA817B012FECE4CF62BB85162E68", "bassflac.dll"},
852-
{"5C2A325EC18952945F07C881CB7E44CC", "bassmidi.dll"},
853-
{"6CBD7A375E98420DC8CC2475B62C895B", "bassmix.dll"},
848+
{"AFF8A753E795DF59C9285324124B9132", "bassmidi.dll"},
849+
{"7B00E76ABC6128AE2B29B2B7F77F49FC", "bassmix.dll"},
854850
{"4E35BA785CD3B37A3702E577510F39E3", "bassopus.dll"},
855851
{"0CE7A9F1930591C51B35BF6AA5EC7424", "basswma.dll"},
856852
{"6E2C5DCF4EE973E69ECA39288D20C436", "tags.dll"},

Client/mods/deathmatch/logic/CClientDFF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void CClientDFF::InternalRestoreModel(unsigned short usModel)
263263

264264
// Restore all the models we replaced.
265265
CModelInfo* pModelInfo = g_pGame->GetModelInfo(usModel);
266-
pModelInfo->ResetVehicleDummies();
266+
pModelInfo->ResetVehicleDummies(true);
267267
pModelInfo->RestoreOriginalModel();
268268
pModelInfo->ResetAlphaTransparency();
269269

@@ -369,5 +369,5 @@ bool CClientDFF::ReplaceVehicleModel(RpClump* pClump, ushort usModel, bool bAlph
369369
// Return true if data looks like DFF file contents
370370
bool CClientDFF::IsDFFData(const SString& strData)
371371
{
372-
return strData.length() > 32 && memcmp(strData, "\x10\x00\x00\x00", 4) == 0;
372+
return strData.length() > 32 && (memcmp(strData, "\x10\x00\x00\x00", 4) == 0 || memcmp(strData, "\x2B\x00\x00\x00", 4) == 0);
373373
}

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,12 @@ bool CStaticFunctionDefinitions::GetElementModel(CClientEntity& Entity, unsigned
752752
usModel = pPickup.GetModel();
753753
break;
754754
}
755+
case CCLIENTPROJECTILE:
756+
{
757+
CClientProjectile& pProjectile = static_cast<CClientProjectile&>(Entity);
758+
usModel = pProjectile.GetModel();
759+
break;
760+
}
755761
default:
756762
return false;
757763
}

0 commit comments

Comments
 (0)