Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.50 KB | None | 0 0
  1. using Flux.Helpers;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Runtime.InteropServices;
  5.  
  6.  
  7. namespace Flux.Game
  8. {
  9. class UnrealClasses
  10. {
  11. #region Structs
  12. [StructLayout(LayoutKind.Explicit)]
  13. public struct UWorld //class UWorld
  14. {
  15. [FieldOffset(0x30)]
  16. public IntPtr pPersistentLevel; //ULevel* PersistentLevel;
  17.  
  18. [FieldOffset(0x0160)]
  19. public IntPtr pOwningGameInstance; //class UGameInstance* OwningGameInstance;
  20. }
  21. [StructLayout(LayoutKind.Explicit)]
  22. public struct ULevel
  23. {
  24. [FieldOffset(0x98)] //I think I manually found this in reclass, check PM's with CorM
  25. public TArray<AActor> AActors;
  26.  
  27. }
  28.  
  29. [StructLayout(LayoutKind.Explicit)]
  30. public struct AActor
  31. {
  32. [FieldOffset(0x00)]
  33. public IntPtr BaseOffset;
  34.  
  35. [FieldOffset(0x18)]
  36. public int Id;
  37.  
  38. [FieldOffset(0x0140)] //AActor: class APawn* Instigator;
  39. public IntPtr pPawn;
  40.  
  41. [FieldOffset(0x158)]
  42. public IntPtr pRootComponent; //AActor: class USceneComponent* RootComponent;
  43.  
  44. [FieldOffset(0x0338)]
  45. public IntPtr pPlayerState; //AController: class APlayerState* PlayerState;
  46.  
  47. [FieldOffset(0x07B0)] //AINSCharacter: float Health;
  48. public float Health;
  49.  
  50. [FieldOffset(0x0C68)]
  51. public IntPtr pCurrentWeapon; //AINSSoldier: class AItemEquipable* CurrentWeapon;
  52.  
  53. [FieldOffset(0x1688)]
  54. public float SwayFactor; //AINSSoldier: float SwayFactor;
  55.  
  56. [FieldOffset(0x173F)]
  57. public byte bInRestrictedArea; //AINSSoldier: bool bInRestrictedArea;
  58.  
  59. [FieldOffset(0x1740)]
  60. public byte RestrictedAreaCount; //AINSSoldier: unsigned char RestrictedAreaCount;
  61.  
  62. [FieldOffset(0x1741)]
  63. public byte bOutsidePlayableArea; //AINSSoldier: bool bOutsidePlayableArea;
  64.  
  65. [FieldOffset(0x1742)]
  66. public byte PlayableAreaCount; //AINSSoldier: unsigned char PlayableAreaCount;
  67.  
  68. [FieldOffset(0x1744)]
  69. public float PlayableAreaLeavetime; //AINSSoldier: float PlayableAreaLeaveTime;
  70.  
  71. [FieldOffset(0x1748)]
  72. public float PlayableAreaKillTime; //AINSSoldier: float PlayableAreaKillTime;
  73.  
  74. [FieldOffset(0x174C)]
  75. public float RestrictedAreaEnterTime; //AINSSoldier: float RestrictedAreaEnterTime;
  76.  
  77. [FieldOffset(0x1750)]
  78. public float WeaponRestrictionTime; //AINSSoldier: float WeaponRestrictionTime;
  79.  
  80. public Vector3 Location
  81. {
  82. get
  83. {
  84. return this.RootComponent.RelativeLocation;
  85. }
  86. }
  87.  
  88. public bool IsAlive
  89. {
  90. get
  91. {
  92. return this.Health > 0;
  93. }
  94. }
  95.  
  96. public APawn Pawn
  97. {
  98. get
  99. {
  100. return M.Read<APawn>(this.pPawn);
  101. }
  102. }
  103.  
  104. public bool InGame
  105. {
  106. get
  107. {
  108. return true;
  109. }
  110. }
  111.  
  112. public USceneComponent RootComponent
  113. {
  114. get
  115. {
  116. return M.Read<USceneComponent>(this.pRootComponent);
  117. }
  118. }
  119. public static IntPtr g_pLocalPlayer = IntPtr.Zero;
  120. public static AActor GetLocalPlayer()
  121. {
  122. if (g_pLocalPlayer != IntPtr.Zero)
  123. {
  124. var localplayer = M.Read<AActor>(g_pLocalPlayer);
  125. localplayer.BaseOffset = g_pLocalPlayer;
  126. return localplayer;
  127. }
  128.  
  129. return M.Read<AActor>(g_pLocalPlayer);
  130. }
  131.  
  132. public AItemFirearm CurrentWeapon
  133. {
  134. get
  135. {
  136. return M.Read<AItemFirearm>(this.pCurrentWeapon);
  137. }
  138. }
  139. }
  140.  
  141. [StructLayout(LayoutKind.Explicit)]
  142. public struct AItemFirearm
  143. {
  144. [FieldOffset(0x3128)]
  145. public FFirearmConfig WeaponConfig; //AItemFirearm: struct FFirearmConfig WeaponConfig;
  146. }
  147.  
  148. [StructLayout(LayoutKind.Sequential)]
  149. public unsafe struct FFirearmConfig //struct FFirearmConfig
  150. {
  151. public IntPtr ProjectileClass;
  152. public float MuzzleVelocity;
  153. public byte bForceSimpleBulletcollision;
  154. public fixed byte UnknownData00[0x3];
  155. public float TimeBetweenShots;
  156. public float InitialShotDelay;
  157. public byte bFireprojectileOnNotify;
  158. public fixed byte UnknownData01[0x3];
  159. public float FireProjectileDelay;
  160. public byte bLockSightsInFireDelay;
  161. public fixed byte UnknownData02[0x3];
  162. public float ImminentShotTolerance;
  163. public byte bSupportsSpeedReload;
  164. public fixed byte UnknownData03[0x3];
  165. public float ReloadInterruptDuration;
  166. public byte bCanAmmoCheck;
  167. public fixed byte UnknownData04[0x3];
  168. public float AmmoCheckDuration;
  169. public float BoltCycleTime;
  170. public float BoltCycleSequenceTime;
  171. public float BoltSpeed;
  172. public float BarrelLength;
  173. public float BarrelLengthTraceStart;
  174. public float BarrelObstructionThreshhold;
  175. public byte bAllowFireDuringMelee;
  176. public fixed byte UnknownData05[0x3];
  177. public int Firemodes;
  178. public byte bOverrideDefaultFiremode;
  179. public byte DefaultFiremode;
  180. public byte Burstrounds;
  181. public fixed byte UnknownData06[0x1];
  182. public float BurstDelay;
  183. public float FiremodeCycleDuration;
  184. public float FiremodeCycleGraceTime;
  185. public byte bTerminateBurstOnTriggerRelease;
  186. public byte bResetBurstOnTermination;
  187. public byte bAllowAimDownSights;
  188. public fixed byte UnknownData07[0x1];
  189. public float AimDownSightsTime;
  190. public float AimDownSightsFOV;
  191. public float AimDownSightsViewModelFOV;
  192. public float AimDownSightsViewModelFocusFOV;
  193. public float AimDownSightsViewModelDistance;
  194. public float AimDownSightsViewModelAngle;
  195. public float FocusFOV;
  196. public float FocusTime;
  197. public float ScopeFOV;
  198. public byte bAverageFireRate;
  199. public fixed byte UnknownData08[0x3];
  200. public Vector2 RecoilLateralRange;
  201. public Vector2 RecoilVerticalRange;
  202. public Vector2 RecoilRollRange;
  203. public Vector2 RecoilAimPunchRange;
  204. public float RecoilRestDelay;
  205. public float RecoilRestRate;
  206. public float RecoilRollRestRate;
  207. public float RecoilAdditionalRestPerShot;
  208. public float RecoilPunchAdditiveFactor;
  209. public int RecoilMaxShots;
  210. public float RecoilShotResetTime;
  211. public fixed byte WeightCurve[0x88];
  212. public float AimingRecoilFactor;
  213. public fixed byte UnknownData09[0x4];
  214. public fixed byte LeaningRecoilWeightFactor[0x88];
  215. public float CrouchedRecoilFactor;
  216. public float ProneRecoilFactor;
  217. public fixed byte StaminaRecoilWeightFactor[0x88];
  218. public float FocusRecoilFactor;
  219. public fixed byte UnknownData10[0x4];
  220. public fixed byte MovementRecoilWeightFactor[0x88];
  221. public float MovementAimRecoilFactor;
  222. public float RecoilMaxFactor;
  223. public float RecoilFreeaimVerticalFrac;
  224. public float RecoilFreeaimLateralFrac;
  225. public float BurstRecoilFactor;
  226. public float SwayMagnitude;
  227. public float SwapSpeed;
  228. }
  229.  
  230. [StructLayout(LayoutKind.Explicit)]
  231. public struct APawn
  232. {
  233. [FieldOffset(0x0350)]
  234. public IntPtr pPlayerState; //APawn: class APlayerState* PlayerState;
  235.  
  236. [FieldOffset(0x0390)]
  237. public IntPtr pMesh; //ACharacter: class USkeletalMeshComponent* Mesh;
  238.  
  239. public APlayerState PlayerState
  240. {
  241. get
  242. {
  243. return M.Read<APlayerState>(this.pPlayerState);
  244. }
  245. }
  246.  
  247. public USkeletalMeshComponent MeshComponent
  248. {
  249. get
  250. {
  251. return M.Read<USkeletalMeshComponent>(this.pMesh);
  252. }
  253. }
  254. }
  255.  
  256.  
  257. [StructLayout(LayoutKind.Explicit)]
  258. public struct USkeletalMeshComponent
  259. {
  260. [FieldOffset(0x06BE)]
  261. public byte bRecentlyRendered; //USkinnedMeshComponent: unsigned char bRecentlyRendered : 1;
  262.  
  263. public bool RecentlyRendered
  264. {
  265. get
  266. {
  267. var bitField = this.bRecentlyRendered;
  268. bitField >>= 4;
  269. bitField &= 1;
  270. return bitField == 1 ? true : false;
  271. }
  272. }
  273. }
  274.  
  275. [StructLayout(LayoutKind.Explicit)]
  276. public struct APlayerState
  277. {
  278. [FieldOffset(0x0460)]
  279. public byte isPlaying; //AINSPlayerState: bool bIsPlaying;
  280.  
  281. [FieldOffset(0x690)]
  282. public byte teamId; //AINSPlayerState: unsigned char TeamId;
  283. }
  284.  
  285.  
  286. [StructLayout(LayoutKind.Explicit)]
  287. public struct UGameInstance
  288. {
  289. [FieldOffset(0x38)]
  290. public IntPtr pULocalPlayer; //TArray<class ULocalPlayer*> LocalPlayers
  291.  
  292. public ULocalPlayer LocalPlayer
  293. {
  294. get
  295. {
  296. IntPtr pLocalPlayer = M.Read<IntPtr>(this.pULocalPlayer);
  297. var result = M.Read<ULocalPlayer>(pLocalPlayer);
  298. result.pBase = pLocalPlayer;
  299. return result;
  300. }
  301. }
  302. }
  303.  
  304. [StructLayout(LayoutKind.Explicit)]
  305. public struct ULocalPlayer
  306. {
  307. [FieldOffset(0x00)]
  308. public IntPtr pBase;
  309.  
  310. [FieldOffset(0x30)]
  311. public IntPtr pPlayerController; //UPlayer: class APlayerController* PlayerController;
  312.  
  313. [FieldOffset(0x70)]
  314. public IntPtr pViewportClient; //ULocalPlayer: class UGameViewportClient* ViewportClient;
  315.  
  316. // fixed byte UnknownData01[0x1C];
  317. //I think this is NULL / garbage currently, it honestly doesn't make a difference.
  318. //I get the location of my localplayer via the AActor struct's USceneComponent, not ULocalPlayer
  319. [FieldOffset(0x78)]
  320. public Vector3 Location;
  321. public APlayerController PlayerController
  322. {
  323. get
  324. {
  325. return M.Read<APlayerController>(this.pPlayerController);
  326. }
  327. }
  328. public UGameViewportClient ViewportClient
  329. {
  330. get
  331. {
  332. return M.Read<UGameViewportClient>(this.pViewportClient);
  333. }
  334. }
  335.  
  336. }
  337.  
  338. [StructLayout(LayoutKind.Explicit)]
  339. public struct UGameViewportClient
  340. {
  341. //this is the actual UWorld. In UE4 what they're doing is giving you a global world PROXY
  342. //however you're not actually supposed to use this like you would a UWorld. That's why
  343. //you have to reverse the proxy, and then find the actual world
  344. [FieldOffset(0x0078)]
  345. public IntPtr pUWorld; //class UWorld* World;
  346. }
  347.  
  348. [StructLayout(LayoutKind.Explicit)]
  349. public struct APlayerController
  350. {
  351. [FieldOffset(0x03B0)] //APlayerController: class APawn* AcknowledgedPawn;
  352. public IntPtr pLocalPlayer;
  353.  
  354. //class AController : public AActor
  355. //struct FRotator ControlRotation;
  356. [FieldOffset(0x0398)]
  357. public FRotator ControlRotation;
  358.  
  359. [FieldOffset(0x03C8)]
  360. public IntPtr pPlayerCameraManager; //APlayerController: class APlayerCameraManager* PlayerCameraManager;
  361.  
  362. public APlayerCameraManager PlayerCameraManager
  363. {
  364. get
  365. {
  366. return M.Read<APlayerCameraManager>(pPlayerCameraManager);
  367. }
  368. }
  369. }
  370.  
  371. [StructLayout(LayoutKind.Explicit)]
  372. public struct APlayerCameraManager
  373. {
  374. [FieldOffset(0x0348)]
  375. public float DefaultFOV; //float DefaultFOV;
  376.  
  377. [FieldOffset(0x0350)]
  378. public float DefaultOrthoWidth; //float DefaultOrthoWidth;
  379.  
  380. [FieldOffset(0x0358)]
  381. public float DefaultAspectRatio; //float DefaultAspectRatio;
  382.  
  383. [FieldOffset(0x0EC0)]
  384. public FCameraCacheEntry CameraCache; //struct FTViewTarget ViewTarget;
  385. }
  386.  
  387. [StructLayout(LayoutKind.Explicit)]
  388. public struct FCameraCacheEntry
  389. {
  390. [FieldOffset(0x10)]
  391. public FMinimalViewInfo POV;
  392. }
  393.  
  394. [StructLayout(LayoutKind.Sequential)]
  395. public struct FMinimalViewInfo
  396. {
  397. public Vector3 Location; // 0x0000(0x000C) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
  398. public FRotator Rotation; // 0x000C(0x000C) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
  399. public float FOV; // 0x0018(0x0004) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
  400. public float DesiredFOV; // 0x001C(0x0004) (ZeroConstructor, Transient, IsPlainOldData)
  401. public float OrthoWidth; // 0x001C(0x0004) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
  402. public float OrthoNearClipPlane; // 0x0020(0x0004) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
  403. public float OrthoFarClipPlane; // 0x0024(0x0004) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
  404. public float AspectRatio; // 0x0028(0x0004) (CPF_Edit, CPF_BlueprintVisible, CPF_ZeroConstructor, CPF_IsPlainOldData)
  405. public byte bConstrainAspectRatio; // 0x002C(0x0001) (CPF_Edit, CPF_BlueprintVisible)
  406. public byte bUseFieldOfViewForLOD; // 0x002C(0x0001) (CPF_Edit, CPF_BlueprintVisible)
  407. }
  408.  
  409. [StructLayout(LayoutKind.Explicit)]
  410. public struct USceneComponent
  411. {
  412. [FieldOffset(0x0164)]
  413. public Vector3 RelativeLocation; //struct FVector RelativeLocation;
  414.  
  415. [FieldOffset(0x0170)]
  416. public Vector3 RelativeRotation; //struct FRotator RelativeRotation;
  417.  
  418. [FieldOffset(0x017C)]
  419. public Vector3 RelativeScale3D; //struct FVector RelativeScale3D;
  420.  
  421. [FieldOffset(0x01C0)]
  422. public Vector3 ComponentVelocity; //struct FVector ComponentVelocity;
  423. }
  424.  
  425. //no idea if this works, not used
  426. //[StructLayout(LayoutKind.Sequential)]
  427. //public unsafe struct FText
  428. //{
  429. // fixed byte pad0[0x28];
  430. // public FString fstring;
  431. //}
  432.  
  433. //no idea if this works, not used
  434. //[StructLayout(LayoutKind.Sequential)]
  435. //public unsafe struct FString
  436. //{
  437. // fixed sbyte arrName[64];
  438.  
  439. // public override string ToString()
  440. // {
  441. // fixed (sbyte* pName = arrName)
  442. // return new string(pName);
  443. // }
  444. //}
  445.  
  446. [StructLayout(LayoutKind.Sequential)]
  447. public struct FRotator
  448. {
  449. public float Pitch;
  450. public float Yaw;
  451. public float Roll;
  452.  
  453. public FRotator(float flPitch, float flYaw, float flRoll)
  454. {
  455. Pitch = flPitch;
  456. Yaw = flYaw;
  457. Roll = flRoll;
  458. }
  459.  
  460. public double Length
  461. {
  462. get
  463. {
  464. return Math.Sqrt(this.Pitch * this.Pitch + this.Yaw * this.Yaw + this.Roll * this.Roll);
  465. }
  466. }
  467.  
  468. public FRotator Clamp()
  469. {
  470. var result = this;
  471.  
  472. if (result.Pitch > 180)
  473. result.Pitch -= 360;
  474.  
  475. else if (result.Pitch < -180)
  476. result.Pitch += 360;
  477.  
  478. if (result.Yaw > 180)
  479. result.Yaw -= 360;
  480.  
  481. else if (result.Yaw < -180)
  482. result.Yaw += 360;
  483.  
  484. if (result.Pitch < -89)
  485. result.Pitch = -89;
  486.  
  487. if (result.Pitch > 89)
  488. result.Pitch = 89;
  489.  
  490. while (result.Yaw < -180.0f)
  491. result.Yaw += 360.0f;
  492.  
  493. while (result.Yaw > 180.0f)
  494. result.Yaw -= 360.0f;
  495.  
  496. result.Roll = 0;
  497.  
  498. return result;
  499. }
  500.  
  501. public void GetAxes(out Vector3 x, out Vector3 y, out Vector3 z)
  502. {
  503. var m = ToMatrix();
  504.  
  505. x = new Vector3(m.M11, m.M12, m.M13);
  506. y = new Vector3(m.M21, m.M22, m.M23);
  507. z = new Vector3(m.M31, m.M32, m.M33);
  508. }
  509.  
  510. public Vector3 ToVector()
  511. {
  512. float radPitch = (float)(this.Pitch * Math.PI / 180f);
  513. float radYaw = (float)(this.Yaw * Math.PI / 180f);
  514.  
  515. float SP = (float)Math.Sin(radPitch);
  516. float CP = (float)Math.Cos(radPitch);
  517. float SY = (float)Math.Sin(radYaw);
  518. float CY = (float)Math.Cos(radYaw);
  519.  
  520. return new Vector3(CP * CY, CP * SY, SP);
  521. }
  522.  
  523. public SharpDX.Matrix ToMatrix(Vector3 origin = default)
  524. {
  525.  
  526. float radPitch = (float)(this.Pitch * Math.PI / 180f);
  527. float radYaw = (float)(this.Yaw * Math.PI / 180f);
  528. float radRoll = (float)(this.Roll * Math.PI / 180f);
  529.  
  530. float SP = (float)Math.Sin(radPitch);
  531. float CP = (float)Math.Cos(radPitch);
  532. float SY = (float)Math.Sin(radYaw);
  533. float CY = (float)Math.Cos(radYaw);
  534. float SR = (float)Math.Sin(radRoll);
  535. float CR = (float)Math.Cos(radRoll);
  536.  
  537. SharpDX.Matrix m = new SharpDX.Matrix();
  538. m[0, 0] = CP * CY;
  539. m[0, 1] = CP * SY;
  540. m[0, 2] = SP;
  541. m[0, 3] = 0f;
  542.  
  543. m[1, 0] = SR * SP * CY - CR * SY;
  544. m[1, 1] = SR * SP * SY + CR * CY;
  545. m[1, 2] = -SR * CP;
  546. m[1, 3] = 0f;
  547.  
  548. m[2, 0] = -(CR * SP * CY + SR * SY);
  549. m[2, 1] = CY * SR - CR * SP * SY;
  550. m[2, 2] = CR * CP;
  551. m[2, 3] = 0f;
  552.  
  553. m[3, 0] = origin.X;
  554. m[3, 1] = origin.Y;
  555. m[3, 2] = origin.Z;
  556. m[3, 3] = 1f;
  557. return m;
  558. }
  559.  
  560. public static FRotator operator +(FRotator angA, FRotator angB) => new FRotator(angA.Pitch + angB.Pitch, angA.Yaw + angB.Yaw, angA.Roll + angB.Roll);
  561. public static FRotator operator -(FRotator angA, FRotator angB) => new FRotator(angA.Pitch - angB.Pitch, angA.Yaw - angB.Yaw, angA.Roll - angB.Roll);
  562. public static FRotator operator /(FRotator angA, float flNum) => new FRotator(angA.Pitch / flNum, angA.Yaw / flNum, angA.Roll / flNum);
  563. public static FRotator operator *(FRotator angA, float flNum) => new FRotator(angA.Pitch * flNum, angA.Yaw * flNum, angA.Roll * flNum);
  564. public static bool operator ==(FRotator angA, FRotator angB) => angA.Pitch == angB.Pitch && angA.Yaw == angB.Yaw && angA.Yaw == angB.Yaw;
  565. public static bool operator !=(FRotator angA, FRotator angB) => angA.Pitch != angB.Pitch || angA.Yaw != angB.Yaw || angA.Yaw != angB.Yaw;
  566. }
  567.  
  568. [StructLayout(LayoutKind.Sequential)]
  569. public struct TArray<T> where T : struct
  570. {
  571. public IntPtr pData;
  572. public int Count;
  573. public int Max;
  574.  
  575. public IntPtr this[int nIndex]
  576. {
  577. get
  578. {
  579. return pData + nIndex * IntPtr.Size;
  580. }
  581. }
  582. public T ReadValue(int nIndex, bool bDeref)
  583. {
  584. IntPtr ptrData = pData + nIndex * IntPtr.Size;
  585.  
  586. if (bDeref)
  587. ptrData = M.Read<IntPtr>(ptrData);
  588.  
  589. return M.Read<T>(ptrData);
  590. }
  591. }
  592. [StructLayout(LayoutKind.Sequential)]
  593. public struct GNames
  594. {
  595. public IntPtr pData;
  596. public int Num;
  597. public int Max;
  598.  
  599. public TStaticIndirectArrayThreadSafeRead GetStaticArray()
  600. {
  601. return M.Read<TStaticIndirectArrayThreadSafeRead>(this.pData);
  602. }
  603. }
  604. [StructLayout(LayoutKind.Sequential)]
  605. public unsafe struct TStaticIndirectArrayThreadSafeRead
  606. {
  607. private const int MaxTotalElements = 0x200000;
  608. private const int ElementsPerChunk = 0x4000;
  609. private const int ChunkCount = 128;
  610.  
  611. public fixed long Chunks[ChunkCount];
  612.  
  613. public int NumElements;
  614. public int NumChunks;
  615.  
  616. public List<byte[]> ChunkData
  617. {
  618. get
  619. {
  620. List<byte[]> listChunkdata = new List<byte[]>();
  621.  
  622.  
  623. fixed (long* arrChunkPointers = Chunks)
  624. for (int nChunk = 0; nChunk < ChunkCount; nChunk++)
  625. listChunkdata.Add(M.Read((IntPtr)arrChunkPointers[nChunk], ElementsPerChunk * IntPtr.Size));
  626.  
  627. return listChunkdata;
  628. }
  629. }
  630.  
  631. public IntPtr this[int nIndex]
  632. {
  633. get
  634. {
  635. fixed (long* chunks = Chunks)
  636. {
  637. var pChunk = (IntPtr)chunks[nIndex / ElementsPerChunk];
  638. var arrChunkData = ChunkData[nIndex / ElementsPerChunk];
  639. return (IntPtr)BitConverter.ToInt64(arrChunkData, nIndex % ElementsPerChunk * IntPtr.Size);
  640. }
  641. }
  642. }
  643. public string[] DumpNames()
  644. {
  645. string[] arrNames = new string[MaxTotalElements];
  646. var arrChunkData = ChunkData;
  647.  
  648. for (int nIndex = 0; nIndex < MaxTotalElements; nIndex++)
  649. {
  650. byte[] arrCurrentChunkData = arrChunkData[nIndex / ElementsPerChunk];
  651.  
  652. IntPtr pName = (IntPtr)BitConverter.ToInt64(arrCurrentChunkData, nIndex % ElementsPerChunk * IntPtr.Size);
  653.  
  654. // Neccessary?
  655. //if (pName == IntPtr.Zero)
  656. // arrNames[nIndex] = "NO_NAME";
  657. //else
  658. if (pName != IntPtr.Zero)
  659. arrNames[nIndex] = M.Read<FNameEntry>(pName).ToString();
  660. }
  661.  
  662. return arrNames;
  663. }
  664. [StructLayout(LayoutKind.Explicit)]
  665. public unsafe struct FNameEntry
  666. {
  667. [FieldOffset(0x0C)]
  668. fixed sbyte arrName[64];
  669.  
  670. public override string ToString()
  671. {
  672. fixed (sbyte* pName = arrName)
  673. return new string(pName);
  674. }
  675. }
  676. }
  677. [StructLayout(LayoutKind.Sequential)]
  678. public struct Vector3
  679. {
  680. public float X;
  681. public float Y;
  682. public float Z;
  683.  
  684. public Vector3(float x, float y, float z)
  685. {
  686. X = x;
  687. Y = y;
  688. Z = z;
  689. }
  690.  
  691. public double Length
  692. {
  693. get
  694. {
  695. return Math.Sqrt(this.X * this.X + this.Y * this.Y + this.Z * this.Z);
  696. }
  697. }
  698. public Vector2 To2D()
  699. {
  700. return new Vector2(this.X, this.Y);
  701. }
  702. public FRotator ToFRotator()
  703. {
  704. FRotator rot = new FRotator();
  705.  
  706. float RADPI = (float)(180 / Math.PI);
  707. rot.Yaw = (float)Math.Atan2(this.Y, this.X) * RADPI;
  708. rot.Pitch = (float)Math.Atan2(this.Z, Math.Sqrt((this.X * this.X) + (this.Y * this.Y))) * RADPI;
  709. rot.Roll = 0;
  710.  
  711. return rot;
  712. }
  713.  
  714. public static float DotProduct(Vector3 vecA, Vector3 vecB) => vecA.X * vecB.X + vecA.Y * vecB.Y + vecA.Z * vecB.Z;
  715.  
  716. #region Overrides
  717. public override string ToString()
  718. {
  719. return $"{X},{Y},{Z}";
  720. }
  721. #endregion
  722. #region Operators
  723. public static Vector3 operator +(Vector3 vecA, Vector3 vecB) => new Vector3(vecA.X + vecB.X, vecA.Y + vecB.Y, vecA.Z + vecB.Z);
  724. public static Vector3 operator -(Vector3 vecA, Vector3 vecB) => new Vector3(vecA.X - vecB.X, vecA.Y - vecB.Y, vecA.Z - vecB.Z);
  725. public static Vector3 operator *(Vector3 vecA, Vector3 vecB) => new Vector3(vecA.X * vecB.X, vecA.Y * vecB.Y, vecA.Z * vecB.Z);
  726. public static Vector3 operator *(Vector3 vecA, int n) => new Vector3(vecA.X * n, vecA.Y * n, vecA.Z * n);
  727. public static Vector3 operator /(Vector3 vecA, Vector3 vecB) => new Vector3(vecA.X / vecB.X, vecA.Y / vecB.Y, vecA.Z / vecB.Z);
  728.  
  729. public static bool operator ==(Vector3 vecA, Vector3 vecB) => vecA.X == vecB.X && vecA.Y == vecB.Y && vecA.Y == vecB.Y;
  730. public static bool operator !=(Vector3 vecA, Vector3 vecB) => vecA.X != vecB.X || vecA.Y != vecB.Y || vecA.Y != vecB.Y;
  731. #endregion
  732. }
  733.  
  734. [StructLayout(LayoutKind.Sequential)]
  735. public struct Vector2
  736. {
  737. public float X;
  738. public float Y;
  739.  
  740. public Vector2(float x, float y)
  741. {
  742. X = x;
  743. Y = y;
  744. }
  745. public Vector2(double x, double y)
  746. {
  747. X = (float)x;
  748. Y = (float)y;
  749. }
  750.  
  751. public double Length
  752. {
  753. get
  754. {
  755. return Math.Sqrt(this.X * this.X + this.Y * this.Y);
  756. }
  757. }
  758. #region Functions
  759. public Vector2 Rotate(Vector2 centerpoint, double angle, bool bAngleInRadians = false)
  760. {
  761. if (!bAngleInRadians)
  762. angle = Math.PI * angle / 180.0;
  763.  
  764. return new Vector2(this.X * Math.Cos(angle) - this.Y * Math.Sin(angle), this.X * Math.Sin(angle) + this.Y * Math.Cos(angle));
  765. }
  766. #endregion
  767. #region Overrides
  768. public override string ToString()
  769. {
  770. return $"{X},{Y}";
  771. }
  772. #endregion
  773. #region Operators
  774. public static Vector2 operator +(Vector2 vecA, Vector2 vecB) => new Vector2(vecA.X + vecB.X, vecA.Y + vecB.Y);
  775. public static Vector2 operator -(Vector2 vecA, Vector2 vecB) => new Vector2(vecA.X - vecB.X, vecA.Y - vecB.Y);
  776. public static Vector2 operator *(Vector2 vecA, int n) => new Vector2(vecA.X * n, vecA.Y * n);
  777. public static Vector2 operator /(Vector2 vecA, Vector2 vecB) => new Vector2(vecA.X / vecB.X, vecA.Y / vecB.Y);
  778.  
  779. public static Vector2 operator +(Vector2 vecA, float val) => new Vector2(vecA.X + val, vecA.Y + val);
  780. public static Vector2 operator -(Vector2 vecA, float val) => new Vector2(vecA.X - val, vecA.Y - val);
  781. public static Vector2 operator *(Vector2 vecA, float val) => new Vector2(vecA.X * val, vecA.Y * val);
  782. public static Vector2 operator /(Vector2 vecA, float val) => new Vector2(vecA.X / val, vecA.Y / val);
  783.  
  784.  
  785. public static bool operator ==(Vector2 vecA, Vector2 vecB) => vecA.X == vecB.X && vecA.Y == vecB.Y && vecA.Y == vecB.Y;
  786. public static bool operator !=(Vector2 vecA, Vector2 vecB) => vecA.X != vecB.X || vecA.Y != vecB.Y || vecA.Y != vecB.Y;
  787. #endregion
  788. }
  789. #endregion
  790. }
  791. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement