예제 #1
0
 public void AddToLog(string s)
 {
     lock (UpdateLog)
     {
         UpdateLog.Add(RealPlugin.FormatDateTime(DateTime.Now) + " - " + s);
     }
 }
예제 #2
0
        internal static Image LoadImageData(RealPlugin plug, string ifn)
        {
            Uri u = new Uri(ifn);

            if (u.IsFile == true)
            {
                return(LoadImage(u.LocalPath));
            }
            else
            {
                string fn = Path.Combine(plug.path, "TriggernometryRemoteImages");
                if (Directory.Exists(fn) == false)
                {
                    Directory.CreateDirectory(fn);
                }
                string ext = Path.GetExtension(u.LocalPath);
                fn = Path.Combine(fn, plug.GenerateHash(u.AbsoluteUri) + Path.GetExtension(u.LocalPath));
                if (File.Exists(fn) == false)
                {
                    using (WebClient wc = new WebClient())
                    {
                        wc.Headers["User-Agent"] = "Triggernometry Image Retriever";
                        byte[] data = wc.DownloadData(u.AbsoluteUri);
                        File.WriteAllBytes(fn, data);
                    }
                }
                if (File.Exists(fn) == true)
                {
                    return(LoadImage(fn));
                }
            }
            return(null);
        }
예제 #3
0
        private static object GetInstance()
        {
            RealPlugin.PluginWrapper wrap = RealPlugin.InstanceHook(ActPluginName, ActPluginType);
            switch (wrap.state)
            {
            case 0:
            {
                if (ckw == false)
                {
                    LogMessage(RealPlugin.DebugLevelEnum.Warning, I18n.Translate("internal/ffxiv/missingactplugin", "FFXIV ACT plugin with filename ({0}) or type ({1}) could not be located, some functions may not work as expected", ActPluginName, ActPluginType));
                    ckw = true;
                }
                return(null);
            }

            case 1:
            {
                return(wrap.pluginObj);
            }

            case 2:
            {
                LogMessage(RealPlugin.DebugLevelEnum.Warning, I18n.Translate("internal/ffxiv/oldactplugin", "FFXIV ACT plugin version is lower ({0}) than expected ({1}), some functions may not work as expected", wrap.fileversion, wrap.expectedversion));
                return(wrap.pluginObj);
            }
            }
            return(null);
        }
