예제 #1
0
    public void should_ignore_special_tag([Values(null, "kind")] object?kind, [Values(null, "tag")] object?tag)
    {
        if (kind is null && tag is null)
        {
            Assert.Ignore("Impossible arguments combination");
        }

        // --arrange
        var unit1 = new UnitId(kind, tag);
        var unit2 = new UnitId(kind, SpecialTag.Any);

        // --assert
        unit1.Equals(unit2).Should().BeFalse();
        unit2.Equals(unit1).Should().BeFalse();
    }
예제 #2
0
        public bool validateDupplicateCode(out string msg)
        {
            msg = "";
            if (UnitId.Equals(Guid.Empty))
            {
                return(true);
            }
            currentUnit = UnitEdittingXDS.Session.GetObjectByKey <Unit>(UnitId);
            if (currentUnit == null)
            {
                throw new Exception(String.Format("Not existing data with UnitId {0}", UnitId));
            }
            string inputCode = txtUnitEditCode.Text.Trim();
            bool   flg       = Util.isExistXpoObject <Unit>("Code", inputCode, Utility.Constant.ROWSTATUS_INACTIVE, Utility.Constant.ROWSTATUS_ACTIVE, Utility.Constant.ROWSTATUS_DEFAULT);

            switch (MODE)
            {
            case "Edit":
                if (!currentUnit.Code.Equals(inputCode))
                {
                    if (flg)
                    {
                        msg = String.Format("Mã quy cách '{0}' đã tồn tại", txtUnitEditCode.Text.Trim());
                        return(false);
                    }
                }
                break;

            case "Add":
                if (flg)
                {
                    msg = String.Format("Mã quy cách '{0}' đã tồn tại", txtUnitEditCode.Text.Trim());
                    return(false);
                }
                break;

            default:
                break;
            }
            return(true);
        }
        /// <summary>
        /// Returns true if UserProvisionItem instances are equal
        /// </summary>
        /// <param name="other">Instance of UserProvisionItem to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(UserProvisionItem other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     UnitId == other.UnitId ||
                     UnitId != null &&
                     UnitId.Equals(other.UnitId)
                     ) &&
                 (
                     Roles == other.Roles ||
                     Roles != null &&
                     other.Roles != null &&
                     Roles.SequenceEqual(other.Roles)
                 ));
        }
