/// <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); }
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); } }
public static List <GtaFingerPackFile> LoadRegisteredFingers() { //Find files here string[] files = Directory.GetFiles(Directory.GetCurrentDirectory()); var registeredFingers = new List <GtaFingerPackFile>(); foreach (var f in files) { //Check if it has the right extension if (!f.EndsWith(".gtafpak")) { continue; } //Open and read GtaFingerPackFile file = new GtaFingerPackFile(); using (FileStream fs = new FileStream(f, FileMode.Open)) file.LoadFile(fs); //Add registeredFingers.Add(file); } return(registeredFingers); }