少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
#include <config.h>
#include <glib.h>
 
 
 
#include "Directory-c-api.h"
#include "File-c-api.h"
#include "w32error.h"
#include "w32file.h"
#include "utils/strenc.h"
#include <mono/metadata/w32handle.h>
 
 
#ifdef HOST_WIN32
 
gunichar2
ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
{
    return (gunichar2) ':';    /* colon */
}
 
gunichar2
ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
{
    return (gunichar2) '\\';    /* backslash */
}
 
gunichar2
ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
{
    return (gunichar2) '/';    /* forward slash */
}
 
gunichar2
ves_icall_System_IO_MonoIO_get_PathSeparator ()
{
    return (gunichar2) ';';    /* semicolon */
}
 
void ves_icall_System_IO_MonoIO_DumpHandles (void)
{
    return;
}
#endif /* HOST_WIN32 */
 
gpointer
mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs)
{
    int error = 0;
    gpointer handle;
    gchar* palPath = mono_unicode_to_external(name);
    handle =  UnityPalOpen(palPath, (int) createmode, (int) fileaccess, (int) sharemode, attrs, &error);
    mono_w32error_set_last(error);
    g_free(palPath);
 
    if (handle == NULL)
        return INVALID_HANDLE_VALUE;
 
    return handle;
}
 
gboolean
mono_w32file_close (gpointer handle)
{
    if (handle == NULL)
        return FALSE;
    
    int error = 0;
    gboolean result = UnityPalClose(handle, &error);
    mono_w32error_set_last(error);
    
    return result;
}
 
gboolean
mono_w32file_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread)
{
    int error = 0;
    
    *bytesread =  UnityPalRead(handle, buffer, numbytes, &error);
    mono_w32error_set_last(error);
    
    return TRUE;
}
 
gboolean
mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten)
{
    int error = 0;
 
    *byteswritten = UnityPalWrite(handle, buffer, numbytes, &error);
    mono_w32error_set_last(error);
 
    return (*byteswritten > 0);
}
 
gboolean
mono_w32file_flush (gpointer handle)
{
    int error = 0;
    
    gboolean result = UnityPalFlush(handle, &error);
    mono_w32error_set_last(error);
    
    return result;
}
 
gboolean
mono_w32file_truncate (gpointer handle)
{
    int error = 0;
 
    gboolean result = UnityPalTruncate(handle, &error);
    mono_w32error_set_last(error);
 
    return result;
}
 
guint32
mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistance, guint32 method)
{
    int error = 0;
    
    int32_t result = UnityPalSeek(handle, movedistance, 0, &error);
    mono_w32error_set_last(error);
 
    return result;
}
 
gint
mono_w32file_get_type (gpointer handle)
{
    if (handle == NULL)
        return 0;
 
    return UnityPalGetFileType(handle);
}
 
gboolean
mono_w32file_get_times (gpointer handle, FILETIME *create_time, FILETIME *access_time, FILETIME *write_time)
{
    /* Not Supported in UnityPAL */
    g_assert_not_reached();
}
 
gboolean
mono_w32file_set_times (gpointer handle, const FILETIME *create_time, const FILETIME *access_time, const FILETIME *write_time)
{
    int error = 0;
 
    gboolean result = UnityPalSetFileTime(handle, create_time, access_time, write_time, &error);
    mono_w32error_set_last(error);
 
    return  result;
}
 
gpointer
mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data)
{
    gchar* palPath = mono_unicode_to_external(pattern);
    UnityPalFindHandle* findHandle = UnityPalDirectoryFindHandleNew(palPath);
    int32_t resultAttributes = 0;
 
    int32_t result = 0;
    const char* filename;
 
    result = UnityPalDirectoryFindFirstFile(findHandle, palPath, &filename, &resultAttributes);
 
    if (result != 0)
    {
        mono_w32error_set_last(result);
        return INVALID_HANDLE_VALUE;
    }
 
    find_data->dwFileAttributes = resultAttributes;
 
    gunichar2 *utf16_basename;
    glong bytes;
    utf16_basename = g_utf8_to_utf16 (filename, -1, NULL, &bytes, NULL);
    
    /* this next section of memset and memcpy is code from mono, the cFileName field is 
       gunichar2 cFileName [MAX_PATH].  
       Notes from mono:      
       Truncating a utf16 string like this might leave the last
       gchar incomplete
       utf16 is 2 * utf8
    */
    bytes *= 2;
    memset (find_data->cFileName, '\0', (MAX_PATH * 2));
    memcpy (find_data->cFileName, utf16_basename, bytes < (MAX_PATH * 2) - 2 ? bytes : (MAX_PATH * 2) - 2);
 
    g_free(filename);
    g_free(palPath);
    g_free(utf16_basename);
 
    find_data->dwReserved0 = 0;
    find_data->dwReserved1 = 0;
 
    find_data->cAlternateFileName [0] = 0;    
 
    return findHandle;
}
 
