Skip to content

Commit

Permalink
Additions(broken, but soon will be working)
Browse files Browse the repository at this point in the history
  • Loading branch information
naydef committed Mar 10, 2018
1 parent 331e5e8 commit 0d15470
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 31 deletions.
14 changes: 14 additions & 0 deletions sourcemod/gamedata/udp-cap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"windows" "\x55\x8B\xEC\x81\xEC\x50\x0A"
"linux" "_ZN11CBaseServer27ProcessConnectionlessPacketEP11netpacket_s"
}

"NET_SendPacket"
{
"library" "engine"
"windows" "\x55\x8B\xEC\xB8\x84"
"linux" "_Z14NET_SendPacketP11INetChanneliRK8netadr_sPKhiP8bf_writeb"
}
}
}
/* Here other game signatures will be added */
Expand All @@ -24,6 +31,13 @@
"windows" "\x55\x8B\xEC\x81\xEC\x50\x0A"
"linux" "_ZN11CBaseServer27ProcessConnectionlessPacketEP11netpacket_s"
}

"NET_SendPacket"
{
"library" "engine"
"windows" "\x55\x8B\xEC\xB8\x84"
"linux" "_Z14NET_SendPacketP11INetChanneliRK8netadr_sPKhiP8bf_writeb"
}
}
}
}
4 changes: 3 additions & 1 deletion sourcemod/scripting/include/udpcap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ enum netadrtype_t
NA_IP,
};

forward Action UDPC_ProcessIncomingPacket(const char[] ip, int port, const char[] data, int length, netadrtype_t netaddrtype);
forward Action UDPC_ProcessInboundPacket(const char[] ip, int port, char[] data, int& length, netadrtype_t netaddrtype);

forward Action UDPC_ProcessOutboundPacket(const char[] ip, int port, char[] data, int& length, netadrtype_t netaddrtype);



Expand Down
24 changes: 12 additions & 12 deletions src/UDPCap.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="fastdefs.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="smsdk_config.h" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="569" topLine="18" />
<Cursor1 position="1814" topLine="38" />
</Cursor>
</File>
<File name="extension.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="..\sourcemod\public\smsdk_ext.cpp" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2451" topLine="42" />
<Cursor1 position="4578" topLine="123" />
</Cursor>
</File>
<File name="..\sourcemod\public\smsdk_ext.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="fastdefs.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="4578" topLine="123" />
<Cursor1 position="116" topLine="0" />
</Cursor>
</File>
<File name="fastdefs.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="extension.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="116" topLine="0" />
<Cursor1 position="1705" topLine="30" />
</Cursor>
</File>
<File name="extension.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="fastdefs.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3446" topLine="64" />
<Cursor1 position="569" topLine="18" />
</Cursor>
</File>
<File name="smsdk_config.h" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="extension.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1814" topLine="38" />
<Cursor1 position="3446" topLine="64" />
</Cursor>
</File>
</CodeBlocks_layout_file>
68 changes: 50 additions & 18 deletions src/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,50 @@ UDPCap g_Sample; /**< Global singleton for extension's main interface */
SMEXT_LINK(&g_Sample);

INetChannel* netchannelptr=nullptr;
CDetour *g_pDetour=nullptr;
IForward *g_pProcessPacket = nullptr;
CDetour *g_pDetourProcessPacket=nullptr;
CDetour *g_pDetourSendPacket=nullptr;
IForward *g_pProcessPacketIn = nullptr;
IForward *g_pProcessPacketOut = nullptr;
IGameConfig *g_pGameConf = nullptr;

