상속: XNode
예제 #1
0
        public static string GetMethodName(XNodeIn localNode, int nodeID)
        {
            var node = XRay.Nodes[nodeID];

            var  parentClass  = node.GetParentClass(false);
            bool includeClass = (parentClass != localNode.GetParentClass(false));

            if (node.ObjType == XObjType.Field)
            {
                string name = node.UnformattedName;

                if (includeClass)
                {
                    name = parentClass.Name + "::" + name;
                }

                if (node.ReturnID != 0)
                {
                    var retNode = XRay.Nodes[node.ReturnID];
                    name = retNode.Name + " " + name;
                }

                return(name);
            }

            else if (node.ObjType == XObjType.Method)
            {
                return(node.GetMethodName(includeClass));
            }

            return("unknown");
        }
예제 #2
0
 public NodeModel(ViewModel model, XNodeIn xNode)
 {
     Model = model;
     XNode = xNode;
     Name = XNode.Name;
     ID = XNode.ID;
     ObjType = XNode.ObjType;
 }
예제 #3
0
 public NodeModel(ViewModel model, XNodeIn xNode)
 {
     Model   = model;
     XNode   = xNode;
     Name    = XNode.Name;
     ID      = XNode.ID;
     ObjType = XNode.ObjType;
 }
예제 #4
0
        public InstanceModel(XNodeIn node, string filter, Action updatedTree = null, Action <IFieldModel> expandedField = null)
        {
            SelectedNode  = node;
            FieldFilter   = filter;
            UpdatedTree   = updatedTree;
            ExpandedField = expandedField;

            Columns.Add("Type");
            Columns.Add("Name");
        }
