Skip to content

Commit

Permalink
Merge branch 'bugfix/controlstate_static' of https://github.com/FileE…
Browse files Browse the repository at this point in the history
…X/mtasa-blue into bugfix/controlstate_static
  • Loading branch information
FileEX committed Jan 1, 2025
2 parents 8e30580 + f762077 commit c666c8e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 0 additions & 2 deletions Client/mods/deathmatch/logic/CClientPad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#define CS_NAN -32768

SFixedArray<short, MAX_GTA_CONTROLS> CClientPad::m_sScriptedStates;
SFixedArray<bool, MAX_GTA_ANALOG_CONTROLS> CClientPad::m_bScriptedStatesNextFrameOverride;
bool CClientPad::m_bFlyWithMouse;
bool CClientPad::m_bSteerWithMouse;

Expand Down
18 changes: 9 additions & 9 deletions Client/mods/deathmatch/logic/CClientPad.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ class CClientPad

void DoPulse(CClientPed* pPed);

static bool GetAnalogControlState(const char* szName, CControllerState& cs, bool bOnFoot, float& fState, bool bIgnoreOverrides);
static bool SetAnalogControlState(const char* szName, float fState, bool bFrameForced);
static void RemoveSetAnalogControlState(const char* szName);
bool GetAnalogControlState(const char* szName, CControllerState& cs, bool bOnFoot, float& fState, bool bIgnoreOverrides);
bool SetAnalogControlState(const char* szName, float fState, bool bFrameForced);
void RemoveSetAnalogControlState(const char* szName);

static void ProcessSetAnalogControlState(CControllerState& cs, bool bOnFoot);
static void ProcessControl(short& usControlValue, unsigned int uiIndex);
void ProcessSetAnalogControlState(CControllerState& cs, bool bOnFoot);
void ProcessControl(short& usControlValue, unsigned int uiIndex);

static void ProcessAllToggledControls(CControllerState& cs, bool bOnFoot);
static bool ProcessToggledControl(const char* szName, CControllerState& cs, bool bOnFoot, bool bEnabled);
static bool GetControlState(const char* szName, CControllerState& State, bool bOnFoot);

static SFixedArray<short, MAX_GTA_CONTROLS> m_sScriptedStates;
static SFixedArray<bool, MAX_GTA_ANALOG_CONTROLS> m_bScriptedStatesNextFrameOverride;
static bool m_bFlyWithMouse;
static bool m_bSteerWithMouse;
static bool m_bFlyWithMouse;
static bool m_bSteerWithMouse;

protected:
SFixedArray<float, MAX_GTA_CONTROLS> m_fStates;
SFixedArray<short, MAX_GTA_CONTROLS> m_sScriptedStates;
SFixedArray<bool, MAX_GTA_ANALOG_CONTROLS> m_bScriptedStatesNextFrameOverride;
};
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2960,7 +2960,7 @@ void CClientPed::ApplyControllerStateFixes(CControllerState& Current)
// Process our scripted control settings
bool bOnFoot = pVehicle ? false : true;
CClientPad::ProcessAllToggledControls(Current, bOnFoot);
CClientPad::ProcessSetAnalogControlState(Current, bOnFoot);
m_Pad.ProcessSetAnalogControlState(Current, bOnFoot);
}

// Is the player stealth aiming?
Expand Down
13 changes: 8 additions & 5 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1725,10 +1725,12 @@ bool CStaticFunctionDefinitions::GetPedControlState(CClientPed& Ped, const char*
bState = CClientPad::GetControlState(szControl, cs, bOnFoot);
float fState = 0;
unsigned int uiIndex;
CClientPad pad = Ped.m_Pad;

// Check it's Analog
if (CClientPad::GetAnalogControlIndex(szControl, uiIndex))
{
if (CClientPad::GetAnalogControlState(szControl, cs, bOnFoot, fState, false))
if (pad.GetAnalogControlState(szControl, cs, bOnFoot, fState, false))
{
bState = fState > 0;
return true;
Expand Down Expand Up @@ -1765,7 +1767,7 @@ bool CStaticFunctionDefinitions::GetPedAnalogControlState(CClientPed& Ped, const

// check it's analog or use binary.
if (CClientPad::GetAnalogControlIndex(szControl, uiIndex))
CClientPad::GetAnalogControlState(szControl, cs, bOnFoot, fState, bRawInput);
Ped.m_Pad.GetAnalogControlState(szControl, cs, bOnFoot, fState, bRawInput);
else
fState = CClientPad::GetControlState(szControl, cs, bOnFoot) == true ? 1.0f : 0.0f;

Expand Down Expand Up @@ -7196,7 +7198,7 @@ bool CStaticFunctionDefinitions::GetAnalogControlState(const char* szControl, fl
else
pLocalPlayer->GetControllerState(cs);

if (CClientPad::GetAnalogControlState(szControl, cs, bOnFoot, fState, bRawInput))
if (pLocalPlayer->m_Pad.GetAnalogControlState(szControl, cs, bOnFoot, fState, bRawInput))
{
return true;
}
Expand All @@ -7223,12 +7225,13 @@ bool CStaticFunctionDefinitions::SetControlState(const char* szControl, bool bSt
{
assert(szControl);
unsigned int uiIndex;
CClientPlayer* pLocalPlayer = m_pPlayerManager->GetLocalPlayer();

if (bState)
{
if (CClientPad::GetAnalogControlIndex(szControl, uiIndex))
{
if (CClientPad::SetAnalogControlState(szControl, 1.0, false))
if (pLocalPlayer->m_Pad.SetAnalogControlState(szControl, 1.0, false))
{
return true;
}
Expand All @@ -7248,7 +7251,7 @@ bool CStaticFunctionDefinitions::SetControlState(const char* szControl, bool bSt
{
if (CClientPad::GetAnalogControlIndex(szControl, uiIndex))
{
CClientPad::RemoveSetAnalogControlState(szControl);
pLocalPlayer->m_Pad.RemoveSetAnalogControlState(szControl);
return true;
}
else
Expand Down
6 changes: 4 additions & 2 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ int CLuaFunctionDefs::SetAnalogControlState(lua_State* luaVM)
CScriptArgReader argStream(luaVM);
argStream.ReadString(strControlState);

CClientPlayer* localPlayer = CStaticFunctionDefinitions::GetLocalPlayer();

if (!argStream.HasErrors())
{
if (argStream.NextIsNumber())
Expand All @@ -316,15 +318,15 @@ int CLuaFunctionDefs::SetAnalogControlState(lua_State* luaVM)
if (argStream.NextIsBool())
argStream.ReadBool(bForceOverrideNextFrame, false);

if (CClientPad::SetAnalogControlState(strControlState, fState, bForceOverrideNextFrame))
if (localPlayer->m_Pad.SetAnalogControlState(strControlState, fState, bForceOverrideNextFrame))
{
lua_pushboolean(luaVM, true);
return 1;
}
}
else if (argStream.NextIsNone())
{
CClientPad::RemoveSetAnalogControlState(strControlState);
localPlayer->m_Pad.RemoveSetAnalogControlState(strControlState);
lua_pushboolean(luaVM, true);
return 1;
}
Expand Down

0 comments on commit c666c8e

Please sign in to comment.