csharp/0ceal0t/JobBars/JobBars/JobBars.Hooks.cs

JobBars.Hooks.cs
using System;
using System.Collections.Generic;
using JobBars.GameStructs;
using JobBars.Data;
using Dalamud.Game.ClientState.Objects.Types;
using JobBars.Helper;
using Dalamud.Logging;

namespace JobBars {
    public unsafe partial clast JobBars {
        private void ReceiveActionEffect(int sourceId, IntPtr sourceCharacter, IntPtr pos, IntPtr effectHeader, IntPtr effectArray, IntPtr effectTrail) {
            if (!PlayerExists) {
                ReceiveActionEffectHook.Original(sourceId, sourceCharacter, pos, effectHeader, effectArray, effectTrail);
                return;
            }

            uint id = *((uint*)effectHeader.ToPointer() + 0x2);
            byte type = *((byte*)effectHeader.ToPointer() + 0x1F); // 1 = action

            var selfId = (int)ClientState.LocalPlayer.ObjectId;
            var isSelf = sourceId == selfId;
            var isPet = !isSelf && (GaugeManager?.CurrentJob == JobIds.SMN || GaugeManager?.CurrentJob == JobIds.SCH) && IsPet(sourceId, selfId);
            var isParty = !isSelf && !isPet && IsInParty((uint)sourceId);

            if (type != 1 || !(isSelf || isPet || isParty)) {
                ReceiveActionEffectHook.Original(sourceId, sourceCharacter, pos, effectHeader, effectArray, effectTrail);
                return;
            }

            var actionItem = new Item {
                Id = id,
                Type = (UIHelper.IsGCD(id) ? ItemType.GCD : ItemType.OGCD)
            };

            if (!isParty) { // don't let party members affect our gauge
                GaugeManager?.PerformAction(actionItem);
            }
            if (!isPet) {
                BuffManager?.PerformAction(actionItem, (uint)sourceId);
                CooldownManager?.PerformAction(actionItem, (uint)sourceId);
            }

            byte targetCount = *(byte*)(effectHeader + 0x21);

            int effectsEntries = 0;
            int targetEntries = 1;
            if (targetCount == 0) {
                effectsEntries = 0;
                targetEntries = 1;
            }
            else if (targetCount == 1) {
                effectsEntries = 8;
                targetEntries = 1;
            }
            else if (targetCount