static public void GetMaximumMagnitudeAndRate()
        {
            var assembly = new UnmanagedArray <System.Byte>();

            assembly.Add(new System.Byte[8] {
                0xF3, 0x0F, 0x10, 0xB3, 0x9C, 0x00, 0x00, 0x00
            });                                                                                                 // movss xmm6, [rbx+9C]
            assembly.Add(new System.Byte[4] {
                0xF3, 0x0F, 0x59, 0xF7
            });                                                                                                                         // mulss xmm6, xmm7
            assembly.Add(new System.Byte[3] {
                0x0F, 0x28, 0xF8
            });                                                                                                                                 // movaps xmm7,xmm0

            Memory.SafeWrite <System.Byte>(ScrambledBugs.Offsets.Patches.AccumulatingMagnitude.GetMaximumMagnitudeAndRate, assembly);

            /*
             * AccumulatingValueModifierEffect* accumulatingValueModifierEffect;	// rbx
             * System.Single frameTime;											// xmm7
             * System.Single maximumMagnitude;										// xmm0
             *
             * var rate				= accumulatingValueModifierEffect->MaximumMagnitude() * frameTime;
             * var maximumMagnitude	= accumulatingValueModifierEffect->GetCurrentMagnitude();
             */
        }
Example #2
0
        static public void AddNoHitEffectArtFlag()
        {
            var assembly = new UnmanagedArray <System.Byte>();

            assembly.Add(new System.Byte[2] {
                0x24, 0xF8
            });                                                                 // and al, F8 (1 << 2 (NoHitEffectArt), 1 << 4 (NoInitialFlare))
            assembly.Add(new System.Byte[1] {
                Assembly.Nop
            });                                                                 // nop
            assembly.Add(new System.Byte[1] {
                Assembly.Nop
            });                                                                 // nop

            Memory.SafeWrite <System.Byte>(ScrambledBugs.Offsets.Patches.AttachHitEffectArt.AddNoHitEffectArtFlag, assembly);
        }
Example #3
0
        static public UnmanagedArray <TDestination> CreateInstance(TDestination[] elements)
        {
            var array = new UnmanagedArray <TDestination>();

            array.Add(elements);

            return(array);
        }
        static public void GetMaximumMagnitude()
        {
            var assembly = new UnmanagedArray <System.Byte>();

            assembly.Add(new System.Byte[3] {
                0x48, 0x8B, 0xCB
            });                                                                                                                                                                                                 // mov rcx, rbx
            assembly.Add(Assembly.RelativeCall(ScrambledBugs.Offsets.Patches.AccumulatingMagnitude.GetMaximumMagnitude, 3, Eggstensions.Offsets.ActiveEffect.GetCurrentMagnitude.ToPointer()));                 // call ActiveEffect.GetCurrentMagnitude

            Memory.SafeWrite <System.Byte>(ScrambledBugs.Offsets.Patches.AccumulatingMagnitude.GetMaximumMagnitude, assembly);

            /*
             * AccumulatingValueModifierEffect* accumulatingValueModifierEffect;	// rbx
             * System.Single maximumMagnitude;										// xmm0
             *
             * var maximumMagnitude = accumulatingValueModifierEffect->GetCurrentMagnitude();
             */
        }
Example #5
0
        static public UnmanagedArray <TDestination> CreateInstance <TSource>(TSource[] elements)
            where TSource : unmanaged
        {
            var array = new UnmanagedArray <TDestination>();

            array.Add(elements);

            return(array);
        }
