示例#1
0
        private static void RegionParse_cmd06(ROM rom, List <Region> regions, RegionParseState state)
        {
            int segment = rom.Read8(4);

            if (segment != 0x0e)
            {
                return;
            }

            int type = rom.Read8(1);

            if (type != 0)
            {
                throw new NotSupportedException("Terminating Branch not supported!");
            }

            int segmentedAddress = rom.Read32(4);
            int address          = rom.GetROMAddress(segmentedAddress);

            List <Region>    regionsBranch = new List <Region>();
            RegionParseState stateBranch   = PerformRegionParseInternal(rom, regionsBranch, address, 0);

            // TODO: Copy/update more if needed
            if (stateBranch.FDAddress != -1)
            {
                state.FDAddress = stateBranch.FDAddress;
            }

            foreach (Region region in regionsBranch)
            {
                state.textureData.AddRegion(region.romStart, region.length);
            }
        }
示例#2
0
        private static void RegionParse_cmd2E(ROM rom, List <Region> regions, RegionParseState state)
        {
            int segmentedAddress = rom.Read32(4);
            int segment          = rom.Read8(4);

            // Only 0x19 or 0x0E commands are supported
            if (segment != 0x19 && segment != 0x0E)
            {
                return;
            }

            try
            {
                List <Region> collisionRegions = new List <Region>();
                Collision.PerformRegionParse(rom, collisionRegions, (int)rom.GetROMAddress(segmentedAddress));
                foreach (Region region in collisionRegions)
                {
                    region.area = state.area;
                }

                regions.AddRange(collisionRegions);
            }
            catch (NotSupportedException e)
            {
                MessageBox.Show(String.Format("Model {0} collision parsing is not supported! Reason : '{1}'", state.area, e.Message), "Level Parser", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Format("Failed to parse model {0} collision! Reason : '{1}'", state.area, e.Message), "Level Parser", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        private static void TriangleMapParse_cmd04(ROM rom, TriangleMap map, TriangleMapParseState state)
        {
            state.vertexLoadCmd = (UInt64)rom.Read64();
            byte vertexDesc = rom.Read8(1);

            byte  vertexCount            = (byte)(((vertexDesc & 0xF0) >> 4) + 1);
            byte  vertexOffset           = (byte)((vertexDesc & 0x0F));
            Int32 vertexSegmentedAddress = rom.Read32(4);

            state.segmentedVertexBufferAddress = vertexSegmentedAddress;

            Int32 romPtr = rom.GetROMAddress(vertexSegmentedAddress);

            if (romPtr == -1)
            {
                throw new ArgumentException("Invalid segmented address!");
            }

            rom.PushOffset(romPtr);
            for (int vertex = vertexOffset; vertex < vertexCount; vertex++)
            {
                Int64 lo = rom.Read64();
                Int64 hi = rom.Read64(8);

                state.vbuf[vertex]         = new Vertex((UInt64)lo, (UInt64)hi);
                state.vbufRomStart[vertex] = rom.offset;
                state.scrollBuf[vertex]    = FindMatchingScroll(state.scrolls, vertexSegmentedAddress, state.td);

                rom.AddOffset(0x10);
                vertexSegmentedAddress += 0x10;
            }
            rom.PopOffset();
        }
示例#4
0
        private static void RegionParse_cmd03(ROM rom, List <Region> regions, RegionParseState state)
        {
            int segment = rom.Read8(4);

            if (segment != 0x0e)
            {
                return;
            }

            int segmentedAddress = rom.Read32(4);
            int address          = rom.GetROMAddress(segmentedAddress);

            state.lightData.AddRegion(address, 0x8);
        }
示例#5
0
        private static void RegionParse_cmd15(ROM rom, List <Region> regions)
        {
            int segment = rom.Read8(4);

            if (segment != 0x0e)
            {
                return;
            }

            int segmentedAddress = rom.Read32(4);
            int address          = (int)rom.GetROMAddress(segmentedAddress);

            DisplayList.PerformRegionParse(rom, regions, address, rom.Read8(1));
        }
示例#6
0
        private static void RegionParse_cmd04(ROM rom, List <Region> regions, RegionParseState state)
        {
            int segment = rom.Read8(4);

            if (segment != 0x0e)
            {
                return;
            }

            int segmentedAddress = rom.Read32(4);
            int address          = rom.GetROMAddress(segmentedAddress);

            state.vertexData.AddRegion(address, rom.Read16(2));
            //regions.Add(new Region(address, rom.Read16(2), RegionState.VertexInfo));
        }
示例#7
0
        private static void RegionParse_cmdFD(ROM rom, List <Region> regions, RegionParseState state)
        {
            state.FDAddress = -1;

            int segment = rom.Read8(4);

            if (segment != 0x0e)
            {
                return;
            }

            int segmentedAddress = rom.Read32(4);
            int address          = (int)rom.GetROMAddress(segmentedAddress);

            state.FDAddress = address;
        }
示例#8
0
        private static void RegionParse_cmd06(ROM rom, List <Region> regions, RegionParseState state)
        {
            int segmentedAddress = rom.Read32(4);
            int segment          = SegmentedAddressHelper.GetSegment(segmentedAddress);

            // 06 command will return one way or another, so just wait for it
            if (segment != 0x19)
            {
                return;
            }

            CutRegion(rom, regions, state, rom.offset, state.regionState);

            state.retAddressStack.Push(rom.offset + rom.Read8(1));
            int offset = (int)rom.GetROMAddress(segmentedAddress);

            rom.offset  = offset - 8; // kostul for next cmd switching
            state.start = offset;
        }
示例#9
0
        private static void RegionParse_cmd00(ROM rom, List <Region> regions, RegionParseState state)
        {
            int segment = rom.Read8(3);

            if (segment != 0x19)
            {
                throw new MessageException("ROM does not use bank 0x19. Did you import a level?");
            }

            int startAddress             = rom.Read32(4);
            int endAddress               = rom.Read32(8);
            SegmentDescriptor descriptor = new SegmentDescriptor(startAddress, endAddress - startAddress);

            rom.SetSegment(segment, descriptor);

            int segmentedAddress   = rom.Read32(12);
            int levelscriptAddress = rom.GetROMAddress(segmentedAddress);

            rom.offset  = levelscriptAddress - 0x10; // kostul for adding 0x10
            state.start = levelscriptAddress;
        }
示例#10
0
        private static void RegionParse_cmd22(ROM rom, List <Region> regions, RegionParseState state)
        {
            if (state.regionState != RegionState.ModelsLoader)
            {
                CutRegion(rom, regions, state, rom.offset, RegionState.ModelsLoader);
            }

            int segmentedAddress = rom.Read32(4);
            int segment          = rom.Read8(4);
            int model            = rom.Read8(3);

            // Only 0x19 or 0x0E commands are supported
            if (segment != 0x19 && segment != 0x0E)
            {
                return;
            }

            try
            {
                List <Region> modelRegions = new List <Region>();

                int geoLayoutROMAddress = rom.GetROMAddress(segmentedAddress);
                GeoLayout.PerformRegionParse(rom, modelRegions, geoLayoutROMAddress);

                foreach (Region region in modelRegions)
                {
                    region.model = model;
                }

                regions.AddRange(modelRegions);
            }
            catch (NotSupportedException e)
            {
                MessageBox.Show(String.Format("Model {0} graphics parsing is not supported! Reason : '{1}'", state.area, e.Message), "Level Parser", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Format("Failed to parse model {0} graphics! Reason : '{1}'", state.area, e.Message), "Level Parser", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#11
0
        private static void RegionParse_cmd1F(ROM rom, List <Region> regions, RegionParseState state)
        {
            CutRegion(rom, regions, state, rom.offset, RegionState.AreaHeader);

            int   segmentedAddress = rom.Read32(4);
            int   segment          = rom.Read8(4);
            sbyte area             = (sbyte)rom.Read8(2);

            state.area        = area;
            state.regionState = RegionState.AreaHeader;

            // Only 0x19 or 0x0E commands are supported
            // Usually it is in segment 19 anyways
            if (segment != 0x19 && segment != 0x0E)
            {
                return;
            }

            int           geoLayoutROMAddress  = rom.GetROMAddress(segmentedAddress);
            List <Region> areaGeolayoutRegions = new List <Region>();

            try
            {
                GeoLayout.PerformRegionParse(rom, areaGeolayoutRegions, geoLayoutROMAddress);
                foreach (Region region in areaGeolayoutRegions)
                {
                    region.area = area;
                }

                regions.AddRange(areaGeolayoutRegions);
            }
            catch (NotSupportedException e)
            {
                MessageBox.Show(String.Format("Area {0} graphics parsing is not supported! Reason : '{1}'", state.area, e.Message), "Level Parser", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Format("Failed to parse area {0} graphics! Reason : '{1}'", state.area, e.Message), "Level Parser", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#12
0
        private static void HeaderParse_cmd00(ROM rom)
        {
            int segment = rom.Read8(3);

            if (segment != 0x19)
            {
                throw new MessageException("ROM does not use bank 0x19. Did you import a level?");
            }

            int startAddress             = rom.Read32(4);
            int endAddress               = rom.Read32(8);
            SegmentDescriptor descriptor = new SegmentDescriptor(startAddress, endAddress - startAddress);

            rom.SetSegment(segment, descriptor);

            //rom.levelScriptEntryOffset = rom.offset + 12;

            int segmentedAddress   = rom.Read32(12);
            int levelscriptAddress = rom.GetROMAddress(segmentedAddress);

            rom.offset = levelscriptAddress - 0x10; // kostul for adding 0x10
        }
示例#13
0
        static RegionParseState PerformRegionParseInternal(ROM rom, List <Region> regions, int offset, int layer)
        {
            RegionParseState state = new RegionParseState();

            rom.PushOffset(offset);
            try
            {
                int cmd = 0;
                do
                {
                    cmd = rom.Read8();
                    parser[cmd](rom, regions, state);
                    rom.AddOffset(8);
                }while (cmd != 0xB8);

                Region           region;
                SortedRegionList graphicsData = new SortedRegionList();

                foreach (KeyValuePair <int, int> lightRegion in state.lightData.RegionList)
                {
                    //region = new Region(lightRegion.Key, lightRegion.Value, RegionState.LightData);
                    graphicsData.AddRegion(lightRegion.Key, lightRegion.Value);
                    //regions.Add(region);
                }

                // kostul
                if (state.lightData.RegionList.Count == 0)
                {
                    graphicsData.AddRegion(rom.GetROMAddress(0x0E000000), 0x10);
                }

                foreach (KeyValuePair <int, int> textureRegion in state.textureData.RegionList)
                {
                    //region = new Region(textureRegion.Key, textureRegion.Value, RegionState.TextureInfo);
                    graphicsData.AddRegion(textureRegion.Key, textureRegion.Value);
                    //regions.Add(region);
                }

                foreach (KeyValuePair <int, int> vertexRegion in state.vertexData.RegionList)
                {
                    //region = new Region(vertexRegion.Key, vertexRegion.Value, RegionState.VertexInfo);
                    graphicsData.AddRegion(vertexRegion.Key, vertexRegion.Value);
                    //regions.Add(region);
                }

                int count = 0;
                foreach (KeyValuePair <int, int> notFixedRegion in graphicsData.RegionList)
                {
                    region        = new DynamicRegion(notFixedRegion.Key, notFixedRegion.Value, RegionState.GraphicsData);
                    region.number = count++;
                    regions.Add(region);
                }


                region = new DisplayListRegion(offset, rom.offset - offset, state.isFogEnabled, state.isEnvColorEnabled, state.FCCount, state.B9cmdfirst, layer);
                regions.Add(region);
            }
            finally
            {
                rom.PopOffset();
            }
            return(state);
        }