예제 #4
0
        private List<UnitProduction> GetGUnitNumberOfQueuedUnit(Int32 iUnitNum, UnitId structureId)
        {
            _.Info("Assign Special Attributes Of Units", _.InfoImportance.Important);

            var lUnitIds = new List<UnitProduction>();

            /* Content of Abilities (pAbilities) */
            var iUnitAbilitiesPointer = Memory.ReadUInt32(MyOffsets.UnitStruct + 0xDC + MyOffsets.UnitStructSize * iUnitNum);
            /* BitConverter.ToUInt32(InteropCalls.Help_ReadProcessMemory(HStarcraft, MyOffsets.UnitStruct + 0xDC + MyOffsets.UnitStructSize * iUnitNum, 4), 0);*/

            /* Bitwise AND */
            iUnitAbilitiesPointer = iUnitAbilitiesPointer & 0xFFFFFFFC;

            var iAbilityCount = Memory.ReadInt16((int)iUnitAbilitiesPointer + 0x16);
            /*BitConverter.ToInt16(InteropCalls.Help_ReadProcessMemory(HStarcraft, (int)iUnitAbilitiesPointer + 0x16, 2),
                                 0);
            */

            /* Reading the Bytearray */

            /* Read the result of iUnitAbilitiesPointer (p1) */
            var iUnitAbilitiesPointerResult = Memory.ReadInt32(iUnitAbilitiesPointer);
            /*BitConverter.ToInt32(InteropCalls.Help_ReadProcessMemory(HStarcraft,
                                                                                             (int)iUnitAbilitiesPointer, 4),
                                                         0);*/

            /* Add 3 to that value */
            iUnitAbilitiesPointerResult += 3;

            try
            {
                Memory.ReadMemory(iUnitAbilitiesPointerResult, iAbilityCount);
            }

            catch
            {
                throw new Exception("If you read this, don't commit suicide! I f****d up - sorry.\n" +
                "Just report this thing!");
            }

            Int32 iIndexToLookAt = -1;
            var byteBuffer = Memory.ReadMemory(iUnitAbilitiesPointerResult, iAbilityCount);// InteropCalls.Help_ReadProcessMemory(HStarcraft, iUnitAbilitiesPointerResult, iAbilityCount);

            for (var i = 0; i < byteBuffer.Length; i++)
            {
            #if !DEBUG

                if (byteBuffer[i].Equals(0x19))
                {
                    iIndexToLookAt = i;

                    if (!structureId.Equals(UnitId.TbPlanetary))
                        break;
                }

            #else
                #region Debug/ Tests

                var _iContentOfPointer = Memory.ReadUInt32(iUnitAbilitiesPointer + 0x18 + 4*i);
                   /* BitConverter.ToUInt32(
                        InteropCalls.Help_ReadProcessMemory(HStarcraft, (Int32)iUnitAbilitiesPointer + 0x18 + 4 * i, 4),
                        0);*/

                // Number of queued Units
                var _iNumberOfQueuedUnits = Memory.ReadInt32(_iContentOfPointer + 0x28);
                    /*BitConverter.ToInt32(
                    InteropCalls.Help_ReadProcessMemory(HStarcraft, (Int32)_iContentOfPointer + 0x28, 4), 0);*/

                var _bReactorAttached = Memory.ReadInt32(_iContentOfPointer + 0x48);
                    /*BitConverter.ToInt32(
                InteropCalls.Help_ReadProcessMemory(HStarcraft, (Int32)_iContentOfPointer + 0x48, 4), 0) != 0
                                       ? true
                                       : false;*/

                var result2 = Memory.ReadUInt32(iUnitAbilitiesPointerResult - 3 + 0xA4 + (i*4));
                /*    BitConverter.ToUInt32(
                        InteropCalls.Help_ReadProcessMemory(HStarcraft, iUnitAbilitiesPointerResult - 3 + 0xA4 + (i * 4), 4), 0);
                */
                var resultOfResult2 = Memory.ReadUInt32(result2 + 4);
                  /*  BitConverter.ToUInt32(
                        InteropCalls.Help_ReadProcessMemory(HStarcraft, (UInt32)(result2 + 4), 4), 0);
                */

                var strAbilityName = Memory.ReadString(resultOfResult2, 16, Encoding.UTF8);
                   /* Encoding.UTF8.GetString(InteropCalls.Help_ReadProcessMemory(HStarcraft, resultOfResult2,
                        16));*/

                var _iArrayOfBytes = Memory.ReadInt32(_iContentOfPointer + 0x34);
                   /* BitConverter.ToInt32(
                        InteropCalls.Help_ReadProcessMemory(HStarcraft, (Int32)_iContentOfPointer + 0x34, 4), 0);
                */

                var _iTempPtr = Memory.ReadInt32(_iArrayOfBytes);
                   /* BitConverter.ToInt32(
                        InteropCalls.Help_ReadProcessMemory(HStarcraft, (Int32)_iArrayOfBytes, 4), 0);
                */

                var _productionChunk = Memory.ReadMemory(_iTempPtr, 0x80);
                   /* InteropCalls.Help_ReadProcessMemory(HStarcraft, _iTempPtr, 0x80);*/

                var _iType = BitConverter.ToInt32(_productionChunk, 0x44);
                var _iSupplyRaw = BitConverter.ToInt32(_productionChunk, 0x64);
                var _iTimeMax = BitConverter.ToUInt32(_productionChunk, 0x68);
                var _iTimeLeft = (float)BitConverter.ToUInt32(_productionChunk, 0x6C);
                var _iMineralCost = BitConverter.ToInt32(_productionChunk, 0x74);
                var _iVespineCost = BitConverter.ToInt32(_productionChunk, 0x78);

                var _iSomething = Memory.ReadInt32(_iContentOfPointer + 0x4);
                   /* BitConverter.ToInt32(
                        InteropCalls.Help_ReadProcessMemory(HStarcraft, (Int32) _iContentOfPointer + 0x4, 4), 0);
                */

                Debug.WriteLine("\n");
                Debug.WriteLine("i: " + i);
                Debug.WriteLine("iPointerResult - 3: 0x" + (iUnitAbilitiesPointerResult - 3).ToString("X8"));
                Debug.WriteLine("Result2 (0xA4): 0x" + result2.ToString("X8"));
                Debug.WriteLine("Result of Result2: 0x" + result2.ToString("X8"));
                Debug.WriteLine("Ability Name: " + strAbilityName);
                //Debug.WriteLine("NumberOfQueuedUnits: " + _iNumberOfQueuedUnits);
                //Debug.WriteLine("Bytebuffer Item: 0x" + byteBuffer[i].ToString("X2") + " - " + byteBuffer[i]);
                //Debug.WriteLine("Minerals: " + _iMineralCost);
                //Debug.WriteLine("Reactor Attached: " + _bReactorAttached);
                //Debug.WriteLine("iType: " + _iType);
                //Debug.WriteLine("Time Left: " + _iTimeLeft);
                //Debug.WriteLine("iContent of pointer: 0x" + _iContentOfPointer.ToString("X8"));
                //Debug.WriteLine("Temp ptr: 0x" + _iTempPtr.ToString("X8"));
                //Debug.WriteLine("iSometzhing: 0x" + _iSomething.ToString("X8"));

                #endregion

            #endif
            }

            /* Read the DATA Pointer (that leads to our result) */
            var iContentOfPointer = Memory.ReadUInt32(iUnitAbilitiesPointer + 0x18 + 4 * iIndexToLookAt);
            /*BitConverter.ToUInt32(
                InteropCalls.Help_ReadProcessMemory(HStarcraft, (Int32)iUnitAbilitiesPointer + 0x18 + 4 * iIndexToLookAt, 4), 0);*/

            /* Number of queued Units */
            var iNumberOfQueuedUnits = Memory.ReadInt32(iContentOfPointer + 0x28);
            /*   BitConverter.ToInt32(
               InteropCalls.Help_ReadProcessMemory(HStarcraft, (Int32) iContentOfPointer + 0x28, 4), 0);*/

            //Check if an addon is beeing added
            var bAddOnAttaching = Memory.ReadInt32(iContentOfPointer + 0x9C) == 260;

            var bReactorAttached = Memory.ReadInt32(iContentOfPointer + 0x48) != 0;
            /*  BitConverter.ToInt32(
              InteropCalls.Help_ReadProcessMemory(HStarcraft, (Int32) iContentOfPointer + 0x48, 4), 0) != 0;*/

            var iArrayOfBytes = Memory.ReadInt32(iContentOfPointer + 0x34);
            /* BitConverter.ToInt32(
                 InteropCalls.Help_ReadProcessMemory(HStarcraft, (Int32) iContentOfPointer + 0x34, 4), 0);*/

            var iTempPtr = Memory.ReadInt32(iArrayOfBytes);
            /*BitConverter.ToInt32(
                InteropCalls.Help_ReadProcessMemory(HStarcraft, iArrayOfBytes , 4), 0);*/

            /* Because it's possible that a Reactor builds two different units, we have to check that! */
            if (bReactorAttached && iNumberOfQueuedUnits > 1)
            {
                var iTempPtr2 = Memory.ReadInt32(iArrayOfBytes + 4);
                /*   BitConverter.ToInt32(
                   InteropCalls.Help_ReadProcessMemory(HStarcraft, iArrayOfBytes + 4, 4), 0);*/

                var productionChunk2 = Memory.ReadMemory(iTempPtr2, 0x80);
                /*InteropCalls.Help_ReadProcessMemory(HStarcraft, iTempPtr2, 0x80);*/

                var iType2 = BitConverter.ToInt32(productionChunk2, 0x44);
                var iSupplyRaw2 = BitConverter.ToInt32(productionChunk2, 0x64);
                var iTimeMax2 = BitConverter.ToUInt32(productionChunk2, 0x68);
                var iTimeLeft2 = (float)BitConverter.ToUInt32(productionChunk2, 0x6C);
                var iMineralCost2 = BitConverter.ToInt32(productionChunk2, 0x74);
                var iVespineCost2 = BitConverter.ToInt32(productionChunk2, 0x78);
                var iUnitIndexBuiltFrom2 = BitConverter.ToUInt16(productionChunk2, 0x5E) / 4;

                Console.WriteLine("Supply Raw: " + iSupplyRaw2);

                var prd2 = new UnitProduction();
                prd2.ProductionStatus = 100 - (iTimeLeft2 / iTimeMax2) * 100;
                prd2.Id = HelpFunctions.GetUnitIdFromLogicalId(structureId, iType2, (Int32)iTimeMax2, iMineralCost2, iVespineCost2, iSupplyRaw2 >> 12);
                prd2.ReactorAttached = bReactorAttached;
                prd2.UnitsInProduction = iNumberOfQueuedUnits;
                prd2.MineralCost = iMineralCost2;
                prd2.AttachingAddOn = bAddOnAttaching;
                prd2.VespineCost = iVespineCost2;
                prd2.SupplyRaw = iSupplyRaw2;
                prd2.Supply = iSupplyRaw2 >> 12;
                prd2.ProductionTimeLeft = iTimeLeft2 / 65536;

                lUnitIds.Add(prd2);
            }

            //That will happen if there is no unit to be build or something is morphing like a Hatch => Lair
            //Thus: Check if the sourcebuilding is a hatch or something..
            else if (iNumberOfQueuedUnits <= 0)
            {
                if (structureId.Equals(UnitId.ZbHatchery) ||
                    structureId.Equals(UnitId.ZbLiar) ||
                    structureId.Equals(UnitId.ZbSpire) ||
                    structureId.Equals(UnitId.ZuBroodlordCocoon) ||
                    structureId.Equals(UnitId.ZuOverseerCocoon) ||
                    structureId.Equals(UnitId.TbCcGround) ||
                    structureId.Equals(UnitId.PuMothershipCore) ||
                    structureId.Equals(UnitId.PuArchon))
                {
                    var iUnitCommandQueuePointer = Memory.ReadUInt32(MyOffsets.UnitStruct + 0xD4 + MyOffsets.UnitStructSize * iUnitNum);
                    /*InteropCalls.ReadUInt32(HStarcraft,
                    MyOffsets.UnitStruct + 0xD4 + MyOffsets.UnitStructSize * iUnitNum);*/

                    if (iUnitCommandQueuePointer > 0)
                    {
                        var iUnitCommandQueueChunk = Memory.ReadMemory(iUnitCommandQueuePointer + 0x98, 0xCC);
                        /*InteropCalls.Help_ReadProcessMemory(HStarcraft,
                            iUnitCommandQueuePointer + 0x98,
                            0xCC);
                        */
                        var iType2 = -1; //BitConverter.ToInt32(iUnitCommandQueueChunk, 0x44);
                        var iTimeMax2 = BitConverter.ToUInt32(iUnitCommandQueueChunk, 0x1C);
                        var iTimeLeft2 = (float)BitConverter.ToUInt32(iUnitCommandQueueChunk, 0);
                        var iMineralCost2 = BitConverter.ToInt32(iUnitCommandQueueChunk, 0xC4);
                        var iVespineCost2 = BitConverter.ToInt32(iUnitCommandQueueChunk, 0xC8);

                        var prd2 = new UnitProduction
                        {
                            Id =
                                HelpFunctions.GetUnitIdFromLogicalId(structureId, iType2, (Int32)iTimeMax2,
                                    iMineralCost2, iVespineCost2, 0),
                            MineralCost = iMineralCost2,
                            ProductionStatus = 100 - (iTimeLeft2 / iTimeMax2) * 100,
                            ProductionTimeLeft = iTimeLeft2 / 65536,
                            ReactorAttached = false,
                            Supply = 0,
                            SupplyRaw = 0,
                            UnitsInProduction = 0,
                            VespineCost = iVespineCost2
                        };

                        lUnitIds.Add(prd2);

                    }
                }
            }

            var productionChunk = Memory.ReadMemory(iTempPtr, 0x80);// InteropCalls.Help_ReadProcessMemory(HStarcraft, iTempPtr, 0x80);

            #region Debug and Tests

            // /* Read all 4- Bytes */

            // //var sw = new StreamWriter("Seeking.txt");
            // var strResult = "Looking for (Marine): 85 - (0x55)\n\n";

            // //sw.WriteLine(strResult);
            // for (var i = 0; i < productionChunk.Length / 4; i++)
            // {
            //     //strResult = String.Empty;

            //     //strResult += "0x" + (i * 4).ToString("X2");
            //     //strResult += ":";
            //     //strResult += (BitConverter.ToInt32(productionChunk, i * 4)).ToString() + " - (0x" +
            //     //             (BitConverter.ToInt32(productionChunk, i * 4)).ToString("X2") + ")";

            //     //sw.WriteLine(strResult);
            //     var iProbPtr = BitConverter.ToInt32(productionChunk, i * 4);
            //     var iResPtr = InteropCalls.Help_ReadProcessMemory(HStarcraft, iProbPtr, 4);

            //     var iInt32ResPtr = BitConverter.ToInt32(iResPtr, 0);

            //     //if (iInt32ResPtr != 0)
            //     //{
            //     //    var iChunk = InteropCalls.Help_ReadProcessMemory(HStarcraft, iInt32ResPtr, 0x80);

            //     //    strResult += "We are at: 0x" + iInt32ResPtr.ToString("X2") + "\n";

            //     //    for (var j = 0; j < 0x80/2; j++)
            //     //    {
            //     //        strResult += "0x" + (j*2).ToString("X2") + ": " + (BitConverter.ToUInt16(iChunk, j*2) / 4096).ToString() +
            //     //                     " - (0x" +
            //     //                     (BitConverter.ToUInt16(iChunk, j*2) / 4096).ToString("X2") + ")";
            //     //        strResult += "\n";

            //     //    }

            //     if (iInt32ResPtr != 0)
            //     {
            //         strResult += "0x" + (i * 4).ToString("X2");
            //         strResult += ":";
            //         strResult += ((BitConverter.ToInt32(productionChunk, i * 4) << 5) & 0xFFFFFFFC).ToString() + " - (0x" +
            //                      ((BitConverter.ToInt32(productionChunk, i * 4) << 5) & 0xFFFFFFFC).ToString("X2") + ")";
            //         strResult += "\n";
            //     }

            //     //}
            // }
            // MessageBox.Show(strResult);

            //// sw.Close();

            // //MessageBox.Show(strResult);

            #endregion

            var iType = BitConverter.ToInt32(productionChunk, 0x44);
            var iSupplyRaw = BitConverter.ToInt32(productionChunk, 0x64);
            var iTimeMax = BitConverter.ToUInt32(productionChunk, 0x68);
            var iTimeLeft = (float)BitConverter.ToUInt32(productionChunk, 0x6C);
            var iMineralCost = BitConverter.ToInt32(productionChunk, 0x74);
            var iVespineCost = BitConverter.ToInt32(productionChunk, 0x78);
            var iUnitIndexBuiltFrom = BitConverter.ToUInt16(productionChunk, 0x5E) / 4;
            var strType = Convert.ToString(iType, 16);

            var prd = new UnitProduction();
            prd.ProductionStatus = 100 - (iTimeLeft / iTimeMax) * 100;
            prd.Id = HelpFunctions.GetUnitIdFromLogicalId(structureId, iType, (Int32)iTimeMax, iMineralCost, iVespineCost, iSupplyRaw >> 12);
            prd.ReactorAttached = bReactorAttached;
            prd.UnitsInProduction = iNumberOfQueuedUnits;
            prd.MineralCost = iMineralCost;
            prd.VespineCost = iVespineCost;
            prd.SupplyRaw = iSupplyRaw;
            prd.Supply = iSupplyRaw >> 12;
            prd.ProductionTimeLeft = iTimeLeft / 65536;
            prd.AttachingAddOn = bAddOnAttaching;

            if (prd.Id != UnitId.None)
                lUnitIds.Add(prd);

            return lUnitIds;
        }
