Skip to content

Commit 57d24e6

Browse files
loonglyliuyunlong
authored andcommitted
+ ios runing
1 parent 6fe46cb commit 57d24e6

23 files changed

Lines changed: 189 additions & 963 deletions

File tree

BindGenerater/Tools/ScriptEngine.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
using System.Runtime.InteropServices;
33
using AOT;
44
using System;
5-
#if UNITY_EDITOR
6-
using UnityEditor;
7-
#endif
5+
86
namespace PureScript
97
{
108
public class ScriptEngine
119
{
12-
const string XMONO_LIB = "ScriptEngine";
10+
11+
const string XMONO_LIB = "__Internal";
12+
13+
//const string XMONO_LIB = "ScriptEngine";
14+
1315

1416
[DllImport(XMONO_LIB, CallingConvention = CallingConvention.Cdecl)]
1517
public static extern IntPtr GetFuncPointer();

DemoProject/MonoTest/EngineTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public static void Main(string[] args)
2323

2424
static void StartTest()
2525
{
26-
var ptr = ScriptEngine.GetFuncPointer();
27-
MonoBind.InitBind(ptr);
26+
//var ptr = ScriptEngine.GetFuncPointer();
27+
//MonoBind.InitBind(ptr);
2828

29-
DebugHelper.InitLog(true);
29+
//DebugHelper.InitLog(true);
3030

3131
Debug.LogError(" ========223 中午 ==== +-*x&!@$#$()_+<>?{}|ff ~");
3232

@@ -36,9 +36,9 @@ static void StartTest()
3636

3737
var obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
3838
//obj.AddComponent<TestDelegate>();
39-
//obj.AddComponent<TestLoader>();
40-
//obj.AddComponent<TestBehaviourScript>();
41-
obj.AddComponent<TestException>();
39+
obj.AddComponent<TestLoader>();
40+
obj.AddComponent<TestBehaviourScript>();
41+
//obj.AddComponent<TestException>();
4242
}
4343

4444
static void TestCube()

DemoProject/MonoTest/MonoTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

ScriptEngine/custom/event_binding.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
void init_event_method(EventMethodDesc* desc, MonoClass *monoklass, Il2CppClass* ilklass, const char* method_name, int param_count, Il2CppMethodPointer hook2)
77
{
8+
if(monoklass == NULL || ilklass == NULL)
9+
return;
810
desc->hooked = mono_lookup_method(method_name,monoklass,param_count);
911
desc->orign = hook_method2(ilklass, method_name, param_count, hook2);
1012
}

ScriptEngine/custom/ios_setup.m

Lines changed: 138 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,58 @@
3030

3131
const char * runtime_bundle_path(void);
3232

33+
static char *bundle_path;
34+
static char *doc_path;
35+
36+
const char *
37+
get_bundle_path (void)
38+
{
39+
if (bundle_path)
40+
return bundle_path;
41+
42+
#if RUNTIME_IOS
43+
NSBundle *main_bundle = [NSBundle mainBundle];
44+
NSString *path;
45+
46+
path = [main_bundle bundlePath];
47+
bundle_path = strdup ([path UTF8String]);
48+
#else
49+
if ((bundle_path = _getcwd(NULL, 0)) == NULL)
50+
{
51+
perror("getcwd error");
52+
}
53+
else
54+
{
55+
printf("doc_path=%s\n", doc_path);
56+
}
57+
#endif
58+
return bundle_path;
59+
}
60+
61+
const char *
62+
get_documents_path(void)
63+
{
64+
if (doc_path)
65+
return doc_path;
66+
67+
#if RUNTIME_IOS
68+
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
69+
NSString *path = [paths objectAtIndex : 0];
70+
doc_path = strdup([path UTF8String]);
71+
#else
72+
if ((doc_path = _getcwd(NULL, 0)) == NULL)
73+
{
74+
perror("getcwd error");
75+
}
76+
else
77+
{
78+
printf("doc_path=%s\n", doc_path);
79+
}
80+
#endif
81+
return doc_path;
82+
}
83+
84+
3385
void mono_ios_setup_execution_mode (void)
3486
{
3587
mono_icall_table_init ();
@@ -58,7 +110,7 @@ void set_log_callback(print_log callback)
58110
const char *bundle = runtime_bundle_path ();
59111

60112
// LOG (PRODUCT ": Looking for aot data for assembly '%s'.", name);
61-
res = snprintf (path, sizeof (path) - 1, "%s/%s.aotdata", bundle, aname);
113+
res = snprintf (path, sizeof (path) - 1, "%s/%s.dll.aotdata", bundle, aname);
62114
assert (res > 0);
63115

64116
int fd = open (path, O_RDONLY);
@@ -129,28 +181,96 @@ void set_log_callback(print_log callback)
129181
//mono_jit_init_version ("Mono.ios", "mobile");
130182
}
131183

132-
char* doc_path = NULL;
184+
185+
186+
//
187+
// ICALLS used by the mobile profile of mscorlib
188+
//
189+
// NOTE: The timezone functions are duplicated in XI, so if you're going to modify here, you have to
190+
// modify there.
191+
//
192+
// See in XI runtime/xamarin-support.m
193+
194+
void*
195+
xamarin_timezone_get_data (const char *name, uint32_t *size)
196+
{
197+
NSTimeZone *tz = nil;
198+
if (name) {
199+
NSString *n = [[NSString alloc] initWithUTF8String: name];
200+
tz = [[NSTimeZone alloc] initWithName:n];
201+
} else {
202+
tz = [NSTimeZone localTimeZone];
203+
}
204+
NSData *data = [tz data];
205+
*size = [data length];
206+
void* result = malloc (*size);
207+
memcpy (result, data.bytes, *size);
208+
return result;
209+
}
210+
211+
//
212+
// Returns the geopolitical region ID of the local timezone.
213+
133214
const char *
134-
get_documents_path(void)
215+
xamarin_timezone_get_local_name ()
135216
{
136-
if (doc_path)
137-
return doc_path;
217+
NSTimeZone *tz = nil;
218+
tz = [NSTimeZone localTimeZone];
219+
NSString *name = [tz name];
220+
return (name != nil) ? strdup ([name UTF8String]) : strdup ("Local");
221+
}
138222

139-
#if RUNTIME_IOS
140-
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
141-
NSString *path = [paths objectAtIndex : 0];
142-
doc_path = strdup([path UTF8String]);
223+
char**
224+
xamarin_timezone_get_names (uint32_t *count)
225+
{
226+
// COOP: no managed memory access: any mode.
227+
NSArray *array = [NSTimeZone knownTimeZoneNames];
228+
*count = array.count;
229+
char** result = (char**) malloc (sizeof (char*) * (*count));
230+
for (uint32_t i = 0; i < *count; i++) {
231+
NSString *s = [array objectAtIndex: i];
232+
result [i] = strdup (s.UTF8String);
233+
}
234+
return result;
235+
}
236+
237+
// called from mono-extensions/mcs/class/corlib/System/Environment.iOS.cs
238+
const char *
239+
xamarin_GetFolderPath (int folder)
240+
{
241+
// COOP: no managed memory access: any mode.
242+
// NSUInteger-based enum (and we do not want corlib exposed to 32/64 bits differences)
243+
NSSearchPathDirectory dd = (NSSearchPathDirectory) folder;
244+
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:dd inDomains:NSUserDomainMask] lastObject];
245+
NSString *path = [url path];
246+
return strdup ([path UTF8String]);
247+
}
248+
249+
250+
// mcs/class/corlib/System/Console.iOS.cs
251+
void
252+
xamarin_log (const unsigned short *unicodeMessage)
253+
{
254+
// COOP: no managed memory access: any mode.
255+
int length = 0;
256+
const unsigned short *ptr = unicodeMessage;
257+
while (*ptr++)
258+
length += sizeof (unsigned short);
259+
NSString *msg = [[NSString alloc] initWithBytes: unicodeMessage length: length encoding: NSUTF16LittleEndianStringEncoding];
260+
261+
// if(print_log_callback != NULL)
262+
// print_log_callback(msg);
263+
#if TARGET_OS_WATCH && defined (__arm__) // maybe make this configurable somehow?
264+
const char *utf8 = [msg UTF8String];
265+
int len = strlen (utf8);
266+
fwrite (utf8, 1, len, stdout);
267+
if (len == 0 || utf8 [len - 1] != '\n')
268+
fwrite ("\n", 1, 1, stdout);
269+
fflush (stdout);
143270
#else
144-
if ((doc_path = _getcwd(NULL, 0)) == NULL)
145-
{
146-
perror("getcwd error");
147-
}
148-
else
149-
{
150-
printf("doc_path=%s\n", doc_path);
151-
}
271+
// os_log (stdout_log, "%{public}@", msg);
272+
NSLog (@"%@", msg);
152273
#endif
153-
return doc_path;
154274
}
155275