예제 #4
0
 public static void SubscribeToNetworkEvents(RealPlugin p)
 {
     try
     {
         object plug = GetInstance();
         if (plug == null)
         {
             throw new ArgumentException("No plugin instance available");
         }
         PropertyInfo pi = plug.GetType().GetProperty("DataSubscription", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
         if (pi == null)
         {
             throw new ArgumentException("No DataSubscription found");
         }
         dynamic subs = pi.GetValue(plug);
         if (subs == null)
         {
             throw new ArgumentException("DataSubscription not initialized");
         }
         EventInfo ei = subs.GetType().GetEvent("ParsedLogLine", BindingFlags.GetField | BindingFlags.Public | BindingFlags.Instance);
         if (subs == null)
         {
             throw new ArgumentException("No ParsedLogLine found");
         }
         MethodInfo mix     = p.GetType().GetMethod("NetworkLogLineReceiver");
         Type       deltype = ei.EventHandlerType;
         Delegate   handler = Delegate.CreateDelegate(deltype, p, mix);
         ei.AddEventHandler(subs, handler);
         LogMessage(RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/ffxiv/networksubok", "Subscribed to FFXIV network events"));
     }
     catch (Exception ex)
     {
         LogMessage(RealPlugin.DebugLevelEnum.Error, I18n.Translate("internal/ffxiv/networksubexception", "Could not subscribe to FFXIV network events due to an exception: {0}", ex.Message));
     }
 }
예제 #5
0
 internal void AddToLog(RealPlugin p, RealPlugin.DebugLevelEnum level, string message)
 {
     RealPlugin.DebugLevelEnum dx = GetDebugLevel(p);
     if (level > dx)
     {
         return;
     }
     p.UnfilteredAddToLog(level, message);
 }
예제 #6
0
 internal void DeferredFire(RealPlugin p, Context ctx, RealPlugin.MutexInformation mi, RealPlugin.MutexTicket m)
 {
     using (m)
     {
         mi.Acquire(ctx, m);
         if (Fire(p, ctx, mi) == false)
         {
             mi.Release(ctx);
         }
     }
 }
예제 #7
0
        internal MethodInfo GetImplMethodInfo(Type interfaceType, string methodName)
        {
            Debug.Assert(RealPlugin != null);
            MethodInfo m = RealPlugin.GetType().GetMethod(interfaceType.FullName + '.' + methodName);

            if (m == null)
            {
                m = RealPlugin.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            }
            return(m);
        }
예제 #8
0
        internal string Run(RealPlugin rp, Context ctx, string scp)
        {
            Globals globs = new Globals()
            {
                TrigInstance = rp, TrigContext = ctx
            };
            var    result = CSharpScript.RunAsync(scp, sop, globs, typeof(Globals)).Result;
            object rob    = result.ReturnValue;

            return(rob != null?rob.ToString() : "");
        }
예제 #9
0
        private VariableList GetListVariable(RealPlugin p, string varname, bool createNew)
        {
            if (p.listvariables.ContainsKey(varname) == true)
            {
                return(p.listvariables[varname]);
            }
            VariableList vl = new VariableList();

            if (createNew == true)
            {
                p.listvariables[varname] = vl;
            }
            return(vl);
        }
예제 #10
0
        internal void QueueActions(Context ctx, DateTime curtime, RealPlugin.MutexInformation mtx)
        {
            RealPlugin p = ctx.plug;

            System.Diagnostics.Debug.WriteLine("### queuing actions for " + ctx.ToString());
            if (_Sequential == false)
            {
                var ix = from tx in Actions
                         orderby tx.OrderNumber ascending
                         select tx;
                foreach (Action a in ix)
                {
                    if (a._Enabled == true)
                    {
                        curtime = curtime.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, a._ExecutionDelayExpression));
                        p.QueueAction(ctx, this, mtx, a, curtime);
                    }
                }
            }
            else
            {
                Action prev  = null;
                Action first = null;
                var    ix    = from tx in Actions
                               orderby tx.OrderNumber ascending
                               select tx;
                foreach (Action a in ix)
                {
                    if (a._Enabled == false)
                    {
                        continue;
                    }
                    if (prev != null)
                    {
                        prev.NextAction = a;
                    }
                    else
                    {
                        first   = a;
                        curtime = curtime.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, a._ExecutionDelayExpression));
                    }
                    prev = a;
                }
                if (first != null)
                {
                    p.QueueAction(ctx, this, mtx, first, curtime);
                }
            }
        }
예제 #11
0
 internal RealPlugin.DebugLevelEnum GetDebugLevel(RealPlugin p)
 {
     if (_DebugLevel == RealPlugin.DebugLevelEnum.Inherit)
     {
         if (p.cfg != null)
         {
             return(p.cfg.DebugLevel);
         }
         else
         {
             return(RealPlugin.DebugLevelEnum.Verbose);
         }
     }
     return(_DebugLevel);
 }
예제 #12
0
        internal Engine(RealPlugin rp)
        {
            var pi = typeof(RealPlugin).Assembly.GetType().GetMethod("GetRawBytes", BindingFlags.Instance | BindingFlags.NonPublic);

            byte[] b    = (byte[])pi.Invoke(typeof(RealPlugin).Assembly, null);
            var    mref = MetadataReference.CreateFromImage(b);

            sop = ScriptOptions.Default.AddReferences(mref).AddReferences(new string[]
            {
                "System.Text.RegularExpressions",
            }).AddImports(new string[]
            {
                "System", "System.Text", "System.IO", "System.Text.RegularExpressions", "System.Collections.Generic", "Triggernometry.VariableTypes"
            });
        }
