1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Crash at Start

Discussion in 'Script Support' started by Joshua, Sep 12, 2017.

  1. Joshua
    Offline

    Platinum Donator

    Joined:
    Sep 13, 2014
    Messages:
    403
    Likes Received:
    16
    So.. I decided that it was time to test things out and delete the test save folder and let it regenerate. When I restarted the server I got this error.

    Code (C#):
    1. Loading Ultima Live map changes
    2. ...done (0 items, 0 mobiles, 0 customs) (0.05 seconds)
    3. Error:
    4. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Unable to cast object of type 'Server.Mobiles.Kevin' to type 'Server.Mobiles.PlayerMobile'.
    5.    at Server.Items.BaseWeapon.OnEquip(Mobile from)
    6.    at Server.Mobiles.BaseCreature.AddItem(Item item)
    7.    at Server.Mobiles.BaseVendor..ctor(String title)
    8.    at Server.Engines.Quests.HumilityQuestMobile..ctor(String name, String title)
    9.    at Server.Mobiles.Kevin..ctor()
    10.    at Server.Engines.Quests.HumilityShrinePersistence.SetupMobiles()
    11.    at Server.Engines.Quests.HumilityShrinePersistence.Initialize()
    12.    --- End of inner exception stack trace ---
    13.    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    14.    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    15.    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    16.    at Server.ScriptCompiler.Invoke(String method) in k:\AlfheimRebornServer\Ultima Server2\Server\ScriptCompiler.cs:line 667
    17.    at Server.Core.Main(String[] args) in k:\AlfheimRebornServer\Ultima Server2\Server\Main.cs:line 558
    18. This exception is fatal, press return to exit
    I've made no changes to the quest system however have made changes to basearmor/baseweapon/basecreature, I'm just not sure which change caused the fail.
     
  2. Joshua
    Offline

    Platinum Donator

    Joined:
    Sep 13, 2014
    Messages:
    403
    Likes Received:
    16
    I suspect this is something in baseweapon as i added onequip changes, and the kevin script equips a weapon
     
  3. Lokai
    Offline

    Moderator ServUO Developer

    Joined:
    Dec 4, 2014
    Messages:
    879
    Likes Received:
    135
    Post your "OnEquip(Mobile from)" method in BaseWeapon.

    My guess is that you cast from to PlayerMobile as if only a player might equip a weapon. While it is OK to assume this, you must then make a quick check to see if from actually IS a playermobile, and Stop the next part of the code if it is not.
     
    • Two Thumbs Up Two Thumbs Up x 1
  4. Joshua
    Offline

    Platinum Donator

    Joined:
    Sep 13, 2014
    Messages:
    403
    Likes Received:
    16
    Here is the requested snippit. I only assume its this , it does state the basearmor and others
    Code (C#):
    1.         public override bool OnEquip(Mobile from)
    2.         {
    3.             int strBonus = m_AosAttributes.BonusStr;
    4.             int dexBonus = m_AosAttributes.BonusDex;
    5.             int intBonus = m_AosAttributes.BonusInt;
    6.  
    7.             if ((strBonus != 0 || dexBonus != 0 || intBonus != 0))
    8.             {
    9.                 Mobile m = from;
    10.  
    11.                 string modName = Serial.ToString();
    12.  
    13.                 if (strBonus != 0)
    14.                 {
    15.                     m.AddStatMod(new StatMod(StatType.Str, modName + "Str", strBonus, TimeSpan.Zero));
    16.                 }
    17.  
    18.                 if (dexBonus != 0)
    19.                 {
    20.                     m.AddStatMod(new StatMod(StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero));
    21.                 }
    22.  
    23.                 if (intBonus != 0)
    24.                 {
    25.                     m.AddStatMod(new StatMod(StatType.Int, modName + "Int", intBonus, TimeSpan.Zero));
    26.                 }
    27.             }
    28.  
    29.             from.NextCombatTime = Core.TickCount + (int)GetDelay(from).TotalMilliseconds;
    30.  
    31.             if (UseSkillMod && m_AccuracyLevel != WeaponAccuracyLevel.Regular)
    32.             {
    33.                 if (m_SkillMod != null)
    34.                 {
    35.                     m_SkillMod.Remove();
    36.                 }
    37.  
    38.                 m_SkillMod = new DefaultSkillMod(AccuracySkill, true, (int)m_AccuracyLevel * 5);
    39.                 from.AddSkillMod(m_SkillMod);
    40.             }
    41.  
    42.             if (Core.AOS && m_AosWeaponAttributes.MageWeapon != 0 && m_AosWeaponAttributes.MageWeapon != 30)
    43.             {
    44.                 if (m_MageMod != null)
    45.                 {
    46.                     m_MageMod.Remove();
    47.                 }
    48.  
    49.                 m_MageMod = new DefaultSkillMod(SkillName.Magery, true, -30 + m_AosWeaponAttributes.MageWeapon);
    50.                 from.AddSkillMod(m_MageMod);
    51.             }
    52.  
    53.             if (Core.TOL)
    54.             {
    55.                 if ((m_ExtendedWeaponAttributes.MysticWeapon != 0 && m_ExtendedWeaponAttributes.MysticWeapon != 30) || Enhancement.GetValue(from, ExtendedWeaponAttribute.MysticWeapon) > 0)
    56.                     AddMysticMod(from);
    57.             }
    58.  
    59.             XmlAttach.CheckOnEquip(this, from);
    60.  
    61. //////CUSTOMIZATION - Alfheim Online!////// This is for Human Weapons.
    62.             var validTypeHumanWeapon1 = IsValidTypeHumanWeapon( this.GetType( ) );
    63.             if ( validTypeHumanWeapon1 )
    64.             {
    65.                 if ( from.Body == 0x190 || from.Body == 0x191)
    66.                 {
    67.                     PlayerMobile pm = (PlayerMobile)from;
    68.                     BaseWeapon weapon = (BaseWeapon)this;
    69.                     XmlSockets armorsockets = (XmlSockets)XmlAttach.FindAttachment(this, typeof(XmlSockets));
    70.                     XmlLevelItem levelitem = (XmlLevelItem)XmlAttach.FindAttachment(this, typeof(XmlLevelItem));
    71.                     XmlSocketable socketable = (XmlSocketable)XmlAttach.FindAttachment(this, typeof(XmlSocketable));
    72.                
    73.                     if (levelitem == null)
    74.                     {
    75.                         from.SendMessage( "The weapon starts to crave exp, it feels almost alive..." );
    76.                         levelitem = new XmlLevelItem();
    77.                         armorsockets = new XmlSockets(Utility.RandomMinMax(1, 4));
    78.                         socketable = new XmlSocketable(Utility.RandomMinMax(5, 10));
    79.                         XmlAttach.AttachTo(this, levelitem);
    80.                         XmlAttach.AttachTo(this, armorsockets);
    81.                         XmlAttach.AttachTo(this, socketable);
    82.                     //    armorsockets = new XmlSockets(Utility.RandomList(1, 2, 3, 4)));
    83.                     }
    84.                
    85.                     if (levelitem.Level > pm.Levell )
    86.                     {      
    87.                         from.SendMessage( "You Lack the Level to Equip this!" );
    88.                         return false;
    89.                     }
    90.                
    91.                     else
    92.                     {
    93.                         return true;
    94.                     }
    95.                 }
    96.                 else if ( from.Body != 0x190 || from.Body != 0x191)
    97.                 {
    98.                     from.SendMessage( "You can't figure out how to wield this stange human weapon..." );
    99.                     return false;
    100.                 }
    101.             }
    102.        
    103. //////CUSTOMIZATION - Alfheim Online!////// This is for Human Weapon. (( NO XML LEVEL ITEM!))  //////
    104.             var validTypeFairyWeaponNOXML1 = IsValidHumanWeaponTypesNoXML( this.GetType( ) );
    105.             if ( validTypeFairyWeaponNOXML1 )
    106.             {
    107.            
    108.                 if ( from.Body == 0x190 || from.Body == 0x191)
    109.                 {
    110.                     return true;
    111.                 }
    112.                 else if ( from.Body != 0x190 || from.Body != 0x191)
    113.                 {
    114.                     from.SendMessage( "You can't figure out how to equip this human weapon..." );
    115.                     return false;
    116.                 }
    117.             }
    118.        
    119.        
    120. //////CUSTOMIZATION - Alfheim Online!////// This is for Fairy Weapons.
    121.             var validTypeFairyWeapon1 = IsValidTypeFairyWeapon( this.GetType( ) );
    122.             if ( validTypeFairyWeapon1 )
    123.             {
    124.                 if ( from.Body == 0x29A || from.Body == 0x29B)
    125.                 {
    126.                     PlayerMobile pm = (PlayerMobile)from;
    127.                     XmlSockets armorsockets = (XmlSockets)XmlAttach.FindAttachment(this, typeof(XmlSockets));
    128.                     XmlLevelItem levelitem = (XmlLevelItem)XmlAttach.FindAttachment(this, typeof(XmlLevelItem));
    129.                     XmlSocketable socketable = (XmlSocketable)XmlAttach.FindAttachment(this, typeof(XmlSocketable));
    130.                
    131.                     if (levelitem == null)
    132.                     {
    133.                         from.SendMessage( "The weapon starts to crave exp, it feels almost alive..." );
    134.                         levelitem = new XmlLevelItem();
    135.                         armorsockets = new XmlSockets(Utility.RandomMinMax(1, 4));
    136.                         socketable = new XmlSocketable(Utility.RandomMinMax(5, 10));
    137.                         XmlAttach.AttachTo(this, levelitem);
    138.                         XmlAttach.AttachTo(this, armorsockets);
    139.                         XmlAttach.AttachTo(this, socketable);
    140.                     //    armorsockets = new XmlSockets(Utility.RandomList(1, 2, 3, 4)));
    141.                     }
    142.                
    143.                     if (levelitem.Level > pm.Levell )
    144.                     {      
    145.                         from.SendMessage( "You Lack the Level to Equip this!" );
    146.                         return false;
    147.                     }
    148.                     else
    149.                     {
    150.                         return true;
    151.                     }
    152.                 }
    153.                 else if ( from.Body != 0x29A || from.Body != 0x29B)
    154.                 {
    155.                     from.SendMessage( "You can't figure out how to wield this stange fairy weapon..." );
    156.                     return false;
    157.                 }
    158.             }
    159.        
    160. //////CUSTOMIZATION - Alfheim Online!////// This is for Fairy Weapon.  (( NO XML LEVEL ITEM ATTACHMENT!! ))
    161.             var validTypeFairyWeaponNOXML = IsValidFairyWeaponTypesNoXML( this.GetType( ) );
    162.             if ( validTypeFairyWeaponNOXML )
    163.             {
    164.                 if ( from.Body == 0x29A || from.Body == 0x29B)
    165.                 {
    166.                     return true;
    167.                 }
    168.                 else if ( from.Body != 0x29A || from.Body != 0x29B)
    169.                 {
    170.                     from.SendMessage( "You can't figure out how to equip this fairy weapon..." );
    171.                     return false;
    172.                 }
    173.             }
    174.        
    175.             return true;
    176.         }
    177.  
    178.         public override void OnAdded(object parent)
    179.         {
    180.             base.OnAdded(parent);
    181.  
    182.             if (parent is Mobile)
    183.             {
    184.                 Mobile from = (Mobile)parent;
    185.  
    186.                 if (Core.AOS)
    187.                 {
    188.                     m_AosSkillBonuses.AddTo(from);
    189.                 }
    190.  
    191.                 #region Mondain's Legacy Sets
    192.                 if (IsSetItem)
    193.                 {
    194.                     m_SetEquipped = SetHelper.FullSetEquipped(from, SetID, Pieces);
    195.  
    196.                     if (m_SetEquipped)
    197.                     {
    198.                         m_LastEquipped = true;
    199.                         SetHelper.AddSetBonus(from, SetID);
    200.                     }
    201.                 }
    202.                 #endregion
    203.  
    204.                 from.CheckStatTimers();
    205.                 from.Delta(MobileDelta.WeaponDamage);
    206.             }
    207.         }
    --- Double Post Merged, Sep 12, 2017 ---
    Here are the actual base scripts mentioned in that error.
    --- Double Post Merged, Sep 12, 2017 ---
    Took your suggestion and applied this code at the beginning of my custom onequip section.

    Code (C#):
    1.             if ( validTypeHumanWeapon1 )  
    2.             {
    3.                 if (from is PlayerMobile)
    4.                     return true;
    5.                 else
    6.                     return false;
    That allowed the humility mobs to generate. So that tells me... I have a lot of work to do with adding these checks because I'm sure this is not the only fail point.
     
    #4 Joshua, Sep 12, 2017
    Last edited: Sep 12, 2017
  5. Lokai
    Offline

    Moderator ServUO Developer

    Joined:
    Dec 4, 2014
    Messages:
    879
    Likes Received:
    135
    Here is the line I was referring to:

    Code (C#):
    1. PlayerMobile pm = (PlayerMobile)from;
    Like I said, this is fine, but what you did was an OK fix.

    In general, what you should do after you run this line is something like this:

    Code (C#):
    1. if (pm != null)
    2. {
    3.      //run your custom code....
    4. }
    5. // else don't run it...
    That way you won't run into a situation where something tries to reference a PlayerMobile where there was none to begin with. But, you are correct, if they are not supposed to wear it at all then you could return false if they are not a PlayerMobile. That would also prevent the bad code from getting called.
     
  6. Joshua
    Offline

    Platinum Donator

    Joined:
    Sep 13, 2014
    Messages:
    403
    Likes Received:
    16
    I ended up using this instead
    Code (C#):
    1. if ( validTypeHumanArmor && from is PlayerMobile )    
    Honestly It never occurred to me to do those checks.. in the older distro I'm coming from this wasn't an issue for some reason. It makes sense though, I have a lot of custom code that is open to this kind of problem as I have a lot of references to playermobile without checking to see if its actually a playermobile, likely they will never get hit by a non playermobile but why take the risk.
     
Similar Threads: Crash Start
Forum Title Date
ServUO Discussion server crash and restart Apr 27, 2017
Windows Support Crash at Start Aug 5, 2016
Script Support Server startup crash - invulnerable vendors May 14, 2014
Windows Support Server Startup Crash Feb 19, 2014
Mono Support Crashed - ServUO restarts constantly Feb 6, 2014
Archived Bug Reports Player crashing when entering same area Sep 10, 2017
Archived Bug Reports New PingListener can crash shards Sep 3, 2017