예제 #5
0
        internal bool LoadMsil()
        {
            if (MsilPos == 0 || MsilLines == 0)
            {
                return(false);
            }

            if (Msil != null)
            {
                return(true);
            }

            using (FileStream DatStream = new FileStream(XRay.DatPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                DatStream.Position = MsilPos;

                Msil = new List <XInstruction>();
                var code = new StringBuilder();

                for (int i = 0; i < MsilLines; i++)
                {
                    var inst = new XInstruction();
                    inst.Offset = BitConverter.ToInt32(DatStream.Read(4), 0);
                    inst.OpCode = XNodeIn.ReadString(DatStream);
                    inst.Line   = XNodeIn.ReadString(DatStream);
                    inst.RefId  = BitConverter.ToInt32(DatStream.Read(4), 0);

                    if (inst.RefId != 0 && !inst.Line.StartsWith("goto "))
                    {
                        inst.Line = Utilities.GetMethodName(this, inst.RefId);
                    }

                    Msil.Add(inst);
                    code.Append(inst.Offset.ToString("X") + ": " + inst.OpCode + " " + inst.Line + "\r\n");
                }

                PlainMsil = code.ToString();
            }

            return(true);
        }
예제 #6
0
        private void ResetTimer_Tick(object sender, EventArgs e)
        {
            if (XRay.Nodes == null)
            {
                return;
            }

            for (int i = 0; i < XRay.Nodes.Length; i++)
            {
                XNodeIn node = XRay.Nodes[i];

                if (node != null)
                {
                    if (node.FunctionHit > 0)
                    {
                        node.FunctionHit--;
                    }

                    if (XRay.ThreadTracking &&
                        node.ConflictHit > 0)
                    {
                        node.ConflictHit--;
                    }
                }
            }

            // reset
            if (XRay.FlowTracking)
            {
                // time out function calls
                TimeoutFunctinCalls(XRay.CallMap);
                TimeoutFunctinCalls(XRay.ClassCallMap);
            }

            TreeView.Redraw();
        }
예제 #7
0
        private static void TrackFunctionCall(int dest, XNodeIn node, int thread, object[] parameters, bool loadField=false)
        {
            // check that thread is in map
            ThreadFlow flow;
            if (!FlowMap.TryGetValue(thread, out flow))
            {
                flow = new ThreadFlow()
                {
                    ThreadID = thread,
                    Name = node.Name,
                    Handle = Thread.CurrentThread,
                    IsAlive = true
                };

                FlowMap.Add(thread, flow);

                if (Remote != null)
                    foreach (var client in Remote.SyncClients)
                        lock(client.NewThreads)
                            client.NewThreads[flow.ThreadID] = new Tuple<string,bool>(flow.Name, flow.IsAlive);
            }

            bool isMethod = (node.ObjType == XObjType.Method);

            if(isMethod)
                node.StillInside++;

            // if the first entry, return here
            if (flow.Pos == -1)
            {
                flow.CreateStackItem(dest, null, Watch.ElapsedTicks, isMethod, ThreadlineEnabled);
                node.EntryPoint++;
                return;
            }

            // if exceeded tracking max return
            if (flow.Pos >= flow.Stack.Length)
                return;

            // set the source, and put the dest in stack
            int source = flow.Stack[flow.Pos].NodeID;

            // if loading a fields the call goes from field -> node
            if (loadField && FieldGetLeftToRight)
            {
                int temp = source;
                source = dest;
                dest = temp;
            }

            int hash = PairHash(source, dest);

            FunctionCall call;
            if (!CallMap.TryGetValue(hash, out call))
                call = CreateNewCall(hash, source, node);

            if (source != call.Source || dest != call.Destination)
                LogError("Call mismatch  {0}->{1} != {2}->{3}\r\n", source, dest, call.Source, call.Destination);

            call.Hit = ShowTicks;
            call.TotalHits++;
            call.LastParameters = parameters;

            if (!call.ThreadIDs.Contains(thread))
            {
                call.ThreadIDs.Add(thread);

                if (Remote != null)
                    foreach (var client in Remote.SyncClients)
                        lock(client.CallThreads)
                            client.CallThreads.Add(new Tuple<int, int>(call.ID, thread));
            }

            if (Remote != null)
                foreach (var sync in Remote.SyncClients)
                    lock(sync.CallHits)
                        sync.CallHits.Add(hash);

            // if a method
            if (isMethod)
                call.StillInside++;

            flow.CreateStackItem(dest, call, Watch.ElapsedTicks, isMethod, ThreadlineEnabled);

            if(ClassTracking)
                TrackClassCall(call, thread);
        }
예제 #8
0
        private static void TrackInit(XNodeIn node)
        {
            int thread = 0;
            if (ThreadTracking)
                thread = Thread.CurrentThread.ManagedThreadId;

            ThreadFlow flow;
            if (!FlowMap.TryGetValue(thread, out flow))
            {
                LogError("Init Error 1");
                return;
            }

            if (flow.Pos < 0)
            {
                LogError("Init Error 2");
                return;
            }

            XNodeIn sourceClass = null;

            // travel up stack until we find something we know and mark that as the source of the init
            for (int i = flow.Pos; i >= 0; i--)
            {
                int source = flow.Stack[i].NodeID;

                var srcNode = Nodes[source];
                if (srcNode == null)
                    continue;

                sourceClass = GetContainingClass(srcNode) as XNodeIn;
                if (sourceClass != null && sourceClass != node)
                    break;
            }

            if (sourceClass == null)
            {
                LogError("Init Error 3");
                return;
            }

            if (node.ObjType != XObjType.Class)
            {
                LogError("Init Error 4");
                return;
            }

            if (sourceClass == node)
            {
                LogError("Init Error 5 " + node.Name); //? class could create itself...
                return;
            }

            CheckCreateInit(sourceClass, node);
        }
예제 #9
0
        public static FunctionCall CreateNewCall(int hash, int sourceID, XNodeIn dest)
        {
            var call = new FunctionCall() { ID = hash, Source = sourceID, Destination = dest.ID };
            CallMap.Add(hash, call);

            // add link to node that its been called
            dest.AddFunctionCall(ref dest.CalledIn, sourceID, call);

            var source = Nodes[sourceID];
            source.AddFunctionCall(ref source.CallsOut, dest.ID, call);

            //***** new location of create of class to class add function call

            CreateLayerCall(source, dest);

            if (Remote != null)
                foreach (var client in Remote.SyncClients)
                    lock(client.NewCalls)
                        client.NewCalls.Add(new Tuple<int, int>(sourceID, dest.ID));

            CallChange = true;

            if (!ClassTracking)
                return call;

            var srcNode = Nodes[call.Source];
            if (srcNode == null)
                return call;

            var sourceClass = GetContainingClass(srcNode) as XNodeIn;
            var destClass = GetContainingClass(dest) as XNodeIn;

            if (sourceClass == destClass)
                return call;

            if (destClass.ObjType != XObjType.Class || sourceClass.ObjType != XObjType.Class)
            {
                LogError("parent not class type, {0} and {1}", destClass.ObjType, sourceClass.ObjType);
                return call;
            }

            hash = sourceClass.ID * FunctionCount + destClass.ID;

            call.ClassCallHash = hash;

            //LogError("Adding to class map {0} -> {1} with hash {2}", sourceClass.ID, destClass.ID, hash);

            var classCall = new FunctionCall() { ID = hash, Source = sourceClass.ID, Destination = destClass.ID };
            ClassCallMap.Add(hash, classCall);

            destClass.AddFunctionCall(ref destClass.CalledIn, sourceClass.ID, classCall);
            sourceClass.AddFunctionCall(ref sourceClass.CallsOut, destClass.ID, classCall);

            return call;
        }
예제 #10
0
        private static void SetCovered(XNodeIn node)
        {
            node.HitSequence = CurrentSequence++;

            CoverChange = true;

            Utilities.IterateParents<XNode>(
                node,
                n => CoveredNodes[n.ID] = true,
                n => n.Parent);

            // clear cover change on paint
        }
예제 #11
0
        private static void TrackFunctionCall(int nodeID, XNodeIn node, int thread)
        {
            // check that thread is in map
            ThreadFlow flow;
            if (!FlowMap.TryGetValue(thread, out flow))
            {
                flow = new ThreadFlow()
                {
                    ThreadID = thread,
                    Name = node.Name,
                    Handle = Thread.CurrentThread,
                    IsAlive = true
                };

                FlowMap.Add(thread, flow);

                if (Remote != null)
                    foreach (var client in Remote.SyncClients)
                        lock(client.NewThreads)
                            client.NewThreads[flow.ThreadID] = new Tuple<string,bool>(flow.Name, flow.IsAlive);
            }

            bool isMethod = (node.ObjType == XObjType.Method);

            if(isMethod)
                node.StillInside++;

            // if the first entry, return here
            if (flow.Pos == -1)
            {
                flow.CreateStackItem(nodeID, null, Watch.ElapsedTicks, isMethod, ThreadlineEnabled);
                node.EntryPoint++;
                return;
            }

            // if exceeded tracking max return
            if (flow.Pos >= flow.Stack.Length)
                return;

            // set the source, and put the dest in stack
            int source = flow.Stack[flow.Pos].NodeID;

            // the ids are small and auto-inc based on the # of funcs
            // just hashing together is not unique enough, and many conflicts because the numbers
            // are small and close together. so expand the number to a larger domain.
            // also ensure s->d != d->s
            int hash = source * FunctionCount + nodeID;

            FunctionCall call;
            if (!CallMap.TryGetValue(hash, out call))
                call = CreateNewCall(hash, source, node);

            if (source != call.Source || nodeID != call.Destination)
                LogError("Call mismatch  {0}->{1} != {2}->{3}\r\n", source, nodeID, call.Source, call.Destination);

            call.Hit = ShowTicks;
            call.TotalHits++;

            if (!call.ThreadIDs.Contains(thread))
            {
                call.ThreadIDs.Add(thread);

                if (Remote != null)
                    foreach (var client in Remote.SyncClients)
                        lock(client.CallThreads)
                            client.CallThreads.Add(new Tuple<int, int>(call.ID, thread));
            }

            if (Remote != null)
                foreach (var sync in Remote.SyncClients)
                    lock(sync.CallHits)
                        sync.CallHits.Add(hash);

            // if a method
            if (isMethod)
                call.StillInside++;

            flow.CreateStackItem(nodeID, call, Watch.ElapsedTicks, isMethod, ThreadlineEnabled);

            if(ClassTracking)
                TrackClassCall(call, thread);
        }
예제 #12
0
        private static void TrackInit(XNodeIn node)
        {
            int thread = 0;
            if (ThreadTracking)
                thread = Thread.CurrentThread.ManagedThreadId;

            ThreadFlow flow;
            if (!FlowMap.TryGetValue(thread, out flow))
            {
                LogError("Init Error 1");
                return;
            }

            if (flow.Pos < 0)
            {
                LogError("Init Error 2");
                return;
            }

            XNodeIn sourceClass = null;

            // travel up stack until we find something we know and mark that as the source of the init
            for (int i = flow.Pos; i >= 0; i--)
            {
                int source = flow.Stack[i].NodeID;

                var srcNode = Nodes[source];
                if (srcNode == null)
                    continue;

                sourceClass = GetContainingClass(srcNode) as XNodeIn;
                if (sourceClass != null && sourceClass != node)
                    break;
            }

            if (sourceClass == null)
            {
                LogError("Init Error 3");
                return;
            }

            if (node.ObjType != XObjType.Class)
            {
                LogError("Init Error 4");
                return;
            }

            if (sourceClass == node)
            {
                LogError("Init Error 5 " + node.Name); //? class could create itself...
                return;
            }

            // link
            int hash = sourceClass.ID * FunctionCount + node.ID;

            FunctionCall call;
            if (!InitMap.TryGetValue(hash, out call))
            {
                //LogError("Adding to init map {0} -> {1} with hash {2}", sourceClass.ID, node.ID, hash);

                call = new FunctionCall() { Source = sourceClass.ID, Destination = node.ID };
                InitMap.Add(hash, call);

                if (node.InitsBy == null)
                    node.InitsBy = new HashSet<int>();

                if (sourceClass.InitsOf == null)
                    sourceClass.InitsOf = new HashSet<int>();

                node.InitsBy.Add(sourceClass.ID);
                sourceClass.InitsOf.Add(node.ID);
            }
        }
예제 #13
0
        static bool LoadNodeMap()
        {
            RootNode = null;
            FunctionCount = 0;
            Dictionary<int, XNodeIn> map = new Dictionary<int, XNodeIn>();

            try
            {
                var dependenciesFrom = new Dictionary<int, List<int>>();

                using (FileStream stream = new FileStream(DatPath, FileMode.Open))
                {
                    while (stream.Position < stream.Length)
                    {
                        long startPos = stream.Position;

                        int totalSize;
                        XPacketType type = XNodeIn.ReadNextPacket(stream, out totalSize);

                        stream.Position = startPos;

                        if (type == XPacketType.Setting)
                        {
                            string name, value;
                            XNodeIn.ReadSetting(stream, out name, out value);

                            Settings[name] = value;
                        }
                        else if (type == XPacketType.Node)
                        {
                            XNodeIn node = XNodeIn.ReadNode(stream);
                            map[node.ID] = node;

                            // first node read is the root
                            if (RootNode == null)
                                RootNode = node;

                            else if (map.ContainsKey(node.ParentID))
                            {
                                node.Parent = map[node.ParentID];
                                node.Parent.Nodes.Add(node);
                            }
                            else
                                LogError("Could not find parent {0} or {1}", node.Parent, node.Name);

                            if (node.ID > FunctionCount)
                                FunctionCount = node.ID;

                            // create converse dependency edges
                            if (node.Dependencies != null)
                                foreach (var to in node.Dependencies)
                                {
                                    if (!dependenciesFrom.ContainsKey(to))
                                        dependenciesFrom[to] = new List<int>();

                                    dependenciesFrom[to].Add(node.ID);
                                }
                        }

                        stream.Position = startPos + totalSize;
                    }
                }

                FunctionCount++; // so id can be accessed in 0 based index

                Nodes = new XNodeIn[FunctionCount];
                foreach (var node in map.Values)
                    Nodes[node.ID] = node;

                foreach (var from in dependenciesFrom.Keys)
                    Nodes[from].Independencies = dependenciesFrom[from].ToArray();

                return true;
            }
            catch(Exception ex)
            {
                File.WriteAllText(Path.Combine(AppDir, "XRayError.txt"), "XRay::LoadNode - " + ex.Message + ":\r\n" + ex.StackTrace);
            }

            return false;
        }
예제 #14
0
        public static FunctionCall CreateNewCall(int hash, int sourceID, XNodeIn dest)
        {
            var call = new FunctionCall() { Source = sourceID, Destination = dest.ID };
            CallMap.Add(hash, call);

            // add link to node that its been called
            dest.AddFunctionCall(ref dest.CalledIn, sourceID, call);

            var source = Nodes[sourceID];
            source.AddFunctionCall(ref source.CallsOut, dest.ID, call);

            //***** new location of create of class to class add function call

            CreateLayerCall(source, dest);

            CallChange = true;

            return call;
        }
예제 #15
0
        public InstanceModel(XNodeIn node, string filter, Action updatedTree=null, Action<IFieldModel> expandedField=null)
        {
            SelectedNode = node;
            FieldFilter = filter;
            UpdatedTree = updatedTree;
            ExpandedField = expandedField;

            Columns.Add("Type");
            Columns.Add("Name");
        }
예제 #16
0
        static bool LoadNodeMap()
        {
            RootNode = null;
            FunctionCount = 0;

            try
            {
                var dependenciesFrom = new Dictionary<int, List<int>>();

                using (FileStream stream = new FileStream(DatPath, FileMode.Open))
                {
                    while (stream.Position < stream.Length)
                    {
                        long startPos = stream.Position;

                        int totalSize;
                        XPacketType type = XNodeIn.ReadNextPacket(stream, out totalSize);

                        stream.Position = startPos;

                        if (type == XPacketType.Setting)
                        {
                            string name, value;
                            XNodeIn.ReadSetting(stream, out name, out value);

                            Settings[name] = value;

                            if (name == "FunctionCount")
                            {
                                FunctionCount = int.Parse(value);

                                Nodes = new XNodeIn[FunctionCount];
                            }
                        }
                        else if (type == XPacketType.Node)
                        {
                            XNodeIn node = XNodeIn.ReadNode(stream);
                            Nodes[node.ID] = node;

                            // first node read is the root
                            if (RootNode == null)
                                RootNode = node;

                            else if (Nodes[node.ParentID] != null)
                            {
                                node.Parent = Nodes[node.ParentID];
                                node.Parent.Nodes.Add(node);
                            }
                            else
                                LogError("Could not find parent {0} or {1}", node.Parent, node.Name);

                            if (node.ID > FunctionCount)
                                FunctionCount = node.ID;

                            // create converse dependency edges
                            if (node.Dependencies != null)
                                foreach (var to in node.Dependencies)
                                {
                                    if (!dependenciesFrom.ContainsKey(to))
                                        dependenciesFrom[to] = new List<int>();

                                    dependenciesFrom[to].Add(node.ID);
                                }

                            if (node.ObjType == XObjType.Internal)
                            {
                                node.Record = new InstanceRecord();
                                node.Record.Add(typeof(XRay));
                            }
                        }

                        else if (type == XPacketType.CallMap || type == XPacketType.InitMap)
                        {
                            stream.Read(4); // re-read total size
                            stream.Read(1); // re-read packet type

                            int count = BitConverter.ToInt32(stream.Read(4), 0);

                            for (int i = 0; i < count; i++)
                            {
                                int source = BitConverter.ToInt32(stream.Read(4), 0);
                                int dest = BitConverter.ToInt32(stream.Read(4), 0);

                                int hash = PairHash(source, dest);

                                if (type == XPacketType.CallMap)
                                    CreateNewCall(hash, source, Nodes[dest]);
                                else
                                    CheckCreateInit(Nodes[source], Nodes[dest]);
                            }
                        }

                        stream.Position = startPos + totalSize;
                    }
                }

                foreach (var from in dependenciesFrom.Keys)
                    Nodes[from].Independencies = dependenciesFrom[from].ToArray();

                return true;
            }
            catch(Exception ex)
            {
                File.WriteAllText(Path.Combine(AppDir, "XRayError.txt"), "XRay::LoadNode - " + ex.Message + ":\r\n" + ex.StackTrace);
            }

            return false;
        }
예제 #17
0
        public static void TrackClassCall(XNodeIn node, int source, int thread)
        {
            var srcNode = Nodes[source];
            if (srcNode == null)
                return;

            var sourceClass = GetContainingClass(srcNode) as XNodeIn;
            var destClass = GetContainingClass(node) as XNodeIn;

            if (sourceClass == destClass)
                return;

            if (destClass.ObjType != XObjType.Class || sourceClass.ObjType != XObjType.Class)
            {
                LogError("parent not class type, {0} and {1}", destClass.ObjType, sourceClass.ObjType);
                return;
            }

            int hash = sourceClass.ID * FunctionCount + destClass.ID;

            FunctionCall call;
            if (!ClassCallMap.TryGetValue(hash, out call))
            {
                //LogError("Adding to class map {0} -> {1} with hash {2}", sourceClass.ID, destClass.ID, hash);

                call = new FunctionCall() { Source = sourceClass.ID, Destination = destClass.ID };
                ClassCallMap.Add(hash, call);

                destClass.AddFunctionCall(ref destClass.CalledIn, sourceClass.ID, call);

                sourceClass.AddFunctionCall(ref sourceClass.CallsOut, destClass.ID, call);
            }

            call.ThreadIDs.Add(thread);
            call.Hit = ShowTicks;
            call.TotalHits++;
        }
예제 #18
0
        static bool LoadNodeMap(string path)
        {
            RootNode = null;
            DatPath = path;
            FunctionCount = 0;
            Dictionary<int, XNodeIn> map = new Dictionary<int, XNodeIn>();

            try
            {
                var dependenciesFrom = new Dictionary<int, List<int>>();

                using (FileStream stream = new FileStream(DatPath, FileMode.Open))
                {
                    while (stream.Position < stream.Length)
                    {
                        long startPos = stream.Position;

                        int totalSize;
                        XPacketType type = XNodeIn.ReadNextPacket(stream, out totalSize);

                        stream.Position = startPos;

                        if (type == XPacketType.Setting)
                        {
                            string name, value;
                            XNodeIn.ReadSetting(stream, out name, out value);

                            if (name == "Version")
                                BuilderVersion = value;
                            if (name == "Pro")
                                Pro.LoadFromString(value);
                        }
                        else if (type == XPacketType.Node)
                        {
                            XNodeIn node = XNodeIn.ReadNode(stream);
                            map[node.ID] = node;

                            // first node read is the root
                            if (RootNode == null)
                                RootNode = node;

                            else if (map.ContainsKey(node.ParentID))
                            {
                                node.Parent = map[node.ParentID];
                                node.Parent.Nodes.Add(node);
                            }
                            else
                                LogError("Could not find parent {0} or {1}", node.Parent, node.Name);

                            if (node.ID > FunctionCount)
                                FunctionCount = node.ID;

                            // create converse dependency edges
                            if (node.Dependencies != null)
                                foreach (var to in node.Dependencies)
                                {
                                    if (!dependenciesFrom.ContainsKey(to))
                                        dependenciesFrom[to] = new List<int>();

                                    dependenciesFrom[to].Add(node.ID);
                                }
                        }

                        stream.Position = startPos + totalSize;
                    }
                }

                FunctionCount++; // so id can be accessed in 0 based index

                Nodes = new XNodeIn[FunctionCount];
                foreach (var node in map.Values)
                    Nodes[node.ID] = node;

                foreach (var from in dependenciesFrom.Keys)
                    Nodes[from].Independencies = dependenciesFrom[from].ToArray();

                return true;
            }
            catch(Exception ex)
            {
                MessageBox.Show("XRay data file not found: " + ex.Message); // would this even work? test
            }

            return false;
        }
예제 #19
0
        public static XNodeIn ReadNode(FileStream stream)
        {
            // total size 4
            // name size 4
            // name x
            // type 4
            // value 4
            // external 1
            // anon 1
            // id 8
            // parent exist? 1
            //      parent id 4
            // dependencies? 1
            //      dependency count 4
            //      dependent ids 4x

            XNodeIn node = new XNodeIn();

            int totalSize = BitConverter.ToInt32(stream.Read(4), 0);

            int packetType = stream.ReadByte();

            Debug.Assert(packetType == (int)XPacketType.Node);

            node.Name = ReadString(stream);

            node.ObjType  = (XObjType)BitConverter.ToInt32(stream.Read(4), 0);
            node.Lines    = BitConverter.ToInt64(stream.Read(8), 0);
            node.External = BitConverter.ToBoolean(stream.Read(1), 0);
            node.IsAnon   = BitConverter.ToBoolean(stream.Read(1), 0);
            node.ID       = BitConverter.ToInt32(stream.Read(4), 0);

            // mod name for readability
            node.UnformattedName = node.Name;
            node.Name            = Utilities.FormatTemplateName(node.UnformattedName);

            if (node.ObjType == XObjType.Field)
            {
                int pos = node.Name.LastIndexOf(' ');
                if (pos != -1)
                {
                    node.UnformattedName = node.Name.Substring(pos + 1);
                }
            }

            bool hasParent = BitConverter.ToBoolean(stream.Read(1), 0);

            if (hasParent)
            {
                node.ParentID = BitConverter.ToInt32(stream.Read(4), 0);
            }

            node.ReturnID = BitConverter.ToInt32(stream.Read(4), 0);

            int paramCount = BitConverter.ToInt32(stream.Read(4), 0);

            if (paramCount > 0)
            {
                node.ParamIDs   = new int[paramCount];
                node.ParamNames = new string[paramCount];

                for (int i = 0; i < paramCount; i++)
                {
                    node.ParamIDs[i]   = BitConverter.ToInt32(stream.Read(4), 0);
                    node.ParamNames[i] = ReadString(stream);
                }
            }

            int dependencyCount = BitConverter.ToInt32(stream.Read(4), 0);

            if (dependencyCount > 0)
            {
                node.Dependencies = new int[dependencyCount];

                for (int i = 0; i < dependencyCount; i++)
                {
                    node.Dependencies[i] = BitConverter.ToInt32(stream.Read(4), 0);
                }
            }

            node.CSharpLength = BitConverter.ToInt32(stream.Read(4), 0);
            node.CSharpPos    = stream.Position;
            stream.Position  += node.CSharpLength;

            node.MsilLines = BitConverter.ToInt32(stream.Read(4), 0);
            if (node.MsilLines > 0)
            {
                node.MsilPos = stream.Position;
            }

            //stream.Position += node.MsilLines; // lines dont translate into bytes

            return(node);
        }
예제 #20
0
        private static void CheckCreateInit(XNodeIn sourceClass, XNodeIn classNode)
        {
            int hash = sourceClass.ID * FunctionCount + classNode.ID;

            FunctionCall call;
            if (!InitMap.TryGetValue(hash, out call))
            {
                //LogError("Adding to init map {0} -> {1} with hash {2}", sourceClass.ID, node.ID, hash);

                call = new FunctionCall() { ID = hash, Source = sourceClass.ID, Destination = classNode.ID };
                InitMap.Add(hash, call);

                if (classNode.InitsBy == null)
                    classNode.InitsBy = new HashSet<int>();

                if (sourceClass.InitsOf == null)
                    sourceClass.InitsOf = new HashSet<int>();

                classNode.InitsBy.Add(sourceClass.ID);
                sourceClass.InitsOf.Add(classNode.ID);

                if (Remote != null)
                    foreach (var client in Remote.SyncClients)
                        lock(client.Inits)
                            client.Inits.Add(new Tuple<int, int>(sourceClass.ID, classNode.ID));
            }
        }
예제 #21
0
        public static XNodeIn ReadNode(FileStream stream)
        {
            // total size 4
            // name size 4
            // name x
            // type 4
            // value 4
            // external 1
            // anon 1
            // id 8
            // parent exist? 1
            //      parent id 4
            // dependencies? 1
            //      dependency count 4
            //      dependent ids 4x

            XNodeIn node = new XNodeIn();

            int totalSize = BitConverter.ToInt32(stream.Read(4), 0);

            int packetType = stream.ReadByte();
            Debug.Assert(packetType == (int)XPacketType.Node);

            node.Name = ReadString(stream);

            node.ObjType =(XObjType) BitConverter.ToInt32(stream.Read(4), 0);
            node.Lines = BitConverter.ToInt64(stream.Read(8), 0);
            node.External = BitConverter.ToBoolean(stream.Read(1), 0);
            node.IsAnon = BitConverter.ToBoolean(stream.Read(1), 0);
            node.ID = BitConverter.ToInt32(stream.Read(4), 0);

            // mod name for readability
            node.UnformattedName = node.Name;
            node.Name = Utilities.FormatTemplateName(node.UnformattedName);

            if (node.ObjType == XObjType.Field)
            {
                int pos = node.Name.LastIndexOf(' ');
                if (pos != -1)
                    node.UnformattedName = node.Name.Substring(pos + 1);
            }

            bool hasParent = BitConverter.ToBoolean(stream.Read(1), 0);
            if(hasParent)
                node.ParentID = BitConverter.ToInt32(stream.Read(4), 0);

            node.ReturnID = BitConverter.ToInt32(stream.Read(4), 0);

            int paramCount = BitConverter.ToInt32(stream.Read(4), 0);
            if (paramCount > 0)
            {
                node.ParamIDs = new int[paramCount];
                node.ParamNames = new string[paramCount];

                for (int i = 0; i < paramCount; i++)
                {
                    node.ParamIDs[i] = BitConverter.ToInt32(stream.Read(4), 0);
                    node.ParamNames[i] = ReadString(stream);
                }
            }

            int dependencyCount = BitConverter.ToInt32(stream.Read(4), 0);
            if(dependencyCount > 0)
            {
                node.Dependencies = new int[dependencyCount];

                for (int i = 0; i < dependencyCount; i++)
                    node.Dependencies[i] = BitConverter.ToInt32(stream.Read(4), 0);
            }

            node.CSharpLength = BitConverter.ToInt32(stream.Read(4), 0);
            node.CSharpPos = stream.Position;
            stream.Position += node.CSharpLength;

            node.MsilLines = BitConverter.ToInt32(stream.Read(4), 0);
            if (node.MsilLines > 0)
                node.MsilPos = stream.Position;

            //stream.Position += node.MsilLines; // lines dont translate into bytes

            return node;
        }
예제 #22
0
        private static void CreateLayerCall(XNodeIn source, XNodeIn dest)
        {
            var sourceChain = source.GetParentChain();
            var destChain = dest.GetParentChain();

            for (int i = 0; i < sourceChain.Length; i++)
                for (int x = 0; x < destChain.Length; x++)
                    if (sourceChain[i] == destChain[x])
                    {
                        if (i == 0 || x == 0)
                        {
                            LogError(string.Format("Error trying to find common link between {0} and {1}, common had 0 index", sourceChain[i].Name, destChain[x].Name));
                            return;
                        }

                        var sourceLayer = sourceChain[i - 1];
                        var destLayer = destChain[x - 1];

                        if (sourceLayer.LayerOut == null)
                            sourceLayer.LayerOut = new HashSet<int>();

                        if (destLayer.LayerIn == null)
                            destLayer.LayerIn = new HashSet<int>();

                        sourceLayer.LayerOut.Add(destLayer.ID);
                        destLayer.LayerIn.Add(sourceLayer.ID);

                        return;
                    }
        }