예제 #13
0
 internal string Run(RealPlugin rp, Context ctx, Script scp)
 {
     if (scp.Compiled != null)
     {
         Globals globs = new Globals()
         {
             TrigInstance = rp, TrigContext = ctx
         };
         var    result = scp.Compiled.RunAsync(globs).Result;
         object rob    = result.ReturnValue;
         return(rob != null?rob.ToString() : "");
     }
     else
     {
         return(Run(rp, ctx, scp.Code));
     }
 }
예제 #14
0
 public ImportForm(RealPlugin p)
 {
     InitializeComponent();
     plug = p;
     if (DesignMode == false)
     {
         tabControl1.ItemSize = new Size(0, 1);
         tabControl1.SizeMode = TabSizeMode.Fixed;
     }
     radImportFromText.Select();
     radExistingActTriggers.Enabled = plug.CustomTriggerCheckHook();
     treeView1.TreeViewNodeSorter   = new NodeSorter();
     treeView1.ItemDrag            += TreeView1_ItemDrag;
     treeView1.DragDrop            += TreeView1_DragDrop;
     treeView1.DragEnter           += TreeView1_DragEnter;
     treeView1.DragOver            += TreeView1_DragOver;
     RestoredSavedDimensions();
 }
예제 #15
0
        private void DgvLog_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
        {
            InternalLog il = virtualData[e.RowIndex];

            switch (e.ColumnIndex)
            {
            case 0:
                e.Value = RealPlugin.FormatDateTime(il.Timestamp);
                break;

            case 1:
                e.Value = I18n.Translate("internal/Plugin/loglevel" + il.Level.ToString(), "{0}", il.Level.ToString());
                break;

            case 2:
                e.Value = il.Message;
                break;
            }
        }
예제 #16
0
        private void RefreshViewStatic()
        {
            List <DataGridViewRow> rows = new List <DataGridViewRow>();
            List <InternalLog>     p1   = BuildDataset();

            foreach (InternalLog il in p1)
            {
                DataGridViewRow row = (DataGridViewRow)dgvLog.RowTemplate.Clone();
                row.CreateCells(dgvLog, RealPlugin.FormatDateTime(il.Timestamp), I18n.Translate("internal/Plugin/loglevel" + il.Level.ToString(), "{0}", il.Level.ToString()), il.Message);
                switch (il.Level)
                {
                case RealPlugin.DebugLevelEnum.Verbose:
                    row.DefaultCellStyle.BackColor = Color.LightGray;
                    row.DefaultCellStyle.ForeColor = Color.Black;
                    break;

                case RealPlugin.DebugLevelEnum.Info:
                    row.DefaultCellStyle.BackColor = Color.White;
                    row.DefaultCellStyle.ForeColor = Color.Black;
                    break;

                case RealPlugin.DebugLevelEnum.Warning:
                    row.DefaultCellStyle.BackColor = Color.Yellow;
                    row.DefaultCellStyle.ForeColor = Color.Black;
                    break;

                case RealPlugin.DebugLevelEnum.Error:
                    row.DefaultCellStyle.BackColor = Color.Red;
                    row.DefaultCellStyle.ForeColor = Color.Yellow;
                    break;
                }
                rows.Add(row);
            }
            dgvLog.Rows.Clear();
            dgvLog.Rows.AddRange(rows.ToArray());
            dgvLog.ClearSelection();
            lblStatus.Text = I18n.Translate("internal/LogForm/displaying", "Displaying {0} out of {1}", p1.Count, logData.Count);
        }
