Прострел через Землю for Rust C#

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
9 Фев 2021
Сообщения
91
Реакции
25
C#:
Expand Collapse Copy
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ff : BaseMovement
{
private void Start()
    {
        byte[] ds = { 0x55, 0x48, 0x8b, 0xec, 0x56, 0x57, 0x41, 0x56, 0x48, 0x83, 0xec, 0x08 };
        gg = new DumbHook(typeof(GameTrace), "TraceAll", typeof(ff), "TraceAll", typeof(ff), "TraceAllTrampoline", ds);
        gg.Hook();
    }
    DumbHook gg;
public static void TraceAll(HitTest test, List<TraceInfo> traces, int layerMask = -5)
    {
        if (CFG.Setting.grass12)//Прострел через дерево
        {
            layerMask &= CFG.Setting.grass ? -1073741825 : -5;
        }
        layerMask &= CFG.Setting.grass ? -8388609 : -5;//если память не изменяте это через объекты
        layerMask &= CFG.Setting.grass ? -65537 : -5;//через землю

        if (CFG.Setting.grass ? test.HitMaterial != "Flesh" : true)
        {
            List<RaycastHit> list = Facepunch.Pool.GetList<RaycastHit>();
            Vector3 origin = test.AttackRay.origin;
            Vector3 direction = test.AttackRay.direction;
            float maxDistance = test.MaxDistance;
            float radius = test.Radius;
            if ((layerMask & 16384) != 0)
            {
                layerMask &= -16385;
                GamePhysics.TraceAllUnordered(new Ray(origin - direction * 5f, direction), radius, list, maxDistance + 5f, 16384, QueryTriggerInteraction.UseGlobal);
                for (int i = 0; i < list.Count; i++)
                {
                    RaycastHit raycastHit = list[i];
                    raycastHit.distance -= 5f;
                    list[i] = raycastHit;
                }
            }
            GamePhysics.TraceAllUnordered(new Ray(origin, direction), radius, list, maxDistance, layerMask, QueryTriggerInteraction.UseGlobal);
            for (int j = 0; j < list.Count; j++)
            {
                RaycastHit hit = list[j];
                Collider collider = hit.GetCollider();
                if (!collider.isTrigger)
                {
                    ColliderInfo component = collider.GetComponent<ColliderInfo>();
                    if (!component || component.Filter(test))
                    {
                        BaseCollision component2 = collider.GetComponent<BaseCollision>();
                        if (component2 != null)
                        {
                            component2.TraceTest(test, traces);
                        }
                        else if (hit.distance > 0f)
                        {
                            TraceInfo traceInfo = default(TraceInfo);
                            traceInfo.valid = true;
                            traceInfo.distance = hit.distance;
                            traceInfo.partID = 0U;
                            traceInfo.point = hit.point;
                            traceInfo.normal = hit.normal;
                            traceInfo.collider = collider;
                            traceInfo.material = collider.GetMaterialAt(hit.point);
                            traceInfo.entity = collider.gameObject.ToBaseEntity();
                            traceInfo.bone = Model.GetTransform(collider.transform, hit.point, traceInfo.entity);
                            if (!traceInfo.entity || (traceInfo.entity.isClient && traceInfo.entity != test.ignoreEntity))
                            {
                                traces.Add(traceInfo);
                            }
                        }
                    }
                }
            }
            traces.Sort((TraceInfo a, TraceInfo b) => a.distance.CompareTo(b.distance));
            Facepunch.Pool.FreeList<RaycastHit>(ref list);
        }
    }
    public static void TraceAllTrampoline(HitTest test, List<TraceInfo> traces, int layerMask = -5)
    {
        int a = 12;
        int b = 9;
        int c = 12 * 9 - 4;
        int d = c * a - 15;
        int e = d + a;
        int f = b + c;
        a = b + 12;
        b = c - 4;
        d = a + b;
        e = a + c + d;
    }
    }
C#:
Expand Collapse Copy
using System;
using System.Reflection;
using System.Runtime.InteropServices;

class DumbHook
{

    private byte[] original;

    public MethodInfo OriginalMethod { get; private set; }
    public MethodInfo HookMethod { get; private set; }
    public MethodInfo OriginalNew { get; private set; }
    public DumbHook()
    {
        original = null;
        OriginalMethod = HookMethod = null;
    }
    public DumbHook(MethodInfo orig, MethodInfo hook, MethodInfo orignew)
    {
        original = null;
        Init(orig, hook, orignew);
    }

    public DumbHook(Type typeOrig, string nameOrig, Type typeHook, string nameHook, Type typeOrigNew, string nameOrigNew, byte[] orig)
    {

        original = new byte[orig.Length];
        original = orig;
      
        if (nameOrig == "TraceAll")
        {
            Init(typeOrig.GetMethod(nameOrig), typeHook.GetMethod(nameHook), typeOrigNew.GetMethod(nameOrigNew));
        }
        
    }


