using System;
using System.IO;
using UnityEngine;

public class FileHackGlobalGameManagers
{
	public static string Path
	{
		get
		{
			return Application.dataPath + "/globalgamemanagers";
		}
	}

	public static byte[] ReadAllBytes(string path = "")
	{
		if (string.IsNullOrEmpty(path))
		{
			path = FileHackGlobalGameManagers.Path;
		}
		byte[] result = null;
		try
		{
			result = File.ReadAllBytes(path);
		}
		catch (Exception ex)
		{
			Debug.LogError(ex.Message);
		}
		return result;
	}

	public static bool WriteAllBytes(byte[] src, string path = "")
	{
		if (string.IsNullOrEmpty(path))
		{
			path = FileHackGlobalGameManagers.Path;
		}
		bool result = false;
		try
		{
			File.WriteAllBytes(path, src);
			result = true;
		}
		catch (Exception ex)
		{
			Debug.LogError(ex.Message);
		}
		return result;
	}

	public static int IndexOfVRFlag(byte[] src)
	{
		if (src == null || src.Length <= 0)
		{
			return -1;
		}
		string text = "com.";
		string text2 = "1.0";
		int num = FileHackGlobalGameManagers.IndexOf(src, 0, text);
		if (num <= 0)
		{
			return -1;
		}
		int num2 = FileHackGlobalGameManagers.IndexOf(src, num, text2);
		if (num2 <= 0)
		{
			return -1;
		}
		int num3 = num2 + text2.Length + 9;
		return (num3 >= src.Length) ? -1 : num3;
	}

	public static int IndexOf(byte[] src, int offset, string text)
	{
		byte[] array = new byte[text.Length];
		for (int i = 0; i < text.Length; i++)
		{
			array[i] = (byte)text[i];
		}
		int num = 0;
		while (num + offset < src.Length)
		{
			if (src[num + offset] == array[0])
			{
				int num2 = num + offset;
				int num3 = 0;
				while (num2 < src.Length && num3 < array.Length)
				{
					if ((char)src[num2] != text[num3])
					{
						num3 = -1;
						break;
					}
					num2++;
					num3++;
				}
				if (0 < num3)
				{
					return num + offset;
				}
			}
			num++;
		}
		return -1;
	}
}
