I wanted to add SpellCharges to my bot for spells like Savage Defense, Dark Soul: Misery, Shield Block ...
you need to get the spell category from SpellDB. I do not have an OOP sub for that so I dumped the column using TomRus's DB Tool and made a sub that returns spell category from spell ID. Then you use that number to get the SpellCatagoryDB row field 9 and then search the SpellChargesHistory table. You count up the number of times you find it and subtract that from the max available.
You can find all of the code you need in the 20726 binary sub 67172b.
-counted
Code:
public int UsedCharges
{
get
{
// from Script_GetSpellCharges
//20726 sub 67172b
//pSpellRow = GetEncryptedRow(spellID)
//val GetRow(g_DB_SpellCategories, pSpellRow + 0x30) // Field 0xc
// val = spelldb catagory => spellcatagoryDB => val
uint pCurrentEntry = TC.Pmr.Read<uint>(Offsets.SpellChargesBase + 8 * 4);
int count = 0;
int v4 = 0;
int catagoryIndex = BarMapper.GetSpellCatagory(SpellId);
CGDBC.CGDBCTable db = CGDBC.Instance.GetDb(eCGDBC.SpellCategories);
CGDBC.Row cataRow = db.GetRow(catagoryIndex);
int spellcatagory = cataRow.GetField<int>(9);
while ((pCurrentEntry & 1) == 0 && pCurrentEntry > 0)
{
uint pNextEntry = TC.Pmr.Read<uint>(pCurrentEntry + 4);
int currentcatagory = TC.Pmr.Read<int>(pCurrentEntry + 8);
if (currentcatagory == spellcatagory)
{
count = count + TC.Pmr.Read<byte>(pCurrentEntry + 0xc);
//todo [BarSpell] what the heck is v4 doing??
if (v4 == 0 || TC.Pmr.Read<uint>(pCurrentEntry + 0x10) - v4 < 0)
v4 = TC.Pmr.Read<int>(pCurrentEntry + 0x10);
}
pCurrentEntry = pNextEntry;
}
return count;
}
}