11using System ;
22using System . Threading ;
3+ using Dalamud . Game . ClientState . Conditions ;
34using Dalamud . Game . ClientState . Objects ;
45using Dalamud . Hooking ;
56using Dalamud . Utility . Signatures ;
@@ -22,18 +23,20 @@ public unsafe class AnimationHookService : IDisposable
2223 private readonly CollectionResolver _collectionResolver ;
2324 private readonly DrawObjectState _drawObjectState ;
2425 private readonly CollectionResolver _resolver ;
26+ private readonly Condition _conditions ;
2527
2628 private readonly ThreadLocal < ResolveData > _animationLoadData = new ( ( ) => ResolveData . Invalid , true ) ;
2729 private readonly ThreadLocal < ResolveData > _characterSoundData = new ( ( ) => ResolveData . Invalid , true ) ;
2830
2931 public AnimationHookService ( PerformanceTracker performance , ObjectTable objects , CollectionResolver collectionResolver ,
30- DrawObjectState drawObjectState , CollectionResolver resolver )
32+ DrawObjectState drawObjectState , CollectionResolver resolver , Condition conditions )
3133 {
3234 _performance = performance ;
3335 _objects = objects ;
3436 _collectionResolver = collectionResolver ;
3537 _drawObjectState = drawObjectState ;
3638 _resolver = resolver ;
39+ _conditions = conditions ;
3740
3841 SignatureHelper . Initialise ( this ) ;
3942
@@ -137,13 +140,17 @@ private IntPtr LoadCharacterSoundDetour(IntPtr character, int unk1, int unk2, In
137140 private ulong LoadTimelineResourcesDetour ( IntPtr timeline )
138141 {
139142 using var performance = _performance . Measure ( PerformanceType . TimelineResources ) ;
140- var last = _animationLoadData . Value ;
143+ // Do not check timeline loading in cutscenes.
144+ if ( _conditions [ ConditionFlag . OccupiedInCutSceneEvent ] || _conditions [ ConditionFlag . WatchingCutscene ] || _conditions [ ConditionFlag . WatchingCutscene78 ] )
145+ return _loadTimelineResourcesHook . Original ( timeline ) ;
146+
147+ var last = _animationLoadData . Value ;
141148 _animationLoadData . Value = GetDataFromTimeline ( timeline ) ;
142149 var ret = _loadTimelineResourcesHook . Original ( timeline ) ;
143150 _animationLoadData . Value = last ;
144151 return ret ;
145152 }
146-
153+
147154 /// <summary>
148155 /// Probably used when the base idle animation gets loaded.
149156 /// Make it aware of the correct collection to load the correct pap files.
@@ -287,17 +294,17 @@ private void ScheduleClipUpdateDetour(ClipScheduler* x)
287294 }
288295
289296 /// <summary> Use timelines vfuncs to obtain the associated game object. </summary>
290- private ResolveData GetDataFromTimeline( IntPtr timeline )
297+ private ResolveData GetDataFromTimeline( nint timeline )
291298 {
292299 try
293300 {
294301 if ( timeline != IntPtr. Zero)
295- {
296- var getGameObjectIdx = ( ( delegate * unmanaged< IntPtr , int > * * ) timeline) [ 0 ] [ Offsets. GetGameObjectIdxVfunc] ;
302+ {
303+ var getGameObjectIdx = ( ( delegate * unmanaged< nint , int > * * ) timeline) [ 0 ] [ Offsets. GetGameObjectIdxVfunc] ;
297304 var idx = getGameObjectIdx( timeline ) ;
298305 if ( idx >= 0 && idx < _objects . Length )
299306 {
300- var obj = ( GameObject * ) _objects . GetObjectAddress ( idx ) ;
307+ var obj = ( GameObject * ) _objects . GetObjectAddress ( idx ) ;
301308 return obj != null ? _collectionResolver . IdentifyCollection ( obj , true ) : ResolveData . Invalid ;
302309 }
303310 }
@@ -310,7 +317,6 @@ private ResolveData GetDataFromTimeline(IntPtr timeline)
310317 return ResolveData. Invalid;
311318 }
312319
313-
314320 private delegate void UnkMountAnimationDelegate( DrawObject* drawObject, uint unk1, byte unk2, uint unk3) ;
315321
316322 [ Signature( "48 89 5 C 24 ?? 48 89 6 C 24 ?? 89 54 24 ", DetourName = nameof( UnkMountAnimationDetour) ) ]
@@ -334,7 +340,7 @@ private void UnkParasolAnimationDetour(DrawObject* drawObject, int unk1)
334340 {
335341 var last = _animationLoadData. Value;
336342 _animationLoadData. Value = _collectionResolver. IdentifyCollection( drawObject , true ) ;
337- _unkParasolAnimationHook ! . Original ( drawObject , unk1 ) ;
343+ _unkParasolAnimationHook . Original ( drawObject , unk1 ) ;
338344 _animationLoadData . Value = last ;
339345 }
340346
0 commit comments