Beispiel #1
0
        public HardcodeTablesModel(Singletons singletons, byte[] data, StoredMetadata metadata = null) : base(data, metadata, singletons)
        {
            if (metadata != null && !metadata.IsEmpty)
            {
                return;
            }

            gameCode = this.GetGameCode();

            // in vanilla emerald, this pointer isn't four-byte aligned
            // it's at the very front of the ROM, so if there's no metadata we can be pretty sure that the pointer is still there
            if (gameCode == Emerald && data.Length > EarliestAllowedAnchor && data[0x1C3] == 0x08)
            {
                ObserveRunWritten(noChangeDelta, new PointerRun(0x1C0));
            }

            var gamesToDecode = new[] { Ruby, Sapphire, Emerald, FireRed, LeafGreen, Ruby1_1, Sapphire1_1, FireRed1_1, LeafGreen1_1 };

            if (gamesToDecode.Contains(gameCode))
            {
                LoadDefaultMetadata(gameCode.Substring(0, 4).ToLower());
                DecodeHeader();
                if (singletons.GameReferenceTables.TryGetValue(gameCode, out var referenceTables))
                {
                    DecodeTablesFromReference(referenceTables);
                }
            }

            ResolveConflicts();
        }
        public HardcodeTablesModel(Singletons singletons, byte[] data, StoredMetadata metadata = null) : base(data, metadata, singletons)
        {
            gameCode = this.GetGameCode();
            if (metadata != null && !metadata.IsEmpty)
            {
                InitializationWorkload = (singletons?.WorkDispatcher ?? InstantDispatch.Instance).RunBackgroundWork(() => Initialize(metadata));
                return;
            }

            InitializationWorkload = (singletons?.WorkDispatcher ?? InstantDispatch.Instance).RunBackgroundWork(() => {
                {
                    if (singletons.GameReferenceConstants.TryGetValue(gameCode, out var referenceConstants))
                    {
                        metadata = DecodeConstantsFromReference(this, singletons.MetadataInfo, metadata, referenceConstants);
                    }
                    Initialize(metadata);
                    isCFRU = GetIsCFRU();

                    // in vanilla emerald, this pointer isn't four-byte aligned
                    // it's at the very front of the ROM, so if there's no metadata we can be pretty sure that the pointer is still there
                    if (gameCode == Emerald && data.Length > EarliestAllowedAnchor && data[0x1C3] == 0x08)
                    {
                        ObserveRunWritten(noChangeDelta, new PointerRun(0x1C0));
                    }

                    var gamesToDecode = new[] { Ruby, Sapphire, Emerald, FireRed, LeafGreen, Ruby1_1, Sapphire1_1, FireRed1_1, LeafGreen1_1, "BPRF0" };
                    if (gamesToDecode.Contains(gameCode))
                    {
                        foreach (var defaultMetadata in GetDefaultMetadatas(gameCode.Substring(0, 4).ToLower(), gameCode.ToLower()))
                        {
                            this.LoadMetadata(defaultMetadata);
                        }
                        if (singletons.GameReferenceTables.TryGetValue(gameCode, out var referenceTables))
                        {
                            DecodeTablesFromReference(referenceTables);
                        }
                    }

                    ResolveConflicts();
                }
            });
        }