I made a few modifications to this for enabling other chat types besides tell.
The following instructions assume you don't have the older version already, if you do, just replace what you have from the patch.
Add this in
chat_message.cpp :
Code: Select all
CNPCMessagePacket::CNPCMessagePacket(int8* name, CHAT_MESSAGE_TYPE MessageType, uint8 zone, int8* dat, uint8 size)
{
this->type = 0x17;
this->size = 32 + strlen(dat) + strlen(dat)%2;
WBUFB(data,(0x04)-4) = MessageType;
WBUFB(data,(0x06)-4) = zone;
memcpy(data+(0x08)-4, name,size);
memcpy(data+(0x18)-4, dat, strlen(dat));
}
Add this in
chat_message.h right above the
#endif line:
Code: Select all
class CNPCMessagePacket : public CBasicPacket
{
public:
CNPCMessagePacket(int8* name, CHAT_MESSAGE_TYPE MessageType, uint8 zone, int8* dat,uint8 size);
};
In
luautils.cpp find:
Code: Select all
Lunar<CLuaAbility>::Register(LuaHandle);
and make these new lines above it
Code: Select all
lua_register(LuaHandle,"SpoofSay",luautils::SpoofSay);
lua_register(LuaHandle,"SpoofTell",luautils::SpoofTell);
Also in
luautils.cpp find:
Code: Select all
/************************************************************************
* *
* Загружаем значение переменной TextID указанной зоны *
* *
************************************************************************/
int32 GetTextIDVariable(uint16 ZoneID, const char* variable)
And place this code above it:
Code: Select all
/************************************************************************
* *
* Send a fake "say" message from an NPC or MOB. *
* *
************************************************************************/
int32 SpoofSay(lua_State* L)
{
uint32 mobid = (uint32)lua_tointeger(L,1);
uint32 CharID = (uint32)lua_tointeger(L,2);
CBaseEntity* PNPC = (CBaseEntity*)zoneutils::GetEntity(mobid, TYPE_MOB | TYPE_NPC);
if (PNPC != NULL)
{
const int8* Query = "SELECT targid, pos_zone FROM chars INNER JOIN accounts_sessions USING(charid) WHERE charid = %u LIMIT 1";
int32 ret = Sql_Query(SqlHandle, Query, CharID);
if (ret != SQL_ERROR &&
Sql_NumRows(SqlHandle) != 0 &&
Sql_NextRow(SqlHandle) == SQL_SUCCESS)
{
uint16 TargID = (uint16)Sql_GetUIntData(SqlHandle,0);
uint8 ZoneID = (uint8) Sql_GetUIntData(SqlHandle,1);
CCharEntity* PTellRecipient = (CCharEntity*)zoneutils::GetZone(ZoneID)->GetEntity(TargID, TYPE_PC);
int8* data = (int8*)lua_tolstring(L,3,NULL);
int8* name = (int8*)PNPC->GetObjectName();
uint8 size = (uint8)PNPC->name.size();
PTellRecipient->pushPacket(new CNPCMessagePacket(name,MESSAGE_SAY,ZoneID,data,size));
}
}
return 1;
}
/************************************************************************
* *
* Send a fake "tell" message from an NPC or MOB. *
* *
************************************************************************/
int32 SpoofTell(lua_State* L)
{
uint32 mobid = (uint32)lua_tointeger(L,1);
uint32 CharID = (uint32)lua_tointeger(L,2);
CBaseEntity* PNPC = (CBaseEntity*)zoneutils::GetEntity(mobid, TYPE_MOB | TYPE_NPC);
if (PNPC != NULL)
{
const int8* Query = "SELECT targid, pos_zone FROM chars INNER JOIN accounts_sessions USING(charid) WHERE charid = %u LIMIT 1";
int32 ret = Sql_Query(SqlHandle, Query, CharID);
if (ret != SQL_ERROR &&
Sql_NumRows(SqlHandle) != 0 &&
Sql_NextRow(SqlHandle) == SQL_SUCCESS)
{
uint16 TargID = (uint16)Sql_GetUIntData(SqlHandle,0);
uint8 ZoneID = (uint8) Sql_GetUIntData(SqlHandle,1);
CCharEntity* PTellRecipient = (CCharEntity*)zoneutils::GetZone(ZoneID)->GetEntity(TargID, TYPE_PC);
int8* data = (int8*)lua_tolstring(L,3,NULL);
int8* name = (int8*)PNPC->GetObjectName();
uint8 size = (uint8)PNPC->name.size();
PTellRecipient->pushPacket(new CNPCMessagePacket(name,MESSAGE_TELL,ZoneID,data,size));
}
}
return 1;
}
In
luautils.h find:
Code: Select all
int32 UpdateNMSpawnPoint(lua_State* L); // Update the spawn point of an NM
and place these newlines below it:
Code: Select all
int32 SpoofSay(lua_State* L); // Send faked say messages from NPCs or MOBs.
int32 SpoofTell(lua_State* L); // Send faked tell messages from NPCs or MOBs.
If you compare with the patch you'll see I didn't change much. All really did I did was add the chat type instead of a static 0x03 and renamed the command(s).
Thank you daiiawn for posting the original version of this!
Edit: missed a piece of code in baseentity.cpp right after
Code: Select all
const int8* CBaseEntity::GetName()
{
return name.c_str();
}
I have this (which I think is almost identical to the original patch, don't remember changing it *shrug*):
Code: Select all
const int8* CBaseEntity::GetObjectName()
{
// Strip out the _ in names
ObjectName = name;
size_t start_pos = ObjectName.find("_");
if (start_pos < name.size())
{
ObjectName.replace(start_pos,1," ");
}
return ObjectName.c_str();
}
In baseentitity.h find:
Code: Select all
virtual const int8* GetName(); // The entity name
and add:
Code: Select all
virtual const int8* GetObjectName(); // The entity name