Jump to content


Photo

[RESOLVED] Spell protections bug


  • Please log in to reply
60 replies to this topic

#21 Suslik

Suslik

    Investigator

  • Member
  • 500 posts

Posted 01 January 2012 - 02:37 PM

nice work Suslik

I think this is the laziest solution:

// set the HEAP_ZERO_MEMORY flag for calls to HeapAlloc
BACKUP ~blah_backup~
AUTHOR ~blah~
README ~~
VERSION ~v0~

BEGIN ~tob_spell_turning_workaround~
	COPY ~bgmain.exe~ ~bgmain.exe~ 
		WRITE_BYTE "0x0063951B" 0x08
		WRITE_BYTE "0x0063AE6E" 0x08
		WRITE_BYTE "0x00640E4B" 0x08

Hey, it worked too! So my assumption that the bug is caused by uninitialized memory was correct! Awesome, thanks for the info, i suppose this solution is better than my workaround for doing the same thing the hard way, hehe.

#22 Suslik

Suslik

    Investigator

  • Member
  • 500 posts

Posted 06 January 2012 - 04:22 PM

Hey Asc64. I've been working again on that problem about spell reflection animation. Not the problem about spells being consumed instead of being reflected(that problem was really solved in this thread by starting debug BGMain in TobExLoader / setting ZERO_HEAP_MEMORY flags), but about that spsturni.bam animation which should appear when a spell is being reflected but it does not.

I was investigating the problem in this thread for a while already: http://forums.gibber...showtopic=23754

I know you are a busy man and all and i'll try to summarize the info i currently have for you:

- Instead of being played normally, only the first frame of animation spsturni.bam appears in vanilla ToB game whenever a spell is reflected.
- The animation is played perfectly in vanilla SoA(without ToB)
- If I replace SoA's BGMain.exe with ToB's one it gets really glitchy due to lack of ToB's resources but I can load SoA's savegame with ToB's BGMain.exe and there is no reflection animation(only first frame again).

So I suggest that ToB's BGMain.exe fires spsturni.bam somehow wrong and only the first frame is played. SoA's BGMain.exe does it right on the other hand. If I am more or less able to debug ToB's executable(i know necessary function offsets), but i cannot do it with SoA's binary.

My question to you is: how do you suggest I can find the difference in spsturni.bam being fired in SoA's BGMain and ToB's one?

#23 Ascension64

Ascension64
  • Modder
  • 5983 posts

Posted 06 January 2012 - 09:03 PM

One way is to find the equivalent proc in the two EXEs. Hex-matching may work, but since you have spsturni in ASCII, you may be able to find references to that to track down the equivalent proc.

--------------
Retired Modder
Note: I do not respond to profile comments/personal messages in regards to troubleshooting my modifications. Please post on the public forums instead.

Baldur's Gate Trilogy-WeiDU and Mods
Throne of Bhaal Extender (TobEx)

Contributions: (NWN2) A Deathstalker (voice acting) - (IWD2) IWD2 NPC Project (soundset editing) - (Misc) SHS PC Soundsets (voice acting)
Legacy: (BG/Tutu/BGT) Beregost Crash Fixer 1.9 (18 Jul 10) - (BG2) Enable conversations with charmed/dominated creatures (18 Jul 10) - (BG2) Experience Corrections (18 Jul 10) - (Misc) Platform Conversion Utility RC2 (13 Feb 10)


#24 Suslik

Suslik

    Investigator

  • Member
  • 500 posts

Posted 07 January 2012 - 01:42 AM

Okay, thanks. I will try to set a memory breakpoint to "spsturni" string.

#25 Suslik

Suslik

    Investigator

  • Member
  • 500 posts

Posted 08 January 2012 - 11:12 AM

What I currently know:
- "spsturni.bam" is fired somehow differently in SoA's BGMain.exe and ToB's one. This causes only the very first frame to be played in ToB.
- I know exact procedure address where it is called Both in SoA and ToB
- I have disassembled and then decompiled those two procedures.

Forgive me for posting such huge code listings, but I have failed to narrow the search range any further:

SoA's CReflectionSpellList::Update(), address 4605CB, it works well:
Spoiler


The same procedure in ToB's BGMain.exe, address 464BFB:
Spoiler

Most functions(i have checked about 95% of them) are 100% identical inside(of course addresses and offsets are different). But I only looked one level deeper(I did not compare functions inside functions and so on).

