Skip to content

Commit

Permalink
Merge pull request #41 from harliq/SupportNewAceHexReadWrite
Browse files Browse the repository at this point in the history
Supports New ACE weenie formatting (Hex for certain fields)
  • Loading branch information
harliq authored Nov 5, 2021
2 parents 8e85db7 + 4eebae2 commit 9e58045
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 54 deletions.
50 changes: 13 additions & 37 deletions WeenieFab/WeenieFab/Decode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,21 @@ public static DataTable DecodeInstanceID(string integerblob, string pattern)

// Check for Hex
int iidValue = 0;
string checkHex = match.Groups[3].ToString();
if (checkHex.Contains("x") || checkHex.Contains("X"))
iidValue = (int)MainWindow.ConvertToDecimal(checkHex);
string checkHex = "";
if (match.Groups[3].ToString().Contains("0x"))
{
checkHex = match.Groups[3].ToString().Replace("0x", "");
iidValue = MainWindow.ConvertHexToDecimal(checkHex);
}
else if (match.Groups[3].ToString().Contains("0X"))
{
checkHex = match.Groups[3].ToString().Replace("0X", "");
iidValue = MainWindow.ConvertHexToDecimal(checkHex);
}
else
{
iidValue = MainWindow.ConvertToInteger(checkHex);
}

dr[0] = MainWindow.ConvertToInteger(match.Groups[2].ToString());
dr[1] = iidValue;
Expand All @@ -81,18 +91,7 @@ public static DataTable DecodeInstanceID(string integerblob, string pattern)

