Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Private Providers
DBCD/Providers/MirrorDBCProvider.cs

# Rider
.idea/
11 changes: 11 additions & 0 deletions DBCD.IO/Attributes/EnumAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace DBCD.IO.Attributes
{
[AttributeUsage(AttributeTargets.Field)]
public class EnumAttribute(string enumName, bool isFlags) : Attribute
{
public readonly string EnumName = enumName;
public readonly bool IsFlags = isFlags;
}
}
27 changes: 26 additions & 1 deletion DBCD.Tests/ReadingTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DBCD.Providers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;

namespace DBCD.Tests
Expand Down Expand Up @@ -208,7 +209,6 @@ public void TestReadingAllDB2s()
// System.Console.WriteLine($"B: {countBefore} => A: {countAfter}");
//}


//[TestMethod]
//public void TestFilesystemDBDProvider()
//{
Expand All @@ -217,5 +217,30 @@ public void TestReadingAllDB2s()
// // Spell is present in Classic Era -> Retail: https://www.wowhead.com/spell=17/
// Assert.AreEqual("Power Word: Shield", storage[17]["Name_lang"]);
//}

[TestMethod]
public void TestEnumReadingSingle()
{
var dbcd = new DBCD(wagoDBCProvider, githubDBDProvider, new GithubEnumProvider(useCache: true));

var storage = dbcd.Load("SpellEffect", "12.0.1.66220");
var spellEffectRow = storage[1177101];
Assert.AreEqual(spellEffectRow.IsEnumMember("Effect", "SET_PLAYER_DATA_ELEMENT_ACCOUNT"), true);
}

[TestMethod]
public void TestEnumReadingArray()
{
var dbcd = new DBCD(wagoDBCProvider, githubDBDProvider, new GithubEnumProvider(useCache: true));

var storage = dbcd.Load("SpellMisc", "12.0.1.66220");
var spellMiscRow = storage[66253];

Assert.AreEqual(spellMiscRow.HasFlag("Attributes", 0, "ON_NEXT_SWING"), false);
Assert.AreEqual(spellMiscRow.HasFlag("Attributes", 0, "HIDDEN_CLIENTSIDE"), true);

// Throws an exception because the Enum Member is not in the Enum
Assert.ThrowsException<KeyNotFoundException>(() => spellMiscRow.HasFlag("Attributes", 1, "HIDDEN_CLIENTSIDE"));
}
}
}
33 changes: 18 additions & 15 deletions DBCD/DBCD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using DBDefsLib.Structs;

namespace DBCD
{

public class DBCD
{
private readonly IDBCProvider dbcProvider;
private readonly IDBDProvider dbdProvider;
private readonly IEnumProvider enumProvider;

private readonly bool useBDBD;
private readonly Dictionary<string, Structs.TableInfo> BDBDCache;
private readonly Dictionary<string, TableInfo> BDBDTableCache;

/// <summary>
/// Creates a DBCD instance that uses the given DBC and DBD providers.
/// </summary>
/// <param name="dbcProvider">The IDBCProvider for DBC files.</param>
/// <param name="dbdProvider">The IDBDProvider for DBD files.</param>
public DBCD(IDBCProvider dbcProvider, IDBDProvider dbdProvider)
/// <param name="enumProvider">The optional IEnumProvider for enum/flag metadata.</param>
public DBCD(IDBCProvider dbcProvider, IDBDProvider dbdProvider, IEnumProvider enumProvider = null)
{
this.dbcProvider = dbcProvider;
this.dbdProvider = dbdProvider;
this.enumProvider = enumProvider;
this.useBDBD = false;
}

Expand All @@ -33,12 +36,16 @@ public DBCD(IDBCProvider dbcProvider, IDBDProvider dbdProvider)
/// </summary>
/// <param name="dbcProvider">The IDBCProvider for DBC files.</param>
/// <param name="bdbdStream">The stream for a BDBD (Binary DBD) file to load all definitions from.</param>
/// <param name="enumProvider">The optional IEnumProvider for enum/flag metadata.</param>
/// <remarks>WARNING: The usage of a BDBD file for supplying definitions is still experimental and currently has little to no advantages.</remarks>
public DBCD(IDBCProvider dbcProvider, Stream bdbdStream)
public DBCD(IDBCProvider dbcProvider, Stream bdbdStream, IEnumProvider enumProvider = null)
{
this.dbcProvider = dbcProvider;
this.enumProvider = enumProvider;
this.useBDBD = true;
this.BDBDCache = BDBDReader.Read(bdbdStream);

var bdbd = BDBDReader.Read(bdbdStream);
BDBDTableCache = bdbd.tableDefinitions;
}

/// <summary>
Expand All @@ -52,7 +59,7 @@ public IDBCDStorage Load(string tableName, string build = null, Locale locale =
{
var dbcStream = this.dbcProvider.StreamForTableName(tableName, build);

Structs.DBDefinition databaseDefinition;
DBDefinition databaseDefinition;

if (!useBDBD)
{
Expand All @@ -62,23 +69,19 @@ public IDBCDStorage Load(string tableName, string build = null, Locale locale =
}
else
{
if (!BDBDCache.TryGetValue(tableName, out var tableInfo))
if (!BDBDTableCache.TryGetValue(tableName, out var tableInfo))
throw new FileNotFoundException($"Table {tableName} not found in BDBD.");

databaseDefinition = tableInfo.dbd;
}

var builder = new DBCDBuilder(locale);
var builder = new DBCDBuilder(locale, enumProvider);

var dbReader = new DBParser(dbcStream);
var definition = builder.Build(dbReader, databaseDefinition, tableName, build);

var type = typeof(DBCDStorage<>).MakeGenericType(definition.Item1);

return (IDBCDStorage)Activator.CreateInstance(type, new object[2] {
dbReader,
definition.Item2
});
var type = typeof(DBCDStorage<>).MakeGenericType(definition.Type);
return (IDBCDStorage)Activator.CreateInstance(type, dbReader, definition.Info);
}
}

Expand All @@ -102,4 +105,4 @@ public enum Locale
PtBR = PtPT,
ItIT = 11,
}
}
}
2 changes: 1 addition & 1 deletion DBCD/DBCD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DBDefsLib" Version="1.0.1" />
<PackageReference Include="DBDefsLib" Version="1.0.1.2-beta4" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>

Expand Down
Loading