From 2473ce81192128c75490b6080e4dcf11a629cc9b Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 28 Dec 2015 00:06:15 +0100 Subject: [PATCH] Feeder. --- .gitignore | 3 +- iw4.sln | 6 +- iw4/Components/Feeder.cpp | 287 ++++++++++++++++++++++++++++++++++++++ iw4/Components/Feeder.hpp | 51 +++++++ iw4/Components/Loader.cpp | 1 + iw4/Components/Loader.hpp | 1 + iw4/iw4.vcxproj | 20 +-- iw4/iw4.vcxproj.filters | 6 + iw4/iw4.vcxproj.user | 2 +- 9 files changed, 363 insertions(+), 14 deletions(-) create mode 100644 iw4/Components/Feeder.cpp create mode 100644 iw4/Components/Feeder.hpp diff --git a/.gitignore b/.gitignore index 44c814bb..f42aa55f 100644 --- a/.gitignore +++ b/.gitignore @@ -56,8 +56,7 @@ Temporary Items *.suo # Additional stuff -Release -iw4/Release +Normal # IDA # ========================= diff --git a/iw4.sln b/iw4.sln index 761e7914..e9a2632a 100644 --- a/iw4.sln +++ b/iw4.sln @@ -7,11 +7,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "iw4", "iw4\iw4.vcxproj", "{ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Release|Win32 = Release|Win32 + Normal|Win32 = Normal|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {38B4FC13-CEBC-4099-8698-3E62943C1EAA}.Release|Win32.ActiveCfg = Release|Win32 - {38B4FC13-CEBC-4099-8698-3E62943C1EAA}.Release|Win32.Build.0 = Release|Win32 + {38B4FC13-CEBC-4099-8698-3E62943C1EAA}.Normal|Win32.ActiveCfg = Normal|Win32 + {38B4FC13-CEBC-4099-8698-3E62943C1EAA}.Normal|Win32.Build.0 = Normal|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/iw4/Components/Feeder.cpp b/iw4/Components/Feeder.cpp new file mode 100644 index 00000000..1a0de92e --- /dev/null +++ b/iw4/Components/Feeder.cpp @@ -0,0 +1,287 @@ +#include "..\STDInclude.hpp" + +namespace Components +{ + Feeder::Container Feeder::Current; + std::map Feeder::Feeders; + + void Feeder::Add(float feeder, Feeder::GetItemCount_t itemCountCb, Feeder::GetItemText_t itemTextCb, Feeder::Select_t selectCb) + { + Feeder::Feeders[feeder] = { itemCountCb, itemTextCb, selectCb }; + } + + const char* Feeder::GetItemText() + { + if (Feeder::Feeders.find(Feeder::Current.Num) != Feeder::Feeders.end()) + { + return Feeder::Feeders[Feeder::Current.Num].GetItemText(Feeder::Current.Index, Feeder::Current.Column); + } + + return nullptr; + } + + int Feeder::GetItemCount() + { + if (Feeder::Feeders.find(Feeder::Current.Num) != Feeder::Feeders.end()) + { + return Feeder::Feeders[Feeder::Current.Num].GetItemCount(); + } + + return 0; + } + + bool Feeder::SetItemSelection() + { + if (Feeder::Feeders.find(Feeder::Current.Num) != Feeder::Feeders.end()) + { + Feeder::Feeders[Feeder::Current.Num].Select(Feeder::Current.Index); + return true; + } + + return false; + } + + bool Feeder::CheckFeeder() + { + if (Feeder::Current.Num == 15.0f) return false; + return (Feeder::Feeders.find(Feeder::Current.Num) != Feeder::Feeders.end()); + } + + void __declspec(naked) Feeder::SetItemSelectionStub() + { + __asm + { + mov eax, [esp + 08h] + mov Feeder::Current.Num, eax + + mov eax, [esp + 0Ch] + mov Feeder::Current.Index, eax + + call Feeder::SetItemSelection + + test eax, eax + jz continue + + retn + + continue: + fld ds : 739FD0h + + mov eax, 4C25D6h + jmp eax + } + } + + void __declspec(naked) Feeder::GetItemTextStub() + { + __asm + { + mov eax, [esp + 0Ch] + mov Feeder::Current.Num, eax + + mov eax, [esp + 10h] + mov Feeder::Current.Index, eax + + mov eax, [esp + 14h] + mov Feeder::Current.Column, eax + + call Feeder::GetItemText + + test eax, eax + jz continue + + push ebx + mov ebx, [esp + 4 + 28h] + mov dword ptr[ebx], 0 + pop ebx + retn + + continue: + push ecx + fld ds:739FD0h + + mov eax, 4CE9E7h + jmp eax + } + } + + void __declspec(naked) Feeder::GetItemCountStub() + { + __asm + { + mov eax, [esp + 8h] + mov Feeder::Current.Num, eax + + call Feeder::GetItemCount + + test eax, eax + jz continue + + retn + + continue: + push ecx + fld ds:739FD0h + + mov eax, 41A0D7h + jmp eax; + } + } + + void __declspec(naked) Feeder::HandleKeyStub() + { + static int NextClickTime = 0; + + __asm + { + mov ebx, ebp + mov eax, [ebp + 12Ch] + mov Feeder::Current.Num, eax + + push ebx + call Feeder::CheckFeeder + pop ebx + + test eax, eax + jz continueOriginal + + // Get current milliseconds + call Game::Com_Milliseconds + + // Check if allowed to click + cmp eax, NextClickTime + jl continueOriginal + + // Set next allowed click time to current time + 300ms + add eax, 300 + mov NextClickTime, eax + + // Get item cursor position ptr + mov ecx, ebx + add ecx, Game::itemDef_t::cursorPos + + // Get item listbox ptr + mov edx, ebx + add edx, Game::itemDef_t::typeData + + // Get listbox cursor pos + mov edx, [edx] + add edx, Game::listBoxDef_s::startPos + mov edx, [edx] + + // Resolve item cursor pos pointer + mov ebx, [ecx] + + // Check if item cursor pos equals listbox cursor pos + cmp ebx, edx + je returnSafe + + // Update indices if not + mov [ecx], edx + mov Feeder::Current.Index, edx + + call Feeder::SetItemSelection + + returnSafe: + retn + + continueOriginal: + mov eax, 635570h + jmp eax + } + } + + void __declspec(naked) Feeder::MouseEnterStub() + { + __asm + { + mov eax, [edi + 12Ch] + mov Feeder::Current.Num, eax + + call Feeder::CheckFeeder + + test eax, eax + jnz continue + + mov[edi + 130h], esi + + continue: + mov eax, 639D75h + jmp eax + } + } + + void __declspec(naked) Feeder::MouseSelectStub() + { + __asm + { + mov eax, [esp + 08h] + mov Feeder::Current.Num, eax + + call Feeder::CheckFeeder + + test eax, eax + jnz continue + + mov eax, 4C25D0h + jmp eax + + continue: + retn + } + } + + void __declspec(naked) Feeder::PlaySoundStub() + { + __asm + { + mov eax, [edi + 12Ch] + mov Feeder::Current.Num, eax + + call Feeder::CheckFeeder + + test eax, eax + jnz continue + + mov eax, 685E10h + jmp eax + + continue: + retn + } + } + + Feeder::Feeder() + { + // Get feeder item count + Utils::Hook(0x41A0D0, Feeder::GetItemCountStub, HOOK_JUMP).Install()->Quick(); + + // Get feeder item text + Utils::Hook(0x4CE9E0, Feeder::GetItemTextStub, HOOK_JUMP).Install()->Quick(); + + // Select feeder item + Utils::Hook(0x4C25D0, Feeder::SetItemSelectionStub, HOOK_JUMP).Install()->Quick(); + + // Mouse enter check + Utils::Hook(0x639D6E, Feeder::MouseEnterStub, HOOK_JUMP).Install()->Quick(); + + // Handle key event + Utils::Hook(0x63C5BC, Feeder::HandleKeyStub, HOOK_CALL).Install()->Quick(); + + // Mouse select check + Utils::Hook(0x639D31, Feeder::MouseSelectStub, HOOK_CALL).Install()->Quick(); + + // Play mouse over sound check + Utils::Hook(0x639D66, Feeder::PlaySoundStub, HOOK_CALL).Install()->Quick(); + + // some thing overwriting feeder 2's data + Utils::Hook::Set(0x4A06A9, 0xEB); + + Feeder::Add(2.0f, [] () { return 10; }, [] (int index, int column) { return Utils::VA("%d : %d", index, column); }, [] (int index){}); + } + + Feeder::~Feeder() + { + Feeder::Feeders.clear(); + } +} diff --git a/iw4/Components/Feeder.hpp b/iw4/Components/Feeder.hpp new file mode 100644 index 00000000..26cbd658 --- /dev/null +++ b/iw4/Components/Feeder.hpp @@ -0,0 +1,51 @@ +namespace Components +{ + class Feeder : public Component + { + public: + typedef int(__cdecl * GetItemCount_t)(); + typedef const char* (__cdecl * GetItemText_t)(int index, int column); + typedef void(__cdecl * Select_t)(int index); + + struct Callbacks + { + GetItemCount_t GetItemCount; + GetItemText_t GetItemText; + Select_t Select; + }; + + Feeder(); + ~Feeder(); + const char* GetName() { return "Feeder"; }; + + static void Add(float feeder, GetItemCount_t itemCountCb, GetItemText_t itemTextCb, Select_t selectCb); + + private: + struct Container + { + float Num; + int Index; + int Column; + }; + + static Container Current; + + static void GetItemCountStub(); + static int GetItemCount(); + + static void GetItemTextStub(); + static const char* GetItemText(); + + static void SetItemSelectionStub(); + static bool SetItemSelection(); + + static bool CheckFeeder(); + + static void MouseEnterStub(); + static void MouseSelectStub(); + static void HandleKeyStub(); + static void PlaySoundStub(); + + static std::map Feeders; + }; +} diff --git a/iw4/Components/Loader.cpp b/iw4/Components/Loader.cpp index 105ec995..eb5868fe 100644 --- a/iw4/Components/Loader.cpp +++ b/iw4/Components/Loader.cpp @@ -13,6 +13,7 @@ namespace Components Loader::Register(new Menus()); Loader::Register(new Party()); Loader::Register(new Colors()); + Loader::Register(new Feeder()); Loader::Register(new Logger()); Loader::Register(new Window()); Loader::Register(new Command()); diff --git a/iw4/Components/Loader.hpp b/iw4/Components/Loader.hpp index 3fba0bcf..83c6f104 100644 --- a/iw4/Components/Loader.hpp +++ b/iw4/Components/Loader.hpp @@ -24,6 +24,7 @@ namespace Components #include "Maps.hpp" #include "Menus.hpp" #include "Colors.hpp" +#include "Feeder.hpp" #include "Logger.hpp" #include "Window.hpp" #include "Command.hpp" diff --git a/iw4/iw4.vcxproj b/iw4/iw4.vcxproj index 49f97f86..7a3bf7c7 100644 --- a/iw4/iw4.vcxproj +++ b/iw4/iw4.vcxproj @@ -1,8 +1,8 @@  - - Release + + Normal Win32 @@ -12,7 +12,7 @@ iw4 - + DynamicLibrary false v120 @@ -22,15 +22,17 @@ - + - + false iw4m + $(SolutionDir)$(Configuration)\Bin\ + $(SolutionDir)$(Configuration)\Obj\ - + Level3 NotUsing @@ -59,6 +61,7 @@ + @@ -97,6 +100,7 @@ + @@ -123,8 +127,8 @@ - false - + false + diff --git a/iw4/iw4.vcxproj.filters b/iw4/iw4.vcxproj.filters index caf57206..7bd0217a 100644 --- a/iw4/iw4.vcxproj.filters +++ b/iw4/iw4.vcxproj.filters @@ -134,6 +134,9 @@ Source\Components\Modules + + Source\Components\Modules + @@ -244,5 +247,8 @@ Source\Components\Modules + + Source\Components\Modules + \ No newline at end of file diff --git a/iw4/iw4.vcxproj.user b/iw4/iw4.vcxproj.user index 4a74933c..a67d02b0 100644 --- a/iw4/iw4.vcxproj.user +++ b/iw4/iw4.vcxproj.user @@ -1,6 +1,6 @@  - + iw4m.exe D:\Games\SteamLibrary\steamapps\common\Call of Duty Modern Warfare 2\ WindowsLocalDebugger