~ruther/NosSmooth

ref: 53f156e12bb77c47d1bb14c17e23bf4d01b02565 NosSmooth/Local/NosSmooth.LocalCore/Character.cpp -rw-r--r-- 1.3 KiB
53f156e1 — František Boháček feat: add walk command handling to service collection 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "Character.h"
using namespace NosSmoothCore;

const BYTE WALK_OBJECT_PATTERN[] = { 0x33, 0xC9, 0x8B, 0x55, 0xFC, 0xA1, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00 };
const BYTE WALK_FUNCTION_PATTERN[] = { 0x55, 0x8B, 0xEC, 0x83, 0xC4, 0xEC, 0x53, 0x56, 0x57, 0x66, 0x89, 0x4D, 0xFA };

LPCSTR WALK_OBJECT_MASK = "xxxxxx????x????";
LPCSTR WALK_FUNCTION_MASK = "xxxxxxxxxxxxx";

Character::Character(ModuleHook moduleHook)
{
    auto walkFunction = moduleHook.FindPattern(WALK_FUNCTION_PATTERN, WALK_FUNCTION_MASK);
    auto walkObject = *(unsigned int*)(moduleHook.FindPattern(WALK_OBJECT_PATTERN, WALK_OBJECT_MASK) + 0x6);

    if (walkFunction == 0)
    {
        throw "Could not find walk function.";
    }

    if (walkObject == 0)
    {
        throw "Could not find player object.";
    }

    _walkFunction = walkFunction;
    _playerObject = walkObject;
}

void CallWalk(int x, int y, unsigned int playerObject, unsigned int walkFunction)
{
    DWORD position = (y << 16) | x;

    __asm
    {
        push 1
        xor ecx, ecx
        mov edx, position
        mov eax, dword ptr ds : [playerObject]
        mov eax, dword ptr ds : [eax]
        call walkFunction
    }
}

void Character::Walk(int x, int y)
{
    CallWalk(x, y, _playerObject, _walkFunction);
}
Do not follow this link