예제 #17
0
 internal bool Fire(RealPlugin p, Context ctx, RealPlugin.MutexInformation mtx)
 {
     try
     {
         if (mtx == null && _MutexToCapture != "")
         {
             string mn = ctx.EvaluateStringExpression(TriggerContextLogger, p, _MutexToCapture);
             RealPlugin.MutexInformation mi = ctx.plug.GetMutex(mn);
             RealPlugin.MutexTicket      m  = mi.QueueForAcquisition(ctx);
             Task t = new Task(() => {
                 using (m)
                 {
                     DeferredFire(ctx.plug, ctx, mi, m);
                 }
             });
             t.Start();
             return(true);
         }
         if ((ctx.force & Action.TriggerForceTypeEnum.SkipConditions) == 0)
         {
             if (Condition != null && Condition.Enabled == true)
             {
                 if (Condition.CheckCondition(ctx, TriggerContextLogger, ctx.plug) == false)
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/trignotfired", "Trigger '{0}' not fired, condition not met", LogName));
                     return(false);
                 }
             }
         }
         DateTime prevLastFired = LastFired;
         LastFired = DateTime.Now;
         if (_PeriodRefire == RefireEnum.Deny)
         {
             RefireDelayedUntil = LastFired.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, _RefirePeriodExpression));
             AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/delayingrefire", "Delaying trigger '{0}' refire to {1}", LogName, RefireDelayedUntil));
         }
         else
         {
             RefireDelayedUntil = DateTime.MinValue;
         }
         DateTime curtime = DateTime.Now;
         if (_Scheduling == SchedulingEnum.FromLastAction)
         {
             // get the last queued action as curTime
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           orderby ax.when descending
                           select ax;
                 if (ixy.Count() > 0)
                 {
                     curtime = ixy.ElementAt(0).when;
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/lastactionfound", "Last action for trigger '{0}' found at {1}", LogName, curtime));
                 }
             }
         }
         else if (_Scheduling == SchedulingEnum.FromRefirePeriod)
         {
             curtime = prevLastFired.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, _RefirePeriodExpression));
             if (curtime < LastFired)
             {
                 curtime = LastFired;
                 AddToLog(p, RealPlugin.DebugLevelEnum.Verbose, I18n.Translate("internal/Trigger/beforelastfired", "Current time is before last fired for trigger '{0}'", LogName));
             }
         }
         if (_PrevActions == PrevActionsEnum.Interrupt)
         {
             int exx = 0;
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           select ax;
                 if (ixy.Count() > 0)
                 {
                     List <RealPlugin.QueuedAction> rems = new List <RealPlugin.QueuedAction>();
                     rems.AddRange(ixy);
                     foreach (RealPlugin.QueuedAction qa in rems)
                     {
                         ctx.plug.ActionQueue.Remove(qa);
                         exx++;
                     }
                 }
             }
             if (exx > 0)
             {
                 if (_PrevActionsRefire == RefireEnum.Deny)
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/removefromqueuenorefire", "Removed {0} instance(s) of trigger '{1}' actions from queue, refire denied", exx, LogName));
                     return(false);
                 }
                 else
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/removefromqueue", "Removed {0} instance(s) of trigger '{1}' actions from queue", exx, LogName));
                 }
             }
         }
         else if (_PrevActionsRefire == RefireEnum.Deny)
         {
             int exx = 0;
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           select ax;
                 exx = ixy.Count();
             }
             if (exx > 0)
             {
                 AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/refiredenied", "{0} instance(s) of trigger '{1}' actions in queue, refire denied", exx, LogName));
                 return(false);
             }
         }
         QueueActions(ctx, curtime, mtx);
     }
     catch (Exception ex)
     {
         AddToLog(p, RealPlugin.DebugLevelEnum.Error, I18n.Translate("internal/Trigger/firingexception", "Trigger '{0}' didn't fire due to exception: {1}", LogName, ex.Message));
     }
     return(false);
 }
