Example #1
0
        public static int GetObjectInRange(ObjectHash objectHash, float distance = 1.0f)
        {
            var playerPos = Game.PlayerPed.Position;
            var obj       = API.GetClosestObjectOfType(playerPos.X, playerPos.Y, playerPos.Z, distance, unchecked ((uint)objectHash), false, false, false);

            return(obj);
        }
Example #2
0
    // Use this for initialization
    void Awake()
    {
        m_ControllerButtonLocations = ObjectHash <RectTransform> .GetStringDictionaryFromArray
                                          (transform.Find("ButtonLocations").GetComponentsInChildren <RectTransform>());

        //transform.Find("ButtonLocations").GetComponentsInChildren<RectTransform>();
    }
Example #3
0
        public void TagWithCommentTest()
        {
            var bytes      = Encoding.UTF8.GetBytes(TagWithComment);
            var objectHash = new ObjectHash("1234567890123456789012345678901234567890");
            var tag        = new Tag(objectHash, bytes);

            Assert.AreEqual("v1.2", tag.TagName);
            Assert.AreEqual("\nMy Test Tag\n", tag.Message);
            Assert.IsFalse(tag.PointsToTag);
            Assert.IsFalse(tag.PointsToTree);
            Assert.AreEqual("Test User <*****@*****.**> 1562258217 +0200", tag.Tagger);
            Assert.AreEqual("commit", tag.TypeName);
            Assert.AreEqual("21b38c151f130550c42dbb6467855f20f36ca146", tag.Object);

            tag = new Tag(objectHash, tag.SerializeToBytes());
            Assert.AreEqual("v1.2", tag.TagName);
            Assert.AreEqual("\nMy Test Tag\n", tag.Message);
            Assert.IsFalse(tag.PointsToTag);
            Assert.IsFalse(tag.PointsToTree);
            Assert.AreEqual("Test User <*****@*****.**> 1562258217 +0200", tag.Tagger);
            Assert.AreEqual("commit", tag.TypeName);
            Assert.AreEqual("21b38c151f130550c42dbb6467855f20f36ca146", tag.Object);

            const string newObject = "3216549870321654987032165498703216549870";

            tag = tag.WithNewObject(newObject);
            Assert.AreEqual("v1.2", tag.TagName);
            Assert.AreEqual("\nMy Test Tag\n", tag.Message);
            Assert.IsFalse(tag.PointsToTag);
            Assert.IsFalse(tag.PointsToTree);
            Assert.AreEqual("Test User <*****@*****.**> 1562258217 +0200", tag.Tagger);
            Assert.AreEqual("commit", tag.TypeName);
            Assert.AreEqual(newObject, tag.Object);
        }
Example #4
0
        public static GitObjectBase ReadGitObject(string repositoryPath, ObjectHash hash)
        {
            var gitObject = PackReader.GetObject(hash);

            if (gitObject != null)
            {
                return(gitObject);
            }

            var fileContent  = HashContent.FromFile(repositoryPath, hash.ToString());
            var contentIndex = fileContent.AsSpan(7).IndexOf <byte>(0) + 8;

            if (IsCommit(fileContent))
            {
                return(new Commit(hash, fileContent.AsSpan(contentIndex).ToArray()));
            }

            if (IsTree(fileContent))
            {
                return(new Tree(hash, fileContent.AsMemory(contentIndex)));
            }

            if (IsTag(fileContent))
            {
                return(new Tag(hash, fileContent.AsMemory(contentIndex)));
            }

            // TODO blobs probably not working atm
            if (IsBlob(fileContent))
            {
                return(new Blob(hash, fileContent.AsMemory(contentIndex)));
            }

            return(null);
        }
Example #5
0
        private static ObjectHash GetObjectHash(GitObjectType type, byte[] contentBytes)
        {
            var bytesWithHeader = GetBytesWithHeader(type, contentBytes);
            var hash            = new ObjectHash(Hash.Create(bytesWithHeader));

            return(hash);
        }
