From 3e9d5779ca0f68191c28e3596679a219de293ce1 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 16 Aug 2016 20:36:52 +0200 Subject: [PATCH] Lean stuff (unfinished) --- deps/fmt | 2 +- deps/mongoose | 2 +- deps/protobuf | 2 +- src/Components/Loader.cpp | 1 + src/Components/Loader.hpp | 1 + src/Components/Modules/Command.hpp | 3 ++- src/Components/Modules/Lean.cpp | 38 ++++++++++++++++++++++++++++++ src/Components/Modules/Lean.hpp | 22 +++++++++++++++++ src/Game/Functions.cpp | 24 +++++++++++++++++++ src/Game/Functions.hpp | 5 +++- src/Game/Structs.hpp | 13 +++++++++- 11 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 src/Components/Modules/Lean.cpp create mode 100644 src/Components/Modules/Lean.hpp diff --git a/deps/fmt b/deps/fmt index 2bf59a97..f19d8f96 160000 --- a/deps/fmt +++ b/deps/fmt @@ -1 +1 @@ -Subproject commit 2bf59a97c6e65e4963913d9ba2f8d260e5c8fbf5 +Subproject commit f19d8f9655d550234f19c6c1f5a99c7eda798c0e diff --git a/deps/mongoose b/deps/mongoose index 8cdd19bc..ff159bf3 160000 --- a/deps/mongoose +++ b/deps/mongoose @@ -1 +1 @@ -Subproject commit 8cdd19bcaed7f503de7902804d0d96ce51e95a34 +Subproject commit ff159bf30ac1a213c3dd0b0714c7cd07db616ad2 diff --git a/deps/protobuf b/deps/protobuf index 4763e64e..e3891655 160000 --- a/deps/protobuf +++ b/deps/protobuf @@ -1 +1 @@ -Subproject commit 4763e64eb1e72e628ab75a9872f4146fdd2cf765 +Subproject commit e3891655868a465ad0d17ddc2b1ea95dd0a39adf diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 6bbd09f1..e6284704 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -12,6 +12,7 @@ namespace Components Loader::Register(new Auth()); Loader::Register(new Bans()); Loader::Register(new Dvar()); + Loader::Register(new Lean()); Loader::Register(new Maps()); Loader::Register(new News()); Loader::Register(new Node()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 529c5f81..4681166e 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -30,6 +30,7 @@ namespace Components #include "Modules\Auth.hpp" #include "Modules\Bans.hpp" #include "Modules\Dvar.hpp" +#include "Modules\Lean.hpp" #include "Modules\Maps.hpp" #include "Modules\News.hpp" #include "Modules\Flags.hpp" diff --git a/src/Components/Modules/Command.hpp b/src/Components/Modules/Command.hpp index a2c28573..7a4401d8 100644 --- a/src/Components/Modules/Command.hpp +++ b/src/Components/Modules/Command.hpp @@ -30,6 +30,8 @@ namespace Components const char* GetName() { return "Command"; }; #endif + static Game::cmd_function_t* Allocate(); + static void Add(const char* name, Callback* callback); static void AddSV(const char* name, Callback* callback); static void AddRaw(const char* name, void(*callback)()); @@ -43,7 +45,6 @@ namespace Components static std::map> FunctionMap; static std::map> FunctionMapSV; - static Game::cmd_function_t* Allocate(); static void MainCallback(); static void MainCallbackSV(); }; diff --git a/src/Components/Modules/Lean.cpp b/src/Components/Modules/Lean.cpp new file mode 100644 index 00000000..9f84ce1b --- /dev/null +++ b/src/Components/Modules/Lean.cpp @@ -0,0 +1,38 @@ +#include "STDInclude.hpp" + +namespace Components +{ + Game::kbutton_t Lean::in_leanleft; + Game::kbutton_t Lean::in_leanright; + + void Lean::IN_LeanLeft_Up() + { + Game::IN_KeyUp(&Lean::in_leanleft); + } + + void Lean::IN_LeanLeft_Down() + { + Game::IN_KeyDown(&Lean::in_leanleft); + } + + void Lean::IN_LeanRight_Up() + { + Game::IN_KeyUp(&Lean::in_leanright); + } + + void Lean::IN_LeanRight_Down() + { + Game::IN_KeyDown(&Lean::in_leanright); + } + + Lean::Lean() + { + Game::Cmd_AddCommand("+leanleft", Lean::IN_LeanLeft_Down, Command::Allocate(), 1); + Game::Cmd_AddCommand("-leanleft", Lean::IN_LeanLeft_Up, Command::Allocate(), 1); + + Game::Cmd_AddCommand("+leanright", Lean::IN_LeanRight_Down, Command::Allocate(), 1); + Game::Cmd_AddCommand("-leanright", Lean::IN_LeanRight_Up, Command::Allocate(), 1); + + // TODO: Transmit correct button flags in CL_CmdButtons and more? + } +} diff --git a/src/Components/Modules/Lean.hpp b/src/Components/Modules/Lean.hpp new file mode 100644 index 00000000..08fcc1b8 --- /dev/null +++ b/src/Components/Modules/Lean.hpp @@ -0,0 +1,22 @@ +namespace Components +{ + class Lean : public Component + { + public: + Lean(); + +#ifdef DEBUG + const char* GetName() { return "Lean"; }; +#endif + + private: + static Game::kbutton_t in_leanleft; + static Game::kbutton_t in_leanright; + + static void IN_LeanLeft_Up(); + static void IN_LeanLeft_Down(); + + static void IN_LeanRight_Up(); + static void IN_LeanRight_Down(); + }; +} diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index dedaf011..d11a4067 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -430,4 +430,28 @@ namespace Game { Game::SV_GameSendServerCommand(clientNum, 0, Utils::String::VA("%c \"%s\"", 0x67, message.data())); } + + void IN_KeyUp(kbutton_t* button) + { + __asm + { + push esi + mov esi, button + mov eax, 5A5580h + call eax + pop esi + } + } + + void IN_KeyDown(kbutton_t* button) + { + __asm + { + push esi + mov esi, button + mov eax, 5A54E0h + call eax + pop esi + } + } } diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index ef8ed7a3..2b9eff32 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -33,7 +33,7 @@ namespace Game typedef void(__cdecl * CL_SelectStringTableEntryInDvar_f_t)(); extern CL_SelectStringTableEntryInDvar_f_t CL_SelectStringTableEntryInDvar_f; - typedef void(__cdecl * Cmd_AddCommand_t)(const char* name, void(*callback), cmd_function_t* data, char); + typedef void(__cdecl * Cmd_AddCommand_t)(const char* cmdName, void(*function), cmd_function_t* allocedCmd, char); extern Cmd_AddCommand_t Cmd_AddCommand; typedef void(__cdecl * Cmd_AddServerCommand_t)(const char* name, void(*callback), cmd_function_t* data); @@ -512,4 +512,7 @@ namespace Game void Scr_iPrintLn(int clientNum, std::string message); void Scr_iPrintLnBold(int clientNum, std::string message); + + void IN_KeyUp(kbutton_t* button); + void IN_KeyDown(kbutton_t* button); } diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index af01fac0..ed052160 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -136,9 +136,20 @@ namespace Game const char *autoCompleteDir; const char *autoCompleteExt; void(__cdecl *function)(); - int pad; + int unknown; } cmd_function_t; +#pragma pack(push, 4) + struct kbutton_t + { + int down[2]; + unsigned int downtime; + unsigned int msec; + bool active; + bool wasPressed; + }; +#pragma pack(pop) + typedef struct { char type;