using System;

public class CRes
{
	public const int COLOR_FOCUS_MENU = 16767817;

	public const int LIGHT_BLUE = 8040447;

	public const int DARK_BLUE = 84643;

	public const int LIGHT_BLUE_POUP = 2276847;

	public const int DARK_BLUE_POUP = 1144763;

	public const int LIGHT_BLUE_COMMAND = 2263535;

	public const int DARK_BLUE_COMMAND = 1133755;

	public static int TOP_CENTER = mGraphics.TOP | mGraphics.HCENTER;

	public static int TOP_LEFT = mGraphics.TOP | mGraphics.LEFT;

	public static int TOP_RIGHT = mGraphics.TOP | mGraphics.RIGHT;

	public static int BOTTOM_HCENTER = mGraphics.BOTTOM | mGraphics.HCENTER;

	public static int BOTTOM_LEFT = mGraphics.BOTTOM | mGraphics.LEFT;

	public static int BOTTOM_RIGHT = mGraphics.BOTTOM | mGraphics.RIGHT;

	public static int VCENTER_HCENTER = mGraphics.VCENTER | mGraphics.HCENTER;

	public static int VCENTER_LEFT = mGraphics.VCENTER | mGraphics.LEFT;

	public static int[] SKYCOLOR = new int[18]
	{
		1618168, 1938102, 43488, 16316528, 1628316, 3270903, 3576979, 6999725, 14594155, 8562616,
		16026508, 1052688, 13952747, 15268088, 1628316, 6269332, 3940431, 3940431
	};

	public static MyRandom r = new MyRandom();

	private static short[] sinz = new short[91]
	{
		0, 18, 36, 54, 71, 89, 107, 125, 143, 160,
		178, 195, 213, 230, 248, 265, 282, 299, 316, 333,
		350, 367, 384, 400, 416, 433, 449, 465, 481, 496,
		512, 527, 543, 558, 573, 587, 602, 616, 630, 644,
		658, 672, 685, 698, 711, 724, 737, 749, 761, 773,
		784, 796, 807, 818, 828, 839, 849, 859, 868, 878,
		887, 896, 904, 912, 920, 928, 935, 943, 949, 956,
		962, 968, 974, 979, 984, 989, 994, 998, 1002, 1005,
		1008, 1011, 1014, 1016, 1018, 1020, 1022, 1023, 1023, 1024,
		1024
	};

	private static short[] cosz;

	private static int[] tanz;

	public static Image imgMenu;

	public static Image imgCam;

	public static MyVector debug = new MyVector();

	public static sbyte[] readByteArray(Message msg)
	{
		try
		{
			int num = msg.reader().readInt();
			outz("lent = " + num);
			sbyte[] data = new sbyte[num];
			msg.reader().read(ref data);
			return data;
		}
		catch (Exception)
		{
			Cout.LogTryCatch("readByteArray cres " + msg.command);
		}
		return null;
	}

	public static void init()
	{
		MenuScr.imgStone = CCanvas.loadImage("/gui2/stone.png");
		imgMenu = CCanvas.loadImage("/iconmenu.png");
		imgCam = CCanvas.loadImage("/iconcam.png");
		cosz = new short[91];
		tanz = new int[91];
		for (int i = 0; i <= 90; i++)
		{
			cosz[i] = sinz[90 - i];
			if (cosz[i] == 0)
			{
				tanz[i] = int.MaxValue;
			}
			else
			{
				tanz[i] = (sinz[i] << 10) / cosz[i];
			}
		}
	}

	public static int abs(int i)
	{
		return (i <= 0) ? (-i) : i;
	}

	public static Image loadImage(string filename)
	{
		Image image = null;
		try
		{
			image = Image.createImage(filename);
		}
		catch (Exception)
		{
		}
		if (image == null)
		{
			outz("Load image '" + filename + "': ERROR!!!");
		}
		return image;
	}

	public static Image loadImageRMS(string path)
	{
		path = Main.res + "/x" + mGraphics.zoomLevel + path;
		path = CCanvas.cutPng(path);
		Image result = null;
		try
		{
			result = Image.createImage(path);
		}
		catch (Exception)
		{
			try
			{
				string[] array = split(path, "/", 0);
				string filename = "x" + mGraphics.zoomLevel + array[array.Length - 1];
				sbyte[] array2 = Rms.loadRMS(filename);
				if (array2 != null)
				{
					result = Image.createImage(array2, 0, array2.Length);
					array2 = null;
				}
				else
				{
					Cout.LogTryCatch("loadImageRMS1: " + path);
				}
			}
			catch (Exception)
			{
				Cout.LogTryCatch("loadImageRMS2: " + path);
			}
		}
		return result;
	}

	public static void saveIP(string strID)
	{
		Rms.saveRMSString("ARMYIPlink", strID);
	}

	public static string loadIP()
	{
		return Rms.loadRMSString("ARMYIPlink");
	}

	public static int sin(int a)
	{
		a = fixangle(a);
		if (a >= 0 && a < 90)
		{
			return sinz[a];
		}
		if (a >= 90 && a < 180)
		{
			return sinz[180 - a];
		}
		if (a >= 180 && a < 270)
		{
			return -sinz[a - 180];
		}
		return -sinz[360 - a];
	}

	public static int cos(int a)
	{
		a = fixangle(a);
		if (a >= 0 && a < 90)
		{
			return cosz[a];
		}
		if (a >= 90 && a < 180)
		{
			return -cosz[180 - a];
		}
		if (a >= 180 && a < 270)
		{
			return -cosz[a - 180];
		}
		return cosz[360 - a];
	}

	public static int tan(int a)
	{
		a = fixangle(a);
		if (a >= 0 && a < 90)
		{
			return tanz[a];
		}
		if (a >= 90 && a < 180)
		{
			return -tanz[180 - a];
		}
		if (a >= 180 && a < 270)
		{
			return tanz[a - 180];
		}
		return -tanz[360 - a];
	}

	public static int atan(int a)
	{
		for (int i = 0; i <= 90; i++)
		{
			if (tanz[i] >= a)
			{
				return i;
			}
		}
		return 0;
	}

	public static int angle(int dx, int dy)
	{
		int num;
		if (dx != 0)
		{
			int a = Math.abs((dy << 10) / dx);
			num = atan(a);
			if (dy >= 0 && dx < 0)
			{
				num = 180 - num;
			}
			if (dy < 0 && dx < 0)
			{
				num = 180 + num;
			}
			if (dy < 0 && dx >= 0)
			{
				num = 360 - num;
			}
		}
		else
		{
			num = ((dy <= 0) ? 270 : 90);
		}
		return num;
	}

	public static string formatIntoDDHHMMSS(int secsIn, bool isSecond)
	{
		int num = secsIn / 86400;
		int num2 = secsIn % 86400;
		int num3 = num2 / 3600;
		num2 %= 3600;
		int num4 = num2 / 60;
		int num5 = num2 % 60;
		if (num5 < 0)
		{
			num5 = 0;
		}
		if (num4 < 0)
		{
			num4 = 0;
		}
		if (num3 < 0)
		{
			num3 = 0;
		}
		if (isSecond)
		{
			return ((num <= 0) ? string.Empty : (num + "n " + ((num3 >= 10) ? string.Empty : "0"))) + num3 + ":" + ((num4 >= 10) ? string.Empty : "0") + num4 + ":" + ((num5 >= 10) ? string.Empty : "0") + num5;
		}
		return ((num <= 0) ? string.Empty : (num + " ngÃ\u00a0y ")) + string.Empty + num3 + " ngÃ\u00a0y.";
	}

	public static int myAngle(int dx, int dy)
	{
		int num = angle(dx, dy);
		if (num >= 315)
		{
			num = 360 - num;
		}
		return num;
	}

	public static int fixangle(int angle)
	{
		if (angle >= 360)
		{
			angle -= 360;
		}
		if (angle < 0)
		{
			angle += 360;
		}
		return angle;
	}

	public static int subangle(int a1, int a2)
	{
		int num = a2 - a1;
		if (num < -180)
		{
			return num + 360;
		}
		if (num > 180)
		{
			return num - 360;
		}
		return num;
	}

	public static int random_Am_0(int a)
	{
		int num;
		for (num = 0; num == 0; num = r.nextInt() % a)
		{
		}
		return num;
	}

	public static int random(int a, int b)
	{
		return a + r.nextInt(b - a);
	}

	public static int random(int a)
	{
		return r.nextInt() % a;
	}

	public static bool isLand(int color)
	{
		return color != 16777215;
	}

	public static bool inRect(int x, int y, int xrect, int yrect, int width, int height)
	{
		if (x < xrect || x >= xrect + width || y < yrect || y >= yrect + height)
		{
			return false;
		}
		return true;
	}

	public static bool isHit(int x, int y, int w, int h, int tX, int tY, int tW, int tH)
	{
		return x + w >= tX && x <= tX + tW && y + h >= tY && y <= tY + tH;
	}

	public static int sqrt(int a)
	{
		if (a <= 0)
		{
			return 0;
		}
		int num = (a + 1) / 2;
		int num2;
		do
		{
			num2 = num;
			num = num / 2 + a / (2 * num);
		}
		while (Math.abs(num2 - num) > 1);
		return num;
	}

	public static string[] split(string original, string separator, int count)
	{
		int num = original.IndexOf(separator);
		string[] array;
		if (num >= 0)
		{
			array = split(original.Substring(num + separator.Length), separator, count + 1);
		}
		else
		{
			array = new string[count + 1];
			num = original.Length;
		}
		array[count] = original.Substring(0, num);
		return array;
	}

	public static int distance(int x1, int y1, int x2, int y2)
	{
		return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	}

	public static void saveRMSInt(string file, int x)
	{
		Rms.saveRMSInt(file, x);
	}

	public static void saveRMS_String(string filename, string data)
	{
		Rms.saveRMSString(filename, data);
	}

	public static string loadRMS_String(string filename)
	{
		return Rms.loadRMSString(filename);
	}

	public static int byte2int(sbyte b)
	{
		return b & 0xFF;
	}

	public static int getShort(int off, sbyte[] data)
	{
		return (byte2int(data[off]) << 8) | byte2int(data[off + 1]);
	}

	public static Position transTextLimit(Position pos, int limit)
	{
		pos.x += pos.y;
		if (pos.y == -1 && Math.abs(pos.x) > limit)
		{
			pos.y *= -1;
		}
		if (pos.y == 1 && pos.x > 5)
		{
			pos.y *= -1;
		}
		return pos;
	}

	public static string getMoneys(int m)
	{
		string text = string.Empty;
		int num = m / 1000 + 1;
		for (int i = 0; i < num; i++)
		{
			if (m >= 1000)
			{
				int num2 = m % 1000;
				text = ((num2 != 0) ? ((num2 >= 10) ? ((num2 >= 100) ? ("." + num2 + text) : (".0" + num2 + text)) : (".00" + num2 + text)) : (".000" + text));
				m /= 1000;
				continue;
			}
			text = m + text;
			break;
		}
		return text;
	}

	public static string formatNumber(int number)
	{
		string empty = string.Empty;
		string empty2 = string.Empty;
		empty = string.Empty;
		if (number >= 1000000000)
		{
			empty2 = L.billion();
			long num = number % 1000000000 / 100000000;
			number /= 1000000000;
			empty = number + string.Empty;
			if (num > 0)
			{
				string text = empty;
				return text + "," + num + empty2;
			}
			return empty + empty2;
		}
		if (number >= 1000000)
		{
			empty2 = L.million();
			long num2 = number % 1000000 / 100000;
			number /= 1000000;
			empty = number + string.Empty;
			if (num2 > 0)
			{
				string text = empty;
				return text + "," + num2 + empty2;
			}
			return empty + empty2;
		}
		return number + string.Empty;
	}

	public static void outz(string text)
	{
		UnityEngine.Debug.Log(text);
	}

	public static void onScreenDebug(string s)
	{
	}

	public static void paintOnScreenDebug(mGraphics g)
	{
	}

	public static void updateOnScreenDebug()
	{
	}
}
