Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 60 additions & 4 deletions EEex/copy/EEex_scripts/EEex_Opcode_Patch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,56 @@
-- Opcode Changes --
--------------------------------------

--[[
+-----------------------------------------------------------------------------------------------------------+
| Opcode #73 |
+-----------------------------------------------------------------------------------------------------------+
| special bit0 -> Apply to main-hand damage bonus only |
| special bit1 -> Apply to off-hand damage bonus only |
| special 0 or both bits -> Vanilla opcode #73 behavior |
+-----------------------------------------------------------------------------------------------------------+
| [EEex.dll] EEex::Opcode_Hook_DamageMod_ApplyEffect(pEffect: CGameEffect*, pSprite: CGameSprite*) -> int |
| return: |
| -> 0 - Don't alter engine behavior |
| -> !0 - Effect was handled |
+-----------------------------------------------------------------------------------------------------------+
--]]

EEex_HookBeforeRestoreWithLabels(EEex_Label("Hook-CGameEffectDamageMod::ApplyEffect()-FirstInstruction"), 0, 7, 7, {
{"stack_mod", 8},
{"hook_integrity_watchdog_ignore_registers", {
EEex_HookIntegrityWatchdogRegister.RAX, EEex_HookIntegrityWatchdogRegister.R8, EEex_HookIntegrityWatchdogRegister.R9,
EEex_HookIntegrityWatchdogRegister.R10, EEex_HookIntegrityWatchdogRegister.R11
}}},
{[[
#MAKE_SHADOW_SPACE(16)
mov qword ptr ss:[rsp+#SHADOW_SPACE_BOTTOM(-8)], rcx
mov qword ptr ss:[rsp+#SHADOW_SPACE_BOTTOM(-16)], rdx

; rcx already pEffect
; rdx already pSprite
call #L(EEex::Opcode_Hook_DamageMod_ApplyEffect)

mov rdx, qword ptr ss:[rsp+#SHADOW_SPACE_BOTTOM(-16)]
mov rcx, qword ptr ss:[rsp+#SHADOW_SPACE_BOTTOM(-8)]
#DESTROY_SHADOW_SPACE

test eax, eax
jz #L(return)

mov eax, 1
#MANUAL_HOOK_EXIT(1)
ret
]]}
)

-- Manually define the ignored registers for the unusual `ret` above
EEex_HookIntegrityWatchdog_IgnoreRegistersForInstance(EEex_Label("Hook-CGameEffectDamageMod::ApplyEffect()-FirstInstruction"), 1, {
EEex_HookIntegrityWatchdogRegister.RAX, EEex_HookIntegrityWatchdogRegister.RCX, EEex_HookIntegrityWatchdogRegister.RDX,
EEex_HookIntegrityWatchdogRegister.R8, EEex_HookIntegrityWatchdogRegister.R9, EEex_HookIntegrityWatchdogRegister.R10,
EEex_HookIntegrityWatchdogRegister.R11
})

--[[
+------------------------------------------------------------------------------------+
| Opcode #146 |
Expand Down Expand Up @@ -580,11 +630,17 @@
| param2 == 5 -> Override `combat_round_<param1>` in animation INI to `resource`: |
| param1 -> Combat round slot |
| resource -> Resref of RNDBASE*-like .BMP |
| special bit0 -> Tag repeated offhand frame type 11 attacks for THAC0 adjustment |
| param3 -> Direct THAC0 delta for tagged repeated offhand attacks |
+------------------------------------------------------------------------------------------------------+
| [EEex.dll] EEex::Opcode_Hook_Op342_OnUnhandledParam2(pEffect: CGameEffect*, pSprite: CGameSprite*) |
| |
| [EEex.dll] EEex::Sprite_Hook_OnGetAttackFrameType(pSprite: CGameSprite*, numAttacks: byte) -> byte |
| return: Palette index of fetched pixel in RNDBASE*-like .BMP |
| [EEex.dll] EEex::Sprite_Hook_OnSwingGetAttackFrameType( |
| pSprite: CGameSprite*, numAttacks: byte |
| ) -> byte |
| return: Palette index of fetched pixel in RNDBASE*-like .BMP |
+------------------------------------------------------------------------------------------------------+
--]]

Expand All @@ -601,7 +657,7 @@
]]}
)

