Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Mor committed Feb 17, 2019
0 parents commit 462d440
Show file tree
Hide file tree
Showing 32 changed files with 7,025 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
client/temp/
server/temp/
bin/
setup/files_temporary/
effects.cpp
*.lck
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
.vs/
Generated\ Files/
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
_Chutzpah*
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
*.psess
*.vsp
*.vspx
*.sap
*.e2e
*.coverage
*.coveragexml
[Ee]xpress/
*.[Cc]ache
!?*.[Cc]ache/
*.GhostDoc.xml
*.binlog
.localhistory/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Mor

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# **KeyListener**

## Using
---------------------------------
To get started, connect the header file.
```php
#include <sampvoice>
```
Simple example
```php
public void:OnPlayerKeyDown(playerid, keyid) {
new buffer[64];
format(buffer, sizeof(buffer), "KeyDown: %d", keyid);
SendClientMessage(playerid, -1, buffer);
}
public void:OnPlayerKeyUp(playerid, keyid) {
new buffer[64];
format(buffer, sizeof(buffer), "KeyUp: %d", keyid);
SendClientMessage(playerid, -1, buffer);
}
```
79 changes: 79 additions & 0 deletions client/client.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{D52583BE-8BB6-47A8-AB5F-09DB8FAB92C3}</ProjectGuid>
<RootNamespace>client</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>temp\</IntDir>
<TargetName>KeyListener</TargetName>
<TargetExt>.asi</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>TurnOffAllWarnings</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<DebugInformationFormat>None</DebugInformationFormat>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
<FloatingPointModel>Fast</FloatingPointModel>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
<PrecompiledHeaderFile />
<PrecompiledHeaderOutputFile />
<LanguageStandard>stdcpp14</LanguageStandard>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<Version>1.0</Version>
<GenerateDebugInformation>false</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="raknet\bitstream.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="log.h" />
<ClInclude Include="main.h" />
<ClInclude Include="mem.hpp" />
<ClInclude Include="net.h" />
<ClInclude Include="raknet\bitstream.h" />
<ClInclude Include="raknet\rakclient.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
48 changes: 48 additions & 0 deletions client/client.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Исходные файлы">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Файлы заголовков">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Файлы ресурсов">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Исходные файлы\raknet">
<UniqueIdentifier>{a0c0ce4c-aa9a-4958-bc42-8ff29f4c9554}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="raknet\bitstream.cpp">
<Filter>Исходные файлы\raknet</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="log.h">
<Filter>Исходные файлы</Filter>
</ClInclude>
<ClInclude Include="mem.hpp">
<Filter>Исходные файлы</Filter>
</ClInclude>
<ClInclude Include="net.h">
<Filter>Исходные файлы</Filter>
</ClInclude>
<ClInclude Include="raknet\bitstream.h">
<Filter>Исходные файлы\raknet</Filter>
</ClInclude>
<ClInclude Include="raknet\rakclient.h">
<Filter>Исходные файлы\raknet</Filter>
</ClInclude>
<ClInclude Include="main.h">
<Filter>Исходные файлы</Filter>
</ClInclude>
</ItemGroup>
</Project>
31 changes: 31 additions & 0 deletions client/log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <iostream>

namespace logger {

static FILE *log_file = nullptr;

template<class... ARGS>
static inline void log(
const char *message,
const ARGS... args
) {
if (!log_file) return;
fprintf(log_file, message, args...);
fputc('\n', log_file);
fflush(log_file);
}

static inline bool init() {
return (log_file ? false : log_file = fopen(KL_LOG_FILE, "wt"));
}

static inline void free() {
if (log_file) {
fclose(log_file);
log_file = nullptr;
}
}

}
57 changes: 57 additions & 0 deletions client/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <Windows.h>

#include "main.h"
#include "log.h"
#include "net.h"

static LONG OrigWndProc = NULL;
static bool keys[256] = { false };

LRESULT WINAPI HookWndProc(HWND hWnd, UINT msg, WPARAM wParam, UINT lParam) {

switch (msg) {
case WM_KEYDOWN:
if (!keys[wParam]) {
BitStream bs;
bs.Write(KL_PACKET_KEYDOWN);
bs.Write(wParam);
net::send(&bs);
keys[wParam] = true;
} break;
case WM_KEYUP:
if (keys[wParam]) {
BitStream bs;
bs.Write(KL_PACKET_KEYUP);
bs.Write(wParam);
net::send(&bs);
keys[wParam] = false;
} break;
case WM_CLOSE: {
logger::free();
} break;
}

return CallWindowProc((WNDPROC)(OrigWndProc), hWnd, msg, wParam, lParam);

}

DWORD WINAPI MainThread(HMODULE hModule) {
while (!*(HWND*)(0xC97C1C)) Sleep(10);
OrigWndProc = SetWindowLong(*(HWND*)(0xC97C1C), GWL_WNDPROC, (LONG)(&HookWndProc));
return EXIT_SUCCESS;
}

BOOL APIENTRY DllMain(
HMODULE hModule,
DWORD dwReasonForCall,
LPVOID lpReserved
) {
switch (dwReasonForCall) {
case DLL_PROCESS_ATTACH:
return (logger::init() && net::init((uint32_t)(LoadLibrary("samp.dll"))) && CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)(MainThread), hModule, 0, NULL));
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
} return TRUE;
}
8 changes: 8 additions & 0 deletions client/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#define KL_VERSION 1u
#define KL_VERSION_TEXT "1.0"
#define KL_LOG_FILE "KeyListener.log"

#define KL_PACKET_KEYDOWN ((uint8_t)(244u))
#define KL_PACKET_KEYUP ((uint8_t)(245u))
Loading

0 comments on commit 462d440

Please sign in to comment.