コード例 #1
0
        private void bEdit_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            int i = (int)dataGridView1.SelectedRows[0].Tag;

            switch (mode)
            {
            case Mode.Arrays: {
                DataType[] types   = new DataType[connection.ArrayLengths[i]];
                int[]      lenType = new int[connection.ArrayLengths[i]];
                string[]   strings = new string[connection.ArrayLengths[i]];
                connection.WriteDataType(DataTypeSend.GetArray); // code
                connection.WriteInt(i);                          // index
                int lenData = 0;
                for (int j = 0; j < strings.Length; j++)
                {
                    types[j]   = (DataType)connection.ReadInt();
                    lenType[j] = connection.ReadInt();     // len data of type
                    lenData   += lenType[j];
                }
                byte[]       buf = connection.ReadBytes(lenData); // read data
                BinaryReader br  = new BinaryReader(new MemoryStream(buf));
                for (int j = 0; j < strings.Length; j++)
                {
                    switch (types[j])
                    {
                    case DataType.None:
                        br.BaseStream.Position += 4;
                        break;

                    case DataType.Int:
                        strings[j] = br.ReadInt32().ToString();
                        break;

                    case DataType.Float:
                        strings[j] = br.ReadSingle().ToString();
                        break;

                    case DataType.String:
                        byte[] bytes = br.ReadBytes(lenType[j]);
                        strings[j] = System.Text.Encoding.ASCII.GetString(bytes, 0, Array.IndexOf <byte>(bytes, 0));
                        break;
                    }
                }
                br.Close();
                strings = EditorWindow.ShowEditor(this, null, types, strings, connection.ArrayIsMap[i]);
                if (strings != null)       // save
                {
                    MemoryStream ms = new MemoryStream(lenData);
                    BinaryWriter bw = new BinaryWriter(ms);
                    for (int j = 0; j < strings.Length; j++)
                    {
                        switch (types[j])
                        {
                        case DataType.None:
                            bw.BaseStream.Position += 4;
                            break;

                        case DataType.Int:
                            bw.Write(int.Parse(strings[j]));
                            break;

                        case DataType.Float:
                            bw.Write(float.Parse(strings[j]));
                            break;

                        case DataType.String:
                            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(strings[j]);
                            if (bytes.Length < lenType[j])
                            {
                                bw.Write(bytes);
                            }
                            else
                            {
                                bw.Write(bytes, 0, lenType[j] - 1);
                            }
                            bw.Write((byte)0);
                            break;
                        }
                    }
                    // send data to sfall
                    connection.WriteDataType(DataTypeSend.SetArray);
                    connection.WriteInt(i);     // index
                    connection.WriteInt(lenData);
                    connection.WriteBytes(ms.GetBuffer(), 0, lenData);
                    bw.Close();
                }
            }
            break;

            case Mode.Critters: {
                DataType[] types   = new DataType[33];
                string[]   strings = new string[33];
                string[]   names   = new string[33];
                connection.WriteDataType(DataTypeSend.RetrieveCritter);
                connection.WriteInt(i);
                BinaryReader br = new BinaryReader(new System.IO.MemoryStream(connection.ReadBytes(33 * 4)));
                for (int j = 0; j < 33; j++)
                {
                    types[j]   = DataType.Int;
                    strings[j] = br.ReadInt32().ToString();
                }
                br.Close();
                names[0]  = " ID";
                names[1]  = " Tile";
                names[6]  = " Current frame";
                names[7]  = " Rotation";
                names[8]  = " FID";
                names[9]  = " Flags";
                names[10] = " Elevation";
                names[11] = " Inventory count";
                names[13] = " Inventory pointer";
                names[14] = " Reaction";
                names[15] = " Combat state";
                names[16] = " Current AP";
                names[17] = " Combat flags";
                names[18] = " Last Turn Damage";
                names[19] = " AI Packet";
                names[20] = " Team";
                names[21] = " Who hit me";
                names[22] = " HP";
                names[23] = " Rads";
                names[24] = " Poison";
                names[25] = " Proto ID";
                names[26] = " Combat ID";
                names[29] = " Outline flags";
                names[30] = " Script ID";
                names[32] = " Script index";
                strings   = EditorWindow.ShowEditor(this, names, types, strings);
                if (strings != null)
                {
                    MemoryStream ms = new MemoryStream(33 * 4);
                    BinaryWriter bw = new BinaryWriter(ms);
                    for (int j = 0; j < 33; j++)
                    {
                        bw.Write(int.Parse(strings[j]));
                    }
                    connection.WriteDataType(DataTypeSend.SetCritter);
                    connection.WriteInt(i);
                    connection.WriteBytes(ms.GetBuffer(), 0, 33 * 4);
                    bw.Close();
                }
            }
            break;
            }
        }