Example #6
0
        static public void CanPowerAttack()
        {
            Trampoline.WriteRelativeCallBranch
            (
                ScrambledBugs.Offsets.Patches.PowerAttackStamina.GetStaminaCostActor,
                PowerAttackStamina.CanPowerAttack(Memory.ReadRelativeCall(ScrambledBugs.Offsets.Patches.PowerAttackStamina.GetStaminaCostActor))
            );

            var assemblyActor = new UnmanagedArray <System.Byte>();

            assemblyActor.Add(new System.Byte[2] {
                0x84, 0xC0
            });                                                                 // test al, al
            assemblyActor.Add(new System.Byte[1] {
                Assembly.Nop
            });                                                                 // nop
            assemblyActor.Add(new System.Byte[2] {
                0x74, 0x6E
            });                                                                 // jz 6E

            Memory.SafeWrite <System.Byte>(ScrambledBugs.Offsets.Patches.PowerAttackStamina.HasStaminaCostActor, assemblyActor);



            Trampoline.WriteRelativeCallBranch
            (
                ScrambledBugs.Offsets.Patches.PowerAttackStamina.GetStaminaCostPlayerCharacter,
                PowerAttackStamina.CanPowerAttack(Memory.ReadRelativeCall(ScrambledBugs.Offsets.Patches.PowerAttackStamina.GetStaminaCostPlayerCharacter))
            );

            var assemblyPlayerCharacter = new UnmanagedArray <System.Byte>();

            assemblyPlayerCharacter.Add(new System.Byte[2] {
                0x84, 0xC0
            });                                                                                 // test al, al
            assemblyPlayerCharacter.Add(new System.Byte[1] {
                Assembly.Nop
            });                                                                                 // nop
            assemblyPlayerCharacter.Add(new System.Byte[2] {
                0x75, 0x34
            });                                                                                 // jnz 34

            Memory.SafeWrite <System.Byte>(ScrambledBugs.Offsets.Patches.PowerAttackStamina.HasStaminaCostPlayerCharacter, assemblyPlayerCharacter);
        }
        static public void SetRate()
        {
            var assembly = new UnmanagedArray <System.Byte>();

            assembly.Add(new System.Byte[3] {
                0x0F, 0x28, 0xD0
            });                                                                                                                                                                                                                                                                                                                                                                                 // movaps xmm2, xmm0
            assembly.Add(new System.Byte[5] {
                0xF3, 0x0F, 0x10, 0x4F, 0x78
            });                                                                                                                                                                                                                                                                                                                                                                         // movss xmm1, [rdi+78]
            assembly.Add(new System.Byte[6] {
                0x8B, 0x8F, 0x90, 0x00, 0x00, 0x00
            });                                                                                                                                                                                                                         // mov ecx, [rdi+90]
            assembly.Add(Assembly.RelativeCall(ScrambledBugs.Offsets.Patches.AccumulatingMagnitude.SetRate, 3 + 5 + 6, Memory.ReadRelativeCall(ScrambledBugs.Offsets.Patches.AccumulatingMagnitude.SetRate, 3 + 8 + 6)));               // call AccumulatingValueModifierEffect.GetRate

            assembly.Add(new System.Byte[8] {
                0xF3, 0x0F, 0x11, 0x87, 0x9C, 0x00, 0x00, 0x00
            });                                                                                                                                                                                                                                                                                                                                                 // movss [rdi+9C], xmm0

            Memory.SafeWrite <System.Byte>(ScrambledBugs.Offsets.Patches.AccumulatingMagnitude.SetRate, assembly);

            /*
             * AccumulatingValueModifierEffect* accumulatingValueModifierEffect;	// rdi
             * System.Single magicSkill;											// xmm0
             *
             * accumulatingValueModifierEffect->MaximumMagnitude
             * (
             *      AccumulatingValueModifierEffect.GetRate
             *      (
             *              accumulatingValueModifierEffect->ActorValue(),
             *              accumulatingValueModifierEffect->Magnitude(),
             *              magicSkill
             *      )
             * );
             */
        }
        static public void IsPlayerOrTeammate()
        {
            var assembly = new UnmanagedArray <System.Byte>();

            assembly.Add(Memory.ReadArray <System.Byte>(ScrambledBugs.Offsets.Patches.TeammateDifficulty.IsPlayer, System.Runtime.CompilerServices.Unsafe.SizeOf <RelativeCall>()));            // mov edx, 18
            assembly.Add(new System.Byte[2] {
                0x74, 6 + 3 + 2 + 2
            });                                                                                                                                                                                                                                                                                                 // je B

            assembly.Add(new System.Byte[6] {
                0x8B, 0x81, 0xE0, 0x00, 0x00, 0x00
            });                                                                                                                                                                                                                                                                                 // mov eax, [rcx+E0]
            assembly.Add(new System.Byte[3] {
                0xC1, 0xE8, 0x1A
            });                                                                                                                                                                                                                                                                                                 // shr eax, 1A
            assembly.Add(new System.Byte[2] {
                0xF6, 0xD0
            });                                                                                                                                                                                                                                                                                                         // not al
            assembly.Add(new System.Byte[2] {
                0xA8, 0x01
            });                                                                                                                                                                                                                                                                                                         // test al, 1

            assembly.Add(new System.Byte[1] {
                Assembly.Ret
            });                                                                                                                                                                                                                                                                                                         // ret

            Trampoline.WriteRelativeCallBranch(ScrambledBugs.Offsets.Patches.TeammateDifficulty.IsPlayer, assembly);

            // rax
            // eflags

            // actor != null

            /*
             * Actor* actor; // rcx
             *
             * return
             *      (actor == player)
             ||
             ||     ((actor->BoolBits() & ActorBoolBits.PlayerTeammate) == ActorBoolBits.PlayerTeammate);
             */
        }