gboolean
mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data)
{
 
    int32_t resultAttributes = 0;
    int32_t result;
    const char* filename;
 
    result = UnityPalDirectoryFindNextFile(handle, &filename, &resultAttributes);
 
    find_data->dwFileAttributes = resultAttributes;
    gunichar2 *utf16_basename;
    glong bytes;
    utf16_basename = g_utf8_to_utf16 (filename, -1, NULL, &bytes, NULL);
    bytes *= 2;
 
    memset (find_data->cFileName, '\0', (MAX_PATH * 2));
    memcpy (find_data->cFileName, utf16_basename, bytes < (MAX_PATH * 2) - 2 ? bytes : (MAX_PATH * 2) - 2);
 
    g_free(filename);
    g_free(utf16_basename);
 
    find_data->dwReserved0 = 0;
    find_data->dwReserved1 = 0;
 
    find_data->cAlternateFileName [0] = 0;    
 
    return (result == 0);
}
 
gboolean
mono_w32file_find_close (gpointer handle)
{
    gboolean result = UnityPalDirectoryCloseOSHandle(handle);
    UnityPalDirectoryFindHandleDelete(handle);
  
    return result;
}
 
gboolean
mono_w32file_create_directory (const gunichar2 *name)
{
    int error = 0;
 
    gchar* palPath = mono_unicode_to_external(name);
    gboolean result = UnityPalDirectoryCreate(palPath, &error);
    mono_w32error_set_last(error);
    g_free(palPath);
 
    return result;
}
 
guint32
mono_w32file_get_attributes (const gunichar2 *name)
{
    int error = 0;
    
    gchar* palPath = mono_unicode_to_external(name);
    guint32 result =  UnityPalGetFileAttributes(palPath, &error);
    mono_w32error_set_last(error);
    g_free(palPath);
    
    return result;
}
 
gboolean
mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat)
{
    gboolean result;
    UnityPalFileStat palStat;
    int error = 0;
 
    gchar* palPath = mono_unicode_to_external(name);
    result = UnityPalGetFileStat(palPath, &palStat, &error);
    mono_w32error_set_last(error);
 
    if (result) {
        stat->attributes = palStat.attributes;
        stat->creation_time = palStat.creation_time;
        stat->last_access_time = palStat.last_access_time;
        stat->last_write_time = palStat.last_write_time;
        stat->length = palStat.length;
    }
    g_free(palPath);
 
    return result;
}
 
gboolean
mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs)
{
    int error = 0;
 
    gchar* palPath = mono_unicode_to_external(name);
    gboolean result =  UnityPalSetFileAttributes(palPath, attrs, &error);
    mono_w32error_set_last(error);
    g_free(palPath);
 
    return result;
}
 
gboolean
mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size)
{
    return UnityPalCreatePipe(*readpipe, *writepipe);
}
 
gboolean
mono_w32file_get_disk_free_space (const gunichar2 *path_name, guint64 *free_bytes_avail, guint64 *total_number_of_bytes, guint64 *total_number_of_free_bytes)
{
    g_assert_not_reached();
    return FALSE;
}
 
gboolean
mono_w32file_get_volume_information (const gunichar2 *path, gunichar2 *volumename, gint volumesize, gint *outserial, gint *maxcomp, gint *fsflags, gunichar2 *fsbuffer, gint fsbuffersize)
{
    g_assert_not_reached();
    return FALSE;
}
 
gboolean
mono_w32file_move (const gunichar2 *path, const gunichar2 *dest, gint32 *error)
{
    gboolean result;
    *error = 0;
    MONO_ENTER_GC_SAFE;
    
    gchar* palPath = mono_unicode_to_external(path);
    gchar* palDest = mono_unicode_to_external(dest);
    result =  UnityPalMoveFile(palPath, palDest, error);
    mono_w32error_set_last(*error);
    g_free(palPath);
    g_free(palDest);
 
    MONO_EXIT_GC_SAFE;
 
    return result;
}
 
