← Home SEEBIE90 DOCS
Download PDF
The SOFLAM Integration Core mod is published under the Arma Public License (APL)Example code is free to useSuggestions: Discord to the author

SOFLAM Integration Core

Zoom on a handheld device

The same sight zoomed on the tripod and did nothing in the hand. The cause is not in the sight: a handheld device of the binoculars kind is aimed through a different system than a weapon, and three things that a weapon gets for free are missing.

In plain wordsThe handheld SOFLAM is a binoculars-type gadget, not a weapon. Zoom needed three fixes: the keys never arrived, the steps were wrong, and the camera read the field of view only once.

The device in your hand is a gadget

The carried SOFLAM inherits the vanilla binoculars prefab. That prefab is an item with a binoculars gadget component and an optic component, not a weapon. Raising it is gadget aiming, a different path from weapon aiming. It reaches the optic (OnSightADSActivated is called, the overlay and the vision modes work), and that is why nobody noticed anything wrong. But whatever the game does only for weapon aiming does not happen. Three of those things matter for zoom.

What a weapon getsWhat the gadget getsFix
The zoom keys are active (a context that exists only for weapon aiming and for turrets)No zoom keys at allPut the two zoom actions into a context that is active for the gadget
A camera that follows the zoom stepThe binoculars camera reads the field of view once, when it is switched onA camera that asks again every frame
Steps from the sight’s own configurationThe same, if you provide themFixed steps in a small class of your own

1. The zoom keys never arrive

The game switches the zoom actions on only when the character is aiming a weapon whose optic has more than one step (shortened from the vanilla character controller):

Example code – free to usevanilla SCR_CharacterControllerComponent (shortened)
if (player && GetAnimationComponent().IsWeaponADSTag())
{
	SightsComponent sights = GetWeaponManagerComponent().GetCurrentSights();
	if (sights)
	{
		SCR_SightsZoomFOVInfo fovInfo = SCR_SightsZoomFOVInfo.Cast(sights.GetFOVInfo());
		if (fovInfo && fovInfo.GetStepsCount() > 1)
			am.ActivateContext("CharacterWeaponMagnificationContext");	// WeaponOpticsZoomIn / WeaponOpticsZoomOut live here
	}
}

For a gadget there is no weapon, so the context is never activated. The sight itself does register listeners for the two actions when it is switched on (the vanilla 2D sights component does that in OnSightADSActivated), so the only thing missing is that the actions are active. The Core adds them to the contexts that are active for the carried device, next to its own keys:

Example code – free to useSOFLAM Integration Core / Configs/System/chimeraInputCommon.conf (excerpt)
ActionContext CharacterGeneralContext {
 ActionRefs +{
  "GTG_SOFLAM_DesignatorAction"
  "GTG_SOFLAM_RangefindAction"
  "GTG_SOFLAM_TrackingAction"
  "WeaponOpticsZoomIn"
  "WeaponOpticsZoomOut"
 }
}
// the same two lines in CharacterWeaponContext
Contexts, againAn action is only live in the contexts it is listed in. A key that does nothing on one kind of device and works on another is nearly always this: the context, not the code that listens.

2. The steps

Vanilla variable zoom divides the range between a base zoom and a maximum into equal steps. The SOFLAM wants five fixed ones: 2.5, 5 (the old picture), 10, 15 and 20. A small class derived from the vanilla zoom info replaces the step list; the keys, the interpolation and the reticle scaling stay vanilla.

Example code – free to useGTG_SOFLAM_ZoomFOVInfo.c (excerpt)
class GTG_SOFLAM_ZoomFOVInfo : SCR_SightsZoomFOVInfo
{
	static int GTG_ZoomLevels() { return 5; }

	static float GTG_ZoomAt(int level)
	{
		if (level <= 0) return 2.5;
		if (level == 1) return 5;
		if (level == 2) return 10;
		if (level == 3) return 15;
		return 20;
	}

	override array<float> ZoomsToArray()
	{
		array<float> zooms = new array<float>;
		for (int i = 0; i < GTG_ZoomLevels(); i++)
			zooms.Insert(GTG_ZoomAt(i));

		m_iStepsCount = zooms.Count();
		return zooms;
	}

	protected override float GetZoom(int i, int count)
	{
		return GTG_ZoomAt(i);
	}
}

