using System;

namespace SharpQuake
{
	internal class edict_t
	{
		public void Clear()
		{
			this.v = default(entvars_t);
			if (this.fields != null)
			{
				Array.Clear(this.fields, 0, this.fields.Length);
			}
			this.free = false;
		}

		public bool IsV(int offset, out int correctedOffset)
		{
			if (offset < entvars_t.SizeInBytes >> 2)
			{
				correctedOffset = offset;
				return true;
			}
			correctedOffset = offset - (entvars_t.SizeInBytes >> 2);
			return false;
		}

		public unsafe void LoadInt(int offset, eval_t* result)
		{
			int num;
			if (this.IsV(offset, out num))
			{
				fixed (entvars_t* ptr = &this.v)
				{
					void* ptr2 = (void*)ptr;
					eval_t* ptr3 = (eval_t*)((byte*)ptr2 + (IntPtr)num * 4);
					result->_int = ptr3->_int;
				}
				return;
			}
			float[] array;
			void* ptr4;
			if ((array = this.fields) == null || array.Length == 0)
			{
				ptr4 = null;
			}
			else
			{
				ptr4 = (void*)(&array[0]);
			}
			eval_t* ptr5 = (eval_t*)((byte*)ptr4 + (IntPtr)num * 4);
			result->_int = ptr5->_int;
			array = null;
		}

		public unsafe void StoreInt(int offset, eval_t* value)
		{
			int num;
			if (this.IsV(offset, out num))
			{
				fixed (entvars_t* ptr = &this.v)
				{
					void* ptr2 = (void*)ptr;
					eval_t* ptr3 = (eval_t*)((byte*)ptr2 + (IntPtr)num * 4);
					ptr3->_int = value->_int;
				}
				return;
			}
			float[] array;
			void* ptr4;
			if ((array = this.fields) == null || array.Length == 0)
			{
				ptr4 = null;
			}
			else
			{
				ptr4 = (void*)(&array[0]);
			}
			eval_t* ptr5 = (eval_t*)((byte*)ptr4 + (IntPtr)num * 4);
			ptr5->_int = value->_int;
			array = null;
		}

		public unsafe void LoadVector(int offset, eval_t* result)
		{
			int num;
			if (this.IsV(offset, out num))
			{
				fixed (entvars_t* ptr = &this.v)
				{
					void* ptr2 = (void*)ptr;
					eval_t* ptr3 = (eval_t*)((byte*)ptr2 + (IntPtr)num * 4);
					result->vector.FixedElementField = ptr3->vector.FixedElementField;
					*(ref result->vector.FixedElementField + 4) = *(ref ptr3->vector.FixedElementField + 4);
					*(ref result->vector.FixedElementField + (IntPtr)2 * 4) = *(ref ptr3->vector.FixedElementField + (IntPtr)2 * 4);
				}
				return;
			}
			float[] array;
			void* ptr4;
			if ((array = this.fields) == null || array.Length == 0)
			{
				ptr4 = null;
			}
			else
			{
				ptr4 = (void*)(&array[0]);
			}
			eval_t* ptr5 = (eval_t*)((byte*)ptr4 + (IntPtr)num * 4);
			result->vector.FixedElementField = ptr5->vector.FixedElementField;
			*(ref result->vector.FixedElementField + 4) = *(ref ptr5->vector.FixedElementField + 4);
			*(ref result->vector.FixedElementField + (IntPtr)2 * 4) = *(ref ptr5->vector.FixedElementField + (IntPtr)2 * 4);
			array = null;
		}

		public unsafe void StoreVector(int offset, eval_t* value)
		{
			int num;
			if (this.IsV(offset, out num))
			{
				fixed (entvars_t* ptr = &this.v)
				{
					void* ptr2 = (void*)ptr;
					eval_t* ptr3 = (eval_t*)((byte*)ptr2 + (IntPtr)num * 4);
					ptr3->vector.FixedElementField = value->vector.FixedElementField;
					*(ref ptr3->vector.FixedElementField + 4) = *(ref value->vector.FixedElementField + 4);
					*(ref ptr3->vector.FixedElementField + (IntPtr)2 * 4) = *(ref value->vector.FixedElementField + (IntPtr)2 * 4);
				}
				return;
			}
			float[] array;
			void* ptr4;
			if ((array = this.fields) == null || array.Length == 0)
			{
				ptr4 = null;
			}
			else
			{
				ptr4 = (void*)(&array[0]);
			}
			eval_t* ptr5 = (eval_t*)((byte*)ptr4 + (IntPtr)num * 4);
			ptr5->vector.FixedElementField = value->vector.FixedElementField;
			*(ref ptr5->vector.FixedElementField + 4) = *(ref value->vector.FixedElementField + 4);
			*(ref ptr5->vector.FixedElementField + (IntPtr)2 * 4) = *(ref value->vector.FixedElementField + (IntPtr)2 * 4);
			array = null;
		}

		public unsafe int GetInt(int offset)
		{
			int num;
			int @int;
			if (this.IsV(offset, out num))
			{
				fixed (entvars_t* ptr = &this.v)
				{
					void* ptr2 = (void*)ptr;
					eval_t* ptr3 = (eval_t*)((byte*)ptr2 + (IntPtr)num * 4);
					@int = ptr3->_int;
				}
			}
			else
			{
				float[] array;
				void* ptr4;
				if ((array = this.fields) == null || array.Length == 0)
				{
					ptr4 = null;
				}
				else
				{
					ptr4 = (void*)(&array[0]);
				}
				eval_t* ptr5 = (eval_t*)((byte*)ptr4 + (IntPtr)num * 4);
				@int = ptr5->_int;
				array = null;
			}
			return @int;
		}

		public unsafe float GetFloat(int offset)
		{
			int num;
			float @float;
			if (this.IsV(offset, out num))
			{
				fixed (entvars_t* ptr = &this.v)
				{
					void* ptr2 = (void*)ptr;
					eval_t* ptr3 = (eval_t*)((byte*)ptr2 + (IntPtr)num * 4);
					@float = ptr3->_float;
				}
			}
			else
			{
				float[] array;
				void* ptr4;
				if ((array = this.fields) == null || array.Length == 0)
				{
					ptr4 = null;
				}
				else
				{
					ptr4 = (void*)(&array[0]);
				}
				eval_t* ptr5 = (eval_t*)((byte*)ptr4 + (IntPtr)num * 4);
				@float = ptr5->_float;
				array = null;
			}
			return @float;
		}

		public unsafe void SetFloat(int offset, float value)
		{
			int num;
			if (this.IsV(offset, out num))
			{
				fixed (entvars_t* ptr = &this.v)
				{
					void* ptr2 = (void*)ptr;
					eval_t* ptr3 = (eval_t*)((byte*)ptr2 + (IntPtr)num * 4);
					ptr3->_float = value;
				}
				return;
			}
			float[] array;
			void* ptr4;
			if ((array = this.fields) == null || array.Length == 0)
			{
				ptr4 = null;
			}
			else
			{
				ptr4 = (void*)(&array[0]);
			}
			eval_t* ptr5 = (eval_t*)((byte*)ptr4 + (IntPtr)num * 4);
			ptr5->_float = value;
			array = null;
		}

		public edict_t()
		{
			this.area = new link_t(this);
			this.leafnums = new short[16];
			this.fields = new float[progs.EdictSize - entvars_t.SizeInBytes >> 2];
		}

		public bool free;

		public link_t area;

		public int num_leafs;

		public short[] leafnums;

		public entity_state_t baseline;

		public float freetime;

		public entvars_t v;

		public float[] fields;
	}
}