DETOUR_DECL_MEMBER1(Detour_ProcessPacket, bool, netpacket_t*, packet)
DETOUR_DECL_MEMBER1(Detour_ProcessPacketIn, bool, netpacket_t*, packet)
{
if(!g_pProcessPacket)
if(!g_pProcessPacketIn)
{
return DETOUR_MEMBER_CALL(Detour_ProcessPacket)(packet); // This is not supposed to happen normally. Generally speaking, don't mess with destiny.
return DETOUR_MEMBER_CALL(Detour_ProcessPacketIn)(packet); // This is not supposed to happen normally. Generally speaking, don't mess with destiny.
}
cell_t result=0;

g_pProcessPacket->PushString(packet->from.ToString());
g_pProcessPacket->PushCell(packet->from.port);
g_pProcessPacket->PushString((char*)packet->data);
g_pProcessPacket->PushCell(packet->size);
g_pProcessPacket->PushCell(packet->from.type);
g_pProcessPacketIn->PushString(packet->from.ToString());
g_pProcessPacketIn->PushCell(packet->from.port);
g_pProcessPacketIn->PushString((char*)packet->data);
g_pProcessPacketIn->PushCell(packet->size);
g_pProcessPacketIn->PushCell(packet->from.type);

g_pProcessPacket->Execute(&result);
g_pProcessPacketIn->Execute(&result);

if(result==Pl_Handled)
{
return 1;
}
return DETOUR_MEMBER_CALL(Detour_ProcessPacket)(packet);
return DETOUR_MEMBER_CALL(Detour_ProcessPacketIn)(packet);
}

DETOUR_DECL_STATIC5(Detour_ProcessPacketOut, int, void*, netchannel, int, socks, const netadr_t&, to, unsigned char*, data, void*, length)
{
if(!g_pProcessPacketOut)
{
return DETOUR_STATIC_CALL(Detour_ProcessPacketOut)(netchannel, socks, to, data); // This is not supposed to happen normally. Generally speaking, don't mess with destiny.
}
cell_t result=0;

g_pProcessPacketOut->Execute(&result);

if(result==Pl_Handled)
{
return 1;
}
return DETOUR_STATIC_CALL(Detour_ProcessPacketOut)(netchannel, socks, to, data);
}

bool UDPCap::SDK_OnLoad(char *error, size_t maxlength, bool late)
Expand All @@ -80,22 +99,35 @@ bool UDPCap::SDK_OnLoad(char *error, size_t maxlength, bool late)
SM_GET_IFACE(MEMORYUTILS, memutils);
CDetourManager::Init(g_pSM->GetScriptingEngine(), g_pGameConf);

g_pDetour=DETOUR_CREATE_MEMBER(Detour_ProcessPacket, "CBaseServer::ProcessConnectionlessPacket");
g_pDetourProcessPacket=DETOUR_CREATE_MEMBER(Detour_ProcessPacketIn, "CBaseServer::ProcessConnectionlessPacket");

if(g_pDetour==nullptr)
if(g_pDetourProcessPacket==nullptr)
{
snprintf(error, maxlength, "Error loading detour ProcessPacket!");
return false;
}
g_pDetour->EnableDetour();
g_pProcessPacket = forwards->CreateForward("UDPC_ProcessIncomingPacket", ET_Event, 5, NULL, Param_String, Param_Cell, Param_String, Param_Cell, Param_Cell);

g_pDetourSendPacket=DETOUR_CREATE_STATIC(Detour_ProcessPacketOut, "NET_SendPacket");

if(g_pDetourSendPacket==nullptr)
{
snprintf(error, maxlength, "Error loading detour NET_SendPacket!");
return false;
}

g_pDetourProcessPacket->EnableDetour();
g_pDetourSendPacket->EnableDetour();

g_pProcessPacketIn = forwards->CreateForward("UDPC_ProcessInboundPacket", ET_Event, 5, NULL, Param_String, Param_Cell, Param_String, Param_Cell, Param_Cell);
g_pProcessPacketOut = forwards->CreateForward("UDPC_ProcessOutboundPacket", ET_Event, 5, NULL, Param_String, Param_Cell, Param_String, Param_Cell, Param_Cell);

return true;
}

void UDPCap::SDK_OnUnload()
{
g_pDetour->Destroy();
g_pDetourProcessPacket->Destroy();
gameconfs->CloseGameConfigFile(g_pGameConf);
forwards->ReleaseForward(g_pProcessPacket);
forwards->ReleaseForward(g_pProcessPacketIn);
forwards->ReleaseForward(g_pProcessPacketOut);
}

0 comments on commit 0d15470

Please sign in to comment.