コード例 #2
0
        private void bEdit_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count != 1)
            {
                return;
            }
            int i = dataGridView1.SelectedRows[0].Index;

            switch (mode)
            {
            case Mode.Arrays: {
                DataType[] types   = new DataType[connection.ArrayLengths[i]];
                string[]   strings = new string[connection.ArrayLengths[i]];
                connection.WriteDataType(DataTypeSend.GetArray);
                connection.WriteInt(i);
                for (int j = 0; j < strings.Length; j++)
                {
                    types[j] = (DataType)connection.ReadInt();
                }
                byte[]       buf = connection.ReadBytes(connection.ArrayLengths[i] * connection.ArrayDataSizes[i]);
                MemoryStream ms  = new MemoryStream(buf);
                BinaryReader br  = new BinaryReader(ms);
                for (int j = 0; j < strings.Length; j++)
                {
                    ms.Position = j * connection.ArrayDataSizes[i];
                    switch (types[j])
                    {
                    case DataType.Int:
                        strings[j] = br.ReadInt32().ToString();
                        break;

                    case DataType.Float:
                        strings[j] = br.ReadSingle().ToString();
                        break;

                    case DataType.String:
                        byte[] bytes = br.ReadBytes(connection.ArrayDataSizes[i]);
                        strings[j] = System.Text.Encoding.ASCII.GetString(bytes, 0, Array.IndexOf <byte>(bytes, 0));
                        break;
                    }
                }
                br.Close();
                strings = EditorWindow.ShowEditor(null, types, strings);
                if (strings != null)
                {
                    connection.WriteDataType(DataTypeSend.SetArray);
                    connection.WriteInt(i);
                    ms = new MemoryStream(connection.ArrayLengths[i] * connection.ArrayDataSizes[i]);
                    BinaryWriter bw = new BinaryWriter(ms);
                    for (int j = 0; j < strings.Length; j++)
                    {
                        ms.Position = j * connection.ArrayDataSizes[i];
                        switch (types[j])
                        {
                        case DataType.Int:
                            bw.Write(int.Parse(strings[j]));
                            break;

                        case DataType.Float:
                            bw.Write(float.Parse(strings[j]));
                            break;

                        case DataType.String:
                            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(strings[j]);
                            if (bytes.Length < connection.ArrayDataSizes[i])
                            {
                                bw.Write(bytes);
                            }
                            else
                            {
                                bw.Write(bytes, 0, connection.ArrayDataSizes[i] - 1);
                            }
                            bw.Write(0);
                            break;
                        }
                    }
                    connection.WriteBytes(ms.GetBuffer(), 0, connection.ArrayLengths[i] * connection.ArrayDataSizes[i]);
                    bw.Close();
                }
            }
            break;

            case Mode.Critters: {
                DataType[] types   = new DataType[29];
                string[]   strings = new string[29];
                string[]   names   = new string[29];
                connection.WriteDataType(DataTypeSend.RetrieveCritter);
                connection.WriteInt(i);
                BinaryReader br = new BinaryReader(new System.IO.MemoryStream(connection.ReadBytes(29 * 4)));
                for (int j = 0; j < 29; j++)
                {
                    types[j]   = DataType.Int;
                    strings[j] = br.ReadInt32().ToString();
                    names[j]   = "0x" + (j * 4).ToString("x");
                }
                br.Close();
                names[1]  = "Tile";
                names[10] = "Elevation";
                names[11] = "Inventory count";
                names[13] = "Inventory pointer";
                names[16] = "Current AP";
                names[17] = "Crippled limbs";
                names[22] = "HP";
                names[23] = "Rads";
                names[24] = "Poison";
                names[25] = "Proto ID";
                strings   = EditorWindow.ShowEditor(names, types, strings);
                if (strings != null)
                {
                    MemoryStream ms = new MemoryStream(29 * 4);
                    BinaryWriter bw = new BinaryWriter(ms);
                    for (int j = 0; j < 29; j++)
                    {
                        bw.Write(int.Parse(strings[j]));
                    }
                    connection.WriteDataType(DataTypeSend.SetCritter);
                    connection.WriteInt(i);
                    connection.WriteBytes(ms.GetBuffer(), 0, 29 * 4);
                    bw.Close();
                }
            }
            break;
            }
        }