Skip to content

Commit

Permalink
Merge branch 'master' into building/fix_lods_crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Dutchman101 authored Jun 30, 2024
2 parents 356243c + f6f544e commit 8e0b158
Show file tree
Hide file tree
Showing 478 changed files with 5,237 additions and 6,597 deletions.
32 changes: 23 additions & 9 deletions Client/loader/CInstallManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,17 +1269,31 @@ SString CInstallManager::_ProcessAppCompatChecks()
}

// Windows 7: Fix invalid GameUX URL (which causes rundll32.exe to use excessive CPU)
WString strUrlKey = L"SOFTWARE\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\GameUX\\ServiceLocation";
WString strUrlItem = L"Games";
WString strUrlValue = ReadCompatibilityEntries(strUrlItem, strUrlKey, HKEY_CURRENT_USER, 0);
if (!strUrlValue.empty())
{
WriteDebugEvent(SString("GameUX ServiceLocation was '%s'", *ToUTF8(strUrlValue)));
if (strUrlValue.ContainsI(L":"))
WString strUrlKey = L"SOFTWARE\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\GameUX\\ServiceLocation";
WString strUrlItem = L"Games";
WString strUrlValue = ReadCompatibilityEntries(strUrlItem, strUrlKey, HKEY_CURRENT_USER, 0);
if (!strUrlValue.empty())
{
strUrlValue = L"disabled"; // Can be anything not containing `:`
if (!WriteCompatibilityEntries(strUrlItem, strUrlKey, HKEY_CURRENT_USER, 0, strUrlValue))
bTryAdmin = true;
WriteDebugEvent(SString("GameUX ServiceLocation was '%s'", *ToUTF8(strUrlValue)));
if (strUrlValue.ContainsI(L":"))
{
strUrlValue = L"disabled"; // Can be anything not containing `:`
if (!WriteCompatibilityEntries(strUrlItem, strUrlKey, HKEY_CURRENT_USER, 0, strUrlValue))
bTryAdmin = true;
}
}
}

