public override void Load(BinaryReader reader, int size) { //long start_pos = reader.BaseStream.Position; HeaderUnk1 = reader.ReadUInt32(); uint chunkNameLength = reader.ReadUInt32(); ChunkName = new string(reader.ReadChars((int)chunkNameLength)); HeaderUnk2 = reader.ReadUInt32(); HeaderUnk3 = reader.ReadUInt32(); HeaderUnk4 = reader.ReadByte(); if ((HeaderUnk1 & 0x10000) != 0) { SkydomeID = reader.ReadUInt32(); } LightsAmbient = new List <LightAmbient>(); LightsDirectional = new List <LightDirectional>(); LightsPoint = new List <LightPoint>(); LightsNegative = new List <LightNegative>(); if ((HeaderUnk1 & 0x20000) != 0) { HeaderBuffer = reader.ReadBytes(0x400); uint LightsNum = reader.ReadUInt32(); uint LightAmbientNum = reader.ReadUInt32(); uint LightDirectionalNum = reader.ReadUInt32(); uint LightPointNum = reader.ReadUInt32(); uint LightNegativeNum = reader.ReadUInt32(); if (LightAmbientNum > 0) { for (int i = 0; i < LightAmbientNum; i++) { LightAmbient light = new LightAmbient(); light.Flags = reader.ReadBytes(4); light.Radius = reader.ReadSingle(); light.Color_R = reader.ReadSingle(); light.Color_G = reader.ReadSingle(); light.Color_B = reader.ReadSingle(); light.Color_Unk = reader.ReadSingle(); light.Position = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.Vector1 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.Vector2 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); LightsAmbient.Add(light); } } if (LightDirectionalNum > 0) { for (int i = 0; i < LightDirectionalNum; i++) { LightDirectional light = new LightDirectional(); light.Flags = reader.ReadBytes(4); light.Radius = reader.ReadSingle(); light.Color_R = reader.ReadSingle(); light.Color_G = reader.ReadSingle(); light.Color_B = reader.ReadSingle(); light.Color_Unk = reader.ReadSingle(); light.Position = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.Vector1 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.Vector2 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.Vector3 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.unkShort = reader.ReadUInt16(); LightsDirectional.Add(light); } } if (LightPointNum > 0) { for (int i = 0; i < LightPointNum; i++) { LightPoint light = new LightPoint(); light.Flags = reader.ReadBytes(4); light.Radius = reader.ReadSingle(); light.Color_R = reader.ReadSingle(); light.Color_G = reader.ReadSingle(); light.Color_B = reader.ReadSingle(); light.Color_Unk = reader.ReadSingle(); light.Position = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.Vector1 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.Vector2 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.unkShort = reader.ReadUInt16(); LightsPoint.Add(light); } } if (LightNegativeNum > 0) { for (int i = 0; i < LightNegativeNum; i++) { LightNegative light = new LightNegative(); light.Flags = reader.ReadBytes(4); light.Radius = reader.ReadSingle(); light.Color_R = reader.ReadSingle(); light.Color_G = reader.ReadSingle(); light.Color_B = reader.ReadSingle(); light.Color_Unk = reader.ReadSingle(); light.Position = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.Vector1 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.Vector2 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.Vector3 = new Pos(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); light.unkFloat1 = reader.ReadSingle(); light.unkFloat2 = reader.ReadSingle(); light.unkUInt1 = reader.ReadUInt32(); light.unkUInt2 = reader.ReadUInt32(); light.unkUShort1 = reader.ReadUInt16(); light.unkUShort2 = reader.ReadUInt16(); LightsNegative.Add(light); } } } SceneryRoot = null; if (HeaderUnk3 == 0x160A) { unkVar5 = reader.ReadUInt32(); SceneryRoot = LoadScenery(reader); } else { //Console.WriteLine("no scenery!! bug?"); } //Console.WriteLine("end pos: " + (reader.BaseStream.Position - start_pos) + " target: " + size); }
private void Awake() { main = this; }
public override void Initialize() { if (TextureNames == null) { throw new ArgumentNullException("DaytimeChange: Textures not set!"); } if (TextureNames.Count() < TEXTURE_COUNT) { throw new ArgumentException("DaytimeChange: Texture count less than " + TEXTURE_COUNT.ToString() + "!"); } sun = ResourceManager.Instance.CurrentScene.GetObject(SunID); lightDay = ResourceManager.Instance.CurrentScene.DirectionalLights[LightDayID]; lightNight = ResourceManager.Instance.CurrentScene.DirectionalLights[LightNightID]; ambient = ResourceManager.Instance.CurrentScene.AmbientLight; foreach (ObjectComponent comp in this.MyObject.Components) { if (comp.GetType() == typeof(CustomModel)) { myModel = (CustomModel)comp; if (myModel == null) { break; } if (myModel.Mat[0].GetType() != typeof(SkyboxMaterial)) { throw new InvalidOperationException("DaytimeChange: Skybox's material is not SkyboxMaterial!"); } myMaterial = (SkyboxMaterial)myModel.Mat[0]; break; } } if (sun == null || lightDay == null || lightNight == null || myModel == null || myMaterial == null || ambient == null) { throw new ArgumentNullException("DaytimeChange: Some of the objects do not exist!"); } foreach (ObjectComponent comp in sun.Components) { if (comp.GetType() == typeof(Billboard)) { if (((Billboard)comp).Mat != null) { sunMaterial = ((Billboard)comp).Mat; } } } startDaylightColor = lightDay.LightColor; startDaylightSpecular = lightDay.LightSpecularColor; startNightColor = lightNight.LightColor; startNightSpecular = lightNight.LightSpecularColor; startAmbientColor = ambient.LightColor; for (int i = 0; i < TEXTURE_COUNT; ++i) { if (TextureNames[i] != null) { textures[i] = ResourceManager.Instance.LoadTextureCube(TextureNames[i]); } } if (textures[0] != null) { myMaterial.CubeMap = textures[0]; } if (textures[1] != null) { myMaterial.CubeMap1 = textures[1]; } if (textures[2] != null) { myMaterial.CubeMap2 = textures[2]; } if (textures[3] != null) { myMaterial.CubeMap3 = textures[3]; } GameObject pt = ResourceManager.Instance.CurrentScene.GetObject("PlayerTime"); if (pt == null) { throw new ArgumentNullException("DaytimeChange: PlayerTime object does not exist!"); } foreach (ObjectComponent comp in pt.Components) { if (comp.GetType() == typeof(PlayerTime)) { cTime = (PlayerTime)comp; } } if (cTime == null) { throw new ArgumentNullException("DaytimeChange: PlayerTime object has no PlayerTime component!"); } long t = cTime.TotalMilliseconds; if (t >= SunriseMS - StateChangeMS && t <= SunsetMS + StateChangeMS) { switched = true; } else { switched = false; } startSunDiffuse = myMaterial.DiffuseColor; base.Initialize(); }