Exemple #1
0
        public void WriteScripts(JsmHeader header, IEnumerable <JsmGroup> groups, IEnumerable <JsmScript> scripts, IEnumerable <JsmOperation> opertations)
        {
            BinaryWriter bw = new BinaryWriter(_output);

            _output.WriteStruct(header);

            foreach (JsmGroup group in groups)
            {
                bw.Write((ushort)((group.Label << 7) | (group.ScriptsCount - 1)));
            }

            foreach (JsmScript script in scripts)
            {
                bw.Write((ushort)(script.Position | ((script.Flag ? 1 : 0) << 15)));
            }

            foreach (JsmOperation operation in opertations)
            {
                bw.Write(operation.Operation);
            }
        }
Exemple #2
0
        public override void Open()
        {
            BinaryReader br = new BinaryReader(IOStream);

            JsmHeader header = IOStream.ReadStruct <JsmHeader>();

            int groupCount      = (header.ScriptsOffset - 8) / 2;
            int scriptCount     = (header.OperationsOffset - header.ScriptsOffset) / 2;
            int operationsCount = (int)((IOStream.Length - header.OperationsOffset) / 4);

            ushort index = 0;
            SortedList <ushort, JsmGroup> groups = new SortedList <ushort, JsmGroup>(groupCount);

            for (ushort i = 0; i < header.CountAreas; ++i)
            {
                JsmGroup group = ReadJsmGroup(br, index++, JsmModuleType.Area);
                groups.Add(group.Label, group);
            }
            for (ushort i = 0; i < header.CountDoors; ++i)
            {
                JsmGroup group = ReadJsmGroup(br, index++, JsmModuleType.Door);
                groups.Add(group.Label, group);
            }
            for (ushort i = 0; i < header.CountModules; ++i)
            {
                JsmGroup group = ReadJsmGroup(br, index++, JsmModuleType.Module);
                groups.Add(group.Label, group);
            }
            for (ushort i = 0; i < header.CountObjects; ++i)
            {
                JsmGroup group = ReadJsmGroup(br, index++, JsmModuleType.Object);
                groups.Add(group.Label, group);
            }

            JsmScript[] scripts = new JsmScript[scriptCount - 1];
            for (int i = 0; i < scriptCount; ++i)
            {
                ushort pos  = br.ReadUInt16();
                bool   flag = pos >> 15 == 1;
                pos &= 0x7FFF;
                if (i > 0)
                {
                    scripts[i - 1].OperationsCount = (pos - scripts[i - 1].Position);
                }

                if (i < scriptCount - 1)
                {
                    scripts[i] = new JsmScript(pos, flag);
                }
            }

            JsmOperation[] opertations = new JsmOperation[operationsCount];
            for (int i = 0; i < operationsCount; i++)
            {
                opertations[i] = new JsmOperation(br.ReadUInt32());
            }

            Groups      = groups.Values.ToArray();
            Scripts     = scripts;
            Opertations = opertations;
        }