using System;
using System.Collections;
using System.Collections.Generic;
using MaidStatus;
using UnityEngine;

public class SceneVRTouch : MonoBehaviour
{
	private void Start()
	{
		GameMain.Instance.CharacterMgr.DeactivateCharaAll();
		this.m_maid = GameMain.Instance.CharacterMgr.GetMaid(0);
		this.m_maid.Visible = true;
		Dictionary<string, string> tag_backup = GameMain.Instance.ScriptMgr.adv_kag.tag_backup;
		string a;
		if (tag_backup != null && tag_backup.TryGetValue("name", out a) && a == "SceneVRTouch")
		{
			string text;
			if (tag_backup.TryGetValue("label_end", out text))
			{
				this.m_strScriptArgLabelEnd = text;
			}
			if (tag_backup.TryGetValue("label_ft", out text))
			{
				this.m_strScriptArgLabelFT = text;
			}
		}
		GameMain.Instance.ScriptMgr.adv_kag.MessageWindowMgr.CloseMessageWindowPanel();
		this.m_maid.EyeToCamera(Maid.EyeMoveType.目と顔を向ける, 0f);
		GameMain.Instance.MainLight.Reset();
		GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
		GameMain.Instance.MainCamera.SetPos(new Vector3(0f, 1.4871f, 1f));
		GameMain.Instance.MainCamera.SetRotation(new Vector3(0f, -180f, 0f));
		this.m_lstBgInfo = this.ReadBGList();
		foreach (SceneVRTouch.BGInfo bginfo in this.m_lstBgInfo)
		{
			SceneVRTouch.ButtonBG buttonBG = new SceneVRTouch.ButtonBG();
			buttonBG.texIcon = bginfo.texThumb;
			buttonBG.m_bg = bginfo;
			this.m_listBg.Add(buttonBG);
		}
		this.m_listTouchMotionScript = this.ReadMotionList();
		foreach (SceneVRTouch.TouchMotionScript touchMotionScript in this.m_listTouchMotionScript)
		{
			SceneVRTouch.ButtonPose buttonPose = new SceneVRTouch.ButtonPose();
			buttonPose.texIcon = touchMotionScript.m_texThumb;
			buttonPose.m_motion = touchMotionScript;
			this.m_listPose.Add(buttonPose);
		}
		this.m_dicTouchVoiceScript = this.ReadVoiceList();
		this.m_TouchMgr = new VRTouchMgr();
		this.m_MotionScriptMgr = GameMain.Instance.ScriptMgrFast;
		GameObject gameObject = GameObject.Find("Cancel");
		this.m_btnEnd = gameObject.GetComponent<UIButton>();
		EventDelegate.Add(this.m_btnEnd.onClick, new EventDelegate.Callback(this.OnButtonEndClick));
		GameMain.Instance.MainCamera.FadeOut(0f, false, null, true, default(Color));
		base.StartCoroutine(this.CoLoadWait());
	}

	public void OnDestroy()
	{
		if (this.m_MotionScriptMgr != null)
		{
			this.m_MotionScriptMgr.StopAndResetScriptAll();
		}
	}

	private IEnumerator CoLoadWait()
	{
		while (GameMain.Instance.CharacterMgr.IsBusy())
		{
			yield return null;
		}
		GameMain.Instance.CharacterMgr.ResetCharaPosAll();
		this.m_maid.boMabataki = true;
		MaidColliderCollect.AddCollider(this.m_maid, MaidColliderCollect.ColliderType.Grab);
		MaidColliderCollect.AddCollider(this.m_maid, MaidColliderCollect.ColliderType.Touch);
		foreach (SceneVRTouch.TouchMotionScript touchMotionScript in this.m_listTouchMotionScript)
		{
			string[] array = touchMotionScript.m_strNeutralScript.Split(new char[]
			{
				'*'
			});
			this.m_MotionScriptMgr.LoadAndCacheScript(array[0]);
			this.m_MotionScriptMgr.LoadMotionCacheKag(array[0]);
			foreach (KeyValuePair<VRTouchMgr.ETouchPos, Dictionary<VRTouchMgr.ETouchBehavior, string>> keyValuePair in touchMotionScript.m_dicTouchScript)
			{
				foreach (KeyValuePair<VRTouchMgr.ETouchBehavior, string> keyValuePair2 in keyValuePair.Value)
				{
					array = keyValuePair2.Value.Split(new char[]
					{
						'*'
					});
					this.m_MotionScriptMgr.LoadAndCacheScript(array[0]);
					this.m_MotionScriptMgr.LoadMotionCacheKag(array[0]);
				}
			}
		}
		this.BgAndMotion(this.m_lstBgInfo[0]);
		GameMain.Instance.MainCamera.FadeIn(1f, false, new CameraMain.dgOnCompleteFade(this.OnCompleteFadeIn), true, true, default(Color));
		yield break;
	}

	private void OnCompleteFadeIn()
	{
	}