// Windows 10: Disable multi-threaded loading of DLLs.
{
DWORD maxLoaderThreads{};
LPCWSTR imageFileExecutionOptions = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\" GTA_EXE_NAME;
RegQueryInteger(HKEY_LOCAL_MACHINE, imageFileExecutionOptions, L"MaxLoaderThreads", maxLoaderThreads);

if (maxLoaderThreads != 1 && !RegWriteInteger(HKEY_LOCAL_MACHINE, imageFileExecutionOptions, L"MaxLoaderThreads", 1))
{
bTryAdmin = true;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Client/loader/MainFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,9 @@ void CheckDataFiles()
{
const char* expected;
const char* fileName;
} integrityCheckList[] = {{"36CB1B284BC7CBB4F25CD00BBB044550", "bass.dll"}, {"1B909B47946167D153FB94020393E781", "bass_aac.dll"},
} integrityCheckList[] = {{"025B17C1D14BD4CE38F2A181754BD7CD", "bass.dll"}, {"1B909B47946167D153FB94020393E781", "bass_aac.dll"},
{"E7E69A3B369F0ABA1A4A18C831BC4364", "bass_ac3.dll"}, {"E20A57EA7D845FADC9A48A0AA919121A", "bass_fx.dll"},
{"F47DCE69DAFAA06A55A4BC1F07F80C8A", "bassflac.dll"}, {"F246D72BA73E9624FE8BE66E785FB5C5", "bassmidi.dll"},
{"F47DCE69DAFAA06A55A4BC1F07F80C8A", "bassflac.dll"}, {"9A237576912D39FBD57C22C079DB6D38", "bassmidi.dll"},
{"5DEEC10A943E352EF7E0223327E8B48C", "bassmix.dll"}, {"2F87C5E0A1B7B28C8FC0D7E74116DDFC", "bassopus.dll"},
{"0F1B2FC6C0C703A43A24DC05352E7ADA", "basswebm.dll"}, {"893113C6C49DC1E1EF288310E68DB306", "basswma.dll"},
{"C6A44FC3CF2F5801561804272217B14D", "D3DX9_42.dll"}, {"D439E8EDD8C93D7ADE9C04BCFE9197C6", "sa.dat"},
Expand Down
26 changes: 26 additions & 0 deletions Client/loader/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,32 @@ bool IsNativeArm64Host()
return isArm64;
}

bool RegQueryInteger(HKEY rootKey, LPCWSTR keyName, LPCWSTR valueName, DWORD& value)
{
value = {};

HKEY key{};
if (RegOpenKeyExW(rootKey, keyName, 0, KEY_READ, &key) != ERROR_SUCCESS)
return false;

DWORD valueType = REG_DWORD;
DWORD valueSize = sizeof(value);
LSTATUS status = RegQueryValueExW(key, valueName, nullptr, &valueType, reinterpret_cast<LPBYTE>(&value), &valueSize);
RegCloseKey(key);
return status == ERROR_SUCCESS;
}

bool RegWriteInteger(HKEY rootKey, LPCWSTR keyName, LPCWSTR valueName, DWORD value)
{
HKEY key{};
if (RegCreateKeyExW(rootKey, keyName, 0, 0, REG_OPTION_NON_VOLATILE, KEY_WRITE, nullptr, &key, nullptr) != ERROR_SUCCESS)
return false;

LSTATUS status = RegSetValueExW(key, valueName, 0, REG_DWORD, reinterpret_cast<LPBYTE>(&value), sizeof(value));
RegCloseKey(key);
return status == ERROR_SUCCESS;
}

//////////////////////////////////////////////////////////
//
// ReadCompatibilityEntries
Expand Down
10 changes: 10 additions & 0 deletions Client/loader/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ bool IsErrorCodeLoggable(const std::error_code& ec);
*/
bool IsNativeArm64Host();

/**
* @brief Queries the integer value of a specific value item from the registry.
*/
bool RegQueryInteger(HKEY rootKey, LPCWSTR keyName, LPCWSTR valueName, DWORD& value);

/**
* @brief Writes an integer value to a specific value item in the registry.
*/
bool RegWriteInteger(HKEY rootKey, LPCWSTR keyName, LPCWSTR valueName, DWORD value);

// Return false on read failure
template <class T>
bool ReadFileValue(const SString& strFilename, T& value, uint uiOffset)
Expand Down
8 changes: 8 additions & 0 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,11 @@ void CClientPed::InternalSetHealth(float fHealth)
}
else
{
// Ped is alive again (Fix #414)
UnlockHealth();
UnlockArmor();
SetIsDead(false);

// Recreate the player
ReCreateModel();
}
Expand Down Expand Up @@ -5215,6 +5220,9 @@ void CClientPed::Respawn(CVector* pvecPosition, bool bRestoreState, bool bCamera

m_pPlayerPed->SetLanding(false);

// Set it to 0 (Fix #501)
SetCurrentWeaponSlot(eWeaponSlot::WEAPONSLOT_TYPE_UNARMED);

if (bRestoreState)
{
// Jax: restore all the things we saved
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void CResourceManager::StopAll()
}

// pResource may be changed on return, and it could be NULL if the function returns false.
bool CResourceManager::ParseResourcePathInput(std::string strInput, CResource*& pResource, std::string* pStrPath, std::string* pStrMetaPath)
bool CResourceManager::ParseResourcePathInput(std::string strInput, CResource*& pResource, std::string* pStrPath, std::string* pStrMetaPath, bool bPassSize)
{
ReplaceOccurrencesInString(strInput, "\\", "/");

Expand Down Expand Up @@ -190,7 +190,7 @@ bool CResourceManager::ParseResourcePathInput(std::string strInput, CResource*&
}
}
}
else if (pResource && IsValidFilePath(strInput.c_str()))
else if (pResource && (bPassSize ? IsValidFilePath(strInput.c_str(), strInput.size()) : IsValidFilePath(strInput.c_str())))
{
if (pStrPath)
*pStrPath = pResource->GetResourceDirectoryPath(accessType, strInput);
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CResourceManager
void ValidateResourceFile(const SString& strFilename, const char* buffer, size_t bufferSize);
CDownloadableResource* GetDownloadableResourceFile(const SString& strFilename) { return MapFindRef(m_ResourceFileMap, strFilename); }

static bool ParseResourcePathInput(std::string strInput, CResource*& pResource, std::string* pStrPath, std::string* pStrMetaPath = nullptr);
static bool ParseResourcePathInput(std::string strInput, CResource*& pResource, std::string* pStrPath, std::string* pStrMetaPath = nullptr, bool bPassSize = false);

private:
CMappedList<CResource*> m_resources;
Expand Down
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ int CLuaAudioDefs::PlaySound(lua_State* luaVM)
SString strFilename;
bool bIsURL = false;
bool bIsRawData = false;
if (CResourceManager::ParseResourcePathInput(strSound, pResource, &strFilename))

if (CResourceManager::ParseResourcePathInput(strSound, pResource, &strFilename, nullptr, true))
strSound = strFilename;
else
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ Execute `win-create-projects.bat`

Unless otherwise specified, all source code hosted on this repository is licensed under the GPLv3 license. See the [LICENSE](./LICENSE) file for more details.

Grand Theft Auto and all related trademarks are © Rockstar North 1997–2023.
Grand Theft Auto and all related trademarks are © Rockstar North 1997–2024.
49 changes: 44 additions & 5 deletions Server/mods/deathmatch/logic/CScriptDebugging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@

extern CGame* g_pGame;

enum DebugScriptLevels : std::uint8_t
{
NONE,
ERRORS_ONLY,
ERRORS_AND_WARNINGS,
ALL,
};

enum DebugMessageLevels : std::uint8_t
{
MESSAGE_TYPE_DEBUG,
MESSAGE_TYPE_ERROR,
MESSAGE_TYPE_WARNING,
MESSAGE_TYPE_INFO,
MESSAGE_TYPE_CUSTOM,
};

CScriptDebugging::CScriptDebugging()
{
m_uiLogFileLevel = 0;
Expand Down Expand Up @@ -143,16 +160,38 @@ void CScriptDebugging::PrintLog(const char* szText)
}
}

bool CScriptDebugging::CheckForSufficientDebugLevel(std::uint8_t playerDebugLevel, std::uint8_t messageDebugLevel) const noexcept
{
bool sufficientDebugLevel = false;

switch (messageDebugLevel)
{
case MESSAGE_TYPE_ERROR:
sufficientDebugLevel = (playerDebugLevel >= ERRORS_ONLY);
break;
case MESSAGE_TYPE_WARNING:
sufficientDebugLevel = (playerDebugLevel >= ERRORS_AND_WARNINGS);
break;
case MESSAGE_TYPE_INFO:
case MESSAGE_TYPE_CUSTOM:
case MESSAGE_TYPE_DEBUG:
sufficientDebugLevel = (playerDebugLevel == ALL);
break;
}

return sufficientDebugLevel;
}

void CScriptDebugging::Broadcast(const CPacket& Packet, unsigned int uiMinimumDebugLevel)
{
// Tell everyone we log to about it
list<CPlayer*>::const_iterator iter = m_Players.begin();
auto uiRequiredDebugLevel = std::min(uiMinimumDebugLevel, 3u); // Make sure it doesn't skip outputDebugString with level 4
for (; iter != m_Players.end(); iter++)
for (const auto& pPlayer : m_Players)
{
if ((*iter)->m_uiScriptDebugLevel >= uiRequiredDebugLevel)
bool sufficientDebugLevel = CheckForSufficientDebugLevel(pPlayer->m_uiScriptDebugLevel, uiMinimumDebugLevel);

if (sufficientDebugLevel)
{
(*iter)->Send(Packet);
pPlayer->Send(Packet);
}
}
}
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CScriptDebugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class CScriptDebugging
unsigned char ucGreen = 255, unsigned char ucBlue = 255);

