Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add new functions related to underwater effects #3463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
XJMLN wants to merge 13 commits into multitheftauto:master
base: master
Choose a base branch
Loading
from XJMLN:feature/underwater-effect
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit Hold shift + click to select a range
2c3ac63
underwater effect functions
XJMLN Jun 12, 2024
70fdd7b
conditional operator, check if client is underwater
XJMLN Jun 12, 2024
dd153db
reset underwater effects on server connect
XJMLN Jun 12, 2024
b333f63
add space
XJMLN Jun 24, 2024
47b6107
Merge branch 'master' into feature/underwater-effect
XJMLN Jun 26, 2024
a384e4b
update after review
XJMLN Jun 26, 2024
b4c5104
CR changes
XJMLN Jan 20, 2025
132bd64
Merge remote-tracking branch 'origin/master' into feature/underwater-...
XJMLN Jan 20, 2025
004cf6d
Merge branch 'master' into feature/underwater-effect
XJMLN Jan 20, 2025
5e12c2a
add to ResetWorldProperties
XJMLN Jan 20, 2025
518690f
optional frequency
XJMLN Jan 20, 2025
69c0c19
Merge branch 'master' into feature/underwater-effect
FileEX Aug 13, 2025
d7448f8
Merge branch 'master' into feature/underwater-effect
tederis Sep 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some comments aren't visible on the classic Files Changed page.

5 changes: 5 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5492,6 +5492,11 @@ void CClientGame::ResetMapInfo()
g_pMultiplayer->SetGrainMultiplier(eGrainMultiplierType::ALL, 1.0f);
g_pMultiplayer->SetGrainLevel(0);

// Underwater effects
g_pMultiplayer->SetUnderwaterDarkness(true, 90.0f);
g_pMultiplayer->SetUnderwaterEffectEnabled(false);
g_pMultiplayer->SetUnderwaterEffectSpeed(0.0015f, 0.04f);

// Water
GetManager()->GetWaterManager()->ResetWorldWaterLevel();

Expand Down
60 changes: 60 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ void CLuaCameraDefs::LoadFunctions()
{"getCameraGoggleEffect", ArgumentParserWarn<false, GetCameraGoggleEffect>},
{"getCameraFieldOfView", GetCameraFieldOfView},
{"getCameraDrunkLevel", ArgumentParserWarn<false, GetCameraDrunkLevel>},
{"getCameraUnderwaterEffect", ArgumentParser<GetCameraUnderwaterEffect>},
{"getCameraUnderwaterDarkness", ArgumentParser<GetCameraUnderwaterDarkness>},

// Cam set funcs
{"setCameraMatrix", SetCameraMatrix},
Expand All @@ -41,6 +43,11 @@ void CLuaCameraDefs::LoadFunctions()
{"setCameraViewMode", ArgumentParserWarn<false, SetCameraViewMode>},
{"setCameraGoggleEffect", SetCameraGoggleEffect},
{"setCameraDrunkLevel", ArgumentParserWarn<false, SetCameraDrunkLevel>},
{"setCameraUnderwaterEffectEnabled", ArgumentParser<SetCameraUnderwaterEffectEnabled>},
{"setCameraUnderwaterEffectSpeed", ArgumentParser<SetCameraUnderwaterEffectSpeed>},
{"setCameraUnderwaterDarkness", ArgumentParser<SetCameraUnderwaterDarkness>},
{"resetCameraUnderwaterEffect", ArgumentParser<ResetCameraUnderwaterEffect>},
{"resetCameraUnderwaterDarkness", ArgumentParser<ResetCameraUnderwaterDarkness>},
};

// Add functions
Expand Down Expand Up @@ -68,6 +75,8 @@ void CLuaCameraDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "getFarClipDistance", "getFarClipDistance");
lua_classfunction(luaVM, "getNearClipDistance", "getNearClipDistance");
lua_classfunction(luaVM, "getType", ArgumentParser<GetElementType>);
lua_classfunction(luaVM, "getUnderwaterEffect", ArgumentParser<GetCameraUnderwaterEffect>);
lua_classfunction(luaVM, "getUnderwaterDarkness", ArgumentParser<GetCameraUnderwaterDarkness>);