local patchGetAttackFrameType = function(label, spriteRegister)
local patchGetAttackFrameType = function(label, spriteRegister, hookLabel)
EEex_HookNOPsWithLabels(EEex_Label(label), 1, {
{"hook_integrity_watchdog_ignore_registers", {
EEex_HookIntegrityWatchdogRegister.RAX, EEex_HookIntegrityWatchdogRegister.RCX, EEex_HookIntegrityWatchdogRegister.RDX,
Expand All @@ -611,13 +667,13 @@
{[[
mov rcx, #$(1) ]], {spriteRegister}, [[ #ENDL ; pSprite
; dl already numAttacks
call #L(EEex::Sprite_Hook_OnGetAttackFrameType)
call #L(]] .. hookLabel .. [[)
]]}
)
end

patchGetAttackFrameType("Hook-CGameSprite::OneSwing()-GetAttackFrameType()", "rdi")
patchGetAttackFrameType("Hook-CGameSprite::Swing()-GetAttackFrameType()", "rbx")
patchGetAttackFrameType("Hook-CGameSprite::OneSwing()-GetAttackFrameType()", "rdi", "EEex::Sprite_Hook_OnGetAttackFrameType")
patchGetAttackFrameType("Hook-CGameSprite::Swing()-GetAttackFrameType()", "rbx", "EEex::Sprite_Hook_OnSwingGetAttackFrameType")

--[[
+------------------------------------------------------------------------------------------------+
Expand Down
23 changes: 23 additions & 0 deletions EEex/copy/EEex_scripts/EEex_Sprite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,29 @@ function EEex_Sprite_GetActiveStats(sprite)
end
CGameSprite.getActiveStats = EEex_Sprite_GetActiveStats

-- @bubb_doc { EEex_Sprite_GetWeaponStyle / instance_name=getWeaponStyle }
--
-- @summary:
--
-- Returns the given ``sprite``'s currently active weapon style, the active rank for that style, and the original
-- rank recorded on the creature before active stat and effect modification.
--
-- ``style`` is the engine stat id for the active weapon style. For example, the two-weapon style is
-- ``PROFICIENCY2WEAPON``.
--
-- If ``sprite`` is invalid, returns ``-1``, ``0``, and ``0`` respectively.
--
-- @self { sprite / type=CGameSprite }: The sprite whose weapon style is being fetched.
--
-- @return { type=number }: First return value; the active weapon style stat id.
-- @return { type=number }: Second return value; the active rank for ``style`` after derived-stat effects are applied.
-- @return { type=number }: Third return value; the original rank for ``style`` from the engine's inactive proficiency value.

function EEex_Sprite_GetWeaponStyle(sprite)
return EEex.GetWeaponStyle(sprite)
end
CGameSprite.getWeaponStyle = EEex_Sprite_GetWeaponStyle

-- @bubb_doc { EEex_Sprite_GetExtendedStat / instance_name=getExtendedStat }
-- @deprecated: Use ``EEex_Sprite_GetStat()`` instead.
-- @summary: Returns the value of the extended stat on the given ``sprite``.
Expand Down
85 changes: 85 additions & 0 deletions EEex/copy/EEex_scripts/EEex_Sprite_Patch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,50 @@
EEex_HookIntegrityWatchdogRegister.R11
})

local adjustDisplayedDamage = function(label)
EEex_HookBeforeRestoreWithLabels(EEex_Label(label), 0, 7, 7, {
{"hook_integrity_watchdog_ignore_registers", {
EEex_HookIntegrityWatchdogRegister.RAX, EEex_HookIntegrityWatchdogRegister.RCX, EEex_HookIntegrityWatchdogRegister.RDX,
EEex_HookIntegrityWatchdogRegister.R8, EEex_HookIntegrityWatchdogRegister.R9, EEex_HookIntegrityWatchdogRegister.R10,
EEex_HookIntegrityWatchdogRegister.R11
}}},
{[[
mov r9d, dword ptr ss:[rsp+0xF8] ; saved hand argument
#MAKE_SHADOW_SPACE
mov rcx, rdi ; pSprite
mov rdx, r13 ; pItem
mov r8d, eax ; displayed damage
call #L(EEex::Sprite_Hook_AdjustDisplayedDamage)
#DESTROY_SHADOW_SPACE
]]}
)
end

adjustDisplayedDamage("Hook-CGameSprite::GetMaxDamage()-AdjustDisplayedDamage")
adjustDisplayedDamage("Hook-CGameSprite::GetMinDamage()-AdjustDisplayedDamage")

EEex_HookBeforeCallWithLabels(EEex_Label("Hook-CGameSprite::Damage()-AdjustRollHandBonus"), {
{"hook_integrity_watchdog_ignore_registers", {
EEex_HookIntegrityWatchdogRegister.RAX, EEex_HookIntegrityWatchdogRegister.RCX, EEex_HookIntegrityWatchdogRegister.RDX,
EEex_HookIntegrityWatchdogRegister.R8, EEex_HookIntegrityWatchdogRegister.R9, EEex_HookIntegrityWatchdogRegister.R10,
EEex_HookIntegrityWatchdogRegister.R11
}}},
{[[
#MAKE_SHADOW_SPACE(24)
mov qword ptr ss:[rsp+#SHADOW_SPACE_BOTTOM(-8)], rcx
mov qword ptr ss:[rsp+#SHADOW_SPACE_BOTTOM(-16)], rdx
mov qword ptr ss:[rsp+#SHADOW_SPACE_BOTTOM(-24)], r9
mov edx, r8d ; handBonus
mov rcx, rdi ; pSprite
call #L(EEex::Sprite_Hook_AdjustDamageRollHandBonus)
mov r8d, eax
mov r9, qword ptr ss:[rsp+#SHADOW_SPACE_BOTTOM(-24)]
mov rdx, qword ptr ss:[rsp+#SHADOW_SPACE_BOTTOM(-16)]
mov rcx, qword ptr ss:[rsp+#SHADOW_SPACE_BOTTOM(-8)]
#DESTROY_SHADOW_SPACE
]]}
)

--[[
+---------------------------------------------------------------------------------------------------------------------------------+
| Implement X-CLSERG.2DA - Ignore the -8 thac0 penalty characters incur when meleeing with a ranged weapon for specific |
Expand Down Expand Up @@ -763,6 +807,47 @@
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
--]]

--[[
+-------------------------------------------------------------------------------------------------------------+
| Implement opcode #342 special BIT0 repeated-offhand THAC0 tagging |
+-------------------------------------------------------------------------------------------------------------+
| [EEex.dll] EEex::Sprite_Hook_ApplyOp342OffhandFrame(pSprite: CGameSprite*) |
| Promotes the tagged repeated offhand frame into a real offhand damage frame. |
| [EEex.dll] EEex::Sprite_Hook_GetOp342OffhandTHAC0(pSprite: CGameSprite*, thac0: int) -> int |
| Applies the queued opcode #342 THAC0 delta only to the tagged repeated offhand attack roll. |
+-------------------------------------------------------------------------------------------------------------+
--]]

EEex_HookBeforeRestoreWithLabels(EEex_Label("Hook-CGameSprite::Swing()-Op342OffhandFrame"), 0, 5, 5, {
{"hook_integrity_watchdog_ignore_registers", {
EEex_HookIntegrityWatchdogRegister.RAX, EEex_HookIntegrityWatchdogRegister.RCX, EEex_HookIntegrityWatchdogRegister.RDX,
EEex_HookIntegrityWatchdogRegister.R8, EEex_HookIntegrityWatchdogRegister.R9, EEex_HookIntegrityWatchdogRegister.R10,
EEex_HookIntegrityWatchdogRegister.R11
}}},
{[[
#MAKE_SHADOW_SPACE
mov rcx, rbx ; pSprite
call #L(EEex::Sprite_Hook_ApplyOp342OffhandFrame)
#DESTROY_SHADOW_SPACE
]]}
)

EEex_HookBeforeRestoreWithLabels(EEex_Label("Hook-CGameSprite::Hit()-FinalTHAC0Compare"), 0, 5, 5, {
{"hook_integrity_watchdog_ignore_registers", {
EEex_HookIntegrityWatchdogRegister.RAX, EEex_HookIntegrityWatchdogRegister.RCX, EEex_HookIntegrityWatchdogRegister.RDX,
EEex_HookIntegrityWatchdogRegister.R8, EEex_HookIntegrityWatchdogRegister.R9, EEex_HookIntegrityWatchdogRegister.R10,
EEex_HookIntegrityWatchdogRegister.R11
}}},
{[[
#MAKE_SHADOW_SPACE
mov rcx, rbx ; pSprite
movsx edx, r15w ; final THAC0 accumulator
call #L(EEex::Sprite_Hook_GetOp342OffhandTHAC0)
mov r15w, ax
#DESTROY_SHADOW_SPACE
]]}
)

--[[
+-------------------------------------------------------------------------------------------------------------+
| Implement EEex_Sprite_AddAlterBaseWeaponDamageListener() - Lua listeners that can alter base weapon damage |
Expand Down
36 changes: 36 additions & 0 deletions EEex/loader/InfinityLoader.db
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ Pattern=48895C24105556574154415541564157488D6C24F9
Pattern=488D81C81D0000C3
Operations=ADD -16

[CGameSprite::GetActiveWeaponStyleAndLevel]
Pattern=4883EC300FB681F8100000
Operations=ADD -22

[CGameSprite::GetInactiveProficiency]
Pattern=83F82D7728
Operations=ADD -10

[CGameSprite::GetCasterLevel]
Pattern=48895C2418555741564883EC30

Expand Down Expand Up @@ -370,6 +378,10 @@ Operations=ADD -6
Pattern=41554157488D6C24D0
Operations=ADD -4

[CGameSprite::Swing]
Pattern=664183FC027507
Operations=ADD -7

[CGameSprite::UpdateTarget]
Pattern=488BD94885D2740F
Operations=ADD -13
Expand Down Expand Up @@ -2215,6 +2227,10 @@ Operations=ADD 23
Pattern=3881F81000007407
Operations=ADD 56

[Hook-CGameEffectDamageMod::ApplyEffect()-FirstInstruction]
Pattern=40534883EC208B4120
Operations=ADD -112

[Hook-CGameEffectForceSurge::ApplyEffect()-FirstInstruction]
Pattern=898248130000
Operations=ADD -3
Expand Down Expand Up @@ -2340,6 +2356,18 @@ Operations=ADD -8
Pattern=03457F894577
Operations=ADD -8

[Hook-CGameSprite::GetMaxDamage()-AdjustDisplayedDamage]
Pattern=4C8BC88B5010
Operations=ADD 81

[Hook-CGameSprite::GetMinDamage()-AdjustDisplayedDamage]
Pattern=83EA0C7416
Operations=ADD 51

[Hook-CGameSprite::Damage()-AdjustRollHandBonus]
Pattern=488D542448488D4DBF
Operations=ADD -12

[Hook-CGameSprite::GetRatingWithItem()-CGameSprite::Copy()]
Pattern=410FB69D283A0000
Operations=ADD 38
Expand All @@ -2360,6 +2388,10 @@ Operations=ADD 18
Pattern=2BF90FAFC0
Operations=ADD 9

[Hook-CGameSprite::Hit()-FinalTHAC0Compare]
Pattern=66443B7D48
Operations=ADD 0

[Hook-CGameSprite::IsOver()-B3Invis]
Pattern=3843387627
Operations=ADD 3
Expand Down Expand Up @@ -2464,6 +2496,10 @@ Operations=ADD 36
Pattern=488983D84A00004439B3A44E0000
Operations=ADD 75

[Hook-CGameSprite::Swing()-Op342OffhandFrame]
Pattern=0FBF073BC8
Operations=ADD 53

[Hook-CGameSprite::Swing()-NoCImmunitiesWeaponElseContinue]
Pattern=418B47484D8D6F0C
Operations=ADD 41
Expand Down