Skip to content

Instantly share code, notes, and snippets.

@Jadd
Created November 13, 2017 01:01
Show Gist options
  • Save Jadd/41b4bc2ace3d8b97fc7deaa126bf3a26 to your computer and use it in GitHub Desktop.
Save Jadd/41b4bc2ace3d8b97fc7deaa126bf3a26 to your computer and use it in GitHub Desktop.

Revisions

  1. Jadd created this gist Nov 13, 2017.
    29 changes: 29 additions & 0 deletions MaxViewDetection.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    using Afterglow.Internal.Client.Objects;
    using Albion.Common.Photon;
    using UnityEngine;

    namespace Afterglow.Internal.Client.Detection {
    public class MaxViewDetection : PacketHandler {
    protected override void OnPacketEvent(PacketInfo packet) {
    if (packet.Type != PacketType.OperationRequest)
    return;

    if (packet.Opcode != OperationCodes.Move)
    return;

    var movement = (acc) packet.Data;
    var movementPosition = new Vector2(movement.ayo[0], movement.ayo[1]);
    var movementClick = new Vector2(movement.ayq[0], movement.ayq[1]);

    // The distance does not indicate that we can see further than 10 units, so we're safe!
    if (Vector2.Distance(movementPosition, movementClick) <= 10f)
    return;

    // Limit the destination to 9-10 units; remove the interaction target.
    movementClick = Vector2.MoveTowards(movementPosition, movementClick, Random.Range(9f, 10f));
    movement.ayq[0] = movementClick.x;
    movement.ayq[1] = movementClick.y;
    movement.ays = 0;
    }
    }
    }