Example #1
0
 private void TryInitialize()
 {
   this.ThisLevelMesh.ClearGroups();
   this.NextLevelMesh.ClearGroups();
   lock (FarawayPlaceHost.FarawayWaterMutex)
     this.FarawayWaterMesh = (Mesh) null;
   (this.NextLevelMesh.Effect as FarawayEffect).CleanUp();
   foreach (Script script1 in Enumerable.Where<Script>((IEnumerable<Script>) this.LevelManager.Scripts.Values, (Func<Script, bool>) (x => Enumerable.Any<ScriptAction>((IEnumerable<ScriptAction>) x.Actions, (Func<ScriptAction, bool>) (y => y.Operation == "ChangeToFarAwayLevel")))))
   {
     Volume volume1;
     if (this.LevelManager.Volumes.TryGetValue(Enumerable.FirstOrDefault<ScriptTrigger>((IEnumerable<ScriptTrigger>) script1.Triggers, (Func<ScriptTrigger, bool>) (x =>
     {
       if (x.Object.Type == "Volume")
         return x.Event == "Enter";
       else
         return false;
     })).Object.Identifier.Value, out volume1))
     {
       FaceOrientation faceOrientation = Enumerable.FirstOrDefault<FaceOrientation>((IEnumerable<FaceOrientation>) volume1.Orientations);
       ScriptAction scriptAction1 = Enumerable.FirstOrDefault<ScriptAction>((IEnumerable<ScriptAction>) script1.Actions, (Func<ScriptAction, bool>) (x => x.Operation == "ChangeToFarAwayLevel"));
       string str1 = scriptAction1.Arguments[0];
       int num1 = 0;
       string songName;
       FaceOrientation orientation;
       Vector2 vector2;
       bool flag;
       float num2;
       float num3;
       float num4;
       using (MemoryContentManager memoryContentManager = new MemoryContentManager((IServiceProvider) this.Game.Services, this.Game.Content.RootDirectory))
       {
         string str2 = str1;
         if (!MemoryContentManager.AssetExists("Levels" + (object) '\\' + str1.Replace('/', '\\')))
           str2 = this.LevelManager.FullPath.Substring(0, this.LevelManager.FullPath.LastIndexOf("/") + 1) + str1.Substring(str1.LastIndexOf("/") + 1);
         LevelReader.MinimalRead = true;
         Level level;
         try
         {
           level = memoryContentManager.Load<Level>("Levels/" + str2);
         }
         catch (Exception ex)
         {
           Logger.Log("FarawayPlaceHost", Common.LogSeverity.Warning, "Couldn't load faraway place destination level : " + str1);
           continue;
         }
         LevelReader.MinimalRead = false;
         songName = level.SongName;
         int key;
         try
         {
           key = int.Parse(scriptAction1.Arguments[1]);
         }
         catch (Exception ex)
         {
           key = -1;
         }
         Volume volume2 = key == -1 || !level.Volumes.ContainsKey(key) ? level.Volumes[Enumerable.First<ScriptTrigger>((IEnumerable<ScriptTrigger>) Enumerable.First<Script>((IEnumerable<Script>) level.Scripts.Values, (Func<Script, bool>) (s => Enumerable.Any<ScriptAction>((IEnumerable<ScriptAction>) s.Actions, (Func<ScriptAction, bool>) (a =>
         {
           if (a.Object.Type == "Level" && a.Operation.Contains("Level"))
             return a.Arguments[0] == this.LevelManager.Name;
           else
             return false;
         })))).Triggers, (Func<ScriptTrigger, bool>) (t =>
         {
           if (t.Object.Type == "Volume")
             return t.Event == "Enter";
           else
             return false;
         })).Object.Identifier.Value] : level.Volumes[key];
         orientation = Enumerable.FirstOrDefault<FaceOrientation>((IEnumerable<FaceOrientation>) volume2.Orientations);
         Vector3 vector3 = (level.Size / 2f - (volume2.From + volume2.To) / 2f) * (FezMath.RightVector(FezMath.AsViewpoint(orientation)) + Vector3.Up);
         vector2 = new Vector2(vector3.X + vector3.Z, vector3.Y);
         flag = level.WaterType != LiquidType.None;
         num2 = level.WaterHeight - (volume2.From + volume2.To).Y / 2f + this.EngineState.WaterLevelOffset;
         num3 = this.LevelManager.WaterHeight - (volume1.From + volume1.To).Y / 2f - num2 / 4f;
         num4 = level.Size.Y;
         Script script2 = Enumerable.FirstOrDefault<Script>((IEnumerable<Script>) level.Scripts.Values, (Func<Script, bool>) (s =>
         {
           if (Enumerable.Any<ScriptTrigger>((IEnumerable<ScriptTrigger>) s.Triggers, (Func<ScriptTrigger, bool>) (t =>
           {
             if (t.Event == "Start")
               return t.Object.Type == "Level";
             else
               return false;
           })))
             return Enumerable.Any<ScriptAction>((IEnumerable<ScriptAction>) s.Actions, (Func<ScriptAction, bool>) (a =>
             {
               if (a.Object.Type == "Camera")
                 return a.Operation == "SetPixelsPerTrixel";
               else
                 return false;
             }));
           else
             return false;
         }));
         if (script2 != null)
         {
           ScriptAction scriptAction2 = Enumerable.First<ScriptAction>((IEnumerable<ScriptAction>) script2.Actions, (Func<ScriptAction, bool>) (a =>
           {
             if (a.Object.Type == "Camera")
               return a.Operation == "SetPixelsPerTrixel";
             else
               return false;
           }));
           try
           {
             num1 = int.Parse(scriptAction2.Arguments[0]);
           }
           catch (Exception ex)
           {
           }
         }
         num2 = level.WaterHeight;
       }
       Texture2D texture;
       try
       {
         string assetName = "Other Textures/faraway_thumbs/" + (object) str1 + " (" + (string) (object) FezMath.AsViewpoint(orientation) + ")";
         texture = this.CMProvider.CurrentLevel.Load<Texture2D>(assetName);
         texture.Name = assetName;
       }
       catch (Exception ex)
       {
         Logger.Log("FarawayPlacesHost", Common.LogSeverity.Warning, "Couldn't load faraway thumbnail for " + (object) str1 + " (viewpoint = " + (string) (object) FezMath.AsViewpoint(orientation) + ")");
         continue;
       }
       if (!Enumerable.Any<Group>((IEnumerable<Group>) this.ThisLevelMesh.Groups, (Func<Group, bool>) (x => x.Texture == texture)))
       {
         if (num1 == 0)
           num1 = (int) this.CameraManager.PixelsPerTrixel;
         Group group1 = this.ThisLevelMesh.AddFace(new Vector3((float) texture.Width, (float) texture.Height, (float) texture.Width) / 16f / 2f, Vector3.Zero, faceOrientation, true);
         Group group2 = this.NextLevelMesh.AddFace(new Vector3((float) texture.Width, (float) texture.Height, (float) texture.Width) / 16f / 2f, Vector3.Zero, faceOrientation, true);
         FarawayPlaceData farawayPlaceData = new FarawayPlaceData()
         {
           OriginalCenter = (volume1.From + volume1.To) / 2f,
           Viewpoint = FezMath.AsViewpoint(faceOrientation),
           Volume = volume1,
           DestinationOffset = vector2.X * FezMath.RightVector(FezMath.AsViewpoint(faceOrientation)) + Vector3.Up * vector2.Y,
           WaterLevelOffset = new float?(num3),
           DestinationLevelName = str1,
           DestinationWaterLevel = num2,
           DestinationLevelSize = num4
         };
         if (this.LevelManager.WaterType == LiquidType.None && flag)
         {
           if (this.HorizontalGradientTex == null || this.HorizontalGradientTex.IsDisposed)
             this.HorizontalGradientTex = this.CMProvider.Global.Load<Texture2D>("Other Textures/WaterHorizGradient");
           lock (FarawayPlaceHost.FarawayWaterMutex)
           {
             FarawayPlaceHost temp_380 = this;
             // ISSUE: explicit reference operation
             // ISSUE: variable of a reference type
             FarawayPlaceData& temp_381 = @farawayPlaceData;
             Mesh local_28 = new Mesh();
             Mesh temp_383 = local_28;
             DefaultEffect.Textured local_29 = new DefaultEffect.Textured();
             local_29.AlphaIsEmissive = false;
             DefaultEffect.Textured temp_387 = local_29;
             temp_383.Effect = (BaseEffect) temp_387;
             Mesh temp_388;
             Mesh local_43 = temp_388 = local_28;
             // ISSUE: explicit reference operation
             (^temp_381).WaterBodyMesh = temp_388;
             Mesh temp_389 = local_43;
             temp_380.FarawayWaterMesh = temp_389;
             this.FarawayWaterMesh.AddFace(Vector3.One, new Vector3(-0.5f, -1f, -0.5f) + FezMath.Abs(FezMath.AsVector(faceOrientation)) * 0.5f, faceOrientation, false).Material = new Material();
             this.FarawayWaterMesh.AddFace(Vector3.One, new Vector3(-0.5f, -1f, -0.5f) + FezMath.Abs(FezMath.AsVector(faceOrientation)) * 0.5f, faceOrientation, false).Material = new Material();
           }
         }
         group2.CustomData = group1.CustomData = (object) farawayPlaceData;
         group2.Position = group1.Position = farawayPlaceData.OriginalCenter;
         group2.Texture = group1.Texture = (Texture) texture;
         group2.Material = new Material()
         {
           Opacity = 0.125f
         };
         group1.Material = new Material()
         {
           Opacity = 0.125f
         };
         if (volume1.ActorSettings == null)
           volume1.ActorSettings = new VolumeActorSettings();
         volume1.ActorSettings.DestinationSong = songName;
         switch (num1)
         {
           case 1:
             volume1.ActorSettings.DestinationRadius = 80f;
             break;
           case 2:
             volume1.ActorSettings.DestinationRadius = 40f;
             break;
           case 3:
             volume1.ActorSettings.DestinationRadius = 26.66667f;
             break;
           case 4:
             volume1.ActorSettings.DestinationRadius = 20f;
             break;
           case 5:
             volume1.ActorSettings.DestinationRadius = 16f;
             break;
         }
         volume1.ActorSettings.DestinationPixelsPerTrixel = (float) num1;
         volume1.ActorSettings.DestinationOffset = vector2;
       }
     }
   }
 }