void PrintLog(const char* szText);
bool CheckForSufficientDebugLevel(std::uint8_t playerDebugLevel, std::uint8_t messageDebugLevel) const noexcept;
void Broadcast(const CPacket& Packet, unsigned int uiMinimumDebugLevel);

unsigned int m_uiLogFileLevel;
Expand Down
3 changes: 3 additions & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,9 @@ bool CStaticFunctionDefinitions::SetElementHealth(CElement* pElement, float fHea
unsigned char ucHealth = static_cast<unsigned char>(fHealth * 1.25f);
fHealth = static_cast<float>(ucHealth) / 1.25f;
pPed->SetHealth(fHealth);

if (pPed->IsDead() && fHealth > 0.0f)
pPed->SetIsDead(false);
}
else
return false;
Expand Down
68 changes: 23 additions & 45 deletions Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "CLuaPedDefs.h"
#include "CStaticFunctionDefinitions.h"
#include "CScriptArgReader.h"
#include "lua/CLuaFunctionParser.h"

void CLuaPedDefs::LoadFunctions()
{
Expand Down Expand Up @@ -64,7 +65,7 @@ void CLuaPedDefs::LoadFunctions()
{"warpPedIntoVehicle", WarpPedIntoVehicle},
{"removePedFromVehicle", RemovePedFromVehicle},
{"setPedDoingGangDriveby", SetPedDoingGangDriveby},
{"setPedAnimation", SetPedAnimation},
{"setPedAnimation", ArgumentParserWarn<false, SetPedAnimation>},
{"setPedAnimationProgress", SetPedAnimationProgress},
{"setPedAnimationSpeed", SetPedAnimationSpeed},
{"setPedOnFire", SetPedOnFire},
Expand Down Expand Up @@ -404,56 +405,33 @@ int CLuaPedDefs::IsPedFrozen(lua_State* luaVM)
return 1;
}

