예제 #1
0
파일: Atlas.cs 프로젝트: incl/AssetPacker
        public Bitmap GenerateSpriteSheetImage(string path, int padding, bool npot, bool copyBorder)
        {
            List <string> paths = GetImagePaths(path);

            if (paths.Count == 0)
            {
                return(null);
            }

            List <ImagePair> images = GetImages(path, paths, copyBorder, padding);

            images = SortImages(images);
            Sprite root = PackImages(images);

            Sprites = Flatten(root);
            foreach (var sprite in Sprites)
            {
                if (Offsets.ContainsKey(sprite.ImageName))
                {
                    Offset offset = Offsets[sprite.ImageName];
                    sprite.Offset.X = offset.X;
                    sprite.Offset.Y = offset.Y;
                }
            }
            int width  = root.Rect.W;
            int height = root.Rect.H;

            if (npot)
            {
                width = height = NearestPowerOfTwo(Math.Max(width, height));
            }
            image = new Bitmap(width, height);
            var gr = Graphics.FromImage(image);

            gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            root.Render(gr);
            return(image);
        }
        public override object GetData(HookProcess process)
        {
            if (baseAddress.ToInt64() <= 6496)
            {
                return(null);
            }
            if (!Offsets.ContainsKey("SourceSize") || !Offsets.ContainsKey("EntityCount"))
            {
                Console.WriteLine("Couldn't find basic");
                return(null);
            }

            if (!Offsets.ContainsKey("ID") || !Offsets.ContainsKey("Type"))
            {
                Console.WriteLine("Couldn't find player basic");
                return(null);
            }

            var data = new SigActorsData();

            int sourceSize = (int)Offsets["SourceSize"];
            int limit      = (int)Offsets["EntityCount"];
            int ptrSize    = 8; // 64 bit

            byte[] characterAddressMap = process.GetByteArray(baseAddress, ptrSize * limit);
            //byte[] baseSource = process.GetByteArray(baseAddress, sourceSize);

            Dictionary <IntPtr, IntPtr> uniqueAddresses = new Dictionary <IntPtr, IntPtr>();
            IntPtr firstAddress = IntPtr.Zero;

            var firstTime = true;

            for (var i = 0; i < limit; i++)
            {
                IntPtr characterAddress = new IntPtr(BitConverter.TryToInt64(characterAddressMap, ptrSize * i));
                if (characterAddress == IntPtr.Zero)
                {
                    continue;
                }

                if (firstTime)
                {
                    firstAddress = characterAddress;
                    firstTime    = false;
                }

                uniqueAddresses[characterAddress] = characterAddress;
            }

            // Add everyone to removed
            foreach (KeyValuePair <uint, ActorData> kvp in tempActors)
            {
                data.removedActors.Add(kvp.Key, new ActorData()
                {
                    id = kvp.Value.id,
                });
            }

            foreach (KeyValuePair <IntPtr, IntPtr> kvp in uniqueAddresses)
            {
                var    characterAddress = new IntPtr(kvp.Value.ToInt64());
                byte[] playerSource     = process.GetByteArray(characterAddress, sourceSize);

                ActorData existing  = null;
                ActorData actorData = new ActorData()
                {
                    id = BitConverter.TryToUInt32(playerSource, Offsets["ID"]),
                };
                bool addActor = false;
                int  type     = playerSource[Offsets["Type"]];
                if (type == 0x01)   // Player
                {
                    if (data.removedActors.ContainsKey(actorData.id))
                    {
                        data.removedActors.Remove(actorData.id);
                        tempActors.TryGetValue(actorData.id, out existing);
                    }
                    else
                    {
                        addActor = true;
                    }

                    // Was used for TargetID
                    //var isFirstEntry = kvp.Value.ToInt64() == firstAddress.ToInt64();

                    if (true)
                    {
                        if (Offsets.TryGetValue("Name", out int nameid))
                        {
                            actorData.name = process.GetStringFromBytes(playerSource, nameid);
                        }
                        if (Offsets.TryGetValue("PerformanceID", out int perfid))
                        {
                            actorData.perfid = playerSource[perfid];
                        }
                    }

                    if (actorData.id != 0)
                    {
                        if (expiringActors.ContainsKey(actorData.id))
                        {
                            expiringActors.Remove(actorData.id);
                        }
                    }
                    else
                    {
                        // Removed
                        data.addedActors.Remove(actorData.id);
                        continue;
                    }

                    // Only getting memory, no checks?
                    //EnsureMapAndZone(entry);

                    /*
                     * if (isFirstEntry) {
                     *  if (targetAddress.ToInt64() > 0) {
                     *      byte[] targetInfoSource = MemoryHandler.Instance.GetByteArray(targetAddress, 128);
                     *      entry.TargetID = (int)BitConverter.TryToUInt32(targetInfoSource, MemoryHandler.Instance.Structures.ActorItem.ID);
                     *  }
                     * }
                     */

                    // If removed player, just continue
                    if (existing != null)
                    {
                        continue;
                    }
                    if (addActor)
                    {
                        if (!tempActors.ContainsKey(actorData.id))
                        {
                            tempActors.Add(actorData.id, actorData);
                        }
                        data.addedActors.Add(actorData.id, actorData);
                    }
                }
            }

            // Stale removal?

            DateTime now = DateTime.Now;
            TimeSpan staleActorRemovalTime = TimeSpan.FromSeconds(0.25);

            foreach (KeyValuePair <uint, ActorData> kvp2 in data.removedActors)
            {
                if (!expiringActors.ContainsKey(kvp2.Key))
                {
                    expiringActors[kvp2.Key] = now + staleActorRemovalTime;
                }
            }
            // check expiring list for stale actors
            foreach (KeyValuePair <uint, DateTime> kvp2 in expiringActors.ToList())
            {
                if (now > kvp2.Value)
                {
                    tempActors.Remove(kvp2.Key);
                    expiringActors.Remove(kvp2.Key);
                }
                else
                {
                    data.removedActors.Remove(kvp2.Key);
                }
            }

            data.currentActors = tempActors;
            return(data);
        }