It is named at the sight in the prefab, and the chosen level is shared with the other displays (GTG_SOFLAM_VisionShared), so the tablet shows the same zoom:

Example code – free to usePEQ1_SOFLAM.et (excerpt)
GTG_SOFLAM_SoflamSightsComponent "{64C93DB693B5481E}" {
 SightsFOVInfo GTG_SOFLAM_ZoomFOVInfo "{64C93DB6A923F9F6}" {
  m_fBaseZoom 5
 }
}

3. The label changes, the picture does not

With the keys fixed the label in the sight went from 2.5X to 20X, and the picture stayed exactly the same. The binoculars camera is the cause: it reads the optic’s field of view once, when it is activated, and then sets that value in every frame (shortened from the vanilla camera):

Example code – free to usevanilla CharacterCameraBinoculars (shortened)
class CharacterCameraBinoculars : CharacterCamera1stPerson
{
	protected float m_fBinocFOV;
	protected SCR_2DOpticsComponent m_Optics;

	override void OnActivate(ScriptedCameraItem pPrevCamera, ScriptedCameraItemResult pPrevCameraResult)
	{
		super.OnActivate(pPrevCamera, pPrevCameraResult);
		// ...
		m_fBinocFOV = m_Optics.GetFovZoomed();		// once
	}

	override void OnUpdate(float pDt, out ScriptedCameraItemResult pOutResult)
	{
		super.OnUpdate(pDt, pOutResult);
		pOutResult.m_fFOV = m_fBinocFOV;			// the same value in every frame
		pOutResult.m_bBlendFOV = false;
	}
}

A binoculars with a fixed zoom needs nothing more. A zoom that changes while you look through it does. Two small pieces fix it. First a modded class that asks the optic again in every frame; for every other pair of binoculars the answer is the same as before, so nothing changes for them:

Example code – free to useGTG_SOFLAM_BinocularsCamera.c
modded class CharacterCameraBinoculars
{
	override void OnUpdate(float pDt, out ScriptedCameraItemResult pOutResult)
	{
		super.OnUpdate(pDt, pOutResult);

		if (m_Optics)
			pOutResult.m_fFOV = m_Optics.GetFovZoomed();
	}
}

Second the sight sets the optic’s field of view whenever the zoom level changes. A negative value means “this magnification”: the optic turns it into an angle on the next call.

Example code – free to useGTG_SOFLAM_SoflamSightsComponent.c (excerpt)
protected override void AdjustZoom(float value)
{
	super.AdjustZoom(value);

	// the vanilla count runs one past the end when zooming in; limit it here
	int level = m_iSelectedZoomLevel;
	SCR_SightsZoomFOVInfo info = GetSightsFovInfo();
	if (info)
		level = Math.Clamp(level, 0, info.GetStepsCount() - 1);

	m_iSelectedZoomLevel = level;
	GTG_SnapZoom();
	GTG_SOFLAM_VisionShared.SetZoom(level);
}

protected void GTG_SnapZoom()
{
	if (GTG_IsMounted())
		return;			// on the tripod the engine blends the field of view itself

	SetFovZoomed(-m_fMagnification);		// m_fMagnification was set by SelectZoomLevel
}
Two camerasThe tripod and the hand use different cameras. On the tripod the field of view is blended by the engine, and snapping it would remove that. The check GTG_IsMounted() reads the parent chain: it is true when any entity above the device carries the tripod component. It is the same truth the beam and the aiming code ask, in one place.

Do this for your own handheld optic

  1. Find out whether your device is a gadget or a weapon: does its prefab inherit from the binoculars prefab? Then it is a gadget.
  2. Put WeaponOpticsZoomIn and WeaponOpticsZoomOut into a context that is active for the carried device, in your own input configuration or the Core’s.
  3. Give the optic a zoom info class that carries your steps.
  4. Add the modded camera class above (one copy is enough: if the Core is loaded, it is already there), and set SetFovZoomed(-magnification) when your zoom level changes.
  5. Test in the hand and on the tripod. The two paths differ, and a fix for one can break the other.
Example code on this page is free to use in your own projects (credit appreciated). The SOFLAM Integration Core mod is published under the Arma Public License (APL). Suggestions: Discord. Arma Reforger / Enfusion are trademarks of Bohemia Interactive.
Impressum · Privacy Policy