    public void Init(MethodInfo orig, MethodInfo hook, MethodInfo orignew)
    {
        if (MethodInfo.Equals(orig, null))
            throw new ArgumentException("Original method is null");

        if (MethodInfo.Equals(hook, null))
            throw new ArgumentException("Hook method is null");

        //  RuntimeHelpers.PrepareMethod(orig.MethodHandle);
        //  RuntimeHelpers.PrepareMethod(hook.MethodHandle);
        // RuntimeHelpers.PrepareMethod(orignew.MethodHandle);

        OriginalMethod = orig;
        HookMethod = hook;
        OriginalNew = orignew;
    }

    unsafe public void Hook()
    {
        if (MethodInfo.Equals(OriginalMethod, null) || MethodInfo.Equals(HookMethod, null))
            throw new ArgumentException("Hook has to be properly Init'd before use");

        IntPtr functionOriginal = OriginalMethod.MethodHandle.GetFunctionPointer();
        IntPtr functionHook = HookMethod.MethodHandle.GetFunctionPointer();
        IntPtr functionTrampoline = OriginalNew.MethodHandle.GetFunctionPointer();

        uint oldProt;

        Import.VirtualProtect(functionTrampoline, (uint)original.Length + 12, 0x40, out oldProt);
        {
            byte* ptr = (byte*)functionTrampoline;

            for (int i = 0; i < original.Length; ++i)
            {
                ptr[i] = original[i];
            }

            *(ptr + original.Length) = 0x48;
            *(ptr + original.Length + 1) = 0xb8;
            *(IntPtr*)(ptr + original.Length + 2) = (IntPtr)(functionOriginal.ToInt64() + original.Length);
            *(ptr + original.Length + 10) = 0xff;
            *(ptr + original.Length + 11) = 0xe0;
        }
        Import.VirtualProtect(functionTrampoline, (uint)original.Length + 12, oldProt, out oldProt);

        Import.VirtualProtect(functionOriginal, 12, 0x40, out oldProt);
        {
            byte* ptr = (byte*)functionOriginal;

            // movabs rax, addy
            // jmp rax
            *(ptr) = 0x48;
            *(ptr + 1) = 0xb8;
            *(IntPtr*)(ptr + 2) = functionHook;
            *(ptr + 10) = 0xff;
            *(ptr + 11) = 0xe0;
        }
        Import.VirtualProtect(functionOriginal, 12, oldProt, out oldProt);

    }

    unsafe public void Unhook()
    {

        IntPtr functionOriginal = OriginalMethod.MethodHandle.GetFunctionPointer();
        IntPtr functionHook = HookMethod.MethodHandle.GetFunctionPointer();
        IntPtr functionTrampoline = OriginalNew.MethodHandle.GetFunctionPointer();

        uint oldProt;

        Import.VirtualProtect(functionOriginal, 12, 0x40, out oldProt);
        {
            byte* ptr = (byte*)functionOriginal;
            for (int x = 0; x < original.Length; x++)
            {
                *(ptr + x) = original[x];
            }
        }
        Import.VirtualProtect(functionOriginal, 12, oldProt, out oldProt);

    }

    internal class Import
    {
        [DllImport("kernel32.dll", SetLastError = true)]
        internal static extern bool VirtualProtect(IntPtr address, uint size, uint newProtect, out uint oldProtect);

        [DllImport("kernel32.dll", SetLastError = true)]
        internal static extern IntPtr VirtualAlloc(UInt32 lpAddress, UInt32 dwSize, AllocationType lAllocationType, MemoryProtection flProtect);

        [Flags]
        public enum AllocationType
        {
            Commit = 0x1000,
            Reserve = 0x2000,
            Decommit = 0x4000,
            Release = 0x8000,
            Reset = 0x80000,
            Physical = 0x400000,
            TopDown = 0x100000,
            WriteWatch = 0x200000,
            LargePages = 0x20000000
        }
        [Flags()]

        public enum MemoryProtection : uint
        {
            EXECUTE = 0x10,
            EXECUTE_READ = 0x20,
            EXECUTE_READWRITE = 0x40,
            EXECUTE_WRITECOPY = 0x80,
            NOACCESS = 0x01,
            READONLY = 0x02,
            READWRITE = 0x04,
            WRITECOPY = 0x08,
            GUARD_Modifierflag = 0x100,
            NOCACHE_Modifierflag = 0x200,
            WRITECOMBINE_Modifierflag = 0x400
        }
    }
}
 
Как пользоватся этим?
 
Назад
Сверху Снизу