using System;
using System.IO;
using UnityEngine;

public class MaidParts : MonoBehaviour
{
	public bool Initialize(GameObject f_objMaid, Maid f_Maid)
	{
		this.m_objMaid = f_objMaid;
		this.m_Maid = f_Maid;
		for (int i = 0; i < 10; i++)
		{
			this.m_aryPartsColor[i] = MaidParts.m_aryPartsColorDefault[i];
			this.m_aryPartsColorTable[i] = new Texture2D(256, 1, TextureFormat.RGBA32, false);
			this.m_aryPartsColorTable[i].wrapMode = TextureWrapMode.Clamp;
		}
		return true;
	}

	public void SetPartsColor(MaidParts.PARTS_COLOR f_eColorType, MaidParts.PartsColor f_cColor)
	{
		this.m_aryPartsColor[(int)f_eColorType] = f_cColor;
		UTY.UpdateColorTableTexture(f_cColor, ref this.m_aryPartsColorTable[(int)f_eColorType]);
		this.m_Maid.body0.UpdateInfinityColor(f_eColorType);
	}

	public MaidParts.PartsColor GetPartsColor(MaidParts.PARTS_COLOR f_eColorType)
	{
		return this.m_aryPartsColor[(int)f_eColorType];
	}

	public Texture2D GetPartsColorTableTex(MaidParts.PARTS_COLOR f_eColorType)
	{
		return this.m_aryPartsColorTable[(int)f_eColorType];
	}

	public unsafe bool Serialize(BinaryWriter f_bwWrite)
	{
		f_bwWrite.Write("CM3D2_MULTI_COL");
		f_bwWrite.Write(1250);
		f_bwWrite.Write(this.m_aryPartsColor.Length);
		for (int i = 0; i < this.m_aryPartsColor.Length; i++)
		{
			MaidParts.PARTS_COLOR parts_COLOR = (MaidParts.PARTS_COLOR)i;
			f_bwWrite.Write(parts_COLOR.ToString());
			fixed (MaidParts.PartsColor* ptr = &this.m_aryPartsColor[i])
			{
				f_bwWrite.Write(ptr->m_bUse);
				f_bwWrite.Write(ptr->m_nMainHue);
				f_bwWrite.Write(ptr->m_nMainChroma);
				f_bwWrite.Write(ptr->m_nMainBrightness);
				f_bwWrite.Write(ptr->m_nMainContrast);
				f_bwWrite.Write(ptr->m_nShadowRate);
				f_bwWrite.Write(ptr->m_nShadowHue);
				f_bwWrite.Write(ptr->m_nShadowChroma);
				f_bwWrite.Write(ptr->m_nShadowBrightness);
				f_bwWrite.Write(ptr->m_nShadowContrast);
			}
		}
		f_bwWrite.Write(MaidParts.PARTS_COLOR.MAX.ToString());
		return true;
	}

	public unsafe static MaidParts.PartsColor[] DeserializePre(BinaryReader f_brRead)
	{
		MaidParts.PartsColor[] array = new MaidParts.PartsColor[10];
		for (int i = 0; i < 10; i++)
		{
			array[i] = MaidParts.m_aryPartsColorDefault[i];
		}
		string a = f_brRead.ReadString();
		NDebug.Assert(a == "CM3D2_MULTI_COL", "無限色のヘッダーが不正です。");
		int num = f_brRead.ReadInt32();
		int num2 = f_brRead.ReadInt32();
		if (num <= 1200 && ((200 > num) ? (7 != num2) : (9 != num2)))
		{
			NDebug.Assert("無限色数が異なります。セーブデータが破損しています。", false);
		}
		if (num <= 1200)
		{
			string[] array2 = new string[]
			{
				"EYE_L",
				"EYE_R",
				"HAIR",
				"EYE_BROW",
				"UNDER_HAIR",
				"SKIN",
				"NIPPLE",
				"HAIR_OUTLINE",
				"SKIN_OUTLINE"
			};
			for (int j = 0; j < num2; j++)
			{
				MaidParts.PartsColor partsColor = default(MaidParts.PartsColor);
				partsColor.m_bUse = f_brRead.ReadBoolean();
				partsColor.m_nMainHue = f_brRead.ReadInt32();
				partsColor.m_nMainChroma = f_brRead.ReadInt32();
				partsColor.m_nMainBrightness = f_brRead.ReadInt32();
				partsColor.m_nMainContrast = f_brRead.ReadInt32();
				partsColor.m_nShadowRate = f_brRead.ReadInt32();
				partsColor.m_nShadowHue = f_brRead.ReadInt32();
				partsColor.m_nShadowChroma = f_brRead.ReadInt32();
				partsColor.m_nShadowBrightness = f_brRead.ReadInt32();
				partsColor.m_nShadowContrast = f_brRead.ReadInt32();
				MaidParts.PARTS_COLOR parts_COLOR = (MaidParts.PARTS_COLOR)Enum.Parse(typeof(MaidParts.PARTS_COLOR), array2[j], true);
				array[(int)parts_COLOR] = partsColor;
			}
		}
		else
		{
			string value;
			while ((value = f_brRead.ReadString()) != MaidParts.PARTS_COLOR.MAX.ToString())
			{
				MaidParts.PARTS_COLOR parts_COLOR2 = (MaidParts.PARTS_COLOR)Enum.Parse(typeof(MaidParts.PARTS_COLOR), value, true);
				fixed (MaidParts.PartsColor* ptr = &array[(int)parts_COLOR2])
				{
					ptr->m_bUse = f_brRead.ReadBoolean();
					ptr->m_nMainHue = f_brRead.ReadInt32();
					ptr->m_nMainChroma = f_brRead.ReadInt32();
					ptr->m_nMainBrightness = f_brRead.ReadInt32();
					ptr->m_nMainContrast = f_brRead.ReadInt32();
					ptr->m_nShadowRate = f_brRead.ReadInt32();
					ptr->m_nShadowHue = f_brRead.ReadInt32();
					ptr->m_nShadowChroma = f_brRead.ReadInt32();
					ptr->m_nShadowBrightness = f_brRead.ReadInt32();
					ptr->m_nShadowContrast = f_brRead.ReadInt32();
				}
			}
		}
		return array;
	}

