Skip to content

Commit

Permalink
update to 4.0.3
Browse files Browse the repository at this point in the history
patch by TOM_RUS, thanks
http://paste2.org/p/1025135

Signed-off-by: Konctantin <gawrilyako@gmail.com>
  • Loading branch information
Konctantin committed Oct 8, 2010
1 parent 8156df4 commit c0ca56c
Show file tree
Hide file tree
Showing 13 changed files with 860 additions and 437 deletions.
19 changes: 17 additions & 2 deletions SpellWork/DBC/DBC.cs
Expand Up @@ -4,14 +4,27 @@ namespace SpellWork
{
public static class DBC
{
public const string VERSION = "SpellWork 3.3.3a (11723)";
public const string DBC_PATH = @"dbc\";
public const string VERSION = "SpellWork 4.0.3 (13117)";
public const string DBC_PATH = "dbc";

public const int MAX_DBC_LOCALE = 16;
public const int MAX_EFFECT_INDEX = 3;
public const int SPELL_ENTRY_FOR_DETECT_LOCALE = 1;

public static Dictionary<uint, SpellEntry> Spell;
public static Dictionary<uint, SpellEffectEntry> SpellEffect;
public static Dictionary<uint, SpellTargetRestrictionsEntry> SpellTargetRestrictions;
public static Dictionary<uint, SpellAuraRestrictionsEntry> SpellAuraRestrictions;
public static Dictionary<uint, SpellCooldownsEntry> SpellCooldowns;
public static Dictionary<uint, SpellCategoriesEntry> SpellCategories;
public static Dictionary<uint, SpellShapeshiftEntry> SpellShapeshift;
public static Dictionary<uint, SpellAuraOptionsEntry> SpellAuraOptions;
public static Dictionary<uint, SpellLevelsEntry> SpellLevels;
public static Dictionary<uint, SpellClassOptionsEntry> SpellClassOptions;
public static Dictionary<uint, SpellCastingRequirementsEntry> SpellCastingRequirements;
public static Dictionary<uint, SpellPowerEntry> SpellPower;
public static Dictionary<uint, SpellInterruptsEntry> SpellInterrupts;
public static Dictionary<uint, SpellEquippedItemsEntry> SpellEquippedItems;
public static Dictionary<uint, SpellRadiusEntry> SpellRadius;
public static Dictionary<uint, SpellCastTimesEntry> SpellCastTimes;
public static Dictionary<uint, SpellRangeEntry> SpellRange;
Expand All @@ -26,6 +39,8 @@ public static class DBC
public static Dictionary<uint, string> SpellRangeStrings = new Dictionary<uint, string>();
public static Dictionary<uint, string> ScreenEffectStrings = new Dictionary<uint, string>();

public static Dictionary<uint, Dictionary<int, SpellEffectEntry>> SpellEffects = new Dictionary<uint, Dictionary<int, SpellEffectEntry>>();

// DB
public static List<Item> ItemTemplate = new List<Item>();

Expand Down
6 changes: 4 additions & 2 deletions SpellWork/DBC/DBCReader.cs
Expand Up @@ -15,15 +15,17 @@ static class DBCReader

using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open, FileAccess.Read), Encoding.UTF8))
{
if (!File.Exists(fileName))
throw new FileNotFoundException();
// read dbc header
DbcHeader header = reader.ReadStruct<DbcHeader>();
int size = Marshal.SizeOf(typeof(T));

if (!header.IsDBC)
throw new SpellWorkException("{0} is not DBC files", fileName);
throw new Exception(fileName + " is not DBC files");

if (header.RecordSize != size)
throw new SpellWorkException("Size of row in DBC file ({0}) != size of DBC struct ({1}) in DBC: {2}", header.RecordSize, size, fileName);
throw new Exception(string.Format("Size of row in DBC file ({0}) != size of DBC struct ({1}) in DBC: {2}", header.RecordSize, size, fileName));

// read dbc data
for (int r = 0; r < header.RecordsCount; ++r)
Expand Down
706 changes: 542 additions & 164 deletions SpellWork/DBC/Structure.cs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions SpellWork/Extensions/Extensions.cs
Expand Up @@ -280,6 +280,13 @@ public static bool ContainsElement(this uint[] array, uint[] value)
return false;
}

public static bool Match(this SpellClassOptionsEntry opt, SpellClassOptionsEntry arg, uint[] mask)
{
if (opt.SpellFamilyName == arg.SpellFamilyName && opt.SpellFamilyFlags != null && opt.SpellFamilyFlags.ContainsElement(mask))
return true;
return false;
}

/// <summary>
/// Checks if the specified value in a given array
/// </summary>
Expand Down
21 changes: 0 additions & 21 deletions SpellWork/Extensions/SpellWorkException.cs

This file was deleted.

