Skip to content

Commit

Permalink
Changes to work on Linux & OSX, reflection references had to be changed
Browse files Browse the repository at this point in the history
from by name to by offset
  • Loading branch information
linuxgurugamer committed Apr 26, 2016
1 parent 732b670 commit 657c78f
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 98 deletions.
16 changes: 9 additions & 7 deletions EditorExtensionsRedux.userprefs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<Properties StartupItem="Packagers\BetaPackage.mdproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
<MonoDevelop.Ide.Workbench ActiveDocument="EditorExtensionsRedux\EditorExtensionsRedux.version">
<MonoDevelop.Ide.Workbench ActiveDocument="EditorExtensionsRedux\buildRelease.bat">
<Files>
<File FileName="EditorExtensionsRedux\SelectRoot2Behaviour.cs" Line="63" Column="12" />
<File FileName="EditorExtensionsRedux\NoOffsetLimits\NoOffsetLimitsBehaviour.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\buildRelease.bat" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\NoOffsetLimits\NoOffsetLimitsBehaviour.cs" Line="54" Column="13" />
<File FileName="EditorExtensionsRedux\EditorExtensionsRedux.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\Utility.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\SelectRoot2Behaviour.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\buildRelease.bat" Line="43" Column="10" />
<File FileName="EditorExtensionsRedux\deploy.bat" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\Config\ConfigManager.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\EditorExtensionsRedux.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\Logging.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\AppLauncherButton.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\Config\ConfigData.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\PartInfoWindow.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\EditorExtensionsRedux.version" Line="10" Column="12" />
<File FileName="EditorExtensionsRedux\EditorExtensionsRedux.version" Line="9" Column="12" />
<File FileName="EditorExtensionsRedux\StripSymmetry\Enums.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\StripSymmetry\ExtensionMethods.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\Utility.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\StripSymmetry\Hotkey.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\SettingsWindow.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\StripSymmetry\Tools.cs" Line="1" Column="1" />
<File FileName="README.md" Line="46" Column="30" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
Expand Down
83 changes: 82 additions & 1 deletion EditorExtensionsRedux/EditorExtensionsRedux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;

using System.Reflection;
using KSP.IO;
using UnityEngine;
Expand All @@ -19,6 +21,7 @@ public class EditorExtensions : MonoBehaviour

#region member vars


const string ConfigFileName = "config.xml";
const string DegreesSymbol = "\u00B0";

Expand All @@ -40,7 +43,7 @@ public class EditorExtensions : MonoBehaviour
bool zoomSelected = false;
#endregion

public EditorExtensions (){}
// public EditorExtensions (){}

//Unity initialization call, called first
public void Awake ()
Expand All @@ -49,6 +52,81 @@ public void Awake ()
Log.Debug ("launchSiteName: " + EditorLogic.fetch.launchSiteName);
}

#if DEBUG
// http://stackoverflow.com/a/1615860
private static string EncodeNonAsciiCharacters(string value) {
StringBuilder sb = new StringBuilder();
foreach(char c in value) {
// This character is too big for ASCII
string encodedValue = "\\u" + ((int)c).ToString("x4");
sb.Append(encodedValue);
}
return sb.ToString();
}

void localdumpReflection()
{
//Log.Debug("States:");
//foreach (var f in EditorLogic.fetch.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
// if (f.FieldType == typeof(KFSMState)) {
// Log.Debug ("State: " + ((KFSMState)f.GetValue (EditorLogic.fetch)).name + " + " + EncodeNonAsciiCharacters (f.Name));
// }
//}
//Log.Debug("Events:");
//foreach (var f in EditorLogic.fetch.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
// if (f.FieldType == typeof(KFSMEvent)) {
// Log.Debug ("State: " + ((KFSMEvent)f.GetValue (EditorLogic.fetch)).name + " + " + EncodeNonAsciiCharacters (f.Name));
// }
//}

//Log.Debug("State/Event enumeration done.");
EditorLogic el = EditorLogic.fetch;
int c = 0;
foreach (FieldInfo FI in el.GetType().GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
Log.Info ("EditorLogic Field name[" + c.ToString() + "]: " + FI.Name + " Fieldtype: " + FI.FieldType.ToString());
c++;
}

KFSMEvent ke = new KFSMEvent("a");
c = 0;
foreach (FieldInfo FI in ke.GetType().GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
Log.Info ("KFSMEvent KFSMEvent Field name[" + c.ToString() + "]: " + FI.Name + " Fieldtype: " + FI.FieldType.ToString());
c++;
}

MethodInfo[] leMethods = typeof(EditorLogic).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
c = 0;
foreach (MethodInfo FI in leMethods) {
Log.Info ("MethodInfo EditorLogic methods name[" + c.ToString() + "]: " + FI.Name );
c++;
}

MethodInfo[] parts = typeof(Part).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
c = 0;
foreach (MethodInfo FI in parts) {
Log.Info ("MethodInfo Part name[" + c.ToString() + "]: " + FI.Name );
c++;
}

MethodInfo[] kfe = typeof(KFSMEvent).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
c = 0;
foreach (MethodInfo FI in kfe) {
Log.Info ("MethodInfo KFSMEvent methods name[" + c.ToString() + "]: " + FI.Name );
c++;
}


MethodInfo[] ks = typeof(KFSMState).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
c = 0;
foreach (MethodInfo FI in ks) {
Log.Info ("MethodInfo KFSMState methods name[" + c.ToString() + "]: " + FI.Name + " " + FI.ToString() );
c++;
}


}
#endif

