Ejemplo n.º 1
0
        public static void LoadGameItem(byte[] itemData, int storageIndex, out ItemType itemType, out object item)
        {
            item = null;
            var itemName = $"GameItem{storageIndex}";
            var reader   = new BinaryReader(new MemoryStream(itemData));

            // parse to enum
            var iItemType = reader.ReadInt32();

            if (!Enum.IsDefined(typeof(ItemType), iItemType))
            {
                Logger.Info("Invalid item type " + iItemType);
                itemType = ItemType.Invalid;
                return;
            }

            itemType = (ItemType)iItemType;
            switch (itemType)
            {
            case ItemType.Bumper: item = new Bumper.Bumper(reader, itemName); break;

            case ItemType.Decal: item = new Decal.Decal(reader, itemName); break;

            case ItemType.DispReel: item = new DispReel.DispReel(reader, itemName); break;

            case ItemType.Flasher: item = new Flasher.Flasher(reader, itemName); break;

            case ItemType.Flipper: item = new Flipper.Flipper(reader, itemName); break;

            case ItemType.Gate: item = new Gate.Gate(reader, itemName); break;

            case ItemType.HitTarget: item = new HitTarget.HitTarget(reader, itemName); break;

            case ItemType.Kicker: item = new Kicker.Kicker(reader, itemName); break;

            case ItemType.Light: item = new Light.Light(reader, itemName); break;

            case ItemType.LightSeq: item = new LightSeq.LightSeq(reader, itemName); break;

            case ItemType.Plunger: item = new Plunger.Plunger(reader, itemName); break;

            case ItemType.Primitive: item = new Primitive.Primitive(reader, itemName); break;

            case ItemType.Ramp: item = new Ramp.Ramp(reader, itemName); break;

            case ItemType.Rubber: item = new Rubber.Rubber(reader, itemName); break;

            case ItemType.Spinner: item = new Spinner.Spinner(reader, itemName); break;

            case ItemType.Surface: item = new Surface.Surface(reader, itemName); break;

            case ItemType.TextBox: item = new TextBox.TextBox(reader, itemName); break;

            case ItemType.Timer: item = new Timer.Timer(reader, itemName); break;

            case ItemType.Trigger: item = new Trigger.Trigger(reader, itemName); break;

            case ItemType.Trough: item = new Trough.Trough(reader, $"VpeGameItem{storageIndex}"); break;

            case ItemType.MetalWireGuide: item = new MetalWireGuide.MetalWireGuide(reader, itemName); break;

            default:
                Logger.Info("Unhandled item type " + itemType);
                itemType = ItemType.Invalid; break;
            }
        }
Ejemplo n.º 2
0
        private static void LoadGameItems(FileTableContainer tableContainer, CFStorage storage, int count, string storagePrefix)
        {
            for (var i = 0; i < count; i++)
            {
                var itemName = $"{storagePrefix}{i}";
                storage.TryGetStream(itemName, out var itemStream);
                if (itemStream == null)
                {
                    Logger.Warn("Could not find stream {0}, skipping.", itemName);
                    continue;
                }
                var itemData = itemStream.GetData();
                if (itemData.Length < 4)
                {
                    Logger.Warn("Skipping {itemName} because it has size of {itemDataLength}.", itemName, itemData.Length);
                    continue;
                }

                var reader = new BinaryReader(new MemoryStream(itemData));

                // parse to enum
                var iItemType = reader.ReadInt32();
                if (!Enum.IsDefined(typeof(ItemType), iItemType))
                {
                    Logger.Info("Invalid item type " + iItemType);
                    return;
                }

                var itemType = (ItemType)iItemType;
                switch (itemType)
                {
                case ItemType.Bumper: {
                    var item = new VisualPinball.Engine.VPT.Bumper.Bumper(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Decal: {
                    tableContainer.Add(new VisualPinball.Engine.VPT.Decal.Decal(reader, itemName));
                    break;
                }

                case ItemType.DispReel: {
                    var item = new VisualPinball.Engine.VPT.DispReel.DispReel(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Flasher: {
                    var item = new VisualPinball.Engine.VPT.Flasher.Flasher(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Flipper: {
                    var item = new VisualPinball.Engine.VPT.Flipper.Flipper(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Gate: {
                    var item = new VisualPinball.Engine.VPT.Gate.Gate(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.HitTarget: {
                    var item = new VisualPinball.Engine.VPT.HitTarget.HitTarget(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Kicker: {
                    var item = new VisualPinball.Engine.VPT.Kicker.Kicker(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Light: {
                    var item = new VisualPinball.Engine.VPT.Light.Light(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.LightSeq: {
                    var item = new VisualPinball.Engine.VPT.LightSeq.LightSeq(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Plunger: {
                    var item = new VisualPinball.Engine.VPT.Plunger.Plunger(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Primitive: {
                    var item = new Primitive.Primitive(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Ramp: {
                    var item = new Ramp.Ramp(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Rubber: {
                    var item = new Rubber.Rubber(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Spinner: {
                    var item = new Spinner.Spinner(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Surface: {
                    var item = new Surface.Surface(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.TextBox: {
                    var item = new TextBox.TextBox(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Timer: {
                    var item = new Timer.Timer(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Trigger: {
                    var item = new Trigger.Trigger(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Trough: {
                    var item = new Trough.Trough(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.MetalWireGuide:
                {
                    var item = new MetalWireGuide.MetalWireGuide(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }
                }
            }
        }