~ruther/NosSmooth

0b990c826d355e8ce394813f125ba53380d8db65 — František Boháček 3 years ago 8d6c049
fix(localbinding): represent walk function correctly to prevent bug of not walking
1 files changed, 15 insertions(+), 7 deletions(-)

M Local/NosSmooth.LocalBinding/Objects/CharacterBinding.cs
M Local/NosSmooth.LocalBinding/Objects/CharacterBinding.cs => Local/NosSmooth.LocalBinding/Objects/CharacterBinding.cs +15 -7
@@ 20,11 20,11 @@ public class CharacterBinding
{
        [Function
    (
        new[] { FunctionAttribute.Register.eax, FunctionAttribute.Register.edx },
        new[] { FunctionAttribute.Register.eax, FunctionAttribute.Register.edx, FunctionAttribute.Register.ecx },
        FunctionAttribute.Register.eax,
        FunctionAttribute.StackCleanup.Callee
    )]
    private delegate void WalkDelegate(IntPtr characterObject, int position, int unknown = 1);
    private delegate bool WalkDelegate(IntPtr characterObject, int position, short unknown0 = 0, int unknown1 = 1);

    /// <summary>
    /// Create the network binding with finding the network object and functions.


@@ 119,19 119,27 @@ public class CharacterBinding
    /// <param name="x">The x coordinate.</param>
    /// <param name="y">The y coordinate.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Result Walk(ushort x, ushort y)
    public Result<bool> Walk(ushort x, ushort y)
    {
        int param = (y << 16) | x;
        _originalWalk(GetCharacterAddress(), param);
        return Result.FromSuccess();
        try
        {
            return _originalWalk(GetCharacterAddress(), param);
        }
        catch (Exception e)
        {
            return e;
        }
    }

    private void WalkDetour(IntPtr characterObject, int position, int unknown)
    private bool WalkDetour(IntPtr characterObject, int position, short unknown0, int unknown1)
    {
        var result = WalkCall?.Invoke((ushort)(position & 0xFFFF), (ushort)((position >> 16) & 0xFFFF));
        if (result ?? true)
        {
            _originalWalk(characterObject, position, unknown);
            return _originalWalk(characterObject, position, unknown0, unknown1);
        }

        return false;
    }
}
\ No newline at end of file