Ejemplo n.º 1
0
        private void loadDefinition(Default317Buffer stream)
        {
            int _actions = -1;

            do
            {
                int opcode;
                do
                {
                    opcode = stream.getUnsignedByte();
                    if (opcode == 0)
                    {
                        goto label0;
                    }

                    if (opcode == 1)
                    {
                        int modelCount = stream.getUnsignedByte();
                        if (modelCount > 0)
                        {
                            if (modelIds == null || lowMemory)
                            {
                                modelTypes = new int[modelCount];
                                modelIds   = new int[modelCount];
                                for (int m = 0; m < modelCount; m++)
                                {
                                    modelIds[m]   = stream.getUnsignedLEShort();
                                    modelTypes[m] = stream.getUnsignedByte();
                                }
                            }
                            else
                            {
                                stream.position += modelCount * 3;
                            }
                        }
                    }
                    else if (opcode == 2)
                    {
                        name = stream.getString();
                    }
                    else if (opcode == 3)
                    {
                        description = stream.readBytes();
                    }
                    else if (opcode == 5)
                    {
                        int modelCount = stream.getUnsignedByte();
                        if (modelCount > 0)
                        {
                            if (modelIds == null || lowMemory)
                            {
                                modelTypes = null;
                                modelIds   = new int[modelCount];
                                for (int m = 0; m < modelCount; m++)
                                {
                                    modelIds[m] = stream.getUnsignedLEShort();
                                }
                            }
                            else
                            {
                                stream.position += modelCount * 2;
                            }
                        }
                    }
                    else if (opcode == 14)
                    {
                        sizeX = stream.getUnsignedByte();
                    }
                    else if (opcode == 15)
                    {
                        sizeY = stream.getUnsignedByte();
                    }
                    else if (opcode == 17)
                    {
                        solid = false;
                    }
                    else if (opcode == 18)
                    {
                        walkable = false;
                    }
                    else if (opcode == 19)
                    {
                        _actions = stream.getUnsignedByte();
                        if (_actions == 1)
                        {
                            hasActions = true;
                        }
                    }
                    else if (opcode == 21)
                    {
                        adjustToTerrain = true;
                    }
                    else if (opcode == 22)
                    {
                        delayShading = true;
                    }
                    else if (opcode == 23)
                    {
                        wall = true;
                    }
                    else if (opcode == 24)
                    {
                        animationId = stream.getUnsignedLEShort();
                        if (animationId == 65535)
                        {
                            animationId = -1;
                        }
                    }
                    else if (opcode == 28)
                    {
                        offsetAmplifier = stream.getUnsignedByte();
                    }
                    else if (opcode == 29)
                    {
                        ambient = stream.get();
                    }
                    else if (opcode == 39)
                    {
                        diffuse = stream.get();
                    }
                    else if (opcode >= 30 && opcode < 39)
                    {
                        if (actions == null)
                        {
                            actions = new String[5];
                        }

                        actions[opcode - 30] = stream.getString();
                        if (actions[opcode - 30].Equals("hidden", StringComparison.InvariantCultureIgnoreCase))
                        {
                            actions[opcode - 30] = null;
                        }
                    }
                    else if (opcode == 40)
                    {
                        int colourCount = stream.getUnsignedByte();
                        modifiedModelColors = new int[colourCount];
                        originalModelColors = new int[colourCount];
                        for (int c = 0; c < colourCount; c++)
                        {
                            modifiedModelColors[c] = stream.getUnsignedLEShort();
                            originalModelColors[c] = stream.getUnsignedLEShort();
                        }
                    }
                    else if (opcode == 60)
                    {
                        icon = stream.getUnsignedLEShort();
                    }
                    else if (opcode == 62)
                    {
                        rotated = true;
                    }
                    else if (opcode == 64)
                    {
                        castsShadow = false;
                    }
                    else if (opcode == 65)
                    {
                        scaleX = stream.getUnsignedLEShort();
                    }
                    else if (opcode == 66)
                    {
                        scaleY = stream.getUnsignedLEShort();
                    }
                    else if (opcode == 67)
                    {
                        scaleZ = stream.getUnsignedLEShort();
                    }
                    else if (opcode == 68)
                    {
                        mapScene = stream.getUnsignedLEShort();
                    }
                    else if (opcode == 69)
                    {
                        face = stream.getUnsignedByte();
                    }
                    else if (opcode == 70)
                    {
                        translateX = stream.getShort();
                    }
                    else if (opcode == 71)
                    {
                        translateY = stream.getShort();
                    }
                    else if (opcode == 72)
                    {
                        translateZ = stream.getShort();
                    }
                    else if (opcode == 73)
                    {
                        unknownAttribute = true;
                    }
                    else if (opcode == 74)
                    {
                        unwalkableSolid = true;
                    }
                    else
                    {
                        if (opcode != 75)
                        {
                            continue;
                        }

                        _solid = stream.getUnsignedByte();
                    }

                    continue;
                } while(opcode != 77);

                varBitId = stream.getUnsignedLEShort();
                if (varBitId == 65535)
                {
                    varBitId = -1;
                }

                configIds = stream.getUnsignedLEShort();
                if (configIds == 65535)
                {
                    configIds = -1;
                }

                int childCount = stream.getUnsignedByte();
                childIds = new int[childCount + 1];
                for (int c = 0; c <= childCount; c++)
                {
                    childIds[c] = stream.getUnsignedLEShort();
                    if (childIds[c] == 65535)
                    {
                        childIds[c] = -1;
                    }
                }
            } while(true);

label0:
            if (_actions == -1)
            {
                hasActions = modelIds != null && (modelTypes == null || modelTypes[0] == 10);
                if (actions != null)
                {
                    hasActions = true;
                }
            }

            if (unwalkableSolid)
            {
                solid    = false;
                walkable = false;
            }

            if (_solid == -1)
            {
                _solid = solid ? 1 : 0;
            }
        }
