Skip to content

Commit

Permalink
1.5
Browse files Browse the repository at this point in the history
KSP 1.0.4
Fix a rare nullref bug
  • Loading branch information
SirDiazo committed Jun 25, 2015
1 parent 570bf0e commit b3d05b0
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 116 deletions.
Binary file modified AutoAction.v12.suo
Binary file not shown.
17 changes: 7 additions & 10 deletions AutoAction/AutoAction.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\1.0 Dev\GameData\Diazo\AutoAction\</OutputPath>
<OutputPath>..\..\..\1.0.4 Dev\GameData\Diazo\AutoAction\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -31,23 +31,20 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\1.0 dev\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\1.0.4 Dev\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\1.0 dev\KSP_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\1.0.4 Dev\KSP_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\1.0 dev\KSP_Data\Managed\UnityEngine.dll</HintPath>
<Reference Include="UnityEngine">
<HintPath>..\..\..\1.0.4 Dev\KSP_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
218 changes: 112 additions & 106 deletions AutoAction/AutoActionFlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,127 +15,133 @@ public class AutoActionFlight : MonoBehaviour

public void Update()
{
//print("AA " + FlightGlobals.ActiveVessel.loaded + " " + FlightGlobals.ActiveVessel.situation + FlightGlobals.ActiveVessel.HoldPhysics);
if(!FlightGlobals.ActiveVessel.HoldPhysics) //wait until physics is running to tell us everything is loaded, the first Update() acutally runs while on the black loading screen, action states won't match onscreen otherwise (a deployed solar panel drawn as stowed, etc.)
{
if(aaRootPart != FlightGlobals.ActiveVessel.rootPart)
{
//print("Auto act part change");
bool aaPMfound = false; //only process first aaPM we find
foreach(Part p in FlightGlobals.ActiveVessel.parts)
try
{//print("AA " + FlightGlobals.ActiveVessel.loaded + " " + FlightGlobals.ActiveVessel.situation + FlightGlobals.ActiveVessel.HoldPhysics);
if (!FlightGlobals.ActiveVessel.HoldPhysics) //wait until physics is running to tell us everything is loaded, the first Update() acutally runs while on the black loading screen, action states won't match onscreen otherwise (a deployed solar panel drawn as stowed, etc.)
{
foreach(ModuleAutoAction aaPM in p.Modules.OfType<ModuleAutoAction>())
if (aaRootPart != FlightGlobals.ActiveVessel.rootPart)
{
if(!aaPMfound) //if false, first aaPM we've found
//print("Auto act part change");
bool aaPMfound = false; //only process first aaPM we find
foreach (Part p in FlightGlobals.ActiveVessel.parts)
{
if (!aaPM.hasActivated) //make sure this aaPM has not activated before
foreach (ModuleAutoAction aaPM in p.Modules.OfType<ModuleAutoAction>())
{
if (aaPM.activateAbort)
{
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Abort);
//activateAbort = false;
}
if (aaPM.activateBrakes)
{
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Brakes);
//activateBrakes = false;
}
if (aaPM.activateGear)
{
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Gear);
//activateGear = false;
}
if (aaPM.activateLights)
{
//print("Auto act lights");
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Light);
//activateLights = false;
}
if (aaPM.activateRCS)
{
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.RCS);
//activateRCS = false;
}
if (aaPM.activateSAS)
{
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.SAS);
//activateSAS = false;
}

if (aaPM.activateGroupA != 0)
{
callActionGroup(aaPM.activateGroupA);
//activateGroupA = 0;
}
if (aaPM.activateGroupB != 0)
{
callActionGroup(aaPM.activateGroupB);
//activateGroupB = 0;
}
if (aaPM.activateGroupC != 0)
{
callActionGroup(aaPM.activateGroupC);
//activateGroupC = 0;
}
if (aaPM.activateGroupD != 0)
{
callActionGroup(aaPM.activateGroupD);
//activateGroupD = 0;
}
if (aaPM.activateGroupE != 0)
if (!aaPMfound) //if false, first aaPM we've found
{
callActionGroup(aaPM.activateGroupE);
//activateGroupE = 0;
}
if (aaPM.activateGroupF != 0)
{
callActionGroup(aaPM.activateGroupF);
//activateGroupF = 0;
}
if (aaPM.setThrottle != -50)
{
//print("throttle set " + aaPM.setThrottle);
FlightInputHandler.state.mainThrottle = Mathf.Max(0, Mathf.Min((float)aaPM.setThrottle / 100, 1)); //set throttle, from 0 to 1
//setThrottle = -50;
}
if (aaPM.setPrecCtrl)
{

FlightInputHandler.fetch.precisionMode = true;
foreach(Renderer rend in FlightInputHandler.fetch.inputGaugeRenderers)
if (!aaPM.hasActivated) //make sure this aaPM has not activated before
{
//rend.material.color = new Color(0.976f, 0.451f, 0.024f);
rend.material.color = new Color(0.255f, 0.992f, 0.996f);
}
if (aaPM.activateAbort)
{
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Abort);
//activateAbort = false;
}
if (aaPM.activateBrakes)
{
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Brakes);
//activateBrakes = false;
}
if (aaPM.activateGear)
{
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Gear);
//activateGear = false;
}
if (aaPM.activateLights)
{
//print("Auto act lights");
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Light);
//activateLights = false;
}
if (aaPM.activateRCS)
{
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.RCS);
//activateRCS = false;
}
if (aaPM.activateSAS)
{
FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.SAS);
//activateSAS = false;
}

