View Single Post
11-14-05, 12:06 PM   #1
Silversage
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 132
Can API fcns be hooked?

I was trying to write a little experimental mod that involves hooking CastSpell and CastSpellByName. I have the replacement procedures add a message to the default chat window, bump a counter, and then call the original procedure with all the original parms.

When I examine the procedure values after loading, they are as I would expect them to be, in the sense that CastSpell and CastSpellByName are equal to my versions of the same, and the original values that I stored away are different (and happen to have lower values).

BUT, when I take my character into combat and use my special rogue moves (Gouge, Backstab, etc) no extra message are displayed to the chat window, and the counter is not being bumped.

Can anyone please help me understand what's going on? Is it not possible to truly hook procedures that are part of the core API? Here's a code snippet below.

--Qzot


Code:
function POSC_CastSpell(...)
	POSC:log('CastSpell called.');
	POSC.used = POSC.used+1;
	POSC.originalCastSpell(unpack(arg));
end

function POSC_CastSpellByName(...)
	POSC:log('CastSpellByName called.');
	POSC.used = POSC.used+1;
	POSC.originalCastSpellByName(unpack(arg));
end

function POSC:OnLoad()
	self.originalCastSpell = CastSpell;
	CastSpell = POSC_CastSpell;
	self.originalCastSpellByName = CastSpellByName;
	CastSpellByName = POSC_CastSpellByName;
	self:log('Loaded.');
end

function POSC:logCurrentProcedureValues()
	self:log('CastSpell=', CastSpell);
	self:log('POSC_CastSpell=', POSC_CastSpell);
	self:log('POSC.originalCastSpell=', POSC.originalCastSpell);

	self:log('CastSpellByName=', CastSpellByName);
	self:log('POSC_CastSpellByName=', POSC_CastSpellByName);
	self:log('POSC.originalCastSpellByName=', POSC.originalCastSpellByName);
end

POSC:OnLoad();
  Reply With Quote