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

            itemType = reader.ReadInt32();
            switch (itemType)
            {
            case ItemType.Bumper: item = new Bumper.Bumper(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.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.Trigger: item = new Trigger.Trigger(reader, itemName); break;

            default: itemType = -1; break;
            }
        }
Example #2
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, itemName); break;

            default:
                Logger.Info("Unhandled item type " + itemType);
                itemType = ItemType.Invalid; break;
            }
        }
        private static void LoadGameItems(Table table, CFStorage storage)
        {
            for (var i = 0; i < table.Data.NumGameItems; i++)
            {
                var itemName = $"GameItem{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));
                var itemType = reader.ReadInt32();
                switch (itemType)
                {
                case ItemType.Bumper: {
                    var item = new VisualPinball.Engine.VPT.Bumper.Bumper(reader, itemName);
                    table.Bumpers[item.Name] = item;
                    break;
                }

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

                case ItemType.DispReel: {
                    var item = new VisualPinball.Engine.VPT.DispReel.DispReel(reader, itemName);
                    table.DispReels[item.Name] = item;
                    break;
                }

                case ItemType.Flasher: {
                    var item = new VisualPinball.Engine.VPT.Flasher.Flasher(reader, itemName);
                    table.Flashers[item.Name] = item;
                    break;
                }

                case ItemType.Flipper: {
                    var item = new VisualPinball.Engine.VPT.Flipper.Flipper(reader, itemName);
                    table.Flippers[item.Name] = item;
                    break;
                }

                case ItemType.Gate: {
                    var item = new VisualPinball.Engine.VPT.Gate.Gate(reader, itemName);
                    table.Gates[item.Name] = item;
                    break;
                }

                case ItemType.HitTarget: {
                    var item = new VisualPinball.Engine.VPT.HitTarget.HitTarget(reader, itemName);
                    table.HitTargets[item.Name] = item;
                    break;
                }

                case ItemType.Kicker: {
                    var item = new VisualPinball.Engine.VPT.Kicker.Kicker(reader, itemName);
                    table.Kickers[item.Name] = item;
                    break;
                }

                case ItemType.Light: {
                    var item = new VisualPinball.Engine.VPT.Light.Light(reader, itemName);
                    table.Lights[item.Name] = item;
                    break;
                }

                case ItemType.LightSeq: {
                    var item = new VisualPinball.Engine.VPT.LightSeq.LightSeq(reader, itemName);
                    table.LightSeqs[item.Name] = item;
                    break;
                }

                case ItemType.Plunger: {
                    var item = new VisualPinball.Engine.VPT.Plunger.Plunger(reader, itemName);
                    table.Plungers[item.Name] = item;
                    break;
                }

                case ItemType.Primitive: {
                    var item = new Primitive.Primitive(reader, itemName);
                    table.Primitives[item.Name] = item;
                    break;
                }

                case ItemType.Ramp: {
                    var item = new Ramp.Ramp(reader, itemName);
                    table.Ramps[item.Name] = item;
                    break;
                }

                case ItemType.Rubber: {
                    var item = new Rubber.Rubber(reader, itemName);
                    table.Rubbers[item.Name] = item;
                    break;
                }

                case ItemType.Spinner: {
                    var item = new Spinner.Spinner(reader, itemName);
                    table.Spinners[item.Name] = item;
                    break;
                }

                case ItemType.Surface: {
                    var item = new Surface.Surface(reader, itemName);
                    table.Surfaces[item.Name] = item;
                    break;
                }

                case ItemType.Textbox: {
                    var item = new TextBox.TextBox(reader, itemName);
                    table.TextBoxes[item.Name] = item;
                    break;
                }

                case ItemType.Timer: {
                    var item = new Timer.Timer(reader, itemName);
                    table.Timers[item.Name] = item;
                    break;
                }

                case ItemType.Trigger: {
                    var item = new Trigger.Trigger(reader, itemName);
                    table.Triggers[item.Name] = item;
                    break;
                }
                }
            }
        }
        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;
                }
                }
            }
        }