Loading...   

  • Created By Uleat On: 06:01 PM January 12, 2019
  • Link

static bool inventory_dictionary_init = false;
void EQEmu::inventory::InitializeDynamicLookups() {
	if (inventory_dictionary_init == true)
		return;
	inventory_dictionary_init = true;

	// server is configured for static definitions
	if (RuleB(World, UseClientBasedExpansionSettings))
		return;

	uint32 current_expansions = RuleI(World, ExpansionSettings);
	const uint32 dynamic_check_mask = (EQEmu::expansions::bitPoR | EQEmu::expansions::bitTBS | EQEmu::expansions::bitHoT); // the only known expansions that affect inventory

	// if the above expansion bits are present, then static references will suffice
	if ((current_expansions & dynamic_check_mask) == dynamic_check_mask)
		return;

	for (uint32 iter = static_cast<uint32>(EQEmu::versions::ClientVersion::Unknown); iter <= static_cast<uint32>(EQEmu::versions::LastClientVersion); ++iter) {
		// no need to dynamic this condition since it is the lowest compatibilty standard at this time
		if (iter <= static_cast<uint32>(EQEmu::versions::ClientVersion::Titanium))
			continue;

		// direct manipulation of lookup indices is safe so long as (int)ClientVersion::<client> == (int)MobVersion::<client>
		inventory_dynamic_lookup_entries[iter] = std::make_unique<LookupEntry>(new LookupEntry(inventory_static_lookup_entries[iter]));

		// clamp affected fields to the lowest standard
		inventory_dynamic_lookup_entries[iter]->InventoryTypeSize.Bank = Titanium::invtype::BANK_SIZE; // bank size
		inventory_dynamic_lookup_entries[iter]->EquipmentBitmask = Titanium::invslot::EQUIPMENT_BITMASK; // power source
		inventory_dynamic_lookup_entries[iter]->GeneralBitmask = Titanium::invslot::GENERAL_BITMASK; // general size
		inventory_dynamic_lookup_entries[iter]->PossessionsBitmask = 0; // we'll fix later
		inventory_dynamic_lookup_entries[iter]->CorpseBitmask = 0; // we'll fix later

		if (current_expansions & EQEmu::expansions::bitPoR) {
			// update bank size
			if (constants_static_lookup_entries[iter].ExpansionsMask & EQEmu::expansions::bitPoR)
				inventory_dynamic_lookup_entries[iter]->InventoryTypeSize.Bank = SoF::invtype::BANK_SIZE;
		}

		if (current_expansions & EQEmu::expansions::bitTBS) {
			// update power source
			if (constants_static_lookup_entries[iter].ExpansionsMask & EQEmu::expansions::bitTBS)
				inventory_dynamic_lookup_entries[iter]->EquipmentBitmask = SoF::invslot::EQUIPMENT_BITMASK;
		}

		if (current_expansions & EQEmu::expansions::bitHoT) {
			// update general size
			if (constants_static_lookup_entries[iter].ExpansionsMask & EQEmu::expansions::bitHoT)
				inventory_dynamic_lookup_entries[iter]->GeneralBitmask = RoF::invslot::GENERAL_BITMASK;
		}

		// fixup possessions bitmask
		inventory_dynamic_lookup_entries[iter]->PossessionsBitmask =
			(
				inventory_dynamic_lookup_entries[iter]->EquipmentBitmask |
				inventory_dynamic_lookup_entries[iter]->GeneralBitmask |
				inventory_dynamic_lookup_entries[iter]->CursorBitmask
			);

		// fixup corpse bitmask
		inventory_dynamic_lookup_entries[iter]->CorpseBitmask =
			(
				inventory_dynamic_lookup_entries[iter]->GeneralBitmask |
				inventory_dynamic_lookup_entries[iter]->CursorBitmask |
				(inventory_dynamic_lookup_entries[iter]->EquipmentBitmask << 34)
			);

		// expansion-related fields are now updated and all other fields reflect the static entry values
	}

	// only client versions that require a change from their static definitions have been given a dynamic lookup entry
}

Raw Paste Data