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

public class DesktopScreen : MonoBehaviour
{
	private void Start()
	{
		this.m_nDisplayNo = GameMain.Instance.CMSystem.DesktopCaptureMonitorNo;
		Material sharedMaterial = base.GetComponent<Renderer>().sharedMaterial;
		sharedMaterial.mainTexture = Resources.Load<Texture2D>("System/Texture/unsupported");
		this.m_dup = base.gameObject.AddComponent<DesktopDuplication>();
		bool flag = this.m_dup.CreateDesktopDuplication("\\\\.\\DISPLAY" + this.m_nDisplayNo.ToString());
		Size<float> size;
		if (flag && this.m_dup.width != 0 && this.m_dup.height != 0)
		{
			Debug.Log("ディスプレイクラス生成成功:DISPLAY" + this.m_nDisplayNo.ToString());
			Texture2D texture2D = new Texture2D(this.m_dup.width, this.m_dup.height, TextureFormat.BGRA32, false);
			this.m_dup.render_texture = texture2D;
			sharedMaterial.mainTextureScale = new Vector2(-1f, 1f);
			sharedMaterial.mainTexture = texture2D;
			size.width = (float)this.m_dup.width;
			size.height = (float)this.m_dup.height;
			this.m_trCursor = base.transform.Find("Cursor");
			this.m_trCursorBack = base.transform.Find("Screen_back/CursorBack");
		}
		else
		{
			Debug.Log("ディスプレイクラス生成失敗:DISPLAY" + this.m_nDisplayNo.ToString());
			List<Monitor.InfoData> info_data_list = Monitor.info_data_list;
			if (0 < this.m_nDisplayNo && this.m_nDisplayNo <= info_data_list.Count)
			{
				Monitor.InfoData infoData = info_data_list[this.m_nDisplayNo - 1];
				size.width = (float)infoData.width;
				size.height = (float)infoData.height;
			}
			else
			{
				Debug.Log("ディスプレイ番号無し:DISPLAY" + this.m_nDisplayNo.ToString());
				size.width = 1600f;
				size.height = 900f;
			}
		}
		base.transform.localScale = new Vector3(this.m_fSize, 1f, size.height * this.m_fSize / size.width);
	}

	private void Update()
	{
		if (this.m_trCursor != null && this.m_dup.is_mouse_pointer_visible)
		{
			this.m_trCursor.localPosition = new Vector3((float)this.m_dup.mouse_pointer_x / (float)this.m_dup.width * 10f - 5f, 0.005f, (float)this.m_dup.mouse_pointer_y / (float)this.m_dup.height * -10f + 5f);
			this.m_trCursorBack.localPosition = this.m_trCursor.localPosition;
		}
	}

	public int m_nDisplayNo = 1;

	public float m_fSize = 0.3f;

	private DesktopDuplication m_dup;

	private Transform m_trCursor;

	private Transform m_trCursorBack;
}