Example #2
0
 private void InitializeSky()
 {
   if (this.LevelManager.Sky == null)
     return;
   ContentManager contentManager = this.LevelManager.Name == null ? this.CMProvider.Global : this.CMProvider.GetForLevel(this.LevelManager.Name);
   string str1 = "Skies/" + this.LevelManager.Sky.Name + "/";
   if (this.LevelManager.Sky.Name == this.lastSkyName && !this.EngineState.InEditor)
   {
     foreach (string str2 in this.LevelManager.Sky.Clouds)
       contentManager.Load<Texture2D>(str1 + str2);
     foreach (SkyLayer skyLayer in this.LevelManager.Sky.Layers)
       contentManager.Load<Texture2D>(str1 + skyLayer.Name);
     try
     {
       this.skyBackground = contentManager.Load<Texture2D>(str1 + this.LevelManager.Sky.Background);
     }
     catch (Exception ex)
     {
       this.skyBackground = contentManager.Load<Texture2D>("Skies/Default/SkyBack");
     }
     if (this.LevelManager.Sky.Stars == null)
       return;
     contentManager.Load<Texture2D>(str1 + this.LevelManager.Sky.Stars);
   }
   else
   {
     this.lastSkyName = this.LevelManager.Sky.Name;
     if (this.LevelManager.Sky.Stars != null)
       this.stars.Texture = (Dirtyable<Texture>) ((Texture) contentManager.Load<Texture2D>(str1 + this.LevelManager.Sky.Stars));
     else
       this.stars.Texture.Set((Texture) null);
     string assetName1 = str1 + this.LevelManager.Sky.Background;
     try
     {
       this.skyBackground = contentManager.Load<Texture2D>(assetName1);
     }
     catch (Exception ex)
     {
       this.skyBackground = contentManager.Load<Texture2D>("Skies/Default/SkyBack");
     }
     this.fogColors = new Color[this.skyBackground.Width];
     Color[] data1 = new Color[this.skyBackground.Width * this.skyBackground.Height];
     this.skyBackground.GetData<Color>(data1);
     Array.Copy((Array) data1, this.skyBackground.Width * this.skyBackground.Height / 2, (Array) this.fogColors, 0, this.skyBackground.Width);
     using (MemoryContentManager memoryContentManager = new MemoryContentManager(contentManager.ServiceProvider, contentManager.RootDirectory))
     {
       Texture2D texture2D = (Texture2D) null;
       if (this.LevelManager.Sky.CloudTint != null)
       {
         string assetName2 = str1 + this.LevelManager.Sky.CloudTint;
         try
         {
           texture2D = memoryContentManager.Load<Texture2D>(assetName2);
         }
         catch (Exception ex)
         {
           Logger.Log("Sky Init", Common.LogSeverity.Warning, "Cloud tinting texture could not be found");
         }
       }
       if (texture2D != null)
       {
         this.cloudColors = new Color[texture2D.Width];
         Color[] data2 = new Color[texture2D.Width * texture2D.Height];
         texture2D.GetData<Color>(data2);
         Array.Copy((Array) data2, texture2D.Width * (texture2D.Height / 2), (Array) this.cloudColors, 0, texture2D.Width);
       }
       else
         this.cloudColors = new Color[1]
         {
           Color.White
         };
     }
     this.cloudStates.Clear();
     foreach (Mesh mesh in this.cloudMeshes)
       mesh.Dispose();
     this.cloudMeshes.Clear();
     if (this.BgLayers != null)
       this.BgLayers.ClearGroups();
     else
       this.BgLayers = new Mesh()
       {
         AlwaysOnTop = true,
         DepthWrites = false,
         Effect = (BaseEffect) new DefaultEffect.Textured()
       };
     int num1 = 0;
     foreach (SkyLayer skyLayer in this.LevelManager.Sky.Layers)
     {
       Texture2D texture2D1 = contentManager.Load<Texture2D>(str1 + skyLayer.Name);
       Texture2D texture2D2 = (Texture2D) null;
       if (skyLayer.Name == "OBS_SKY_A")
         texture2D2 = contentManager.Load<Texture2D>(str1 + "OBS_SKY_C");
       int num2 = 0;
       foreach (FaceOrientation faceOrientation in Util.GetValues<FaceOrientation>())
       {
         if (FezMath.IsSide(faceOrientation))
         {
           Group group = this.BgLayers.AddFace(Vector3.One, -FezMath.AsVector(faceOrientation) / 2f, faceOrientation, true);
           group.Texture = texture2D2 == null || faceOrientation == FaceOrientation.Left ? (Texture) texture2D1 : (Texture) texture2D2;
           group.AlwaysOnTop = new bool?(skyLayer.InFront);
           group.Material = new Material()
           {
             Opacity = skyLayer.Opacity
           };
           group.CustomData = (object) new SkyHost.BgLayerState()
           {
             Layer = num1,
             Side = num2++,
             OriginalOpacity = skyLayer.Opacity
           };
         }
       }
       ++num1;
     }
     foreach (Layer key in Util.GetValues<Layer>())
       this.cloudStates.Add(key, new List<SkyHost.CloudState>());
     foreach (string str2 in this.LevelManager.Sky.Clouds)
       this.cloudMeshes.Add(new Mesh()
       {
         AlwaysOnTop = true,
         DepthWrites = false,
         Effect = (BaseEffect) new CloudsEffect(),
         Texture = (Dirtyable<Texture>) ((Texture) contentManager.Load<Texture2D>(str1 + str2)),
         Culling = CullMode.None,
         SamplerState = SamplerState.PointClamp
       });
     float num3 = 64f * this.LevelManager.Sky.Density;
     int num4 = (int) Math.Sqrt((double) num3);
     float num5 = num3 / (float) num4;
     float num6 = RandomHelper.Between(0.0, 6.28318548202515);
     float num7 = RandomHelper.Between(0.0, 192.0);
     if (this.cloudMeshes.Count > 0)
     {
       for (int index1 = 0; index1 < num4; ++index1)
       {
         for (int index2 = 0; (double) index2 < (double) num5; ++index2)
         {
           Group group = RandomHelper.InList<Mesh>(this.cloudMeshes).AddFace(Vector3.One, Vector3.Zero, FaceOrientation.Front, true);
           float num2 = RandomHelper.Between(0.0, 1.0 / (double) num4 * 6.28318548202515);
           float num8 = RandomHelper.Between(0.0, 1.0 / (double) num5 * 192.0);
           this.cloudStates[RandomHelper.EnumField<Layer>()].Add(new SkyHost.CloudState()
           {
             Group = group,
             Phi = (float) (((double) index1 / (double) num4 * 6.28318548202515 + (double) num6 + (double) num2) % 6.28318548202515),
             LocalHeightOffset = (float) (((double) index2 / (double) num5 * 96.0 * 2.0 + (double) num7 + (double) num8) % 192.0 - 96.0)
           });
           group.Material = new Material();
         }
       }
     }
     this.flickerIn = RandomHelper.Between(2.0, 10.0);
     this.ResizeLayers();
     this.ResizeStars();
     this.OnViewpointChanged();
     this.OnViewChanged();
   }
 }