Example #9
0
        static public void ApplyCombatHitSpell()
        {
            var position = Trampoline.Reserve((7 + 4 + 4 + 2) + System.Runtime.CompilerServices.Unsafe.SizeOf <AbsoluteJump>() + 1);

            Trampoline.Write += (System.Object sender, System.EventArgs arguments) =>
            {
                var assembly = new UnmanagedArray <System.Byte>();

                assembly.Add(new System.Byte[7] {
                    0x44, 0x8B, 0x97, 0xCC, 0x01, 0x00, 0x00
                });                                                                                                                                                                                                                                                             // mov r10d, [rdi+1CC]
                assembly.Add(new System.Byte[4] {
                    0x41, 0xC1, 0xEA, 0x08
                });                                                                                                                                                                                                                                                                             // shr r10d, 8 (ProjectileFlags.Is3DLoaded)
                assembly.Add(new System.Byte[4] {
                    0x41, 0xF6, 0xC2, 0x01
                });                                                                                                                                                                                                                                                                             // test r10b, 1
                assembly.Add(new System.Byte[2] {
                    0x74, (System.Byte)System.Runtime.CompilerServices.Unsafe.SizeOf <AbsoluteJump>()
                });                                                                                                                                                                             // je E

                assembly.Add(Assembly.AbsoluteJump(Memory.ReadRelativeCall(ScrambledBugs.Offsets.Fixes.ApplySpellPerkEntryPoints.Arrows.ApplyCombatHitSpellArrowProjectile)));                  // call BGSEntryPointPerkEntry.HandleEntryPoints

                assembly.Add(new System.Byte[1] {
                    Assembly.Ret
                });                                                                                                                                                                                                                                                                                             // ret

                Memory.SafeWrite <System.Byte>(Trampoline.Address + position, assembly);
                Memory.WriteRelativeCall(ScrambledBugs.Offsets.Fixes.ApplySpellPerkEntryPoints.Arrows.ApplyCombatHitSpellArrowProjectile, (Trampoline.Address + position).ToPointer());

                // arrowProjectile != null

                /*
                 * ArrowProjectile* arrowProjectile; // rdi
                 *
                 * if ((arrowProjectile->Flags() & ProjectileFlags.Is3DLoaded) == ProjectileFlags.Is3DLoaded)
                 * {
                 *      goto Function;
                 * }
                 *
                 * return;
                 */
            };
        }
        static public void GetMaximumWardPower()
        {
            var assembly = new UnmanagedArray <System.Byte>();

            assembly.Add(new System.Byte[1] {
                0x51
            });                                                                                                                                                                                                                                                 // push rcx
            assembly.Add(new System.Byte[4] {
                0x48, 0x83, 0xEC, 0x40
            });                                                                                                                                                                                                                         // sub rsp, 40
            assembly.Add(new System.Byte[2] {
                0x48, 0xB8
            }); assembly.Add(Eggstensions.Offsets.FindMaxMagnitudeVisitor.VirtualFunctionTable);                                                                        // mov rax
            assembly.Add(new System.Byte[5] {
                0x48, 0x89, 0x44, 0x24, 0x20
            });                                                                                                                                                                                                                         // mov [rsp+20], rax
            assembly.Add(new System.Byte[2] {
                0x31, 0xC0
            });                                                                                                                                                                                                                                         // xor eax, eax
            assembly.Add(new System.Byte[5] {
                0x48, 0x89, 0x44, 0x24, 0x28
            });                                                                                                                                                                                                                         // mov [rsp+28], rax
            assembly.Add(new System.Byte[5] {
                0xB8, 0xFF, 0xFF, 0xFF, 0xFF
            });                                                                                                                                                                                                                         // mov eax, -1
            assembly.Add(new System.Byte[4] {
                0xF3, 0x0F, 0x2A, 0xC0
            });                                                                                                                                                                                                                         // cvtsi2ss xmm0, eax
            assembly.Add(new System.Byte[6] {
                0xF3, 0x0F, 0x11, 0x44, 0x24, 0x30
            });                                                                                                                                                                                                                 // movss [rsp+30], xmm0
            assembly.Add(new System.Byte[5] {
                0x48, 0x8D, 0x54, 0x24, 0x20
            });                                                                                                                                                                                                                         // lea rdx, [rsp+20]
            assembly.Add(new System.Byte[7] {
                0x48, 0x81, 0xC1, 0x98, 0x00, 0x00, 0x00
            });                                                                                                                                                                                 // add rcx, 98
            assembly.Add(Assembly.AbsoluteCall(Eggstensions.Offsets.MagicTarget.VisitActiveEffects.ToPointer()));                                                                               // call MagicTarget.VisitActiveEffects

            assembly.Add(new System.Byte[6] {
                0xF3, 0x0F, 0x10, 0x4C, 0x24, 0x30
            });                                                                                                                                                                                                                 // movss xmm1, [rsp+30]
            assembly.Add(new System.Byte[5] {
                0x48, 0x8B, 0x4C, 0x24, 0x40
            });                                                                                                                                                                                         // mov rcx, [rsp+40]
            assembly.Add(Assembly.AbsoluteCall(Eggstensions.Offsets.Actor.SetMaximumWardPower.ToPointer()));                                                                                            // call Actor.SetMaximumWardPower

            assembly.Add(new System.Byte[5] {
                0x48, 0x8B, 0x4C, 0x24, 0x40
            });                                                                                                                                                 // mov rcx, [rsp+40]
            assembly.Add(Assembly.AbsoluteCall(Memory.ReadRelativeCall(ScrambledBugs.Offsets.Patches.AccumulatingMagnitude.GetMaximumWardPower)));              // call Actor.GetMaximumWardPower

            assembly.Add(new System.Byte[4] {
                0x48, 0x83, 0xC4, 0x48
            });                                                                                                                                                                                                                         // add rsp, 48
            assembly.Add(new System.Byte[1] {
                Assembly.Ret
            });                                                                                                                                                                                                                                         // ret

            Trampoline.WriteRelativeCallBranch(ScrambledBugs.Offsets.Patches.AccumulatingMagnitude.GetMaximumWardPower, assembly);

            /*
             * Actor* actor; // rcx
             *
             * var findMaxMagnitudeVisitor						= new FindMaxMagnitudeVisitor();
             *(System.IntPtr*)&findMaxMagnitudeVisitor		= Eggstensions.Offsets.FindMaxMagnitudeVisitor.VirtualFunctionTable;
             * findMaxMagnitudeVisitor.FinishedActiveEffect	= null;
             * findMaxMagnitudeVisitor.MaximumMagnitude		= -1.0F;
             *
             * actor->MagicTarget()->VisitActiveEffects(&findMaxMagnitudeVisitor);
             * actor->SetMaximumWardPower(findMaxMagnitudeVisitor.MaximumMagnitude);
             *
             * return actor->GetMaximumWardPower();
             */
        }
