Beispiel #1
0
        public bool IPostPerform(IScriptLogic obj, bool postLoad)
        {
            if (obj is T)
            {
                try
                {
                    return(PostPerform(obj as T, postLoad));
                }
                catch (Exception e)
                {
                    Common.Exception(GetType().ToString(), e);
                }
            }

            return(false);
        }
Beispiel #2
0
        private IScriptLogic sc_try_create_Logic(string className)
        {
            if (className == null)
            {
                return(null);
            }

            IScriptLogic scriptLogic = null;

            foreach (Assembly assembly in NFinalizeDeath.GetAssemblies())
            {
                scriptLogic = (IScriptLogic)assembly.CreateInstance(className);
                if (scriptLogic != null)
                {
                    break;
                }
            }
            return(scriptLogic);
        }
Beispiel #3
0
        protected static string GetTaskName(ITask task)
        {
            string name = null;

            IScriptProxy proxy = task as IScriptProxy;

            if (proxy != null)
            {
                IScriptLogic logic = proxy.Target;
                if (logic != null)
                {
                    if (logic is Sim)
                    {
                        name = "Sim: " + (logic as Sim).FullName;
                    }
                    else if (logic is SimUpdate)
                    {
                        name = "SimUpdate: " + (logic as SimUpdate).mSim.FullName;
                    }
                }
            }

            string type = task.GetType().ToString();

            if (string.IsNullOrEmpty(name))
            {
                name = task.ToString();
            }

            if ((!string.IsNullOrEmpty(name)) && (name != type))
            {
                type += " (" + name + ")";
            }

            return(type);
        }
Beispiel #4
0
        protected override void Perform(GameObject obj, object referenceParent, FieldInfo field)
        {
            if (obj is Ocean)
            {
                if (LotManager.sOceanObject == obj)
                {
                    return;
                }
            }
            else if (obj is Terrain)
            {
                if (Terrain.sTerrain == obj)
                {
                    return;
                }
            }

            if (DereferenceManager.HasBeenDestroyed(obj))
            {
                if (obj is Sim)
                {
                    LotManager.sActorList.Remove(obj as Sim);

                    DereferenceManager.Perform(obj, ObjectLookup.GetReference(new ReferenceWrapper(obj)), true, false);
                }
                else
                {
                    GameObjectReference refObj = ObjectLookup.GetReference(new ReferenceWrapper(obj));
                    if (DereferenceManager.Perform(obj, refObj, false, false))
                    {
                        DereferenceManager.Perform(obj, refObj, true, false);

                        ErrorTrap.LogCorrection("Destroyed Object Found: " + obj.GetType());
                    }
                }
                return;
            }

            if (kShowFullReferencing)
            {
                DereferenceManager.Perform(obj, ObjectLookup.GetReference(new ReferenceWrapper(obj)), false, true);
            }

            if (obj.InWorld)
            {
                return;
            }

            if (obj.InInventory)
            {
                if (Inventories.ParentInventory(obj) == null)
                {
                    if ((obj.Parent != null) || (Consignment.ContainsKey(obj)))
                    {
                        obj.SetFlags(GameObject.FlagField.InInventory, false);

                        ErrorTrap.LogCorrection("Invalid Inventory Object Unflagged: " + obj.GetType());
                    }
                    else
                    {
                        ErrorTrap.LogCorrection("Invalid Inventory Object Found: " + obj.GetType());
                        ErrorTrap.AddToBeDeleted(obj, true);
                    }
                }

                return;
            }
            else
            {
                if (SharedInventories.ContainsKey(obj.ObjectId))
                {
                    obj.SetFlags(GameObject.FlagField.InInventory, true);

                    ErrorTrap.LogCorrection("Inventory Object Flagged: " + obj.GetType());
                    return;
                }
            }

            if (EventItems.ContainsKey(obj.ObjectId))
            {
                return;
            }

            bool hasParent = false;

            IGameObject parent = obj.Parent;

            while (parent != null)
            {
                hasParent = true;

                if (DereferenceManager.HasBeenDestroyed(parent))
                {
                    ErrorTrap.LogCorrection("Destroyed Parent Object Found: " + parent.GetType());
                    ErrorTrap.AddToBeDeleted(obj, true);

                    hasParent = false;
                    break;
                }

                parent = parent.Parent;
            }

            if (!hasParent)
            {
                ReferenceWrapper refObj = new ReferenceWrapper(obj);

                GameObjectReference reference = ObjectLookup.GetReference(refObj);
                if ((reference != null) && (reference.HasReferences))
                {
                    if (DereferenceManager.Perform(obj, ObjectLookup.GetReference(refObj), false, false))
                    {
                        IScriptProxy proxy = Simulator.GetProxy(obj.ObjectId);
                        if (proxy != null)
                        {
                            IScriptLogic logic = proxy.Target;
                            if (object.ReferenceEquals(logic, obj))
                            {
                                bool log = !sSilentDestroy.ContainsKey(obj.GetType());

                                if (log)
                                {
                                    ErrorTrap.LogCorrection("Out of World Object Found 2: " + obj.GetType());
                                }
                                else
                                {
                                    ErrorTrap.DebugLogCorrection("Out of World Object Found 3: " + obj.GetType());
                                }

                                ErrorTrap.AddToBeDeleted(obj, log);
                            }
                            else
                            {
                                ErrorTrap.DebugLogCorrection("Out of World Object Found 4: " + obj.GetType());
                                ErrorTrap.DebugLogCorrection("Out of World Object Found 5: " + logic.GetType());
                            }
                        }
                        else
                        {
                            DereferenceManager.Perform(obj, ObjectLookup.GetReference(refObj), true, false);
                        }
                    }
                }
                else
                {
                    ErrorTrap.LogCorrection("Out of World Object Found 1: " + obj.GetType());
                    ErrorTrap.AddToBeDeleted(obj, true);
                }
            }
        }
