Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Flux.Helpers;
- using System;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- namespace Flux.Game
- {
- class UnrealClasses
- {
- #region Structs
- [StructLayout(LayoutKind.Explicit)]
- public struct UWorld //class UWorld
- {
- [FieldOffset(0x30)]
- public IntPtr pPersistentLevel; //ULevel* PersistentLevel;
- [FieldOffset(0x0160)]
- public IntPtr pOwningGameInstance; //class UGameInstance* OwningGameInstance;
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct ULevel
- {
- [FieldOffset(0x98)] //I think I manually found this in reclass, check PM's with CorM
- public TArray<AActor> AActors;
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct AActor
- {
- [FieldOffset(0x00)]
- public IntPtr BaseOffset;
- [FieldOffset(0x18)]
- public int Id;
- [FieldOffset(0x0140)] //AActor: class APawn* Instigator;
- public IntPtr pPawn;
- [FieldOffset(0x158)]
- public IntPtr pRootComponent; //AActor: class USceneComponent* RootComponent;
- [FieldOffset(0x0338)]
- public IntPtr pPlayerState; //AController: class APlayerState* PlayerState;
- [FieldOffset(0x07B0)] //AINSCharacter: float Health;
- public float Health;
- [FieldOffset(0x0C68)]
- public IntPtr pCurrentWeapon; //AINSSoldier: class AItemEquipable* CurrentWeapon;
- [FieldOffset(0x1688)]
- public float SwayFactor; //AINSSoldier: float SwayFactor;
- [FieldOffset(0x173F)]
- public byte bInRestrictedArea; //AINSSoldier: bool bInRestrictedArea;
- [FieldOffset(0x1740)]
- public byte RestrictedAreaCount; //AINSSoldier: unsigned char RestrictedAreaCount;
- [FieldOffset(0x1741)]
- public byte bOutsidePlayableArea; //AINSSoldier: bool bOutsidePlayableArea;
- [FieldOffset(0x1742)]
- public byte PlayableAreaCount; //AINSSoldier: unsigned char PlayableAreaCount;
- [FieldOffset(0x1744)]
- public float PlayableAreaLeavetime; //AINSSoldier: float PlayableAreaLeaveTime;
- [FieldOffset(0x1748)]
- public float PlayableAreaKillTime; //AINSSoldier: float PlayableAreaKillTime;
- [FieldOffset(0x174C)]
- public float RestrictedAreaEnterTime; //AINSSoldier: float RestrictedAreaEnterTime;
- [FieldOffset(0x1750)]
- public float WeaponRestrictionTime; //AINSSoldier: float WeaponRestrictionTime;
- public Vector3 Location
- {
- get
- {
- return this.RootComponent.RelativeLocation;
- }
- }
- public bool IsAlive
- {
- get
- {
- return this.Health > 0;
- }
- }
- public APawn Pawn
- {
- get
- {
- return M.Read<APawn>(this.pPawn);
- }
- }
- public bool InGame
- {
- get
- {
- return true;
- }
- }
- public USceneComponent RootComponent
- {
- get
- {
- return M.Read<USceneComponent>(this.pRootComponent);
- }
- }
- public static IntPtr g_pLocalPlayer = IntPtr.Zero;
- public static AActor GetLocalPlayer()
- {
- if (g_pLocalPlayer != IntPtr.Zero)
- {
- var localplayer = M.Read<AActor>(g_pLocalPlayer);
- localplayer.BaseOffset = g_pLocalPlayer;
- return localplayer;
- }
- return M.Read<AActor>(g_pLocalPlayer);
- }
- public AItemFirearm CurrentWeapon
- {
- get
- {
- return M.Read<AItemFirearm>(this.pCurrentWeapon);
- }
- }
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct AItemFirearm
- {
- [FieldOffset(0x3128)]
- public FFirearmConfig WeaponConfig; //AItemFirearm: struct FFirearmConfig WeaponConfig;
- }
- [StructLayout(LayoutKind.Sequential)]
- public unsafe struct FFirearmConfig //struct FFirearmConfig
- {
- public IntPtr ProjectileClass;
- public float MuzzleVelocity;
- public byte bForceSimpleBulletcollision;
- public fixed byte UnknownData00[0x3];
- public float TimeBetweenShots;
- public float InitialShotDelay;
- public byte bFireprojectileOnNotify;
- public fixed byte UnknownData01[0x3];
- public float FireProjectileDelay;
- public byte bLockSightsInFireDelay;
- public fixed byte UnknownData02[0x3];
- public float ImminentShotTolerance;
- public byte bSupportsSpeedReload;
- public fixed byte UnknownData03[0x3];
- public float ReloadInterruptDuration;
- public byte bCanAmmoCheck;
- public fixed byte UnknownData04[0x3];
- public float AmmoCheckDuration;
- public float BoltCycleTime;
- public float BoltCycleSequenceTime;
- public float BoltSpeed;
- public float BarrelLength;
- public float BarrelLengthTraceStart;
- public float BarrelObstructionThreshhold;
- public byte bAllowFireDuringMelee;
- public fixed byte UnknownData05[0x3];
- public int Firemodes;
- public byte bOverrideDefaultFiremode;
- public byte DefaultFiremode;
- public byte Burstrounds;
- public fixed byte UnknownData06[0x1];
- public float BurstDelay;
- public float FiremodeCycleDuration;
- public float FiremodeCycleGraceTime;
- public byte bTerminateBurstOnTriggerRelease;
- public byte bResetBurstOnTermination;
- public byte bAllowAimDownSights;
- public fixed byte UnknownData07[0x1];
- public float AimDownSightsTime;
- public float AimDownSightsFOV;
- public float AimDownSightsViewModelFOV;
- public float AimDownSightsViewModelFocusFOV;
- public float AimDownSightsViewModelDistance;
- public float AimDownSightsViewModelAngle;
- public float FocusFOV;
- public float FocusTime;
- public float ScopeFOV;
- public byte bAverageFireRate;
- public fixed byte UnknownData08[0x3];
- public Vector2 RecoilLateralRange;
- public Vector2 RecoilVerticalRange;
- public Vector2 RecoilRollRange;
- public Vector2 RecoilAimPunchRange;
- public float RecoilRestDelay;
- public float RecoilRestRate;
- public float RecoilRollRestRate;
- public float RecoilAdditionalRestPerShot;
- public float RecoilPunchAdditiveFactor;
- public int RecoilMaxShots;
- public float RecoilShotResetTime;
- public fixed byte WeightCurve[0x88];
- public float AimingRecoilFactor;
- public fixed byte UnknownData09[0x4];
- public fixed byte LeaningRecoilWeightFactor[0x88];
- public float CrouchedRecoilFactor;
- public float ProneRecoilFactor;
- public fixed byte StaminaRecoilWeightFactor[0x88];
- public float FocusRecoilFactor;
- public fixed byte UnknownData10[0x4];
- public fixed byte MovementRecoilWeightFactor[0x88];
- public float MovementAimRecoilFactor;
- public float RecoilMaxFactor;
- public float RecoilFreeaimVerticalFrac;
- public float RecoilFreeaimLateralFrac;
- public float BurstRecoilFactor;
- public float SwayMagnitude;
- public float SwapSpeed;
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct APawn
- {
- [FieldOffset(0x0350)]
- public IntPtr pPlayerState; //APawn: class APlayerState* PlayerState;
- [FieldOffset(0x0390)]
- public IntPtr pMesh; //ACharacter: class USkeletalMeshComponent* Mesh;
- public APlayerState PlayerState
- {
- get
- {
- return M.Read<APlayerState>(this.pPlayerState);
- }
- }
- public USkeletalMeshComponent MeshComponent
- {
- get
- {
- return M.Read<USkeletalMeshComponent>(this.pMesh);
- }
- }
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct USkeletalMeshComponent
- {
- [FieldOffset(0x06BE)]
- public byte bRecentlyRendered; //USkinnedMeshComponent: unsigned char bRecentlyRendered : 1;
- public bool RecentlyRendered
- {
- get
- {
- var bitField = this.bRecentlyRendered;
- bitField >>= 4;
- bitField &= 1;
- return bitField == 1 ? true : false;
- }
- }
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct APlayerState
- {
- [FieldOffset(0x0460)]
- public byte isPlaying; //AINSPlayerState: bool bIsPlaying;
- [FieldOffset(0x690)]
- public byte teamId; //AINSPlayerState: unsigned char TeamId;
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct UGameInstance
- {
- [FieldOffset(0x38)]
- public IntPtr pULocalPlayer; //TArray<class ULocalPlayer*> LocalPlayers
- public ULocalPlayer LocalPlayer
- {
- get
- {
- IntPtr pLocalPlayer = M.Read<IntPtr>(this.pULocalPlayer);
- var result = M.Read<ULocalPlayer>(pLocalPlayer);
- result.pBase = pLocalPlayer;
- return result;
- }
- }
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct ULocalPlayer
- {
- [FieldOffset(0x00)]
- public IntPtr pBase;
- [FieldOffset(0x30)]
- public IntPtr pPlayerController; //UPlayer: class APlayerController* PlayerController;
- [FieldOffset(0x70)]
- public IntPtr pViewportClient; //ULocalPlayer: class UGameViewportClient* ViewportClient;
- // fixed byte UnknownData01[0x1C];
- //I think this is NULL / garbage currently, it honestly doesn't make a difference.
- //I get the location of my localplayer via the AActor struct's USceneComponent, not ULocalPlayer
- [FieldOffset(0x78)]
- public Vector3 Location;
- public APlayerController PlayerController
- {
- get
- {
- return M.Read<APlayerController>(this.pPlayerController);
- }
- }
- public UGameViewportClient ViewportClient
- {
- get
- {
- return M.Read<UGameViewportClient>(this.pViewportClient);
- }
- }
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct UGameViewportClient
- {
- //this is the actual UWorld. In UE4 what they're doing is giving you a global world PROXY
- //however you're not actually supposed to use this like you would a UWorld. That's why
- //you have to reverse the proxy, and then find the actual world
- [FieldOffset(0x0078)]
- public IntPtr pUWorld; //class UWorld* World;
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct APlayerController
- {
- [FieldOffset(0x03B0)] //APlayerController: class APawn* AcknowledgedPawn;
- public IntPtr pLocalPlayer;
- //class AController : public AActor
- //struct FRotator ControlRotation;
- [FieldOffset(0x0398)]
- public FRotator ControlRotation;
- [FieldOffset(0x03C8)]
- public IntPtr pPlayerCameraManager; //APlayerController: class APlayerCameraManager* PlayerCameraManager;
- public APlayerCameraManager PlayerCameraManager
- {
- get
- {
- return M.Read<APlayerCameraManager>(pPlayerCameraManager);
- }
- }
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct APlayerCameraManager
- {
- [FieldOffset(0x0348)]
- public float DefaultFOV; //float DefaultFOV;
- [FieldOffset(0x0350)]
- public float DefaultOrthoWidth; //float DefaultOrthoWidth;
- [FieldOffset(0x0358)]
- public float DefaultAspectRatio; //float DefaultAspectRatio;
- [FieldOffset(0x0EC0)]
- public FCameraCacheEntry CameraCache; //struct FTViewTarget ViewTarget;
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct FCameraCacheEntry
- {
- [FieldOffset(0x10)]
- public FMinimalViewInfo POV;
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct FMinimalViewInfo
- {
- public Vector3 Location; // 0x0000(0x000C) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
- public FRotator Rotation; // 0x000C(0x000C) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
- public float FOV; // 0x0018(0x0004) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
- public float DesiredFOV; // 0x001C(0x0004) (ZeroConstructor, Transient, IsPlainOldData)
- public float OrthoWidth; // 0x001C(0x0004) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
- public float OrthoNearClipPlane; // 0x0020(0x0004) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
- public float OrthoFarClipPlane; // 0x0024(0x0004) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
- public float AspectRatio; // 0x0028(0x0004) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
- public byte bConstrainAspectRatio; // 0x002C(0x0001) (CPF_Edit, CPF_BlueprintVisible)
- public byte bUseFieldOfViewForLOD; // 0x002C(0x0001) (CPF_Edit, CPF_BlueprintVisible)
- }
- [StructLayout(LayoutKind.Explicit)]
- public struct USceneComponent
- {
- [FieldOffset(0x0164)]
- public Vector3 RelativeLocation; //struct FVector RelativeLocation;
- [FieldOffset(0x0170)]
- public Vector3 RelativeRotation; //struct FRotator RelativeRotation;
- [FieldOffset(0x017C)]
- public Vector3 RelativeScale3D; //struct FVector RelativeScale3D;
- [FieldOffset(0x01C0)]
- public Vector3 ComponentVelocity; //struct FVector ComponentVelocity;
- }
- //no idea if this works, not used
- //[StructLayout(LayoutKind.Sequential)]
- //public unsafe struct FText
- //{
- // fixed byte pad0[0x28];
- // public FString fstring;
- //}
- //no idea if this works, not used
- //[StructLayout(LayoutKind.Sequential)]
- //public unsafe struct FString
- //{
- // fixed sbyte arrName[64];
- // public override string ToString()
- // {
- // fixed (sbyte* pName = arrName)
- // return new string(pName);
- // }
- //}
- [StructLayout(LayoutKind.Sequential)]
- public struct FRotator
- {
- public float Pitch;
- public float Yaw;
- public float Roll;
- public FRotator(float flPitch, float flYaw, float flRoll)
- {
- Pitch = flPitch;
- Yaw = flYaw;
- Roll = flRoll;
- }
- public double Length
- {
- get
- {
- return Math.Sqrt(this.Pitch * this.Pitch + this.Yaw * this.Yaw + this.Roll * this.Roll);
- }
- }
- public FRotator Clamp()
- {
- var result = this;
- if (result.Pitch > 180)
- result.Pitch -= 360;
- else if (result.Pitch < -180)
- result.Pitch += 360;
- if (result.Yaw > 180)
- result.Yaw -= 360;
- else if (result.Yaw < -180)
- result.Yaw += 360;
- if (result.Pitch < -89)
- result.Pitch = -89;
- if (result.Pitch > 89)
- result.Pitch = 89;
- while (result.Yaw < -180.0f)
- result.Yaw += 360.0f;
- while (result.Yaw > 180.0f)
- result.Yaw -= 360.0f;
- result.Roll = 0;
- return result;
- }
- public void GetAxes(out Vector3 x, out Vector3 y, out Vector3 z)
- {
- var m = ToMatrix();
- x = new Vector3(m.M11, m.M12, m.M13);
- y = new Vector3(m.M21, m.M22, m.M23);
- z = new Vector3(m.M31, m.M32, m.M33);
- }
- public Vector3 ToVector()
- {
- float radPitch = (float)(this.Pitch * Math.PI / 180f);
- float radYaw = (float)(this.Yaw * Math.PI / 180f);
- float SP = (float)Math.Sin(radPitch);
- float CP = (float)Math.Cos(radPitch);
- float SY = (float)Math.Sin(radYaw);
- float CY = (float)Math.Cos(radYaw);
- return new Vector3(CP * CY, CP * SY, SP);
- }
- public SharpDX.Matrix ToMatrix(Vector3 origin = default)
- {
- float radPitch = (float)(this.Pitch * Math.PI / 180f);
- float radYaw = (float)(this.Yaw * Math.PI / 180f);
- float radRoll = (float)(this.Roll * Math.PI / 180f);
- float SP = (float)Math.Sin(radPitch);
- float CP = (float)Math.Cos(radPitch);
- float SY = (float)Math.Sin(radYaw);
- float CY = (float)Math.Cos(radYaw);
- float SR = (float)Math.Sin(radRoll);
- float CR = (float)Math.Cos(radRoll);
- SharpDX.Matrix m = new SharpDX.Matrix();
- m[0, 0] = CP * CY;
- m[0, 1] = CP * SY;
- m[0, 2] = SP;
- m[0, 3] = 0f;
- m[1, 0] = SR * SP * CY - CR * SY;
- m[1, 1] = SR * SP * SY + CR * CY;
- m[1, 2] = -SR * CP;
- m[1, 3] = 0f;
- m[2, 0] = -(CR * SP * CY + SR * SY);
- m[2, 1] = CY * SR - CR * SP * SY;
- m[2, 2] = CR * CP;
- m[2, 3] = 0f;
- m[3, 0] = origin.X;
- m[3, 1] = origin.Y;
- m[3, 2] = origin.Z;
- m[3, 3] = 1f;
- return m;
- }
- public static FRotator operator +(FRotator angA, FRotator angB) => new FRotator(angA.Pitch + angB.Pitch, angA.Yaw + angB.Yaw, angA.Roll + angB.Roll);
- public static FRotator operator -(FRotator angA, FRotator angB) => new FRotator(angA.Pitch - angB.Pitch, angA.Yaw - angB.Yaw, angA.Roll - angB.Roll);
- public static FRotator operator /(FRotator angA, float flNum) => new FRotator(angA.Pitch / flNum, angA.Yaw / flNum, angA.Roll / flNum);
- public static FRotator operator *(FRotator angA, float flNum) => new FRotator(angA.Pitch * flNum, angA.Yaw * flNum, angA.Roll * flNum);
- public static bool operator ==(FRotator angA, FRotator angB) => angA.Pitch == angB.Pitch && angA.Yaw == angB.Yaw && angA.Yaw == angB.Yaw;
- public static bool operator !=(FRotator angA, FRotator angB) => angA.Pitch != angB.Pitch || angA.Yaw != angB.Yaw || angA.Yaw != angB.Yaw;
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct TArray<T> where T : struct
- {
- public IntPtr pData;
- public int Count;
- public int Max;
- public IntPtr this[int nIndex]
- {
- get
- {
- return pData + nIndex * IntPtr.Size;
- }
- }
- public T ReadValue(int nIndex, bool bDeref)
- {
- IntPtr ptrData = pData + nIndex * IntPtr.Size;
- if (bDeref)
- ptrData = M.Read<IntPtr>(ptrData);
- return M.Read<T>(ptrData);
- }
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct GNames
- {
- public IntPtr pData;
- public int Num;
- public int Max;
- public TStaticIndirectArrayThreadSafeRead GetStaticArray()
- {
- return M.Read<TStaticIndirectArrayThreadSafeRead>(this.pData);
- }
- }
- [StructLayout(LayoutKind.Sequential)]
- public unsafe struct TStaticIndirectArrayThreadSafeRead
- {
- private const int MaxTotalElements = 0x200000;
- private const int ElementsPerChunk = 0x4000;
- private const int ChunkCount = 128;
- public fixed long Chunks[ChunkCount];
- public int NumElements;
- public int NumChunks;
- public List<byte[]> ChunkData
- {
- get
- {
- List<byte[]> listChunkdata = new List<byte[]>();
- fixed (long* arrChunkPointers = Chunks)
- for (int nChunk = 0; nChunk < ChunkCount; nChunk++)
- listChunkdata.Add(M.Read((IntPtr)arrChunkPointers[nChunk], ElementsPerChunk * IntPtr.Size));
- return listChunkdata;
- }
- }
- public IntPtr this[int nIndex]
- {
- get
- {
- fixed (long* chunks = Chunks)
- {
- var pChunk = (IntPtr)chunks[nIndex / ElementsPerChunk];
- var arrChunkData = ChunkData[nIndex / ElementsPerChunk];
- return (IntPtr)BitConverter.ToInt64(arrChunkData, nIndex % ElementsPerChunk * IntPtr.Size);
- }
- }
- }
- public string[] DumpNames()
- {
- string[] arrNames = new string[MaxTotalElements];
- var arrChunkData = ChunkData;
- for (int nIndex = 0; nIndex < MaxTotalElements; nIndex++)
- {
- byte[] arrCurrentChunkData = arrChunkData[nIndex / ElementsPerChunk];
- IntPtr pName = (IntPtr)BitConverter.ToInt64(arrCurrentChunkData, nIndex % ElementsPerChunk * IntPtr.Size);
- // Neccessary?
- //if (pName == IntPtr.Zero)
- // arrNames[nIndex] = "NO_NAME";
- //else
- if (pName != IntPtr.Zero)
- arrNames[nIndex] = M.Read<FNameEntry>(pName).ToString();
- }
- return arrNames;
- }
- [StructLayout(LayoutKind.Explicit)]
- public unsafe struct FNameEntry
- {
- [FieldOffset(0x0C)]
- fixed sbyte arrName[64];
- public override string ToString()
- {
- fixed (sbyte* pName = arrName)
- return new string(pName);
- }
- }
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct Vector3
- {
- public float X;
- public float Y;
- public float Z;
- public Vector3(float x, float y, float z)
- {
- X = x;
- Y = y;
- Z = z;
- }
- public double Length
- {
- get
- {
- return Math.Sqrt(this.X * this.X + this.Y * this.Y + this.Z * this.Z);
- }
- }
- public Vector2 To2D()
- {
- return new Vector2(this.X, this.Y);
- }
- public FRotator ToFRotator()
- {
- FRotator rot = new FRotator();
- float RADPI = (float)(180 / Math.PI);
- rot.Yaw = (float)Math.Atan2(this.Y, this.X) * RADPI;
- rot.Pitch = (float)Math.Atan2(this.Z, Math.Sqrt((this.X * this.X) + (this.Y * this.Y))) * RADPI;
- rot.Roll = 0;
- return rot;
- }
- public static float DotProduct(Vector3 vecA, Vector3 vecB) => vecA.X * vecB.X + vecA.Y * vecB.Y + vecA.Z * vecB.Z;
- #region Overrides
- public override string ToString()
- {
- return $"{X},{Y},{Z}";
- }
- #endregion
- #region Operators
- public static Vector3 operator +(Vector3 vecA, Vector3 vecB) => new Vector3(vecA.X + vecB.X, vecA.Y + vecB.Y, vecA.Z + vecB.Z);
- public static Vector3 operator -(Vector3 vecA, Vector3 vecB) => new Vector3(vecA.X - vecB.X, vecA.Y - vecB.Y, vecA.Z - vecB.Z);
- public static Vector3 operator *(Vector3 vecA, Vector3 vecB) => new Vector3(vecA.X * vecB.X, vecA.Y * vecB.Y, vecA.Z * vecB.Z);
- public static Vector3 operator *(Vector3 vecA, int n) => new Vector3(vecA.X * n, vecA.Y * n, vecA.Z * n);
- public static Vector3 operator /(Vector3 vecA, Vector3 vecB) => new Vector3(vecA.X / vecB.X, vecA.Y / vecB.Y, vecA.Z / vecB.Z);
- public static bool operator ==(Vector3 vecA, Vector3 vecB) => vecA.X == vecB.X && vecA.Y == vecB.Y && vecA.Y == vecB.Y;
- public static bool operator !=(Vector3 vecA, Vector3 vecB) => vecA.X != vecB.X || vecA.Y != vecB.Y || vecA.Y != vecB.Y;
- #endregion
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct Vector2
- {
- public float X;
- public float Y;
- public Vector2(float x, float y)
- {
- X = x;
- Y = y;
- }
- public Vector2(double x, double y)
- {
- X = (float)x;
- Y = (float)y;
- }
- public double Length
- {
- get
- {
- return Math.Sqrt(this.X * this.X + this.Y * this.Y);
- }
- }
- #region Functions
- public Vector2 Rotate(Vector2 centerpoint, double angle, bool bAngleInRadians = false)
- {
- if (!bAngleInRadians)
- angle = Math.PI * angle / 180.0;
- return new Vector2(this.X * Math.Cos(angle) - this.Y * Math.Sin(angle), this.X * Math.Sin(angle) + this.Y * Math.Cos(angle));
- }
- #endregion
- #region Overrides
- public override string ToString()
- {
- return $"{X},{Y}";
- }
- #endregion
- #region Operators
- public static Vector2 operator +(Vector2 vecA, Vector2 vecB) => new Vector2(vecA.X + vecB.X, vecA.Y + vecB.Y);
- public static Vector2 operator -(Vector2 vecA, Vector2 vecB) => new Vector2(vecA.X - vecB.X, vecA.Y - vecB.Y);
- public static Vector2 operator *(Vector2 vecA, int n) => new Vector2(vecA.X * n, vecA.Y * n);
- public static Vector2 operator /(Vector2 vecA, Vector2 vecB) => new Vector2(vecA.X / vecB.X, vecA.Y / vecB.Y);
- public static Vector2 operator +(Vector2 vecA, float val) => new Vector2(vecA.X + val, vecA.Y + val);
- public static Vector2 operator -(Vector2 vecA, float val) => new Vector2(vecA.X - val, vecA.Y - val);
- public static Vector2 operator *(Vector2 vecA, float val) => new Vector2(vecA.X * val, vecA.Y * val);
- public static Vector2 operator /(Vector2 vecA, float val) => new Vector2(vecA.X / val, vecA.Y / val);
- public static bool operator ==(Vector2 vecA, Vector2 vecB) => vecA.X == vecB.X && vecA.Y == vecB.Y && vecA.Y == vecB.Y;
- public static bool operator !=(Vector2 vecA, Vector2 vecB) => vecA.X != vecB.X || vecA.Y != vecB.Y || vecA.Y != vecB.Y;
- #endregion
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement