Exemplo n.º 1
0
        public EditPreparedList(ROMInterface romIF, bool resolve, Data objPlaces, Data data)
        {
            this.romIF = romIF;

            loadData(resolve, data, objPlaces);

            InitializeComponent();

            setText(additionalIDs, additional);
            setText(resolvedIDs, resolved);
            setText(newResolvedIDs, newResolved);
            information.Text = infoText.Replace("\n", "\r\n");
            resolvedIDs.Enabled = resolve;
        }
Exemplo n.º 2
0
        void loadData(bool r, Data data, Data objPlaces)
        {
            HashSet<ushort> ids = new HashSet<ushort>();
            for (uint i = 0; i < romIF.preparedList_count; i++)
            {
                var h = data.getHalf(i * 2);
                if (h == 0xffff) break;
                ids.Add(h);
            }
            oldIDs = ids.OrderBy(x => x).ToList();

            HashSet<ushort> t = r ? resolve(ids, objPlaces) : new HashSet<ushort>();
            newResolved = t.Except(ids).ToList();
            resolved = t.Except(newResolved).ToList();
            additional = ids.Except(t).ToList();
        }
Exemplo n.º 3
0
 public Data saveData()
 {
     ushort[] IDs =
         Enumerable.Empty<ushort>()
         .Union(getText(resolvedIDs))
         .Union(getText(newResolvedIDs))
         .Union(getText(additionalIDs))
         .OrderBy(x => x)
         .ToArray();
     if (IDs.Length > romIF.preparedList_count - 1)
         throw new IDsTooMany(IDs.Length);
     if (IDs.SequenceEqual(oldIDs))
         throw new ChangeNothing();
     Data data = new Data(new byte[romIF.preparedList_count * 2]);
     for (uint i = 0; i < IDs.Length; i++)
         data.setHalf(i * 2, IDs[i]);
     data.setHalf((uint)IDs.Length * 2, 0xffff);
     return data;
 }
Exemplo n.º 4
0
Arquivo: Map.cs Projeto: anta-/YSedit
        /// <summary>
        /// Mapに関してデータを読み、初期化をする
        /// </summary>
        /// <exception cref="ArgumentException">mapNumberが大きすぎた場合</exception>
        /// <exception cref="DataException">mapNumberが無効なマップを指している、またはROMが壊れている場合</exception>
        public Map(ROM rom_, byte mapNumber, MainView mainView)
        {
            rom = rom_;
            romIF = rom.romIF;
            this.mainView = mainView;
            mainView.onChanged += () => { rom.newChange(true); };

            if (romIF.mapNumbers <= mapNumber)
                throw new ArgumentException("map number is too big");

            currentMapNumber = mapNumber;
            ustruct5 = rom.readData(romIF.ustruct5Table + mapNumber * romIF.ustruct5_size, romIF.ustruct5_size);
            var iUStruct3 = ustruct5.getDataID(romIF.uttruct5_iUStruct3);
            ustruct3 = rom.readData(iUStruct3, romIF.ustruct3_size);
            var iiPlaceVector = ustruct3.getDataID(romIF.ustruct3_iiPlaceVector);
            var iPlaceVector = rom.readData(iiPlaceVector, 4).getDataID(0);
            placeVector = rom.readData(iPlaceVector, romIF.placeVector_size);
            var iObjPlaces = placeVector.getDataID(romIF.placeVector_iObjPlaces);
            var objPlaces = rom.readData(iObjPlaces,
                placeVector.getHalf(romIF.placeVector_numberOfObjPlaces) * romIF.objPlaceC_size);

            mainView.setObjPlaces(objPlaces);   //objPlacesはmainViewが持つ
            mainView.size = new System.Drawing.Size(0x2000, 0x200); //TODO: データから読み込む
        }
Exemplo n.º 5
0
 public void setData(uint offset, Data data)
 {
     Debug.Assert(offset + data.Length <= Length);
     data.bytes.CopyTo(bytes, offset);
 }
Exemplo n.º 6
0
 private void OK_Click(object sender, EventArgs e)
 {
     Action<string> error = s => MessageBox.Show(s, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
     try
     {
         resultData = saveData();
         DialogResult = DialogResult.OK;
         Close();
     }
     catch (ChangeNothing)
     {
         DialogResult = DialogResult.Cancel;
         Close();
     }
     catch (IDsTooMany ex)
     {
         error("IDs is too many (" + ex.num + " / " + (romIF.preparedList_count-1) + ")");
     }
     catch (Exception)
     {
         error("Invalid input");
     }
 }
Exemplo n.º 7
0
        HashSet<ushort> resolve(HashSet<ushort> ids, Data objPlaces)
        {
            HashSet<ushort> s = new HashSet<ushort>();

            Action<ushort,string> addObject = (ushort k, string info) =>
            {
                if (s.Contains(k))
                    return;
                infoText += info + " -> " + k.ToString("x4") + "\n";
                s.Add(k);
            };

            foreach (var k in romIF.basicObjects)
                addObject(k, "basic");

            int numberOfObjs = (int)(objPlaces.Length / romIF.objPlaceC_size);
            for (uint i = 0; i < numberOfObjs; i++)
            {
                var kind = objPlaces.getHalf(i * romIF.objPlaceC_size + romIF.objPlace_kind);
                foreach (var dep in ObjectInfo.getObjectDependents(kind))
                {
                    switch (dep.c)
                    {
                        case ObjectInfo.Dependent.Case.ObjCfg:
                            addObject((ushort)dep.a, "#" + kind.ToString("x4"));
                            break;
                        case ObjectInfo.Dependent.Case.ObjFunc:
                            var ks = ObjectInfo.getFuncObjects(dep.a);
                            if (ks.Count == 0)
                            {
                                //どうしようもない
                                infoText += "!" + kind.ToString("x4") + "->" + dep.a.ToString("x8") + "\n";
                                break;
                            }
                            if (!ks.Any(k => s.Contains(k)))
                            {
                                if (ks.Any(k => ids.Contains(k)))
                                    addObject(ks.Find(k => ids.Contains(k)), "%" + kind.ToString("x4"));
                                else
                                    addObject(ks[0], "$" + kind.ToString("x4"));
                            }
                            break;
                    }
                }
            }

            for (uint i = 0; i < numberOfObjs; i++)
            {
                var kind = objPlaces.getHalf(i * romIF.objPlaceC_size + romIF.objPlace_kind);
                if (s.Remove(kind))
                    infoText += kind.ToString("x4") + " remove" + "\n";
            }

            return s;
        }