Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 968546d

Browse files
committed
2.0.6
* Unstrip fixes and cleanups
1 parent 680556d commit 968546d

18 files changed

+1971
-296
lines changed

src/Explorer.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@
262262
<Compile Include="UI\WindowBase.cs" />
263263
<Compile Include="UI\WindowManager.cs" />
264264
<Compile Include="Unstrip\ImageConversion\ImageConversionUnstrip.cs" />
265+
<Compile Include="Unstrip\IMGUI\Internal_GUIUtility.cs" />
266+
<Compile Include="Unstrip\IMGUI\Internal_TextEditor.cs" />
265267
<Compile Include="Unstrip\LayerMask\LayerMaskUnstrip.cs" />
266268
<Compile Include="Unstrip\Scene\SceneUnstrip.cs" />
267269
<Compile Include="Unstrip\IMGUI\GUIUnstrip.cs" />

src/ExplorerCore.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Explorer.Config;
1+
using System.Collections;
2+
using System.Linq;
3+
using Explorer.Config;
24
using Explorer.UI;
35
using Explorer.UI.Inspectors;
46
using Explorer.UI.Main;
@@ -10,7 +12,7 @@ namespace Explorer
1012
public class ExplorerCore
1113
{
1214
public const string NAME = "Explorer " + VERSION + " (" + PLATFORM + ", " + MODLOADER + ")";
13-
public const string VERSION = "2.0.5";
15+
public const string VERSION = "2.0.6";
1416
public const string AUTHOR = "Sinai";
1517
public const string GUID = "com.sinai.explorer";
1618

src/Helpers/Texture2DHelpers.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Explorer.Helpers
1313
{
1414
public static class Texture2DHelpers
1515
{
16-
#if CPP
16+
#if CPP // If Mono
1717
#else
1818
private static bool isNewEncodeMethod = false;
1919
private static MethodInfo EncodeToPNGMethod => m_encodeToPNGMethod ?? GetEncodeToPNGMethod();
@@ -56,43 +56,38 @@ public static bool IsReadable(this Texture2D tex)
5656
}
5757
}
5858

59-
public static Texture2D Copy(Texture2D other, Rect rect, bool isDTXnmNormal = false)
59+
public static Texture2D Copy(Texture2D orig, Rect rect, bool isDTXnmNormal = false)
6060
{
6161
Color[] pixels;
6262

63-
if (!other.IsReadable())
63+
if (!orig.IsReadable())
6464
{
65-
other = ForceReadTexture(other, isDTXnmNormal);
65+
orig = ForceReadTexture(orig);
6666
}
6767

68-
pixels = other.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
68+
pixels = orig.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
6969

7070
var _newTex = new Texture2D((int)rect.width, (int)rect.height);
7171
_newTex.SetPixels(pixels);
7272

7373
return _newTex;
7474
}
7575

76-
public static Texture2D ForceReadTexture(Texture2D tex, bool isDTXnmNormal = false)
76+
public static Texture2D ForceReadTexture(Texture2D tex)
7777
{
7878
try
7979
{
8080
var origFilter = tex.filterMode;
8181
tex.filterMode = FilterMode.Point;
8282

83-
RenderTexture rt = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32);
83+
var rt = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32);
8484
rt.filterMode = FilterMode.Point;
8585
RenderTexture.active = rt;
8686
Graphics.Blit(tex, rt);
8787

88-
Texture2D _newTex = new Texture2D(tex.width, tex.height, TextureFormat.RGBA32, false);
89-
_newTex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
90-
91-
if (isDTXnmNormal)
92-
{
93-
_newTex = DTXnmToRGBA(_newTex);
94-
}
88+
var _newTex = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
9589

90+
_newTex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
9691
_newTex.Apply(false, false);
9792

9893
RenderTexture.active = null;
@@ -117,8 +112,11 @@ public static void SaveTextureAsPNG(Texture2D tex, string dir, string name, bool
117112
byte[] data;
118113
var savepath = dir + @"\" + name + ".png";
119114

120-
// Fix for non-Readable or Compressed textures.
121-
tex = ForceReadTexture(tex, isDTXnmNormal);
115+
// Make sure we can EncodeToPNG it.
116+
if (tex.format != TextureFormat.ARGB32 || !tex.IsReadable())
117+
{
118+
tex = ForceReadTexture(tex);
119+
}
122120

123121
if (isDTXnmNormal)
124122
{
@@ -129,15 +127,13 @@ public static void SaveTextureAsPNG(Texture2D tex, string dir, string name, bool
129127
#if CPP
130128
data = tex.EncodeToPNG();
131129
#else
132-
var method = EncodeToPNGMethod;
133-
134130
if (isNewEncodeMethod)
135131
{
136-
data = (byte[])method.Invoke(null, new object[] { tex });
132+
data = (byte[])EncodeToPNGMethod.Invoke(null, new object[] { tex });
137133
}
138134
else
139135
{
140-
data = (byte[])method.Invoke(tex, new object[0]);
136+
data = (byte[])EncodeToPNGMethod.Invoke(tex, new object[0]);
141137
}
142138
#endif
143139

@@ -148,8 +144,10 @@ public static void SaveTextureAsPNG(Texture2D tex, string dir, string name, bool
148144
else
149145
{
150146
#if CPP
151-
// The IL2CPP method will return invalid byte data.
152-
// However, we can just iterate into safe C# byte[] array.
147+
// The Il2Cpp EncodeToPNG() method does return System.Byte[],
148+
// but for some reason it is not recognized or valid.
149+
// Simple fix is iterating into a new array manually.
150+
153151
byte[] safeData = new byte[data.Length];
154152
for (int i = 0; i < data.Length; i++)
155153
{
@@ -185,7 +183,7 @@ public static Texture2D DTXnmToRGBA(Texture2D tex)
185183
);
186184
}
187185

188-
var newtex = new Texture2D(tex.width, tex.height, TextureFormat.RGBA32, false);
186+
var newtex = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
189187
newtex.SetPixels(colors);
190188

191189
return newtex;

src/Input/InputManager.cs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,37 @@ public static void Init()
5050
public static void ResetInputAxes() => UnityEngine.Input.ResetInputAxes();
5151
#endif
5252

53-
//#if CPP
54-
//#pragma warning disable IDE1006
55-
// // public extern static string compositionString { get; }
53+
#if CPP
54+
#pragma warning disable IDE1006
55+
// public extern static string compositionString { get; }
5656

57-
// internal delegate string get_compositionString_delegate();
58-
// internal static get_compositionString_delegate get_compositionString_iCall =
59-
// IL2CPP.ResolveICall<get_compositionString_delegate>("UnityEngine.Input::get_compositionString");
57+
internal delegate IntPtr d_get_compositionString();
58+
internal static d_get_compositionString get_compositionString_iCall =
59+
IL2CPP.ResolveICall<d_get_compositionString>("UnityEngine.Input::get_compositionString");
6060

61-
// public static string compositionString => get_compositionString_iCall();
61+
public static string compositionString => IL2CPP.Il2CppStringToManaged(get_compositionString_iCall());
6262

63-
// // public extern static Vector2 compositionCursorPos { get; set; }
63+
// public extern static Vector2 compositionCursorPos { get; set; }
6464

65-
// internal delegate Vector2 get_compositionCursorPos_delegate();
66-
// internal static get_compositionCursorPos_delegate get_compositionCursorPos_iCall =
67-
// IL2CPP.ResolveICall<get_compositionCursorPos_delegate>("UnityEngine.Input::get_compositionCursorPos");
65+
internal delegate void d_get_compositionCursorPos(out Vector2 ret);
66+
internal static d_get_compositionCursorPos get_compositionCursorPos_iCall =
67+
IL2CPP.ResolveICall<d_get_compositionCursorPos>("UnityEngine.Input::get_compositionCursorPos_Injected");
6868

69-
// internal delegate void set_compositionCursorPos_delegate(Vector2 value);
70-
// internal static set_compositionCursorPos_delegate set_compositionCursorPos_iCall =
71-
// IL2CPP.ResolveICall<set_compositionCursorPos_delegate>("UnityEngine.Input::set_compositionCursorPos");
69+
internal delegate void set_compositionCursorPos_delegate(ref Vector2 value);
70+
internal static set_compositionCursorPos_delegate set_compositionCursorPos_iCall =
71+
IL2CPP.ResolveICall<set_compositionCursorPos_delegate>("UnityEngine.Input::set_compositionCursorPos_Injected");
7272

73-
// public static Vector2 compositionCursorPos
74-
// {
75-
// get => get_compositionCursorPos_iCall();
76-
// set => set_compositionCursorPos_iCall(value);
77-
// }
73+
public static Vector2 compositionCursorPos
74+
{
75+
get
76+
{
77+
get_compositionCursorPos_iCall(out Vector2 ret);
78+
return ret;
79+
}
80+
set => set_compositionCursorPos_iCall(ref value);
81+
}
7882

79-
//#pragma warning restore IDE1006
80-
//#endif
83+
#pragma warning restore IDE1006
84+
#endif
8185
}
8286
}

src/UI/Inspectors/Reflection/InstanceInspector.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ public override void Update()
7272

7373
public void DrawInstanceControls(Rect rect)
7474
{
75-
if (m_uObj)
76-
{
77-
GUILayout.Label("Name: " + m_uObj.name, new GUILayoutOption[0]);
78-
}
79-
GUILayout.EndHorizontal();
75+
//if (m_uObj)
76+
//{
77+
// GUILayout.Label("Name: " + m_uObj.name, new GUILayoutOption[0]);
78+
//}
79+
//GUILayout.EndHorizontal();
8080

8181
if (m_uObj)
8282
{
@@ -89,13 +89,17 @@ public void DrawInstanceControls(Rect rect)
8989
GUILayout.Label("GameObject:", new GUILayoutOption[] { GUILayout.Width(135) });
9090
var charWidth = obj.name.Length * 15;
9191
var maxWidth = rect.width - 350;
92-
var labelWidth = charWidth < maxWidth ? charWidth : maxWidth;
93-
if (GUILayout.Button("<color=#00FF00>" + obj.name + "</color>", new GUILayoutOption[] { GUILayout.Width(labelWidth) }))
92+
var btnWidth = charWidth < maxWidth ? charWidth : maxWidth;
93+
if (GUILayout.Button("<color=#00FF00>" + obj.name + "</color>", new GUILayoutOption[] { GUILayout.Width(btnWidth) }))
9494
{
9595
WindowManager.InspectObject(obj, out bool _);
9696
}
9797
GUI.skin.label.alignment = TextAnchor.UpperLeft;
9898
}
99+
else
100+
{
101+
GUILayout.Label("Name: " + m_uObj.name, new GUILayoutOption[0]);
102+
}
99103
GUILayout.EndHorizontal();
100104
}
101105
}

src/UI/Inspectors/ReflectionInspector.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,12 @@ public override void WindowFunction(int windowID)
263263
? new GUILayoutOption[] { GUILayout.Width(245f) }
264264
: new GUILayoutOption[0];
265265
GUILayout.Label("<b>Type:</b> <color=cyan>" + TargetType.FullName + "</color>", labelWidth);
266+
GUILayout.EndHorizontal();
266267

267268
if (asInstance != null)
268269
{
269270
asInstance.DrawInstanceControls(rect);
270271
}
271-
else
272-
{
273-
GUILayout.EndHorizontal();
274-
}
275272

276273
UIStyles.HorizontalLine(Color.grey);
277274

src/UI/InteractiveValue/Object/InteractiveEnumerable.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
using UnityEngine;
77
using Explorer.UI.Shared;
88
using Explorer.CacheObject;
9+
using System.Linq;
10+
#if CPP
11+
using UnhollowerBaseLib;
12+
#endif
913

1014
namespace Explorer.UI
1115
{

src/UI/Main/ConsolePage.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ConsolePage : BaseMainMenuPage
3333
public static TextEditor textEditor;
3434
private bool shouldRefocus;
3535

36-
public static GUIStyle AutocompleteStyle => autocompleteStyle ?? GetCompletionStyle();
36+
public static GUIStyle AutocompleteStyle => autocompleteStyle ?? GetAutocompleteStyle();
3737
private static GUIStyle autocompleteStyle;
3838

3939
public static readonly string[] DefaultUsing = new string[]
@@ -342,9 +342,9 @@ private void GetAutocompletes(string input)
342342
}
343343

344344
// Credit ManlyMarco
345-
private static GUIStyle GetCompletionStyle()
345+
private static GUIStyle GetAutocompleteStyle()
346346
{
347-
return autocompleteStyle = new GUIStyle(GUI.skin.button)
347+
var style = new GUIStyle
348348
{
349349
border = new RectOffset(0, 0, 0, 0),
350350
margin = new RectOffset(0, 0, 0, 0),
@@ -353,8 +353,10 @@ private static GUIStyle GetCompletionStyle()
353353
normal = { background = null },
354354
focused = { background = Texture2D.whiteTexture, textColor = Color.black },
355355
active = { background = Texture2D.whiteTexture, textColor = Color.black },
356-
alignment = TextAnchor.MiddleLeft,
356+
alignment = TextAnchor.MiddleLeft
357357
};
358+
359+
return autocompleteStyle = style;
358360
}
359361

360362
private class VoidType

0 commit comments

Comments
 (0)