Esempio n. 1
0
        private void ApplyTrapsGear()
        {
            if (Loadout == null || Loadout.Length != LoadoutSlotsNumber)
            {
                throw new Exception("9 traps/gear must be used");
            }

            int startIndexLoadout = UPKFile.FindBytesKMP(SpitfireGameUPK.HeroObjectLoadoutHeader, SpitfireGameUPK.HeroObjects[Name].Offset, SpitfireGameUPK.HeroObjects[Name].Size - UPKFile.nBytesRemoved);

            if (startIndexLoadout == -1)
            {
                // Get position after Archetype and Add Header and Field Type
                startIndexLoadout = UPKFile.FindBytesKMP(SpitfireGameUPK.HeroObjectDefaultInventoryArchetypesHeader, SpitfireGameUPK.HeroObjects[Name].Offset, SpitfireGameUPK.HeroObjects[Name].Size) + SpitfireGameUPK.HeroObjectDefaultInventoryArchetypesSectionLength;

                UPKFile.InsertZeroedBytes(startIndexLoadout, LoadoutSectionLength);

                UPKFile.OverrideBytes(SpitfireGameUPK.HeroObjectLoadoutHeader, startIndexLoadout);
                UPKFile.OverrideBytes(SpitfireGameUPK.HeroObjectLoadoutFieldType, startIndexLoadout + SpitfireGameUPK.HeroObjectLoadoutHeader.Length);
            }

            int arraySizeIndex         = startIndexLoadout + LoadoutArraySizeOffset;
            int arrayElementCountIndex = startIndexLoadout + LoadoutArrayElementCountOffset;
            int loadoutSlotsIndex      = startIndexLoadout + LoadoutSlotsOffset;

            // IF there aren't 9 slots set up we create them and insert necessary bytes
            int loadoutSlotsUsed = UPKFile.GetByte(arrayElementCountIndex);

            if (loadoutSlotsUsed != LoadoutSlotsNumber)
            {
                UPKFile.OverrideSingleByte((LoadoutSlotsNumber + 1) * LoadoutSlotByteSize, arraySizeIndex); // Array Size (+1 to count the size field itself too)
                UPKFile.OverrideSingleByte(LoadoutSlotsNumber, arrayElementCountIndex);                     // Array Element Count ( the 4 bytes inbetween are "index 0")

                // Add new slots (as many as missing)
                int indexAfterUsedSlots = loadoutSlotsIndex + (loadoutSlotsUsed * LoadoutSlotByteSize);

                UPKFile.InsertZeroedBytes(indexAfterUsedSlots, (LoadoutSlotsNumber - loadoutSlotsUsed) * LoadoutSlotByteSize);
            }

            // Convert and apply Loadout
            byte[] loadoutBytes = ConvertLoadoutToBytes(Loadout);
            UPKFile.OverrideBytes(loadoutBytes, loadoutSlotsIndex);
        }
Esempio n. 2
0
 private void FillRemovedBytes(int insertIndex)
 {
     UPKFile.InsertZeroedBytes(insertIndex, 0);
 }