private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (treeView1.SelectedNode == null | treeView1.SelectedNode is GroupWrapper) { return; } ValuesWrapper wrp = treeView1.SelectedNode as ValuesWrapper; for (int i = 0; i < wrp.Parameters.Count; ++i) { var t = wrp.Parameters[i].Type; object val = wrp.Parameters[i].Value; try { switch (t) { case ParameterType.s8: val = Convert.ToSByte(tbl.Rows[i][1]); break; case ParameterType.u8: val = Convert.ToByte(tbl.Rows[i][1]); break; case ParameterType.s16: val = Convert.ToInt16(tbl.Rows[i][1]); break; case ParameterType.u16: val = Convert.ToUInt16(tbl.Rows[i][1]); break; case ParameterType.s32: val = Convert.ToInt32(tbl.Rows[i][1]); break; case ParameterType.u32: val = Convert.ToUInt32(tbl.Rows[i][1]); break; case ParameterType.f32: val = Convert.ToSingle(tbl.Rows[i][1]); break; case ParameterType.str: val = tbl.Rows[i][1]; break; } } catch (Exception) { } wrp.Parameters[i].Value = val; tbl.Rows[i][1] = val; } }
private void ParseParams(string filepath) { using (FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite)) { using (var reader = new BinaryReader(stream)) { stream.Seek(0x08, SeekOrigin.Begin); var wrp = new ValuesWrapper("Group[0]"); int group = 0; while (stream.Position != stream.Length) { ParameterType type = (ParameterType)stream.ReadByte(); switch (type) { case ParameterType.u8: wrp.Parameters.Add(new ParamEntry(reader.ReadByte(), type)); break; case ParameterType.s8: wrp.Parameters.Add(new ParamEntry(reader.ReadByte(), type)); break; case ParameterType.u16: wrp.Parameters.Add(new ParamEntry(reader.ReadUInt16().Reverse(), type)); break; case ParameterType.s16: wrp.Parameters.Add(new ParamEntry(reader.ReadInt16().Reverse(), type)); break; case ParameterType.u32: wrp.Parameters.Add(new ParamEntry(reader.ReadUInt32().Reverse(), type)); break; case ParameterType.s32: wrp.Parameters.Add(new ParamEntry(reader.ReadInt32().Reverse(), type)); break; case ParameterType.f32: wrp.Parameters.Add(new ParamEntry(reader.ReadSingle().Reverse(), type)); break; case ParameterType.str: int tmp = reader.ReadInt32().Reverse(); wrp.Parameters.Add(new ParamEntry(new string(reader.ReadChars(tmp)), type)); break; case ParameterType.group: if (wrp.Parameters.Count > 0) { wrp.Wrap(); treeView1.Nodes.Add(wrp); } wrp = new GroupWrapper(++group); ((GroupWrapper)wrp).EntryCount = reader.ReadInt32().Reverse(); break; default: throw new NotImplementedException($"unk typecode: {type} at offset: {stream.Position:X}"); } } wrp.Wrap(); treeView1.Nodes.Add(wrp); } } }