40 changes: 20 additions & 20 deletions SpellWork/Forms/FormMain.cs
Expand Up @@ -202,7 +202,7 @@ private void AdvansedFilter()
var bTarget2 = _cbTarget2.SelectedIndex != 0;
var fTarget2 = _cbTarget2.SelectedValue.ToInt32();

// additional filtert
// additional filter
var advVal1 = _tbAdvansedFilter1Val.Text;
var advVal2 = _tbAdvansedFilter2Val.Text;

Expand All @@ -213,12 +213,12 @@ private void AdvansedFilter()
bool use2val = advVal2 != string.Empty;

_spellList = (from spell in DBC.Spell.Values
where ( !bFamilyNames || spell.SpellFamilyName == fFamilyNames)
&& (!bSpellEffect || spell.Effect.ContainsElement((uint)fSpellEffect))
&& (!bSpellAura || spell.EffectApplyAuraName.ContainsElement((uint)fSpellAura))
&& (!bTarget1 || spell.EffectImplicitTargetA.ContainsElement((uint)fTarget1))
&& (!bTarget2 || spell.EffectImplicitTargetB.ContainsElement((uint)fTarget2))

where (!bFamilyNames || spell.SpellClassOptions.SpellFamilyName == fFamilyNames)
&& (!bSpellEffect || spell.HasSpellEffect(fSpellEffect))
&& (!bSpellAura || spell.HasSpellAura(fSpellAura))
&& (!bTarget1 || spell.HasSpellTargetA(fTarget1))
&& (!bTarget2 || spell.HasSpellTargetB(fTarget2))
&& (!use1val || spell.CreateFilter(field1, advVal1))
&& (!use2val || spell.CreateFilter(field2, advVal2))

Expand All @@ -227,7 +227,6 @@ private void AdvansedFilter()
_lvSpellList.VirtualListSize = _spellList.Count();
if (_lvSpellList.SelectedIndices.Count > 0)
_lvSpellList.Items[_lvSpellList.SelectedIndices[0]].Selected = false;

}

#endregion
Expand Down Expand Up @@ -315,13 +314,15 @@ private void SetProcAtribute(SpellEntry spell)
{
new SpellInfo(_rtbProcSpellInfo, spell);

_cbProcSpellFamilyTree.SelectedValue = spell.SpellFamilyName;
_clbProcFlags.SetCheckedItemFromFlag(spell.ProcFlags);
var classOptions = spell.SpellClassOptions;
_cbProcSpellFamilyTree.SelectedValue = classOptions.SpellFamilyName;
var auraOptions = spell.SpellAuraOptions;
_clbProcFlags.SetCheckedItemFromFlag(auraOptions.ProcFlags);
_clbSchools.SetCheckedItemFromFlag(spell.SchoolMask);
_cbProcFitstSpellFamily.SelectedValue = spell.SpellFamilyName;
_cbProcFitstSpellFamily.SelectedValue = classOptions.SpellFamilyName;
_tbPPM.Text = "0"; // need correct value
_tbChance.Text = spell.ProcChance.ToString();
_tbCooldown.Text = (spell.RecoveryTime / 1000f).ToString();
_tbChance.Text = auraOptions.ProcChance.ToString();
_tbCooldown.Text = (spell.SpellCooldowns.RecoveryTime / 1000f).ToString();
}

private void GetProcAttribute(SpellEntry spell)
Expand Down Expand Up @@ -375,11 +376,11 @@ private void ProcFilter()

_spellProcList = (from spell in DBC.Spell.Values

where (!bFamilyNames || spell.SpellFamilyName == fFamilyNames)
&& (!bSpellEffect || spell.Effect.ContainsElement((uint)fSpellEffect))
&& (!bSpellAura || spell.EffectApplyAuraName.Contains((uint)fSpellAura))
&& (!bTarget1 || spell.EffectImplicitTargetA.ContainsElement((uint)fTarget1))
&& (!bTarget2 || spell.EffectImplicitTargetB.ContainsElement((uint)fTarget2))
where (!bFamilyNames || spell.SpellClassOptions.SpellFamilyName == fFamilyNames)
&& (!bSpellEffect || spell.HasSpellEffect(fSpellEffect))
&& (!bSpellAura || spell.HasSpellAura(fSpellAura))
&& (!bTarget1 || spell.HasSpellTargetA(fTarget1))
&& (!bTarget2 || spell.HasSpellTargetB(fTarget2))

select spell).ToList();

Expand All @@ -398,8 +399,7 @@ private void FamilyTree_AfterCheck(object sender, TreeViewEventArgs e)
uint[] mask = ((TreeView)sender).GetMask();

