public bool Deserialize()
 {
     if (this._data == null)
     {
         this._result = DeserializeResult.NoData;
         return(false);
     }
     if (this._result == DeserializeResult.Success)
     {
         return(true);
     }
     try
     {
         this._data.position = (int)this._offset;
         ushort num1 = this._data.ReadUShort();
         for (int index = 0; index < (int)num1; ++index)
         {
             string      str         = this._data.ReadString();
             ClassMember classMember = (ClassMember)null;
             System.Type key         = (System.Type)null;
             if (str.StartsWith("@"))
             {
                 if (this._extraProperties == null)
                 {
                     this._extraProperties = new MultiMap <string, object>();
                 }
                 byte num2 = this._data.ReadByte();
                 if (((int)num2 & 1) != 0)
                 {
                     byte num3 = (byte)((uint)num2 >> 1);
                     BinaryClassMember.typeMap.TryGetKey(num3, out key);
                 }
                 else
                 {
                     key = Editor.GetType(this._data.ReadString());
                 }
                 str = str.Substring(1, str.Length - 1);
             }
             else
             {
                 classMember = Editor.GetMember(this.GetType(), str);
                 if (classMember != null)
                 {
                     key = classMember.type;
                 }
             }
             uint num4 = this._data.ReadUInt();
             if (key != (System.Type)null)
             {
                 int position = this._data.position;
                 if (typeof(BinaryClassChunk).IsAssignableFrom(key))
                 {
                     BinaryClassChunk binaryClassChunk = BinaryClassChunk.DeserializeHeader(key, this._data, root: false);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)binaryClassChunk);
                     }
                     else
                     {
                         this._headerDictionary[str] = binaryClassChunk;
                     }
                     this._data.position = position + (int)num4;
                 }
                 else if (key.IsArray)
                 {
                     Array array = this.DeserializeArray(key, key.GetElementType(), this._data);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)array);
                     }
                     else
                     {
                         classMember.SetValue((object)this, (object)array);
                     }
                 }
                 else if (key.IsGenericType && key.GetGenericTypeDefinition() == typeof(List <>))
                 {
                     Array array    = this.DeserializeArray(typeof(object[]), key.GetGenericArguments()[0], this._data);
                     IList instance = Activator.CreateInstance(key) as IList;
                     foreach (object obj in array)
                     {
                         instance.Add(obj);
                     }
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)instance);
                     }
                     else
                     {
                         classMember.SetValue((object)this, (object)instance);
                     }
                 }
                 else if (key.IsGenericType && key.GetGenericTypeDefinition() == typeof(HashSet <>))
                 {
                     Array array     = this.DeserializeArray(typeof(object[]), key.GetGenericArguments()[0], this._data);
                     IList instance1 = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(key.GetGenericArguments()[0]));
                     foreach (object obj in array)
                     {
                         instance1.Add(obj);
                     }
                     object instance2 = Activator.CreateInstance(key, (object)instance1);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, instance2);
                     }
                     else
                     {
                         classMember.SetValue((object)this, instance2);
                     }
                 }
                 else
                 {
                     object element = !key.IsEnum ? this._data.Read(key, false) : (object)this._data.ReadInt();
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, element);
                     }
                     else
                     {
                         classMember.SetValue((object)this, element);
                     }
                 }
             }
             else
             {
                 this._data.position += (int)num4;
             }
         }
     }
     catch (Exception ex)
     {
         this._exception = ex;
         this._result    = DeserializeResult.ExceptionThrown;
         return(false);
     }
     this._result = DeserializeResult.Success;
     return(true);
 }
 public void Clear()
 {
     this._items       = new MultiMap <T, T2>();
     this._globalItems = new List <T2>();
 }
        protected override void OnSerialize()
        {
            this._serializedData.Write(this._index);
            if (this._device is Keyboard)
            {
                this.serializedData.Write((byte)0);
            }
            else if (this._device is XInputPad)
            {
                this.serializedData.Write((byte)1);
            }
            else if (this._device is GenericController)
            {
                if ((this._device as GenericController).device is XInputPad)
                {
                    this.serializedData.Write((byte)1);
                }
                else
                {
                    this.serializedData.Write((byte)2);
                }
            }
            else
            {
                this.serializedData.Write((byte)2);
            }
            MultiMap <string, int> multiMap = (MultiMap <string, int>)null;

            if (this._device != null)
            {
                multiMap = this._inputProfile.GetMappings(this._device.GetType());
            }
            if (multiMap != null)
            {
                this.serializedData.Write(true);
                byte val1 = 0;
                foreach (KeyValuePair <string, List <int> > keyValuePair in (MultiMap <string, int, List <int> >)multiMap)
                {
                    if (keyValuePair.Value.Count > 0)
                    {
                        ++val1;
                    }
                }
                this.serializedData.Write(val1);
                foreach (KeyValuePair <string, List <int> > keyValuePair in (MultiMap <string, int, List <int> >)multiMap)
                {
                    if (keyValuePair.Value.Count > 0)
                    {
                        this.serializedData.Write(Triggers.toIndex[keyValuePair.Key]);
                        this.serializedData.Write(keyValuePair.Value[0]);
                    }
                }
                DeviceInputMapping deviceInputMapping = this._device.overrideMap == null?Input.GetDefaultMapping(this._device.productName, this._device.productGUID, p : this._profile) : this._device.overrideMap;

                if (deviceInputMapping.graphicMap.Count > 0)
                {
                    this.serializedData.Write(true);
                    this.serializedData.Write((byte)deviceInputMapping.graphicMap.Count);
                    using (Dictionary <int, string> .Enumerator enumerator = deviceInputMapping.graphicMap.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            KeyValuePair <int, string> pair = enumerator.Current;
                            Sprite sprite = Input.buttonStyles.FirstOrDefault <Sprite>((Func <Sprite, bool>)(x => x.texture != null && x.texture.textureName == pair.Value));
                            byte   val2   = 0;
                            if (sprite != null)
                            {
                                val2 = (byte)Input.buttonStyles.IndexOf(sprite);
                            }
                            this.serializedData.Write(pair.Key);
                            this.serializedData.Write(val2);
                        }
                    }
                }
                else
                {
                    this.serializedData.Write(false);
                }
            }
            else
            {
                this.serializedData.Write(false);
            }
            base.OnSerialize();
        }
        public override void Update()
        {
            ChallengeLevel._timer.Update();
            if (this._fading)
            {
                DuckGame.Graphics.fade = Lerp.Float(DuckGame.Graphics.fade, 0.0f, 0.05f);
                if ((double)DuckGame.Graphics.fade >= 0.00999999977648258)
                {
                    return;
                }
                if (this._validityTest)
                {
                    ArcadeTestDialogue.success = this._challenge.wonTrophies.Count > 0 && this._challenge.wonTrophies[0].type == TrophyType.Developer;
                    Level.current          = (Level)ArcadeTestDialogue.currentEditor;
                    DuckGame.Graphics.fade = 1f;
                }
                else
                {
                    if (this.things[typeof(EditorTestLevel)].Count <Thing>() > 0)
                    {
                        Level.current = (Level)(this.things[typeof(EditorTestLevel)].First <Thing>() as EditorTestLevel).editor;
                        Music.Stop();
                    }
                    else
                    {
                        Level.current = Arcade.currentArcade == null ? (Level)ArcadeLevel.currentArcade : (Level)Arcade.currentArcade;
                    }
                    this._fading = false;
                }
            }
            else
            {
                if ((double)this._restartMessageWait > 0.0)
                {
                    this._restartMessageWait -= 0.008f;
                }
                else
                {
                    HUD.CloseCorner(HUDCorner.TopLeft);
                }
                if (this._doRestart)
                {
                    ChallengeLevel.running = false;
                    this._waitForRestart  -= 0.04f;
                    if ((double)this._waitForRestart <= 0.0)
                    {
                        this._restarting = true;
                    }
                }
                this._waitFade -= 0.04f;
                if (!this._didFade && (double)this._waitFade <= 0.0 && (double)DuckGame.Graphics.fade < 1.0)
                {
                    DuckGame.Graphics.fade = Lerp.Float(DuckGame.Graphics.fade, 1f, 0.04f);
                }
                else if (this._restarting)
                {
                    ChallengeLevel.running         = false;
                    this.transitionSpeedMultiplier = 2f;
                    EditorTestLevel editorTestLevel = (EditorTestLevel)null;
                    if (this.things[typeof(EditorTestLevel)].Count <Thing>() > 0)
                    {
                        editorTestLevel = this.things[typeof(EditorTestLevel)].First <Thing>() as EditorTestLevel;
                    }
                    Level.current = !(this._level != "") ? (Level) new ChallengeLevel(this._levelData, this._validityTest) : (Level) new ChallengeLevel(this._level);
                    Level.current.transitionSpeedMultiplier    = 2f;
                    ((ChallengeLevel)Level.current)._waitSpawn = 0.0f;
                    if (editorTestLevel == null)
                    {
                        return;
                    }
                    Level.current.AddThing((Thing)editorTestLevel);
                }
                else
                {
                    if ((double)this._waitFade > 0.0)
                    {
                        return;
                    }
                    this._didFade = true;
                    if (this._finished)
                    {
                        ChallengeLevel.running = false;
                        this.PauseLogic();
                        if ((double)this._finishWait > 0.0)
                        {
                            this._finishWait -= 0.01f;
                        }
                        else
                        {
                            if (!this._playedEndMusic)
                            {
                                this._playedEndMusic          = true;
                                Level.current.simulatePhysics = false;
                                ArcadeFrame arcadeFrame = (ArcadeFrame)null;
                                if (this._win)
                                {
                                    if (ArcadeLevel.currentArcade != null)
                                    {
                                        arcadeFrame = ArcadeLevel.currentArcade.GetFrame();
                                        if (arcadeFrame != null)
                                        {
                                            Vec2  renderTargetSize = arcadeFrame.GetRenderTargetSize();
                                            float renderTargetZoom = arcadeFrame.GetRenderTargetZoom();
                                            if (this._captureTarget == null)
                                            {
                                                this._captureTarget = new RenderTarget2D((int)((double)renderTargetSize.x * 6.0), (int)((double)renderTargetSize.y * 6.0));
                                            }
                                            int    num    = DuckGame.Graphics.width / 320;
                                            Camera camera = new Camera(0.0f, 0.0f, (float)this._captureTarget.width * renderTargetZoom, (float)this._captureTarget.height * renderTargetZoom);
                                            if (ChallengeLevel._duck != null)
                                            {
                                                Layer.HUD.visible = false;
                                                MonoMain.RenderGame(MonoMain.screenCapture);
                                                Layer.HUD.visible = true;
                                                Matrix result;
                                                Matrix.CreateOrthographicOffCenter(0.0f, (float)MonoMain.screenCapture.width, (float)MonoMain.screenCapture.height, 0.0f, 0.0f, -1f, out result);
                                                result.M41 += -0.5f * result.M11;
                                                result.M42 += -0.5f * result.M22;
                                                Matrix matrix = Level.current.camera.getMatrix();
                                                Vec3   vec3   = (Vec3)DuckGame.Graphics.viewport.Project((Vector3) new Vec3(ChallengeLevel._duck.cameraPosition.x, ChallengeLevel._duck.cameraPosition.y, 0.0f), (Microsoft.Xna.Framework.Matrix)result, (Microsoft.Xna.Framework.Matrix)matrix, (Microsoft.Xna.Framework.Matrix)Matrix.Identity);
                                                DuckGame.Graphics.SetRenderTarget(this._captureTarget);
                                                camera.center = new Vec2(vec3.x, vec3.y);
                                                if ((double)camera.bottom > (double)MonoMain.screenCapture.height)
                                                {
                                                    camera.centerY = (float)MonoMain.screenCapture.height - camera.height / 2f;
                                                }
                                                if ((double)camera.top < 0.0)
                                                {
                                                    camera.centerY = camera.height / 2f;
                                                }
                                                if ((double)camera.right > (double)MonoMain.screenCapture.width)
                                                {
                                                    camera.centerX = (float)MonoMain.screenCapture.width - camera.width / 2f;
                                                }
                                                if ((double)camera.left < 0.0)
                                                {
                                                    camera.centerX = camera.width / 2f;
                                                }
                                                DuckGame.Graphics.Clear(Color.Black);
                                                DuckGame.Graphics.screen.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone, (MTEffect)null, camera.getMatrix());
                                                DuckGame.Graphics.Draw((Tex2D)MonoMain.screenCapture, 0.0f, 0.0f);
                                                DuckGame.Graphics.screen.End();
                                                DuckGame.Graphics.SetRenderTarget((RenderTarget2D)null);
                                            }
                                        }
                                    }
                                    if (this._challenge.wonTrophies.Count > 0 && this._challenge.wonTrophies[0].type == TrophyType.Developer)
                                    {
                                        SFX.Play("developerWin");
                                    }
                                    else
                                    {
                                        SFX.Play("challengeWin");
                                    }
                                    this._showEndTextWait = 1f;
                                }
                                else
                                {
                                    SFX.Play("challengeLose");
                                    this._showEndTextWait = 1f;
                                }
                                if (this._challenge.wonTrophies.Count > 0)
                                {
                                    this._trophyGroup = new UIComponent(Layer.HUD.camera.width / 2f, Layer.HUD.camera.height / 2f, 0.0f, 0.0f);
                                    this._trophyMenu  = new UIMenu("@LWING@" + this._challenge.challenge.name + "@RWING@", Layer.HUD.camera.width / 2f, Layer.HUD.camera.height / 2f, 210f, conString: "@DPAD@MOVE  @SELECT@SELECT");
                                    UIDivider uiDivider1 = new UIDivider(false, 0.0f, 6f);
                                    UIDivider uiDivider2 = new UIDivider(true, 0.0f);
                                    SpriteMap spriteMap  = new SpriteMap("challengeTrophy", 70, 65);
                                    if (this._challenge.wonTrophies.Count > 0)
                                    {
                                        if (this._challenge.wonTrophies[0].type == TrophyType.Bronze)
                                        {
                                            spriteMap.frame = 1;
                                            uiDivider2.leftSection.Add((UIComponent) new UIText("BRONZE", Colors.Bronze, UIAlign.Top), true);
                                        }
                                        else if (this._challenge.wonTrophies[0].type == TrophyType.Silver)
                                        {
                                            spriteMap.frame = 2;
                                            uiDivider2.leftSection.Add((UIComponent) new UIText("SILVER", Colors.Silver, UIAlign.Top), true);
                                        }
                                        else if (this._challenge.wonTrophies[0].type == TrophyType.Gold)
                                        {
                                            spriteMap.frame = 3;
                                            uiDivider2.leftSection.Add((UIComponent) new UIText("GOLD", Colors.Gold, UIAlign.Top), true);
                                        }
                                        else if (this._challenge.wonTrophies[0].type == TrophyType.Platinum)
                                        {
                                            spriteMap.frame = 4;
                                            uiDivider2.leftSection.Add((UIComponent) new UIText("PLATINUM", Colors.Platinum, UIAlign.Top), true);
                                        }
                                        else if (this._challenge.wonTrophies[0].type == TrophyType.Developer)
                                        {
                                            spriteMap.frame = 5;
                                            uiDivider2.leftSection.Add((UIComponent) new UIText("UR THE BEST", Colors.Developer, UIAlign.Top), true);
                                        }
                                    }
                                    uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.White, UIAlign.Left), true);
                                    bool flag = false;
                                    ChallengeSaveData saveData = Challenges.GetSaveData(this.id, ChallengeLevel._duck.profile);
                                    int bestTime = saveData.bestTime;
                                    if (saveData.bestTime == 0 || (int)(ChallengeLevel.timer.elapsed.TotalSeconds * 1000.0) < saveData.bestTime)
                                    {
                                        saveData.bestTime = (int)(ChallengeLevel.timer.elapsed.TotalSeconds * 1000.0);
                                    }
                                    if (this._challenge.wonTrophies[0].type > saveData.trophy)
                                    {
                                        saveData.trophy = this._challenge.wonTrophies[0].type;
                                        if (saveData.trophy > TrophyType.Silver)
                                        {
                                            flag = true;
                                        }
                                    }
                                    int targets1 = saveData.targets;
                                    if (ChallengeLevel.targetsShot > saveData.targets)
                                    {
                                        saveData.targets = ChallengeLevel.targetsShot;
                                    }
                                    int targets2 = saveData.targets;
                                    if (ChallengeLevel.goodiesGot > saveData.goodies)
                                    {
                                        saveData.goodies = ChallengeLevel.goodiesGot;
                                    }
                                    if (this._challenge.challenge.hasTimeRequirements)
                                    {
                                        uiDivider2.leftSection.Add((UIComponent) new UIText("TIME", Color.White, UIAlign.Left), true);
                                        uiDivider2.leftSection.Add((UIComponent) new UIText(MonoMain.TimeString(ChallengeLevel.timer.elapsed, small: true), Color.Lime, UIAlign.Right), true);
                                        uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.White, UIAlign.Left), true);
                                        if (targets1 != 0)
                                        {
                                            if ((double)bestTime < ChallengeLevel.timer.elapsed.TotalSeconds * 1000.0)
                                            {
                                                TimeSpan span = TimeSpan.FromMilliseconds(ChallengeLevel.timer.elapsed.TotalSeconds * 1000.0 - (double)bestTime);
                                                uiDivider2.leftSection.Add((UIComponent) new UIText("DIFFERENCE", Color.White, UIAlign.Left), true);
                                                uiDivider2.leftSection.Add((UIComponent) new UIText("+" + MonoMain.TimeString(span, small: true), Color.Red, UIAlign.Right), true);
                                            }
                                            else
                                            {
                                                TimeSpan span = TimeSpan.FromMilliseconds((double)bestTime - ChallengeLevel.timer.elapsed.TotalSeconds * 1000.0);
                                                uiDivider2.leftSection.Add((UIComponent) new UIText("DIFFERENCE", Color.White, UIAlign.Left), true);
                                                uiDivider2.leftSection.Add((UIComponent) new UIText("-" + MonoMain.TimeString(span, small: true), Color.Lime, UIAlign.Right), true);
                                                flag = true;
                                            }
                                        }
                                        else
                                        {
                                            uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.White, UIAlign.Left), true);
                                            uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.White, UIAlign.Left), true);
                                        }
                                    }
                                    if (saveData.trophy < TrophyType.Gold)
                                    {
                                        flag = false;
                                    }
                                    if (this._challenge.challenge.countTargets)
                                    {
                                        if (this._challenge.challenge.prefix != "" && this._challenge.challenge.prefix != null)
                                        {
                                            uiDivider2.leftSection.Add((UIComponent) new UIText(this._challenge.challenge.prefix, Color.White, UIAlign.Left), true);
                                        }
                                        else
                                        {
                                            uiDivider2.leftSection.Add((UIComponent) new UIText("TARGETS", Color.White, UIAlign.Left), true);
                                        }
                                        string textVal = Convert.ToString(ChallengeLevel.targetsShot);
                                        Color  c       = Color.Lime;
                                        if (targets1 != 0)
                                        {
                                            if (targets1 < ChallengeLevel.targetsShot)
                                            {
                                                int num = ChallengeLevel.targetsShot - targets1;
                                                c       = Color.Lime;
                                                textVal = textVal + " (+" + Convert.ToString(num) + ")";
                                                flag    = true;
                                            }
                                            else if (targets1 > ChallengeLevel.targetsShot)
                                            {
                                                int num = targets1 - ChallengeLevel.targetsShot;
                                                c       = Color.Red;
                                                textVal = textVal + " (-" + Convert.ToString(num) + ")";
                                            }
                                            else
                                            {
                                                c = Color.White;
                                            }
                                        }
                                        uiDivider2.leftSection.Add((UIComponent) new UIText(textVal, c, UIAlign.Right), true);
                                        uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.White, UIAlign.Left), true);
                                    }
                                    if (this._challenge.challenge.countGoodies)
                                    {
                                        if (this._challenge.challenge.prefix != "" && this._challenge.challenge.prefix != null)
                                        {
                                            uiDivider2.leftSection.Add((UIComponent) new UIText(this._challenge.challenge.prefix, Color.White, UIAlign.Left), true);
                                        }
                                        else
                                        {
                                            uiDivider2.leftSection.Add((UIComponent) new UIText("NUMBER", Color.White, UIAlign.Left), true);
                                        }
                                        string textVal = Convert.ToString(ChallengeLevel.goodiesGot);
                                        Color  c       = Color.Lime;
                                        if (targets2 != 0)
                                        {
                                            if (targets2 < ChallengeLevel.goodiesGot)
                                            {
                                                int num = ChallengeLevel.goodiesGot - targets2;
                                                c       = Color.Lime;
                                                textVal = textVal + " (+" + Convert.ToString(num) + ")";
                                                flag    = true;
                                            }
                                            else if (targets2 > ChallengeLevel.goodiesGot)
                                            {
                                                int num = targets2 - ChallengeLevel.goodiesGot;
                                                c       = Color.Red;
                                                textVal = textVal + " (-" + Convert.ToString(num) + ")";
                                            }
                                            else
                                            {
                                                c = Color.White;
                                            }
                                        }
                                        uiDivider2.leftSection.Add((UIComponent) new UIText(textVal, c, UIAlign.Right), true);
                                        uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.White, UIAlign.Left), true);
                                    }
                                    uiDivider2.rightSection.Add((UIComponent) new UIImage((Sprite)spriteMap, UIAlign.Right), true);
                                    uiDivider1.leftSection.Add((UIComponent)uiDivider2, true);
                                    uiDivider1.rightSection.vertical     = false;
                                    uiDivider1.rightSection.borderSize.y = 2f;
                                    if (this._validityTest)
                                    {
                                        if (this._challenge.wonTrophies.Count > 0 && this._challenge.wonTrophies[0].type == TrophyType.Developer)
                                        {
                                            uiDivider1.rightSection.Add((UIComponent) new UIMenuItem("CONTINUE   ", (UIMenuAction) new UIMenuActionCloseMenuSetBoolean(this._trophyGroup, this._quit), UIAlign.Left), true);
                                        }
                                        else
                                        {
                                            uiDivider1.rightSection.Add((UIComponent) new UIMenuItem("RETRY", (UIMenuAction) new UIMenuActionCloseMenuSetBoolean(this._trophyGroup, this._restart), UIAlign.Left), true);
                                        }
                                    }
                                    else
                                    {
                                        uiDivider1.rightSection.Add((UIComponent) new UIMenuItem("CONTINUE   ", (UIMenuAction) new UIMenuActionCloseMenuSetBoolean(this._trophyGroup, this._quit), UIAlign.Left), true);
                                        uiDivider1.rightSection.Add((UIComponent) new UIMenuItem("RETRY", (UIMenuAction) new UIMenuActionCloseMenuSetBoolean(this._trophyGroup, this._restart), UIAlign.Left), true);
                                    }
                                    this._trophyMenu.Add((UIComponent)uiDivider1, true);
                                    this._trophyMenu.Close();
                                    this._trophyGroup.Add((UIComponent)this._trophyMenu, false);
                                    this._trophyGroup.Close();
                                    Level.Add((Thing)this._trophyGroup);
                                    if (arcadeFrame != null && flag && saveData != null)
                                    {
                                        saveData.frameID     = arcadeFrame._identifier;
                                        saveData.frameImage  = Editor.TextureToString((Texture2D)(Tex2D)this._captureTarget);
                                        arcadeFrame.saveData = saveData;
                                    }
                                    Challenges.Save(this.id);
                                    Profiles.Save(ChallengeLevel._duck.profile);
                                }
                                else
                                {
                                    this._trophyGroup = new UIComponent(Layer.HUD.camera.width / 2f, Layer.HUD.camera.height / 2f, 0.0f, 0.0f);
                                    this._trophyMenu  = new UIMenu("@LWING@" + this._challenge.challenge.name + "@RWING@", Layer.HUD.camera.width / 2f, Layer.HUD.camera.height / 2f, 210f, conString: "@DPAD@MOVE  @SELECT@SELECT");
                                    UIDivider uiDivider1 = new UIDivider(false, 0.0f, 6f);
                                    UIDivider uiDivider2 = new UIDivider(true, 0.0f);
                                    uiDivider2.leftSection.Add((UIComponent) new UIText("FAILED", Color.Red, UIAlign.Top), true);
                                    uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.White, UIAlign.Left), true);
                                    uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.White, UIAlign.Left), true);
                                    uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.Lime, UIAlign.Right), true);
                                    uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.White, UIAlign.Left), true);
                                    uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.White, UIAlign.Left), true);
                                    uiDivider2.leftSection.Add((UIComponent) new UIText("               ", Color.White, UIAlign.Left), true);
                                    uiDivider2.rightSection.Add((UIComponent) new UIImage((Sprite) new SpriteMap("challengeTrophy", 70, 65)
                                    {
                                        frame = 0
                                    }, UIAlign.Right), true);
                                    uiDivider1.leftSection.Add((UIComponent)uiDivider2, true);
                                    uiDivider1.rightSection.vertical     = false;
                                    uiDivider1.rightSection.borderSize.y = 2f;
                                    uiDivider1.rightSection.Add((UIComponent) new UIMenuItem("CONTINUE   ", (UIMenuAction) new UIMenuActionCloseMenuSetBoolean(this._trophyGroup, this._quit), UIAlign.Left), true);
                                    uiDivider1.rightSection.Add((UIComponent) new UIMenuItem("RETRY", (UIMenuAction) new UIMenuActionCloseMenuSetBoolean(this._trophyGroup, this._restart), UIAlign.Left), true);
                                    this._trophyMenu.Add((UIComponent)uiDivider1, true);
                                    this._trophyMenu.Close();
                                    this._trophyGroup.Add((UIComponent)this._trophyMenu, false);
                                    this._trophyGroup.Add((UIComponent)Options.optionsMenu, false);
                                    Options.openOnClose = this._trophyMenu;
                                    this._trophyGroup.Close();
                                    Level.Add((Thing)this._trophyGroup);
                                }
                            }
                            if ((double)this._showEndTextWait > 0.0)
                            {
                                this._showEndTextWait -= 0.01f;
                            }
                            else
                            {
                                this._fontFade = 1f;
                                if ((double)this._showResultsWait > 0.0)
                                {
                                    this._showResultsWait -= 0.01f;
                                }
                                else if (!this._showedEndMenu)
                                {
                                    this._trophyGroup.Open();
                                    this._trophyMenu.Open();
                                    MonoMain.pauseMenu = this._trophyGroup;
                                    SFX.Play("pause", 0.6f, -0.2f);
                                    this._showedEndMenu = true;
                                }
                                if (this._restart.value)
                                {
                                    this._restarting = true;
                                    SFX.Play("resume", 0.6f);
                                }
                                else
                                {
                                    if (!this._quit.value)
                                    {
                                        return;
                                    }
                                    this._fading = true;
                                    SFX.Play("resume", 0.6f);
                                }
                            }
                        }
                    }
                    else
                    {
                        this._waitSpawn -= 0.06f;
                        if ((double)this._waitSpawn > 0.0)
                        {
                            return;
                        }
                        if (this._pendingSpawns != null && this._pendingSpawns.Count > 0)
                        {
                            this._waitSpawn = 0.5f;
                            Duck pendingSpawn = this._pendingSpawns[0];
                            this.AddThing((Thing)pendingSpawn);
                            this._pendingSpawns.RemoveAt(0);
                            Vec3 color = pendingSpawn.profile.persona.color;
                            Level.Add((Thing) new SpawnLine(pendingSpawn.x, pendingSpawn.y, 0, 0.0f, new Color((int)color.x, (int)color.z, (int)color.z), 32f));
                            Level.Add((Thing) new SpawnLine(pendingSpawn.x, pendingSpawn.y, 0, -4f, new Color((int)color.x, (int)color.y, (int)color.z), 4f));
                            Level.Add((Thing) new SpawnLine(pendingSpawn.x, pendingSpawn.y, 0, 4f, new Color((int)color.x, (int)color.y, (int)color.z), 4f));
                            SFX.Play("pullPin", 0.7f);
                            ChallengeLevel._duck          = pendingSpawn;
                            this._challenge               = this.things[typeof(ChallengeMode)].First <Thing>() as ChallengeMode;
                            ChallengeLevel.random         = this._challenge.random.value;
                            this._challenge.duck          = pendingSpawn;
                            ChallengeLevel._timer.maxTime = TimeSpan.FromSeconds((double)this._challenge.challenge.trophies[0].timeRequirement);
                            HUD.AddCornerTimer(HUDCorner.BottomRight, "", (Timer)ChallengeLevel._timer);
                            if (this._challenge.challenge.countTargets)
                            {
                                int targets = this._challenge.challenge.trophies[0].targets;
                                HUD.AddCornerCounter(HUDCorner.BottomLeft, "@RETICULE@", new FieldBinding((object)this, "targetsShot"), targets > 0 ? targets : 0);
                            }
                            if (this._challenge.challenge.countGoodies)
                            {
                                MultiMap <System.Type, ISequenceItem> multiMap = new MultiMap <System.Type, ISequenceItem>();
                                foreach (ISequenceItem element in Level.current.things[typeof(ISequenceItem)])
                                {
                                    System.Type  type     = element.GetType();
                                    SequenceItem sequence = (element as Thing).sequence;
                                    if (sequence.isValid && sequence.type == SequenceItemType.Goody)
                                    {
                                        multiMap.Add(type, element);
                                    }
                                }
                                System.Type key = (System.Type)null;
                                int         num = 0;
                                foreach (KeyValuePair <System.Type, List <ISequenceItem> > keyValuePair in (MultiMap <System.Type, ISequenceItem, List <ISequenceItem> >)multiMap)
                                {
                                    if (keyValuePair.Value.Count > num)
                                    {
                                        key = keyValuePair.Key;
                                        num = keyValuePair.Value.Count;
                                    }
                                }
                                if (key != (System.Type)null)
                                {
                                    ISequenceItem sequenceItem = multiMap[key][0];
                                    string        text         = "@STARGOODY@";
                                    switch (sequenceItem)
                                    {
                                    case LapGoody _:
                                    case InvisiGoody _:
                                        text = "@LAPGOODY@";
                                        break;

                                    case SuitcaseGoody _:
                                        text = "@SUITCASEGOODY@";
                                        break;

                                    case Window _:
                                    case YellowBarrel _:
                                    case Door _:
                                        text = "@RETICULE@";
                                        break;
                                    }
                                    int goodies = this._challenge.challenge.trophies[0].goodies;
                                    HUD.AddCornerCounter(HUDCorner.BottomLeft, text, new FieldBinding((object)this, "goodiesGot"), goodies > 0 ? goodies : 0);
                                }
                            }
                            if (this._firstStart)
                            {
                                if (ChallengeLevel.random)
                                {
                                    IEnumerable <Thing> thing = this.things[typeof(ISequenceItem)];
                                    if (thing.Count <Thing>() > 0)
                                    {
                                        thing.ElementAt <Thing>(Rando.Int(thing.Count <Thing>() - 1)).sequence.BeginRandomSequence();
                                    }
                                }
                                else
                                {
                                    foreach (TargetDuck targetDuck in this.things[typeof(TargetDuck)])
                                    {
                                        if (targetDuck.sequence.order == 0)
                                        {
                                            targetDuck.sequence.Activate();
                                        }
                                    }
                                }
                                this._firstStart = false;
                            }
                            if (!Music.stopped)
                            {
                                return;
                            }
                            if ((string)this._challenge.music == "")
                            {
                                Music.Load("Challenging");
                            }
                            else if ((string)this._challenge.music == "donutmystery")
                            {
                                Music.Load("spacemystery");
                            }
                            else
                            {
                                Music.Load(Music.FindSong((string)this._challenge.music));
                            }
                        }
                        else if (!this._started)
                        {
                            this._waitAfterSpawn -= 0.06f;
                            if ((double)this._waitAfterSpawn > 0.0)
                            {
                                return;
                            }
                            ++this._waitAfterSpawnDings;
                            if (this._waitAfterSpawnDings > 2)
                            {
                                this._started          = true;
                                this.simulatePhysics   = true;
                                ChallengeLevel.running = true;
                                SFX.Play("ding");
                                ChallengeLevel._timer.Start();
                                if (Music.stopped)
                                {
                                    Music.PlayLoaded();
                                }
                            }
                            else
                            {
                                SFX.Play("preStartDing");
                            }
                            this._waitSpawn = 1.1f;
                        }
                        else
                        {
                            this._fontFade -= 0.1f;
                            if ((double)this._fontFade < 0.0)
                            {
                                this._fontFade = 0.0f;
                            }
                            this.PauseLogic();
                        }
                    }
                }
            }
        }