There was a minor difference in function 64C49B(one extra function was called in ToB and was not called in SoA), but editing it did not help(I have NOP'ed the function call).

Apparently both listings are quite similar. It seems like they only have different offsets and probably constants which I do not know.

Expected feedback:
- Amidoinitrite?
- Any info on functions/constants that were used in ToB's listing
- Any info on where else to look for the root of the problem

Edited by Suslik, 08 January 2012 - 12:23 PM.


#26 Ascension64

Ascension64
  • Modder
  • 5983 posts

Posted 08 January 2012 - 06:35 PM

I'd really have to have a detailed look at this to work out what is going on. Are the two pseudocodes you posted equivalent? Hard to eye-ball just from looking at it.

--------------
Retired Modder
Note: I do not respond to profile comments/personal messages in regards to troubleshooting my modifications. Please post on the public forums instead.

Baldur's Gate Trilogy-WeiDU and Mods
Throne of Bhaal Extender (TobEx)

Contributions: (NWN2) A Deathstalker (voice acting) - (IWD2) IWD2 NPC Project (soundset editing) - (Misc) SHS PC Soundsets (voice acting)
Legacy: (BG/Tutu/BGT) Beregost Crash Fixer 1.9 (18 Jul 10) - (BG2) Enable conversations with charmed/dominated creatures (18 Jul 10) - (BG2) Experience Corrections (18 Jul 10) - (Misc) Platform Conversion Utility RC2 (13 Feb 10)


#27 Suslik

Suslik

    Investigator

  • Member
  • 500 posts

Posted 08 January 2012 - 07:16 PM

As I have already said, listings seem to be equivalent. Furthermore, even all functions that are called inside these two are equivalent too, but I have checked only one level deeper in stack.

I think I can do monotonous work like comparing all those functions myself, I want you just to tell me what to pay attention on. And where else to look.

#28 Ascension64

Ascension64
  • Modder
  • 5983 posts

Posted 08 January 2012 - 08:02 PM

I want you just to tell me what to pay attention on. And where else to look.

Hmm, like I said, a bit hard without me delving into detail what's going on. I'll let you know when I do.

--------------
Retired Modder
Note: I do not respond to profile comments/personal messages in regards to troubleshooting my modifications. Please post on the public forums instead.

Baldur's Gate Trilogy-WeiDU and Mods
Throne of Bhaal Extender (TobEx)

Contributions: (NWN2) A Deathstalker (voice acting) - (IWD2) IWD2 NPC Project (soundset editing) - (Misc) SHS PC Soundsets (voice acting)
Legacy: (BG/Tutu/BGT) Beregost Crash Fixer 1.9 (18 Jul 10) - (BG2) Enable conversations with charmed/dominated creatures (18 Jul 10) - (BG2) Experience Corrections (18 Jul 10) - (Misc) Platform Conversion Utility RC2 (13 Feb 10)


#29 Suslik

Suslik

    Investigator

  • Member
  • 500 posts

Posted 09 January 2012 - 04:07 AM

Ok. I am sort of stuck for now and do not know where else to look. I'll wait for any info from you.

#30 Ascension64

Ascension64
  • Modder
  • 5983 posts

Posted 10 January 2012 - 06:01 PM

Looks like the CProtectedSpl update counter at CCreatureObject+6448h doesn't get zero'ed, causing the problem that you fixed with zeroing memory.

Not sure about the spell turning graphic yet.

--------------
Retired Modder
Note: I do not respond to profile comments/personal messages in regards to troubleshooting my modifications. Please post on the public forums instead.

Baldur's Gate Trilogy-WeiDU and Mods
Throne of Bhaal Extender (TobEx)

Contributions: (NWN2) A Deathstalker (voice acting) - (IWD2) IWD2 NPC Project (soundset editing) - (Misc) SHS PC Soundsets (voice acting)
Legacy: (BG/Tutu/BGT) Beregost Crash Fixer 1.9 (18 Jul 10) - (BG2) Enable conversations with charmed/dominated creatures (18 Jul 10) - (BG2) Experience Corrections (18 Jul 10) - (Misc) Platform Conversion Utility RC2 (13 Feb 10)


#31 Ascension64

Ascension64
  • Modder
  • 5983 posts

Posted 10 January 2012 - 09:22 PM

Hmm, I just tested the issue under the SoA 23037 executable, and the infinite spell absorption as well as the graphic not showing also exist. Did you see the graphic in a different version of SoA?

Update: Turns out SoA 22941 still plays the spell turn graphic, and that this code is added somewhere between 22941 and 23037.

In void CVisualEffect::AIUpdate()
//using ToB26498 offsets
mov	edx, [ebp+var_34]
mov	eax, [edx+6450h]
mov	[ebp+var_1A0], eax
mov	ecx, [ebp+var_1A0]
cmp	ecx, ds:dword_AAD1D0
jnz	short loc_654CCA
mov	edx, [ebp+var_2B4]
mov	eax, [edx+30h]
mov	[ebp+var_1A8], eax
mov	ecx, [ebp+var_34]
mov	[ebp+var_1A4], ecx
mov	edx, [ebp+var_1A4]
mov	eax, [ebp+var_1A8]
mov	[edx+6450h], eax
jmp	short loc_654D36 //if cre.eVisualEffect == -1, cre.eVisualEffect = this.e; ...

loc_654CCA:
mov	ecx, [ebp+var_34]
mov	edx, [ecx+6450h]
mov	[ebp+var_1AC], edx
mov	eax, [ebp+var_2B4]
mov	ecx, [ebp+var_1AC]
cmp	ecx, [eax+30h] //if cre.eVisualEffect == this.e, ...
jz	short loc_654D36
mov	edx, dword_B773CC
mov	eax, [edx+42BAh]
mov	[ebp+var_1B0], eax
push	0FFFFFFFFh
mov	cl, ds:byte_AAD1CB
push	ecx
mov	edx, [ebp+var_2B4]
mov	eax, [edx+25Eh]
push	eax
mov	ecx, [ebp+var_1B0]
add	ecx, 37F6h
call	sub_676808
mov	byte ptr [ebp+var_14], al
mov	ecx, [ebp+var_2B4]
call	sub_656D2E //purge!
jmp	loc_6561E8
Since the spell turning graphic on the ground is already owned by the cre, the extra graphic gets purged because it is a new visual effect and doesn't have the same index (e) as the graphic on the ground.

Probably an unintentional bug created by a bugfix for something else, so we can't just remove this extra code.

Update2: So, you can simply make it play independently of the cre by not giving the VisualEffect an owner.

In void CProtectedSplList::Update(CCreatureObject&)
loc_465116:
mov	ecx, [ebp+var_100]
mov	[ebp+var_68], ecx
mov	[ebp+var_4], 0FFFFFFFFh
mov	edx, [ebp+var_68]
mov	[ebp+var_30], edx //pVisualEffect
sub	esp, 8
mov	ecx, esp
mov	[ebp+var_70], esp
push	offset aSpsturni ; "spsturni"
call	sub_999EFB
lea	ecx, [ebp+var_40]
call	sub_64C310
mov	[ebp+var_4], 3
lea	ecx, [ebp+var_40]
call	sub_64C49B
mov	[ebp+var_44], eax //pVidCell
mov	eax, [ebp+var_20]
add	eax, 6
push	eax
mov	ecx, [ebp+arg_0]
add	ecx, 6
push	ecx
call	sub_8AD080
add	esp, 8
movsx	edx, ax
mov	eax, [ebp+var_44]
mov	[eax+30Ch], edx
mov	ecx, [ebp+var_44]
mov	dword ptr [ecx+7Ah], 8
mov	edx, [ebp+var_44]
mov	byte ptr [edx+38Eh], 1
mov	eax, [ebp+arg_0]
mov	ecx, [eax+30h]
mov	[ebp+var_C4], ecx //pCreatureObject->e
mov	edx, [ebp+var_30]
mov	eax, [ebp+var_C4]
//------------------------------------------------------- nop me!
mov	[edx+25Eh], eax //pVisualEffect->eOwner
//-------------------------------------------------------
mov	ecx, [ebp+var_30]
mov	dword ptr [ecx+52h], 1
mov	edx, [ebp+arg_0]
mov	eax, [edx+6]
mov	ecx, [edx+0Ah]
mov	edx, [ebp+var_30]
mov	[edx+256h], eax
mov	[edx+25Ah], ecx
mov	eax, [ebp+arg_0]
mov	ecx, [eax+12h]
mov	[ebp+var_C8], ecx
mov	dl, ds:byte_AAA9EE
push	edx
push	20h
mov	eax, [ebp+arg_0]
add	eax, 6
push	eax
mov	ecx, [ebp+var_C8]
push	ecx
mov	ecx, [ebp+var_30]
call	sub_6561F8

Edited by Ascension64, 10 January 2012 - 10:40 PM.

--------------
Retired Modder
Note: I do not respond to profile comments/personal messages in regards to troubleshooting my modifications. Please post on the public forums instead.

Baldur's Gate Trilogy-WeiDU and Mods
Throne of Bhaal Extender (TobEx)

Contributions: (NWN2) A Deathstalker (voice acting) - (IWD2) IWD2 NPC Project (soundset editing) - (Misc) SHS PC Soundsets (voice acting)
Legacy: (BG/Tutu/BGT) Beregost Crash Fixer 1.9 (18 Jul 10) - (BG2) Enable conversations with charmed/dominated creatures (18 Jul 10) - (BG2) Experience Corrections (18 Jul 10) - (Misc) Platform Conversion Utility RC2 (13 Feb 10)


#32 Salk

Salk
  • Modder
  • 1411 posts

Donator

Posted 11 January 2012 - 01:00 AM

Very nice find, guys! :cheers:

#33 Suslik

Suslik

    Investigator

  • Member
  • 500 posts

Posted 12 January 2012 - 07:58 AM

Ascension64

Looks like the CProtectedSpl update counter at CCreatureObject+6448h doesn't get zero'ed, causing the problem that you fixed with zeroing memory.

Update: Turns out SoA 22941 still plays the spell turn graphic, and that this code is added somewhere between 22941 and 23037.

Man, you're awesome.

Since the spell turning graphic on the ground is already owned by the cre, the extra graphic gets purged because it is a new visual effect and doesn't have the same index (e) as the graphic on the ground.
Probably an unintentional bug created by a bugfix for something else, so we can't just remove this extra code.

I see. Apparently my asm comprehension skills fail to figure such complex issues myself. But why does it get purged only for being owned by the same creature? There are apparently a lot of graphics can be attached to 1 creature(spell protections/mirror images/globes/etc), why can't we attach one more?

Update2: So, you can simply make it play independently of the cre by not giving the VisualEffect an owner.

It does work, but I have to call it only a workaround, because in SoA the animation is attached to cre and when creature walks, animation moves with it. But if we nullify its parent, it just stands where it was spawned. Do you see any ways to make it work without detaching it from cre?

and again, really great job.

Edited by Suslik, 12 January 2012 - 08:01 AM.


#34 Ascension64

Ascension64
  • Modder
  • 5983 posts

Posted 12 January 2012 - 11:02 PM

I see. Apparently my asm comprehension skills fail to figure such complex issues myself. But why does it get purged only for being owned by the same creature? There are apparently a lot of graphics can be attached to 1 creature(spell protections/mirror images/globes/etc), why can't we attach one more?

We can. A visual effect is essentially made up of a list of vid cells, and two lists of vef components. For various other visual effects, the engine would add a vid cell to the visual effect, if the creature already has an existing visual effect. The bugged code above is probably legacy in that it simply creates a visual effect, adds SPSTURNI vid cell, and sets the creature as its owner without actually checking beforehand whether the creature already had a visual effect.

It does work, but I have to call it only a workaround, because in SoA the animation is attached to cre and when creature walks, animation moves with it. But if we nullify its parent, it just stands where it was spawned. Do you see any ways to make it work without detaching it from cre?

So a more complicated fix would be to check if the creature already has a visual effect, and if not make a visual effect containing SPSTURNI vid cell. If it already does, simply add the vid cell to it. I think there already exists a proc to do this, so we don't necessarily have to re-code it.

However, I wonder why the bouncing animation should move with the creature. A spell bouncing off a wall should have the wall stationary and not moving.

--------------
Retired Modder
Note: I do not respond to profile comments/personal messages in regards to troubleshooting my modifications. Please post on the public forums instead.

Baldur's Gate Trilogy-WeiDU and Mods
Throne of Bhaal Extender (TobEx)

Contributions: (NWN2) A Deathstalker (voice acting) - (IWD2) IWD2 NPC Project (soundset editing) - (Misc) SHS PC Soundsets (voice acting)
Legacy: (BG/Tutu/BGT) Beregost Crash Fixer 1.9 (18 Jul 10) - (BG2) Enable conversations with charmed/dominated creatures (18 Jul 10) - (BG2) Experience Corrections (18 Jul 10) - (Misc) Platform Conversion Utility RC2 (13 Feb 10)


#35 Suslik

Suslik

    Investigator

  • Member
  • 500 posts

Posted 13 January 2012 - 04:16 AM

However, I wonder why the bouncing animation should move with the creature. A spell bouncing off a wall should have the wall stationary and not moving.

well, it just looks somewhat weird when a creature with high movement speed(boots of speed, improved haste) can walk more than my screen's width while the animation is slowly floating stationary in the air.

can you please send me 23037 executable? it's easier to compare with my 22941(?) than ToB.

Edited by Suslik, 13 January 2012 - 04:49 AM.


#36 Dakk

Dakk
  • Member
  • 398 posts

Posted 13 January 2012 - 07:09 AM

However, I wonder why the bouncing animation should move with the creature. A spell bouncing off a wall should have the wall stationary and not moving.

Isn't that - moving with the caster - the behaviour of all caster protections (mirror image, GOI, Otiluke etc) in the game?

#37 Ascension64

Ascension64
  • Modder
  • 5983 posts

Posted 13 January 2012 - 01:38 PM

can you please send me 23037 executable? it's easier to compare with my 22941(?) than ToB.

Probably easier just to download the 23037 patch online and extract the cab.


Isn't that - moving with the caster - the behaviour of all caster protections (mirror image, GOI, Otiluke etc) in the game?

These are continuous graphics though, like the spell turning graphic on the floor. The graphic that isn't showing is one that only plays when a spell bounces.

--------------
Retired Modder
Note: I do not respond to profile comments/personal messages in regards to troubleshooting my modifications. Please post on the public forums instead.

Baldur's Gate Trilogy-WeiDU and Mods
Throne of Bhaal Extender (TobEx)

Contributions: (NWN2) A Deathstalker (voice acting) - (IWD2) IWD2 NPC Project (soundset editing) - (Misc) SHS PC Soundsets (voice acting)
Legacy: (BG/Tutu/BGT) Beregost Crash Fixer 1.9 (18 Jul 10) - (BG2) Enable conversations with charmed/dominated creatures (18 Jul 10) - (BG2) Experience Corrections (18 Jul 10) - (Misc) Platform Conversion Utility RC2 (13 Feb 10)


#38 Ascension64

Ascension64
  • Modder
  • 5983 posts

Posted 13 January 2012 - 04:08 PM

I've had a closer look at whether it is possible to make the turning move with the creature.
Turns out that if the visual effect isn't purged because the creature already has one, the vid cell itself is purged unless an effect re-applies it. So, it becomes incredibly tricky to achieve this.

--------------
Retired Modder
Note: I do not respond to profile comments/personal messages in regards to troubleshooting my modifications. Please post on the public forums instead.

Baldur's Gate Trilogy-WeiDU and Mods
Throne of Bhaal Extender (TobEx)

Contributions: (NWN2) A Deathstalker (voice acting) - (IWD2) IWD2 NPC Project (soundset editing) - (Misc) SHS PC Soundsets (voice acting)
Legacy: (BG/Tutu/BGT) Beregost Crash Fixer 1.9 (18 Jul 10) - (BG2) Enable conversations with charmed/dominated creatures (18 Jul 10) - (BG2) Experience Corrections (18 Jul 10) - (Misc) Platform Conversion Utility RC2 (13 Feb 10)


#39 Suslik

Suslik

    Investigator

  • Member
  • 500 posts

Posted 13 January 2012 - 07:14 PM

Turns out that if the visual effect isn't purged because the creature already has one, the vid cell itself is purged unless an effect re-applies it. So, it becomes incredibly tricky to achieve this.

but.. why? why did that not happen in earlier builds? and which functions(addresses i mean) are you currently investigating?

#40 Ascension64

Ascension64
  • Modder
  • 5983 posts

Posted 14 January 2012 - 02:10 AM

I use hardware breakpoints to track object instances, so it could land on any proc. Will give you some details tomorrow.
Why is always a tough question to answer. I am reluctant to remove functioning code because it is likely to be part of a bugfix... there was lot wrong with unpatched Shadows of Amn.

--------------
Retired Modder
Note: I do not respond to profile comments/personal messages in regards to troubleshooting my modifications. Please post on the public forums instead.

Baldur's Gate Trilogy-WeiDU and Mods
Throne of Bhaal Extender (TobEx)

Contributions: (NWN2) A Deathstalker (voice acting) - (IWD2) IWD2 NPC Project (soundset editing) - (Misc) SHS PC Soundsets (voice acting)
Legacy: (BG/Tutu/BGT) Beregost Crash Fixer 1.9 (18 Jul 10) - (BG2) Enable conversations with charmed/dominated creatures (18 Jul 10) - (BG2) Experience Corrections (18 Jul 10) - (Misc) Platform Conversion Utility RC2 (13 Feb 10)