Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bunch of improvements #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
29 changes: 27 additions & 2 deletions DBC Viewer/Forms/DefinitionEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,35 @@ private void comboBox1_KeyUp(object sender, KeyEventArgs e)
private void button2_Click(object sender, EventArgs e)
{
ListViewItem item;

string nameBase = "newField_";
string name;

int counter = 0;
do
{
bool contains = false;
name = nameBase + counter.ToString();
foreach (ListViewItem listItem in listView1.Items)
{
if (listItem.SubItems[1].Text == name)
{
contains = true;
++counter;
break;
}
}
if (!contains)
break;
} while (true);

item = new ListViewItem(new string[] { "0", name, "int", "False" });

if (listView1.SelectedItems.Count > 0)
item = listView1.Items.Insert(listView1.SelectedItems[0].Index + 1, new ListViewItem(new string[] { "0", "newField", "int", "False" }));
item = listView1.Items.Insert(listView1.SelectedItems[0].Index + 1, item);
else
item = listView1.Items.Add(new ListViewItem(new string[] { "0", "newField", "int", "False" }));
item = listView1.Items.Add(item);

item.Selected = true;
m_changed = true;
}
Expand Down
6 changes: 3 additions & 3 deletions DBC Viewer/Forms/FilterForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ public partial class FilterForm : Form

private Object[] decimalOperators = new Object[]
{
ComparisonType.Equal,
ComparisonType.And,
ComparisonType.AndNot,
ComparisonType.Equal,
ComparisonType.NotEqual,
ComparisonType.Less,
ComparisonType.Greater
};

private Object[] stringOperators = new Object[]
{
ComparisonType.Contains,
ComparisonType.Equal,
ComparisonType.NotEqual,
ComparisonType.StartWith,
ComparisonType.EndsWith,
ComparisonType.Contains
ComparisonType.EndsWith
};

private Object[] floatOperators = new Object[]
Expand Down
17 changes: 17 additions & 0 deletions DBC Viewer/Forms/MainForm.EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ namespace DBCViewer
{
partial class MainForm
{
private string lastPath = "";

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
if (lastPath.Length > 0)
openFileDialog1.InitialDirectory = lastPath;

lastPath = "";
if (openFileDialog1.ShowDialog() != DialogResult.OK)
return;

lastPath = Path.GetDirectoryName(openFileDialog1.FileName);
LoadFile(openFileDialog1.FileName);
}

Expand Down Expand Up @@ -180,6 +187,16 @@ private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
else
dataRow[j] = m_reader.StringTable[br.ReadInt32()];
break;
case "intarray":
{
int columns = br.ReadByte();
var sb = new StringBuilder();
for (var c = 0; c < columns; ++c)
sb.Append(br.ReadUInt32()).Append(", ");

dataRow[j] = sb.ToString();
break;
}
default:
throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "Unknown field type {0}!", types[j]));
}
Expand Down
1 change: 1 addition & 0 deletions DBC Viewer/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ private void CreateColumns()
m_dataTable.Columns.Add(colName, typeof(double));
break;
case "string":
case "intarray":
m_dataTable.Columns.Add(colName, typeof(string));
break;
default:
Expand Down
21 changes: 9 additions & 12 deletions DBC Viewer/Readers/DB2Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,16 @@ public DB2Reader(string fileName)
uint build = reader.ReadUInt32(); // new field in WDB2
uint unk1 = reader.ReadUInt32(); // new field in WDB2

if (build > 12880) // new extended header
int MinId = reader.ReadInt32(); // new field in WDB2
int MaxId = reader.ReadInt32(); // new field in WDB2
int locale = reader.ReadInt32(); // new field in WDB2
int unk5 = reader.ReadInt32(); // new field in WDB2

if (MaxId != 0)
{
int MinId = reader.ReadInt32(); // new field in WDB2
int MaxId = reader.ReadInt32(); // new field in WDB2
int locale = reader.ReadInt32(); // new field in WDB2
int unk5 = reader.ReadInt32(); // new field in WDB2

if (MaxId != 0)
{
var diff = MaxId - MinId + 1; // blizzard is weird people...
reader.ReadBytes(diff * 4); // an index for rows
reader.ReadBytes(diff * 2); // a memory allocation bank
}
var diff = MaxId - MinId + 1; // blizzard is weird people...
reader.ReadBytes(diff * 4); // an index for rows
reader.ReadBytes(diff * 2); // a memory allocation bank
}

m_rows = new byte[RecordsCount][];
Expand Down