From bde833d4524a40ca0f8b09b10473c29ba6622f6a Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sat, 13 Jan 2018 23:17:54 -0500 Subject: [PATCH] Core/Scripts: Fixes ValidateSpellScripts, and type mismatch of parameters --- Source/Game/Globals/ObjectManager.cs | 2 +- Source/Game/Scripting/ScriptManager.cs | 29 +++++++++++++++++++++++++- Source/Scripts/Spells/Items.cs | 10 ++++----- Source/Scripts/Spells/Quest.cs | 3 ++- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index f1b47b4fd..fdcf7752e 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -1597,7 +1597,7 @@ namespace Game uint count = 0; - foreach (var script in spellScriptsStorage.ToList()) + foreach (var script in spellScriptsStorage.KeyValueList) { SpellInfo spellEntry = Global.SpellMgr.GetSpellInfo(script.Key); diff --git a/Source/Game/Scripting/ScriptManager.cs b/Source/Game/Scripting/ScriptManager.cs index ed5dd7345..e1c4c11be 100644 --- a/Source/Game/Scripting/ScriptManager.cs +++ b/Source/Game/Scripting/ScriptManager.cs @@ -99,7 +99,7 @@ namespace Game.Scripting var constructors = type.GetConstructors(); if (constructors.Length == 0) { - Log.outError(LogFilter.Scripts, "Type: {0} contains no Public Constructors. Can't load script.", type.Name); + Log.outError(LogFilter.Scripts, "Script: {0} contains no Public Constructors. Can't load script.", type.Name); continue; } @@ -108,6 +108,33 @@ namespace Game.Scripting var genericType = type; string name = type.Name; + bool validArgs = true; + int i = 0; + foreach (var constructor in constructors) + { + var parameters = constructor.GetParameters(); + if (parameters.Length != attribute.Args.Length) + continue; + + foreach (var arg in constructor.GetParameters()) + { + if (arg.ParameterType != attribute.Args[i++].GetType()) + { + validArgs = false; + break; + } + } + + if (validArgs) + break; + } + + if (!validArgs) + { + Log.outError(LogFilter.Scripts, "Script: {0} contains no Public Constructors with the right parameter types. Can't load script.", type.Name); + continue; + } + switch (type.BaseType.Name) { case "SpellScript": diff --git a/Source/Scripts/Spells/Items.cs b/Source/Scripts/Spells/Items.cs index 9c97ba7e2..b5005efc0 100644 --- a/Source/Scripts/Spells/Items.cs +++ b/Source/Scripts/Spells/Items.cs @@ -74,8 +74,8 @@ namespace Scripts.Spells.Items public const uint StrengthOfTheTaunkaHero = 71561; // +700 Strength //Defibrillate - public const int GoblinJumperCablesFail = 8338; - public const int GoblinJumperCablesXlFail = 23055; + public const uint GoblinJumperCablesFail = 8338; + public const uint GoblinJumperCablesXlFail = 23055; //Desperatedefense public const uint DesperateRage = 33898; @@ -898,9 +898,9 @@ namespace Scripts.Spells.Items // 8342 - Defibrillate (Goblin Jumper Cables) have 33% chance on success // 22999 - Defibrillate (Goblin Jumper Cables XL) have 50% chance on success // 54732 - Defibrillate (Gnomish Army Knife) have 67% chance on success - [Script("spell_item_goblin_jumper_cables", 33, SpellIds.GoblinJumperCablesFail)] - [Script("spell_item_goblin_jumper_cables_xl", 50, SpellIds.GoblinJumperCablesXlFail)] - [Script("spell_item_gnomish_army_knife", 67, 0)] + [Script("spell_item_goblin_jumper_cables", 33u, SpellIds.GoblinJumperCablesFail)] + [Script("spell_item_goblin_jumper_cables_xl", 50u, SpellIds.GoblinJumperCablesXlFail)] + [Script("spell_item_gnomish_army_knife", 67u, 0u)] class spell_item_defibrillate : SpellScript { public spell_item_defibrillate(uint chance, uint failSpell) diff --git a/Source/Scripts/Spells/Quest.cs b/Source/Scripts/Spells/Quest.cs index e4f6c26b6..c3f2b9b46 100644 --- a/Source/Scripts/Spells/Quest.cs +++ b/Source/Scripts/Spells/Quest.cs @@ -289,7 +289,8 @@ namespace Scripts.Spells.Quest [Script("spell_q11515_fel_siphon_dummy", SpellEffectName.Dummy, 0u, CreatureIds.FelbloodInitiate, CreatureIds.EmaciatedFelblood, true)] class spell_generic_quest_update_entry : SpellScript { - public spell_generic_quest_update_entry(SpellEffectName spellEffect, uint effIndex, uint originalEntry, uint newEntry, bool shouldAttack, uint despawnTime = 0) + public spell_generic_quest_update_entry(SpellEffectName spellEffect, uint effIndex, uint originalEntry, uint newEntry, bool shouldAttack) : this(spellEffect, effIndex, originalEntry, newEntry, shouldAttack, 0) { } + public spell_generic_quest_update_entry(SpellEffectName spellEffect, uint effIndex, uint originalEntry, uint newEntry, bool shouldAttack, uint despawnTime) { _spellEffect = spellEffect; _effIndex = (byte)effIndex;