var query = from Spell in DBC.Spell.Values
where Spell.SpellFamilyName == ProcInfo.SpellProc.SpellFamilyName
&& Spell.SpellFamilyFlags.ContainsElement(mask)
where Spell.SpellClassOptions.Match(ProcInfo.SpellProc.SpellClassOptions, mask)
join sk in DBC.SkillLineAbility on Spell.ID equals sk.Value.SpellId into temp1
from Skill in temp1.DefaultIfEmpty()
//join skl in DBC.SkillLine on Skill.Value.SkillId equals skl.Value.ID into temp2
Expand Down
10 changes: 5 additions & 5 deletions SpellWork/Forms/FormSearch.cs
Expand Up @@ -79,11 +79,11 @@ private void SpellFamily_SelectedIndexChanged(object sender, EventArgs e)

_spellList = (from spell in DBC.Spell.Values

where (!bFamilyNames || spell.SpellFamilyName == fFamilyNames)
&& (!bSpellEffect || spell.Effect.ContainsElement((uint)fSpellEffect))
&& (!bSpellAura || spell.EffectApplyAuraName.ContainsElement((uint)fSpellAura))
&& (!bTarget1 || spell.EffectImplicitTargetA.ContainsElement((uint)fTarget1))
&& (!bTarget2 || spell.EffectImplicitTargetB.ContainsElement((uint)fTarget2))
where (!bFamilyNames || spell.SpellClassOptions.SpellFamilyName == fFamilyNames)
&& (!bSpellEffect || spell.HasSpellEffect(fSpellEffect))
&& (!bSpellAura || spell.HasSpellAura(fSpellAura))
&& (!bTarget1 || spell.HasSpellTargetA(fTarget1))
&& (!bTarget2 || spell.HasSpellTargetB(fTarget2))

select spell).ToList();

Expand Down
81 changes: 47 additions & 34 deletions SpellWork/Loader.cs
@@ -1,53 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace SpellWork
{
class Loader
{
public Loader(bool thread)
public Loader()
{
DBC.Spell = DBCReader.ReadDBC<SpellEntry>(DBC.SpellStrings);

if (thread)
new Thread(RunOther).Start();
else
RunOther();

DBC.Locale = DetectedLocale;
}
DBC.Spell = DBCReader.ReadDBC<SpellEntry>(DBC.SpellStrings);
DBC.SpellEffect = DBCReader.ReadDBC<SpellEffectEntry>(null);

private void RunOther()
{
DBC.SkillLine = DBCReader.ReadDBC<SkillLineEntry>(DBC.SkillLineStrings);
DBC.SpellRange = DBCReader.ReadDBC<SpellRangeEntry>(DBC.SpellRangeStrings);
DBC.ScreenEffect = DBCReader.ReadDBC<ScreenEffectEntry>(DBC.ScreenEffectStrings);

DBC.SpellDuration = DBCReader.ReadDBC<SpellDurationEntry>(null);
DBC.SkillLineAbility = DBCReader.ReadDBC<SkillLineAbilityEntry>(null);
DBC.SpellRadius = DBCReader.ReadDBC<SpellRadiusEntry>(null);
DBC.SpellCastTimes = DBCReader.ReadDBC<SpellCastTimesEntry>(null);
// this is to speedup spelleffect lookups
foreach (var value in DBC.SpellEffect)
{
if (DBC.SpellEffects.ContainsKey(value.Value.EffectSpellId))
{
DBC.SpellEffects[value.Value.EffectSpellId].Add((int)value.Value.EffectIndex, value.Value);
}
else
{
Dictionary<int, SpellEffectEntry> temp = new Dictionary<int, SpellEffectEntry>(3);
DBC.SpellEffects.Add(value.Value.EffectSpellId, temp);
DBC.SpellEffects[value.Value.EffectSpellId].Add((int)value.Value.EffectIndex, value.Value);
}
}

DBC.SpellTargetRestrictions = DBCReader.ReadDBC<SpellTargetRestrictionsEntry>(null);
DBC.SpellAuraRestrictions = DBCReader.ReadDBC<SpellAuraRestrictionsEntry>(null);
DBC.SpellCooldowns = DBCReader.ReadDBC<SpellCooldownsEntry>(null);
DBC.SpellCategories = DBCReader.ReadDBC<SpellCategoriesEntry>(null);
DBC.SpellShapeshift = DBCReader.ReadDBC<SpellShapeshiftEntry>(null);
DBC.SpellAuraOptions = DBCReader.ReadDBC<SpellAuraOptionsEntry>(null);
DBC.SpellLevels = DBCReader.ReadDBC<SpellLevelsEntry>(null);
DBC.SpellClassOptions = DBCReader.ReadDBC<SpellClassOptionsEntry>(null);
DBC.SpellCastingRequirements = DBCReader.ReadDBC<SpellCastingRequirementsEntry>(null);
DBC.SpellPower = DBCReader.ReadDBC<SpellPowerEntry>(null);
DBC.SpellInterrupts = DBCReader.ReadDBC<SpellInterruptsEntry>(null);
DBC.SpellEquippedItems = DBCReader.ReadDBC<SpellEquippedItemsEntry>(null);
DBC.SpellDuration = DBCReader.ReadDBC<SpellDurationEntry>(null);
DBC.SkillLineAbility = DBCReader.ReadDBC<SkillLineAbilityEntry>(null);
DBC.SpellRadius = DBCReader.ReadDBC<SpellRadiusEntry>(null);
DBC.SpellCastTimes = DBCReader.ReadDBC<SpellCastTimesEntry>(null);

DBC.OverrideSpellData = DBCReader.ReadDBC<OverrideSpellDataEntry>(null);
DBC.OverrideSpellData = DBCReader.ReadDBC<OverrideSpellDataEntry>(null);
DBC.SkillLine = DBCReader.ReadDBC<SkillLineEntry>(DBC.SkillLineStrings);
DBC.SpellRange = DBCReader.ReadDBC<SpellRangeEntry>(DBC.SpellRangeStrings);
DBC.ScreenEffect = DBCReader.ReadDBC<ScreenEffectEntry>(DBC.ScreenEffectStrings);

DBC.Locale = DetectedLocale();
}

private LocalesDBC DetectedLocale
private LocalesDBC DetectedLocale()
{
get
byte locale = 0;
while (DBC.Spell[DBC.SPELL_ENTRY_FOR_DETECT_LOCALE].GetName(locale) == string.Empty)
{
byte locale = 0;
while (DBC.Spell[DBC.SPELL_ENTRY_FOR_DETECT_LOCALE].GetName(locale) == String.Empty)
{
++locale;
++locale;

if (locale >= DBC.MAX_DBC_LOCALE)
throw new SpellWorkException("Detected unknown locale index {0}", locale);
}
return (LocalesDBC)locale;
if (locale >= DBC.MAX_DBC_LOCALE)
throw new Exception("Detected unknown locale index " + locale);
}
return (LocalesDBC)locale;
}
}
}
37 changes: 8 additions & 29 deletions SpellWork/Program.cs
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;

