Skip to content

Commit

Permalink
Fix totem api on vanilla.
Browse files Browse the repository at this point in the history
  • Loading branch information
ratkosrb committed May 28, 2022
1 parent d5b5fe9 commit b2f9c1b
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 5 deletions.
96 changes: 96 additions & 0 deletions HermesProxy/CSV/TotemSpells.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
SpellId,TotemSlot
1535,0
3599,0
4971,0
5605,0
6274,0
6363,0
6364,0
6365,0
8181,0
8190,0
8227,0
8249,0
8264,0
8498,0
8499,0
10437,0
10438,0
10478,0
10479,0
10526,0
10585,0
10586,0
10587,0
11314,0
11315,0
11899,0
15038,0
15867,0
16387,0
18975,0
22047,0
23419,0
24309,0
27623,0
2484,1
5730,1
6390,1
6391,1
6392,1
8071,1
8075,1
8143,1
8154,1
8155,1
8160,1
8161,1
10406,1
10407,1
10408,1
10427,1
10428,1
10442,1
15786,1
23420,1
23789,1
25000,1
25361,1
5394,2
5675,2
6375,2
6377,2
8166,2
8170,2
8184,2
8262,2
10462,2
10463,2
10495,2
10496,2
10497,2
10537,2
10538,2
16190,2
17354,2
17359,2
23422,2
24854,2
6495,3
8177,3
8512,3
8835,3
10595,3
10600,3
10601,3
10613,3
10614,3
10627,3
15107,3
15111,3
15112,3
15787,3
23423,3
25359,3
25908,3
27621,3
16 changes: 16 additions & 0 deletions HermesProxy/World/Client/PacketHandlers/UpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,22 @@ public void StoreObjectUpdate(WowGuid128 guid, ObjectType objectType, BitArray u
if (UNIT_CREATED_BY_SPELL >= 0 && updateMaskArray[UNIT_CREATED_BY_SPELL])
{
updateData.UnitData.CreatedBySpell = updates[UNIT_CREATED_BY_SPELL].Int32Value;

if (LegacyVersion.RemovedInVersion(ClientVersionBuild.V2_0_1_6180) &&
isCreate && updateData.UnitData.CreatedBy == GetSession().GameState.CurrentPlayerGuid)
{
int totemSlot = GameData.GetTotemSlotForSpell((uint)updateData.UnitData.CreatedBySpell);
if (totemSlot >= 0)
{
TotemCreated totem = new();
totem.Slot = (byte)totemSlot;
totem.Totem = guid;
totem.Duration = 120000;
totem.SpellId = (uint)updateData.UnitData.CreatedBySpell;
totem.CannotDismiss = true;
SendPacketToClient(totem);
}
}
}
int UNIT_NPC_FLAGS = LegacyVersion.GetUpdateField(UnitField.UNIT_NPC_FLAGS);
if (UNIT_NPC_FLAGS >= 0 && updateMaskArray[UNIT_NPC_FLAGS])
Expand Down
37 changes: 37 additions & 0 deletions HermesProxy/World/GameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class GameData
public static Dictionary<uint, uint> ItemEnchantVisuals = new Dictionary<uint, uint>();
public static Dictionary<uint, uint> SpellVisuals = new Dictionary<uint, uint>();
public static Dictionary<uint, uint> LearnSpells = new Dictionary<uint, uint>();
public static Dictionary<uint, uint> TotemSpells = new Dictionary<uint, uint>();
public static Dictionary<uint, uint> Gems = new Dictionary<uint, uint>();
public static Dictionary<uint, float> UnitDisplayScales = new Dictionary<uint, float>();
public static Dictionary<uint, uint> TransportPeriods = new Dictionary<uint, uint>();
Expand Down Expand Up @@ -182,6 +183,14 @@ public static uint GetSpellVisual(uint spellId)
return 0;
}

public static int GetTotemSlotForSpell(uint spellId)
{
uint slot;
if (TotemSpells.TryGetValue(spellId, out slot))
return (int)slot;
return -1;
}

public static uint GetRealSpell(uint learnSpellId)
{
uint realSpellId;
Expand Down Expand Up @@ -301,6 +310,7 @@ public static void LoadEverything()
LoadItemEnchantVisuals();
LoadSpellVisuals();
LoadLearnSpells();
LoadTotemSpells();
LoadGems();
LoadUnitDisplayScales();
LoadTransports();
Expand Down Expand Up @@ -479,6 +489,33 @@ public static void LoadLearnSpells()
}
}

public static void LoadTotemSpells()
{
if (LegacyVersion.GetExpansionVersion() > 1)
return;

var path = Path.Combine("CSV", $"TotemSpells.csv");
using (TextFieldParser csvParser = new TextFieldParser(path))
{
csvParser.CommentTokens = new string[] { "#" };
csvParser.SetDelimiters(new string[] { "," });
csvParser.HasFieldsEnclosedInQuotes = false;

// Skip the row with the column names
csvParser.ReadLine();

while (!csvParser.EndOfData)
{
// Read current line fields, pointer moves to the next line.
string[] fields = csvParser.ReadFields();

uint spellId = UInt32.Parse(fields[0]);
uint totemSlot = UInt32.Parse(fields[1]);
TotemSpells.Add(spellId, totemSlot);
}
}
}

public static void LoadGems()
{
if (ModernVersion.GetExpansionVersion() <= 1)
Expand Down
11 changes: 6 additions & 5 deletions HermesProxy/World/Server/Packets/SpellPackets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1537,14 +1537,15 @@ public override void Write()
_worldPacket.WritePackedGuid128(Totem);
_worldPacket.WriteUInt32(Duration);
_worldPacket.WriteUInt32(SpellId);
_worldPacket.WriteUInt32(TimeMod);
_worldPacket.WriteBool(CannotDismiss);
_worldPacket.WriteFloat(TimeMod);
_worldPacket.WriteBit(CannotDismiss);
_worldPacket.FlushBits();
}
public byte Slot;
public WowGuid128 Totem;
public UInt32 Duration;
public UInt32 SpellId;
public UInt32 TimeMod = 1;
public uint Duration;
public uint SpellId;
public float TimeMod = 1;
public bool CannotDismiss = false;
}

Expand Down

0 comments on commit b2f9c1b

Please sign in to comment.