|
1 | 1 | using System.Collections; |
| 2 | +using System.Reflection; |
2 | 3 | using HarmonyLib; |
3 | 4 | using Lamb.UI; |
4 | 5 | using LeTai.Asset.TranslucentImage; |
| 6 | +using Sirenix.Serialization.Utilities; |
5 | 7 | using Spine; |
| 8 | +using Spine.Unity; |
6 | 9 | using src.Alerts; |
7 | 10 | using UnityEngine; |
8 | 11 | using UnityEngine.Experimental.Rendering; |
@@ -248,20 +251,79 @@ private static bool PlayerFarming_Start(PlayerFarming __instance) |
248 | 251 | if (!CustomPlayerSpines.ContainsKey(spineOverride)) return true; |
249 | 252 | if (CustomPlayerSpines[spineOverride] == null) return true; |
250 | 253 |
|
| 254 | + __instance.simpleSpineAnimator = __instance.GetComponentInChildren<SimpleSpineAnimator>(); |
| 255 | + //attempt to collect the event delegates via reflection |
| 256 | + MulticastDelegate delegates; |
| 257 | + try { |
| 258 | + LogWarning("Reflection start BEFORE"); |
| 259 | + var target = __instance.simpleSpineAnimator.anim.AnimationState; |
| 260 | + var field = target.GetType().GetField("Event", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic); |
| 261 | + LogWarning("Reflection field 1"); |
| 262 | + |
| 263 | + delegates = field.GetValue(target) as MulticastDelegate; |
| 264 | + |
| 265 | + LogWarning("Reflection field 2 delegate success, size is " + delegates.GetInvocationList().Length); |
| 266 | + delegates.GetInvocationList().ForEach(x => __instance.simpleSpineAnimator.anim.AnimationState.Event += x as Spine.AnimationState.TrackEntryEventDelegate); |
| 267 | + |
| 268 | + |
| 269 | + } |
| 270 | + catch (Exception e) { |
| 271 | + delegates = null; |
| 272 | + LogWarning(e.ToString()); |
| 273 | + } |
| 274 | + |
251 | 275 | var selectedSpineSkin = spineOverride.Split(['/'], 2)[1]; |
252 | 276 | var runtimeSkeletonAsset = CustomPlayerSpines[spineOverride]; |
253 | | - __instance.simpleSpineAnimator = __instance.GetComponentInChildren<SimpleSpineAnimator>(); |
254 | 277 | __instance.Spine.skeletonDataAsset = runtimeSkeletonAsset; |
255 | 278 | __instance.Spine.initialSkinName = selectedSpineSkin; |
256 | 279 | __instance.Spine.Initialize(true); |
257 | 280 |
|
258 | 281 | //this.anim.AnimationState.Event += new Spine.AnimationState.TrackEntryEventDelegate(this.SpineEventHandler); |
259 | 282 | //enable the spine animator event tracker after replacing spine |
| 283 | + try { |
| 284 | + if (delegates != null) |
| 285 | + { |
| 286 | + |
| 287 | + foreach (var delegateX in delegates.GetInvocationList()) |
| 288 | + { |
| 289 | + LogWarning("Attempting to Reapply animation handler - " + delegateX.GetMethodInfo().DeclaringType + "." + delegateX.GetMethodInfo().Name); |
| 290 | + __instance.simpleSpineAnimator.anim.AnimationState.Event -= delegateX as Spine.AnimationState.TrackEntryEventDelegate; |
| 291 | + __instance.simpleSpineAnimator.anim.AnimationState.Event += delegateX as Spine.AnimationState.TrackEntryEventDelegate; |
| 292 | + } |
| 293 | + } |
| 294 | + } |
| 295 | + catch (Exception e) { |
| 296 | + LogWarning("Error trying to add animation handlers! Some actions may not work! " + e.ToString()); |
| 297 | + } |
260 | 298 | __instance.simpleSpineAnimator.anim.AnimationState.Event -= |
261 | 299 | __instance.simpleSpineAnimator.SpineEventHandler; |
262 | 300 | __instance.simpleSpineAnimator.anim.AnimationState.Event += |
263 | 301 | __instance.simpleSpineAnimator.SpineEventHandler; |
264 | 302 |
|
| 303 | + // try |
| 304 | + // { |
| 305 | + // LogWarning("Reapplying Animation Handlers"); |
| 306 | + // __instance.simpleSpineAnimator.anim.AnimationState.Event += __instance.playerController.HandleAnimationStateEvent; |
| 307 | + // __instance.simpleSpineAnimator.anim.AnimationState.Event += __instance.playerWeapon.HandleAnimationStateEvent; |
| 308 | + |
| 309 | + // } |
| 310 | + // catch (Exception e) |
| 311 | + // { |
| 312 | + // LogWarning("Error adding animation handlers! Some actions may not work! " + e.ToString()); |
| 313 | + // } |
| 314 | + //remove player shaders to prevent random sprites from showing |
| 315 | + __instance.Spine.CustomMaterialOverride.Clear(); |
| 316 | + __instance.Spine.CustomSlotMaterials.Clear(); |
| 317 | + |
| 318 | + var allShaderRenderers = __instance.GetComponentsInChildren<SkeletonRendererCustomMaterials>(); |
| 319 | + foreach (var shaderRenderer in allShaderRenderers) |
| 320 | + { |
| 321 | + shaderRenderer.customMaterialOverrides.Clear(); |
| 322 | + shaderRenderer.customSlotMaterials.Clear(); |
| 323 | + shaderRenderer.enabled = false; |
| 324 | + } |
| 325 | + |
| 326 | + |
265 | 327 | LogInfo("PLAYERFARMING_START: Loaded Custom Spine " + spineOverride + " with skin " + selectedSpineSkin + " For player ID " + __instance.playerID); |
266 | 328 |
|
267 | 329 | return true; |
|
0 commit comments