Beispiel #5
0
        public static void OnScriptError(ScriptCore.ScriptProxy proxy, Exception exception)
        {
            try
            {
                using (TestSpan span = new TestSpan(TimeSpanLogger.Bin, "OnScriptError", DebuggingLevel))
                {
                    bool fullReset = true;

                    bool record = !IgnoreList.IsIgnored(exception, out fullReset);

                    IScriptLogic target = null;
                    if (proxy != null)
                    {
                        target = proxy.Target;
                    }

                    StringBuilder noticeText = new StringBuilder();
                    StringBuilder logText    = new StringBuilder();

                    SimUpdate update = target as SimUpdate;
                    if (update != null)
                    {
                        target = update.mSim;
                    }
                    else
                    {
                        AutonomyManager autonomy = target as AutonomyManager;
                        if (autonomy != null)
                        {
                            target = SearchForAutonomy(exception.StackTrace);
                        }
                        else
                        {
                            Services services = target as Services;
                            if (services != null)
                            {
                                target = SearchForAssignedSim(exception.StackTrace);
                            }
                        }
                    }

                    SimDescription targetSim = SearchForSim(exception.StackTrace);
                    if (targetSim != null)
                    {
                        new FixInvisibleTask(targetSim).AddToSimulator();
                    }

                    IGameObject obj = null;

                    if (targetSim != null)
                    {
                        obj = ScriptCoreLogger.Convert(targetSim, noticeText, logText);
                    }
                    else
                    {
                        obj = ScriptCoreLogger.Convert(target, noticeText, logText);
                        if (obj == null)
                        {
                            obj = target as IGameObject;
                        }
                    }

                    ObjectGuid id       = ObjectGuid.InvalidObjectGuid;
                    bool       moonDial = false;
                    if (obj != null)
                    {
                        id = obj.ObjectId;

                        moonDial = obj.GetType() == typeof(Sims3.Gameplay.Objects.Decorations.MoonDial);

                        if (moonDial)
                        {
                            record = false;
                        }
                    }

                    if (record)
                    {
                        ScriptCoreLogger.Append(noticeText, logText, id, ObjectGuid.InvalidObjectGuid, exception, sAlreadyCaught);
                    }

                    /* do not use else if here */
                    if ((proxy != null) && (proxy.Target is RoleManagerTask))
                    {
                        new CheckRoleManagerTask().Perform(proxy.Target as RoleManagerTask, true);
                    }

                    Sim simObj = obj as Sim;
                    if (simObj != null)
                    {
                        try
                        {
                            if (simObj.Household == null)
                            {
                                fullReset = true;
                            }

                            if ((!fullReset) && (proxy != null))
                            {
                                proxy.OnReset();
                            }
                        }
                        catch (Exception e)
                        {
                            Common.Exception(proxy.Target, null, "PartialReset", e);
                            fullReset = true;
                        }

                        if (fullReset)
                        {
                            if (update != null)
                            {
                                try
                                {
                                    Simulator.DestroyObject(update.Proxy.ObjectId);
                                }
                                catch
                                { }
                            }

                            new ResetSimTask(simObj);
                            return;
                        }
                    }
                    else if (proxy != null && !moonDial)
                    {
                        proxy.OnReset();
                    }
                }
            }
            catch (Exception e)
            {
                Exception(proxy.Target, e);
            }
        }
