예제 #1
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;
        }