Exemple #1
0
        public static string CallScriptFunction(string pFunctionNamespace, string pFunctionName, object[] args,
                                                out bool found)
        {
            if (pFunctionNamespace != null)
            {
                ISimObject obj  = SimDictionary.Find(pFunctionNamespace);
                Type       type = GetObjectType(null, pFunctionNamespace, obj);

                if (type == null)
                {
                    found = false;
                    return(null);
                }

                return(CallNamespaceMethod(type, obj, pFunctionName, args, out found));
            }

            if (!FunctionDictionary.ContainsKey(pFunctionName))
            {
                found = false;
                return(null);
            }

            found = true;
            MethodInfo methodInfo = FunctionDictionary[pFunctionName];

            return(InvokeMethod(methodInfo, null, args, out found));
        }
Exemple #2
0
        public static IntPtr FindDataBlockPtrByName(string name)
        {
            SimObject obj = SimDictionary.Find <SimObject>(name);

            if (obj != null)
            {
                return(obj.ObjectPtr);
            }
            return(InternalUnsafeMethods.FindDataBlockByName(name));
        }
Exemple #3
0
        public static IntPtr FindObjectPtrById(uint id)
        {
            SimObject obj = SimDictionary.Find <SimObject>(id);

            if (obj != null)
            {
                return(obj.ObjectPtr);
            }
            return(InternalUnsafeMethods.FindObjectById(id));
        }
Exemple #4
0
        public static T FindObjectById <T>(uint id) where T : SimObject
        {
            IntPtr objPtr = InternalUnsafeMethods.FindObjectById(id);
            T      obj    = SimDictionary.Find <T>(id);

            if (obj != null && obj.ObjectPtr == objPtr)
            {
                return(obj);
            }
            obj = (T)FormatterServices.GetUninitializedObject(typeof(T));
            obj.SetPointer(objPtr);
            SimDictionary.RegisterObject(obj);
            return(obj);
        }
Exemple #5
0
        public static T FindObjectByName <T>(string name) where T : SimObject
        {
            T dictObj = SimDictionary.Find <T>(name);

            if (dictObj != null)
            {
                return(dictObj);
            }
            T obj = (T)FormatterServices.GetUninitializedObject(typeof(T));

            if (obj is SimDataBlock)
            {
                IntPtr objPtr = FindDataBlockPtrByName(name);
                if (objPtr == IntPtr.Zero)
                {
                    objPtr = FindObjectPtrByName(name);
                }
                if (objPtr == IntPtr.Zero)
                {
                    return(null);
                }
                obj.SetPointer(objPtr);
            }
            else
            {
                IntPtr objPtr = FindObjectPtrByName(name);
                if (objPtr == IntPtr.Zero)
                {
                    return(null);
                }
                obj.SetPointer(objPtr);
            }
            if (obj.ObjectPtr == IntPtr.Zero)
            {
                return(null);
            }
            SimDictionary.RegisterObject(obj);
            return(obj);
        }
Exemple #6
0
        public static Type GetObjectType(string className, string classNamespace, ISimObject objectBaseWrapper)
        {
            string objectName = objectBaseWrapper?.GetName();

            if (objectName != null && ClassTypeDictionary.ContainsKey(objectName))
            {
                return(ClassTypeDictionary[objectName]);
            }

            if (classNamespace != null && ClassTypeDictionary.ContainsKey(classNamespace))
            {
                return(ClassTypeDictionary[classNamespace]);
            }

            if (className != null && ClassTypeDictionary.ContainsKey(className))
            {
                return(ClassTypeDictionary[className]);
            }

            if (objectName != null && SimDictionary.Find(objectName) != null)
            {
                return(SimDictionary.Find(objectName).GetType());
            }

            if (objectBaseWrapper != null && SimDictionary.Find(objectBaseWrapper.GetId()) != null)
            {
                return(SimDictionary.Find(objectBaseWrapper.GetId()).GetType());
            }

            if (objectBaseWrapper != null && ClassTypeDictionary.ContainsKey(objectBaseWrapper.GetType().Name))
            {
                return(ClassTypeDictionary[objectBaseWrapper.GetType().Name]);
            }

            return(null);
        }