I think this would be better, because it would just return the link to the item from the function, rather than outputting it as a generic tell (great for seeing what you're working for in a quest):
Note: I haven't tested this, it's just a specific idea. All changes are in
red.
In
zone/questmgr.h, change
Code:
char* itemlink(int item_id);
In
zone/questmgr.cpp, change
Code:
char* QuestManager::itemlink(int item_id) {
//I dont think this is right anymore, need the hash
/*
uint32_t calc_hash (const char *string)
{
register hash = 0;
while (*string != '\0')
{
register c = toupper(*string);
asm volatile("
imul $31, %1, %1;
movzx %%ax, %%edx;
addl %%edx, %1;
movl %1, %0;
"
:"=r"(hash)
:"D"(hash), "a"(c)
:"%edx"
);
//This is what the inline asm is doing:
//hash *= 0x1f;
//hash += (int)c;
string++;
}
return hash;
}
Now the not so simple part, generating the string to feed into the hash function.
The string for normal (unaugmented) items looks like this:
Code:
sprintf(hashstr, "%d%s%s%d %d %d %d %d %d %d %d", id, name, "-1-1-1-1-1", hp, mana, ac, light, icon, price, size, weight);
The string for bags looks like this:
Code:
sprintf(hashstr, "%d%s%d%d%d%d", id, name, bagslots, bagwr, price, weight);
The string for books looks like this:
Code:
sprintf(hashstr, "%d%s%d%d", id, name, weight, booktype);
*/
// MYRA - added itemlink(ID) command
const Item_Struct* item = 0;
int16 itemid = item_id;
item = database.GetItem(itemid);
return (sprintf("%c%06X%s%s%c",0x12,itemid,"000000000000000000000000000000000000000",item,0x12));
}
And in
zone/perlparser.cpp (
really not sure about this part), change
Code:
XS(XS__itemlink);
XS(XS__itemlink)
{
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: itemlink(item_id)");
char* RETVAL;
int item_id = (int)SvIV(ST(0));
RETVAL = quest_manager.itemlink(item_id);
ST(0) = RETVAL;
sv_2mortal(ST(0));
XSRETURN(1);
}
Any thoughts?