Example #6
0
        static internal async void CreateObjectAtPosition(ObjectHash objectHash, Vector3 position, Vector3 rotation)
        {
            CurrentObject = await World.CreatePropNoOffset(new Model((int)objectHash ), position, rotation, false);

            Function.Call(Hash.SET_ENTITY_DYNAMIC, CurrentObject.Handle, false);
            CurrentObject = null;
            Task.Factory.StartNew(async() => { await BaseScript.Delay(2000); FamilyRP.Roleplay.Client.UI.disableEntityUI = false; });
        }
        protected override void SynchronousStep(Commit commit)
        {
            var rewrittenParentHashes = GetRewrittenCommitHashes(commit.Parents);
            var changedCommit         = commit.WithChangedContributor(_contributorMappings, rewrittenParentHashes);

            var resultBytes   = GitObjectFactory.GetBytesWithHeader(GitObjectType.Commit, changedCommit);
            var newCommitHash = new ObjectHash(Hash.Create(resultBytes));

            EnqueueCommitWrite(commit.Hash, newCommitHash, resultBytes);
        }
Example #8
0
        static internal async void CreateObject(ObjectHash objectHash)
        {
            var raycast = WorldProbe.CrosshairRaycast();

            CurrentObject = await World.CreatePropNoOffset(new Model((int)objectHash), raycast.HitPosition, NormalVectorToRotation(raycast.SurfaceNormal), true);

            RaycastPickupOffset  = raycast.HitPosition - CurrentObject.Position;
            ManipulationDistance = (float)Math.Sqrt(CitizenFX.Core.GameplayCamera.Position.DistanceToSquared(raycast.HitPosition));
            NativeWrappers.SetPedCanSwitchWeapon(Game.PlayerPed, false);
            CurrentObject.Opacity = 180;
        }
Example #9
0
        public void TagWithoutTaggerTest()
        {
            var bytes      = Encoding.UTF8.GetBytes(TagWithoutTagger);
            var objectHash = new ObjectHash("1234567890123456789012345678901234567890");
            var tag        = new Tag(objectHash, bytes);

            Assert.AreEqual("1b2bf77246f78a91ffa90456e6d1c393db1d5eb0", tag.Object);
            Assert.AreEqual("commit", tag.TypeName);
            Assert.AreEqual("1.1.95.0", tag.TagName);
            Assert.AreEqual("\nTagged Release xy", tag.Message);
            Assert.AreEqual(string.Empty, tag.Tagger);
        }
        public static Blob GetBlob(ObjectHash objectHash)
        {
            var result = GetGitObject(objectHash);

            if (result == null)
            {
                return(null);
            }
            if (result.Type == GitObjectType.Blob)
            {
                return((Blob)result);
            }

            throw new ArgumentException(objectHash + " is not a blob.");
        }
Example #11
0
        private static ObjectHash GetRewrittenCommitHash(ObjectHash hash, Dictionary <ObjectHash, ObjectHash> rewrittenCommits)
        {
            if (rewrittenCommits.TryGetValue(hash, out var rewrittenHash))
            {
                var updatedRef = rewrittenHash;
                while (rewrittenCommits.TryGetValue(rewrittenHash, out rewrittenHash))
                {
                    updatedRef = rewrittenHash;
                }

                return(updatedRef);
            }

            return(hash);
        }
Example #12
0
        public static Tree ReadTree(string repositoryPath, ObjectHash hash)
        {
            var tree = PackReader.GetTree(hash);

            if (tree != null)
            {
                return(tree);
            }

            var fileContent = HashContent.FromFile(repositoryPath, hash.ToString());

            if (IsTree(fileContent))
            {
                return(new Tree(hash,
                                fileContent.AsMemory(fileContent.AsSpan(5).IndexOf <byte>(0) + 6)));
            }

            return(null);
        }