Example #11
0
        static public void UpdateConditions()
        {
            var assembly = new UnmanagedArray <System.Byte>();

            assembly.Add(new System.Byte[3] {
                0x0F, 0x57, 0xC0
            });                                                                                                                                                                                                                                                                 // xorps xmm0, xmm0
            assembly.Add(new System.Byte[3] {
                0x0F, 0x2F, 0xC8
            });                                                                                                                                                                                                                                                                 // comiss xmm1, xmm0
            assembly.Add(new System.Byte[2] {
                0x77, 5 + 8
            });                                                                                                                                                                                                                                                                         // ja D (elapsedTime <= 0.0F)

            assembly.Add(new System.Byte[8] {
                0xF3, 0x0F, 0x11, 0xB7, 0x8C, 0x00, 0x00, 0x00
            });                                                                                                                                                                                                                                 // movss [rdi+8C], xmm6 (padding8C = frameTime)
            assembly.Add(new System.Byte[5] {
                0xE9, 0x6C - ((3 + 3 + 2) + (8 + 5)) + 0x87, 0x00, 0x00, 0x00
            });                                                                                                                                                                                                                         // jmp DE (Skip)

            assembly.Add(new System.Byte[8] {
                0xF3, 0x0F, 0x10, 0x97, 0x8C, 0x00, 0x00, 0x00
            });                                                                                                                                                                                                                                 // movss xmm2, [rdi+8C]
            assembly.Add(new System.Byte[3] {
                0x0F, 0x2F, 0xD0
            });                                                                                                                                                                                                                                                                 // comiss xmm2, xmm0
            assembly.Add(new System.Byte[2] {
                0x76, (5 + 4 + 4 + 3 + 2) + (4 + 8 + 5)
            });                                                                                                                                                                                                                                         // jna 23 (padding8C > 0.0F)

            assembly.Add(new System.Byte[5] {
                0xB9, 0x01, 0x00, 0x00, 0x00
            });                                                                                                                                                                                                                                                         // mov ecx, 1
            assembly.Add(new System.Byte[4] {
                0xF3, 0x0F, 0x2A, 0xC1
            });                                                                                                                                                                                                                                                         // cvtsi2ss xmm0, ecx
            assembly.Add(new System.Byte[4] {
                0xF3, 0x0F, 0x5E, 0xC3
            });                                                                                                                                                                                                                                                         // divss xmm0,xmm3
            assembly.Add(new System.Byte[3] {
                0x0F, 0x2F, 0xC2
            });                                                                                                                                                                                                                                                                 // comiss xmm0, xmm2
            assembly.Add(new System.Byte[2] {
                0x76, (4 + 8 + 5)
            });                                                                                                                                                                                                                                                                 // jna 11 (activeEffectConditionUpdateInterval > padding8C)

            assembly.Add(new System.Byte[4] {
                0xF3, 0x0F, 0x58, 0xD6
            });                                                                                                                                                                                                                                                         // addss xmm2, xmm6
            assembly.Add(new System.Byte[8] {
                0xF3, 0x0F, 0x11, 0x97, 0x8C, 0x00, 0x00, 0x00
            });                                                                                                                                                                                                                                 // movss [rdi+8C], xmm2 (padding8C += frameTime)
            assembly.Add(new System.Byte[5] {
                0xE9, 0x6C - ((3 + 3 + 2) + (8 + 5) + (8 + 3 + 2) + (5 + 4 + 4 + 3 + 2) + (4 + 8 + 5)) + 0x87, 0x00, 0x00, 0x00
            });                                                                                                                                                                 // jmp AE (Skip)

            assembly.Add(new System.Byte[8] {
                0xF3, 0x0F, 0x11, 0xB7, 0x8C, 0x00, 0x00, 0x00
            });                                                                                                                                                                                                                                 // movss [rdi+8C], xmm6 (padding8C = frameTime)
            assembly.Add(new System.Byte[2] {
                0xEB, 0x6C - ((3 + 3 + 2) + (8 + 5) + (8 + 3 + 2) + (5 + 4 + 4 + 3 + 2) + (4 + 8 + 5) + (8 + 2))
            });                                                                                                                                                                                 // jmp 1D (Update)

            Memory.SafeFill <System.Byte>(ScrambledBugs.Offsets.Fixes.MagicEffectConditions.UpdateConditions, 0x6C, Assembly.Nop);
            Memory.SafeWrite <System.Byte>(ScrambledBugs.Offsets.Fixes.MagicEffectConditions.UpdateConditions, assembly);

            // ecx
            // eflags
            // xmm0
            // xmm2

            // activeEffect != null

            /*
             * ActiveEffect* activeEffect;							// rdi
             * System.Single elapsedTime;							// xmm1
             * System.Single activeEffectConditionUpdateFrequency;	// xmm3
             * System.Single frameTime;							// xmm6
             *
             * if (elapsedTime <= 0.0F)
             * {
             *      activeEffect->Padding8C(frameTime);
             *
             *      goto Skip;
             * }
             *
             * System.Single padding8C = activeEffect->Padding8C();
             *
             * if (padding8C > 0.0F)
             * {
             *      System.Single activeEffectConditionUpdateInterval = 1.0F / activeEffectConditionUpdateFrequency;
             *
             *      if (padding8C < activeEffectConditionUpdateInterval)
             *      {
             *              activeEffect->Padding8C(padding8C + frameTime);
             *
             *              goto Skip;
             *      }
             * }
             *
             * activeEffect->Padding8C(frameTime);
             *
             * goto Update;
             */
        }
