protected TResult Add(AmfObject node) { _object.Push(node); Update(); VM.Instance.NotifySaveRequiredChanged(true); return(this[_object.DenseCount - 1]); }
public new virtual TResult Add(object value) { _object.Push(value); Update(); VM.Instance.NotifySaveRequiredChanged(true); return(this[_object.DenseCount - 1]); }
public void CleanupInventory() { //shift all the items around in the inventory const int maxSlots = 10; AmfObject inv = GetObj("inventory"); AmfObject nInv = new AmfObject(AmfTypes.Array); for (int i = 0; i < maxSlots; ++i) { AmfObject item = (AmfObject)inv[i]; if (item == null) { continue; } if (item.GetString("classInstance") != XmlItem.Empty.ID) { nInv.Push(item); } } SetValue("inventory", nInv); }
public void UpdateInventory() { _inventory.Clear(); const int maxSlots = 10; AmfObject inv = GetObj("inventory"); for (int i = 0; i < maxSlots; ++i) { AmfObject item = (AmfObject)inv[i]; if (item == null) { //just add an empty item, we'll fix it later maybe item = new AmfObject(AmfTypes.Object); item["classInstance"] = XmlItem.Empty.ID; item["shortName"] = XmlItem.Empty.Name; item["quantity"] = 0; item["version"] = 1; inv.Push(item); } _inventory.Add(item); } }
public GameVM(AmfFile file, GameVM previousVM, bool isRevampMod = false) : base(file) { if (previousVM != null) { _itemSearchText = previousVM._itemSearchText; _perkSearchText = previousVM._perkSearchText; _rawDataSearchText = previousVM._rawDataSearchText; _keyItemSearchText = previousVM._keyItemSearchText; } // Is this save from vanilla CoC or the CoC-Revamp-Mod? IsRevampMod = isRevampMod; // Unique children Ass = new AssVM(file.GetObj("ass")); LipPiercing = new PiercingVM(file, "lip", PiercingLocation.Lip); NosePiercing = new PiercingVM(file, "nose", PiercingLocation.Nose); EarsPiercing = new PiercingVM(file, "ears", PiercingLocation.Ears); EyebrowPiercing = new PiercingVM(file, "eyebrow", PiercingLocation.Eyebrow); NipplesPiercing = new PiercingVM(file, "nipples", PiercingLocation.Nipples); TonguePiercing = new PiercingVM(file, "tongue", PiercingLocation.Tongue); // Collections Cocks = new CockArrayVM(this, file.GetObj("cocks")); Vaginas = new VaginaArrayVM(file.GetObj("vaginas")); Breasts = new BreastArrayVM(this, file.GetObj("breastRows")); Vaginas.CollectionChanged += OnGenitalCollectionChanged; Breasts.CollectionChanged += OnGenitalCollectionChanged; Cocks.CollectionChanged += OnGenitalCollectionChanged; // Flags int numFlags = XmlData.Current.Flags.Max(x => x.ID) + 25; // was 200; I'm unsure if there's really a need for a buffer at all anymore var xmlFlagByID = new XmlEnum[numFlags]; foreach(var xml in XmlData.Current.Flags) xmlFlagByID[xml.ID] = xml; var flagsArray = GetObj("flags"); if (flagsArray == null) { // For very old versions of CoC _obj["flags"] = flagsArray = new AmfObject(AmfTypes.Array); for (int i = 0; i < 3000; ++i) flagsArray.Push(0); } _allFlags = new FlagVM[numFlags]; for (int i = 0; i < _allFlags.Length; ++i) _allFlags[i] = new FlagVM(this, flagsArray, xmlFlagByID[i], i); Flags = new UpdatableCollection<FlagVM>(_allFlags.Where(x => x.Index > 0 && x.Match(_rawDataSearchText))); // Statuses var cocStatuses = file.GetObj("statusAffects"); var xmlStatuses = XmlData.Current.Statuses; ImportMissingNamedVectors(cocStatuses, xmlStatuses, "statusAffectName"); _allStatuses = XmlData.Current.Statuses.OrderBy(x => x.Name).Select(x => new StatusVM(this, cocStatuses, x)).ToArray(); Statuses = new UpdatableCollection<StatusVM>(_allStatuses.Where(x => x.Match(_rawDataSearchText))); // KeyItems var cocKeys = file.GetObj("keyItems"); var xmlKeys = XmlData.Current.KeyItems; ImportMissingNamedVectors(cocKeys, xmlKeys, "keyName"); _allKeyitems = XmlData.Current.KeyItems.OrderBy(x => x.Name).Select(x => new KeyItemVM(this, cocKeys, x)).ToArray(); KeyItems = new UpdatableCollection<KeyItemVM>(_allKeyitems.Where(x => x.Match(_keyItemSearchText))); // Perks var cocPerks = _obj.GetObj("perks"); var xmlPerks = XmlData.Current.PerkGroups.SelectMany(x => x.Perks).ToArray(); var unknownPerkGroup = XmlData.Current.PerkGroups.Last(); ImportMissingNamedVectors(cocPerks, xmlPerks, "id", null, unknownPerkGroup.Perks); PerkGroups = new List<PerkGroupVM>(); foreach (var xmlGroup in XmlData.Current.PerkGroups) { var perksVM = xmlGroup.Perks.OrderBy(x => x.Name).Select(x => new PerkVM(this, cocPerks, x)).ToArray(); _allPerks.AddRange(perksVM); var groupVM = new PerkGroupVM(this, xmlGroup.Name, perksVM); PerkGroups.Add(groupVM); } // Item containers var containers = new List<ItemContainerVM>(); _inventory = new ItemContainerVM(this, "Inventory", ItemCategories.All); containers.Add(_inventory); UpdateInventory(); _chest = new ItemContainerVM(this, IsRevampMod ? "Chest(s)" : "Chest", ItemCategories.All); containers.Add(_chest); UpdateChest(); _weaponRack = new ItemContainerVM(this, "Weapon rack", ItemCategories.Weapon | ItemCategories.Unknown); containers.Add(_weaponRack); UpdateWeaponRack(); _armorRack = new ItemContainerVM(this, "Armor rack", ItemCategories.Armor | ItemCategories.ArmorCursed | ItemCategories.Unknown); containers.Add(_armorRack); UpdateArmorRack(); if (IsRevampMod) { _shieldRack = new ItemContainerVM(this, "Shield rack", ItemCategories.Shield | ItemCategories.Unknown); containers.Add(_shieldRack); UpdateShieldRack(); _dresser = new ItemContainerVM(this, "Dresser", ItemCategories.Undergarment | ItemCategories.Unknown); containers.Add(_dresser); UpdateDresser(); _jewelryBox = new ItemContainerVM(this, "Jewelry box", ItemCategories.Jewelry | ItemCategories.Unknown); containers.Add(_jewelryBox); UpdateJewelryBox(); } // Import missing items var unknownItemGroup = XmlData.Current.ItemGroups.Last(); foreach (var slot in containers.SelectMany(x => x.Slots)) { // Add this item to the DB if it does not exist var type = slot.Type; if (String.IsNullOrEmpty(type)) continue; if (XmlData.Current.ItemGroups.SelectMany(x => x.Items).Any(x => x.ID == type)) continue; var xml = new XmlItem { ID = type, Name = type }; unknownItemGroup.Items.Add(xml); } foreach (var slot in containers.SelectMany(x => x.Slots)) slot.UpdateGroups(); // Update item groups after new items have been added // Complete slots creation ItemContainers = new UpdatableCollection<ItemContainerVM>(containers.Where(x => x.Slots.Count != 0)); }
AmfObject ReadArray() { // Stored by ref? bool isInstance; var indexOrCount = ReadU29(out isInstance); if (!isInstance) return (AmfObject)_objectLookup[indexOrCount]; // Stored by value var result = new AmfObject(AmfTypes.Array); _objectLookup.Add(result); // Associative part (key-value pairs) while (true) { var key = ReadString(); if (key == "") break; var value = ReadValue(); result[key] = value; } // Dense part (consecutive indices >=0 and <count) for (int i = 0; i < indexOrCount; i++) { var value = ReadValue(); result.Push(value); } return result; }
AmfObject ReadVector(AmfTypes type) { // Stored by ref? bool isInstance; int lengthOrIndex = ReadU29(out isInstance); if (!isInstance) return (AmfObject)_objectLookup[lengthOrIndex]; // Stored by value var result = new AmfObject(type); _objectLookup.Add(result); result.IsFixedVector = _reader.ReadBoolean(); if (type == AmfTypes.VectorGeneric) result.GenericElementType = ReadString(); for (int j = 0; j < lengthOrIndex; ++j) { switch (type) { case AmfTypes.VectorInt: result.Push(ReadI32()); break; case AmfTypes.VectorUInt: result.Push(ReadU32()); break; case AmfTypes.VectorDouble: result.Push(ReadDouble()); break; case AmfTypes.VectorGeneric: result.Push(ReadValue()); break; default: throw new NotImplementedException(); } } return result; }