Beispiel #6
0
        internal bool sc_set_logic(IScriptLogic obj, bool postLoad)
        {
            if (__dontcall)
            {
                return(true);
            }

            var _this = (ScriptCore.ScriptProxy)(object) this;

            try
            {
                _this.mTarget       = obj;
                _this.mTarget.Proxy = _this;

                try
                {
#if ENDBLE_SCTESTINGERRORAddNRaasErrorTrap
                    if (ScriptCore.ExceptionTrap.OnPrePostLoad != null)
                    {
                        ScriptCore.ExceptionTrap.OnPrePostLoad(_this, _this.mTarget, postLoad);
                    }
#endif
#if ENDBLE_SCTESTINGERRORAddNRaasErrorTrap
                    try
#endif
                    {
                        if (mInit != null)
                        {
                            _this.mExecuteType = (ScriptExecuteType)mInit.Invoke(_this.mTarget, new object[1]
                            {
                                postLoad
                            });
                        }
                        else
                        {
                            _this.mExecuteType = _this.mTarget.Init(postLoad);
                        }
                    }

#if ENDBLE_SCTESTINGERRORAddNRaasErrorTrap
                    finally
                    {
                        if (ScriptCore.ExceptionTrap.OnPostPostLoad != null)
                        {
                            ScriptCore.ExceptionTrap.OnPostPostLoad(_this, _this.mTarget, postLoad);
                        }
                    }
#endif
                }
                catch (ResetException)
                {
                    _this.mExecuteType = ScriptExecuteType.InitFailed;
                }
#if ENDBLE_SCTESTINGERRORAddNRaasErrorTrap
                ScriptCore.ExceptionTrap.Notify(new object[3]
                {
                    "ScriptProxy:SetLogic",
                    _this.mExecuteType,
                    _this.mTarget
                });
#endif
                if (_this.mExecuteType == ScriptExecuteType.InitFailed)
                {
                    _this.mExecuteType = ScriptExecuteType.Threaded;
                }
                if (_this.mExecuteType == ScriptExecuteType.None)
                {
                    _this.mExecuteType = ScriptExecuteType.Threaded;
                }
            }
            catch (StackOverflowException e2)
            {
                if (Sims3.SimIFace.Simulator.CheckYieldingContext(false))
                {
                    throw;
                }
                try
                {
                    _this.OnScriptError(e2);
                }
                catch (StackOverflowException)
                {
                    throw;
                }
                catch (Exception)
                { }
            }
            catch (Exception e)
            {
                try
                {
                    _this.OnScriptError(e.InnerException ?? e);
                }
                catch (Exception)
                { }
                if (_this.mExecuteType == ScriptExecuteType.None)
                {
                    _this.mExecuteType = ScriptExecuteType.Threaded;
                }
            }
            return(true);
        }
Beispiel #7
0
        public bool sc_create_Logic(string className)
        {
            if (__dontcall)
            {
                return(true);
            }

            var _this = (ScriptCore.ScriptProxy)(object) this;

            if (_this.mTarget != null)
            {
                return(true);
            }

            string p = null;

            try
            {
                className = ScriptCore.ScriptProxy.SubstituteClass(className);
                if (className == null)
                {
                    return(false);
                }
                p = className;
                IScriptLogic scriptLogic = _this.TryCreateLogic(className);
                if (scriptLogic == null)
                {
                    string text = ScriptCore.ScriptProxy.CreateLogicFailureName(className);
                    if (text != null)
                    {
                        scriptLogic = _this.TryCreateLogic(text);
                        if (scriptLogic == null)
                        {
                            throw new NullReferenceException("--- ERROR:  Unable to create failure logic '" + text + "'. ---");
                        }
                    }
                    if (scriptLogic == null)
                    {
                        throw new NullReferenceException("--- ERROR:  Unable to create logic type '" + className + "'. ---");
                    }
                }
                return(_this.SetLogic(scriptLogic, false));
            }
            catch
            {
                if (p != null)
                {
                    try
                    {
                        Type tpye = null;
                        foreach (Assembly assembly in NFinalizeDeath.GetAssemblies())
                        {
                            tpye = assembly.GetType(p, false);
                            if (tpye != null)
                            {
                                break;
                            }
                        }
                        if (tpye == null)
                        {
                            throw new NullReferenceException("--- ERROR:  Could not find Class Name. ---");
                        }
                        var constructor = tpye.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, CallingConventions.Any, new Type[0], null);
                        if (constructor == null)
                        {
                            throw new NullReferenceException("--- ERROR:  Could not find Constructor ctor() of " + tpye.FullName);
                        }
                        IScriptLogic s = (IScriptLogic)constructor.Invoke(null);
                        if (s == null)
                        {
                            throw new NullReferenceException("--- ERROR:  Failed to create IScriptLogic TypeName: '" + tpye.FullName + "'. ---");
                        }
                        return(_this.SetLogic(s, false));
                    }
                    catch (Exception)
                    { }
                }
                return(true);
            }
        }