Example #12
0
        static public System.Byte[] CanPowerAttack(void *getStaminaCost)
        {
            var assembly = new UnmanagedArray <System.Byte>();

            assembly.Add(new System.Byte[1] {
                0x51
            });                                                                                                                                         // push rcx
            assembly.Add(new System.Byte[4] {
                0x48, 0x83, 0xEC, 0x20
            });                                                                                                                 // sub rsp, 20
            assembly.Add(Assembly.AbsoluteCall(getStaminaCost));                                                                // call ActorValueOwner.GetStaminaCost

            assembly.Add(new System.Byte[3] {
                0x0F, 0x57, 0xC9
            });                                                                                                                         // xorps xmm1, xmm1
            assembly.Add(new System.Byte[3] {
                0x0F, 0x2F, 0xC1
            });                                                                                                                         // comiss xmm0, xmm1
            assembly.Add(new System.Byte[2] {
                0x76, (5 + 5 + 3 + 6 + 3) + (5 + 2) + (2 + 2)
            });                                                                                                 // jbe 21

            assembly.Add(new System.Byte[5] {
                0xBA, 0x1A, 0x00, 0x00, 0x00
            });                                                                                                                 // mov edx, 1A
            assembly.Add(new System.Byte[5] {
                0x48, 0x8B, 0x4C, 0x24, 0x20
            });                                                                                                                 // mov rcx, [rsp+20]
            assembly.Add(new System.Byte[3] {
                0x48, 0x8B, 0x01
            });                                                                                                                         // mov rax, [rcx]
            assembly.Add(new System.Byte[6] {
                0xF3, 0x0F, 0x11, 0x44, 0x24, 0x20
            });                                                                                                         // movss [rsp+20], xmm0
            assembly.Add(new System.Byte[3] {
                0xFF, 0x50, 0x08
            });                                                                                                                         // call [rax+8] (ActorValueOwner.GetActorValue)

            assembly.Add(new System.Byte[5] {
                0x0F, 0x2F, 0x44, 0x24, 0x20
            });                                                                                                                 // comiss xmm0, [rsp+20]
            assembly.Add(new System.Byte[2] {
                0x73, 2 + 2
            });                                                                                                                                 // jae 4

            assembly.Add(new System.Byte[2] {
                0x31, 0xC0
            });                                                                                                                                 // xor eax, eax
            assembly.Add(new System.Byte[2] {
                0xEB, 0x05
            });                                                                                                                                 // jmp 5

            assembly.Add(new System.Byte[5] {
                0xB8, 0x01, 0x00, 0x00, 0x00
            });                                                                                                                 // mov eax, 1

            assembly.Add(new System.Byte[4] {
                0x48, 0x83, 0xC4, 0x28
            });                                                                                                                 // add rsp, 28
            assembly.Add(new System.Byte[1] {
                Assembly.Ret
            });                                                                                                                                 // ret

            return(assembly);

            /*
             * ActorValueOwner* actorValueOwner;	// rcx
             * BGSAttackData* attackData;			// rdx
             *
             * var staminaCost = actorValueOwner->GetStaminaCost(attackData);
             *
             * if (staminaCost <= 0.0F)
             * {
             *      return true;
             * }
             *
             * var stamina = actorValueOwner->GetActorValue(ActorValue.Stamina);
             *
             * if (stamina >= staminaCost)
             * {
             *      return true;
             * }
             *
             * return false;
             */
        }
