Defensive descriptor conversion

def _vehicle_key(value):
    if isinstance(value, (int, long)):
        return int(value)  # compact descriptor or verified numeric key
    if isinstance(value, basestring):
        value = value.strip()
        if value:
            return value  # verified internal type name
    raise ValueError('unsupported vehicle identity')

Do not guess whether an arbitrary integer is a compact descriptor, inventory ID, arena vehicle ID, or entity ID. Name variables by their actual domain.

Modules, equipment, shells, and appearance data

These systems also have static descriptors and account-owned item wrappers. A UI selection index is presentation state, not a durable item identifier. Persist semantic keys or compact descriptors and rebuild indexes when the UI opens.

Optional equipment: a verified source-tracing example

The equipment-selection menu and the hangar slot menu are separate owners. In the current client, OptDeviceItemContextMenu controls an item selected for fitting, while HangarOptDeviceSlotContextMenu controls an installed hangar slot. Patch only the owner whose user action you are extending.

  1. Obtain the selected optional-device wrapper from the context-menu instance.
  2. Pass current inventory vehicle objects to device.getInstalledVehicles(...).
  3. Inspect every known configuration through vehicle.optDevices.setupLayouts.setups.
  4. Resolve the exact setup and slot without changing the player's selected configuration.
  5. Run one state-changing action, reject repeated clicks while it is pending, and inspect its result.
def find_device_slots(vehicle, device_cd):
    matches = []
    setups = vehicle.optDevices.setupLayouts.setups
    for setup_idx, setup in setups.iteritems():
        for slot_idx in xrange(setup.getCapacity()):
            item = setup[slot_idx]
            if item is not None and item.intCD == device_cd:
                matches.append((setup_idx, slot_idx))
    return matches

ActionsFactory.REMOVE_OPT_DEVICE currently constructs RemoveOptionalDevice(vehicle, device, slotID, destroy=False, forFitting=False, everywhere=True). That signature is version-sensitive. Verify its current constructor and native callers before use.

Keep ID domains explicit: a vehicle instance, vehicle type compact descriptor, inventory ID, device compact descriptor, setup index, and slot index are different values even when several happen to be integers.