lua_classfunction(luaVM, "setPosition", OOP_SetCameraPosition);
lua_classfunction(luaVM, "setRotation", OOP_SetCameraRotation);
Expand All @@ -80,6 +89,11 @@ void CLuaCameraDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "setClip", "setCameraClip");
lua_classfunction(luaVM, "setFarClipDistance", "setFarClipDistance");
lua_classfunction(luaVM, "setNearClipDistance", "setNearClipDistance");
lua_classfunction(luaVM, "setUnderwaterEffectEnabled", ArgumentParser<SetCameraUnderwaterEffectEnabled>);
lua_classfunction(luaVM, "setUnderwaterEffectSpeed", ArgumentParser<SetCameraUnderwaterEffectSpeed>);
lua_classfunction(luaVM, "setUnderwaterDarkness", ArgumentParser<SetCameraUnderwaterDarkness>);
lua_classfunction(luaVM, "resetUnderwaterEffect", ArgumentParser<ResetCameraUnderwaterEffect>);
lua_classfunction(luaVM, "resetUnderwaterDarkness", ArgumentParser<ResetCameraUnderwaterDarkness>);

lua_classvariable(luaVM, "interior", "setCameraInterior", "getCameraInterior");
lua_classvariable(luaVM, "target", "setCameraTarget", "getCameraTarget");
Expand Down Expand Up @@ -162,6 +176,16 @@ unsigned char CLuaCameraDefs::GetCameraDrunkLevel()
return g_pGame->GetPlayerInfo()->GetCamDrunkLevel();
}

CLuaMultiReturn<bool, float, float> CLuaCameraDefs::GetCameraUnderwaterEffect()
{
return g_pMultiplayer->GetUnderwaterEffect();
}

CLuaMultiReturn<bool, float> CLuaCameraDefs::GetCameraUnderwaterDarkness()
{
return g_pMultiplayer->GetUnderwaterDarkness();
}

int CLuaCameraDefs::SetCameraMatrix(lua_State* luaVM)
{
CVector vecPosition;
Expand Down Expand Up @@ -464,6 +488,42 @@ int CLuaCameraDefs::SetCameraGoggleEffect(lua_State* luaVM)
return 1;
}

bool CLuaCameraDefs::SetCameraUnderwaterEffectEnabled(bool bEnabled)
{
g_pMultiplayer->SetUnderwaterEffectEnabled(bEnabled);

return true;
}

bool CLuaCameraDefs::SetCameraUnderwaterEffectSpeed(float fSpeed, float fFrequency)
{
g_pMultiplayer->SetUnderwaterEffectSpeed(fSpeed, fFrequency);

return true;
}

bool CLuaCameraDefs::SetCameraUnderwaterDarkness(bool bEnabled, std::optional<float> fFullDarknessDepth)
{
g_pMultiplayer->SetUnderwaterDarkness(bEnabled, fFullDarknessDepth.value_or(90.0f));

return true;
}

bool CLuaCameraDefs::ResetCameraUnderwaterEffect()
{
g_pMultiplayer->SetUnderwaterEffectEnabled(false);
g_pMultiplayer->SetUnderwaterEffectSpeed(0.0015f, 0.04f);

return true;
}

bool CLuaCameraDefs::ResetCameraUnderwaterDarkness()
{
g_pMultiplayer->SetUnderwaterDarkness(true, 90.0f);

return true;
}