gboolean
mono_w32file_replace (const gunichar2 *destination_file_name, const gunichar2 *source_file_name, const gunichar2 *destination_backup_file_name, guint32 flags, gint32 *error)
{
    gboolean result;
    gchar* destPath = NULL;
    gchar* sourcePath = NULL;
    gchar* destBackupPath = NULL;
 
    if (destination_file_name != NULL)
    {
        destPath = mono_unicode_to_external(destination_file_name);
    }
 
    if (source_file_name != NULL)
    {
        sourcePath = mono_unicode_to_external(source_file_name);
    }
 
    if (destination_backup_file_name != NULL)
    {
        destBackupPath = mono_unicode_to_external(destination_backup_file_name);
    }
 
    MONO_ENTER_GC_SAFE;
 
    result =  UnityPalReplaceFile(sourcePath, destPath, destBackupPath, 0, error);
    mono_w32error_set_last(*error);
 
    MONO_EXIT_GC_SAFE;
 
    g_free(destPath);
    g_free(sourcePath);
    g_free(destBackupPath);
 
    return result;
}
 
gboolean
mono_w32file_copy (const gunichar2 *path, const gunichar2 *dest, gboolean overwrite, gint32 *error)
{
    gboolean result;
    *error = 0;
 
    MONO_ENTER_GC_SAFE;
    
    gchar* palPath = mono_unicode_to_external(path);
    gchar* palDest = mono_unicode_to_external(dest);
    result = UnityPalCopyFile(palPath, palDest, overwrite, error);
    mono_w32error_set_last(*error);
    g_free(palPath);
    g_free(palDest);
 
    MONO_EXIT_GC_SAFE;
 
    return result;
}
 
gboolean
mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *error)
{
    MONO_ENTER_GC_SAFE;
 
    UnityPalLock(handle, position, length, error);
    mono_w32error_set_last(*error);
 
    MONO_EXIT_GC_SAFE;
 
    return (*error == 0);
}
 
gboolean
mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *error)
{
    MONO_ENTER_GC_SAFE;
 
    UnityPalUnlock(handle, position, length, error);
    mono_w32error_set_last(*error);
 
    MONO_EXIT_GC_SAFE;
 
    return (*error == 0);
}
 
gpointer
mono_w32file_get_console_input (void)
{
    return UnityPalGetStdInput();
}
 
gpointer
mono_w32file_get_console_output (void)
{
    return UnityPalGetStdOutput();
}
 
gpointer
mono_w32file_get_console_error (void)
{
    return UnityPalGetStdError();
}
 
gint64
mono_w32file_get_file_size (gpointer handle, gint32 *error)
{
    gint64 length;
 
    MONO_ENTER_GC_SAFE;
 
    length = UnityPalGetLength(handle, error);
    mono_w32error_set_last(*error);
 
    MONO_EXIT_GC_SAFE;
 
    return length;
}
 
guint32
mono_w32file_get_drive_type (const gunichar2 *root_path_name)
{
    return 0;
}
 
gint32
mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf)
{
    return -1;
}
 
gboolean
mono_w32file_remove_directory (const gunichar2 *name)
{
    int error = 0;
 
    gchar* palPath = mono_unicode_to_external (name);
    gboolean result =  UnityPalDirectoryRemove(palPath, &error);
    mono_w32error_set_last(error);
    g_free(palPath);
 
    return result;
}
 
gboolean mono_w32file_delete(const gunichar2 *name)
{
    int error = 0;
 
    gchar* palPath = mono_unicode_to_external (name);
    gboolean result = UnityPalDeleteFile(palPath, &error);
    mono_w32error_set_last (error);
    g_free(palPath);
 
    return result;
}
 
guint32
mono_w32file_get_cwd (guint32 length, gunichar2 *buffer)
{
    /* length is the number of characters in buffer, including the null terminator */
    /* count is the number of characters in the current directory, including the null terminator */
    gunichar2 *utf16_path;
    glong count;
    uintptr_t bytes;
    int error = 0;
 
    const char* palPath = UnityPalDirectoryGetCurrent(&error);
    mono_w32error_set_last (error);
    utf16_path = mono_unicode_from_external(palPath, &bytes);
    count = (bytes / 2) + 1;
 
    if (count <= length) {
        /* Add the terminator */
        memset (buffer, '\0', bytes+2);
        memcpy (buffer, utf16_path, bytes);
    }
 
    g_free(utf16_path);
    g_free(palPath);
 
    return count;
}
 
gboolean
mono_w32file_set_cwd (const gunichar2 *path)
{
    int error = 0;
 
    gchar* palPath = mono_unicode_to_external(path);
    gboolean result = UnityPalDirectorySetCurrent(palPath, &error);
    mono_w32error_set_last (error);
    g_free(palPath);
 
    return result;
}
 
gboolean
mono_w32file_set_length (gpointer handle, gint64 length, gint32 *error)
{
    gboolean result = UnityPalSetLength(handle, length, error);
    mono_w32error_set_last(*error);
 
    return result;
}
 
void
mono_w32file_cleanup (void)
{
}
 
void
mono_w32file_init (void)
{
}