	private static readonly MaidParts.PartsColor[] m_aryPartsColorDefault = new MaidParts.PartsColor[]
	{
		new MaidParts.PartsColor
		{
			m_nMainHue = 6,
			m_nMainChroma = 117,
			m_nMainBrightness = 179,
			m_nMainContrast = 94
		},
		new MaidParts.PartsColor
		{
			m_nMainHue = 6,
			m_nMainChroma = 117,
			m_nMainBrightness = 179,
			m_nMainContrast = 94
		},
		new MaidParts.PartsColor
		{
			m_nMainHue = 69,
			m_nMainChroma = 186,
			m_nMainBrightness = 270,
			m_nMainContrast = 94
		},
		new MaidParts.PartsColor
		{
			m_nMainHue = 0,
			m_nMainChroma = 0,
			m_nMainBrightness = 183,
			m_nMainContrast = 0
		},
		new MaidParts.PartsColor
		{
			m_nMainHue = 0,
			m_nMainChroma = 0,
			m_nMainBrightness = 0,
			m_nMainContrast = 0
		},
		new MaidParts.PartsColor
		{
			m_nMainHue = 18,
			m_nMainChroma = 149,
			m_nMainBrightness = 247,
			m_nMainContrast = 100
		},
		new MaidParts.PartsColor
		{
			m_nMainHue = 18,
			m_nMainChroma = 149,
			m_nMainBrightness = 247,
			m_nMainContrast = 100
		},
		new MaidParts.PartsColor
		{
			m_nMainHue = 69,
			m_nMainChroma = 0,
			m_nMainBrightness = 67,
			m_nMainContrast = 100
		},
		new MaidParts.PartsColor
		{
			m_nMainHue = 18,
			m_nMainChroma = 100,
			m_nMainBrightness = 138,
			m_nMainContrast = 85
		},
		new MaidParts.PartsColor
		{
			m_nMainHue = 18,
			m_nMainChroma = 36,
			m_nMainBrightness = 434,
			m_nMainContrast = 100,
			m_nShadowRate = 255,
			m_nShadowHue = 18,
			m_nShadowChroma = 79,
			m_nShadowBrightness = 321,
			m_nShadowContrast = 0
		}
	};

	private MaidParts.PartsColor[] m_aryPartsColor = new MaidParts.PartsColor[10];

	private Texture2D[] m_aryPartsColorTable = new Texture2D[10];

	private GameObject m_objMaid;

	private Maid m_Maid;

	public enum PARTS_COLOR
	{
		NONE = -1,
		EYE_L,
		EYE_R,
		HAIR,
		EYE_BROW,
		UNDER_HAIR,
		SKIN,
		NIPPLE,
		HAIR_OUTLINE,
		SKIN_OUTLINE,
		EYE_WHITE,
		MAX
	}

	public struct PartsColor
	{
		public bool m_bUse;

		public int m_nMainHue;

		public int m_nMainChroma;

		public int m_nMainBrightness;

		public int m_nMainContrast;

		public int m_nShadowRate;

		public int m_nShadowHue;

		public int m_nShadowChroma;

		public int m_nShadowBrightness;

		public int m_nShadowContrast;
	}
}