Example #13
0
        static public void ShouldAttach()
        {
            var assemblyBranch = new UnmanagedArray <System.Byte>();

            assemblyBranch.Add(new System.Byte[2] {
                0x41, 0x54
            });                                                                                                                         // push r12
            assemblyBranch.Add(new System.Byte[2] {
                0x41, 0x55
            });                                                                                                                         // push r13
            assemblyBranch.Add(new System.Byte[4] {
                0x48, 0x83, 0xEC, 0x28
            });                                                                                                                 // sub rsp, 28
            assemblyBranch.Add(new System.Byte[4] {
                0x48, 0x8B, 0x4E, 0x30
            });                                                                                                                 // mov rcx, [rsi+30] (modelReferenceEffect->Controller)
            assemblyBranch.Add(new System.Byte[3] {
                0x48, 0x8B, 0x01
            });                                                                                                                 // mov rax, [rcx]
            assemblyBranch.Add(new System.Byte[3] {
                0xFF, 0x50, 0x78
            });                                                                                                                 // call [rax+78] (ReferenceEffectController.GetAttachRoot(controller))
            assemblyBranch.Add(new System.Byte[3] {
                0x48, 0x85, 0xC0
            });                                                                                                                 // test rax, rax (attachRoot)
            assemblyBranch.Add(new System.Byte[2] {
                0x75, 3 + 3 + 6
            });                                                                                                                         // jnz C (attachRoot == null)

            assemblyBranch.Add(new System.Byte[3] {
                0x48, 0x8B, 0xCB
            });                                                                                                                 // mov rcx, rbx (actor)
            assemblyBranch.Add(new System.Byte[3] {
                0x48, 0x8B, 0x01
            });                                                                                                                 // mov rax, [rcx]
            assemblyBranch.Add(new System.Byte[6] {
                0xFF, 0x90, 0x68, 0x04, 0x00, 0x00
            });                                                                                                 // call [rax+468] (TESObjectREFR.GetCurrent3D(actor))

            assemblyBranch.Add(new System.Byte[3] {
                0x45, 0x31, 0xE4
            });                                                                                                                 // xor r12d, r12d (attachRootNode)
            assemblyBranch.Add(new System.Byte[3] {
                0x48, 0x85, 0xC0
            });                                                                                                                 // test rax, rax
            assemblyBranch.Add(new System.Byte[2] {
                0x74, (3 + 3 + 3 + 3 + 3 + 3 + 2) + 4
            });                                                                                                 // jz 18 (attachRoot != null)

            assemblyBranch.Add(new System.Byte[3] {
                0x4C, 0x8B, 0xE8
            });                                                                                                                 // mov r13, rax
            assemblyBranch.Add(new System.Byte[3] {
                0x48, 0x8B, 0xC8
            });                                                                                                                 // mov rcx, rax
            assemblyBranch.Add(new System.Byte[3] {
                0x48, 0x8B, 0x01
            });                                                                                                                 // mov rax, [rcx]
            assemblyBranch.Add(new System.Byte[3] {
                0xFF, 0x50, 0x18
            });                                                                                                                 // call [rax+18] (NiObject.AsNode(attachRoot))
            assemblyBranch.Add(new System.Byte[3] {
                0x4C, 0x8B, 0xE0
            });                                                                                                                 // mov r12, rax
            assemblyBranch.Add(new System.Byte[3] {
                0x4D, 0x85, 0xE4
            });                                                                                                                 // test r12, r12
            assemblyBranch.Add(new System.Byte[2] {
                0x75, 4
            });                                                                                                                                 // jnz 4 (attachRootNode == null)

            assemblyBranch.Add(new System.Byte[4] {
                0x4D, 0x8B, 0x65, 0x30
            });                                                                                                                 // mov r12, [r13+30] (attachRoot->Parent)

            assemblyBranch.Add(new System.Byte[4] {
                0x4C, 0x3B, 0x66, 0x70
            });                                                                                                                 // cmp r12, [rsi+70]
            assemblyBranch.Add(new System.Byte[3] {
                0x0F, 0x95, 0xC0
            });                                                                                                                 // setne al (attachRootNode != modelReferenceEffect->HitEffectArtData.AttachRoot)
            assemblyBranch.Add(new System.Byte[4] {
                0x48, 0x83, 0xC4, 0x28
            });                                                                                                                 // add rsp, 28
            assemblyBranch.Add(new System.Byte[2] {
                0x41, 0x5D
            });                                                                                                                         // pop r13
            assemblyBranch.Add(new System.Byte[2] {
                0x41, 0x5C
            });                                                                                                                         // pop r12
            assemblyBranch.Add(new System.Byte[1] {
                Assembly.Ret
            });                                                                                                                         // ret

            Trampoline.WriteRelativeCallBranch(ScrambledBugs.Offsets.Patches.AttachHitEffectArt.IsPlayerAttach, assemblyBranch);

            // Volatile registers

            // actor							!= null
            // modelReferenceEffect				!= null
            // modelReferenceEffect->Controller	!= null

            /*
             * ModelReferenceEffect* modelReferenceEffect;	// rsi
             * Actor* actor;								// rbx
             *
             * ReferenceEffectController* controller	= modelReferenceEffect->Controller();
             * NiAVObject* attachRoot					= controller->GetAttachRoot();
             *
             * if (attachRoot == null)
             * {
             *      attachRoot = actor->GetCurrent3D();
             * }
             *
             * NiNode* attachRootNode = null;
             *
             * if (attachRoot != null)
             * {
             *      attachRootNode = attachRoot->AsNode();
             *
             *      if (attachRootNode == null)
             *      {
             *              attachRootNode = attachRoot->Parent();
             *      }
             * }
             *
             * return attachRootNode != modelReferenceEffect->HitEffectArtData()->AttachRoot();
             */



            var assembly = new UnmanagedArray <System.Byte>();

            assembly.Add(new System.Byte[2] {
                0x84, 0xC0
            });                                                          // test al, al
            assembly.Add(new System.Byte[2] {
                0x74, 0x55
            });                                                          // jz 55

            Memory.SafeWrite <System.Byte>(ScrambledBugs.Offsets.Patches.AttachHitEffectArt.IsPlayerAttach, System.Runtime.CompilerServices.Unsafe.SizeOf <RelativeCall>(), assembly);
        }