Example #3
0
 public override void Load(string levelName)
 {
   levelName = levelName.Replace('\\', '/');
   string str = levelName;
   Level level;
   using (MemoryContentManager memoryContentManager = new MemoryContentManager((IServiceProvider) this.Game.Services, this.Game.Content.RootDirectory))
   {
     if (!string.IsNullOrEmpty(this.Name))
       levelName = this.Name.Substring(0, this.Name.LastIndexOf("/") + 1) + levelName.Substring(levelName.LastIndexOf("/") + 1);
     if (!MemoryContentManager.AssetExists("Levels" + (object) '\\' + levelName.Replace('/', '\\')))
       levelName = str;
     try
     {
       level = memoryContentManager.Load<Level>("Levels/" + levelName);
     }
     catch (Exception ex)
     {
       Logger.LogError(ex);
       this.oldLevel = new Level();
       return;
     }
   }
   level.Name = levelName;
   ContentManager forLevel = this.CMProvider.GetForLevel(levelName);
   foreach (ArtObjectInstance artObjectInstance in level.ArtObjects.Values)
     artObjectInstance.ArtObject = forLevel.Load<ArtObject>(string.Format("{0}/{1}", (object) "Art Objects", (object) artObjectInstance.ArtObjectName));
   if (level.Sky == null)
     level.Sky = forLevel.Load<Sky>("Skies/" + level.SkyName);
   if (level.TrileSetName != null)
     level.TrileSet = forLevel.Load<TrileSet>("Trile Sets/" + level.TrileSetName);
   if (level.SongName != null)
   {
     level.Song = forLevel.Load<TrackedSong>("Music/" + level.SongName);
     level.Song.Initialize();
   }
   if (this.levelData != null)
     this.GameState.SaveData.ThisLevel.FirstVisit = false;
   this.ClearArtSatellites();
   this.oldLevel = this.levelData ?? new Level();
   this.levelData = level;
 }