private static string CallNamespaceMethod(Type namespaceClass, ISimObject objectBaseWrapper, string methodName, object[] args, out bool found) { // TODO: Ensure callbackMethod is most recent override of method. (e.g. GameConnection re-defining delete) MethodInfo callbackMethod = namespaceClass .GetMethods(bindingFlags) .FirstOrDefault(x => x.Name.ToLowerInvariant().Equals(methodName.ToLowerInvariant())); if (callbackMethod != null) { ISimObject simObj = null; if (!callbackMethod.IsStatic) { simObj = (ISimObject)SimDictionary.CreateInstance(namespaceClass, objectBaseWrapper); } return(InvokeMethod(callbackMethod, simObj, args, out found)); } found = false; return(null); }
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); }
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); }
public static void Initialize(string[] args, Libraries libraryNames) { DllLoadUtils = Platform.IsLinux() ? (IDllLoadUtils) new DllLoadUtilsLinux() : new DllLoadUtilsWindows(); string platformMain; if (Platform.IsLinux()) { //platformMain = "torque_unixmain"; platformMain = "TorqueMain"; LibraryName = IntPtr.Size == 8 ? libraryNames.Linux64bit : libraryNames.Linux32bit; } else if (Platform.IsOSX()) { //platformMain = "torque_macmain"; platformMain = "TorqueMain"; LibraryName = IntPtr.Size == 8 ? libraryNames.OSX64bit : libraryNames.OSX32bit; } else { //platformMain = "torque_winmain"; platformMain = "TorqueMain"; LibraryName = IntPtr.Size == 8 ? libraryNames.Windows64bit : libraryNames.Windows32bit; } Torque3DLibHandle = DllLoadUtils.LoadLibrary(LibraryName); if (Torque3DLibHandle == IntPtr.Zero) { throw new Exception("Unable to load " + (IntPtr.Size == 8 ? "64" : "32") + " bit dll: " + LibraryName + ", in directory: " + Directory.GetCurrentDirectory()); } var mainHandle = DllLoadUtils.GetProcAddress(Torque3DLibHandle, platformMain); var setCallbacksHandle = DllLoadUtils.GetProcAddress(Torque3DLibHandle, "SetCallbacks"); var engineInitHandle = DllLoadUtils.GetProcAddress(Torque3DLibHandle, "torque_engineinit"); var engineTickHandle = DllLoadUtils.GetProcAddress(Torque3DLibHandle, "torque_enginetick"); var getReturnStatusHandle = DllLoadUtils.GetProcAddress(Torque3DLibHandle, "torque_getreturnstatus"); var engineShutdownHandle = DllLoadUtils.GetProcAddress(Torque3DLibHandle, "torque_engineshutdown"); var setCallbacks = (SetCallbacks)Marshal.GetDelegateForFunctionPointer( setCallbacksHandle, typeof(SetCallbacks)); //var main = (TorqueMain)Marshal.GetDelegateForFunctionPointer( // mainHandle, typeof(TorqueMain)); var engineInit = (torque_engineinit)Marshal.GetDelegateForFunctionPointer( engineInitHandle, typeof(torque_engineinit)); var engineTick = (torque_enginetick)Marshal.GetDelegateForFunctionPointer( engineTickHandle, typeof(torque_enginetick)); //var engineGetReturnStatus = (torque_getreturnstatus)Marshal.GetDelegateForFunctionPointer( // getReturnStatusHandle, typeof(torque_getreturnstatus)); var engineShutdown = (torque_engineshutdown)Marshal.GetDelegateForFunctionPointer( engineShutdownHandle, typeof(torque_engineshutdown)); CallFunction callDelegate = CallFunctionDelegate; CallMethod methodDelegate = CallMethodDelegate; IsMethod isMethodDelegate = IsMethodDelegate; IntPtr mainEntryPointPtr = IntPtr.Zero; if (Initializer.GetScriptEntry() != null) { mainEntryPointPtr = Marshal.GetFunctionPointerForDelegate( (MainEntryPoint)Initializer.GetScriptEntry().CreateDelegate(typeof(MainEntryPoint))); } setCallbacks(Marshal.GetFunctionPointerForDelegate(callDelegate) , Marshal.GetFunctionPointerForDelegate(methodDelegate) , Marshal.GetFunctionPointerForDelegate(isMethodDelegate) , mainEntryPointPtr); if (!engineInit(args.Length, args)) { return; } while (engineTick() > 0) { } engineShutdown(); SimDictionary.Shutdown(); DllLoadUtils.FreeLibrary(Torque3DLibHandle); }