diff --git a/CLre/Fixes/CooldownCrossSlotSync.cs b/CLre/Fixes/CooldownCrossSlotSync.cs index 5e5235f..0045a18 100644 --- a/CLre/Fixes/CooldownCrossSlotSync.cs +++ b/CLre/Fixes/CooldownCrossSlotSync.cs @@ -86,7 +86,7 @@ namespace CLre.Fixes //API.Utility.Logging.MetaLog($"Cooling down? {isInCooldown} for {cooldownLeft}s"); // build functions for querying all Game.Handhelds.WeaponCooldownEntityView objects Type protoRaw = - typeof(Reflection.QueryEntityViews).GetGenericTypeDefinition() + typeof(Reflection.QueryEntityViews<>) .MakeGenericType( AccessTools.TypeByName("Game.Handhelds.WeaponCooldownEntityView")); Delegate queryAllWCEV = @@ -100,10 +100,16 @@ namespace CLre.Fixes object collectionStruct = queryAllWCEV.DynamicInvoke((int) baseGroup); int count = Traverse.Create(collectionStruct).Field("_count").Value; - PropertyInfo indexer = typeof(Svelto.DataStructures.ReadOnlyCollectionStruct).GetGenericTypeDefinition() + PropertyInfo indexer = typeof(Svelto.DataStructures.ReadOnlyCollectionStruct<>) .MakeGenericType(AccessTools.TypeByName("Game.Handhelds.WeaponCooldownEntityView")) .GetIndexer(); - object[] indexParams = {0}; + + if (!isRunningTick) + { + isRunningTick = true; + cooldownTickEverything(characterId, cwcevExists, queryCWCEV, queryWCEV, queryAllWCEV, indexer, baseGroup).Run(); + } + /*object[] indexParams = {0}; for (int index = 0; index < count; index++) { #if DEBUG @@ -119,12 +125,7 @@ namespace CLre.Fixes Traverse.Create(wcev) .Field("weaponCooldownComponent") .Property("isInCooldown").Value = isInCooldown; - } - - if (!isRunningTick) - { - cooldownTickEverything(characterId, entitiesDB, cwcevExists, queryCWCEV, queryWCEV, queryAllWCEV, indexer, baseGroup).Run(); - } + }*/ } [HarmonyTargetMethod] @@ -134,14 +135,10 @@ namespace CLre.Fixes new[] {typeof(int), typeof(bool)}); } - private static IEnumerator cooldownTickEverything(int characterId, IEntitiesDB entitiesDb, Reflection.ExistsV2 cwcevExists, Reflection.QueryEntityViewV2 cwcevQuery, Reflection.QueryEntityViewV2 wcevQuery, Delegate wcevQueryAll, PropertyInfo indexer, ExclusiveGroup baseGroup) + private static IEnumerator cooldownTickEverything(int characterId, Reflection.ExistsV2 cwcevExists, Reflection.QueryEntityViewV2 cwcevQuery, Reflection.QueryEntityViewV2 wcevQuery, Delegate wcevQueryAll, PropertyInfo indexer, ExclusiveGroup baseGroup) { - isRunningTick = true; while (cwcevExists(characterId, (int) DEPRECATED_SveltoExtensions.DEPRECATED_GROUP)) { -#if DEBUG - API.Utility.Logging.MetaLog("Doing cooldown tick for all weapons"); -#endif // get equipped handheld info object cwcevOriginal = cwcevQuery(characterId, (ExclusiveGroup.ExclusiveGroupStruct) DEPRECATED_SveltoExtensions.DEPRECATED_GROUP); @@ -157,9 +154,9 @@ namespace CLre.Fixes Traverse.Create(wcevOriginal).Field("weaponCooldownComponent").Property("cooldownLeft").Value; bool isInCooldown = Traverse.Create(wcevOriginal).Field("weaponCooldownComponent").Property("isInCooldown").Value; - if (!isInCooldown) break; object[] indexParams = {0}; // iterate over other handhelds and sync their cooldowns to the held item + API.Utility.Logging.MetaDebugLog($"Syncing {count} weapon cooldowns with the held item {toolId}"); for (int index = 0; index < count; index++) { indexParams[0] = index; @@ -173,10 +170,12 @@ namespace CLre.Fixes .Field("weaponCooldownComponent") .Property("isInCooldown").Value = isInCooldown; } - + // stop running this task after one final sync to set every handheld to non-cooldown state + if (!isInCooldown && cooldownLeft <= 0) break; yield return null; } // cleanup + API.Utility.Logging.MetaDebugLog("Custom cooldown ticks complete"); isRunningTick = false; yield return null; }