Ejemplo n.º 2
0
        public static void unpack(Archive streamLoader, GameFont[] fonts, Archive mediaArchive)
        {
            spriteCache = new Cache(50000);
            Default317Buffer stream = new Default317Buffer(streamLoader.decompressFile("data"));
            int parentId            = -1;
            int interfaceCount      = stream.getUnsignedLEShort();

            cache = new RSInterface[interfaceCount];
            while (stream.position < stream.buffer.Length)
            {
                int id = stream.getUnsignedLEShort();
                if (id == 65535)
                {
                    parentId = stream.getUnsignedLEShort();
                    id       = stream.getUnsignedLEShort();
                }

                RSInterface rsInterface = cache[id] = new RSInterface();
                rsInterface.id           = id;
                rsInterface.parentID     = parentId;
                rsInterface.type         = stream.getUnsignedByte();
                rsInterface.actionType   = stream.getUnsignedByte();
                rsInterface.contentType  = stream.getUnsignedLEShort();
                rsInterface.width        = stream.getUnsignedLEShort();
                rsInterface.height       = stream.getUnsignedLEShort();
                rsInterface.alpha        = (byte)stream.getUnsignedByte();
                rsInterface.hoveredPopup = stream.getUnsignedByte();
                if (rsInterface.hoveredPopup != 0)
                {
                    rsInterface.hoveredPopup = (rsInterface.hoveredPopup - 1 << 8) + stream.getUnsignedByte();
                }
                else
                {
                    rsInterface.hoveredPopup = -1;
                }
                int conditionCount = stream.getUnsignedByte();
                if (conditionCount > 0)
                {
                    rsInterface.conditionType  = new int[conditionCount];
                    rsInterface.conditionValue = new int[conditionCount];
                    for (int c = 0; c < conditionCount; c++)
                    {
                        rsInterface.conditionType[c]  = stream.getUnsignedByte();
                        rsInterface.conditionValue[c] = stream.getUnsignedLEShort();
                    }
                }

                int opcodeCount = stream.getUnsignedByte();
                if (opcodeCount > 0)
                {
                    rsInterface.opcodes = new int[opcodeCount][];
                    for (int c = 0; c < opcodeCount; c++)
                    {
                        int subOpcodeCount = stream.getUnsignedLEShort();
                        rsInterface.opcodes[c] = new int[subOpcodeCount];
                        for (int s = 0; s < subOpcodeCount; s++)
                        {
                            rsInterface.opcodes[c][s] = stream.getUnsignedLEShort();
                        }
                    }
                }

                if (rsInterface.type == 0)
                {
                    rsInterface.scrollMax = stream.getUnsignedLEShort();
                    rsInterface.hoverOnly = stream.getUnsignedByte() == 1;
                    int childCount = stream.getUnsignedLEShort();
                    rsInterface.children = new int[childCount];
                    rsInterface.childX   = new int[childCount];
                    rsInterface.childY   = new int[childCount];
                    for (int child = 0; child < childCount; child++)
                    {
                        rsInterface.children[child] = stream.getUnsignedLEShort();
                        rsInterface.childX[child]   = stream.getShort();
                        rsInterface.childY[child]   = stream.getShort();
                    }
                }

                if (rsInterface.type == 1)
                {
                    stream.getUnsignedLEShort();
                    stream.getUnsignedByte();
                }

                if (rsInterface.type == 2)
                {
                    rsInterface.inventoryItemId              = new int[rsInterface.width * rsInterface.height];
                    rsInterface.inventoryStackSize           = new int[rsInterface.width * rsInterface.height];
                    rsInterface.itemSwappable                = stream.getUnsignedByte() == 1;
                    rsInterface.inventory                    = stream.getUnsignedByte() == 1;
                    rsInterface.usableItemInterface          = stream.getUnsignedByte() == 1;
                    rsInterface.itemDeletesDragged           = stream.getUnsignedByte() == 1;
                    rsInterface.inventorySpritePaddingColumn = stream.getUnsignedByte();
                    rsInterface.inventorySpritePaddingRow    = stream.getUnsignedByte();
                    rsInterface.spritesX = new int[20];
                    rsInterface.spritesY = new int[20];
                    rsInterface.sprites  = new Sprite[20];
                    for (int sprite = 0; sprite < 20; sprite++)
                    {
                        int spriteExists = stream.getUnsignedByte();
                        if (spriteExists == 1)
                        {
                            rsInterface.spritesX[sprite] = stream.getShort();
                            rsInterface.spritesY[sprite] = stream.getShort();
                            String name = stream.getString();
                            if (mediaArchive != null && name.Length > 0)
                            {
                                int spriteId = name.LastIndexOf(',');
                                rsInterface.sprites[sprite] = getImage(int.Parse(name.Substring(spriteId + 1)),
                                                                       mediaArchive, name.Substring(0, spriteId));
                            }
                        }
                    }

                    rsInterface.actions = new String[5];
                    for (int action = 0; action < 5; action++)
                    {
                        rsInterface.actions[action] = stream.getString();
                        if (rsInterface.actions[action].Length == 0)
                        {
                            rsInterface.actions[action] = null;
                        }
                    }
                }

                if (rsInterface.type == 3)
                {
                    rsInterface.filled = stream.getUnsignedByte() == 1;
                }
                if (rsInterface.type == 4 || rsInterface.type == 1)
                {
                    rsInterface.textCentred = stream.getUnsignedByte() == 1;
                    int font = stream.getUnsignedByte();
                    if (fonts != null)
                    {
                        rsInterface.textDrawingAreas = fonts[font];
                    }
                    rsInterface.textShadowed = stream.getUnsignedByte() == 1;
                }

                if (rsInterface.type == 4)
                {
                    rsInterface.textDefault = stream.getString();
                    rsInterface.textActive  = stream.getString();
                }

                if (rsInterface.type == 1 || rsInterface.type == 3 || rsInterface.type == 4)
                {
                    rsInterface.colourDefault = stream.getInt();
                }
                if (rsInterface.type == 3 || rsInterface.type == 4)
                {
                    rsInterface.colourActive       = stream.getInt();
                    rsInterface.colourDefaultHover = stream.getInt();
                    rsInterface.colourActiveHover  = stream.getInt();
                }

                if (rsInterface.type == 5)
                {
                    String spriteName = stream.getString();
                    if (mediaArchive != null && spriteName.Length > 0)
                    {
                        int spriteId = spriteName.LastIndexOf(",");
                        rsInterface.spriteDefault = getImage(int.Parse(spriteName.Substring(spriteId + 1)),
                                                             mediaArchive, spriteName.Substring(0, spriteId));
                    }

                    spriteName = stream.getString();
                    if (mediaArchive != null && spriteName.Length > 0)
                    {
                        int spriteId = spriteName.LastIndexOf(",");
                        rsInterface.spriteActive = getImage(int.Parse(spriteName.Substring(spriteId + 1)),
                                                            mediaArchive, spriteName.Substring(0, spriteId));
                    }
                }

                if (rsInterface.type == 6)
                {
                    int interfaceId = stream.getUnsignedByte();
                    if (interfaceId != 0)
                    {
                        rsInterface.modelTypeDefault = 1;
                        rsInterface.modelIdDefault   = (interfaceId - 1 << 8) + stream.getUnsignedByte();
                    }

                    interfaceId = stream.getUnsignedByte();
                    if (interfaceId != 0)
                    {
                        rsInterface.modelTypeActive = 1;
                        rsInterface.modelIdActive   = (interfaceId - 1 << 8) + stream.getUnsignedByte();
                    }

                    interfaceId = stream.getUnsignedByte();
                    if (interfaceId != 0)
                    {
                        rsInterface.animationIdDefault = (interfaceId - 1 << 8) + stream.getUnsignedByte();
                    }
                    else
                    {
                        rsInterface.animationIdDefault = -1;
                    }
                    interfaceId = stream.getUnsignedByte();
                    if (interfaceId != 0)
                    {
                        rsInterface.animationIdActive = (interfaceId - 1 << 8) + stream.getUnsignedByte();
                    }
                    else
                    {
                        rsInterface.animationIdActive = -1;
                    }
                    rsInterface.modelZoom      = stream.getUnsignedLEShort();
                    rsInterface.modelRotationX = stream.getUnsignedLEShort();
                    rsInterface.modelRotationY = stream.getUnsignedLEShort();
                }

                if (rsInterface.type == 7)
                {
                    rsInterface.inventoryItemId    = new int[rsInterface.width * rsInterface.height];
                    rsInterface.inventoryStackSize = new int[rsInterface.width * rsInterface.height];
                    rsInterface.textCentred        = stream.getUnsignedByte() == 1;
                    int font = stream.getUnsignedByte();
                    if (fonts != null)
                    {
                        rsInterface.textDrawingAreas = fonts[font];
                    }
                    rsInterface.textShadowed  = stream.getUnsignedByte() == 1;
                    rsInterface.colourDefault = stream.getInt();
                    rsInterface.inventorySpritePaddingColumn = stream.getShort();
                    rsInterface.inventorySpritePaddingRow    = stream.getShort();
                    rsInterface.inventory = stream.getUnsignedByte() == 1;
                    rsInterface.actions   = new String[5];
                    for (int active = 0; active < 5; active++)
                    {
                        rsInterface.actions[active] = stream.getString();
                        if (rsInterface.actions[active].Length == 0)
                        {
                            rsInterface.actions[active] = null;
                        }
                    }
                }

                if (rsInterface.actionType == 2 || rsInterface.type == 2)
                {
                    rsInterface.selectedActionName = stream.getString();
                    rsInterface.spellName          = stream.getString();
                    rsInterface.spellUsableOn      = stream.getUnsignedLEShort();
                }

                if (rsInterface.type == 8)
                {
                    rsInterface.textDefault = stream.getString();
                }

                if (rsInterface.actionType == 1 || rsInterface.actionType == 4 || rsInterface.actionType == 5 ||
                    rsInterface.actionType == 6)
                {
                    rsInterface.tooltip = stream.getString();
                    if (rsInterface.tooltip.Length == 0)
                    {
                        if (rsInterface.actionType == 1)
                        {
                            rsInterface.tooltip = "Ok";
                        }
                        if (rsInterface.actionType == 4)
                        {
                            rsInterface.tooltip = "Select";
                        }
                        if (rsInterface.actionType == 5)
                        {
                            rsInterface.tooltip = "Select";
                        }
                        if (rsInterface.actionType == 6)
                        {
                            rsInterface.tooltip = "Continue";
                        }
                    }
                }
            }

            spriteCache = null;
        }