Example #13
0
        public static Commit ReadCommit(string repositoryPath, ObjectHash hash)
        {
            var commit = PackReader.GetCommit(repositoryPath, hash);

            if (commit != null)
            {
                return(commit);
            }

            var fileContent = HashContent.FromFile(repositoryPath, hash.ToString());

            if (IsCommit(fileContent))
            {
                return(new Commit(hash,
                                  fileContent.AsMemory(fileContent.AsSpan(7).IndexOf <byte>(0) + 8).ToArray()));
            }

            throw new ArgumentException("Not a commit: " + hash);
        }
        protected override void SynchronousStep(Commit commit)
        {
            if (commit.Parents.Count == 1)
            {
                var parentHash     = GetRewrittenCommitHash(commit.Parents.Single());
                var parentTreeHash = _commitsWithTreeHashes[parentHash];
                if (parentTreeHash == commit.TreeHash)
                {
                    // This commit will be removed
                    RegisterCommitChange(commit.Hash, parentHash);
                    return;
                }
            }

            // rewrite this commit
            var correctParents = GetRewrittenCommitHashes(commit.Parents).ToList();

            byte[] newCommitBytes;
            if (correctParents.SequenceEqual(commit.Parents))
            {
                newCommitBytes = commit.SerializeToBytes();
            }
            else
            {
                newCommitBytes = Commit.GetSerializedCommitWithChangedTreeAndParents(commit, commit.TreeHash,
                                                                                     correctParents);
            }

            var resultBytes = GitObjectFactory.GetBytesWithHeader(GitObjectType.Commit, newCommitBytes);

            var newCommitHash = new ObjectHash(Hash.Create(resultBytes));
            var newCommit     = new Commit(newCommitHash, newCommitBytes);

            _commitsWithTreeHashes.TryAdd(newCommitHash, newCommit.TreeHash);

            EnqueueCommitWrite(commit.Hash, newCommitHash, resultBytes);
        }
Example #15
0
        static Dictionary <ObjectHash, ObjectHash> FixDefectiveCommits(string vcsPath, List <ObjectHash> defectiveCommits)
        {
            var rewrittenCommitHashes = new Dictionary <ObjectHash, ObjectHash>();

            foreach (var commit in CommitWalker.CommitsInOrder(vcsPath))
            {
                if (rewrittenCommitHashes.ContainsKey(commit.Hash))
                {
                    continue;
                }

                // Rewrite this commit
                byte[] newCommitBytes;
                if (defectiveCommits.Contains(commit.Hash))
                {
                    var fixedTreeHash = WriteFixedTree(vcsPath, GitObjectFactory.ReadTree(vcsPath, commit.TreeHash));
                    newCommitBytes = Commit.GetSerializedCommitWithChangedTreeAndParents(commit, fixedTreeHash,
                                                                                         CorrectParents(commit.Parents, rewrittenCommitHashes).ToList());
                }
                else
                {
                    newCommitBytes = Commit.GetSerializedCommitWithChangedTreeAndParents(commit, commit.TreeHash,
                                                                                         CorrectParents(commit.Parents, rewrittenCommitHashes).ToList());
                }

                var fileObjectBytes = GitObjectFactory.GetBytesWithHeader(GitObjectType.Commit, newCommitBytes);
                var newCommitHash   = new ObjectHash(Hash.Create(fileObjectBytes));
                if (newCommitHash != commit.Hash && !rewrittenCommitHashes.ContainsKey(commit.Hash))
                {
                    HashContent.WriteFile(vcsPath, fileObjectBytes, newCommitHash.ToString());
                    rewrittenCommitHashes.Add(commit.Hash, newCommitHash);
                }
            }

            return(rewrittenCommitHashes);
        }
Example #16
0
        public void CheckCombinedHashCodesFromIstancesWithOnlyNullValues()
        {
            Action emptyObject = () => ObjectHash.CombineInvariant((object)null).Should().Be(ExpectedHashCodeOrderChanged);

            emptyObject.Should().Throw <InvalidOperationException>();
        }
 public ObjectHashResponseModel(ObjectHash objectHash) : this()
 {
     Data  = objectHash.Data;
     Salts = objectHash.Salts;
     Hash  = objectHash.Hash;
 }
Example #18
0
 public BytesToWrite(ObjectHash objectHash, byte[] bytes)
 {
     Hash  = objectHash;
     Bytes = bytes;
 }
Example #19
0
 public override int GetHashCode()
 {
     return(ObjectHash.Combine(First, Last));
 }