Skip to content

Commit

Permalink
Updated for 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxgurugamer committed Jun 11, 2017
1 parent 3b07b27 commit 6d50370
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 95 deletions.
Binary file modified GameData/ProbeControlRoom/ProbeControlRoom.dll
Binary file not shown.
Binary file modified GameData/ProbeControlRoom/ProbeControlRoomToolbar.dll
Binary file not shown.
146 changes: 73 additions & 73 deletions ProbeControlRoom/DynamicEmitFields.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
/*
VirindiHelpers.DynamicEmitFields
Copyright (C) 2017 Virindi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Reflection;
using System.Reflection.Emit;

namespace VirindiHelpers
{
static class DynamicEmitFields
{
public delegate T delCreateDynamicInstanceFieldGet<T, Cls>(Cls c);
public static delCreateDynamicInstanceFieldGet<T, Cls> CreateDynamicInstanceFieldGet<T, Cls>(string fieldname)
{
string newname = string.Format("__DynGet__{0}__{1}", typeof(Cls), fieldname);

FieldInfo fi = typeof(Cls).GetField(fieldname, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
if (fi == null)
throw new ArgumentException ("Instance field not found.", "fieldname");
if (typeof(T) != fi.FieldType)
throw new ArgumentException ("Instance field is of the wrong type.", "fieldname");

DynamicMethod temp = new DynamicMethod(newname, MethodAttributes.Static | MethodAttributes.Public, CallingConventions.Standard, typeof(T), new Type[] { typeof(Cls) }, MethodBase.GetCurrentMethod().DeclaringType, true);

ILGenerator gen = temp.GetILGenerator();
gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Ldfld, fi);
gen.Emit(OpCodes.Ret);

delCreateDynamicInstanceFieldGet<T, Cls> ret = (delCreateDynamicInstanceFieldGet<T, Cls>)temp.CreateDelegate(typeof(delCreateDynamicInstanceFieldGet<T, Cls>));

return ret;
}

public delegate void delCreateDynamicInstanceFieldSet<T, Cls>(Cls c, T val);
public static delCreateDynamicInstanceFieldSet<T, Cls> CreateDynamicInstanceFieldSet<T, Cls>(string fieldname)
{
string newname = string.Format("__DynSet__{0}__{1}", typeof(Cls), fieldname);

FieldInfo fi = typeof(Cls).GetField(fieldname, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
if (fi == null)
throw new ArgumentException ("Instance field not found.", "fieldname");
if (typeof(T) != fi.FieldType)
throw new ArgumentException ("Instance field is of the wrong type.", "fieldname");

DynamicMethod temp = new DynamicMethod(newname, MethodAttributes.Static | MethodAttributes.Public, CallingConventions.Standard, null, new Type[] { typeof(Cls), typeof(T) }, MethodBase.GetCurrentMethod().DeclaringType, true);

ILGenerator gen = temp.GetILGenerator();
gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Ldarg_1);
gen.Emit(OpCodes.Stfld, fi);
gen.Emit(OpCodes.Ret);

delCreateDynamicInstanceFieldSet<T, Cls> ret = (delCreateDynamicInstanceFieldSet<T, Cls>)temp.CreateDelegate(typeof(delCreateDynamicInstanceFieldSet<T, Cls>));
return ret;
}
}
}
/*
VirindiHelpers.DynamicEmitFields
Copyright (C) 2017 Virindi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Reflection;
using System.Reflection.Emit;

namespace VirindiHelpers
{
static class DynamicEmitFields
{
public delegate T delCreateDynamicInstanceFieldGet<T, Cls>(Cls c);
public static delCreateDynamicInstanceFieldGet<T, Cls> CreateDynamicInstanceFieldGet<T, Cls>(string fieldname)
{
string newname = string.Format("__DynGet__{0}__{1}", typeof(Cls), fieldname);

FieldInfo fi = typeof(Cls).GetField(fieldname, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
if (fi == null)
throw new ArgumentException ("Instance field not found.", "fieldname");
if (typeof(T) != fi.FieldType)
throw new ArgumentException ("Instance field is of the wrong type.", "fieldname");

DynamicMethod temp = new DynamicMethod(newname, MethodAttributes.Static | MethodAttributes.Public, CallingConventions.Standard, typeof(T), new Type[] { typeof(Cls) }, MethodBase.GetCurrentMethod().DeclaringType, true);

ILGenerator gen = temp.GetILGenerator();
gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Ldfld, fi);
gen.Emit(OpCodes.Ret);

delCreateDynamicInstanceFieldGet<T, Cls> ret = (delCreateDynamicInstanceFieldGet<T, Cls>)temp.CreateDelegate(typeof(delCreateDynamicInstanceFieldGet<T, Cls>));

return ret;
}

public delegate void delCreateDynamicInstanceFieldSet<T, Cls>(Cls c, T val);
public static delCreateDynamicInstanceFieldSet<T, Cls> CreateDynamicInstanceFieldSet<T, Cls>(string fieldname)
{
string newname = string.Format("__DynSet__{0}__{1}", typeof(Cls), fieldname);

FieldInfo fi = typeof(Cls).GetField(fieldname, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
if (fi == null)
throw new ArgumentException ("Instance field not found.", "fieldname");
if (typeof(T) != fi.FieldType)
throw new ArgumentException ("Instance field is of the wrong type.", "fieldname");

DynamicMethod temp = new DynamicMethod(newname, MethodAttributes.Static | MethodAttributes.Public, CallingConventions.Standard, null, new Type[] { typeof(Cls), typeof(T) }, MethodBase.GetCurrentMethod().DeclaringType, true);

ILGenerator gen = temp.GetILGenerator();
gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Ldarg_1);
gen.Emit(OpCodes.Stfld, fi);
gen.Emit(OpCodes.Ret);

delCreateDynamicInstanceFieldSet<T, Cls> ret = (delCreateDynamicInstanceFieldSet<T, Cls>)temp.CreateDelegate(typeof(delCreateDynamicInstanceFieldSet<T, Cls>));
return ret;
}
}
}

8 changes: 4 additions & 4 deletions ProbeControlRoom/ProbeControlRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public class ProbeControlRoom : MonoBehaviour
bool HasCachedVesselLabelsSetting = false;
bool CachedVesselLabelsSetting = false;
bool VesselLabelKeyDisabled = false;
KeyCode CachedLabelPrimaryKey = GameSettings.TOGGLE_LABELS.primary;
KeyCode CachedLabelSecondaryKey = GameSettings.TOGGLE_LABELS.secondary;
KeyCodeExtended CachedLabelPrimaryKey = GameSettings.TOGGLE_LABELS.primary;
KeyCodeExtended CachedLabelSecondaryKey = GameSettings.TOGGLE_LABELS.secondary;
private static System.Reflection.MethodInfo method_vessellabels_enablealllabels = null;
private static System.Reflection.MethodInfo method_vessellabels_disablealllabels = null;

Expand Down Expand Up @@ -467,8 +467,8 @@ public bool startIVA()
VesselLabelKeyDisabled = true;
CachedLabelPrimaryKey = GameSettings.TOGGLE_LABELS.primary;
CachedLabelSecondaryKey = GameSettings.TOGGLE_LABELS.secondary;
GameSettings.TOGGLE_LABELS.primary = KeyCode.None;
GameSettings.TOGGLE_LABELS.secondary = KeyCode.None;
GameSettings.TOGGLE_LABELS.primary = new KeyCodeExtended(KeyCode.None);
GameSettings.TOGGLE_LABELS.secondary = new KeyCodeExtended(KeyCode.None);
}
SetVesselLabelsValue (false);

Expand Down
29 changes: 14 additions & 15 deletions ProbeControlRoom/ProbeControlRoom.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,30 @@
</CustomCommands>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProbeControlRoom.cs" />
<Compile Include="ProbeControlRoomPart.cs" />
<Compile Include="ProbeControlRoomUtils.cs" />
<Compile Include="ProbeControlRoomSettings.cs" />
<Compile Include="DynamicEmitFields.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\ksp-win64-1.2.2 - Copy\KSP_win64\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>R:\KSP_1.3.0_dev\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\ksp-win64-1.2.2 - Copy\KSP_win64\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath>R:\KSP_1.3.0_dev\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="KSPAssets">
<HintPath>..\..\..\ksp-win64-1.2.2 - Copy\KSP_win64\KSP_x64_Data\Managed\KSPAssets.dll</HintPath>
<Reference Include="System">
<HintPath>R:\KSP_1.3.0_dev\KSP_x64_Data\Managed\System.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\ksp-win64-1.2.2 - Copy\KSP_win64\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>R:\KSP_1.3.0_dev\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\..\..\ksp-win64-1.2.2 - Copy\KSP_win64\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
<HintPath>R:\KSP_1.3.0_dev\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProbeControlRoom.cs" />
<Compile Include="ProbeControlRoomPart.cs" />
<Compile Include="ProbeControlRoomUtils.cs" />
<Compile Include="ProbeControlRoomSettings.cs" />
<Compile Include="DynamicEmitFields.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy /Y "$(TargetDir)$(TargetFileName)" "$(SolutionDir)GameData\ProbeControlRoom\$(TargetFileName)"</PostBuildEvent>
Expand Down
12 changes: 9 additions & 3 deletions ProbeControlRoomToolbar/ProbeControlRoomToolbar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\Development\Kerbal Space Program\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>R:\KSP_1.3.0_dev\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>R:\KSP_1.3.0_dev\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="Toolbar">
<HintPath>F:\Development\Kerbal Space Program\GameData\000_Toolbar\Toolbar.dll</HintPath>
<HintPath>R:\KSP_1.3.0_dev\GameData\000_Toolbar\Toolbar.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\..\Development\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>R:\KSP_1.3.0_dev\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>R:\KSP_1.3.0_dev\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 6d50370

Please sign in to comment.