/// <summary>
        /// Use this only when parsing.
        /// </summary>
        public Script GetScript(int offset)
        {
            if (!_initializing)
            {
                throw new Exception("Not initializing.");
            }

            if (offset < 0)
            {
                return(null);
            }

            SakuraiEntryNode e = GetEntry(offset);

            if (e is Script)
            {
                return(e as Script);
            }
            else if (e is Event)
            {
                return(((Event)e)._script);
            }

            return(null);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// If the entry isn't null,
 /// adds the size of the entry to the current part length
 /// and adds the entry's lookup count to the main lookup count.
 /// </summary>
 protected void GetSize(SakuraiEntryNode entry)
 {
     if (entry != null)
     {
         _lengths[_lengths.Count - 1] += entry.GetSize();
         _lookup += entry.GetLookupCount();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// If the entry isn't null,
        /// adds the size of the entry to the current part length
        /// and adds the entry's lookup count to the main lookup count.
        /// the incrementLookup argument will add a lookup offset for the offset to the entry
        /// </summary>
        protected void GetSize(SakuraiEntryNode entry, bool incrementLookup = false)
        {
            if (entry != null)
            {
                _currentSize        += entry.GetSize();
                _currentLookupCount += entry.GetLookupCount();

                //Increment lookup for the offset in a header to this data
                if (incrementLookup && entry._calcSize > 0)
                {
                    IncLookup();
                }
            }
        }
Ejemplo n.º 4
0
        protected int Write(SakuraiEntryNode entry, int incAmt = 0)
        {
            if (entry != null)
            {
                //DEBUG
                if (entry._calcSize == 0 || entry._calcSize != entry.TotalSize)
                {
                    throw new Exception("Entry size issues");
                }

                int offset = entry.Write(_currentAddress);
                _currentAddress += incAmt > 0 ? incAmt : entry._calcSize;
            }
            return(0);
        }
Ejemplo n.º 5
0
        public override void PostParse()
        {
            //Get script node using raw offset
            //This happens in post parse so that all scripts have been parsed already

            MovesetNode node = (MovesetNode)_root;

            SakuraiEntryNode e     = _root.GetEntry(RawOffset);
            bool             exist = e != null && e is Event;

            _offsetInfo = node.GetScriptLocation(RawOffset);

            Script a;

            if (_offsetInfo._list == ListValue.Null && !exist)
            {
                node.SubRoutines.Add(a = Parse <Script>(RawOffset));
            }
            else if (_offsetInfo._list != ListValue.References)
            {
                a = node.GetScript(_offsetInfo);
            }
            else
            {
                if (_externalEntry == null && _offsetInfo._index >= 0 && _offsetInfo._index < _root.ReferenceList.Count)
                {
                    _externalEntry = _root.ReferenceList[_offsetInfo._index];
                    _externalEntry.References.Add(this);
                }
                return;
            }

            if (a == null)
            {
                a = GetScript();
            }

            if (a != null)
            {
                a._actionRefs.Add(this);
            }
            else
            {
                throw new Exception("Script not found.");
            }

            _script = a;
        }
Ejemplo n.º 6
0
        internal void LinkScript()
        {
            MovesetNode node = (MovesetNode)_root;

            SakuraiEntryNode e     = _root.GetEntry(RawOffset);
            bool             exist = e != null && e is Event;

            _offsetInfo = node.GetScriptLocation(RawOffset);

            Script a;

            if (_offsetInfo.list == ListValue.Null && !exist)
            {
                node.SubRoutines.Add(a = Parse <Script>(RawOffset));
            }
            else if (_offsetInfo.list != ListValue.References)
            {
                a = node.GetScript(_offsetInfo);
            }
            else
            {
                if (_externalEntry == null && _offsetInfo.index >= 0 && _offsetInfo.index < _root.ReferenceList.Count)
                {
                    _externalEntry = _root.ReferenceList[_offsetInfo.index];
                    _externalEntry.References.Add(this);
                }
                return;
            }

            if (a == null)
            {
                a = GetScript();
            }

            if (a != null)
            {
                a._actionRefs.Add(this);
            }
            else
            {
                throw new Exception("Script not found.");
            }

            _script = a;
        }
Ejemplo n.º 7
0
        protected int Write(SakuraiEntryNode entry, int incAmt = 0)
        {
            if (entry != null)
            {
#if DEBUG
                if (entry._calcSize == 0 || entry._calcSize != entry.TotalSize)
                {
                    throw new Exception("Entry size issues");
                }
#endif

                int offset = entry.Write(_currentAddress);

                _currentLookup.AddRange(entry.LookupAddresses);
                _currentAddress += incAmt > 0 ? incAmt : entry._calcSize;

                return(offset);
            }
            return(0);
        }
Ejemplo n.º 8
0
        public unsafe void Write(SakuraiArchiveNode node, VoidPtr address, int length)
        {
            _baseAddress    = address + 0x20;
            _currentAddress = _baseAddress;

            //Write header
            SakuraiArchiveHeader *hdr = (SakuraiArchiveHeader *)address;

            hdr->_sectionCount            = _sectionCount;
            hdr->_externalSubRoutineCount = _referenceCount;
            hdr->_lookupEntryCount        = _lookupManager.Count;
            hdr->_fileSize = length;
            hdr->_pad1     = hdr->_pad2 = hdr->_pad3 = 0;

            List <int> _sectionOffsets = new List <int>();

            //Write section data
            foreach (TableEntryNode section in node.SectionList)
            {
                SakuraiEntryNode entry = section;

                //If this section is referenced from an entry,
                //write that entry instead
                if (section.References.Count > 0)
                {
                    entry = section.References[0];
                }

                _sectionOffsets.Add(entry.Write(_currentAddress));
                _currentAddress += entry.TotalSize;
            }

            //Write lookup values
            hdr->_lookupOffset = (int)_currentAddress - (int)_baseAddress;
            _lookupManager.Write(ref _currentAddress);

            //These can only be accessed after the lookup offset and count
            //have been written to the header.
            sStringEntry *sectionAddr = hdr->Sections;
            sStringEntry *refAddr     = hdr->ExternalSubRoutines;
        }
Ejemplo n.º 9
0
        protected unsafe void Write(SakuraiEntryNode entry, VoidPtr offsetAddr)
        {
            if (entry != null)
            {
#if DEBUG
                if (entry._calcSize == 0)
                {
                    throw new Exception("Entry size issues");
                }
#endif

                int offset = entry.Write(_currentAddress);

                _currentLookup.AddRange(entry.LookupAddresses);
                _currentAddress += entry._calcSize;

                *(bint *)offsetAddr = offset;
                Lookup(offsetAddr);
            }
            else
            {
                *(bint *)offsetAddr = 0;
            }
        }
        /// <summary>
        /// Use this only when parsing.
        /// </summary>
        internal ScriptOffsetInfo GetScriptLocation(int offset)
        {
            if (!_initializing)
            {
                throw new Exception("Not initializing.");
            }

            //Create new offset info
            ScriptOffsetInfo info = new ScriptOffsetInfo();

            //Check if the offset is legit
            if (offset <= 0)
            {
                return(info);
            }

            info._list = ListValue.Actions;

            //Search action offsets
            for (info._type = 0; (int)info._type < 2; info._type++)
            {
                if ((info._index = _scriptOffsets[(int)info._list][(int)info._type].IndexOf(offset)) != -1)
                {
                    return(info);
                }
            }

            info._list++;

            //Search subaction offsets
            for (info._type = 0; (int)info._type < 4; info._type++)
            {
                if ((info._index = _scriptOffsets[(int)info._list][(int)info._type].IndexOf(offset)) != -1)
                {
                    return(info);
                }
            }

            info._type = TypeValue.None;
            info._list++;

            //Search subroutine offsets
            if ((info._index = _scriptOffsets[(int)info._list][0].IndexOf(offset)) != -1)
            {
                return(info);
            }

            info._list++;

            //Search reference entry offsets
            SakuraiEntryNode e = GetEntry(offset);

            if (e is TableEntryNode && e != null)
            {
                info._index = e.Index;
                return(info);
            }

            //Set values to null
            info._list++;
            info._type  = TypeValue.None;
            info._index = -1;

            //Continue searching dataCommon
            if (_dataCommon != null)
            {
                info._list++;

                //Search screen tint offsets
                if ((info._index = _scriptOffsets[3][0].IndexOf(offset)) != -1)
                {
                    return(info);
                }

                info._list++;

                //Search flash overlay offsets
                if ((info._index = _scriptOffsets[4][0].IndexOf(offset)) != -1)
                {
                    return(info);
                }

                info._list = ListValue.Null;
            }
            return(info);
        }
 protected unsafe void Set(int i, SakuraiEntryNode node)
 {
     ((bint *)_address)[i] = node.RebuildOffset;
 }
Ejemplo n.º 12
0
        public int GetSize()
        {
            _calculatingSize = true;

            //Reset variables
            _lookupCount          = _lookupLen = 0;
            _lookupManager        = new LookupManager();
            _postProcessNodes     = new List <SakuraiEntryNode>();
            _referenceStringTable = new CompactStringTable();

            //Add header size
            _size = SakuraiArchiveHeader.Size;

            //Calculate the size of each section and add names to string table
            foreach (TableEntryNode section in _rootNode.SectionList)
            {
                SakuraiEntryNode entry = section;

                //Sections *usually* have only one reference in data or dataCommon
                //An example of an exception to this is the 'AnimCmd' section
                //If a reference exists, calculate the size of that reference instead
                if (section.References.Count > 0)
                {
                    entry = section.References[0];
                }

                //Add the size of the entry's data, and the entry itself
                _size += entry.GetSize() + 8;

                //Add the lookup count
                _lookupCount += entry.GetLookupCount();

                //Add the section's name to the string table
                _referenceStringTable.Add(entry.Name);
            }

            //Calculate reference table size and add names to string table
            foreach (TableEntryNode reference in _rootNode.ReferenceList)
            {
                if (reference.References.Count > 0 || AddUnreferencedReferences)
                {
                    //Add entry name to string table
                    _referenceStringTable.Add(reference.Name);

                    //Add entry size (reference don't have any actual 'data' size)
                    _size += 8;
                }

                //TODO: Does each reference offset throughout the file
                //have a lookup offset?
                //Also, subtract 1 because the initial offset has no lookup entry
                //lookupCount += e.References.Count - 1;
            }

            _calculatingSize = false;

            //Add the lookup size and reference table size
            _size += (_lookupLen = _lookupCount * 4) + _referenceStringTable.TotalSize;

            return(_size);
        }