Core/Scripts: Fixes ValidateSpellScripts, and type mismatch of parameters

This commit is contained in:
hondacrx
2018-01-13 23:17:54 -05:00
parent a96e26329f
commit bde833d452
4 changed files with 36 additions and 8 deletions
+1 -1
View File
@@ -1597,7 +1597,7 @@ namespace Game
uint count = 0; uint count = 0;
foreach (var script in spellScriptsStorage.ToList()) foreach (var script in spellScriptsStorage.KeyValueList)
{ {
SpellInfo spellEntry = Global.SpellMgr.GetSpellInfo(script.Key); SpellInfo spellEntry = Global.SpellMgr.GetSpellInfo(script.Key);
+28 -1
View File
@@ -99,7 +99,7 @@ namespace Game.Scripting
var constructors = type.GetConstructors(); var constructors = type.GetConstructors();
if (constructors.Length == 0) 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; continue;
} }
@@ -108,6 +108,33 @@ namespace Game.Scripting
var genericType = type; var genericType = type;
string name = type.Name; 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) switch (type.BaseType.Name)
{ {
case "SpellScript": case "SpellScript":
+5 -5
View File
@@ -74,8 +74,8 @@ namespace Scripts.Spells.Items
public const uint StrengthOfTheTaunkaHero = 71561; // +700 Strength public const uint StrengthOfTheTaunkaHero = 71561; // +700 Strength
//Defibrillate //Defibrillate
public const int GoblinJumperCablesFail = 8338; public const uint GoblinJumperCablesFail = 8338;
public const int GoblinJumperCablesXlFail = 23055; public const uint GoblinJumperCablesXlFail = 23055;
//Desperatedefense //Desperatedefense
public const uint DesperateRage = 33898; public const uint DesperateRage = 33898;
@@ -898,9 +898,9 @@ namespace Scripts.Spells.Items
// 8342 - Defibrillate (Goblin Jumper Cables) have 33% chance on success // 8342 - Defibrillate (Goblin Jumper Cables) have 33% chance on success
// 22999 - Defibrillate (Goblin Jumper Cables XL) have 50% chance on success // 22999 - Defibrillate (Goblin Jumper Cables XL) have 50% chance on success
// 54732 - Defibrillate (Gnomish Army Knife) have 67% 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", 33u, SpellIds.GoblinJumperCablesFail)]
[Script("spell_item_goblin_jumper_cables_xl", 50, SpellIds.GoblinJumperCablesXlFail)] [Script("spell_item_goblin_jumper_cables_xl", 50u, SpellIds.GoblinJumperCablesXlFail)]
[Script("spell_item_gnomish_army_knife", 67, 0)] [Script("spell_item_gnomish_army_knife", 67u, 0u)]
class spell_item_defibrillate : SpellScript class spell_item_defibrillate : SpellScript
{ {
public spell_item_defibrillate(uint chance, uint failSpell) public spell_item_defibrillate(uint chance, uint failSpell)
+2 -1
View File
@@ -289,7 +289,8 @@ namespace Scripts.Spells.Quest
[Script("spell_q11515_fel_siphon_dummy", SpellEffectName.Dummy, 0u, CreatureIds.FelbloodInitiate, CreatureIds.EmaciatedFelblood, true)] [Script("spell_q11515_fel_siphon_dummy", SpellEffectName.Dummy, 0u, CreatureIds.FelbloodInitiate, CreatureIds.EmaciatedFelblood, true)]
class spell_generic_quest_update_entry : SpellScript 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; _spellEffect = spellEffect;
_effIndex = (byte)effIndex; _effIndex = (byte)effIndex;