Skip to content

Commit

Permalink
Some improvements
Browse files Browse the repository at this point in the history
+ Initial ExtEntityTeleport implementation
* Cleanup stack trace output
  • Loading branch information
igor725 committed Nov 21, 2022
1 parent 71d9571 commit 34d20b6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,14 @@ cs_bool Client_UndefineModel(Client *client, cs_byte id) {
return false;
}

cs_bool Client_ExtTeleportTo(Client *client, cs_byte behavior, Vec *pos, Ang *ang) {
if(Client_GetExtVer(client, EXT_ENTTELEPORT)) {
CPE_WriteExtEntityTeleport(client, behavior, pos, ang);
return true;
}
return false;
}

cs_bool Client_SetProp(Client *client, EEntProp prop, cs_int32 value) {
if(prop >= ENTITY_PROP_COUNT) return false;
client->cpeData.props[prop] = value;
Expand Down
1 change: 1 addition & 0 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ API cs_bool Client_SetGroup(Client *client, cs_uintptr gid);
API cs_bool Client_SpawnParticle(Client *client, cs_byte id, Vec *pos, Vec *origin);
API cs_bool Client_SendPluginMessage(Client *client, cs_byte channel, cs_str message);
API cs_bool Client_UndefineModel(Client *client, cs_byte id);
API cs_bool Client_ExtTeleportTo(Client *client, cs_byte behavior, Vec *pos, Ang *ang);

API EClientState Client_GetState(Client *client);
API cs_str Client_GetName(Client *client);
Expand Down
14 changes: 9 additions & 5 deletions src/cserror.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ NOINL static void PrintCallStack(void) {
};

for(cs_int32 i = 0; i < frames; i++) {
SymFromAddr(GetCurrentProcess(), (cs_uintptr)stack[i], NULL, symbol);
printf("Frame #%d: %s = %p\n", i, symbol->Name, (void *)symbol->Address);
if(SymGetLineFromAddr(GetCurrentProcess(), (cs_uintptr)symbol->Address, (void *)&stack[i], &line))
printf("\tin %s at line %ld\n", line.FileName, line.LineNumber);
if(SymFromAddr(GetCurrentProcess(), (cs_uintptr)stack[i], NULL, symbol)) {
printf("Frame #%d: %s = %p\n", i, symbol->Name, (void *)symbol->Address);
if(SymGetLineFromAddr(GetCurrentProcess(), (cs_uintptr)symbol->Address, (void *)&stack[i], &line))
printf("\tin %s at line %ld\n", line.FileName, line.LineNumber);
if(String_Compare(symbol->Name, "main")) break;
}
}
}

Expand All @@ -50,8 +52,10 @@ static void PrintCallStack(void) {

for(cs_int32 i = 0; i < frames; i++) {
Dl_info dli;
if(dladdr(stack[i], &dli))
if(dladdr(stack[i], &dli)) {
printf("Frame #%d: %s = %p\n", i, dli.dli_sname, dli.dli_saddr);
if(String_Compare(dli.dli_sname, "main")) break;
}
}
# else
printf("*** Callstack printing is not implemented yet for this OS\n");
Expand Down
27 changes: 23 additions & 4 deletions src/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,21 @@ void CPE_WritePluginMessage(Client *client, cs_byte channel, cs_str message) {
PacketWriter_End(client);
}

void CPE_WriteExtEntityTeleport(Client *client, cs_byte behavior, Vec *pos, Ang *ang) {
PacketWriter_Start(client, 17);

*data++ = PACKET_EXTENTITYTP;
*data++ = CLIENT_SELF;
*data++ = behavior;
if(Client_GetExtVer(client, EXT_ENTPOS))
Proto_WriteFlVec(&data, pos);
else
Proto_WriteFlSVec(&data, pos);
Proto_WriteAng(&data, ang);

PacketWriter_End(client);
}

cs_bool CPEHandler_ExtInfo(Client *client, cs_char *data) {
ValidateCpeClient(client, false);
ValidateClientState(client, CLIENT_STATE_MOTD, false);
Expand Down Expand Up @@ -1220,11 +1235,11 @@ static const struct extReg {
{"ChangeModel", 1},
{"EnvMapAppearance", 2},
{"EnvWeatherType", 1},
{"HackControl", 1},
{"MessageTypes", 1},
{"HackControl", 1},
{"PlayerClick", 1},
{"LongerMessages", 1},
{"FullCP437", 1},
{"LongerMessages", 1},
{"BlockDefinitions", 1},
{"BlockDefinitionsExt", 2},
{"BulkBlockUpdate", 1},
Expand All @@ -1234,15 +1249,18 @@ static const struct extReg {
{"ExtEntityPositions", 1},
{"TwoWayPing", 1},
{"InventoryOrder", 1},
// {"ExtendedBlocks", 1},
{"FastMap", 1},
// {"ExtendedTextures", 1},
{"SetHotbar", 1},
{"SetSpawnpoint", 1},
{"VelocityControl", 1},
{"CustomParticles", 1},
{"CustomModels", 2},
{"PluginMessages", 1},
{"ExtEntityTeleport", 1},

// Не думаю, что они когда-нибудь появятся
// {"ExtendedBlocks", 1},
// {"ExtendedTextures", 1},

{NULL, 0}
};
Expand All @@ -1267,6 +1285,7 @@ void Packet_RegisterDefault(void) {
(void)Packet_Register(PACKET_TWOWAYPING, 3, CPEHandler_TwoWayPing);
(void)Packet_Register(PACKET_PLAYERCLICKED, 14, CPEHandler_PlayerClick);
(void)Packet_Register(PACKET_PLUGINMESSAGE, 65, CPEHandler_PluginMessage);

(void)Packet_SetCPEHandler(PACKET_ENTITYTELEPORT, EXT_ENTPOS, 1, 15, NULL);
}

Expand Down
1 change: 1 addition & 0 deletions src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef cs_bool(*packetHandler)(Client *, cs_char *);
NOINL void CPE_WriteDefineModelPart(Client *client, cs_int32 ver, cs_byte id, CPEModelPart *part);
NOINL void CPE_WriteUndefineModel(Client *client, cs_byte id);
NOINL void CPE_WritePluginMessage(Client *client, cs_byte channel, cs_str message);
NOINL void CPE_WriteExtEntityTeleport(Client *client, cs_byte behavior, Vec *pos, Ang *ang);
#endif

API cs_bool Packet_Register(EPacketID id, cs_uint16 size, packetHandler handler);
Expand Down
4 changes: 3 additions & 1 deletion src/types/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define EXT_PARTICLE 0x0D732743ul
#define EXT_CUSTOMMODELS 0xB27EFA32ul
#define EXT_PLUGINMESSAGE 0x59FA7285ul
#define EXT_ENTTELEPORT 0x9af9cdc6ul

typedef enum _EPacketID {
// Vanilla packets
Expand Down Expand Up @@ -96,7 +97,8 @@ typedef enum _EPacketID {
PACKET_DEFINEMODEL = 0x32,
PACKET_DEFINEMODELPART = 0x33,
PACKET_UNDEFINEMODEL = 0x34,
PACKET_PLUGINMESSAGE = 0x35
PACKET_PLUGINMESSAGE = 0x35,
PACKET_EXTENTITYTP = 0x36
} EPacketID;

typedef struct _Packet {
Expand Down

0 comments on commit 34d20b6

Please sign in to comment.