public void ApiTypeLS(IScriptApi api) { if (!(api is ILS_Api)) return; m_LS_Functions = (ILS_Api)api; }
public void ApiTypeAA(IScriptApi api) { if (!(api is IAA_Api)) return; m_AA_Functions = (IAA_Api)api; }
public void ApiTypeMOD(IScriptApi api) { if (!(api is IMOD_Api)) return; m_MOD_Functions = (IMOD_Api)api; }
public void ApiTypebot(IScriptApi api) { if (!(api is IBot_Api)) return; m_Bot_Functions = (IBot_Api)api; }
/// <summary>APIの設定を用いてインスタンスを初期化します。 </summary> /// <param name="api">IronPython用APIの何らかの実装</param> /// <param name="setting">更新処理の設定</param> /// <param name="dictionary">キャラに対応するグローバル変数用にディクショナリ</param> public IronPythonUpdateProcessor(IScriptApi api, IScriptUpdateSetting setting, PythonDictionary dictionary) { _setting = setting; var engine = Python.CreateEngine(); //名前参照にexeのディレクトリとキャラのディレクトリを追加 var paths = engine.GetSearchPaths(); paths.Add(Environment.CurrentDirectory); paths.Add(DirectoryNames.GetCharacterScriptDirectory(api.CharacterName)); engine.SetSearchPaths(paths); //可視領域を限界まで広く取るためビルトインスコープにぶち込んでおく ScriptScope builtin = engine.GetBuiltinModule(); builtin.SetVariable(IronPythonCommonVariableNames.ApiVariableName, api); builtin.SetVariable(IronPythonCommonVariableNames.ApiGlobalDictionaryName, dictionary); string path = Path.Combine(DirectoryNames.GetCharacterScriptDirectory(api.CharacterName), UpdateScriptName); //高スピードで読むので先にコンパイル try { _updateCode = engine.CreateScriptSourceFromFile(path).Compile(); IsValid = true; } catch (Exception) { IsValid = false; } }
public void InitApi(IScriptApi data) { /*ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject); * if (lease != null) * lease.Register(m_sponser);*/ m_apis.Add(data.Name, data); }
public void ApiTypeCM(IScriptApi api) { if (!(api is ICM_Api)) return; m_CM_Functions = (ICM_Api)api; }
/// <summary> /// Initializes a new instance of the <see cref="MoveUseItemEventFactory"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="scriptFactory">A reference to the script factory.</param> public MoveUseItemEventFactory(ILogger logger, IScriptApi scriptFactory) { logger.ThrowIfNull(nameof(logger)); scriptFactory.ThrowIfNull(nameof(scriptFactory)); this.Logger = logger; this.ScriptFactory = scriptFactory; }
public void ApiTypeCM(IScriptApi api) { if (!(api is ICM_Api)) { return; } m_CM_Functions = (ICM_Api)api; }
public void ApiTypeMOD(IScriptApi api) { if (!(api is IMOD_Api)) { return; } m_MOD_Functions = (IMOD_Api)api; }
public void ApiTypeLS(IScriptApi api) { if (!(api is ILS_Api)) { return; } m_LS_Functions = (ILS_Api)api; }
private void InitScriptApi(Yengine engine, string api, IScriptApi scriptApi) { // Set up m_ApiManager_<APINAME> = instance pointer. engine.m_XMRInstanceApiCtxFieldInfos[api].SetValue(this, scriptApi); // Initialize the API instance. scriptApi.Initialize(m_Engine, m_Part, m_Item); this.InitApi(api, scriptApi); }
public void ApiTypeOSSL(IScriptApi api) { if (!(api is IOSSL_Api)) return; m_OSSL_Functions = (IOSSL_Api)api; Prim = new OSSLPrim(this); }
/// <summary> /// Initializes a new instance of the <see cref="MoveUseScriptApiAdapter"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="scriptApi">A reference to the script api in use.</param> public MoveUseScriptApiAdapter( ILogger logger, IScriptApi scriptApi) { logger.ThrowIfNull(nameof(logger)); scriptApi.ThrowIfNull(nameof(scriptApi)); this.Logger = logger.ForContext <MoveUseScriptApiAdapter>(); this.ScriptApi = scriptApi; }
public IScriptApi CreateApi(string api) { if (!m_Apis.ContainsKey(api)) { return(null); } IScriptApi ret = (IScriptApi)(Activator.CreateInstance(m_Apis[api])); return(ret); }
public void ApiTypeOSSL(IScriptApi api) { if (!(api is IOSSL_Api)) { return; } m_OSSL_Functions = (IOSSL_Api)api; Prim = new OSSLPrim(this); }
/// <summary> /// Initializes a new instance of the <see cref="CollisionEventRule"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="scriptFactory">A reference to the script factory in use.</param> /// <param name="conditionSet">The conditions for this event.</param> /// <param name="actionSet">The actions of this event.</param> public CollisionEventRule(ILogger logger, IScriptApi scriptFactory, IList <string> conditionSet, IList <string> actionSet) : base(logger, scriptFactory, conditionSet, actionSet) { var isTypeCondition = this.Conditions.FirstOrDefault(func => IsTypeFunctionName.Equals(func.FunctionName)); if (isTypeCondition == null) { throw new ArgumentNullException($"Unable to find {IsTypeFunctionName} function."); } this.ThingIdOfCollision = Convert.ToUInt16(isTypeCondition.Parameters[1]); }
/// <summary> /// Initializes a new instance of the <see cref="MoveUseEventRulesLoader"/> class. /// </summary> /// <param name="logger">A reference to the logger instance.</param> /// <param name="options">The options for this loader.</param> /// <param name="scriptFactory">A reference to the script factory in use.</param> public MoveUseEventRulesLoader( ILogger logger, IOptions <MoveUseEventRulesLoaderOptions> options, IScriptApi scriptFactory) { logger.ThrowIfNull(nameof(logger)); options.ThrowIfNull(nameof(options)); scriptFactory.ThrowIfNull(nameof(scriptFactory)); this.LoaderOptions = options.Value; this.Logger = logger.ForContext <MoveUseEventRulesLoader>(); this.ItemEventFactory = new MoveUseItemEventFactory(logger, scriptFactory); }
/// <summary> /// Initializes a new instance of the <see cref="MoveUseEventRule"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="scriptApi">A reference to the script factory in use.</param> /// <param name="conditionSet">The conditions for this event.</param> /// <param name="actionSet">The actions of this event.</param> public MoveUseEventRule(ILogger logger, IScriptApi scriptApi, IList <string> conditionSet, IList <string> actionSet) { logger.ThrowIfNull(nameof(logger)); scriptApi.ThrowIfNull(nameof(scriptApi)); this.ScriptFactory = scriptApi; this.Logger = logger.ForContext(this.GetType()); this.Conditions = this.ParseRules(conditionSet); this.Actions = this.ParseRules(actionSet); this.Adapter = new MoveUseScriptApiAdapter(logger, scriptApi); this.isSetup = false; }
public void InitApi(string api, IScriptApi data) { if (!inits.ContainsKey(api)) { return; } MethodInfo mi = inits[api]; Object[] args = new Object[1]; args[0] = data; mi.Invoke(this, args); m_InitialValues = GetVars(); }
/// <summary> スクリプティングAPIの設定にもとづいて初期化を行う </summary> /// <param name="api">APIとなるインスタンス</param> /// <param name="globals">グローバル変数</param> private void InitializeEngine(IScriptApi api, PythonDictionary globals) { _ironPythonEngine = Python.CreateEngine(); //名前参照にexeのディレクトリとキャラのディレクトリを追加 var paths = _ironPythonEngine.GetSearchPaths(); paths.Add(Environment.CurrentDirectory); paths.Add(DirectoryNames.GetCharacterScriptDirectory(api.CharacterName)); _ironPythonEngine.SetSearchPaths(paths); //可視領域を限界まで広く取るためビルトインスコープにぶち込んでおく ScriptScope builtin = _ironPythonEngine.GetBuiltinModule(); builtin.SetVariable(IronPythonCommonVariableNames.ApiVariableName, api); builtin.SetVariable(IronPythonCommonVariableNames.ApiGlobalDictionaryName, globals); }
private void RegisterScriptingApi(IScriptApi scriptApi) { MethodInfo[] allMethods = scriptApi.GetType().GetMethods(); int count = 0; for (int i = 0; i < allMethods.Length; i++) { MethodInfo method = allMethods[i]; object[] match = method.GetCustomAttributes(typeof(ScriptMethodAttribute), false); if (match != null && match.Length > 0) { m_apiMethods[method.Name] = new ApiMethod(scriptApi, method); ++count; } } m_log.Debug("Scripting API " + scriptApi + " registered " + count + " API calls"); }
public void InitApi(string api, IScriptApi data) { if (!inits.ContainsKey(api)) { return; } //ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject); //RemotingServices.GetLifetimeService(data as MarshalByRefObject); // lease.Register(m_sponser); MethodInfo mi = inits[api]; Object[] args = new Object[1]; args[0] = data; mi.Invoke(this, args); m_InitialValues = GetVars(); }
/// <summary> /// Initializes a new instance of the <see cref="UseItemOnEventRule"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="scriptFactory">A reference to the script factory in use.</param> /// <param name="conditionSet">The conditions for this event.</param> /// <param name="actionSet">The actions of this event.</param> public UseItemOnEventRule(ILogger logger, IScriptApi scriptFactory, IList <string> conditionSet, IList <string> actionSet) : base(logger, scriptFactory, conditionSet, actionSet) { // Look for a IsType condition. var isTypeConditions = this.Conditions.Where(func => IsTypeFunctionName.Equals(func.FunctionName)); var typeConditionsList = isTypeConditions as IList <IEventRuleFunction> ?? isTypeConditions.ToList(); var firstTypeCondition = typeConditionsList.FirstOrDefault(); var secondTypeCondition = typeConditionsList.Skip(1).FirstOrDefault(); if (firstTypeCondition == null) { throw new ArgumentNullException($"Unable to find first {IsTypeFunctionName} function."); } if (secondTypeCondition == null) { throw new ArgumentNullException($"Unable to find second {IsTypeFunctionName} function."); } this.ItemToUseId = Convert.ToUInt16(firstTypeCondition.Parameters[1]); this.ThingToUseOnId = Convert.ToUInt16(secondTypeCondition.Parameters[1]); }
/// <summary> /// Default constructor /// </summary> /// <param name="parent">An instance of the API class containing this /// method, or null if the API call is a static method</param> /// <param name="methodInfo">A reference to type information for the /// API call</param> public ApiMethod(IScriptApi parent, MethodInfo methodInfo) { Parent = parent; MethodInfo = methodInfo; Invoker = FastInvoke.Create(methodInfo); }
public void InitApi(string api, IScriptApi data) { if (!inits.ContainsKey(api)) return; //ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject); //RemotingServices.GetLifetimeService(data as MarshalByRefObject); // lease.Register(m_sponser); MethodInfo mi = inits[api]; Object[] args = new Object[1]; args[0] = data; mi.Invoke(this, args); m_InitialValues = GetVars(); }
/// <summary> APIの設定を用いてスクリプト読み込み器を初期化します。 </summary> /// <param name="api"></param> /// <param name="dictionary">スクリプトのグローバル変数を入れておくディクショナリ</param> public IronPythonMainScriptReader(IScriptApi api, PythonDictionary dictionary) { InitializeEngine(api, dictionary); }
public void InitApi(IScriptApi data) { }
public void Setup() { _scriptsApi = new ScriptApi(RUNSPACE_ENDPOINT_BASE_PATH); }
public void InitApi(string api, IScriptApi data) { if (!inits.ContainsKey(api)) return; MethodInfo mi = inits[api]; Object[] args = new Object[1]; args[0] = data; mi.Invoke(this, args); m_InitialValues = GetVars(); }
public void InitApi(IScriptApi data) { m_apis.Add(data.Name, data); }
public void InitApi(IScriptApi data) { /*ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject); if (lease != null) lease.Register(m_sponser);*/ m_apis.Add(data.Name, data); }
private string[] ConvertLSLTypes(string Script, out List <string> GlobalFunctions) { Match vectorMatches; RegexContains(Script, "<.*,.*,.*>", out vectorMatches); while ((vectorMatches = vectorMatches.NextMatch()).Success) { if (vectorMatches.Value != "") { Script = Script.Replace(vectorMatches.Value, "new vector(" + vectorMatches.Value.Substring(1, vectorMatches.Value.Length - 2) + ")"); } } RegexContains(Script, "<.*,.*,.*,.*>", out vectorMatches); while ((vectorMatches = vectorMatches.NextMatch()).Success) { if (vectorMatches.Value != "") { Script = Script.Replace(vectorMatches.Value, "new rotation(" + vectorMatches.Value.Substring(1, vectorMatches.Value.Length - 2) + ")"); } } RegexContains(Script, "[*]", out vectorMatches); while ((vectorMatches = vectorMatches.NextMatch()).Success) { if (vectorMatches.Value != "") { Script = Script.Replace(vectorMatches.Value, "new list(" + vectorMatches.Value.Substring(1, vectorMatches.Value.Length - 2) + ")"); } } RegexContains(Script, m_functionRegex, out vectorMatches); List <string> replacedFunctions = new List <string>(); while ((vectorMatches = vectorMatches.NextMatch()).Success) { if (vectorMatches.Value != "" && !replacedFunctions.Contains(vectorMatches.Value)) { IScriptApi api = m_scriptApis[vectorMatches.Value]; string formatedFunction = String.Format("{3}(({0})m_apis[\"{1}\"]).{2}", api.InterfaceName, api.Name, vectorMatches.Value, DTFunctions.Contains(vectorMatches.Value) ? "yield return " : ""); Script = Script.Replace(vectorMatches.Value, formatedFunction); replacedFunctions.Add(vectorMatches.Value); } } Script = Script.Replace("integer", "LSL_Types.LSLInteger"); Script = Script.Replace("float", "LSL_Types.LSLFloat"); Script = Script.Replace("key", "LSL_Types.LSLString"); Script = Script.Replace("string", "LSL_Types.LSLString"); Script = Script.Replace("vector", "LSL_Types.Vector3"); Script = Script.Replace("rotation", "LSL_Types.Quaternion"); Script = Script.Replace("list", "LSL_Types.list"); string[] split = Script.Split('\n'); bool beforeStates = true; int bracketCount = 0; GlobalFunctions = new List <string>(); for (int i = 0; i < split.Length; i++) { if (split[i].StartsWith("default") || split[i].StartsWith("state ")) { beforeStates = false; } else if (split[i].StartsWith("{")) { bracketCount++; } else if (split[i].StartsWith("}")) { bracketCount--; } else if (split[i].StartsWith("/*")) { bracketCount++; } else if (split[i].StartsWith("*/")) { bracketCount--; } else if (beforeStates && bracketCount == 0) { if (!split[i].Trim().EndsWith(";") && !split[i].Trim().StartsWith("//") && !split[i].Trim().StartsWith("/*") && split[i].Trim() != "") { GlobalFunctions.Add(split[i]); } } } return(split); }
public IScriptApi[] GetAPIs() { if (m_APIs.Length == 0) m_APIs = AuroraModuleLoader.PickupModules<IScriptApi>().ToArray(); IScriptApi[] apis = new IScriptApi[m_APIs.Length]; int i = 0; foreach(IScriptApi api in m_APIs) { apis[i] = api.Copy(); i++; } return apis; }
public List<string> GetFunctionNames(IScriptApi api) { List<string> FunctionNames = new List<string>(); MemberInfo[] members = api.GetType().GetMembers(); foreach (MemberInfo member in members) { if (member.Name.StartsWith(api.Name, StringComparison.CurrentCultureIgnoreCase)) FunctionNames.Add(member.Name); } return FunctionNames; }
private string[] ConvertLSLTypes(string Script, out List <string> GlobalFunctions) { Match vectorMatches; RegexContains(Script, "<.*,.*,.*>", out vectorMatches); while (vectorMatches.Success) { if (vectorMatches.Value != "") { Script = Script.Replace(vectorMatches.Value, "new vector(" + vectorMatches.Value.Substring(1, vectorMatches.Value.Length - 2) + ")"); } vectorMatches = vectorMatches.NextMatch(); } RegexContains(Script, "<.*,.*,.*,.*>", out vectorMatches); while (vectorMatches.Success) { if (vectorMatches.Value != "") { Script = Script.Replace(vectorMatches.Value, "new rotation(" + vectorMatches.Value.Substring(1, vectorMatches.Value.Length - 2) + ")"); } vectorMatches = vectorMatches.NextMatch(); } RegexContains(Script, "[*]", out vectorMatches); while (vectorMatches.Success) { if (vectorMatches.Value != "" && vectorMatches.Value != "*") { Script = Script.Replace(vectorMatches.Value, "new list(" + vectorMatches.Value.Substring(1, vectorMatches.Value.Length - 2) + ")"); } vectorMatches = vectorMatches.NextMatch(); } RegexContains(Script, ".*\\..*", out vectorMatches); while (vectorMatches.Success) { if (vectorMatches.Value != "") { //TODO: check for C# syntax int startValue = 0, index; while ((index = vectorMatches.Value.IndexOf(".", startValue)) != -1) { char c = vectorMatches.Value[index + 1]; char d = vectorMatches.Value[index - 1]; if (!char.IsNumber(c) && !char.IsNumber(d))//Eliminates float values, such as 5.05 { bool mustHaveCommentOrWillFail = false; char nxtChar = c; int i = index + 1; int length = vectorMatches.Value.Length; while (char.IsWhiteSpace(nxtChar)) { if (i == length) { //Blocks things like File. // Delete("Testing"); mustHaveCommentOrWillFail = false; break; } nxtChar = vectorMatches.Value[i++]; //NO putting spaces before other functions } if (!(!mustHaveCommentOrWillFail && (nxtChar == 'x' || nxtChar == 'y' || nxtChar == 'z' || nxtChar == 'w') && !char.IsLetterOrDigit(vectorMatches.Value[i + 1]))) //Eliminate vector.x, etc { //Check whether it is inside "" bool inside = false; bool insideComment = false; int pos = 0; foreach (char chr in vectorMatches.Value) { if (chr == '"') { inside = !inside; } if (chr == '/' && vectorMatches.Value[pos + 1] == '*' && !inside) { insideComment = true; } if (chr == '*' && vectorMatches.Value[pos + 1] == '/') { insideComment = false; } if (chr == '/' && vectorMatches.Value[pos + 1] == '/') { if (!inside) { insideComment = true;//Goes for the entire line if its not inside a "" already } break; } if (pos++ == index) { break; } } if (!inside && !insideComment) { m_compiler.AddError("Failed to find valid expression containing ."); GlobalFunctions = new List <string>(); return(new string[0]); } else { //Inside "" or comment } } else { //vector.x, vector.y, etc } } else { //Float, 0.05, valid } startValue = index + 1; } } vectorMatches = vectorMatches.NextMatch(); } RegexContains(Script, m_functionRegex, out vectorMatches); List <string> replacedFunctions = new List <string>(); while (vectorMatches.Success) { if (vectorMatches.Value != "" && !replacedFunctions.Contains(vectorMatches.Value)) { IScriptApi api = m_scriptApis[vectorMatches.Value]; string formatedFunction = String.Format("{3}(({0})m_apis[\"{1}\"]).{2}", api.InterfaceName, api.Name, vectorMatches.Value, DTFunctions.Contains(vectorMatches.Value) ? "yield return " : ""); Script = Script.Replace(vectorMatches.Value, formatedFunction); replacedFunctions.Add(vectorMatches.Value); } vectorMatches = vectorMatches.NextMatch(); } Script = Script.Replace("integer", "LSL_Types.LSLInteger"); Script = Script.Replace("float", "LSL_Types.LSLFloat"); Script = Script.Replace("key", "LSL_Types.LSLString"); Script = Script.Replace("string", "LSL_Types.LSLString"); Script = Script.Replace("vector", "LSL_Types.Vector3"); Script = Script.Replace("rotation", "LSL_Types.Quaternion"); Script = Script.Replace("list", "LSL_Types.list"); string[] split = Script.Split('\n'); bool beforeStates = true; int bracketCount = 0; GlobalFunctions = new List <string>(); for (int i = 0; i < split.Length; i++) { if (split[i].StartsWith("default") || split[i].StartsWith("state ")) { beforeStates = false; } else if (split[i].StartsWith("{")) { bracketCount++; } else if (split[i].StartsWith("}")) { bracketCount--; } else if (split[i].StartsWith("/*")) { bracketCount++; } else if (split[i].StartsWith("*/")) { bracketCount--; } else if (beforeStates && bracketCount == 0) { string splitTrim = RemoveComments(split[i].Trim()); string splitTrimReplaced = splitTrim.Replace(" ", ""); if (splitTrim != "" && !splitTrim.EndsWith(";") && !splitTrim.StartsWith("//") && !splitTrim.StartsWith("/*") && !splitTrimReplaced.EndsWith(";")) { if (splitTrimReplaced.EndsWith("{")) { bracketCount++; } else if (splitTrimReplaced.EndsWith("}")) { bracketCount--; } GlobalFunctions.Add(splitTrim); } } } return(split); }
public IScriptApi[] GetAPIs() { if (m_APIs.Length == 0) { m_APIs = AuroraModuleLoader.PickupModules<IScriptApi>().ToArray(); List<IScriptApi> internalApis = new List<IScriptApi>(); //Only add Apis that are considered safe foreach (IScriptApi api in m_APIs) { if (ScriptProtection.CheckAPI(api.Name)) { internalApis.Add(api); } } m_APIs = internalApis.ToArray(); } IScriptApi[] apis = new IScriptApi[m_APIs.Length]; int i = 0; foreach (IScriptApi api in m_APIs) { apis[i] = api.Copy(); i++; } return apis; }
/// <summary> /// Initializes a new instance of the <see cref="ThingMovementEventRule"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="scriptFactory">A reference to the script factory in use.</param> /// <param name="conditionSet">The conditions for this event.</param> /// <param name="actionSet">The actions of this event.</param> public ThingMovementEventRule(ILogger logger, IScriptApi scriptFactory, IList <string> conditionSet, IList <string> actionSet) : base(logger, scriptFactory, conditionSet, actionSet) { }
public void InitApi(string api, IScriptApi data) { MethodInfo mi = GetType().GetMethod("ApiType" + api); if (mi == null) return; ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject); if (lease != null) lease.Register(m_sponser); Object[] args = new Object[1]; args[0] = data; mi.Invoke(this, args); m_InitialValues = GetVars(); }