From 9b9120c73ec97bf1b2f24703889a62fc19326f1f Mon Sep 17 00:00:00 2001 From: FileEX Date: Tue, 5 Nov 2024 21:45:56 +0100 Subject: [PATCH 1/2] Fix for randomly bright objects after weapon change (#3838) --- .../multiplayer_sa/CMultiplayerSA_Weapons.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Client/multiplayer_sa/CMultiplayerSA_Weapons.cpp b/Client/multiplayer_sa/CMultiplayerSA_Weapons.cpp index ea0f6fab19..d7513941df 100644 --- a/Client/multiplayer_sa/CMultiplayerSA_Weapons.cpp +++ b/Client/multiplayer_sa/CMultiplayerSA_Weapons.cpp @@ -200,6 +200,33 @@ void _declspec(naked) HOOK_Fx_AddBulletImpact() } } +////////////////////////////////////////////////////////////////////////////////////////// +// +// CVisibilityPlugins::RenderWeaponPedsForPC +// +// Fix for the bright objects after weapon change sometimes +// +////////////////////////////////////////////////////////////////////////////////////////// +#define HOOKPOS_CVisibilityPlugins_RenderWeaponPedsForPC 0x733123 +#define HOOKSIZE_CVisibilityPlugins_RenderWeaponPedsForPC 5 +static constexpr DWORD CONTINUE_CVisibilityPlugins_RenderWeaponPedsForPC = 0x733128; +static void _declspec(naked) HOOK_CVisibilityPlugins_RenderWeaponPedsForPC() +{ + _asm + { + mov eax, 5DF4E0h + call eax // call CPed::ResetGunFlashAlpha + + mov eax, 5533B0h + mov ecx, ebx + + push 0 + call eax // call CPed::RemoveLighting + + jmp CONTINUE_CVisibilityPlugins_RenderWeaponPedsForPC + } +} + ////////////////////////////////////////////////////////////////////////////////////////// // // CMultiplayerSA::InitHooks_Weapons @@ -212,4 +239,5 @@ void CMultiplayerSA::InitHooks_Weapons() EZHookInstall(CWeapon_GenerateDamageEvent); EZHookInstall(CShotInfo_Update); EZHookInstall(Fx_AddBulletImpact); + EZHookInstall(CVisibilityPlugins_RenderWeaponPedsForPC); } From ad1da8709352861deab6c67af8347d2341a345b1 Mon Sep 17 00:00:00 2001 From: lopsi <40902730+Lpsd@users.noreply.github.com> Date: Tue, 5 Nov 2024 22:01:16 +0100 Subject: [PATCH 2/2] Improve random nick generation (#3834) Co-authored-by: Uladzislau Nikalayevich --- Client/core/CNickGen.cpp | 22 +++++++++++++++------- Client/core/CNickGen.h | 5 ----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Client/core/CNickGen.cpp b/Client/core/CNickGen.cpp index a4cb2738e2..f877588539 100644 --- a/Client/core/CNickGen.cpp +++ b/Client/core/CNickGen.cpp @@ -8,10 +8,10 @@ *****************************************************************************/ #include "StdInc.h" -#include "time.h" +#include // These words are of a maximum length of 10 characters, capitalized, and stripped of whitespace -const char* const CNickGen::m_szAdjectives[] = { +const char* const szAdjectives[] = { "Aback", "Abaft", "Abandoned", "Abashed", "Aberrant", "Abhorrent", "Abiding", "Abject", "Ablaze", "Able", "Abnormal", "Aboard", "Aboriginal", "Abortive", "Abounding", "Abrasive", "Abrupt", "Absent", "Absorbed", "Absorbing", "Abstracted", "Absurd", "Abundant", "Abusive", "Acceptable", "Accessible", "Accidental", "Accurate", "Acid", "Acidic", "Acoustic", "Acrid", "Actually", @@ -109,7 +109,7 @@ const char* const CNickGen::m_szAdjectives[] = { "Worried", "Worthless", "Wrathful", "Wretched", "Wrong", "Wry", }; -const char* const CNickGen::m_szNouns[] = { +const char* const szNouns[] = { "Aardvark", "Buffalo", "Alligator", "Ant", "Anteater", "Antelope", "Ape", "Armadillo", "Donkey", "Baboon", "Badger", "Barracuda", "Bat", "Bear", "Beaver", "Bee", "Bison", "Boar", "Bush", "Butterfly", "Camel", "Calf", "Cat", "Kitten", "Cattle", "Chamois", "Cheetah", "Chicken", "Chick", "Chimpanzee", "Infant", "Empress", "Troop", @@ -196,10 +196,18 @@ const char* const CNickGen::m_szNouns[] = { "Vampire", "Parasite", "Tramp", "Bum", "Hobo", "Hitchhiker", "Deadbeat", "Acrobat", }; +constexpr auto numAdjectives = std::size(szAdjectives); +constexpr auto numNouns = std::size(szNouns); +constexpr auto maxNum = 100; + SString CNickGen::GetRandomNickname() { - srand((unsigned int)time(NULL)); - int iAdjective = rand() % NICKGEN_NUM_ADJECTIVES; - int iNoun = rand() % NICKGEN_NUM_NOUNS; - return SString("%s%s%i", m_szAdjectives[iAdjective], m_szNouns[iNoun], rand() % 100); + std::random_device rd; + std::mt19937 gen(rd()); + + std::uniform_int_distribution adjectiveDist(0, numAdjectives - 1); + std::uniform_int_distribution nounDist(0, numNouns - 1); + std::uniform_int_distribution numDist(0, maxNum); + + return SString("%s%s%i", szAdjectives[adjectiveDist(gen)], szNouns[nounDist(gen)], numDist(gen)); } diff --git a/Client/core/CNickGen.h b/Client/core/CNickGen.h index b98254f01b..86a3699072 100644 --- a/Client/core/CNickGen.h +++ b/Client/core/CNickGen.h @@ -9,13 +9,8 @@ #pragma once -#define NICKGEN_NUM_ADJECTIVES 1048 -#define NICKGEN_NUM_NOUNS 934 - class CNickGen { public: - static const char* const m_szAdjectives[NICKGEN_NUM_ADJECTIVES]; - static const char* const m_szNouns[NICKGEN_NUM_NOUNS]; static SString GetRandomNickname(); };