using System;

namespace SharpQuake
{
	internal static class SwapHelper
	{
		public static short ShortSwap(short l)
		{
			byte b = (byte)(l & 255);
			byte b2 = (byte)(l >> 8 & 255);
			return (short)((b << 8) + b2);
		}

		public static int LongSwap(int l)
		{
			int num = (int)((byte)(l & 255));
			byte b = (byte)(l >> 8 & 255);
			byte b2 = (byte)(l >> 16 & 255);
			byte b3 = (byte)(l >> 24 & 255);
			return (num << 24) + ((int)b << 16) + ((int)b2 << 8) + (int)b3;
		}

		public static float FloatSwap(float f)
		{
			byte[] bytes = BitConverter.GetBytes(f);
			return BitConverter.ToSingle(new byte[]
			{
				bytes[3],
				bytes[2],
				bytes[1],
				bytes[0]
			}, 0);
		}

		public static void Swap4b(byte[] buff, int offset)
		{
			byte b = buff[offset];
			byte b2 = buff[offset + 1];
			byte b3 = buff[offset + 2];
			byte b4 = buff[offset + 3];
			buff[offset] = b4;
			buff[offset + 1] = b3;
			buff[offset + 2] = b2;
			buff[offset + 3] = b;
		}
	}
}