if (aaPM.activateGroupA != 0)
{
callActionGroup(aaPM.activateGroupA);
//activateGroupA = 0;
}
if (aaPM.activateGroupB != 0)
{
callActionGroup(aaPM.activateGroupB);
//activateGroupB = 0;
}
if (aaPM.activateGroupC != 0)
{
callActionGroup(aaPM.activateGroupC);
//activateGroupC = 0;
}
if (aaPM.activateGroupD != 0)
{
callActionGroup(aaPM.activateGroupD);
//activateGroupD = 0;
}
if (aaPM.activateGroupE != 0)
{
callActionGroup(aaPM.activateGroupE);
//activateGroupE = 0;
}
if (aaPM.activateGroupF != 0)
{
callActionGroup(aaPM.activateGroupF);
//activateGroupF = 0;
}
if (aaPM.setThrottle != -50)
{
//print("throttle set " + aaPM.setThrottle);
FlightInputHandler.state.mainThrottle = Mathf.Max(0, Mathf.Min((float)aaPM.setThrottle / 100, 1)); //set throttle, from 0 to 1
//setThrottle = -50;
}
if (aaPM.setPrecCtrl)
{

FlightInputHandler.fetch.precisionMode = true;
foreach (Renderer rend in FlightInputHandler.fetch.inputGaugeRenderers)
{
//rend.material.color = new Color(0.976f, 0.451f, 0.024f);
rend.material.color = new Color(0.255f, 0.992f, 0.996f);
}

}
else
{


FlightInputHandler.fetch.precisionMode = false;
foreach (Renderer rend in FlightInputHandler.fetch.inputGaugeRenderers)
{
//rend.material.color = new Color(0.255f, 0.992f, 0.996f);
rend.material.color = new Color(0.976f, 0.451f, 0.024f);
}
}
aaPM.hasActivated = true; //this aaPM has been processed
aaPMfound = true;

}
}
else
else //aaPM has been found and processed already on this vessel, ignore any more aaPM's we find and mark them processed.
{


FlightInputHandler.fetch.precisionMode = false;
foreach (Renderer rend in FlightInputHandler.fetch.inputGaugeRenderers)
{
//rend.material.color = new Color(0.255f, 0.992f, 0.996f);
rend.material.color = new Color(0.976f, 0.451f, 0.024f);
}
aaPM.hasActivated = true;
}
aaPM.hasActivated = true; //this aaPM has been processed
aaPMfound = true;

}
}
else //aaPM has been found and processed already on this vessel, ignore any more aaPM's we find and mark them processed.
{
aaPM.hasActivated = true;
}

aaRootPart = FlightGlobals.ActiveVessel.rootPart;
}
}

aaRootPart = FlightGlobals.ActiveVessel.rootPart;
//print("test " + FlightUIController.fetch.stgPitch.Value + "|" + FlightUIController.fetch.stgPitch.pointer.renderer.material.color);
}
catch
{
Debug.Log("AutoAction Error: Safe to ignore if you did not just launch a new vessel.");
}
}
//print("test " + FlightUIController.fetch.stgPitch.Value + "|" + FlightUIController.fetch.stgPitch.pointer.renderer.material.color);
} //close Update()

public void callActionGroup(int group)
Expand Down

0 comments on commit b3d05b0

Please sign in to comment.