Skip to content

Instantly share code, notes, and snippets.

@sailro
Created April 21, 2015 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sailro/0f5c6501701b5f327597 to your computer and use it in GitHub Desktop.
Save sailro/0f5c6501701b5f327597 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System;
using System.Text;
using System.Linq;
public class Test : MonoBehaviour {
string testCecilSpec;
int[,] dynArray;
int[][][] dynJaggedArray;
static T CreateJaggedArray<T>(params int[] lengths) {
return (T)CreateJaggedArray(typeof(T).GetElementType(), 0, lengths);
}
static object CreateJaggedArray(Type type, int index, int[] lengths) {
var array = Array.CreateInstance(type, lengths[index]);
var elementType = type.GetElementType();
if (elementType != null)
for (int i = 0; i < lengths[index]; i++)
array.SetValue(CreateJaggedArray(elementType, index + 1, lengths), i);
return array;
}
public string MagicConcat(__arglist) {
var builder = new StringBuilder();
ArgIterator ai = new ArgIterator(__arglist);
while (ai.GetRemainingCount() > 0)
{
var tr = ai.GetNextArg();
builder.Append(TypedReference.ToObject(tr));
}
return builder.ToString();
}
unsafe void Start() {
// Test Cecil specs with GenericTypeInstance(Of ArrayType( Of GenericTypeInstance(Of int) ) )
Predicate<Nullable<int>[]> foo = t => t.Length == 3 && t[0] == 6 && !t[1].HasValue && t[2] == 1;
testCecilSpec = foo(new int?[]{6, null, 1}).ToString();
// Test pointers
fixed (char* s = testCecilSpec)
{
short* p = (short*)s;
*(p++) = (short)'X';
*(p++) = (short)'Y';
}
// Test dynamic arrays with lower bounds
dynArray = (int[,])Array.CreateInstance(typeof(int), new int[] { 4, 2 }, new int[] { -4, -1 });
dynArray[-2, -1] = 666;
// Test dynamic jagged array
dynJaggedArray = CreateJaggedArray<int[][][]>(1, 2, 3);
dynJaggedArray[0][1][2] = 999;
}
void OnGUI () {
// Undocumented __makeref, __refvalue and __arglist. Supported by Mono and VS
var str = testCecilSpec + dynArray[-2, -1] + dynJaggedArray[0][1][2] + "-" + MagicConcat(__arglist(1, "a", 5));
GUI.Label(new Rect(0, 0, 128, 32), str); // Should be "XYue666999-1a5" (works in the Unity Editor)
}
}
@sailro
Copy link
Author

sailro commented Apr 21, 2015

__arglist is using a specific OpCode

@sailro
Copy link
Author

sailro commented Apr 21, 2015

Exception: C:\Program Files\Unity\Editor\Data\Tools/UnusedByteCodeStripper2/UnusedBytecodeStripper2.exe did not run properly!
UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:68)
UnityEditorInternal.AssemblyStripper.RunAssemblyLinker (IEnumerable1 args, System.String& out, System.String& err, System.String linkerPath, System.String workingDirectory) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:192) UnityEditorInternal.AssemblyStripper.StripAssembliesTo (System.String outputFolder, System.String workingDirectory, System.String& output, System.String& error, System.String linkerPath, System.String descriptorsFolder, IEnumerable1 additionalBlacklist) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:185)
UnityEditorInternal.AssemblyStripper.Strip (System.String outputFolder, System.String workingDirectory, System.String& output, System.String& error, System.String monoLinkerPath, System.String descriptorsFolder, IEnumerable1 additionalBlacklist) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:136) UnityEditorInternal.AssemblyStripper.Strip (System.String[] assemblies, System.String[] searchDirs, System.String outputFolder, System.String workingDirectory, System.String& output, System.String& error, System.String monoLinkerPath, System.String descriptorsFolder, IEnumerable1 additionalBlacklist) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:121)
UnityEditorInternal.IL2CPPBuilder.RunAssemblyStripper (IEnumerable assemblies, System.String managedAssemblyFolderPath, System.String[] assembliesToStrip, System.String[] searchDirs, System.String monoLinkerPath) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:445)
UnityEditorInternal.IL2CPPBuilder.StripAssemblies (System.String[] assemblies, System.String managedAssemblyFolderPath) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:433)
UnityEditorInternal.IL2CPPBuilder.Run () (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:273)
UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String stagingAreaData, IIl2CppPlatformProvider platformProvider, System.Action`1 modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:218)
UnityEditor.WebGL.WebGlBuildPostprocessor.PostProcess (BuildPostProcessArgs args)
UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:316)
UnityEditor.HostView:OnGUI()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment