using System.Collections;
using UnityEngine;
using Wizard;

namespace Cute;

public class BootNetwork : MonoBehaviour
{
	public bool _autoSetup;

	public static bool IsDoneLanguageSetting;

	public bool IsDoneGameStartCheck { get; set; }

	private void Awake()
	{
		Object.DontDestroyOnLoad(base.gameObject);
	}

	private IEnumerator Start()
	{
		while (Toolbox.BootSystem == null)
		{
			yield return 0;
		}
		while (Toolbox.NetworkManager == null)
		{
			yield return 0;
		}
		Toolbox.BootNetwork = this;
		if (_autoSetup)
		{
			SetupNetwork();
		}
		SetupNetworkLanguage();
		while (!IsDoneLanguageSetting)
		{
			yield return 0;
		}
	}

	private void OnDestroy()
	{
	}

	public void SetupNetwork()
	{
		if (!IsDoneGameStartCheck)
		{
			StartCoroutine(SetupNetworkCoroutine());
		}
	}

	public void SetupNetworkLanguage()
	{
		string text = Toolbox.SavedataManager.GetString("LANG_SETTING");
		if (text == "Jpn")
		{
			Toolbox.SavedataManager.DeleteKey("LANG_SETTING");
			Toolbox.SavedataManager.DeleteKey("LANG_SOUND_SETTING");
			text = "";
			Toolbox.AssetManager.ClearAllAssetFile();
			Toolbox.AssetManager.ClearAssetCacheAssetBundle();
		}
		if (string.IsNullOrEmpty(text))
		{
			CustomPreference.SetScemeMode(CustomPreference.eSchemeType.Https);
			CustomPreference.SetApplicationServerURL("utoongaize.shadowverse.jp/shadowverse/");
		}
		else
		{
			IsDoneLanguageSetting = true;
		}
	}

	private IEnumerator SetupNetworkCoroutine()
	{
		if (!IsDoneGameStartCheck)
		{
			yield return StartCoroutine(Toolbox.NetworkManager._certification.Login());
		}
	}

	public IEnumerator SetupNetworkCertification()
	{
		SetupNetwork();
		while (!IsDoneGameStartCheck)
		{
			yield return 0;
		}
		yield return StartCoroutine(Toolbox.AssetManager.InitializeManifest(null, Data.Load.data._userTutorial.tutorial_step != 100));
	}
}
