From d8ba20f702ac2bbf4171ecfc2b86c512b4fe8abb Mon Sep 17 00:00:00 2001 From: pinguluk Date: Mon, 6 Mar 2023 02:20:33 +0200 Subject: [PATCH] Added hotfix to hooks not registering correctly when starting the game; Added additional comments --- Scripts/main.lua | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Scripts/main.lua b/Scripts/main.lua index 9955dee..5af66f9 100644 --- a/Scripts/main.lua +++ b/Scripts/main.lua @@ -8,6 +8,7 @@ local is_bind_registered = false local is_shadowblink_start_hook_registered = false local is_shadowblink_end_hook_registered = false +-- Change the speed of the ShadowBlink function function SetShadowBlinkSpeed() local shadowBlinkAbilityRootMotion = StaticFindObject( "/Game/Pawn/Student/Abilities/Locomotion/ABL_ShadowBlink.Default__ABL_ShadowBlink_C:ablRootMotionModifiersTask_1.RootMotionModifierProperties_DodgeRoll_0") @@ -15,10 +16,9 @@ function SetShadowBlinkSpeed() print('Setting ShadowBlink speed to ' .. shadowBlinkSpeed) shadowBlinkAbilityRootMotion:SetPropertyValue("BlinkSpeed", shadowBlinkSpeed) end - end --- Change the offset of the ShadowBlink animation end +-- Change the offset of the ShadowBlink animation end function function SetShadowBlinkAnimationEnd(offset) print('Setting ShadowBlinkAnimationEnd to ' .. offset) shadowBlinkAbility:SetPropertyValue("m_EndTime", { @@ -26,7 +26,7 @@ function SetShadowBlinkAnimationEnd(offset) }) end --- Initialise the script +-- Initialise the script function function Init() print('is_bind_registered: ' .. tostring(is_bind_registered)) print('is_shadowblink_start_hook_registered: ' .. tostring(is_shadowblink_start_hook_registered)) @@ -40,7 +40,8 @@ function Init() -- Prevent the key bind from being initialised multiple times if is_bind_registered == false then - -- Bind left control key + print('Registering STOP key hook') + -- Register the STOP key bind to stop the ShadowBlink RegisterKeyBind(stopShadowBlinkKey, {}, function() print('Pressed STOP key while ShadowBlinking? ' .. tostring(isShadowBlinking)) print('Stopping shadow blink') @@ -53,6 +54,7 @@ function Init() -- Prevent the hook from being initialised multiple times if is_shadowblink_start_hook_registered == false then + print('Registering ShadowBlink start hook') -- On ShadowBlink start RegisterHook("/Game/Pawn/Shared/StateTree/BTT_Biped_ShadowBlink_2.BTT_Biped_ShadowBlink_2_C:ReceiveExecute", function() @@ -66,6 +68,7 @@ function Init() -- Prevent the hook from being initialised multiple times if is_shadowblink_end_hook_registered == false then + print('Registering ShadowBlink end hook') -- On ShadowBlink end RegisterHook("/Game/Pawn/Shared/StateTree/BTT_Biped_ShadowBlink_2.BTT_Biped_ShadowBlink_2_C:ExitTask", function() @@ -78,6 +81,14 @@ function Init() end end +-- This will be used to prevent the mod's script from being initialised earlier than it should +-- as the ShadowBlink start & end animations hooks are not registered correctly when launching the game +local shouldInitTheMod = false + +NotifyOnNewObject("/Script/Phoenix.Loadingcreen", function(self) + shouldInitTheMod = true +end) + -- Hook on load / reload RegisterHook("/Script/Engine.PlayerController:ClientRestart", function(Context) print("Hooked on load / reload succesfully") @@ -86,10 +97,11 @@ RegisterHook("/Script/Engine.PlayerController:ClientRestart", function(Context) shadowBlinkAbility = StaticFindObject( "/Game/Pawn/Student/Abilities/Locomotion/ABL_ShadowBlink.Default__ABL_ShadowBlink_C:ablRootMotionModifiersTask_1") - -- If the ability is found, initialise the script - if shadowBlinkAbility:IsValid() then - print('Initialising') + -- If the ability is valid/exists and shouldInitTheMod is true, initialise the mod's scripts + if shadowBlinkAbility:IsValid() and shouldInitTheMod then + shouldInitTheMod = false + print('Initialising InfiniteSwift mod') Init() - print('Finished initialising') + print('Finished initialising InfiniteSwift mod') end end)