예제 #3
0
        public Dictionary <Tuple <int, int>, double> CalculateRodOffsets()
        {
            Offsets.Clear();

            for (int vStart = 0; vStart < Vertices.Count; vStart++)
            {
                var connectedVertices = Edges.Where(e => e.Item1 == vStart).Select(e => e.Item2).ToList();
                connectedVertices.AddRange(Edges.Where(e => e.Item2 == vStart).Select(e => e.Item1).ToList());

                if (connectedVertices.Count == 1)
                {
                    var key = Tuple.Create(vStart, connectedVertices[0]);

                    if (Offsets.ContainsKey(key))
                    {
                        Offsets[key] = Math.Max(Radius / 2, Offsets[key]);
                    }
                    else
                    {
                        Offsets[key] = Radius / 2;
                    }
                }
                else
                {
                    for (int vEnd = 0; vEnd < connectedVertices.Count; vEnd++)
                    {
                        for (int vCompare = vEnd + 1; vCompare < connectedVertices.Count; vCompare++)
                        {
                            var key1 = Tuple.Create(vStart, connectedVertices[vEnd]);
                            var key2 = Tuple.Create(vStart, connectedVertices[vCompare]);

                            var vec1 = Vertices[connectedVertices[vEnd]] - Vertices[vStart];
                            var vec2 = Vertices[connectedVertices[vCompare]] - Vertices[vStart];

                            var cosAng = (vec1.X * vec2.X + vec1.Y * vec2.Y + vec1.Z * vec2.Z) / (vec1.Length * vec2.Length);
                            var sinAng = Math.Sqrt(Math.Pow(vec1.Length * vec2.Length, 2) -
                                                   Math.Pow(vec1.X * vec2.X + vec1.Y * vec2.Y + vec1.Z * vec2.Z, 2)) / (vec1.Length * vec2.Length);

                            double offset = 0;
                            if (Double.IsNaN(sinAng) || sinAng == 0)
                            {
                                offset = JointThickness + Tolerance;
                            }
                            else if (cosAng <= 0)
                            {
                                offset = Math.Max(JointThickness + Tolerance, OuterWallRadius * sinAng);
                            }
                            else
                            {
                                var off = 1 / sinAng * Math.Sqrt(OuterWallRadius * OuterWallRadius + InnerWallRadius * InnerWallRadius +
                                                                 2 * OuterWallRadius * InnerWallRadius * cosAng - InnerWallRadius * InnerWallRadius * sinAng * sinAng);

                                offset = Math.Max(JointThickness + Tolerance, off);
                            }

                            if (Offsets.ContainsKey(key1))
                            {
                                Offsets[key1] = Math.Max(offset, Offsets[key1]);
                            }
                            else
                            {
                                Offsets[key1] = offset;
                            }

                            if (Offsets.ContainsKey(key2))
                            {
                                Offsets[key2] = Math.Max(offset, Offsets[key2]);
                            }
                            else
                            {
                                Offsets[key2] = offset;
                            }
                        }
                    }
                }
            }

            return(Offsets);
        }