Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(ChaosMod CXX)

# Find latest version at https://github.com/OrfeasZ/ZHMModSDK/releases
# Set ZHMMODSDK_DIR variable to a local directory to use a local copy of the ZHMModSDK.
set(ZHMMODSDK_VER "v4.0.2")
set(ZHMMODSDK_VER "v4.1.1")
include(cmake/setup-zhmmodsdk.cmake)

# Set C++ standard to C++23.
Expand Down
10 changes: 3 additions & 7 deletions src/Effects/Player/ZDisableInputsEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,14 @@ DEFINE_PLUGIN_DETOUR(ZDisableInputsEffect, bool, OnInputActionDigital, ZInputAct
return HookResult<bool>(HookAction::Continue());
}

DEFINE_PLUGIN_DETOUR(ZDisableInputsEffect, double, OnInputActionAnalog, ZInputAction* th, int a2)
DEFINE_PLUGIN_DETOUR(ZDisableInputsEffect, float32, OnInputActionAnalog, ZInputAction* th, int a2)
{
if (m_bEnable)
{
// note: hook uses float32, but typed as float64.
// so we need to unpack and repack to/from float32.
auto s_fValue = 0.0f;
auto s_fValueReturn = *Utils::CastRaw<float64>(&s_fValue);
return {HookAction::Return(), s_fValueReturn};
return {HookAction::Return(), 0.0f};
}

return HookResult<float64>(HookAction::Continue());
return HookResult<float32>(HookAction::Continue());
}

REGISTER_CHAOS_EFFECT(ZDisableInputsEffect)
2 changes: 1 addition & 1 deletion src/Effects/Player/ZDisableInputsEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ class ZDisableInputsEffect : public IChaosEffect
bool m_bEnable = false;

DECLARE_PLUGIN_DETOUR(ZDisableInputsEffect, bool, OnInputActionDigital, ZInputAction* th, int a2);
DECLARE_PLUGIN_DETOUR(ZDisableInputsEffect, double, OnInputActionAnalog, ZInputAction* th, int a2);
DECLARE_PLUGIN_DETOUR(ZDisableInputsEffect, float32, OnInputActionAnalog, ZInputAction* th, int a2);
};
11 changes: 3 additions & 8 deletions src/Effects/Player/ZForceForwardMovementEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,18 @@ void ZForceForwardMovementEffect::Stop()
m_bEnable = false;
}

DEFINE_PLUGIN_DETOUR(ZForceForwardMovementEffect, double, OnInputActionAnalog, ZInputAction* th, int a2)
DEFINE_PLUGIN_DETOUR(ZForceForwardMovementEffect, float32, OnInputActionAnalog, ZInputAction* th, int a2)
{
if (m_bEnable)
{
const std::string s_sName = th->m_szName;
if (s_sName == InputActionNames::Keyboard::c_sVertical || s_sName == InputActionNames::Controller::c_sLeftStickVertical)
{
// note: hook uses float32, but typed as float64.
// so we need to unpack and repack to/from float32.
auto s_fValue = 1.0f;

auto s_fValueReturn = *Utils::CastRaw<float64>(&s_fValue);
return {HookAction::Return(), s_fValueReturn};
return {HookAction::Return(), 1.0f};
}
}

return HookResult<float64>(HookAction::Continue());
return HookResult<float32>(HookAction::Continue());
}

REGISTER_CHAOS_EFFECT(ZForceForwardMovementEffect)
2 changes: 1 addition & 1 deletion src/Effects/Player/ZForceForwardMovementEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ class ZForceForwardMovementEffect : public IChaosEffect
private:
bool m_bEnable = false;

DECLARE_PLUGIN_DETOUR(ZForceForwardMovementEffect, double, OnInputActionAnalog, ZInputAction* th, int a2);
DECLARE_PLUGIN_DETOUR(ZForceForwardMovementEffect, float32, OnInputActionAnalog, ZInputAction* th, int a2);
};
14 changes: 4 additions & 10 deletions src/Effects/Player/ZInvertControlsEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,21 @@ void ZInvertControlsEffect::Stop()
m_bEnable = false;
}

DEFINE_PLUGIN_DETOUR(ZInvertControlsEffect, double, OnInputActionAnalog, ZInputAction* th, int a2)
DEFINE_PLUGIN_DETOUR(ZInvertControlsEffect, float32, OnInputActionAnalog, ZInputAction* th, int a2)
{
if (m_bEnable)
{
const std::string s_sName = th->m_szName;
if (s_sName == InputActionNames::Keyboard::c_sVertical || s_sName == InputActionNames::Keyboard::c_sHorizontal || s_sName == InputActionNames::Keyboard::c_sLookVertical || s_sName == InputActionNames::Keyboard::c_sLookHorizontal || s_sName == InputActionNames::Controller::c_sLeftStickVertical || s_sName == InputActionNames::Controller::c_sLeftStickHorizontal || s_sName == InputActionNames::Controller::c_sRightStickVertical || s_sName == InputActionNames::Controller::c_sRightStickHorizontal)
{
auto s_fValueRaw = p_Hook->CallOriginal(th, a2);

// note: hook uses float32, but typed as float64.
// so we need to unpack and repack to/from float32.
auto s_fValue = *Utils::CastRaw<float32>(&s_fValueRaw);

auto s_fValue = p_Hook->CallOriginal(th, a2);
s_fValue *= -1.0f;

auto s_fValueReturn = *Utils::CastRaw<float64>(&s_fValue);
return {HookAction::Return(), s_fValueReturn};
return {HookAction::Return(), s_fValue};
}
}

return HookResult<float64>(HookAction::Continue());
return HookResult<float32>(HookAction::Continue());
}

REGISTER_CHAOS_EFFECT(ZInvertControlsEffect)
2 changes: 1 addition & 1 deletion src/Effects/Player/ZInvertControlsEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ class ZInvertControlsEffect : public IChaosEffect
private:
bool m_bEnable = false;

DECLARE_PLUGIN_DETOUR(ZInvertControlsEffect, double, OnInputActionAnalog, ZInputAction* th, int a2);
DECLARE_PLUGIN_DETOUR(ZInvertControlsEffect, float32, OnInputActionAnalog, ZInputAction* th, int a2);
};
16 changes: 4 additions & 12 deletions src/Effects/Player/ZPlayerTeleportMovementEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ ZPlayerTeleportMovementEffect::ETeleportResult ZPlayerTeleportMovementEffect::Pe
return ETeleportResult::SUCCESS;
}

DEFINE_PLUGIN_DETOUR(ZPlayerTeleportMovementEffect, double, OnInputActionAnalog, ZInputAction* th, int a2)
DEFINE_PLUGIN_DETOUR(ZPlayerTeleportMovementEffect, float32, OnInputActionAnalog, ZInputAction* th, int a2)
{
if (m_eState != EState::DISABLED)
{
Expand All @@ -194,11 +194,7 @@ DEFINE_PLUGIN_DETOUR(ZPlayerTeleportMovementEffect, double, OnInputActionAnalog,
const bool s_bIsHorizontalMovement = s_sName == InputActionNames::Keyboard::c_sHorizontal || s_sName == InputActionNames::Controller::c_sLeftStickHorizontal;
if (s_bIsVerticalMovement || s_bIsHorizontalMovement)
{
auto s_fValueRaw = p_Hook->CallOriginal(th, a2);

// note: hook uses float32, but typed as float64.
// so we need to unpack and repack to/from float32.
auto s_fValue = *Utils::CastRaw<float32>(&s_fValueRaw);
auto s_fValue = p_Hook->CallOriginal(th, a2);

// for positive vertical movement (= walk forward), trigger teleport
// only if above threshold to prevent accidental activation (only relevant for controllers!)
Expand All @@ -207,15 +203,11 @@ DEFINE_PLUGIN_DETOUR(ZPlayerTeleportMovementEffect, double, OnInputActionAnalog,
m_eState = EState::TELEPORT_NEXT_FRAME;
}

// disable all movement via inputs while active
s_fValue = 0.0f;

auto s_fValueReturn = *Utils::CastRaw<float64>(&s_fValue);
return {HookAction::Return(), s_fValueReturn};
return {HookAction::Return(), 0.0f};
}
}

return HookResult<float64>(HookAction::Continue());
return HookResult<float32>(HookAction::Continue());
}

std::string_view ZPlayerTeleportMovementEffect::StateToName(const EState p_eState)
Expand Down
2 changes: 1 addition & 1 deletion src/Effects/Player/ZPlayerTeleportMovementEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ class ZPlayerTeleportMovementEffect : public IChaosEffect
EState m_eState = EState::DISABLED;
float32 m_fCooldownRemaining = 0.0f;

DECLARE_PLUGIN_DETOUR(ZPlayerTeleportMovementEffect, double, OnInputActionAnalog, ZInputAction* th, int a2);
DECLARE_PLUGIN_DETOUR(ZPlayerTeleportMovementEffect, float32, OnInputActionAnalog, ZInputAction* th, int a2);
};
20 changes: 18 additions & 2 deletions src/Helpers/EntityUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,25 @@ ZEntityBlueprintFactoryBase* Utils::GetEntityBlueprintFactoryFor(ZEntityRef p_rE
{
const auto* s_pAspectBPFactory = reinterpret_cast<const ZAspectEntityBlueprintFactory*>(s_pBPFactory);

const auto s_AspectSubIndex = s_pAspectBPFactory->m_aSubEntitiesLookUp[s_nSubIndex];
int s_AspectSubIndex = -1;
if (s_pAspectBPFactory->m_aSubEntitiesLookUp.m_pBegin && s_pAspectBPFactory->m_aSubEntitiesLookUp.m_pEnd)
{
for (auto it = s_pAspectBPFactory->m_aSubEntitiesLookUp.m_pBegin; it != s_pAspectBPFactory->m_aSubEntitiesLookUp.m_pEnd; ++it)
{
if (it->m_nAspectIdx == s_nSubIndex)
{
s_AspectSubIndex = it->m_nSubentityIdx;
Comment thread
shadow578 marked this conversation as resolved.
Resolved
break;
}
}
}

if (s_AspectSubIndex == -1)
{
return nullptr;
}

s_pBPFactory = reinterpret_cast<ZEntityBlueprintFactoryBase*>(s_pAspectBPFactory->m_aBlueprintFactories[s_AspectSubIndex.m_nSubentityIdx]);
s_pBPFactory = reinterpret_cast<ZEntityBlueprintFactoryBase*>(s_pAspectBPFactory->m_aBlueprintFactories[s_AspectSubIndex]);
}

// may have re-resolved the bp pointer (aspect entity), so check again to be sure.
Expand Down
Loading