Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed Distribution/DeepFreeze.zip
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
42 changes: 42 additions & 0 deletions Source/APIs/DFWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,14 @@ internal DeepFreezer(Object a)
FreezerOutofEC = getFreezerOutofEC;
FrzrTmpMethod = DeepFreezerType.GetMethod("get_DFIFrzrTmp", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
FrzrTmp = getFrzrTmp;
FrznChargeUsageMethod = DeepFreezerType.GetMethod("get_DFIFrznChargeUsage", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
FrznChargeUsage = getFrznChargeUsage;
StoredCrewListMethod = DeepFreezerType.GetMethod("get_DFIStoredCrewList", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
actualStoredCrewList = StoredCrewListMethod.Invoke(actualDeepFreezer, null);
ECReqdMethod = DeepFreezerType.GetMethod("get_DFIECReqd", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
ECReqd = getECReqd;
FrznChargeRequiredMethod = DeepFreezerType.GetMethod("get_DFIFrznChargeRequired", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
FrznChargeRequired = getFrznChargeRequired;

//Methods
//LogFormatted("Getting beginFreezeKerbalMethod Method");
Expand Down Expand Up @@ -438,6 +444,42 @@ private FrzrTmpStatus getFrzrTmp
get { return (FrzrTmpStatus)FrzrTmpMethod.Invoke(actualDeepFreezer, null); }
}

/// <summary>
/// True if this DeepFreezer requires Electric Charge for frozen Kerbals
/// </summary>
public bool ECReqd;

private MethodInfo ECReqdMethod;

private bool getECReqd
{
get { return (bool)ECReqdMethod.Invoke(actualDeepFreezer, null); }
}

/// <summary>
/// The current EC Usage of this DeepFreezer
/// </summary>
public float FrznChargeUsage;

private MethodInfo FrznChargeUsageMethod;

private float getFrznChargeUsage
{
get { return (float)FrznChargeUsageMethod.Invoke(actualDeepFreezer, null); }
}

/// <summary>
/// The EC Usage of this DeepFreezer Per Kerbal per minute
/// </summary>
public int FrznChargeRequired;

private MethodInfo FrznChargeRequiredMethod;

private int getFrznChargeRequired
{
get { return (int)FrznChargeRequiredMethod.Invoke(actualDeepFreezer, null); }
}

private Object actualStoredCrewList;
private MethodInfo StoredCrewListMethod;

Expand Down
31 changes: 16 additions & 15 deletions Source/APIs/KACWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static Boolean InitKACWrapper()
_KACWrapped = false;
actualKAC = null;
KAC = null;
LogFormatted("Attempting to Grab KAC Types...");
LogFormatted_DebugOnly("Attempting to Grab KAC Types...");

//find the base type
KACType = AssemblyLoader.loadedAssemblies
Expand Down Expand Up @@ -105,7 +105,7 @@ public static Boolean InitKACWrapper()
}

//now grab the running instance
LogFormatted("Got Assembly Types, grabbing Instance");
LogFormatted_DebugOnly("Got Assembly Types, grabbing Instance");

try
{
Expand All @@ -124,7 +124,7 @@ public static Boolean InitKACWrapper()
}

//If we get this far we can set up the local object and its methods/functions
LogFormatted("Got Instance, Creating Wrapper Objects");
LogFormatted_DebugOnly("Got Instance, Creating Wrapper Objects");
KAC = new KACAPI(actualKAC);
//}
_KACWrapped = true;
Expand All @@ -143,33 +143,33 @@ internal KACAPI(Object KAC)

//these sections get and store the reflection info and actual objects where required. Later in the properties we then read the values from the actual objects
//for events we also add a handler
LogFormatted("Getting APIReady Object");
LogFormatted_DebugOnly("Getting APIReady Object");
APIReadyField = KACType.GetField("APIReady", BindingFlags.Public | BindingFlags.Static);
LogFormatted("Success: " + (APIReadyField != null));
LogFormatted_DebugOnly("Success: " + (APIReadyField != null));

//WORK OUT THE STUFF WE NEED TO HOOK FOR PEOPEL HERE
LogFormatted("Getting Alarms Object");
LogFormatted_DebugOnly("Getting Alarms Object");
AlarmsField = KACType.GetField("alarms", BindingFlags.Public | BindingFlags.Static);
actualAlarms = AlarmsField.GetValue(actualKAC);
LogFormatted("Success: " + (actualAlarms != null));
LogFormatted_DebugOnly("Success: " + (actualAlarms != null));

//Events
LogFormatted("Getting Alarm State Change Event");
LogFormatted_DebugOnly("Getting Alarm State Change Event");
onAlarmStateChangedEvent = KACType.GetEvent("onAlarmStateChanged", BindingFlags.Public | BindingFlags.Instance);
LogFormatted_DebugOnly("Success: " + (onAlarmStateChangedEvent != null));
LogFormatted_DebugOnly("Adding Handler");
AddHandler(onAlarmStateChangedEvent, actualKAC, AlarmStateChanged);

//Methods
LogFormatted("Getting Create Method");
LogFormatted_DebugOnly("Getting Create Method");
CreateAlarmMethod = KACType.GetMethod("CreateAlarm", BindingFlags.Public | BindingFlags.Instance);
LogFormatted_DebugOnly("Success: " + (CreateAlarmMethod != null));

LogFormatted("Getting Delete Method");
LogFormatted_DebugOnly("Getting Delete Method");
DeleteAlarmMethod = KACType.GetMethod("DeleteAlarm", BindingFlags.Public | BindingFlags.Instance);
LogFormatted_DebugOnly("Success: " + (DeleteAlarmMethod != null));

LogFormatted("Getting DrawAlarmAction");
LogFormatted_DebugOnly("Getting DrawAlarmAction");
DrawAlarmActionChoiceMethod = KACType.GetMethod("DrawAlarmActionChoiceAPI", BindingFlags.Public | BindingFlags.Instance);
LogFormatted_DebugOnly("Success: " + (DrawAlarmActionChoiceMethod != null));

Expand Down Expand Up @@ -237,9 +237,9 @@ private KACAlarmList ExtractAlarmList(Object actualAlarmList)
ListToReturn.Add(r1);
}
}
catch (Exception)
catch (Exception ex)
{
//LogFormatted("Arrggg: {0}", ex.Message);
LogFormatted("ExtractAlarmList failed: {0}", ex.Message);
//throw ex;
//
}
Expand Down Expand Up @@ -627,10 +627,11 @@ public class KACAlarmList : List<KACAlarm>
/// </summary>
/// <param name="Message">Text to be printed - can be formatted as per String.format</param>
/// <param name="strParams">Objects to feed into a String.format</param>
[Conditional("DEBUG")]

internal static void LogFormatted_DebugOnly(String Message, params Object[] strParams)
{
LogFormatted(Message, strParams);
if (RSTUtils.Utilities.debuggingOn)
LogFormatted(Message, strParams);
}

/// <summary>
Expand Down
174 changes: 174 additions & 0 deletions Source/APIs/KBWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/**
* DeepFreeze Continued...
* (C) Copyright 2015, Jamie Leighton
*
* Kerbal Space Program is Copyright (C) 2013 Squad. See http://kerbalspaceprogram.com/. This
* project is in no way associated with nor endorsed by Squad.
*
* This file is part of JPLRepo's DeepFreeze (continued...) - a Fork of DeepFreeze. Original Author of DeepFreeze is 'scottpaladin' on the KSP Forums.
* This File was not part of the original Deepfreeze but was written by Jamie Leighton based of code and concepts from the Kerbal Alarm Clock Mod. Which was licensed under the MIT license.
* (C) Copyright 2015, Jamie Leighton
*
* Continues to be licensed under the Attribution-NonCommercial-ShareAlike 3.0 (CC BY-NC-SA 4.0)
* creative commons license. See <https://creativecommons.org/licenses/by-nc-sa/4.0/>
* for full details.
*
*/

using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Debug = UnityEngine.Debug;

namespace DF
{
/// <summary>
/// The Wrapper class to access KB LS
/// </summary>
public class KBWrapper
{
protected static Type KBType;
protected static Object actualKB;

/// <summary>
/// This is the KB LS Actual object
///
/// SET AFTER INIT
/// </summary>
public static KBAPI KBActualAPI;

/// <summary>
/// Whether we found the KB LS assembly in the loadedassemblies.
///
/// SET AFTER INIT
/// </summary>
public static Boolean AssemblyExists { get { return KBType != null; } }

/// <summary>
/// Whether we managed to hook the running Instance from the assembly.
///
/// SET AFTER INIT
/// </summary>
public static Boolean InstanceExists { get { return KBActualAPI != null; } }

/// <summary>
/// Whether we managed to wrap all the methods/functions from the instance.
///
/// SET AFTER INIT
/// </summary>
private static Boolean _KBWrapped;

/// <summary>
/// Whether the object has been wrapped
/// </summary>
public static Boolean APIReady { get { return _KBWrapped; } }

/// <summary>
/// This method will set up the KB LS object and wrap all the methods/functions
/// </summary>
/// <returns></returns>
public static Boolean InitKBWrapper()
{
//reset the internal objects
_KBWrapped = false;
actualKB = null;
LogFormatted_DebugOnly("Attempting to Grab KB LS Types...");

//find the base type
KBType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "KERBALISM.Kerbalism");

if (KBType == null)
{
return false;
}

LogFormatted("KB LS Version:{0}", KBType.Assembly.GetName().Version.ToString());

//If we get this far we can set up the local object and its methods/functions
LogFormatted_DebugOnly("Got Instance, Creating Wrapper Objects");
KBActualAPI = new KBAPI();
//KBIsKerbalTracked = new KBIsKerbalTrackedAPI(actualKBIsKerbalTracked);

_KBWrapped = true;
return true;
}

/// <summary>
/// The Type that is an analogue of the real KB LS. This lets you access all the API-able properties and Methods of KB LS
public class KBAPI
{
internal KBAPI()
{
//these sections get and store the reflection info and actual objects where required. Later in the properties we then read the values from the actual objects
//for events we also add a handler
//LogFormatted("Getting APIReady Object");
//APIReadyField = TRType.GetField("APIReady", BindingFlags.Public | BindingFlags.Static);
//LogFormatted("Success: " + (APIReadyField != null).ToString());

//WORK OUT THE STUFF WE NEED TO HOOK FOR PEOPLE HERE
//Methods
LogFormatted_DebugOnly("Getting hook_DisableKerbal Method");
KBhook_DisableKerbalMethod = KBType.GetMethod("hook_DisableKerbal", BindingFlags.Public | BindingFlags.Static);
LogFormatted_DebugOnly("Success: " + (KBhook_DisableKerbalMethod != null));
}

#region Methods

private MethodInfo KBhook_DisableKerbalMethod;

/// <summary>
/// Un/track a kerbal in KB LS
/// </summary>
/// <param name="kerbal">A string containing the kerbal's name</param>
/// <param name="disabled">A bool to disable or enable</param>
internal void DisableKerbal(string kerbal, bool disabled)
{
try
{
KBhook_DisableKerbalMethod.Invoke(null, new System.Object[] { kerbal, disabled });
}
catch (Exception ex)
{
LogFormatted("Unable to invoke KB LS DisableKerbal Method");
LogFormatted("Exception: {0}", ex);
//throw;
}
}
#endregion Methods
}


#region Logging Stuff

/// <summary>
/// Some Structured logging to the debug file - ONLY RUNS WHEN DLL COMPILED IN DEBUG MODE
/// </summary>
/// <param name="Message">Text to be printed - can be formatted as per String.format</param>
/// <param name="strParams">Objects to feed into a String.format</param>
internal static void LogFormatted_DebugOnly(String Message, params Object[] strParams)
{
if (RSTUtils.Utilities.debuggingOn)
LogFormatted(Message, strParams);
}

/// <summary>
/// Some Structured logging to the debug file
/// </summary>
/// <param name="Message">Text to be printed - can be formatted as per String.format</param>
/// <param name="strParams">Objects to feed into a String.format</param>
internal static void LogFormatted(String Message, params Object[] strParams)
{
Message = String.Format(Message, strParams);
String strMessageLine = String.Format("{0},{2}-{3},{1}",
DateTime.Now, Message, Assembly.GetExecutingAssembly().GetName().Name,
MethodBase.GetCurrentMethod().DeclaringType.Name);
Debug.Log(strMessageLine);
}

#endregion Logging Stuff
}
}
Loading