So trying to get the payload controls to work. I had it so you press Release and it did. But couldn't reattach. SF didn't seem to do that. Not sure if SSU does.
So as I see it it checks to see if an attachment is close to attach_sat2 if it is detach or attach depending on the state.

Code:
void Atlantis::ToggleGrapple2(void)
{
HWND hDlg;
OBJHANDLE hV = GetAttachmentStatus(rms_attach);
if (hV) { // release satellite
ATTACHMENTHANDLE hAtt = CanArrest2();
DetachChild(rms_attach);
if (hDlg = oapiFindDialog(g_Param.hDLL, IDD_RMS)) {
//SetWindowText(GetDlgItem(hDlg, IDC_GRAPPLE), "Grapple");
//EnableWindow(GetDlgItem(hDlg, IDC_STOW), TRUE);
}
// check whether the object being ungrappled is ready to be clamped into the payload bay
#ifdef UNDEF
VECTOR3 pos, dir, rot, gbay, gpos;
GetAttachmentParams (sat_attach, pos, dir, rot);
Local2Global (pos, gbay);
VESSEL *v = oapiGetVesselInterface (hV);
DWORD nAttach = v->AttachmentCount (true);
for (DWORD j = 0; j < nAttach; j++) { // now scan all attachment points
ATTACHMENTHANDLE hAtt = v->GetAttachmentHandle (true, j);
v->GetAttachmentParams (hAtt, pos, dir, rot);
v->Local2Global (pos, gpos);
if (dist (gpos, gbay) < MAX_GRAPPLING_DIST) {
AttachChild (hV, sat_attach, hAtt);
return;
}
}
#endif
}
else { // grapple satellite
VECTOR3 gpos, grms, pos, dir, rot;
//Local2Global(sat_attach2, grms); // global position of RMS tip
//EnableWindow(GetDlgItem(hDlg, IDC_GRAPPLE), FALSE);
// Search the complete vessel list for a grappling candidate.
// Not very scalable ...
for (DWORD i = 0; i < oapiGetVesselCount(); i++) {
OBJHANDLE hV = oapiGetVesselByIndex(i);
if (hV == GetHandle()) continue; // we don't want to grapple ourselves ...
oapiGetGlobalPos(hV, &gpos);
if (dist(gpos, grms) < oapiGetSize(hV)) { // in range
VESSEL *v = oapiGetVesselInterface(hV);
DWORD nAttach = v->AttachmentCount(true);
for (DWORD j = 0; j < nAttach; j++) { // now scan all attachment points of the candidate
ATTACHMENTHANDLE hAtt = v->GetAttachmentHandle(true, j);
const char *id = v->GetAttachmentId(hAtt);
//if (strncmp(id, "GS", 2)) continue; // attachment point not compatible
v->GetAttachmentParams(hAtt, pos, dir, rot);
v->Local2Global(pos, gpos);
if (dist(gpos, grms) < MAX_GRAPPLING_DIST) { // found one!
// check whether satellite is currently clamped into payload bay
//EnableWindow(GetDlgItem(hDlg, IDC_GRAPPLE), TRUE);
if (hV == GetAttachmentStatus(sat_attach))
DetachChild(sat_attach2);
AttachChild(hV, sat_attach2, hAtt);
if (hDlg = oapiFindDialog(g_Param.hDLL, IDD_RMS)) {
// SetWindowText(GetDlgItem(hDlg, IDC_GRAPPLE), "Release");
// EnableWindow(GetDlgItem(hDlg, IDC_STOW), FALSE);
}
return;
}
}
}
}
}
}
void Atlantis::ToggleArrest2(void)
{
HWND hDlg;
if (CanArrest2()) { // try to arrest satellite
ToggleGrapple2();
}
}
// check whether the currently grappled object can be stowed in the cargo bay
ATTACHMENTHANDLE Atlantis::CanArrest2(void) const
{
OBJHANDLE hV = GetAttachmentStatus(sat_attach2);
if (!hV) return 0;
VESSEL *v = oapiGetVesselInterface(hV);
DWORD nAttach = v->AttachmentCount(true);
VECTOR3 pos, dir, rot, gpos, gbay;
//GetAttachmentParams(sat_attach, pos, dir, rot);
Local2Global(pos, gbay);
for (DWORD j = 0; j < nAttach; j++) {
ATTACHMENTHANDLE hAtt = v->GetAttachmentHandle(true, j);
// if (strncmp(v->GetAttachmentId(hAtt), "XS", 2)) continue; // attachment point not compatible
v->GetAttachmentParams(hAtt, pos, dir, rot);
v->Local2Global(pos, gpos);
if (dist(gpos, gbay) < MAX_GRAPPLING_DIST) {
return hAtt;
}
}
return 0;
}
So as I see it it checks to see if an attachment is close to attach_sat2 if it is detach or attach depending on the state.