Example #14
0
        static public void ShouldUpdate()
        {
            var assembly = new UnmanagedArray <System.Byte>();

            assembly.Add(new System.Byte[1] {
                0x52
            });                                                                                                                         // push rdx
            assembly.Add(new System.Byte[2] {
                0x8B, 0xD0
            });                                                                                                                 // mov edx, eax
            assembly.Add(new System.Byte[3] {
                0xC1, 0xEA, 0x07
            });                                                                                                         // shr edx, 7 (ActiveEffectFlags.HasConditions)
            assembly.Add(new System.Byte[3] {
                0xF6, 0xC2, 0x01
            });                                                                                                         // test dl, 1
            assembly.Add(new System.Byte[2] {
                0x75, (2 + 3 + 3 + 2) + (2 + 3 + 3)
            });                                                                                         // jne 12

            assembly.Add(new System.Byte[2] {
                0x8B, 0xD0
            });                                                                                                                 // mov edx, eax
            assembly.Add(new System.Byte[3] {
                0xC1, 0xEA, 0x05
            });                                                                                                         // shr edx, 5 (ActiveEffectFlags.ApplyingVisualEffects)
            assembly.Add(new System.Byte[3] {
                0xF6, 0xC2, 0x01
            });                                                                                                         // test dl, 1
            assembly.Add(new System.Byte[2] {
                0x75, 2 + 3 + 3
            });                                                                                                         // jne 8

            assembly.Add(new System.Byte[2] {
                0x8B, 0xD0
            });                                                                                                                 // mov edx, eax
            assembly.Add(new System.Byte[3] {
                0xC1, 0xEA, 0x06
            });                                                                                                         // shr edx, 6 (ActiveEffectFlags.ApplyingSoundEffects)
            assembly.Add(new System.Byte[3] {
                0xF6, 0xC2, 0x01
            });                                                                                                         // test dl, 1

            assembly.Add(new System.Byte[1] {
                0x5A
            });                                                                                                                         // pop rdx
            assembly.Add(new System.Byte[1] {
                Assembly.Ret
            });                                                                                                                 // ret

            Trampoline.WriteRelativeCallBranch(ScrambledBugs.Offsets.Fixes.HitEffectRaceCondition.ShouldUpdate, assembly);

            // eflags

            /*
             * ActiveEffectFlags flags; // ecx
             *
             * return
             *      ((flags & ActiveEffectFlags.Dispelled) == ActiveEffectFlags.Dispelled)
             ||
             ||     ((flags & ActiveEffectFlags.ApplyingVisualEffects) == ActiveEffectFlags.ApplyingVisualEffects)
             ||
             ||     ((flags & ActiveEffectFlags.ApplyingSoundEffects) == ActiveEffectFlags.ApplyingSoundEffects);
             */
        }