예제 #18
0
 internal void Fire(RealPlugin p, Context ctx)
 {
     try
     {
         if ((ctx.force & Action.TriggerForceTypeEnum.SkipConditions) == 0)
         {
             if (Condition != null && Condition.Enabled == true)
             {
                 if (Condition.CheckCondition(ctx, TriggerContextLogger, ctx.plug) == false)
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/trignotfired", "Trigger '{0}' not fired, condition not met", LogName));
                     return;
                 }
             }
         }
         DateTime prevLastFired = LastFired;
         LastFired = DateTime.Now;
         if (_PeriodRefire == RefireEnum.Deny)
         {
             RefireDelayedUntil = LastFired.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, _RefirePeriodExpression));
             AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/delayingrefire", "Delaying trigger '{0}' refire to {1}", LogName, RefireDelayedUntil));
         }
         else
         {
             RefireDelayedUntil = DateTime.MinValue;
         }
         DateTime curtime = DateTime.Now;
         if (_Scheduling == SchedulingEnum.FromLastAction)
         {
             // get the last queued action as curTime
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           orderby ax.when descending
                           select ax;
                 if (ixy.Count() > 0)
                 {
                     curtime = ixy.ElementAt(0).when;
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/lastactionfound", "Last action for trigger '{0}' found at {1}", LogName, curtime));
                 }
             }
         }
         else if (_Scheduling == SchedulingEnum.FromRefirePeriod)
         {
             curtime = prevLastFired.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, _RefirePeriodExpression));
             if (curtime < LastFired)
             {
                 curtime = LastFired;
                 AddToLog(p, RealPlugin.DebugLevelEnum.Verbose, I18n.Translate("internal/Trigger/beforelastfired", "Current time is before last fired for trigger '{0}'", LogName));
             }
         }
         if (_PrevActions == PrevActionsEnum.Interrupt)
         {
             int exx = 0;
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           select ax;
                 if (ixy.Count() > 0)
                 {
                     List <RealPlugin.QueuedAction> rems = new List <RealPlugin.QueuedAction>();
                     rems.AddRange(ixy);
                     foreach (RealPlugin.QueuedAction qa in rems)
                     {
                         ctx.plug.ActionQueue.Remove(qa);
                         exx++;
                     }
                 }
             }
             if (exx > 0)
             {
                 if (_PrevActionsRefire == RefireEnum.Deny)
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/removefromqueuenorefire", "Removed {0} instance(s) of trigger '{1}' actions from queue, refire denied", exx, LogName));
                     return;
                 }
                 else
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/removefromqueue", "Removed {0} instance(s) of trigger '{1}' actions from queue", exx, LogName));
                 }
             }
         }
         else if (_PrevActionsRefire == RefireEnum.Deny)
         {
             int exx = 0;
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           select ax;
                 exx = ixy.Count();
             }
             if (exx > 0)
             {
                 AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/refiredenied", "{0} instance(s) of trigger '{1}' actions in queue, refire denied", exx, LogName));
                 return;
             }
         }
         if (_Sequential == false)
         {
             var ix = from tx in Actions
                      orderby tx.OrderNumber ascending
                      select tx;
             foreach (Action a in ix)
             {
                 if (a._Enabled == true)
                 {
                     curtime = curtime.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, a._ExecutionDelayExpression));
                     p.QueueAction(ctx, this, a, curtime);
                 }
             }
         }
         else
         {
             Action prev  = null;
             Action first = null;
             var    ix    = from tx in Actions
                            orderby tx.OrderNumber ascending
                            select tx;
             foreach (Action a in ix)
             {
                 if (a._Enabled == false)
                 {
                     continue;
                 }
                 if (prev != null)
                 {
                     prev.NextAction = a;
                 }
                 else
                 {
                     first   = a;
                     curtime = curtime.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, a._ExecutionDelayExpression));
                 }
                 prev = a;
             }
             if (first != null)
             {
                 p.QueueAction(ctx, this, first, curtime);
             }
         }
     }
     catch (Exception ex)
     {
         AddToLog(p, RealPlugin.DebugLevelEnum.Error, I18n.Translate("internal/Trigger/firingexception", "Trigger '{0}' didn't fire due to exception: {1}", LogName, ex.Message));
     }
 }
예제 #19
0
 public override string ToString()
 {
     return(RealPlugin.FormatDateTime(Timestamp) + " - " + I18n.Translate("internal/Plugin/loglevel" + Level.ToString(), "{0}", Level.ToString()) + " - " + Message);
 }