/// <summary> /// This function reads the passed in Assembly and parses all of the Omni Decorations out and makes them available in the engine. /// Used mainly for internal purposes. /// </summary> /// <param name="mAssembly"></param> /// <returns></returns> internal IndexingResult IndexAssembly(Assembly mAssembly) { IndexingResult iResult = new IndexingResult(); List <Type> classlist = mAssembly.GetTypes().ToList(); classlist.Sort((x, y) => String.CompareOrdinal(x.FullName, y.FullName)); List <CustomClassFunctDef> staticfunctions = new List <CustomClassFunctDef>(); foreach (Type c in classlist) { if (c.FullName != null && c.FullName.StartsWith(_mNameSpace + ".Models.User")) { CustomClassDef ccd = new CustomClassDef { mType = c, mClassName = c.FullName.ToLower(), mCtor = c.GetConstructor(new Type[] {}) }; #region Constructor check #if DEBUG ConstructorInfo ci; try { ci = c.GetConstructor(new Type[] {}); } catch (Exception) { throw new Exception("Class " + c.FullName + " does not have a empty constructor."); } ccd.mCtor = ci; #endif #endregion List <MethodInfo> miList = c.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).ToList(); miList.Sort((x, y) => String.CompareOrdinal(x.Name, y.Name)); foreach (MethodInfo mi in miList) { #region Process MethodInfo if (mi.IsStatic && !mi.IsSpecialName && isExposedFunction(mi)) { if (getAlias(mi) != "") { CustomClassFunctDef ccfd = new CustomClassFunctDef { mFunctName = getAlias(mi).ToLower(), mFunctPtr = mi }; staticfunctions.Add(ccfd); } else { CustomClassFunctDef ccfd = new CustomClassFunctDef { mFunctName = mi.Name.ToLower(), mFunctPtr = mi }; staticfunctions.Add(ccfd); } } else if (!mi.IsSpecialName && isExposedFunction(mi)) { if ((mi.GetBaseDefinition().DeclaringType != mi.DeclaringType) || (mi.GetBaseDefinition().DeclaringType.Namespace.StartsWith(_mNameSpace + ".Models.User"))) { if (getAlias(mi) != "") { CustomClassFunctDef ccfd = new CustomClassFunctDef { mFunctName = getAlias(mi).ToLower(), mFunctPtr = mi }; ccd.mFuncts.Add(getAlias(mi), ccfd); } else { CustomClassFunctDef ccfd = new CustomClassFunctDef { mFunctName = mi.Name.ToLower(), mFunctPtr = mi }; ccd.mFuncts.Add(ccfd.mFunctName, ccfd); } } } else if (!mi.IsSpecialName && isExposedSystemFunction(mi)) { if (!ccd.Allowedcallbacks.Contains(mi.Name.ToLower())) { ccd.Allowedcallbacks.Add(mi.Name.ToLower()); } } #endregion } //Don't add any empty classes to the dictionary. if (!ccd.mFuncts.Any() && !ccd.Allowedcallbacks.Any()) { continue; } MCustomClassDef.Add(ccd.mClassName, ccd); iResult.ClassesFound.Add(ccd.mClassName); } #if DEBUG else if (!c.FullName.StartsWith(_mNameSpace + ".Models.Base")) { Console.WriteLine("!!!WARNING!!!! Skipping C# Type : '" + c.FullName + "'."); } #endif } //}); //We are going to sort them to improve performance. staticfunctions.Sort((x, y) => String.CompareOrdinal(x.mFunctName, y.mFunctName)); foreach (CustomClassFunctDef ccfd in staticfunctions) { _mGlobalFuncts.Add(ccfd.mFunctName, ccfd); iResult.GlobalFunctsFound.Add(ccfd.mFunctName); } return(iResult); }
private void WLE_EngineCallBack(int simobjectid, int WLE_OMNI_ARRAY_POSTION, int argc, IntPtr argv, byte[] returnbuff) { ModelBase proxyobject = null; if (WLE_OMNI_ARRAY_POSTION == 0) { proxyobject = simobjectid; } else { proxyobject = _msimdict[WLE_OMNI_ARRAY_POSTION]; } string poName = proxyobject.GetType().FullName.ToLower(); if (MCustomClassDef.ContainsKey(poName)) { //This is where I will need to check if the class //blocks script calls, i.e. all calls made stop here //versus getting sent to the proxyobject.callscript function. CustomClassDef ccd = MCustomClassDef[poName]; string tfunction = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(argv, 0)).ToLower(); #region ScriptExtensions if (_ScriptExtensions_Allow) { List <xmlOverrideData> ovr = csFactory.Instance.GetMemberOverrides(proxyobject.GetType().FullName); foreach (xmlOverrideData xd in ovr) { foreach (CustomClassFunctDef ccfd in xd.FunctionOverrides) { if (ccfd.mFunctName.ToLower() != tfunction) { continue; } object[] parameters = new object[ccfd.MParams.Count()]; parameters[0] = myReflections.ChangeType(proxyobject.ID, ccfd.MParams[0].ParameterType); for (int i = 1; i < ccfd.MParams.Count(); i++) { parameters[i] = (i < argc - 1 ? myReflections.ChangeType(Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(argv, IntPtr.Size * (i + 1))), ccfd.MParams[i].ParameterType) : myReflections.ChangeType(string.Empty, ccfd.MParams[i].ParameterType)); } byte[] returnbytes1 = Encoding.ASCII.GetBytes(ccfd.CallFunction(proxyobject, parameters).ToString()); Buffer.BlockCopy(returnbytes1, 0, returnbuff, 0, returnbytes1.Length); returnbuff[returnbytes1.Length] = 0; return; } } } #endregion if (ccd.mFuncts.ContainsKey(tfunction)) { #if DEBUG if (Debugging) { self.Error("!!!!EngineCallBack!!!! " + proxyobject.getClassName() + " Calling CSHARP function '" + tfunction + "'."); } #endif CustomClassFunctDef ccfd = ccd.mFuncts[tfunction]; object[] parameters = new object[ccfd.MParams.Count()]; for (int i = 0; i < ccfd.MParams.Count(); i++) { parameters[i] = (i < argc - 2 ? myReflections.ChangeType(Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(argv, IntPtr.Size * (i + 2))), ccfd.MParams[i].ParameterType) : myReflections.ChangeType(string.Empty, ccfd.MParams[i].ParameterType)); } byte[] returnbytes1 = Encoding.ASCII.GetBytes(ccd.mFuncts[tfunction].CallFunction(proxyobject, parameters).ToString()); Buffer.BlockCopy(returnbytes1, 0, returnbuff, 0, returnbytes1.Length); returnbuff[returnbytes1.Length] = 0; return; } } string function = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(argv, 0)); if ((!proxyobject.OnFunctionNotFoundCallTorqueScript()) && !MCustomClassDef[poName].Allowedcallbacks.Contains(function.ToLower())) { return; } #region Debug #if DEBUG if (DebuggingShowScriptCalls) { self.Error("!!!!EngineCallBack!!!! " + proxyobject.getClassName() + " Calling TorqueScript function '" + function + "'."); } #endif #endregion List <string> myparams = new List <string>(20); for (int i = 2; i < argc; i++) { myparams.Add(Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(argv, IntPtr.Size * i))); } string returnObject = proxyobject.callScript(function, myparams.ToArray()); byte[] returnbytes = Encoding.ASCII.GetBytes(returnObject); Buffer.BlockCopy(returnbytes, 0, returnbuff, 0, returnbytes.Length); returnbuff[returnbytes.Length] = 0; }