namespace SpellWork
{
Expand All @@ -17,33 +14,15 @@ static void Main(string[] args)
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

if (!File.Exists(DBC.DBC_PATH + "Spell.dbc") ||
!File.Exists(DBC.DBC_PATH + "SpellRadius.dbc") ||
!File.Exists(DBC.DBC_PATH + "SpellRange.dbc") ||
!File.Exists(DBC.DBC_PATH + "SpellDuration.dbc") ||
!File.Exists(DBC.DBC_PATH + "SkillLineAbility.dbc") ||
!File.Exists(DBC.DBC_PATH + "SkillLine.dbc") ||
!File.Exists(DBC.DBC_PATH + "SpellCastTimes.dbc"))
try
{
MessageBox.Show(String.Format("Files not found:\r\n"
+ "{0}Spell.dbc\r\n"
+ "{0}SpellRadius.dbc\r\n"
+ "{0}SpellRange.dbc\r\n"
+ "{0}SpellDuration.dbc\r\n"
+ "{0}SkillLineAbility.dbc\r\n"
+ "{0}SkillLine.dbc\r\n"
+ "{0}SpellCastTimes.dbc\r\n",
DBC.DBC_PATH),
"SpellWork ERROR",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
Application.Exit();
return;
new Loader();
Application.Run(new FormMain());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "SpellWork Eroor!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

new Loader(!(args.Count() > 0 && args[0].ToLower() == "nothread"));

Application.Run(new FormMain());
}
}
}
}
4 changes: 2 additions & 2 deletions SpellWork/Spell/ProcInfo.cs
Expand Up @@ -16,7 +16,7 @@ public ProcInfo(TreeView familyTree, SpellFamilyNames spellfamily)
familyTree.Nodes.Clear();

var spells = from Spell in DBC.Spell
where Spell.Value.SpellFamilyName == (uint)spellfamily
where Spell.Value.SpellClassOptions.SpellFamilyName == (uint)spellfamily
join sk in DBC.SkillLineAbility on Spell.Key equals sk.Value.SpellId into temp1
from Skill in temp1.DefaultIfEmpty()
join skl in DBC.SkillLine on Skill.Value.SkillId equals skl.Key into temp2
Expand Down Expand Up @@ -81,7 +81,7 @@ select new
else
mask[2] = 1U << (node.Index - 64);

if ((spell.SpellFamilyFlags.ContainsElement(mask)))
if ((spell.SpellClassOptions.SpellFamilyFlags.ContainsElement(mask)))
{
TreeNode child = new TreeNode();
child = node.Nodes.Add(name.ToString());
Expand Down

0 comments on commit c0ca56c

Please sign in to comment.