156276
#endif

ScriptEngine/custom/wrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" {
1111

1212
Il2CppReflectionType* get_monobehaviour_wrapper_rtype();
1313
Il2CppClass* get_monobehaviour_wrapper_class();
14-
void call_wrapper_init(Il2CppObject* il2cpp, MonoObject* mono);
14+
1515

1616
//more efficient "get_mono_object" for wrapper
1717
MonoObject* get_mono_wrapper_object(Il2CppObject* il2cpp, MonoClass* m_class);

ScriptEngine/generated/aot_module_register.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
extern void *mono_aot_module_System_Xml_info;
7676
extern void *mono_aot_module_System_Core_info;
7777
extern void *mono_aot_module_mscorlib_info;
78-
78+
//extern void *mono_aot_module_AdapterWrapper_info;
7979

8080

8181
void mono_ios_register_modules(void)
@@ -154,5 +154,7 @@ mono_aot_register_module(mono_aot_module_System_info);
154154
mono_aot_register_module(mono_aot_module_System_Xml_info);
155155
mono_aot_register_module(mono_aot_module_System_Core_info);
156156
mono_aot_register_module(mono_aot_module_mscorlib_info);
157+
//mono_aot_register_module(mono_aot_module_AdapterWrapper_info);
158+
157159
}
158160
#endif

ScriptEngine/generated/icall_binding_gen.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15499,13 +15499,16 @@ void UnityEngine_Cursor_SetCursor_Injected(MonoObject* texture, void * hotspot,
1549915499
}
1550015500
void UnityEngine_DebugLogHandler_Internal_Log(int32_t level, MonoString* msg, MonoObject* obj)
1550115501
{
15502+
1550215503
typedef void (* ICallMethod) (int32_t level, Il2CppString* msg, Il2CppObject* obj);
1550315504
static ICallMethod icall;
1550415505
if(!icall)
1550515506
icall = (ICallMethod)il2cpp_resolve_icall("UnityEngine.DebugLogHandler::Internal_Log");
15507+
Il2CppChar* chars = (Il2CppChar* )mono_string_to_utf16(msg);
15508+
1550615509
Il2CppString* i2msg = get_il2cpp_string(msg);
1550715510
Il2CppObject* i2obj = get_il2cpp_object(obj,il2cpp_get_class_UnityEngine_Object());
15508-
icall(level,i2msg,i2obj);
15511+
//icall(level,i2msg,i2obj);
1550915512
}
1551015513
void UnityEngine_DebugLogHandler_Internal_LogException(MonoObject* exception, MonoObject* obj)
1551115514
{

ScriptEngine/lib/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)