Esempio n. 1
0
        public bool LoadFile(Stream s)
        {
            //Read file headers
            if (_ReadUInt(s) != 1178686535)
            {
                return(false);
            }
            if (_ReadUShort(s) != 0)
            {
                return(false);
            }
            challenges    = new GtaFingerprintChallenge[_ReadUShort(s)];
            modified_utc  = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(_ReadUInt(s));
            screen_width  = _ReadUShort(s);
            screen_height = _ReadUShort(s);

            //Read name
            name = _ReadString(s);

            //Read finger
            finger = new GtaFingerprintTarget(_LoadMask(s));

            //Read challeneges
            for (int i = 0; i < challenges.Length; i++)
            {
                challenges[i] = new GtaFingerprintChallenge(_LoadMask(s));
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Finds which file has the closest matching finger to this one
        /// </summary>
        /// <param name="target"></param>
        private GtaFingerPackFile FindMatchingFinger(GtaFingerprintTarget target)
        {
            //Find finger with the highest match
            GtaFingerPackFile highestMatch = null;
            int highestMatchValue          = int.MinValue;

            foreach (var f in registeredFingers)
            {
                //Get challenege
                var c = f.finger;

                //Resize the mask of the finger
                bool[,] targetMask = target.ResizeDataArray(c.width, c.height);

                //Loop through and generate an number to tell us how closely this matches
                int value = 0;
                for (int x = 0; x < c.width; x++)
                {
                    for (int y = 0; y < c.height; y++)
                    {
                        //Check
                        bool isMatch = targetMask[x, y] == c.data[x, y];
                        if (isMatch)
                        {
                            value++;
                        }
                        else
                        {
                            value--;
                        }
                    }
                }

                //Check if this is the best match
                if (value > highestMatchValue)
                {
                    highestMatchValue = value;
                    highestMatch      = f;
                }
            }

            //Validate
            if (highestMatch == null)
            {
                throw new Exception("Could not find any fingers!");
            }

            return(highestMatch);
        }
Esempio n. 3
0
        public GtaReaderSession(List <GtaFingerPackFile> registeredFingers, Bitmap screenshotBitmap, bool isWindowed)
        {
            //Set
            this.registeredFingers = registeredFingers;
            this.isWindowed        = isWindowed;

            //Open GTA screenshot
            screenshot = new GtaScreenshot(screenshotBitmap, isWindowed);

            //Get screen challenges
            screenChallenges = new List <GtaFingerprintChallenge>();
            for (int x = 0; x < 2; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    screenChallenges.Add(screenshot.GetComponent(x, y));
                }
            }

            //Determine which file this is
            screenTarget = screenshot.GetCloneTarget();
            file         = FindMatchingFinger(screenTarget);

            //Run check on each registered finger
            matches = new List <GtaFingerprintChallenge>();
            List <GtaFingerprintChallenge> workingScreenChallenges = new List <GtaFingerprintChallenge>();

            workingScreenChallenges.AddRange(screenChallenges);
            foreach (var f in file.challenges)
            {
                //Find
                var match = FindMatchingTarget(f, workingScreenChallenges.ToArray());

                //Remove from list so we don't find it again
                workingScreenChallenges.Remove(match);

                //Add
                matches.Add(match);
                Console.WriteLine("X: " + match.fingerX + ", Y: " + match.fingerY);
            }
        }