//Unity, called after Awake()
public void Start()
{
Expand All @@ -59,6 +137,9 @@ public void Start()
InitializeGUI ();
GameEvents.onEditorPartEvent.Add (EditorPartEvent);
GameEvents.onEditorSymmetryModeChange.Add (EditorSymmetryModeChange);
#if DEBUG
localdumpReflection ();
#endif
}

//Unity OnDestroy
Expand Down
4 changes: 2 additions & 2 deletions EditorExtensionsRedux/EditorExtensionsRedux.version
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{
"MAJOR":3,
"MINOR":2,
"PATCH":1,
"BUILD":9
"PATCH":2,
"BUILD":0
},
"KSP_VERSION":
{
Expand Down
51 changes: 20 additions & 31 deletions EditorExtensionsRedux/NoOffsetLimits/NoOffsetLimitsBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ namespace EditorExtensionsRedux.NoOffsetBehaviour {
public class FreeOffsetBehaviour : MonoBehaviour {
//private Log log;

const int ST_OFFSET_TWEAK = 73;
const int SYMUPDATEATTACHNODE = 108;
const int GIZMOOFFSET = 66;

const int UPDATESYMMETRY = 64;
const int ONOFFSETGIZMOUPDATED = 35;

private delegate void CleanupFn();
private CleanupFn OnCleanup;

Expand All @@ -25,14 +32,16 @@ public void Start() {
//log = new Log(this.GetType().Name);
Log.Debug("Start");

var st_offset_tweak = (KFSMState)Refl.GetValue(EditorLogic.fetch, "st_offset_tweak");

// var st_offset_tweak = (KFSMState)Refl.GetValue(EditorLogic.fetch, "st_offset_tweak");
var st_offset_tweak = (KFSMState)Refl.GetValue(EditorLogic.fetch,ST_OFFSET_TWEAK);

KFSMStateChange hookOffsetUpdateFn = (from) => {
var p = EditorLogic.SelectedPart;
var parent = p.parent;
var symCount = p.symmetryCounterparts.Count;
//var attachNode = Refl.GetValue(EditorLogic.fetch, "\u001B\u0002");
var attachNode = Refl.GetValue(EditorLogic.fetch, "symUpdateAttachNode");
//var attachNode = Refl.GetValue(EditorLogic.fetch, "symUpdateAttachNode");
var symUpdateAttachNode = Refl.GetValue(EditorLogic.fetch, SYMUPDATEATTACHNODE);
gizmo = GizmoOffset.Attach(EditorLogic.SelectedPart.transform,
new Callback<Vector3>((offset) => {
Expand All @@ -41,18 +50,22 @@ public void Start() {
Log.Info("symCount: " + symCount.ToString());
if(symCount != 0) {
Refl.Invoke(EditorLogic.fetch, "UpdateSymmetry", p, symCount, parent, attachNode);
// Refl.Invoke(EditorLogic.fetch, "UpdateSymmetry", p, symCount, parent, symUpdateAttachNode);
Refl.Invoke(EditorLogic.fetch, UPDATESYMMETRY, p, symCount, parent, symUpdateAttachNode);
}
GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartOffsetting, EditorLogic.SelectedPart);
}), new Callback<Vector3>((offset) => {
Refl.Invoke(EditorLogic.fetch, "onOffsetGizmoUpdated", offset);
//Refl.Invoke(EditorLogic.fetch, "onOffsetGizmoUpdated", offset);
Refl.Invoke(EditorLogic.fetch, ONOFFSETGIZMOUPDATED, offset);
}), EditorLogic.fetch.editorCamera);
//((GizmoOffset)Refl.GetValue(EditorLogic.fetch, "\u0012")).Detach();
//Refl.SetValue(EditorLogic.fetch, "\u0012", gizmo);
((GizmoOffset)Refl.GetValue(EditorLogic.fetch, "gizmoOffset")).Detach();
Refl.SetValue(EditorLogic.fetch, "gizmoOffset", gizmo);
//((GizmoOffset)Refl.GetValue(EditorLogic.fetch, "gizmoOffset")).Detach();
((GizmoOffset)Refl.GetValue(EditorLogic.fetch, GIZMOOFFSET)).Detach();
//Refl.SetValue(EditorLogic.fetch, "gizmoOffset", gizmo);
Refl.SetValue(EditorLogic.fetch, GIZMOOFFSET, gizmo);
};
st_offset_tweak.OnEnter += hookOffsetUpdateFn;
OnCleanup += () => {
Expand All @@ -67,29 +80,5 @@ public void OnDestroy() {
Log.Debug("Cleanup complete.");
}
}

#if false
public static class Refl {
public static FieldInfo GetField(object obj, string name) {
var f = obj.GetType().GetField(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if(f == null) throw new Exception("No such field: " + obj.GetType() + "#" + name);
return f;
}
public static object GetValue(object obj, string name) {
return GetField(obj, name).GetValue(obj);
}
public static void SetValue(object obj, string name, object value) {
GetField(obj, name).SetValue(obj, value);
}
public static MethodInfo GetMethod(object obj, string name) {
var m = obj.GetType().GetMethod(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if(m == null) throw new Exception("No such method: " + obj.GetType() + "#" + name);
return m;
}
public static object Invoke(object obj, string name, params object[] args) {
return GetMethod(obj, name).Invoke(obj, args);
}
}
#endif
}
#endif
Loading

0 comments on commit 657c78f

Please sign in to comment.