daily pastebin goal
52%
SHARE
TWEET

Untitled

Solokiller May 11th, 2018 97 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. using Server.Game.Entities;
  2. using System;
  3. using System.Runtime.InteropServices;
  4.  
  5. namespace Server.Engine
  6. {
  7.     public unsafe sealed class edict_t
  8.     {
  9.         public const int MAX_ENT_LEAFS = 48;
  10.  
  11.         [StructLayout(LayoutKind.Sequential)]
  12.         internal unsafe struct Native
  13.         {
  14.             internal int free;
  15.             internal int serialnumber;
  16.             internal link_t area;
  17.  
  18.             internal int headnode;
  19.             internal int num_leafs;
  20.             internal fixed short leafnums[MAX_ENT_LEAFS];
  21.  
  22.             internal float freetime;
  23.  
  24.             internal void* pvPrivateData;
  25.  
  26.             internal entvars_t.Native v;
  27.         }
  28.  
  29.         internal Native* Data { get; private set; }
  30.  
  31.         internal edict_t(Native* nativeMemory)
  32.         {
  33.             Data = nativeMemory;
  34.  
  35.             Vars = new entvars_t(&Data->v);
  36.         }
  37.  
  38.         public bool Free
  39.         {
  40.             get => 0 != Data->free;
  41.             set => Data->free = value ? 1 : 0;
  42.         }
  43.  
  44.         public int SerialNumber
  45.         {
  46.             get => Data->serialnumber;
  47.             set => Data->serialnumber = value;
  48.         }
  49.  
  50.         /// <summary>
  51.         /// Linked to a division node or leaf
  52.         /// This works based on the address of the area member, so return the address
  53.         /// </summary>
  54.         public IntPtr Area => new IntPtr(&Data->area);
  55.  
  56.         /// <summary>
  57.         /// -1 to use normal leaf check
  58.         /// </summary>
  59.         public int HeadNode
  60.         {
  61.             get => Data->headnode;
  62.             set => Data->headnode = value;
  63.         }
  64.  
  65.         public int NumLeafs
  66.         {
  67.             get => Data->num_leafs;
  68.             set => Data->num_leafs = value;
  69.         }
  70.  
  71.         //TODO: range check
  72.         public short GetLeafNumber(int index) => Data->leafnums[index];
  73.         public void SetLeafNumber(int index, short number) => Data->leafnums[index] = number;
  74.  
  75.         /// <summary>
  76.         /// sv.time when the object was freed
  77.         /// </summary>
  78.         public float FreeTime
  79.         {
  80.             get => Data->freetime;
  81.             set => Data->freetime = value;
  82.         }
  83.  
  84.         private IEntity _entity;
  85.  
  86.         private IEntity PrivateData
  87.         {
  88.             get => _entity;
  89.  
  90.             set
  91.             {
  92.                 _entity = value;
  93.                 //We can't store the managed type address in the native object since the CLR can move it around
  94.                 //So we just mark the private data as present or not present, since the engine doesn't care about its contents or particular address
  95.                 Data->pvPrivateData = (void*) (null != _entity ? 1 : 0);
  96.             }
  97.         }
  98.  
  99.         /// <summary>
  100.         /// C exported fields from progs
  101.         /// other fields from progs come immediately after
  102.         /// </summary>
  103.         public entvars_t Vars { get; }
  104.     }
  105. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top