bool CLuaCameraDefs::SetCameraDrunkLevel(short drunkLevel)
{
if (drunkLevel < 0 || drunkLevel > 255)
Expand Down
8 changes: 8 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class CLuaCameraDefs : public CLuaDefs
static std::string GetCameraGoggleEffect();
LUA_DECLARE(GetCameraFieldOfView);
static unsigned char GetCameraDrunkLevel();
static CLuaMultiReturn<bool, float, float> GetCameraUnderwaterEffect();
static CLuaMultiReturn<bool, float> GetCameraUnderwaterDarkness();

// Cam set funcs
LUA_DECLARE(SetCameraMatrix);
Expand All @@ -43,6 +45,12 @@ class CLuaCameraDefs : public CLuaDefs
LUA_DECLARE(SetCameraGoggleEffect);
static bool SetCameraDrunkLevel(short drunkLevel);

static bool SetCameraUnderwaterEffectEnabled(bool bEnabled);
static bool SetCameraUnderwaterEffectSpeed(float fSpeed, float fFrequency);
static bool SetCameraUnderwaterDarkness(bool bEnabled, std::optional<float> fFullDarknessDepth);
static bool ResetCameraUnderwaterEffect();
static bool ResetCameraUnderwaterDarkness();

// For OOP only
LUA_DECLARE(OOP_GetCameraPosition);
LUA_DECLARE(OOP_SetCameraPosition);
Expand Down
6 changes: 6 additions & 0 deletions Client/multiplayer_sa/CMultiplayerSA.h
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ class CMultiplayerSA : public CMultiplayer
bool IsNightVisionEnabled();
bool IsThermalVisionEnabled();

std::tuple<bool, float, float> GetUnderwaterEffect();
std::tuple<bool, float> GetUnderwaterDarkness();
void SetUnderwaterEffectEnabled(bool bEnabled);
void SetUnderwaterEffectSpeed(float fSpeed, float fFrequency);
void SetUnderwaterDarkness(bool bEnabled, float fFullDarknessDepth);

void AllowWindowsCursorShowing(bool bAllow);

CShotSyncData* GetLocalShotSyncData();
Expand Down
36 changes: 36 additions & 0 deletions Client/multiplayer_sa/CMultiplayerSA_Postprocess.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ void CMultiplayerSA::SetNightVisionEnabled(bool bEnabled, bool bNoiseEnabled)
}
}

void CMultiplayerSA::SetUnderwaterEffectEnabled(bool bEnabled)
{
MemPutFast<BYTE>(0xC402D3, bEnabled ? 1 : 0);
}

void CMultiplayerSA::SetUnderwaterEffectSpeed(float fSpeed, float fFrequency)
{
MemPutFast<float>(0x8D5138, fSpeed);
MemPutFast<float>(0x8D513C, fFrequency);
}

void CMultiplayerSA::SetUnderwaterDarkness(bool bEnabled, float fFullDarknessDepth)
{
MemPutFast<BYTE>(0x8D5144, bEnabled ? 1 : 0);

MemPutFast<float>(0x8D5148, fFullDarknessDepth);
}

void CMultiplayerSA::SetThermalVisionEnabled(bool bEnabled, bool bNoiseEnabled)
{
if (bEnabled)
Expand Down Expand Up @@ -184,6 +202,24 @@ bool CMultiplayerSA::IsThermalVisionEnabled()
return (*(BYTE*)0xC402B9 == 1);
}

std::tuple<bool, float, float> CMultiplayerSA::GetUnderwaterEffect()
{
bool bEnabled = (*(BYTE*)0xC402D3 == 1) || (*(float*)0xC8132C) >= 0.535f;
float fSpeed = (*(float*)0x8D5138);
float fFrequency = (*(float*)0x8D513C);

return std::tuple<bool, float, float>(bEnabled, fSpeed, fFrequency);
}


std::tuple<bool, float> CMultiplayerSA::GetUnderwaterDarkness()
{
bool bEnabled = (*(BYTE*)0x8D5144);
float fFullDarknessDepth = (*(float*)0x8D5148);

return std::tuple<bool, float>(bEnabled, fFullDarknessDepth);
}

void CMultiplayerSA::InitHooks_Postprocess()
{
HookInstallCall(HOOKPOS_GrainEffect_NightModifier, (DWORD)GrainEffect::NightModifier::ApplyEffect);
Expand Down
6 changes: 6 additions & 0 deletions Client/sdk/multiplayer/CMultiplayer.h
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,10 @@ class CMultiplayer
virtual unsigned int EntryInfoNodePool_NoOfUsedSpaces() const noexcept = 0;
virtual unsigned int PtrNodeSingleLinkPool_NoOfUsedSpaces() const noexcept = 0;
virtual unsigned int PtrNodeDoubleLinkPool_NoOfUsedSpaces() const noexcept = 0;

virtual std::tuple<bool, float, float> GetUnderwaterEffect() = 0;
virtual std::tuple<bool, float> GetUnderwaterDarkness() = 0;
virtual void SetUnderwaterEffectEnabled(bool bEnabled) = 0;
virtual void SetUnderwaterEffectSpeed(float fSpeed, float fFrequency) = 0;
virtual void SetUnderwaterDarkness(bool bEnabled, float fFullDarknessDepth) = 0;
};

AltStyle によって変換されたページ (->オリジナル) /