ARKBreedingStats.ArkOCR.calibrate C# (CSharp) Method

calibrate() public method

public calibrate ( Bitmap screenshot ) : bool
screenshot System.Drawing.Bitmap
return bool
        public bool calibrate(Bitmap screenshot)
        {
            Process[] p = Process.GetProcessesByName("ShooterGame");
            if (p.Length > 0)
                ARKProcess = p[0];

            if (screenshot == null)
                return false;

            if (screenshot.Width == calibrationResolution[0] && screenshot.Height == calibrationResolution[1])
                return true;

            //debugPanel.Controls.Clear();
            //alphabet = new Bitmap[3,255];
            hashMap = new Dictionary<long, List<byte>>();
            statPositions = new Dictionary<string, Point>(9);

            // positions depend on screen resolution.
            int resolution = 0;
            Win32Stuff.Rect res = new Win32Stuff.Rect(); // Win32Stuff.GetWindowRect("ShooterGame");
            if (screenshot != null)
            {
                res.left = 0;
                res.right = screenshot.Width;
                res.top = 0;
                res.bottom = screenshot.Height;
            }
            else
                return false; // error

            if (res.Width == 1920 && res.Height == 1080)
                resolution = 0;
            else if (res.Width == 1680 && res.Height == 1050)
                resolution = 1;
            else if (res.Width == 1600 && res.Height == 900)
                resolution = 2;
            else
            {
                resolution = -1;
                return false; // no supported resolution
            }

            if (currentResolution == resolution)
                return true;

            switch (resolution)
            {
                case 0:
                    // coords for 1920x1080
                    statPositions["NameAndLevel"] = new Point(1280, 170);
                    statPositions["Health"] = new Point(1355, 630);
                    statPositions["Stamina"] = new Point(1355, 665);
                    statPositions["Oxygen"] = new Point(1355, 705);
                    statPositions["Food"] = new Point(1355, 740);
                    statPositions["Weight"] = new Point(1355, 810);
                    statPositions["Melee Damage"] = new Point(1355, 845);
                    statPositions["Movement Speed"] = new Point(1355, 885);
                    statPositions["Torpor"] = new Point(1355, 990);
                    statPositions["CurrentWeight"] = new Point(805, 231); // central version of weight, gives "temporary maximum", useful for determining baby %age
                    statPositions["Imprinting"] = new Point(1260, 594);
                    break;

                case 1:
                    // coords for 1680x1050
                    // 1680/1920 = height-factor; 50 = translation
                    // not yet correct x_1080 |--> (x_1080+60)*1680/1920
                    //statPositions["NameAndLevel"] = new Point(1111, 200);
                    //statPositions["Health"] = new Point(1183, 595);
                    //statPositions["Stamina"] = new Point(1183, 630);
                    //statPositions["Oxygen"] = new Point(1183, 665);
                    //statPositions["Food"] = new Point(1183, 691);
                    //statPositions["Weight"] = new Point(1183, 755);
                    //statPositions["Melee Damage"] = new Point(1183, 788);
                    //statPositions["Movement Speed"] = new Point(1183, 817);
                    //statPositions["Torpor"] = new Point(1183, 912);

                    // version without the "statName:"
                    coordsAfterDot = true;
                    statPositions["NameAndLevel"] = new Point(1111, 200);
                    statPositions["Health"] = new Point(1260, 595);
                    statPositions["Stamina"] = new Point(1277, 630);
                    statPositions["Oxygen"] = new Point(1271, 665);
                    statPositions["Food"] = new Point(1249, 691);
                    statPositions["Weight"] = new Point(1264, 755);
                    statPositions["Melee Damage"] = new Point(1340, 788);
                    statPositions["Movement Speed"] = new Point(1362, 817);
                    statPositions["Torpor"] = new Point(1260, 912);
                    statPositions["CurrentWeight"] = new Point(1, 1); // not correct, TODO
                    break;

                case 2:
                    // coords for 1600x960
                    statPositions["NameAndLevel"] = new Point(1130, 170);
                    statPositions["Health"] = new Point(1130, 550);
                    statPositions["Stamina"] = new Point(1130, 585);
                    statPositions["Oxygen"] = new Point(1130, 615);
                    statPositions["Food"] = new Point(1130, 645);
                    statPositions["Weight"] = new Point(1130, 705);
                    statPositions["Melee Damage"] = new Point(1130, 735);
                    statPositions["Movement Speed"] = new Point(1130, 765);
                    statPositions["Torpor"] = new Point(1130, 855);
                    statPositions["CurrentWeight"] = new Point(1, 1); // not correct, TODO
                    break;
            }
            calibrationResolution[0] = res.Width;
            calibrationResolution[1] = res.Height;

            currentResolution = resolution;

            /*
            AddBitmapToDebug(alphabet['µ']);
            AddBitmapToDebug(alphabet['%']);
            AddBitmapToDebug(alphabet['$']);
            AddBitmapToDebug(alphabet['A']);
            AddBitmapToDebug(alphabet['J']);
            AddBitmapToDebug(alphabet['µ']);
            AddBitmapToDebug(alphabet['?']);
            AddBitmapToDebug(alphabet['-']);
            AddBitmapToDebug(alphabet['[']);
            AddBitmapToDebug(alphabet['z']);
            AddBitmapToDebug(alphabet['(']);
            AddBitmapToDebug(alphabet[')']);
            AddBitmapToDebug(alphabet['f']);
            AddBitmapToDebug(alphabet['K']);

            */

            for (int l = 0; l < alphabet.GetLength(0); l++)
                foreach (char a in ":0123456789.,%/")
                    reducedAlphabet[l, a] = alphabet[l, a];

            return true;
        }