コード例 #1
0
ファイル: GCTNode.cs プロジェクト: 0000duck/brawltools
        public override bool OnInitialize()
        {
            base.OnInitialize();

            GCTCodeLine *lines = (GCTCodeLine *)Data + 1;

            while (true)
            {
                GCTCodeLine line = *lines++;
                if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2)
                {
                    break;
                }
            }

            _header = (GCTHeader *)lines;
            if (((uint)_header - (uint)Data) < WorkingUncompressed.Length)
            {
                if (_header->_nameOffset > 0)
                {
                    _gameName = _header->GameName;
                }
                _name = _header->GameID;
            }

            if (_name == null)
            {
                _name = Path.GetFileNameWithoutExtension(_origPath);
            }

            return(WorkingUncompressed.Length > 16 && _header->_count > 0);
        }
コード例 #2
0
        public override void OnRebuild(VoidPtr address, int length, bool force)
        {
            List <GCTCodeEntryNode> enabledChildren = Children.Select(e => ((GCTCodeEntryNode)e)).Where(e => e._enabled).ToList();

            GCTCodeLine *line = (GCTCodeLine *)address;

            *line++ = GCTCodeLine.Tag;
            foreach (GCTCodeEntryNode n in enabledChildren)
            {
                foreach (GCTCodeLine l in n._lines)
                {
                    *line++ = l;
                }
            }
            *line++ = GCTCodeLine.End;
            if (_writeInfo)
            {
                GCTHeader *hdr = (GCTHeader *)line;
                hdr->_count = (uint)enabledChildren.Count;

                int offset = 12 + enabledChildren.Count * 16;
                _stringTable.WriteTable((VoidPtr)hdr + offset);

                hdr->_idOffset = (uint)_stringTable[_name] - (uint)hdr;
                if (!String.IsNullOrEmpty(_gameName))
                {
                    hdr->_nameOffset = (uint)_stringTable[_gameName] - (uint)hdr;
                }
                else
                {
                    hdr->_nameOffset = 0;
                }

                GCTCodeEntry *entry      = (GCTCodeEntry *)(hdr + 1);
                uint          codeOffset = 8;
                foreach (GCTCodeEntryNode n in enabledChildren)
                {
                    entry->_codeOffset = codeOffset;
                    codeOffset        += (uint)n._lines.Length * 8;

                    entry->_lineCount  = (uint)n._lines.Length;
                    entry->_nameOffset = (uint)_stringTable[n._name] - (uint)entry;
                    if (!String.IsNullOrEmpty(n._description))
                    {
                        entry->_descOffset = (uint)_stringTable[n._description] - (uint)entry;
                    }
                    else
                    {
                        entry->_descOffset = 0;
                    }
                    entry++;
                }
            }
        }
コード例 #3
0
ファイル: GCTNode.cs プロジェクト: 0000duck/brawltools
        internal static GCTNode IsParsable(string path)
        {
            FileMap map = FileMap.FromFile(path, FileMapProtect.ReadWrite);

            GCTCodeLine *data = (GCTCodeLine *)map.Address;

            if (GCTCodeLine.Tag._1 != data->_1 || GCTCodeLine.Tag._2 != data->_2)
            {
                map.Dispose();
                return(null);
            }

            data = (GCTCodeLine *)(map.Address + (uint)Helpers.RoundDown((uint)map.Length, 8) - GCTCodeLine.Size);
            bool endFound = false;
            int  i        = 0;

            while (!endFound)
            {
                GCTCodeLine line = *data--;
                if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2)
                {
                    endFound = true;
                    break;
                }

                i++;
            }

            if (endFound && i <= 0)
            {
                data = (GCTCodeLine *)map.Address + 1;

                string s = "";
                while (true)
                {
                    GCTCodeLine line = *data++;
                    if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2)
                    {
                        break;
                    }

                    s += line.ToStringNoSpace();
                }

                GCTNode g = new GCTNode();

                List <string> _unrecognized = new List <string>();

                foreach (CodeStorage c in Properties.Settings.Default.Codes)
                {
                    int index = -1;
                    if ((index = s.IndexOf(c._code)) >= 0)
                    {
                        g.AddChild(new GCTCodeEntryNode()
                        {
                            _name = c._name, _description = c._description, LinesNoSpaces = s.Substring(index, c._code.Length)
                        });
                        s = s.Remove(index, c._code.Length);
                    }
                }

                if (g.Children.Count > 0)
                {
                    if (s.Length > 0)
                    {
                        MessageBox.Show(String.Format("{0} code{1} w{2} recognized.", g.Children.Count.ToString(), g.Children.Count > 1 ? "s" : "", g.Children.Count > 1 ? "ere" : "as"));
                    }
                }
                else
                {
                    MessageBox.Show("This GCT does not contain any recognizable codes.");
                }

                if (s.Length > 0)
                {
                    g.AddChild(new GCTCodeEntryNode()
                    {
                        _name = "Unrecognized Code(s)", LinesNoSpaces = s
                    });
                }

                return(g);
            }
            else if (endFound && i > 0)
            {
                GCTNode g = new GCTNode();
                g.Initialize(null, new DataSource(map));
                return(g);
            }

            map.Dispose();
            return(null);
        }