	private List<SceneVRTouch.BGInfo> ReadBGList()
	{
		List<SceneVRTouch.BGInfo> list = new List<SceneVRTouch.BGInfo>();
		string text = "vr_touch_bg.nei";
		NDebug.Assert(GameUty.FileSystem.IsExistentFile(text), "背景リストファイルが読み取れません。");
		using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
		{
			using (CsvParser csvParser = new CsvParser())
			{
				bool condition = csvParser.Open(afileBase);
				NDebug.Assert(condition, text + "\nopen failed.");
				for (int i = 1; i < csvParser.max_cell_y; i++)
				{
					if (csvParser.IsCellToExistData(0, i))
					{
						SceneVRTouch.BGInfo bginfo = new SceneVRTouch.BGInfo();
						bginfo.nID = csvParser.GetCellAsInteger(0, i);
						bginfo.strThumbFileName = csvParser.GetCellAsString(1, i);
						bginfo.strName = csvParser.GetCellAsString(2, i);
						bginfo.strScriptTagFT = csvParser.GetCellAsString(3, i);
						bginfo.strFileName = csvParser.GetCellAsString(4, i);
						bginfo.strBGM = csvParser.GetCellAsString(5, i);
						bginfo.strCondition = csvParser.GetCellAsString(6, i);
						if (!string.IsNullOrEmpty(bginfo.strCondition))
						{
							YotogiStage.Data data = YotogiStage.GetData(bginfo.strCondition);
							if (data.isYotogiPlayable(GameMain.Instance.CharacterMgr.status.clubGrade, true))
							{
								goto IL_21A;
							}
						}
						string cellAsString = csvParser.GetCellAsString(7, i);
						string[] array = cellAsString.Split(new char[]
						{
							' ',
							',',
							'f'
						}, StringSplitOptions.RemoveEmptyEntries);
						bginfo.vPos = new Vector3(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]));
						string text2 = csvParser.GetCellAsString(8, i);
						text2 = text2.Trim(new char[]
						{
							' ',
							'f'
						});
						bginfo.fRot = float.Parse(text2);
						bginfo.strValidPack = csvParser.GetCellAsString(9, i);
						if (!string.IsNullOrEmpty(bginfo.strThumbFileName))
						{
							bginfo.texThumb = ImportCM.CreateTexture(bginfo.strThumbFileName + ".tex");
						}
						else
						{
							Debug.LogWarning("BGボタンテクスチャの指定がありません。" + bginfo.strName);
							bginfo.texThumb = Resources.Load<Texture2D>("System/Texture/unsupported");
						}
						list.Add(bginfo);
					}
					IL_21A:;
				}
			}
		}
		return list;
	}

	private Dictionary<VRTouchMgr.ETouchPos, SceneVRTouch.TouchVoiceScript> ReadVoiceList()
	{
		Dictionary<VRTouchMgr.ETouchPos, SceneVRTouch.TouchVoiceScript> dictionary = new Dictionary<VRTouchMgr.ETouchPos, SceneVRTouch.TouchVoiceScript>();
		string text = "vr_touch_voice.nei";
		NDebug.Assert(GameUty.FileSystem.IsExistentFile(text), "背景リストファイルが読み取れません。");
		ScriptManager scriptMgr = GameMain.Instance.ScriptMgr;
		this.m_kag = new VRTouchKagManager(this, scriptMgr.tjs, scriptMgr);
		this.m_kag.enabled = true;
		this.m_kag.Initialize();
		using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
		{
			using (CsvParser csvParser = new CsvParser())
			{
				bool condition = csvParser.Open(afileBase);
				NDebug.Assert(condition, text + "\nopen failed.");
				for (int i = 1; i < csvParser.max_cell_y; i++)
				{
					if (csvParser.IsCellToExistData(0, i))
					{
						string cellAsString = csvParser.GetCellAsString(0, i);
						VRTouchMgr.ETouchPos key = VRTouchMgr.ETouchPos.無し;
						try
						{
							key = (VRTouchMgr.ETouchPos)Enum.Parse(typeof(VRTouchMgr.ETouchPos), cellAsString);
						}
						catch
						{
							NDebug.Assert("このタッチ部位は未定義です。" + cellAsString, false);
						}
						SceneVRTouch.TouchVoiceScript touchVoiceScript;
						if (!dictionary.TryGetValue(key, out touchVoiceScript))
						{
							touchVoiceScript = new SceneVRTouch.TouchVoiceScript();
							dictionary.Add(key, touchVoiceScript);
						}
						string cellAsString2 = csvParser.GetCellAsString(1, i);
						VRTouchMgr.ETouchBehavior key2 = VRTouchMgr.ETouchBehavior.無し;
						try
						{
							key2 = (VRTouchMgr.ETouchBehavior)Enum.Parse(typeof(VRTouchMgr.ETouchBehavior), cellAsString2);
						}
						catch
						{
							NDebug.Assert("この行動は未定義です。" + cellAsString2, false);
						}
						SceneVRTouch.TouchVoiceScript.TouchBehavior touchBehavior;
						if (!touchVoiceScript.m_listBeh.TryGetValue(key2, out touchBehavior))
						{
							touchBehavior = new SceneVRTouch.TouchVoiceScript.TouchBehavior();
							touchVoiceScript.m_listBeh.Add(key2, touchBehavior);
						}
						int num = csvParser.GetCellAsInteger(2, i) - 1;
						SceneVRTouch.TouchVoiceScript.TouchOrder touchOrder;
						if (!touchBehavior.m_dicOrderNo.TryGetValue(num, out touchOrder))
						{
							touchOrder = new SceneVRTouch.TouchVoiceScript.TouchOrder();
							touchBehavior.m_dicOrderNo.Add(num, touchOrder);
							if (touchBehavior.nOrderNoMax < num)
							{
								touchBehavior.nOrderNoMax = num;
							}
						}
						touchOrder.m_nLimit = csvParser.GetCellAsInteger(3, i);
						touchOrder.m_nTime = csvParser.GetCellAsInteger(4, i);
						string text2 = csvParser.GetCellAsString(5, i);
						if (string.IsNullOrEmpty(text2))
						{
							foreach (string str in this.m_strConditionNameTbl)
							{
								text2 = text2 + str + "|";
							}
						}
						int num2 = 0;
						int num3 = 0;
						string text3 = csvParser.GetCellAsString(6, i);
						if (string.IsNullOrEmpty(text3))
						{
							text3 = "A^M";
						}
						string[] array = text3.Split(new char[]
						{
							'^'
						});
						num2 = (int)(array[0][0] - 'A');
						num3 = (int)(array[1][0] - 'A');
						int num4 = 0;
						int num5 = 999;
						string text4 = csvParser.GetCellAsString(7, i);
						if (string.IsNullOrEmpty(text4))
						{
							text4 = "0^999";
						}
						string[] array2 = text4.Split(new char[]
						{
							'^'
						});
						num4 = int.Parse(array2[0]);
						num5 = int.Parse(array2[1]);
						string cellAsString3 = csvParser.GetCellAsString(8, i);
						string cellAsString4 = csvParser.GetCellAsString(9, i);
						string cellAsString5 = csvParser.GetCellAsString(10, i);
						string[] array3 = text2.Split(new char[]
						{
							'|'
						});
						foreach (string text5 in array3)
						{
							if (!string.IsNullOrEmpty(text5) && !(text5 == "無し"))
							{
								Relation relation = (Relation)Array.IndexOf<string>(this.m_strConditionNameTbl, text5);
								SceneVRTouch.TouchVoiceScript.TouchCondition touchCondition;
								if (!touchOrder.m_dicCondition.TryGetValue(relation, out touchCondition))
								{
									touchCondition = new SceneVRTouch.TouchVoiceScript.TouchCondition();
									touchCondition.eRelation = relation;
									touchOrder.m_dicCondition.Add(relation, touchCondition);
								}
								SceneVRTouch.TouchVoiceScript.Cup cup = touchCondition.FindCupRange(num2, num3);
								if (cup == null)
								{
									cup = new SceneVRTouch.TouchVoiceScript.Cup();
									cup.nCupLower = num2;
									cup.nCupUpper = num3;
									touchCondition.m_listCup.Add(cup);
								}
								SceneVRTouch.TouchVoiceScript.Waist waist = cup.FindWaistRange(num4, num5);
								if (waist == null)
								{
									waist = new SceneVRTouch.TouchVoiceScript.Waist();
									waist.nWaistLower = num4;
									waist.nWaistUpper = num5;
									cup.m_listWaist.Add(waist);
								}
								waist.strScriptFirst = cellAsString3;
								waist.strScriptBreath = cellAsString4;
								waist.strScriptAfter = cellAsString5;
								Dictionary<int, SceneVRTouch.RandVoiceList> randVoiceListFirst = this.ScriptRead(cellAsString3);
								Dictionary<int, SceneVRTouch.RandVoiceList> randVoiceListBreath = this.ScriptRead(cellAsString4);
								Dictionary<int, SceneVRTouch.RandVoiceList> randVoiceListAfter = this.ScriptRead(cellAsString5);
								waist.SetRandVoiceListFirst(randVoiceListFirst);
								waist.SetRandVoiceListBreath(randVoiceListBreath);
								waist.SetRandVoiceListAfter(randVoiceListAfter);
							}
						}
					}
				}
			}
		}
		if (this.m_kag != null)
		{
			this.m_kag.Dispose();
			this.m_kag = null;
		}
		return dictionary;
	}

	private Dictionary<int, SceneVRTouch.RandVoiceList> ScriptRead(string f_strScriptFileName)
	{
		Dictionary<int, SceneVRTouch.RandVoiceList> dicSet = new Dictionary<int, SceneVRTouch.RandVoiceList>();
		if (string.IsNullOrEmpty(f_strScriptFileName))
		{
			return null;
		}
		this.m_kag.SetShuffleDg(delegate(int f_nKouhun, string f_strVoiceFileName, string f_strFace, string f_strFaceBlend)
		{
			SceneVRTouch.RandVoiceList randVoiceList = null;
			if (!dicSet.TryGetValue(f_nKouhun, out randVoiceList))
			{
				randVoiceList = new SceneVRTouch.RandVoiceList();
				dicSet.Add(f_nKouhun, randVoiceList);
			}
			randVoiceList.AddSet(f_strVoiceFileName, f_strFace, f_strFaceBlend);
		});
		this.m_kag.LoadScriptFile(ScriptManager.ReplacePersonal(this.m_maid, f_strScriptFileName) + ".ks", string.Empty);
		this.m_kag.Exec();
		return dicSet;
	}

	private List<SceneVRTouch.TouchMotionScript> ReadMotionList()
	{
		List<SceneVRTouch.TouchMotionScript> list = new List<SceneVRTouch.TouchMotionScript>();
		string text = "vr_touch_motion.nei";
		NDebug.Assert(GameUty.FileSystem.IsExistentFile(text), "モーションリストファイルが読み取れません。");
		using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
		{
			using (CsvParser csvParser = new CsvParser())
			{
				bool condition = csvParser.Open(afileBase);
				NDebug.Assert(condition, text + "\nopen failed.");
				for (int i = 1; i < csvParser.max_cell_y; i++)
				{
					if (csvParser.IsCellToExistData(0, i))
					{
						SceneVRTouch.TouchMotionScript touchMotionScript = new SceneVRTouch.TouchMotionScript();
						touchMotionScript.m_nId = csvParser.GetCellAsInteger(0, i);
						touchMotionScript.m_strThumb = csvParser.GetCellAsString(1, i);
						touchMotionScript.m_strFTScript = csvParser.GetCellAsString(2, i);
						if (!string.IsNullOrEmpty(touchMotionScript.m_strFTScript))
						{
							touchMotionScript.m_strFTScript = ScriptManager.ReplacePersonal(this.m_maid, touchMotionScript.m_strFTScript) + ".ks";
						}
						touchMotionScript.m_strNeutralScript = csvParser.GetCellAsString(3, i);
						for (int j = 4; j < csvParser.max_cell_x; j++)
						{
							string cellAsString = csvParser.GetCellAsString(j, 0);
							string[] array = cellAsString.Split(new char[]
							{
								'_'
							});
							VRTouchMgr.ETouchPos f_pos = VRTouchMgr.ETouchPos.無し;
							try
							{
								f_pos = (VRTouchMgr.ETouchPos)Enum.Parse(typeof(VRTouchMgr.ETouchPos), array[0]);
							}
							catch
							{
								NDebug.Assert("この部位は未定義です。" + array[0], false);
							}
							VRTouchMgr.ETouchBehavior f_beh = VRTouchMgr.ETouchBehavior.無し;
							try
							{
								f_beh = (VRTouchMgr.ETouchBehavior)Enum.Parse(typeof(VRTouchMgr.ETouchBehavior), array[1]);
							}
							catch
							{
								NDebug.Assert("この行動は未定義です。" + array[1], false);
							}
							string cellAsString2 = csvParser.GetCellAsString(j, i);
							touchMotionScript.AddScript(f_pos, f_beh, cellAsString2);
						}
						if (!string.IsNullOrEmpty(touchMotionScript.m_strThumb))
						{
							touchMotionScript.m_texThumb = ImportCM.CreateTexture(touchMotionScript.m_strThumb + ".tex");
						}
						else
						{
							Debug.LogWarning("モーションボタンテクスチャの指定がありません。" + touchMotionScript.m_nId);
							touchMotionScript.m_texThumb = Resources.Load<Texture2D>("System/Texture/unsupported");
						}
						list.Add(touchMotionScript);
					}
				}
			}
		}
		return list;
	}

	public void Bg(SceneEdit.PVBInfo f_pvb)
	{
		SceneVRTouch.ButtonBG buttonBG = f_pvb as SceneVRTouch.ButtonBG;
		this.BgAndMotion(buttonBG.m_bg);
	}

	private void BgAndMotion(SceneVRTouch.BGInfo f_bi)
	{
		this.m_BGInfoNow = f_bi;
		GameMain.Instance.BgMgr.ChangeBg(f_bi.strFileName);
		GameMain.Instance.BgMgr.SetPos(f_bi.vPos);
		GameMain.Instance.BgMgr.SetRot(new Vector3(0f, f_bi.fRot, 0f));
		GameMain.Instance.SoundMgr.PlayBGM(f_bi.strBGM + ".ogg", 1f, true);
		this.Motion((this.m_MotionScriptNow != null) ? this.m_MotionScriptNow : this.m_listTouchMotionScript[0]);
	}

	public void Pose(SceneEdit.PVBInfo f_pvb)
	{
		SceneVRTouch.ButtonPose buttonPose = f_pvb as SceneVRTouch.ButtonPose;
		this.Motion(buttonPose.m_motion);
	}

	private void Motion(SceneVRTouch.TouchMotionScript f_motion)
	{
		this.m_MotionScriptNow = f_motion;
		if (!string.IsNullOrEmpty(f_motion.m_strFTScript) && !string.IsNullOrEmpty(this.m_BGInfoNow.strScriptTagFT))
		{
			GameMain.Instance.ScriptMgr.EvalScript("global.__vrtouch_first_file = '" + f_motion.m_strFTScript + "';");
			GameMain.Instance.ScriptMgr.EvalScript("global.__vrtouch_first_tag = '*" + this.m_BGInfoNow.strScriptTagFT + "';");
			GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_strScriptArgLabelFT);
			GameMain.Instance.ScriptMgr.adv_kag.Exec();
		}
		else
		{
			Debug.LogWarning("モーションFTの指定がありませんでした。ID:" + f_motion.m_nId);
		}
		this.PlayMotionScript(f_motion.GetScriptNeutral());
	}

	private void PlayMotionScript(string f_strFileLabelName)
	{
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		string[] array = f_strFileLabelName.Split(new char[]
		{
			'*'
		});
		this.m_MotionScriptMgr.LoadAndCacheScript(array[0]);
		this.m_MotionScriptMgr.StartMotionScript(array[0], "*" + array[1], 0, null);
		Debug.Log("PlayMotionScript time=" + (Time.realtimeSinceStartup - realtimeSinceStartup).ToString("F6"));
	}

	public void ClothesState(SceneEditInfo.ClothesState f_cs)
	{
		Maid maid = this.m_maid;
		if (f_cs == SceneEditInfo.ClothesState.Nude)
		{
			maid.body0.SetMaskMode(TBody.MaskMode.Nude);
		}
		else if (f_cs == SceneEditInfo.ClothesState.Underwear)
		{
			maid.body0.SetMaskMode(TBody.MaskMode.Underwear);
		}
		if (f_cs == SceneEditInfo.ClothesState.Wear)
		{
			maid.body0.SetMaskMode(TBody.MaskMode.None);
		}
	}

	private IEnumerator CoVoicePlayFirstAndBreath(SceneVRTouch.TouchVoiceScript.TouchOrder f_order, bool f_bFirstPlay, bool f_bForceFirstPlay)
	{
		this.m_bVoiceAfter = false;
		this.m_bSkippedPlayFirst = true;
		SceneVRTouch.TouchVoiceScript.TouchCondition cond = f_order.GetTouchCondition(this.m_maid);
		SceneVRTouch.TouchVoiceScript.Cup cup = cond.GetCup(this.m_maid);
		SceneVRTouch.TouchVoiceScript.Waist waist = cup.GetWaist(this.m_maid);
		int nKouhun = Math.Min((int)this.m_fKouhunNow, f_order.m_nLimit);
		SceneVRTouch.RandVoiceList randFirst = waist.GetRandVoiceListFirst(nKouhun);
		SceneVRTouch.RandVoiceList randBreath = waist.GetRandVoiceListBreath(nKouhun);
		SceneVRTouch.RandVoiceList randAfter = waist.GetRandVoiceListAfter(nKouhun);
		SceneVRTouch.RandVoiceList.Set setFirst = randFirst.GetVoiceFace();
		if (f_bFirstPlay && (f_bForceFirstPlay || !this.m_bNowPlayFirst))
		{
			if (this.m_maid.AudioMan.isPlay())
			{
				this.m_maid.AudioMan.Stop();
			}
			this.m_bNowPlayFirst = true;
			this.m_bSkippedPlayFirst = false;
			this.m_maid.AudioMan.LoadPlay(setFirst.m_strVoiceFileName, 0f, false, false);
			this.m_maid.FaceAnime(setFirst.m_strFace, 1f, 0);
			this.m_maid.FaceBlend((!string.IsNullOrEmpty(setFirst.m_strFaceBlend)) ? setFirst.m_strFaceBlend : "無し");
		}
		while (this.m_bNowPlayFirst)
		{
			if (!this.m_maid.AudioMan.isPlay())
			{
				this.m_bNowPlayFirst = false;
				break;
			}
			yield return null;
		}
		while (!this.m_bVoiceAfter)
		{
			SceneVRTouch.RandVoiceList.Set set = randBreath.GetVoiceFace();
			this.m_maid.AudioMan.LoadPlay(set.m_strVoiceFileName, 0f, false, false);
			this.m_maid.FaceAnime(set.m_strFace, 1f, 0);
			this.m_maid.FaceBlend((!string.IsNullOrEmpty(set.m_strFaceBlend)) ? set.m_strFaceBlend : "無し");
			while (this.m_maid.AudioMan.isPlay())
			{
				yield return null;
			}
		}
		for (;;)
		{
			SceneVRTouch.RandVoiceList.Set set2 = randAfter.GetVoiceFace();
			this.m_maid.AudioMan.LoadPlay(set2.m_strVoiceFileName, 0f, false, false);
			this.m_maid.FaceAnime(set2.m_strFace, 1f, 0);
			this.m_maid.FaceBlend((!string.IsNullOrEmpty(set2.m_strFaceBlend)) ? set2.m_strFaceBlend : "無し");
			while (this.m_maid.AudioMan.isPlay())
			{
				yield return null;
			}
		}
		yield break;
	}

	private void PlayVoice_First(SceneVRTouch.TouchVoiceScript.TouchOrder f_order, bool f_bFirstPlay, bool f_bForceFirstPlay)
	{
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		if (this.m_coVoicePlayBraeth != null)
		{
			base.StopCoroutine(this.m_coVoicePlayBraeth);
		}
		this.m_coVoicePlayBraeth = base.StartCoroutine(this.CoVoicePlayFirstAndBreath(f_order, f_bFirstPlay, f_bForceFirstPlay));
	}

	private void PlayVoice_After()
	{
		this.m_bVoiceAfter = true;
	}

	private void OnButtonEndClick()
	{
		GameMain.Instance.MainCamera.FadeOut(1f, false, new CameraMain.dgOnCompleteFade(this.OnCompleteFadeOut), true, default(Color));
	}

	private void OnCompleteFadeOut()
	{
		if (!string.IsNullOrEmpty(this.m_strScriptArgLabelEnd))
		{
			Debug.Log("OnEndScene JumpTo " + this.m_strScriptArgLabelEnd);
			GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_strScriptArgLabelEnd);
			GameMain.Instance.ScriptMgr.adv_kag.Exec();
		}
	}

	private void Update()
	{
		this.m_TouchMgr.FrameStart();
		bool flag = false;
		VRTouchMgr.EHand eTouchHandNow = VRTouchMgr.EHand.Non;
		VRTouchMgr.ETouchPos etouchPos = VRTouchMgr.ETouchPos.無し;
		VRTouchMgr.ETouchBehavior eTouchBehNow = VRTouchMgr.ETouchBehavior.無し;
		bool flag2 = false;
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		foreach (KeyValuePair<VRTouchMgr.ETouchPos, SceneVRTouch.TouchVoiceScript> keyValuePair in this.m_dicTouchVoiceScript)
		{
			for (int i = 0; i <= 1; i++)
			{
				for (int j = 1; j <= 2; j++)
				{
					SceneVRTouch.TouchVoiceScript.TouchBehavior touchBehavior;
					if (this.m_TouchMgr.GetBehaviorTouchDown((VRTouchMgr.EHand)i, keyValuePair.Key, (VRTouchMgr.ETouchBehavior)j, 0) && keyValuePair.Value.m_listBeh.TryGetValue((VRTouchMgr.ETouchBehavior)j, out touchBehavior))
					{
						if (this.m_eTouchPosNow == VRTouchMgr.ETouchPos.無し || (this.m_eTouchHandNow == (VRTouchMgr.EHand)i && this.m_eTouchPosNow == keyValuePair.Key && this.m_eTouchBehNow != (VRTouchMgr.ETouchBehavior)j))
						{
							this.m_nOrderNoNow = 0;
							flag = true;
							bool f_bFirstPlay = true;
							bool f_bForceFirstPlay = false;
							if (this.m_eTouchBehNow == VRTouchMgr.ETouchBehavior.掴む && j == 1)
							{
								f_bFirstPlay = false;
							}
							if (this.m_eTouchBehNow == VRTouchMgr.ETouchBehavior.触る && j == 2)
							{
								f_bForceFirstPlay = true;
							}
							if (this.m_eTouchBehNow == VRTouchMgr.ETouchBehavior.無し && j == 2)
							{
								f_bForceFirstPlay = true;
							}
							eTouchHandNow = (this.m_eTouchHandNow = (VRTouchMgr.EHand)i);
							etouchPos = (this.m_eTouchPosNow = keyValuePair.Key);
							eTouchBehNow = (this.m_eTouchBehNow = (VRTouchMgr.ETouchBehavior)j);
							this.PlayVoice_First(touchBehavior.m_dicOrderNo[this.m_nOrderNoNow], f_bFirstPlay, f_bForceFirstPlay);
							this.PlayMotionScript(this.m_MotionScriptNow.GetScript(this.m_eTouchPosNow, this.m_eTouchBehNow));
						}
						flag2 = true;
						break;
					}
				}
				if (flag2)
				{
					break;
				}
			}
			if (flag2)
			{
				break;
			}
		}
		SceneVRTouch.TouchVoiceScript.TouchBehavior touchBehavior2;
		if (this.m_eTouchPosNow != VRTouchMgr.ETouchPos.無し && this.m_TouchMgr.GetBehaviorTouchOrGrab(this.m_eTouchHandNow, this.m_eTouchPosNow, 0) && this.m_dicTouchVoiceScript[this.m_eTouchPosNow].m_listBeh.TryGetValue(this.m_eTouchBehNow, out touchBehavior2))
		{
			int num = (int)this.m_fKouhunNow;
			SceneVRTouch.TouchVoiceScript.TouchOrder touchOrder = null;
			try
			{
				touchOrder = touchBehavior2.m_dicOrderNo[this.m_nOrderNoNow];
			}
			catch
			{
				Debug.LogError(string.Concat(new object[]
				{
					"発生順オーバー:",
					this.m_nOrderNoNow,
					"/",
					touchBehavior2.nOrderNoMax,
					":",
					this.m_eTouchPosNow,
					":",
					this.m_eTouchBehNow
				}));
			}
			if (this.m_fKouhunNow <= (float)touchOrder.m_nLimit)
			{
				this.m_fKouhunNow += Time.deltaTime / (float)touchOrder.m_nTime;
				if ((float)touchOrder.m_nLimit < this.m_fKouhunNow)
				{
					this.m_fKouhunNow = (float)touchOrder.m_nLimit;
				}
				flag = true;
			}
			if (num < (int)this.m_fKouhunNow)
			{
				this.m_nOrderNoNow++;
				if (touchBehavior2.nOrderNoMax < this.m_nOrderNoNow)
				{
					this.m_nOrderNoNow = touchBehavior2.nOrderNoMax;
				}
				Debug.Log("興奮度UP:" + this.m_nOrderNoNow);
				this.PlayVoice_First(touchBehavior2.m_dicOrderNo[this.m_nOrderNoNow], true, false);
			}
			eTouchHandNow = this.m_eTouchHandNow;
			etouchPos = this.m_eTouchPosNow;
			eTouchBehNow = this.m_eTouchBehNow;
		}
		SceneVRTouch.TouchVoiceScript.TouchBehavior touchBehavior3;
		if (!flag && this.m_dicTouchVoiceScript[VRTouchMgr.ETouchPos.無し].m_listBeh.TryGetValue(VRTouchMgr.ETouchBehavior.無し, out touchBehavior3))
		{
			this.m_fKouhunNow += Time.deltaTime / (float)touchBehavior3.m_dicOrderNo[0].m_nTime;
			if (this.m_fKouhunNow <= 0f)
			{
				this.m_fKouhunNow = 0f;
			}
			if (0f < this.m_fKouhunBefore && this.m_fKouhunNow <= 0f)
			{
				this.PlayVoice_First(touchBehavior3.m_dicOrderNo[0], true, false);
				this.PlayMotionScript(this.m_MotionScriptNow.m_strNeutralScript);
			}
		}
		if (etouchPos == VRTouchMgr.ETouchPos.無し)
		{
			this.PlayVoice_After();
		}
		this.m_fKouhunBefore = this.m_fKouhunNow;
		this.m_eTouchHandNow = eTouchHandNow;
		this.m_eTouchPosNow = etouchPos;
		this.m_eTouchBehNow = eTouchBehNow;
		this.m_TouchMgr.FrameEnd();
		if (GameMain.Instance.ScriptMgr.is_motion_all_prop_seq)
		{
			GameMain.Instance.ScriptMgr.motion_all_prop_seq_maid.AllProcPropSeqStart();
			GameMain.Instance.ScriptMgr.motion_all_prop_seq_maid = null;
			GameMain.Instance.ScriptMgr.is_motion_all_prop_seq = false;
		}
		this.m_MotionScriptMgr.Update();
	}

	private List<SceneVRTouch.BGInfo> m_lstBgInfo;

	private string[] m_strConditionNameTbl = new string[]
	{
		"無し",
		"緊張",
		"お近づき",
		"信頼",
		"恋人",
		"愛奴"
	};

	private Dictionary<VRTouchMgr.ETouchPos, SceneVRTouch.TouchVoiceScript> m_dicTouchVoiceScript;

	private List<SceneVRTouch.TouchMotionScript> m_listTouchMotionScript;

	private Maid m_maid;

	private Vector3 m_vCamResetTargetPos;

	private Vector2 m_vCamResetAngle;

	private float m_fCamResetDistance;

	private VRTouchMgr m_TouchMgr;

	private VRTouchKagManager m_kag;

	[SerializeField]
	private VRTouchMgr.EHand m_eTouchHandNow = VRTouchMgr.EHand.Non;

	[SerializeField]
	private VRTouchMgr.ETouchPos m_eTouchPosNow;

	[SerializeField]
	private VRTouchMgr.ETouchBehavior m_eTouchBehNow;

	[SerializeField]
	private int m_nOrderNoNow;

	[SerializeField]
	private float m_fKouhunNow;

	private float m_fKouhunBefore;

	private SceneVRTouch.BGInfo m_BGInfoNow;

	private SceneVRTouch.TouchMotionScript m_MotionScriptNow;

	private string m_strScriptArgLabelEnd;

	private string m_strScriptArgLabelFT;

	public List<SceneEdit.PVBInfo> m_listPose = new List<SceneEdit.PVBInfo>();

	public List<SceneEdit.PVBInfo> m_listBg = new List<SceneEdit.PVBInfo>();

	private UIButton m_btnEnd;

	private ScriptManagerFast m_MotionScriptMgr;

	private Coroutine m_coVoicePlayBraeth;

	private bool m_bVoiceAfter;

	private bool m_bNowPlayFirst;

	private bool m_bSkippedPlayFirst;

	public class RandVoiceList
	{
		public void AddSet(string f_strVoiceFileName, string f_strFace, string f_strFaceBlend)
		{
			this.m_listVoiceFace.Add(new SceneVRTouch.RandVoiceList.Set(f_strVoiceFileName + ".ogg", f_strFace, f_strFaceBlend));
		}

		private void Shuffle()
		{
			System.Random random = new System.Random();
			List<SceneVRTouch.RandVoiceList.Set> listVoiceFace = this.m_listVoiceFace;
			int i = listVoiceFace.Count;
			while (i > 1)
			{
				i--;
				int index = random.Next(i + 1);
				SceneVRTouch.RandVoiceList.Set value = listVoiceFace[index];
				listVoiceFace[index] = listVoiceFace[i];
				listVoiceFace[i] = value;
			}
		}

		public SceneVRTouch.RandVoiceList.Set GetVoiceFace()
		{
			if (this.m_nNow == 0)
			{
				this.Shuffle();
			}
			SceneVRTouch.RandVoiceList.Set result = this.m_listVoiceFace[this.m_nNow];
			if (this.m_listVoiceFace.Count <= this.m_nNow)
			{
				this.m_nNow = 0;
			}
			return result;
		}

		private List<SceneVRTouch.RandVoiceList.Set> m_listVoiceFace = new List<SceneVRTouch.RandVoiceList.Set>();

		private int m_nNow;

		public class Set
		{
			public Set(string f_strVoiceFileName, string f_strFace, string f_strFaceBlend)
			{
				this.m_strVoiceFileName = f_strVoiceFileName;
				this.m_strFace = f_strFace;
				this.m_strFaceBlend = f_strFaceBlend;
			}

			public string m_strVoiceFileName;

			public string m_strFace;

			public string m_strFaceBlend;
		}
	}

	private class BGInfo
	{
		public int nID;

		public string strThumbFileName;

		public string strName;

		public string strScriptTagFT;

		public string strFileName;

		public string strBGM;

		public string strCondition;

		public Vector3 vPos;

		public float fRot;

		public string strValidPack;

		public Texture2D texThumb;
	}

	private class TouchVoiceScript
	{
		public Dictionary<VRTouchMgr.ETouchBehavior, SceneVRTouch.TouchVoiceScript.TouchBehavior> m_listBeh = new Dictionary<VRTouchMgr.ETouchBehavior, SceneVRTouch.TouchVoiceScript.TouchBehavior>();

		public class Waist
		{
			public void SetRandVoiceListFirst(Dictionary<int, SceneVRTouch.RandVoiceList> f_dicRandVoiceList)
			{
				this.m_dicRandVoiceFirst = f_dicRandVoiceList;
			}

			public void SetRandVoiceListBreath(Dictionary<int, SceneVRTouch.RandVoiceList> f_dicRandVoiceList)
			{
				this.m_dicRandVoiceBreath = f_dicRandVoiceList;
			}

			public void SetRandVoiceListAfter(Dictionary<int, SceneVRTouch.RandVoiceList> f_dicRandVoiceList)
			{
				this.m_dicRandVoiceAfter = f_dicRandVoiceList;
			}

			public SceneVRTouch.RandVoiceList GetRandVoiceListFirst(int f_nKouhun)
			{
				return this.m_dicRandVoiceFirst[f_nKouhun];
			}

			public SceneVRTouch.RandVoiceList GetRandVoiceListBreath(int f_nKouhun)
			{
				return this.m_dicRandVoiceBreath[f_nKouhun];
			}

			public SceneVRTouch.RandVoiceList GetRandVoiceListAfter(int f_nKouhun)
			{
				return this.m_dicRandVoiceAfter[f_nKouhun];
			}

			public int nWaistLower;

			public int nWaistUpper = 999;

			public string strScriptFirst;

			public string strScriptBreath;

			public string strScriptAfter;

			private Dictionary<int, SceneVRTouch.RandVoiceList> m_dicRandVoiceFirst = new Dictionary<int, SceneVRTouch.RandVoiceList>();

			private Dictionary<int, SceneVRTouch.RandVoiceList> m_dicRandVoiceBreath = new Dictionary<int, SceneVRTouch.RandVoiceList>();

			private Dictionary<int, SceneVRTouch.RandVoiceList> m_dicRandVoiceAfter = new Dictionary<int, SceneVRTouch.RandVoiceList>();
		}

		public class Cup
		{
			public SceneVRTouch.TouchVoiceScript.Waist FindWaistRange(int nMin, int nMax)
			{
				return this.m_listWaist.Find((SceneVRTouch.TouchVoiceScript.Waist a) => a.nWaistLower == nMin && a.nWaistUpper == nMax);
			}

			public SceneVRTouch.TouchVoiceScript.Waist FindWaistValue(int nValue)
			{
				return this.m_listWaist.Find((SceneVRTouch.TouchVoiceScript.Waist a) => a.nWaistLower <= nValue && nValue <= a.nWaistUpper);
			}

			public SceneVRTouch.TouchVoiceScript.Waist GetWaist(Maid f_maid)
			{
				SceneVRTouch.TouchVoiceScript.Waist waist = this.FindWaistValue(f_maid.status.body.waist);
				NDebug.Assert(waist != null, "ウェスト条件に合うボイススクリプトがありません。");
				return waist;
			}

			public int nCupLower;

			public int nCupUpper = 9;

			public List<SceneVRTouch.TouchVoiceScript.Waist> m_listWaist = new List<SceneVRTouch.TouchVoiceScript.Waist>();
		}

		public class TouchCondition
		{
			public SceneVRTouch.TouchVoiceScript.Cup FindCupRange(int nMin, int nMax)
			{
				return this.m_listCup.Find((SceneVRTouch.TouchVoiceScript.Cup a) => a.nCupLower == nMin && a.nCupUpper == nMax);
			}

			public SceneVRTouch.TouchVoiceScript.Cup FindCupValue(int nValue)
			{
				return this.m_listCup.Find((SceneVRTouch.TouchVoiceScript.Cup a) => a.nCupLower <= nValue && nValue <= a.nCupUpper);
			}

			public SceneVRTouch.TouchVoiceScript.Cup GetCup(Maid f_maid)
			{
				SceneVRTouch.TouchVoiceScript.Cup cup = this.FindCupValue((int)(f_maid.status.body.cup[0] - 'A'));
				NDebug.Assert(cup != null, "カップ条件に合うボイススクリプトがありません。");
				return cup;
			}

			public Relation eRelation;

			public List<SceneVRTouch.TouchVoiceScript.Cup> m_listCup = new List<SceneVRTouch.TouchVoiceScript.Cup>();
		}

		public class TouchOrder
		{
			public SceneVRTouch.TouchVoiceScript.TouchCondition GetTouchCondition(Maid f_maid)
			{
				return this.m_dicCondition[f_maid.status.relation];
			}

			public int m_nLimit;

			public int m_nTime;

			public Dictionary<Relation, SceneVRTouch.TouchVoiceScript.TouchCondition> m_dicCondition = new Dictionary<Relation, SceneVRTouch.TouchVoiceScript.TouchCondition>();
		}

		public class TouchBehavior
		{
			public int nOrderNoMax;

			public Dictionary<int, SceneVRTouch.TouchVoiceScript.TouchOrder> m_dicOrderNo = new Dictionary<int, SceneVRTouch.TouchVoiceScript.TouchOrder>();
		}
	}

	private class TouchMotionScript
	{
		public void AddScript(VRTouchMgr.ETouchPos f_pos, VRTouchMgr.ETouchBehavior f_beh, string f_strScript)
		{
			Dictionary<VRTouchMgr.ETouchBehavior, string> dictionary;
			if (!this.m_dicTouchScript.TryGetValue(f_pos, out dictionary))
			{
				dictionary = new Dictionary<VRTouchMgr.ETouchBehavior, string>();
				this.m_dicTouchScript.Add(f_pos, dictionary);
			}
			dictionary.Add(f_beh, f_strScript);
		}

		public string GetScript(VRTouchMgr.ETouchPos f_pos, VRTouchMgr.ETouchBehavior f_beh)
		{
			return this.m_dicTouchScript[f_pos][f_beh];
		}

		public string GetScriptNeutral()
		{
			return this.m_strNeutralScript;
		}

		public int m_nId;

		public string m_strThumb;

		public string m_strFTScript;

		public string m_strNeutralScript;

		public Texture2D m_texThumb;

		public Dictionary<VRTouchMgr.ETouchPos, Dictionary<VRTouchMgr.ETouchBehavior, string>> m_dicTouchScript = new Dictionary<VRTouchMgr.ETouchPos, Dictionary<VRTouchMgr.ETouchBehavior, string>>();
	}

	private class ButtonPose : SceneEdit.PVBInfo
	{
		public SceneVRTouch.TouchMotionScript m_motion;
	}

	private class ButtonBG : SceneEdit.PVBInfo
	{
		public SceneVRTouch.BGInfo m_bg;
	}
}