int CLuaPedDefs::SetPedAnimation(lua_State* luaVM)
bool CLuaPedDefs::SetPedAnimation(CElement* pPed, std::optional<std::variant<std::string, std::monostate, bool>> blockName,
std::optional<std::variant<std::string, std::monostate, bool>> animName, std::optional<int> time, std::optional<bool> loop,
std::optional<bool> updatePosition, std::optional<bool> interruptable, std::optional<bool> freezeLastFrame,
std::optional<int> blendTime, std::optional<bool> restoreTask)
{
// bool setPedAnimation ( ped thePed [, string block=nil, string anim=nil, int time=-1, int blend=250, bool loop=true, bool updatePosition=true, bool
// interruptable=true, bool freezeLastFrame = true] )
CElement* pPed;
SString strBlockName, strAnimName;
int iTime;
int iBlend = 250;
bool bLoop, bUpdatePosition, bInterruptable, bFreezeLastFrame;
bool bDummy;
bool bTaskToBeRestoredOnAnimEnd;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pPed);
if (argStream.NextIsBool())
argStream.ReadBool(bDummy); // Wiki used setPedAnimation(source,false) as an example
else if (argStream.NextIsNil())
argStream.m_iIndex++; // Wiki docs said blockName could be nil
else
argStream.ReadString(strBlockName, "");
argStream.ReadString(strAnimName, "");
if (argStream.NextCouldBeNumber()) // Freeroam skips the time arg sometimes
argStream.ReadNumber(iTime, -1);
else
iTime = -1;
argStream.ReadBool(bLoop, true);
argStream.ReadBool(bUpdatePosition, true);
argStream.ReadBool(bInterruptable, true);
argStream.ReadBool(bFreezeLastFrame, true);
argStream.ReadNumber(iBlend, 250);
argStream.ReadBool(bTaskToBeRestoredOnAnimEnd, false);
std::string animBlockName;
std::string animationName;

if (!argStream.HasErrors())
if (blockName.has_value())
{
const char *szBlock, *szAnim;
szBlock = strBlockName.empty() ? NULL : strBlockName.c_str();
szAnim = strAnimName.empty() ? NULL : strAnimName.c_str();
if (std::holds_alternative<std::string>(blockName.value()))
animBlockName = std::get<std::string>(blockName.value());
else if (std::holds_alternative<bool>(blockName.value()))
if (std::get<bool>(blockName.value()))
throw LuaFunctionError("Anim block name cannot be true. Possible values: nil, false, string.");
}

if (CStaticFunctionDefinitions::SetPedAnimation(pPed, szBlock, szAnim, iTime, iBlend, bLoop, bUpdatePosition, bInterruptable, bFreezeLastFrame,
bTaskToBeRestoredOnAnimEnd))
{
lua_pushboolean(luaVM, true);
return 1;
}
if (animName.has_value())
{
if (std::holds_alternative<std::string>(animName.value()))
animationName = std::get<std::string>(animName.value());
else if (std::holds_alternative<bool>(animName.value()))
if (std::get<bool>(animName.value()))
throw LuaFunctionError("Animation name cannot be true. Possible values: nil, false, string.");
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
return CStaticFunctionDefinitions::SetPedAnimation(pPed, animBlockName, animationName, time.value_or(-1), blendTime.value_or(250), loop.value_or(true), updatePosition.value_or(true), interruptable.value_or(true), freezeLastFrame.value_or(true), restoreTask.value_or(false));
}

int CLuaPedDefs::SetPedAnimationProgress(lua_State* luaVM)
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CLuaPedDefs : public CLuaDefs
LUA_DECLARE_OOP(WarpPedIntoVehicle);
LUA_DECLARE(RemovePedFromVehicle);
LUA_DECLARE(SetPedDoingGangDriveby);
LUA_DECLARE(SetPedAnimation);
static bool SetPedAnimation(CElement* pPed, std::optional<std::variant<std::string, std::monostate, bool>> blockName, std::optional<std::variant<std::string, std::monostate, bool>> animName, std::optional<int> time, std::optional<bool> loop, std::optional<bool> updatePosition, std::optional<bool> interruptable, std::optional<bool> freezeLastFrame, std::optional<int> blendTime, std::optional<bool> restoreTask);
LUA_DECLARE(SetPedAnimationProgress);
LUA_DECLARE(SetPedAnimationSpeed);
LUA_DECLARE(SetPedWeaponSlot);
Expand Down
Binary file modified Shared/data/MTA San Andreas/MTA/bass.dll
Binary file not shown.
Binary file modified Shared/data/MTA San Andreas/MTA/bassmidi.dll
Binary file not shown.
Loading

0 comments on commit 8e0b158

Please sign in to comment.