Exemple #1
0
 public override void Unswizzle(IList <EventNode> nodes)
 {
     if (NextIfFalse is DummyEventNode dummy)
     {
         if (dummy.Id >= nodes.Count)
         {
             ApiUtil.Assert($"Invalid event id: {Id} links to {dummy.Id} when false, but the set only contains {nodes.Count} events");
             NextIfFalse = null;
         }
         else
         {
             NextIfFalse = nodes[dummy.Id];
         }
     }
     base.Unswizzle(nodes);
 }
        EventDefSettingsCommand(IEventNode eventNode, EventDefOptions options)
        {
            this.eventNode   = eventNode;
            this.newOptions  = options;
            this.origOptions = new EventDefOptions(eventNode.EventDef);

            this.origParentNode       = (IFileTreeNodeData)eventNode.TreeNode.Parent.Data;
            this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(eventNode.TreeNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
            {
                throw new InvalidOperationException();
            }

            this.nameChanged = origOptions.Name != newOptions.Name;
        }
Exemple #3
0
        public virtual void Unswizzle(IList <EventNode> nodes)
        {
            if (!(Next is DummyEventNode dummy))
            {
                return;
            }

            if (dummy.Id >= nodes.Count)
            {
                ApiUtil.Assert($"Invalid event id: {Id} links to {dummy.Id}, but the set only contains {nodes.Count} events");
                Next = null;
            }
            else
            {
                Next = nodes[dummy.Id];
            }
        }
Exemple #4
0
    public void FormatChain(StringBuilder sb, IEventNode firstEvent, int indent = 0)
    {
        if (sb == null)
        {
            throw new ArgumentNullException(nameof(sb));
        }
        if (firstEvent == null)
        {
            return;
        }

        var uniqueEvents = ExploreGraph(firstEvent);
        var sorted       = uniqueEvents.OrderBy(x => x.Id).ToList();

        foreach (var e in sorted)
        {
            sb.Append(new string(' ', 4 * indent));
            sb.AppendLine(Format(e, sorted[0].Id));
        }
    }
            public ControlFlowGraph(IEventNode node)
            {
                var entryNode = new EventNode(-1, null)
                {
                    NextEvent = node
                };
                var terminalNode = new EventNode(-2, null);

                //var leaders = new HashSet<IEventNode> { entryNode, node, terminalNode }; // Entry and exit nodes are always leaders
                //FindLeaders(entryNode, leaders, terminalNode);
                BuildBlocks(entryNode, terminalNode);//, leaders);
                LinkBlocks();
                Start = Blocks[entryNode];
                if (!Blocks.ContainsKey(terminalNode))
                {
                    throw new InvalidOperationException("Invalid procedure: never exits");
                }
                End = Blocks[terminalNode];
                CombineBlocks();
            }
Exemple #6
0
    public virtual void Unswizzle(IList <EventNode> nodes)
    {
        if (nodes == null)
        {
            throw new ArgumentNullException(nameof(nodes));
        }
        if (Next is not DummyEventNode dummy)
        {
            return;
        }

        if (dummy.Id >= nodes.Count)
        {
            ApiUtil.Assert($"Invalid event id: {Id} links to {dummy.Id}, but the set only contains {nodes.Count} events");
            Next = null;
        }
        else
        {
            Next = nodes[dummy.Id];
        }
    }
Exemple #7
0
        public void Unswizzle(MapId mapId, Func <ushort, IEventNode> getEvent, Func <ushort, ushort> getChain)
        {
            if (getEvent == null)
            {
                throw new ArgumentNullException(nameof(getEvent));
            }
            if (getChain == null)
            {
                throw new ArgumentNullException(nameof(getChain));
            }
            ChainSource = mapId;
            if (Node is DummyEventNode dummy)
            {
                Node = getEvent(dummy.Id);
            }

            if (Node != null)
            {
                Chain = getChain(Node.Id);
            }
        }
Exemple #8
0
 static void PrintChain(StreamWriter sw, EventFormatter formatter, IEventNode e, int indent)
 {
     do
     {
         sw.Write($"{e.Id:000}");
         sw.Write("".PadRight(indent * 4));
         if (e is IBranchNode branch)
         {
             sw.WriteLine($"if (!{formatter.GetText(e)}) {{");
             if (branch.NextIfFalse != null)
             {
                 PrintChain(sw, formatter, branch.NextIfFalse, indent + 1);
             }
             sw.WriteLine("}".PadLeft(4 + indent * 4));
             sw.WriteLine("else...".PadLeft(10 + indent * 4));
         }
         else
         {
             sw.WriteLine(formatter.GetText(e));
         }
         e = e.Next;
     } while (e != null);
 }
Exemple #9
0
 static void PrintChain(EventFormatter formatter, IEventNode e, int indent)
 {
     do
     {
         Console.Write($"{e.Id:000}");
         Console.Write("".PadRight(indent * 4));
         if (e is IBranchNode branch)
         {
             Console.WriteLine($"if (!{formatter.GetText(e)}) {{");
             if (branch.NextEventWhenFalse != null)
             {
                 PrintChain(formatter, branch.NextEventWhenFalse, indent + 1);
             }
             Console.WriteLine("}".PadLeft(4 + indent * 4));
             Console.WriteLine("else...".PadLeft(10 + indent * 4));
         }
         else
         {
             Console.WriteLine(formatter.GetText(e));
         }
         e = e.NextEvent;
     } while (e != null);
 }
Exemple #10
0
        public void FormatChainDecompiled(StringBuilder sb, IEventNode firstEvent, IList <IEventNode> additionalEntryPoints, int indent)
        {
            var events = ExploreGraph(firstEvent);

            events.Remove(firstEvent);
            var sorted = new List <IEventNode> {
                firstEvent
            };

            sorted.AddRange(events);
            List <(string, ControlFlowGraph)> steps = new();

            try
            {
                var tree  = Decompiler.Decompile(sorted, steps);
                var inner = new StringBuilder();
                tree.ToPseudocode(inner, true, false);
                ScriptUtil.PrettyPrintScript(sb, inner.ToString(), indent);
            }
            catch (ControlFlowGraphException)
            {
                FormatChain(sb, firstEvent, indent); // Fallback to raw view
            }
        }
Exemple #11
0
		CreateEventDefCommand(ITypeNode ownerNode, EventDefOptions options) {
			this.ownerNode = ownerNode;
			this.eventNode = ownerNode.Create(options.CreateEventDef(ownerNode.TypeDef.Module));
		}
Exemple #12
0
		DeleteEventDefCommand(IEventNode[] eventNodes) {
			this.nodes = new DeletableNodes<IEventNode>(eventNodes);
		}
Exemple #13
0
			public void Restore(IEventNode[] nodes) {
				Debug.Assert(infos != null);
				if (infos == null)
					throw new InvalidOperationException();
				Debug.Assert(infos.Length == nodes.Length);
				if (infos.Length != nodes.Length)
					throw new InvalidOperationException();

				for (int i = infos.Length - 1; i >= 0; i--) {
					var node = nodes[i];
					var info = infos[i];
					info.OwnerType.Events.Insert(info.EventIndex, node.EventDef);

					for (int j = info.Methods.Length - 1; j >= 0; j--)
						info.OwnerType.Methods.Insert(info.MethodIndexes[j], info.Methods[j]);
				}

				infos = null;
			}
Exemple #14
0
 public override void OnEventReceiver(IEventNode @event)
 {
 }
Exemple #15
0
		public EvntInfo GetEvent(IEventNode ev)
		{
			return (EvntInfo)defs[ev];
		}
Exemple #16
0
 CreateEventDefCommand(ITypeNode ownerNode, EventDefOptions options)
 {
     this.ownerNode = ownerNode;
     this.eventNode = ownerNode.Create(options.CreateEventDef(ownerNode.TypeDef.Module));
 }
Exemple #17
0
 public EventNodeCreator(IModuleDocumentNode modNode, ITypeNode ownerNode, EventDef @event)
 {
     this.ownerNode = ownerNode;
     this.eventNode = modNode.Context.DocumentTreeView.Create(@event);
 }
Exemple #18
0
    public override void OnEventReceiver(IEventNode @event)
    {
        var lst = (@event as RoleEventNode).Data;

        Debug.Log($"{lst[0]}  {lst[1]}");
    }
 public void Add(IEventNode node)
 {
     Nodes.Add(node);
 }
Exemple #20
0
		public void visit(IEventNode value)
		{

		}
Exemple #21
0
 /// <summary>
 /// 负责接收外部传来的事件内容
 /// </summary>
 /// <param name="node">事件节点</param>
 public void OnEventReceiver(IEventNode @event)
 {
     OnEventDispatch(@event);
 }
Exemple #22
0
		public void visit(IEventNode value)
		{
            throw new System.NotSupportedException(value.GetType().ToString());
		}
Exemple #23
0
		EventDefSettingsCommand(IEventNode eventNode, EventDefOptions options) {
			this.eventNode = eventNode;
			this.newOptions = options;
			this.origOptions = new EventDefOptions(eventNode.EventDef);

			this.origParentNode = (IFileTreeNodeData)eventNode.TreeNode.Parent.Data;
			this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(eventNode.TreeNode);
			Debug.Assert(this.origParentChildIndex >= 0);
			if (this.origParentChildIndex < 0)
				throw new InvalidOperationException();

			this.nameChanged = origOptions.Name != newOptions.Name;
		}
Exemple #24
0
 /// <summary>
 /// 负责接收外部传来的事件内容
 /// </summary>
 /// <param name="node">事件节点</param>
 public void OnEventReceiver(RoleNumber number, IEventNode @event)
 {
     OnEventDispatch(number, @event);
 }
Exemple #25
0
 public TriggerChainEvent(EventChain chain, IEventNode node, NpcCharacterId npcId)
     : this(chain, node, new EventSource.Npc(npcId))
 {
 }
Exemple #26
0
 public TriggerChainEvent(EventChain chain, IEventNode node, EventSource source)
 {
     Chain  = chain ?? throw new ArgumentNullException(nameof(chain));
     Node   = node ?? throw new ArgumentNullException(nameof(node));
     Source = source ?? throw new ArgumentNullException(nameof(source));
 }
Exemple #27
0
 public TriggerChainEvent(EventChain chain, IEventNode node, EventSetId eventSetId)
     : this(chain, node, new EventSource.EventSet(eventSetId))
 {
 }
Exemple #28
0
		public EvntInfo AddEvent(IEventNode ev, EventBuilder eb)
		{
			EvntInfo ei = new EvntInfo(eb);
			defs[ev] = ei;
			return ei;
		}
Exemple #29
0
			public void Delete(IEventNode[] nodes) {
				Debug.Assert(infos == null);
				if (infos != null)
					throw new InvalidOperationException();

				infos = new ModelInfo[nodes.Length];

				for (int i = 0; i < infos.Length; i++) {
					var node = nodes[i];

					var info = new ModelInfo(node.EventDef);
					infos[i] = info;
					info.OwnerType.Events.RemoveAt(info.EventIndex);

					for (int j = 0; j < info.Methods.Length; j++) {
						int index = info.OwnerType.Methods.IndexOf(info.Methods[j]);
						Debug.Assert(index >= 0);
						if (index < 0)
							throw new InvalidOperationException();
						info.OwnerType.Methods.RemoveAt(index);
						info.MethodIndexes[j] = index;
					}
				}
			}
Exemple #30
0
 public virtual void OnEventReceiver(IEventNode @event)
 {
 }
		public virtual void visit(IEventNode value)
		{
			
		}
 public virtual void visit(IEventNode value)
 {
 }
Exemple #33
0
 public virtual void OnEventDispatch(IEventNode @event)
 {
 }
Exemple #34
0
 public EvntInfo GetEvent(IEventNode ev)
 {
     return((EvntInfo)defs[ev]);
 }
Exemple #35
0
 public TriggerChainEvent(EventChain chain, IEventNode node, TriggerType trigger, MapDataId mapId, int x, int y)
     : this(chain, node, new EventSource.Map(mapId, trigger, x, y))
 {
 }