예제 #5
0
        public static UnitId GetUnitIdFromLogicalId(UnitId structureBuildFrom, Int32 logicalId, Int32 maximumTime, Int32 mineralCost, Int32 vespineCost, int supply)
        {
            if (logicalId.Equals(0))
                return UnitId.NbXelNagaTower;

            if (!logicalId.Equals(-1))
            {

                var strStuff = Convert.ToString(logicalId, 16);
                strStuff = "1" + strStuff.Substring(1);

                var inumber = int.Parse(strStuff, NumberStyles.HexNumber);

                logicalId = inumber;
            }

            #region Terran

            #region CC - Orbital - PF

            if (structureBuildFrom.Equals(UnitId.TbCcGround))
            {
                //E.G. Upgrade to Lair/ Hive
                if (logicalId == -1)
                {
                    if (mineralCost == 150 && vespineCost == 0)
                        return UnitId.TupUpgradeToOrbital;

                    if (mineralCost == 150 && vespineCost == 150)
                        return UnitId.TupUpgradeToPlanetary;
                }

                return UnitId.TuScv;
            }

            if (structureBuildFrom.Equals(UnitId.TbPlanetary))
                return UnitId.TuScv;

            if (structureBuildFrom.Equals(UnitId.TbOrbitalGround))
                return UnitId.TuScv;

            #endregion

            #region Barracks

            if (structureBuildFrom.Equals(UnitId.TbBarracksGround))
            {
                /* Database for the units from the Barracks
                 * Unit         |   Time    |   Min |   Ves |   Sup
                 * -------------|-----------|-------|-------|-------
                 * Marine       |1638400    |   50  |   0   |   1
                 * Reaper       |2949120    |   50  |   50  |   1
                 * Marauder     |1966080    |   100 |   25  |   2
                 * Ghost        |2621440    |   200 |   100 |   2
                 * */

                switch (maximumTime)
                {
                    case 1638400:
                        return UnitId.TuMarine;

                    case 2949120:
                        return UnitId.TuReaper;

                    case 2621440:
                        return UnitId.TuGhost;

                    case 1966080:
                        return UnitId.TuMarauder;
                }
            }

            #endregion

            #region Factory

            else if (structureBuildFrom.Equals(UnitId.TbFactoryGround))
            {
                /* Database for the units from the Barracks
                * Unit         |   Time    |   Min |   Ves |   Sup
                * -------------|-----------|-------|-------|-------
                * Hellion      |1966080    |   100 |   0   |   2
                * Hellbat      |1966080    |   100 |   0   |   2
                * Mine         |2621440    |   75  |   25  |   2
                * Siege Tank   |2949120    |   150 |   125 |   3
                * Thor         |3932160    |   300 |   200 |   6
                * */

                if (logicalId.Equals(65541))
                    return UnitId.TuHellion;

                if (logicalId.Equals(65542))
                    return UnitId.TuHellbat;

                switch (maximumTime)
                {
                    case 3932160:
                        return UnitId.TuThor;

                    case 2621440:
                        return UnitId.TuWidowMine;

                    case 2949120:
                        return UnitId.TuSiegetank;
                }
            }

            #endregion

            #region Starport

            else if (structureBuildFrom.Equals(UnitId.TbStarportGround))
            {
                /* Database for the units from the Barracks
                * Unit         |   Time    |   Min |   Ves |   Sup
                * -------------|-----------|-------|-------|-------
                * Viking       |2752512    |   150 |   75  |   2
                * Medivac      |2752512    |   100 |   100 |   2
                * Raven        |3932160    |   100 |   200 |   2
                * Banshee      |3932160    |   150 |   100 |   3
                * Battlecruiser|5898240    |   400 |   300 |   6
                * */

                if (mineralCost.Equals(150) &&
                    vespineCost.Equals(75))
                    return UnitId.TuVikingAir;

                if (mineralCost.Equals(100) &&
                    vespineCost.Equals(100))
                    return UnitId.TuMedivac;

                if (mineralCost.Equals(100) &&
                    vespineCost.Equals(200))
                    return UnitId.TuRaven;

                if (mineralCost.Equals(150) &&
                    vespineCost.Equals(100))
                    return UnitId.TuBanshee;

                if (mineralCost.Equals(400) &&
                    vespineCost.Equals(300))
                    return UnitId.TuBattlecruiser;
            }

            #endregion

            /* - Upgrades - */

            #region Engineering Bay

            if (structureBuildFrom.Equals(UnitId.TbEbay))
            {
                if (logicalId.Equals(0x10002))
                    return UnitId.TupInfantryWeapon1;

                if (logicalId.Equals(0x10003))
                    return UnitId.TupInfantryWeapon2;

                if (logicalId.Equals(0x10004))
                    return UnitId.TupInfantryWeapon3;

                if (logicalId.Equals(0x10006))
                    return UnitId.TupInfantryArmor1;

                if (logicalId.Equals(0x10007))
                    return UnitId.TupInfantryArmor2;

                if (logicalId.Equals(0x10008))
                    return UnitId.TupInfantryArmor3;

                if (mineralCost.Equals(100) &&
                    vespineCost.Equals(100) &&
                    maximumTime.Equals(5242880))
                    return UnitId.TupHighSecAutoTracking;

                if (mineralCost.Equals(100) &&
                    vespineCost.Equals(100) &&
                    maximumTime.Equals(7208960))
                    return UnitId.TupNeosteelFrame;

                if (mineralCost.Equals(150) &&
                    vespineCost.Equals(150) &&
                    maximumTime.Equals(9175040))
                    return UnitId.TupStructureArmor;
            }

            #endregion

            #region GhostAcademy

            else if (structureBuildFrom.Equals(UnitId.TbGhostacademy))
            {
                if (mineralCost.Equals(150))
                    return UnitId.TupPersonalCloak;

                if (mineralCost.Equals(100))
                {
                    if (logicalId.Equals(0x10000))
                        return UnitId.TuNuke;

                    return UnitId.TupMoebiusReactor;
                }

            }

            #endregion

            #region FusionCore

            else if (structureBuildFrom.Equals(UnitId.TbFusioncore))
            {
                if (maximumTime.Equals(3932160))
                    return UnitId.TupWeaponRefit;

                if (maximumTime.Equals(5242880))
                    return UnitId.TupBehemothReactor;
            }

            #endregion

            #region Armory

            else if (structureBuildFrom.Equals(UnitId.TbArmory))
            {
                if (mineralCost.Equals(100) &&
                    vespineCost.Equals(100) &&
                    maximumTime.Equals(10485760) &&
                    logicalId.Equals(65536))
                    return UnitId.TupVehicleWeapon1;

                if (mineralCost.Equals(175) &&
                    vespineCost.Equals(175) &&
                    maximumTime.Equals(12451840) &&
                    logicalId.Equals(65537))
                    return UnitId.TupVehicleWeapon2;

                if (mineralCost.Equals(250) &&
                    vespineCost.Equals(250) &&
                    maximumTime.Equals(14417920) &&
                    logicalId.Equals(65538))
                    return UnitId.TupVehicleWeapon3;

                if (mineralCost.Equals(100) &&
                    vespineCost.Equals(100) &&
                    maximumTime.Equals(10485760) &&
                    logicalId.Equals(65547))
                    return UnitId.TupShipWeapon1;

                if (mineralCost.Equals(175) &&
                    vespineCost.Equals(175) &&
                    maximumTime.Equals(12451840) &&
                    logicalId.Equals(65548))
                    return UnitId.TupShipWeapon2;

                if (mineralCost.Equals(250) &&
                    vespineCost.Equals(250) &&
                    maximumTime.Equals(14417920) &&
                    logicalId.Equals(65549))
                    return UnitId.TupShipWeapon3;

                if (mineralCost.Equals(100) &&
                    vespineCost.Equals(100) &&
                    maximumTime.Equals(10485760) &&
                    logicalId.Equals(65539))
                    return UnitId.TupVehicleShipPlanting1;

                if (mineralCost.Equals(175) &&
                    vespineCost.Equals(175) &&
                    maximumTime.Equals(12451840) &&
                    logicalId.Equals(65540))
                    return UnitId.TupVehicleShipPlanting2;

                if (mineralCost.Equals(250) &&
                    vespineCost.Equals(250) &&
                    maximumTime.Equals(14417920) &&
                    logicalId.Equals(65541))
                    return UnitId.TupVehicleShipPlanting3;
            }

            #endregion

            #region Techlab Barracks

            else if (structureBuildFrom.Equals(UnitId.TbTechlabRax))
            {
                if (maximumTime.Equals(11141120))
                    return UnitId.TupStim;

                if (maximumTime.Equals(7208960))
                    return UnitId.TupCombatShields;

                if (maximumTime.Equals(3932160))
                    return UnitId.TupConcussiveShells;
            }

            #endregion

            #region Techlab Factory

            else if (structureBuildFrom.Equals(UnitId.TbTechlabFactory))
            {
                if (logicalId.Equals(65537))
                    return UnitId.TupBlueFlame;

                if (logicalId.Equals(65539))
                    return UnitId.TupTransformatorServos;

                if (logicalId.Equals(65540))
                    return UnitId.TupDrillingClaws;
            }

            #endregion

            #region Techlab Starport

            else if (structureBuildFrom.Equals(UnitId.TbTechlabStarport))
            {
                if (logicalId.Equals(65536))
                    return UnitId.TupCloakingField;

                if (logicalId.Equals(65539))
                    return UnitId.TupCorvidReactor;

                if (logicalId.Equals(65543))
                    return UnitId.TupDurableMeterials;

                if (logicalId.Equals(65538))
                    return UnitId.TupCaduceusReactor;
            }

            #endregion

            #endregion

            #region Protoss

            if (structureBuildFrom.Equals(UnitId.PuMothershipCore))
            {
                //E.G. Upgrade to Lair/ Hive
                if (logicalId == -1)
                {
                    if (mineralCost == 300 && vespineCost == 300)
                        return UnitId.PupUpgradeToMothership;
                }
            }

            #region Units

            #region Nexus

            if (structureBuildFrom.Equals(UnitId.PbNexus))
            {
                switch (maximumTime)
                {
                    case 1114112:
                        return UnitId.PuProbe;

                    case 1966080:
                        return UnitId.PuMothershipCore;
                }
            }

            #endregion

            #region Gateway

            if (structureBuildFrom.Equals(UnitId.PbGateway))
            {
                /* Database for the units from the Gateway
                * Unit         |   Time    |   Min |   Ves |   Sup
                * -------------|-----------|-------|-------|-------
                * Zealot       |2490368    |   100 |   0   |   2
                * Stalker      |2752512    |   125 |   50  |   2
                * Sentry       |2424832    |   50  |   100 |   2
                * HT           |3604480    |   50  |   150 |   2
                * DT           |3604480    |   125 |   125 |   2
                * */
                if (mineralCost.Equals(100))
                    return UnitId.PuZealot;

                if (mineralCost.Equals(125) &&
                    vespineCost.Equals(50))
                    return UnitId.PuStalker;

                if (mineralCost.Equals(50) &&
                    vespineCost.Equals(100))
                    return UnitId.PuSentry;

                if (mineralCost.Equals(50) &&
                    vespineCost.Equals(150))
                    return UnitId.PuHightemplar;

                if (mineralCost.Equals(125) &&
                    vespineCost.Equals(125))
                    return UnitId.PuDarktemplar;
            }

            #endregion

            #region Stargate

            else if (structureBuildFrom.Equals(UnitId.PbStargate))
            {
                /* Database for the units from the Gateway
                * Unit         |   Time    |   Min |   Ves |   Sup
                * -------------|-----------|-------|-------|-------
                * Phoenix      |2293760    |   150 |   100 |   2
                * Oracle       |3276800    |   150 |   150 |   3
                * Void Ray     |3932160    |   250 |   150 |   4
                * Tempest      |3932160    |   300 |   200 |   4
                * Carrier      |7864320    |   350 |   250 |   6
                * */

                if (mineralCost.Equals(150) &&
                    vespineCost.Equals(100))
                    return UnitId.PuPhoenix;

                if (mineralCost.Equals(150) &&
                    vespineCost.Equals(150))
                    return UnitId.PuOracle;

                if (mineralCost.Equals(250) &&
                    vespineCost.Equals(150))
                    return UnitId.PuVoidray;

                if (mineralCost.Equals(300) &&
                    vespineCost.Equals(200))
                    return UnitId.PuTempest;

                if (mineralCost.Equals(350) &&
                    vespineCost.Equals(250))
                    return UnitId.PuCarrier;
            }

            #endregion

            #region Robotics

            if (structureBuildFrom.Equals(UnitId.PbRoboticsbay))
            {
                /* Database for the units from the Gateway
                * Unit         |   Time    |   Min |   Ves |   Sup
                * -------------|-----------|-------|-------|-------
                * Observer     |1966080    |   25  |   75  |   1
                * Warp Prism   |3276800    |   200 |   0   |   2
                * Colossus     |4915200    |   300 |   200 |   6
                * Immortal     |3604480    |   250 |   100 |   4
                * */

                if (mineralCost.Equals(25))
                    return UnitId.PuObserver;

                if (mineralCost.Equals(200))
                    return UnitId.PuWarpprismTransport;

                if (mineralCost.Equals(300))
                    return UnitId.PuColossus;

                if (mineralCost.Equals(250))
                    return UnitId.PuImmortal;
            }

            #endregion

            #endregion

            #region Upgrades

            #region Forge

            if (structureBuildFrom.Equals(UnitId.PbForge))
            {
                if (logicalId.Equals(0x10000))
                    return UnitId.PupGroundW1;

                if (logicalId.Equals(0x10001))
                    return UnitId.PupGroundW2;

                if (logicalId.Equals(0x10002))
                    return UnitId.PupGroundW3;

                if (logicalId.Equals(0x10003))
                    return UnitId.PupGroundA1;

                if (logicalId.Equals(0x10004))
                    return UnitId.PupGroundA2;

                if (logicalId.Equals(0x10005))
                    return UnitId.PupGroundA3;

                if (logicalId.Equals(0x10006))
                    return UnitId.PupS1;

                if (logicalId.Equals(0x10007))
                    return UnitId.PupS2;

                if (logicalId.Equals(0x10008))
                    return UnitId.PupS3;
            }

            #endregion

            #region CyberCore

            if (structureBuildFrom.Equals(UnitId.PbCybercore))
            {
                if (logicalId.Equals(0x10000))
                    return UnitId.PupAirW1;

                if (logicalId.Equals(0x10001))
                    return UnitId.PupAirW2;

                if (logicalId.Equals(0x10002))
                    return UnitId.PupAirW3;

                if (logicalId.Equals(0x10003))
                    return UnitId.PupAirA1;

                if (logicalId.Equals(0x10004))
                    return UnitId.PupAirA2;

                if (logicalId.Equals(0x10005))
                    return UnitId.PupAirA3;

                if (logicalId.Equals(0x10006))
                    return UnitId.PupWarpGate;
            }

            #endregion

            #region Robotics Support Bay

            if (structureBuildFrom.Equals(UnitId.PbRoboticssupportbay))
            {
                if (logicalId.Equals(0x10001))
                    return UnitId.PupGraviticBooster;

                if (logicalId.Equals(0x10002))
                    return UnitId.PupGraviticDrive;

                if (logicalId.Equals(0x10005))
                    return UnitId.PupExtendedThermalLance;
            }

            #endregion

            #region Twilight Council

            if (structureBuildFrom.Equals(UnitId.PbTwilightcouncil))
            {
                if (logicalId.Equals(0x10000))
                    return UnitId.PupCharge;

                if (logicalId.Equals(0x10001))
                    return UnitId.PupBlink;
            }

            #endregion

            #region Fleet Beacon

            if (structureBuildFrom.Equals(UnitId.PbFleetbeacon))
            {
                if (logicalId.Equals(0x10000))
                    return UnitId.PupGravitonCatapult;

                if (logicalId.Equals(0x10002))
                    return UnitId.PupAnionPulseCrystals;
            }

            #endregion

            #region Templar Archives

            if (structureBuildFrom.Equals(UnitId.PbTemplararchives))
            {
                if (logicalId.Equals(0x10004))
                    return UnitId.PupStorm;
            }

            #endregion

            #endregion

            #endregion

            #region Zerg

            if (structureBuildFrom.Equals(UnitId.ZbHatchery) ||
                structureBuildFrom.Equals(UnitId.ZbLiar) ||
                structureBuildFrom.Equals(UnitId.ZbHive))
            {
                if (logicalId.Equals(0x10001))
                    return UnitId.ZupPneumatizedCarapace;

                if (logicalId.Equals(0x10002))
                    return UnitId.ZupVentralSacs;

                if (logicalId.Equals(0x10003))
                    return UnitId.ZupBurrow;

                //E.G. Upgrade to Lair/ Hive
                if (logicalId == -1)
                {
                    if (mineralCost == 150 && vespineCost == 100)
                        return UnitId.ZupUpgradeToLair;

                    if (mineralCost == 200 && vespineCost == 150)
                        return UnitId.ZupUpgradeToHive;
                }

                return UnitId.ZuQueen;
            }

            if (structureBuildFrom.Equals(UnitId.ZbSpire))
            {
                //E.G. Upgrade to Lair/ Hive
                if (logicalId == -1)
                {
                    if (mineralCost == 100 && vespineCost == 150)
                        return UnitId.ZupUpgradeToGreaterSpire;
                }
            }

            #region Units

            if (structureBuildFrom.Equals(UnitId.ZuBanelingCocoon))
            {
                if (maximumTime.Equals(1310720))
                    return UnitId.ZuBaneling;
            }

            if (structureBuildFrom.Equals(UnitId.ZuBroodlordCocoon))
            {
                //E.G. Upgrade to Lair/ Hive
                if (logicalId == -1)
                {
                    if (mineralCost == 150 && vespineCost == 150)
                        return UnitId.ZupUpgradeToBroodlord;
                }
            }

            if (structureBuildFrom.Equals(UnitId.ZuOverseerCocoon))
            {
                //E.G. Upgrade to Lair/ Hive
                if (logicalId == -1)
                {
                    if (mineralCost == 50 && vespineCost == 50)
                        return UnitId.ZupUpgradeToOverseer;
                }
            }

            /* For the eggs, we have to cchack using other values..
             Player 2 has the Type waay different. */
            if (structureBuildFrom.Equals(UnitId.ZuEgg))
            {
                /* Database for the units from the egg
                 * Unit         |   Time    |   Min |   Ves |   Sup
                 * -------------|-----------|-------|-------|-------
                 * Drone        |1114112    |   50  |   0   |   1
                 * Zergling     |1572864    |   50  |   0   |   1
                 * Overlord     |1638400    |   100 |   0   |   -
                 * Roach        |1769472    |   75  |   25  |   2
                 * Hydralisk    |2162688    |   100 |   50  |   2
                 * Mutalsik     |2162688    |   100 |   100 |   2
                 * Corruptor    |2621440    |   150 |   100 |   3
                 * Infestor     |3276800    |   100 |   150 |   2
                 * Swarm Host   |2621440    |   200 |   100 |   3
                 * Viper        |2621440    |   100 |   200 |   3
                 * Ultralisk    |3604480    |   300 |   200 |   6
                 * */

                if (maximumTime.Equals(1114112))
                    return UnitId.ZuDrone;

                if (maximumTime.Equals(1572864))
                    return UnitId.ZuZergling;

                if (maximumTime.Equals(1638400))
                    return UnitId.ZuOverlord;

                if (maximumTime.Equals(1769472))
                    return UnitId.ZuRoach;

                if (maximumTime.Equals(2162688))
                {
                    if (vespineCost.Equals(50))
                        return UnitId.ZuHydralisk;

                    return UnitId.ZuMutalisk;
                }

                if (maximumTime.Equals(2621440))
                {
                    if (mineralCost.Equals(150))
                        return UnitId.ZuCorruptor;

                    if (mineralCost.Equals(100) &&
                        vespineCost == 200 &&
                        supply == 4)
                        return UnitId.ZuSwarmHost;

                    if (mineralCost.Equals(100) &&
                        vespineCost == 200 &&
                        supply == 3)
                        return UnitId.ZuViper;
                }

                if (maximumTime.Equals(3276800))
                    return UnitId.ZuInfestor;

                if (maximumTime.Equals(3604480))
                    return UnitId.ZuUltra;

            }

            #endregion

            #region Upgrades

            #region Evolution Chamber

            if (structureBuildFrom.Equals(UnitId.ZbEvolutionChamber))
            {
                if (logicalId.Equals(0x10000))
                    return UnitId.ZupGroundM1;

                if (logicalId.Equals(0x10001))
                    return UnitId.ZupGroundM2;

                if (logicalId.Equals(0x10002))
                    return UnitId.ZupGroundM3;

                if (logicalId.Equals(0x10003))
                    return UnitId.ZupGroundA1;

                if (logicalId.Equals(0x10004))
                    return UnitId.ZupGroundA2;

                if (logicalId.Equals(0x10005))
                    return UnitId.ZupGroundA3;

                if (logicalId.Equals(0x10006))
                    return UnitId.ZupGroundW1;

                if (logicalId.Equals(0x10007))
                    return UnitId.ZupGroundW2;

                if (logicalId.Equals(0x10008))
                    return UnitId.ZupGroundW3;
            }

            #endregion

            #region Spire/ Greater Spire

            if (structureBuildFrom.Equals(UnitId.ZbSpire) ||
                structureBuildFrom.Equals(UnitId.ZbGreaterspire))
            {
                if (logicalId.Equals(0x10000))
                    return UnitId.ZupAirW1;

                if (logicalId.Equals(0x10001))
                    return UnitId.ZupAirW2;

                if (logicalId.Equals(0x10002))
                    return UnitId.ZupAirW3;

                if (logicalId.Equals(0x10003))
                    return UnitId.ZupAirA1;

                if (logicalId.Equals(0x10004))
                    return UnitId.ZupAirA2;

                if (logicalId.Equals(0x10005))
                    return UnitId.ZupAirA3;
            }

            #endregion

            #region Hydra Den

            if (structureBuildFrom.Equals(UnitId.ZbHydraDen))
            {
                if (logicalId.Equals(0x10002))
                    return UnitId.ZupGroovedSpines;

                if (logicalId.Equals(0x10003))
                    return UnitId.ZupMuscularAugments;
            }

            #endregion

            #region Roach Warran

            if (structureBuildFrom.Equals(UnitId.ZbRoachWarren))
            {
                if (logicalId.Equals(0x10001))
                    return UnitId.ZupGlialReconstruction;

                if (logicalId.Equals(0x10002))
                    return UnitId.ZupTunnelingClaws;
            }

            #endregion

            #region Infestation Pit

            if (structureBuildFrom.Equals(UnitId.ZbInfestationPit))
            {
                if (logicalId.Equals(0x10002))
                    return UnitId.ZupPathoglenGlands;

                if (logicalId.Equals(0x10003))
                    return UnitId.ZupNeutralParasite;

                if (logicalId.Equals(0x10004))
                    return UnitId.ZupEnduringLocusts;

                if (logicalId.Equals(0x10005))
                    return UnitId.ZupFlyingLocust;
            }

            #endregion

            #region Spawning Pool

            if (structureBuildFrom.Equals(UnitId.ZbSpawningPool))
            {
                if (logicalId.Equals(0x10000))
                    return UnitId.ZupAdrenalGlands;

                if (logicalId.Equals(0x10001))
                    return UnitId.ZupMetabolicBoost;
            }

            #endregion

            #region Baneling Nest

            if (structureBuildFrom.Equals(UnitId.ZbBanelingNest))
            {
                if (logicalId.Equals(0x10000))
                    return UnitId.ZupCentrifugalHooks;
            }

            #endregion

            #region Ultra Cavern

            if (structureBuildFrom.Equals(UnitId.ZbUltraCavern))
            {
                if (logicalId.Equals(0x10002))
                    return UnitId.ZupChitinousPlating;
            }

            #endregion

            #endregion

            /* Missing: Broodlord Cocoon and Overseer Cocoon - Cant be found.. */
            #endregion

            return UnitId.None;
        }