public static DataTable DecodeInt64(string integerblob, string pattern)
{
//DataTable tempDataTable = new DataTable();

//DataColumn propertyInt = new DataColumn("Property");
//DataColumn valueInt = new DataColumn("Value");
//DataColumn descript = new DataColumn("Description");

//propertyInt.DataType = Type.GetType("System.Int32");
//valueInt.DataType = Type.GetType("System.Int32");

//tempDataTable.Columns.Add(propertyInt);
//tempDataTable.Columns.Add(valueInt);
//tempDataTable.Columns.Add(descript);
DataTable tempDataTable = MainWindow.integer64DataTable.Clone();
tempDataTable.Clear();

Expand Down Expand Up @@ -146,17 +145,6 @@ public static DataTable DecodeThreeValuesBool(string boolblob, string pattern)
{
DataTable tempDataTable = MainWindow.boolDataTable.Clone();
tempDataTable.Clear();
//DataTable tempDataTable = new DataTable();

//DataColumn propertyInt = new DataColumn("Property");
//DataColumn valueBool = new DataColumn("Value");
//DataColumn descript = new DataColumn("Description");
//propertyInt.DataType = Type.GetType("System.Int32");
//valueBool.DataType = Type.GetType("System.Boolean");

//tempDataTable.Columns.Add(propertyInt);
//tempDataTable.Columns.Add(valueBool);
//tempDataTable.Columns.Add(descript);

foreach (var blobLine in boolblob.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
{
Expand Down Expand Up @@ -184,18 +172,6 @@ public static DataTable DecodeThreeValuesString(string floatblob, string pattern
DataTable tempDataTable = MainWindow.stringDataTable.Clone();
tempDataTable.Clear();

//DataTable tempDataTable = new DataTable();

//DataColumn propertyInt = new DataColumn("Property");
//DataColumn valueString = new DataColumn("Value");
//DataColumn descript = new DataColumn("Description");
//propertyInt.DataType = Type.GetType("System.Int32");
//valueString.DataType = Type.GetType("System.String");

//tempDataTable.Columns.Add(propertyInt);
//tempDataTable.Columns.Add(valueString);
//tempDataTable.Columns.Add(descript);

foreach (var blobLine in floatblob.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
{
if (blobLine.Contains("\""))
Expand Down
16 changes: 8 additions & 8 deletions WeenieFab/WeenieFab/FileOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ public void ReadSQLFile(string filepath)
var floatPattern = @"\((\d+),\s*(\d+),\s*([-+]?[0-9]*\.[0-9]+|[0-9]+)\)\s*\/\*\s*(.*)\s*\*\/*.*$"; // Spells also uses same pattern.
var stringPattern = @"\((\d+),\s*(\d+),\s*'(.*)'\)\s*\/\*\s*(.*)\s*\*\/.*.*$";
// var stringPattern = @"\((\d+),\s*(\d+),\s*'([a-zA-Z0-9_ .!?]*)'\)\s*\/\*\s*(.*)\s*\*\/.*.*$";
var didPattern = @"\((\d+),\s*(\d+),\s*(-?\d+)\) \/\*(.*)\*\/*.*$";
// var didPattern = @"\((\d+),\s*(\d+),\s*(-?\d+)\) \/\*(.*)\*\/*.*$";
// var didPattern = @"\((\d+),\s*(\d+),\s*(-?\d+)\) \/\*(.*)\*\/*.*$|\((\d+),\s*(\d+),\s*(-?0[xX][0-9a-fA-F]+)\) \/\*(.*)\*\/*.*$";

var didPattern = @"\((\d+),\s*(\d+),\s*(-?[a-zA-Z0-9_.-]*)\) \/\*(.*)\*\/*.*$";

var attribPattern = @"\((\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)\) \/\*(.*)\*\/*.*$";
var attrib2Pattern = @"\((\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)\) \/\*(.*)\*\/*.*$";
var skillsPattern = @"\((\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*([-+]?[0-9]*\.[0-9]+|[-+]?[0-9]+)\) \/\*(.*)\*\/*.*$";
Expand Down Expand Up @@ -269,7 +273,7 @@ public void ReadSQLFile(string filepath)
else if (line.Contains("INSERT INTO `weenie_properties_d_i_d`"))
{
didBlob = ReadBlob(sr);
didDataTable = DecodeSql.DecodeThreeValuesInt(didBlob, didPattern);
didDataTable = DecodeSql.DecodeInstanceID(didBlob, didPattern);
didDataTable.AcceptChanges();
didDataTable = ResortDataTable(didDataTable, "Property", "ASC");
dgDiD.DataContext = didDataTable;
Expand Down Expand Up @@ -381,11 +385,6 @@ public void ReadSQLFile(string filepath)
dgCreateItems.DataContext = createListDataTable;
dgCreateItems.Items.Refresh();

//createListDataTable = DecodeSql.DecodeThreeValuesFloat(createListBlob, createListPattern);
//createListDataTable.AcceptChanges();
//// createListDataTable = ResortDataTable(spellDataTable, "Property", "ASC");
//dgCreateItems.DataContext = createListDataTable;

}

}
Expand Down Expand Up @@ -461,7 +460,7 @@ public void WriteSQLFile(string filename)

// DiD
header = $"INSERT INTO `weenie_properties_d_i_d` (`object_Id`, `type`, `value`)";
body += TableToSql.ConvertTriValueTable(didDataTable, tbWCID.Text, header);
body += TableToSql.ConvertDidTable(didDataTable, tbWCID.Text, header);

// IiD
header = $"INSERT INTO `weenie_properties_i_i_d` (`object_Id`, `type`, `value`)";
Expand Down Expand Up @@ -708,6 +707,7 @@ private async void ProgressBarClearAnimation()
pgBarOne.BeginAnimation(ProgressBar.ValueProperty, null);

}

}

}
31 changes: 28 additions & 3 deletions WeenieFab/WeenieFab/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,37 @@ public static decimal ConvertToDecimal(string text)
decimal.TryParse(text, out i);
return i;
}
public static decimal ConvertHexToDecimal(string text)
public static int ConvertHexToDecimal(string hexValue)
{
decimal i = 0;
decimal.TryParse(text, out i);
//decimal i = 0;
//decimal.TryParse(text, out i);
//return i;
int i = 0;
//int i = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
Int32.TryParse(hexValue, out i);

try
{
i = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
}
catch (Exception)
{

throw;
}

return i;
}
public static string ConvertToHex(string value)
{

int i = ConvertToInteger(value);
string hexValue = i.ToString("X8");

return hexValue;

}

// UI Stuff
public void ClearAllDataTables()
{
Expand Down
102 changes: 99 additions & 3 deletions WeenieFab/WeenieFab/TableToSql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,67 @@ public static string ConvertIidTable(DataTable dt, string wcid, string header)
foreach (DataRow row in dt.Rows)
{
// Check for Hex
int iidValue = 0;
string iidValue = "";
//int iidValue = 0;
string checkHex = row[1].ToString();
if (checkHex.Contains("x") || checkHex.Contains("X"))
iidValue = (int) MainWindow.ConvertToDecimal(checkHex);
{
// iidValue = (int)MainWindow.ConvertToDecimal(checkHex);
iidValue = checkHex;
}
else
iidValue = MainWindow.ConvertToInteger(checkHex);
{
iidValue = "0x" + MainWindow.ConvertToHex(checkHex);
}

if (counter == 1 && counter == rowcount)
sqltext += $" ({wcid},{row[0],4},{iidValue,11}) /* {row[2]} */;\n";
else if (counter == 1)
sqltext += $" ({wcid},{row[0],4},{iidValue,11}) /* {row[2]} */\n";
else
{
if (counter == rowcount)
sqltext += $" , ({wcid},{row[0],4},{iidValue,11}) /* {row[2]} */;\n";
else
sqltext += $" , ({wcid},{row[0],4},{iidValue,11}) /* {row[2]} */\n";
}
counter++;
}
}
if (rowcount > 0)
sqltext += $"\n";
else
{
}
return sqltext;
}
public static string ConvertDidTable(DataTable dt, string wcid, string header)
{
string sqltext = "";

int counter = 1;
int rowcount = dt.Rows.Count;

if (rowcount > 0)
{
sqltext = header + $"\nVALUES";
foreach (DataRow row in dt.Rows)
{
int propertyValue = MainWindow.ConvertToInteger(row[0].ToString());
// Check for Hex
string iidValue = "";
//int iidValue = 0;
string checkHex = row[1].ToString();
if (checkHex.Contains("x") || checkHex.Contains("X"))
{
// iidValue = (int)MainWindow.ConvertToDecimal(checkHex);
iidValue = checkHex;
}
else
{
if (IsHexProperty(propertyValue))
iidValue = "0x" + MainWindow.ConvertToHex(checkHex);
}

if (counter == 1 && counter == rowcount)
sqltext += $" ({wcid},{row[0],4},{iidValue,11}) /* {row[2]} */;\n";
Expand All @@ -560,5 +614,47 @@ public static string ConvertIidTable(DataTable dt, string wcid, string header)
}
return sqltext;
}
public static bool IsHexProperty(int property)
{
switch (property)
{

case 43: //PropertyDataId.AccountHouseId:
case 57: //PropertyDataId.AlternateCurrency:
case 56: //PropertyDataId.AugmentationCreateItem:
case 54: //PropertyDataId.AugmentationEffect:
case 58: //PropertyDataId.BlueSurgeSpell:
case 39: //PropertyDataId.DeathSpell:
case 35: //PropertyDataId.DeathTreasureType:
case 42: //PropertyDataId.HouseId:
case 37: //PropertyDataId.ItemSkillLimit:
case 41: //PropertyDataId.ItemSpecializedOnly:
case 47: //PropertyDataId.LastPortal:
case 31: //PropertyDataId.LinkedPortalOne:
case 48: //PropertyDataId.LinkedPortalTwo:
case 61: //PropertyDataId.OlthoiDeathTreasureType:
case 49: //PropertyDataId.OriginalPortal:
case 30: //PropertyDataId.PhysicsScript:
case 55: //PropertyDataId.ProcSpell:
case 60: //PropertyDataId.RedSurgeSpell:
case 44: //PropertyDataId.RestrictionEffect:
case 28: //PropertyDataId.Spell:
case 29: //PropertyDataId.SpellComponent:
case 38: //PropertyDataId.UseCreateItem:
case 23: //PropertyDataId.UseSound:
case 40: //PropertyDataId.VendorsClassId:
case 32: //PropertyDataId.WieldedTreasureType:
case 59: //PropertyDataId.YellowSurgeSpell:

case int i when i >= 8001:
return false;


default:
return true;
}

}

}
}
6 changes: 3 additions & 3 deletions WeenieFab/WeenieFab/WeenieFab.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<Version>0.9.9.701</Version>
<Version>0.9.9.731</Version>
<ApplicationIcon>WeenieFabAppIcon.ico</ApplicationIcon>
<AssemblyVersion>0.9.9.701</AssemblyVersion>
<FileVersion>0.9.9.701</FileVersion>
<AssemblyVersion>0.9.9.731</AssemblyVersion>
<FileVersion>0.9.9.731</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 9e58045

Please sign in to comment.