Bug fixes, removed silentpatch checks

1. Added a mouse fix ( no longer need silentpatch)
2. Fixed issues with the radio scroll
This commit is contained in:
Grinch_ 2021-06-20 17:23:24 +06:00
parent 157f22e681
commit f863451777
6 changed files with 94 additions and 40 deletions

View File

@ -159,15 +159,16 @@ void CheatMenu::ApplyStyle()
void MenuThread(void* param)
{
static bool game_init = false;
static bool bGameInit = false;
Hook::ApplyMouseFix();
// Wait till the game is initialized
Events::initGameEvent += []
{
game_init = true;
bGameInit = true;
};
while (!game_init)
while (!bGameInit)
Sleep(1000);
if (GetModuleHandle("SAMP.dll"))
@ -176,13 +177,6 @@ void MenuThread(void* param)
return;
}
// SP fixes some mouse issues
if (!GetModuleHandle("SilentPatchSA.asi"))
{
MessageBox(RsGlobal.ps->window, "SilentPatch isn't installed. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR);
return;
}
flog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: "
GITHUB_LINK "\n" << std::endl;
CFastman92limitAdjuster::Init();

View File

@ -146,44 +146,19 @@ HRESULT Hook::Dx11Handler(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Fl
return oPresent11(pSwapChain, SyncInterval, Flags);
}
// Thanks imring
void Hook::ShowMouse(bool state)
{
if (state)
{
CPad::NewMouseControllerState.X = 0;
CPad::NewMouseControllerState.Y = 0;
patch::SetUChar(0x6194A0, 0xC3);
// Don't nop this, WindowedMode uses it
// patch::Nop(0x53F417, 5); // don't call CPad__getMouseState
patch::SetUChar(0x746ED0, 0xC3);
patch::SetRaw(0x53F41F, (void*)"\x33\xC0\x0F\x84", 4); // disable camera mouse movement
}
else
{
if (m_bMouseVisibility != m_bShowMouse)
{
patch::SetUChar(0x6194A0, 0xE9); // jmp setup
patch::SetUChar(0x746ED0, 0xA1);
patch::SetRaw(0x53F41F, (void*)"\x85\xC0\x0F\x8C", 4);
// xor eax, eax -> test eax, eax , enable camera mouse movement
// jz loc_53F526 -> jl loc_53F526
}
}
if (m_bMouseVisibility != m_bShowMouse)
{
CPad::ClearMouseHistory();
CPad::UpdatePads();
// TODO: Replace this with windows cursor
ImGui::GetIO().MouseDrawCursor = state;
CPad::NewMouseControllerState.X = 0;
CPad::NewMouseControllerState.Y = 0;
m_bMouseVisibility = m_bShowMouse;
Hook::ApplyMouseFix(); // Reapply the patches
}
}
@ -216,3 +191,86 @@ Hook::~Hook()
ImGui::DestroyContext();
kiero::shutdown();
}
struct Mouse
{
unsigned int x, y;
unsigned int wheelDelta;
char k1, k2, k3, k4, k5;
};
struct MouseInfo
{
int x, y, wheelDelta;
} mouseInfo;
static BOOL __stdcall _SetCursorPos(int X, int Y)
{
if (Hook::m_bShowMouse || GetActiveWindow() != RsGlobal.ps->window)
return 1;
mouseInfo.x = X;
mouseInfo.y = Y;
return SetCursorPos(X, Y);
}
int __cdecl _psMouseSetPos(RwV2d* pos)
{
return _SetCursorPos(pos->x, pos->y);
}
static LRESULT __stdcall _DispatchMessage(MSG* lpMsg)
{
if (lpMsg->message == WM_MOUSEWHEEL && !Hook::m_bShowMouse)
{
mouseInfo.wheelDelta += *(int*)(&lpMsg->wParam);
}
return DispatchMessageA(lpMsg);
}
static int _cdecl _GetMouseState(Mouse* pMouse)
{
if (Hook::m_bShowMouse)
return -1;
struct tagPOINT Point;
pMouse->x = 0;
pMouse->y = 0;
pMouse->wheelDelta = mouseInfo.wheelDelta;
GetCursorPos(&Point);
if (mouseInfo.x >= 0)
pMouse->x = int(Point.x - mouseInfo.x);
if (mouseInfo.y >= 0)
pMouse->y = int(Point.y - mouseInfo.y);
mouseInfo.wheelDelta = 0;
pMouse->k1 = (GetAsyncKeyState(1) >> 8);
pMouse->k2 = (GetAsyncKeyState(2) >> 8);
pMouse->k3 = (GetAsyncKeyState(4) >> 8);
pMouse->k4 = (GetAsyncKeyState(5) >> 8);
pMouse->k5 = (GetAsyncKeyState(6) >> 8);
return 0;
}
void Hook::ApplyMouseFix()
{
patch::ReplaceFunctionCall(0x53F417, _GetMouseState);
patch::Nop(0x57C59B, 1);
patch::ReplaceFunctionCall(0x57C59C, _SetCursorPos);
patch::Nop(0x81E5D4, 1);
patch::ReplaceFunctionCall(0x81E5D5, _SetCursorPos);
patch::RedirectJump(0x6194A0, _psMouseSetPos);
patch::Nop(0x748A7C, 1);
patch::ReplaceFunctionCall(0x748A7D, _DispatchMessage);
patch::SetChar(0x746A08, 32); // diMouseOffset
patch::SetChar(0x746A58, 32); // diDeviceoffset
}

View File

@ -23,9 +23,11 @@ private:
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static void ShowMouse(bool state);
protected:
public:
inline static bool m_bShowMouse = false;
inline static std::function<void()> window_callback = nullptr;
static void ApplyMouseFix();
Hook();
~Hook();
};

View File

@ -2,5 +2,5 @@
#define MENU_NAME "Cheat Menu"
#define MENU_VERSION_NUMBER "2.7"
#define MENU_VERSION MENU_VERSION_NUMBER"-beta"
#define BUILD_NUMBER "20210615"
#define BUILD_NUMBER "20210620"
#define MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")"

View File

@ -177,7 +177,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
<AdditionalDependencies>d3d9.lib;d3d11.lib;XInput9_1_0.lib</AdditionalDependencies>
<AdditionalDependencies>d3d9.lib;d3d11.lib</AdditionalDependencies>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">

View File

@ -21,7 +21,7 @@ Get stable binaries from [here](https://github.com/user-grinch/Cheat-Menu/releas
1. Install [DirectX9](https://www.microsoft.com/en-us/download/details.aspx?id=35) & [Visual C++ Redistributable 2019 x86](hhttps://aka.ms/vs/16/release/vc_redist.x86.exe) if not already installed.
2. If your game version isn't v1.0 then you'll need to [downgrade](https://gtaforums.com/topic/927016-san-andreas-downgrader/).
3. Install [asi loader](https://www.gtagarage.com/mods/show.php?id=21709) & [silent patch](https://gtaforums.com/topic/669045-silentpatch/)
3. Install [asi loader](https://www.gtagarage.com/mods/show.php?id=21709)
4. Download **CheatMenu.7z** and extract everything in game directory (replace if necessary).
## Building