* added bbGetPackedGUID, bbPutPackedGUID script funcs. thx bLuma for patch!
* added datatype "strnz" (non-zero-terminated string) to bytebuffer read/write script funcs.
This commit is contained in:
parent
74bb1a8a42
commit
1452efa4e8
@ -50,6 +50,11 @@ DefReturnResult DefScriptPackage::func_bbappend(CmdSet& Set)
|
|||||||
*bb << Set.defaultarg;
|
*bb << Set.defaultarg;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if(dtype == "strnz")
|
||||||
|
{
|
||||||
|
bb->append(Set.defaultarg.c_str(), Set.defaultarg.length()); // append the string skipping \0
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
BB_MACRO_INSERT(bb, dtype, uint8);
|
BB_MACRO_INSERT(bb, dtype, uint8);
|
||||||
BB_MACRO_INSERT(bb, dtype, uint16);
|
BB_MACRO_INSERT(bb, dtype, uint16);
|
||||||
@ -77,6 +82,20 @@ DefReturnResult DefScriptPackage::func_bbread(CmdSet& Set)
|
|||||||
*bb >> g;
|
*bb >> g;
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
else if(dtype == "strnz") // extract some amount of bytes not terminated by \0
|
||||||
|
{
|
||||||
|
uint32 bytes = (uint32)toUint64(Set.arg[1]);
|
||||||
|
if(bytes)
|
||||||
|
{
|
||||||
|
std::string g;
|
||||||
|
char *buf = new char[bytes];
|
||||||
|
bb->read((uint8*)buf,bytes);
|
||||||
|
g = buf;
|
||||||
|
delete [] buf;
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
BB_MACRO_EXTRACT_I(bb, dtype, uint8);
|
BB_MACRO_EXTRACT_I(bb, dtype, uint8);
|
||||||
BB_MACRO_EXTRACT_I(bb, dtype, uint16);
|
BB_MACRO_EXTRACT_I(bb, dtype, uint16);
|
||||||
|
|||||||
@ -53,6 +53,8 @@ void DefScriptPackage::_InitDefScriptInterface(void)
|
|||||||
AddFunc("sendworldpacket",&DefScriptPackage::SCSendWorldPacket);
|
AddFunc("sendworldpacket",&DefScriptPackage::SCSendWorldPacket);
|
||||||
AddFunc("getopcodename",&DefScriptPackage::SCGetOpcodeName);
|
AddFunc("getopcodename",&DefScriptPackage::SCGetOpcodeName);
|
||||||
AddFunc("getopcodeid",&DefScriptPackage::SCGetOpcodeID);
|
AddFunc("getopcodeid",&DefScriptPackage::SCGetOpcodeID);
|
||||||
|
AddFunc("bbgetpackedguid",&DefScriptPackage::SCBBGetPackedGuid);
|
||||||
|
AddFunc("bbputpackedguid",&DefScriptPackage::SCBBPutPackedGuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
DefReturnResult DefScriptPackage::SCshdn(CmdSet& Set)
|
DefReturnResult DefScriptPackage::SCshdn(CmdSet& Set)
|
||||||
@ -899,7 +901,61 @@ DefReturnResult DefScriptPackage::SCGetOpcodeName(CmdSet &Set)
|
|||||||
return GetOpcodeName((uint32)DefScriptTools::toUint64(Set.defaultarg));
|
return GetOpcodeName((uint32)DefScriptTools::toUint64(Set.defaultarg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefReturnResult DefScriptPackage::SCBBGetPackedGuid(CmdSet &Set)
|
||||||
|
{
|
||||||
|
ByteBuffer *bb = bytebuffers.GetNoCreate(_NormalizeVarName(Set.defaultarg,Set.myname));
|
||||||
|
if (!bb)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (bb->size() - bb->rpos() < sizeof(uint8))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
uint8 mask;
|
||||||
|
*bb >> mask;
|
||||||
|
uint64 guid=0;
|
||||||
|
for(uint8 i=0;i<8;i++)
|
||||||
|
{
|
||||||
|
if(mask & (1<<i) )
|
||||||
|
{
|
||||||
|
if (bb->size() - bb->rpos() < sizeof(uint8))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*bb >> ((uint8*)&guid)[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return toString(guid);
|
||||||
|
}
|
||||||
|
|
||||||
|
DefReturnResult DefScriptPackage::SCBBPutPackedGuid(CmdSet &Set)
|
||||||
|
{
|
||||||
|
ByteBuffer *bb = bytebuffers.Get(_NormalizeVarName(Set.arg[0],Set.myname));
|
||||||
|
|
||||||
|
uint64 guid = DefScriptTools::toUint64(Set.defaultarg);
|
||||||
|
if (!guid) // fast check if guid is empty (in this case mask must be 0 with no extra data)
|
||||||
|
{
|
||||||
|
*bb << uint8(0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuffer bbmask;
|
||||||
|
uint8 mask = 0;
|
||||||
|
|
||||||
|
for(uint8 i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if(guid & 0xFF)
|
||||||
|
{
|
||||||
|
mask |= (1<<i);
|
||||||
|
bbmask << ((uint8)(guid & 0xFF));
|
||||||
|
}
|
||||||
|
guid >>= 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
*bb << mask;
|
||||||
|
bb->append(bbmask);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void DefScriptPackage::My_LoadUserPermissions(VarSet &vs)
|
void DefScriptPackage::My_LoadUserPermissions(VarSet &vs)
|
||||||
{
|
{
|
||||||
@ -973,3 +1029,4 @@ void DefScriptPackage::My_Run(std::string line, std::string username)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -44,5 +44,7 @@ DefReturnResult SCGetClass(CmdSet&);
|
|||||||
DefReturnResult SCSendWorldPacket(CmdSet&);
|
DefReturnResult SCSendWorldPacket(CmdSet&);
|
||||||
DefReturnResult SCGetOpcodeName(CmdSet&);
|
DefReturnResult SCGetOpcodeName(CmdSet&);
|
||||||
DefReturnResult SCGetOpcodeID(CmdSet&);
|
DefReturnResult SCGetOpcodeID(CmdSet&);
|
||||||
|
DefReturnResult SCBBGetPackedGuid(CmdSet&);
|
||||||
|
DefReturnResult SCBBPutPackedGuid(CmdSet&);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user