commit ecb94ca91f79df4ba5ba3297b4fd32c20c81ae74 Author: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Sat May 19 05:20:28 2018 +0300 Initial commit diff --git a/Release/CL.read.1.tlog b/Release/CL.read.1.tlog new file mode 100644 index 0000000..c19f3f6 Binary files /dev/null and b/Release/CL.read.1.tlog differ diff --git a/Release/CL.write.1.tlog b/Release/CL.write.1.tlog new file mode 100644 index 0000000..bcf844b Binary files /dev/null and b/Release/CL.write.1.tlog differ diff --git a/Release/cl.command.1.tlog b/Release/cl.command.1.tlog new file mode 100644 index 0000000..a008fd0 Binary files /dev/null and b/Release/cl.command.1.tlog differ diff --git a/Release/link.command.1.tlog b/Release/link.command.1.tlog new file mode 100644 index 0000000..fa8f115 Binary files /dev/null and b/Release/link.command.1.tlog differ diff --git a/Release/link.read.1.tlog b/Release/link.read.1.tlog new file mode 100644 index 0000000..a158c51 Binary files /dev/null and b/Release/link.read.1.tlog differ diff --git a/Release/link.write.1.tlog b/Release/link.write.1.tlog new file mode 100644 index 0000000..7d78d89 Binary files /dev/null and b/Release/link.write.1.tlog differ diff --git a/Release/main.obj b/Release/main.obj new file mode 100644 index 0000000..bbef908 Binary files /dev/null and b/Release/main.obj differ diff --git a/Release/mt.command.1.tlog b/Release/mt.command.1.tlog new file mode 100644 index 0000000..8f086f0 Binary files /dev/null and b/Release/mt.command.1.tlog differ diff --git a/Release/mt.read.1.tlog b/Release/mt.read.1.tlog new file mode 100644 index 0000000..a799dd9 Binary files /dev/null and b/Release/mt.read.1.tlog differ diff --git a/Release/mt.write.1.tlog b/Release/mt.write.1.tlog new file mode 100644 index 0000000..9ba73e4 Binary files /dev/null and b/Release/mt.write.1.tlog differ diff --git a/Release/sv_a2s_fix.Build.CppClean.log b/Release/sv_a2s_fix.Build.CppClean.log new file mode 100644 index 0000000..08ce866 --- /dev/null +++ b/Release/sv_a2s_fix.Build.CppClean.log @@ -0,0 +1,19 @@ +..\..\..\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.pdb +D:\GMOD9_SERVER\GMOD9\LUA\BIN\SV_A2S_FIX.DLL +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.exp +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.lib +D:\GMOD9_SERVER\GMOD9\LUA\BIN\SV_A2S_FIX.PDB +D:\lua502\lua\sv_a2s_fix\..\..\..\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.dll +D:\lua502\lua\sv_a2s_fix\Release\cl.command.1.tlog +D:\lua502\lua\sv_a2s_fix\Release\CL.read.1.tlog +D:\lua502\lua\sv_a2s_fix\Release\CL.write.1.tlog +D:\lua502\lua\sv_a2s_fix\Release\link.command.1.tlog +D:\lua502\lua\sv_a2s_fix\Release\link.read.1.tlog +D:\lua502\lua\sv_a2s_fix\Release\link.write.1.tlog +D:\LUA502\LUA\SV_A2S_FIX\RELEASE\MAIN.OBJ +D:\lua502\lua\sv_a2s_fix\Release\mt.command.1.tlog +D:\lua502\lua\sv_a2s_fix\Release\mt.read.1.tlog +D:\lua502\lua\sv_a2s_fix\Release\mt.write.1.tlog +D:\LUA502\LUA\SV_A2S_FIX\RELEASE\SV_A2S_FIX.DLL.INTERMEDIATE.MANIFEST +D:\lua502\lua\sv_a2s_fix\Release\sv_a2s_fix.write.1.tlog +D:\LUA502\LUA\SV_A2S_FIX\RELEASE\VC100.PDB diff --git a/Release/sv_a2s_fix.dll.intermediate.manifest b/Release/sv_a2s_fix.dll.intermediate.manifest new file mode 100644 index 0000000..ecea6f7 --- /dev/null +++ b/Release/sv_a2s_fix.dll.intermediate.manifest @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Release/sv_a2s_fix.lastbuildstate b/Release/sv_a2s_fix.lastbuildstate new file mode 100644 index 0000000..c2d4a05 --- /dev/null +++ b/Release/sv_a2s_fix.lastbuildstate @@ -0,0 +1,2 @@ +#v4.0:v100:false +Release|Win32|D:\lua502\lua\| diff --git a/Release/sv_a2s_fix.log b/Release/sv_a2s_fix.log new file mode 100644 index 0000000..25ea927 --- /dev/null +++ b/Release/sv_a2s_fix.log @@ -0,0 +1,29 @@ +Build started 19.05.2018 4:49:57. + 1>Project "D:\lua502\lua\sv_a2s_fix\sv_a2s_fix.vcxproj" on node 2 (build target(s)). + 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(299,5): warning MSB8004: каталог Output заканчивается не косой чертой. Этот экземпляр построения добавит косую черту, поскольку она необходима для правильного определения каталога Output. + 1>InitializeBuildStatus: + Creating "Release\sv_a2s_fix.unsuccessfulbuild" because "AlwaysCreate" was specified. + ClCompile: + C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /ID:\source2006\public\dlls /ID:\source2006\dlls\hl2_dll /ID:\source2006\game_shared\hl2 /ID:\source2006\game_shared\hl2mp /ID:\source2006\game_shared /ID:\source2006\dlls /ID:\source2006\public\tier1 /ID:\source2006\public\tier0 /ID:\source2006\public /ID:\source2006\common /ID:\lua502\lua\lua502_sdk /Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D _WINDLL /D _MBCS /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt main.cpp + main.cpp + 1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(1140): warning C4005: ARRAYSIZE: изменение макроопределения + d:\source2006\public\tier0\commonmacros.h(35): см. предыдущее определение "ARRAYSIZE" + 1>main.cpp(156): warning C4800: int: принудительно задано логическое значение "true" или "false" (предупреждение о производительности) + 1>main.cpp(197): warning C4800: int: принудительно задано логическое значение "true" или "false" (предупреждение о производительности) + 1>main.cpp(198): warning C4800: int: принудительно задано логическое значение "true" или "false" (предупреждение о производительности) + Link: + C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"..\..\..\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.dll" /NOLOGO /LIBPATH:D:\source2006\lib\public /LIBPATH:D:\lua502\lua\Release lua502_sdk.lib vstdlib.lib tier0.lib tier1.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /NODEFAULTLIB:LIBCMT.lib /MANIFEST /ManifestFile:"Release\sv_a2s_fix.dll.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.pdb" /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"..\..\..\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.lib" /MACHINE:X86 /DLL Release\main.obj + Создается библиотека ..\..\..\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.lib и объект ..\..\..\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.exp + Создание кода + Создание кода завершено + sv_a2s_fix.vcxproj -> D:\lua502\lua\sv_a2s_fix\..\..\..\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.dll + Manifest: + C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\mt.exe /nologo /verbose /outputresource:"..\..\..\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.dll;#2" /manifest Release\sv_a2s_fix.dll.intermediate.manifest + FinalizeBuildStatus: + Deleting file "Release\sv_a2s_fix.unsuccessfulbuild". + Touching "Release\sv_a2s_fix.lastbuildstate". + 1>Done Building Project "D:\lua502\lua\sv_a2s_fix\sv_a2s_fix.vcxproj" (build target(s)). + +Построение успешно завершено. + +Time Elapsed 00:00:02.21 diff --git a/Release/sv_a2s_fix.write.1.tlog b/Release/sv_a2s_fix.write.1.tlog new file mode 100644 index 0000000..fa9ed7f --- /dev/null +++ b/Release/sv_a2s_fix.write.1.tlog @@ -0,0 +1,15 @@ +^D:\lua502\lua\sv_a2s_fix\sv_a2s_fix.vcxproj +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.lib +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.lib +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.exp +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.exp +^D:\lua502\lua\sv_a2s_fix\sv_a2s_fix.vcxproj +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.lib +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.lib +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.exp +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.exp +^D:\lua502\lua\sv_a2s_fix\sv_a2s_fix.vcxproj +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.lib +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.lib +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.exp +D:\GMod9_Server\gmod9\lua\bin\sv_a2s_fix.exp diff --git a/Release/vc100.pdb b/Release/vc100.pdb new file mode 100644 index 0000000..a5afec7 Binary files /dev/null and b/Release/vc100.pdb differ diff --git a/lua/bin/sv_a2s_fix.dll b/lua/bin/sv_a2s_fix.dll new file mode 100644 index 0000000..b36a539 Binary files /dev/null and b/lua/bin/sv_a2s_fix.dll differ diff --git a/lua/init/a2s_info.lua b/lua/init/a2s_info.lua new file mode 100644 index 0000000..75be6ff --- /dev/null +++ b/lua/init/a2s_info.lua @@ -0,0 +1,7 @@ +function onClientResponse(addr,req) + return true +end + +function onServerQuery(info,addr) + return info +end \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..253659e --- /dev/null +++ b/main.cpp @@ -0,0 +1,251 @@ +#define GAME_DLL +#include "cbase.h" +#include "bitbuf.h" +#include "plugin.h" +#include "glua.h" +#include "chook.h" + +typedef struct { + uint16 family; + uint16 port; + uint32 addr; +} ws2_addr; + +#define LUA_CALLBACK "onServerQuery" +#define LUA_CALLBACK2 "onClientResponse" + +typedef int (__stdcall* SendTo_t)(int,const char*,int,int,void*,int); + +DECLARE_PLUGIN(CA2SFix) +public: + virtual bool Load(CreateInterfaceFn, + CreateInterfaceFn); + virtual void Unload(); + virtual bool LuaInit(lua_State*); + bool IsResponseAllowed(uint32 naddr,unsigned char req); + bool ProcessResponse(bf_read&,bf_write&,uint32); + bool ProcessLua(bf_read&,bf_write&,uint32); + + bool m_bLua; + lua_State* L; + static CHook* s_pSendHook; + static SendTo_t s_SendTo; +END_PLUGIN(CA2SFix,"A2S Fix"); + +CHook* CA2SFix::s_pSendHook = NULL; +SendTo_t CA2SFix::s_SendTo = NULL; + +static int __stdcall SendTo_Hook(int s,const char* buf, + int len,int flags,void* addr,int tolen) +{ + static char s_szBuf[1024]; + uint32 naddr = ((ws2_addr*)addr)->addr; + if(*(uint32*)buf == 0xFFFFFFFF) + { + if(!s_CA2SFix.IsResponseAllowed(naddr,(unsigned char)buf[4])) + return len; + } + if(*(uint32*)buf == 0xFFFFFFFF && buf[4] == 0x49) + { + memset(s_szBuf,'\0',1024); + bf_read br(buf,len); + bf_write bf(s_szBuf,1024); + if(!s_CA2SFix.ProcessResponse(br,bf,naddr)) + return len; + return CA2SFix::s_SendTo(s,(const char*)bf.GetData(), + bf.GetNumBytesWritten(),flags,addr,tolen); + } + return CA2SFix::s_SendTo(s,buf,len,flags,addr,tolen); +} + +bool CA2SFix::Load(CreateInterfaceFn engineFn,CreateInterfaceFn) +{ + s_pSendHook = new CHook((DWORD)GetProcAddress( + GetModuleHandle("WS2_32.dll"),"sendto"),5); + s_SendTo = (SendTo_t)s_pSendHook + ->HookFunction((DWORD)&SendTo_Hook); + m_bLua = (GetModuleHandle("lua502.dll") != NULL); + return true; +} + +void CA2SFix::Unload() +{ + delete s_pSendHook; +} + +bool CA2SFix::LuaInit(lua_State* _L) +{ + L = _L; + return true; +} + +bool CA2SFix::ProcessResponse(bf_read& br,bf_write& bf,uint32 naddr) +{ + bf.WriteLong(br.ReadLong()); + bf.WriteByte(br.ReadByte()); + br.ReadByte(); + bf.WriteByte(7); //Protocol version + if(m_bLua) + { + if(!ProcessLua(br,bf,naddr)) + return false; + } + else bf.WriteBitsFromBuffer(&br,br.GetNumBitsLeft()); + return true; +} + +#define lua_setstring(L,name,s) \ + lua_pushstring(L,name); \ + lua_pushstring(L,s); \ + lua_settable(L,-3) + +#define lua_setnumber(L,name,d) \ + lua_pushstring(L,name); \ + lua_pushnumber(L,(double)d); \ + lua_settable(L,-3) + +inline const char* lua_getstring(lua_State* L, + const char* name) +{ + lua_pushstring(L,name); + lua_gettable(L,-2); + const char* pStr = lua_tostring(L,-1); + lua_pop(L,1); + return pStr; +} + +inline int lua_getnumber(lua_State* L, + const char* name) +{ + lua_pushstring(L,name); + lua_gettable(L,-2); + int pNum = lua_tonumber(L,-1); + lua_pop(L,1); + return pNum; +} + +int _aterror(lua_State* L) +{ + return g_pLua502->GetLuaCallbacks()->OnLuaError(L); +} + +inline char* addr2str(uint32 naddr) +{ + static char szBuf[32] = {0}; + unsigned char* ip = (unsigned char*)&naddr; + sprintf(szBuf,"%d.%d.%d.%d",ip[0], + ip[1],ip[2],ip[3]); + return szBuf; +} + +bool CA2SFix::IsResponseAllowed(uint32 naddr,unsigned char req) +{ + lua_pushcfunction(L,_aterror); + int iHandler = lua_gettop(L); + + lua_getglobal(L,LUA_CALLBACK2); + if(lua_isnil(L,-1)) + { + lua_pop(L,2); + return true; + } + + lua_pushstring(L,addr2str(naddr)); + lua_pushnumber(L,req); + lua_pcall(L,2,1,iHandler); + bool bRet = lua_toboolean(L,-1); + lua_pop(L,2); + return bRet; +} + +bool CA2SFix::ProcessLua(bf_read& br,bf_write& bf,uint32 naddr) +{ + lua_pushcfunction(L,_aterror); + int iHandler = lua_gettop(L); + + lua_getglobal(L,LUA_CALLBACK); + if(lua_isnil(L,-1)) + { + lua_pop(L,2); + bf.WriteBitsFromBuffer(&br,br.GetNumBitsLeft()); + return true; + } + + static char szServer[256] = {0}; + static char szMapName[128] = {0}; + static char szFolder[128]; + static char szGame[64] = {0}; + static char szVersion[32] = {0}; + int iAppId,iPlayers,iMaxPlayers,iBots; + char szSvType[2] = {0,0}; + char szSvEnv[2] = {0,0}; + bool bVisibility,bVac; + + br.ReadString(szServer,256); + br.ReadString(szMapName,128); + br.ReadString(szFolder,128); + br.ReadString(szGame,64); + + iAppId = br.ReadWord(); + iPlayers = br.ReadByte(); + iMaxPlayers = br.ReadByte(); + iBots = br.ReadByte(); + + szSvType[0] = br.ReadByte(); + szSvEnv[0] = br.ReadByte(); + + bVisibility = br.ReadByte(); + bVac = br.ReadByte(); + br.ReadString(szVersion,32); + + lua_newtable(L); + + lua_setstring(L,"name",szServer); + lua_setstring(L,"map",szMapName); + lua_setstring(L,"folder",szFolder); + lua_setstring(L,"game",szGame); + + lua_setnumber(L,"appid",iAppId); + lua_setnumber(L,"players",iPlayers); + lua_setnumber(L,"maxplayers",iMaxPlayers); + lua_setnumber(L,"bots",iBots); + + lua_setstring(L,"type",szSvType); + lua_setstring(L,"env",szSvEnv); + + lua_setnumber(L,"visibility",bVisibility); + lua_setnumber(L,"vac",bVac); + + lua_setstring(L,"version",szVersion); + + lua_pushstring(L,addr2str(naddr)); + lua_pcall(L,2,1,iHandler); + if(lua_isnil(L,-1)) + { + lua_pop(L,2); + bf.WriteBitsFromBuffer(&br,br.GetNumBitsLeft()); + return true; + } + + bf.WriteString(lua_getstring(L,"name")); + bf.WriteString(lua_getstring(L,"map")); + bf.WriteString(lua_getstring(L,"folder")); + bf.WriteString(lua_getstring(L,"game")); + + bf.WriteWord(lua_getnumber(L,"appid")); + bf.WriteByte(lua_getnumber(L,"players")); + bf.WriteByte(lua_getnumber(L,"maxplayers")); + bf.WriteByte(lua_getnumber(L,"bots")); + + bf.WriteByte(lua_getstring(L,"type")[0]); + bf.WriteByte(lua_getstring(L,"env")[0]); + + bf.WriteByte(lua_getnumber(L,"visibility")); + bf.WriteByte(lua_getnumber(L,"vac")); + + bf.WriteString(lua_getstring(L,"version")); + bf.WriteBitsFromBuffer(&br,br.GetNumBitsLeft()); + + lua_pop(L,2); + return true; +} \ No newline at end of file diff --git a/sv_a2s_fix.vcxproj b/sv_a2s_fix.vcxproj new file mode 100644 index 0000000..e6d84b3 --- /dev/null +++ b/sv_a2s_fix.vcxproj @@ -0,0 +1,74 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {9063DF3A-3CCF-497C-916F-E44CC01DE942} + sv_a2s_fix + + + + Application + true + MultiByte + + + DynamicLibrary + false + true + MultiByte + + + + + + + + + + + + + ..\..\..\GMod9_Server\gmod9\lua\bin + + + + Level3 + Disabled + + + true + + + + + Level3 + MaxSpeed + true + true + D:\source2006\public\dlls;D:\source2006\dlls\hl2_dll;D:\source2006\game_shared\hl2;D:\source2006\game_shared\hl2mp;D:\source2006\game_shared;D:\source2006\dlls;D:\source2006\public\tier1;D:\source2006\public\tier0;D:\source2006\public;D:\source2006\common;D:\lua502\lua\lua502_sdk;%(AdditionalIncludeDirectories) + + + true + true + true + D:\source2006\lib\public;D:\lua502\lua\Release;%(AdditionalLibraryDirectories) + lua502_sdk.lib;vstdlib.lib;tier0.lib;tier1.lib;%(AdditionalDependencies) + LIBCMT.lib;%(IgnoreSpecificDefaultLibraries) + + + + + + + + + \ No newline at end of file diff --git a/sv_a2s_fix.vcxproj.filters b/sv_a2s_fix.vcxproj.filters new file mode 100644 index 0000000..1aa6936 --- /dev/null +++ b/sv_a2s_fix.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Файлы исходного кода + + + \ No newline at end of file diff --git a/sv_a2s_fix.vcxproj.user b/sv_a2s_fix.vcxproj.user new file mode 100644 index 0000000..ace9a86 --- /dev/null +++ b/sv_a2s_fix.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file