-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathffrunner.c
More file actions
752 lines (616 loc) · 21 KB
/
ffrunner.c
File metadata and controls
752 lines (616 loc) · 21 KB
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
#include "ffrunner.h"
#include "arg.h"
NPP_t npp;
NPPluginFuncs pluginFuncs;
NPNetscapeFuncs netscapeFuncs;
NPSavedData saved;
NPSavedData *savedPtr;
NPObject browserObject;
NPClass browserClass;
NPWindow npWin;
NPObject *scriptableObject;
Arguments args = { 0 };
#define NPIDENTIFIERCOUNT 32
#define NPSTRINGMAXSIZE 128
char npidentifiers[NPIDENTIFIERCOUNT][NPSTRINGMAXSIZE];
NPIdentifier
getNPIdentifier(const char *s)
{
int i;
assert(*s != '\0');
assert(strlen(s) < NPSTRINGMAXSIZE);
for (i = 0; i < NPIDENTIFIERCOUNT; i++) {
if (strncmp(s, npidentifiers[i], NPSTRINGMAXSIZE) == 0)
return (NPIdentifier)&npidentifiers[i];
if (npidentifiers[i][0] == '\0')
break;
}
/*
* Make sure there's still room.
* i would have already been incremented to NPIDENTIFIERCOUNT if
* the loop went through all iterations.
*/
assert(i < NPIDENTIFIERCOUNT);
assert(npidentifiers[i][0] == '\0');
strncpy(npidentifiers[i], s, NPSTRINGMAXSIZE);
return &npidentifiers[i];
}
NPError
NPN_GetURLProc(NPP instance, const char* url, const char* window)
{
logmsg("< NPN_GetURLProc:%p, url: %s, window: %s\n", instance, url, window);
register_get_request(url, false, NULL);
return NPERR_NO_ERROR;
}
NPError
NPN_GetURLNotifyProc(NPP instance, const char* url, const char* window, void* notifyData)
{
logmsg("< NPN_GetURLNotifyProc:%p, url: %s, window: %s, notifyData: %p\n", instance, url, window, notifyData);
register_get_request(url, true, notifyData);
return NPERR_NO_ERROR;
}
NPError
NPN_PostURLProc(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file)
{
logmsg("< NPN_PostURLProc:%p, url: %s, window: %s, len: %d, buf: %s, file: %d\n",
instance, url, window, len, buf, file);
register_post_request(url, false, NULL, len, buf);
return NPERR_NO_ERROR;
}
NPError
NPN_PostURLNotifyProc(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file, void* notifyData)
{
logmsg("< NPN_PostURLNotifyProc:%p, url: %s, window: %s, len: %d, buf: %s, file: %d, notifyData: %p\n",
instance, url, window, len, buf, file, notifyData);
register_post_request(url, true, notifyData, len, buf);
return NPERR_NO_ERROR;
}
const char *
NPN_UserAgentProc(NPP instance)
{
logmsg("< NPN_UserAgentProc, NPP:%p\n", instance);
return USERAGENT;
}
bool
NPN_GetPropertyProc(NPP npp, NPObject *obj, NPIdentifier propertyName, NPVariant *result)
{
logmsg("< NPN_GetPropertyProc\n");
return false;
}
bool
NPN_InvokeProc(NPP npp, NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
logmsg("< NPN_InvokeProc:%p, obj: %p, methodName: %p, argCount:%d\n", npp, obj, methodName, argCount);
return false;
}
void
NPN_ReleaseVariantValueProc(NPVariant *variant)
{
logmsg("< NPN_ReleaseVariantValueProc\n");
}
NPObject *
NPN_CreateObjectProc(NPP npp, NPClass *aClass)
{
NPObject *npobj;
logmsg("< NPN_CreateObjectProc\n");
assert(aClass);
if (aClass->allocate)
npobj = aClass->allocate(npp, aClass);
else
npobj = malloc(sizeof(*npobj));
if (npobj) {
npobj->_class = aClass;
npobj->referenceCount = 1;
}
return npobj;
}
NPObject *
NPN_RetainObjectProc(NPObject *obj)
{
logmsg("< NPN_RetainObjectProc\n");
assert(obj);
obj->referenceCount++;
return obj;
}
void
NPN_ReleaseObjectProc(NPObject *obj)
{
logmsg("< NPN_ReleaseObjectProc\n");
assert(obj);
obj->referenceCount--;
if (obj->referenceCount == 0) {
/* should never ask to deallocate the (statically allocated) browser window object */
assert(obj != &browserObject);
if (obj->_class && obj->_class->deallocate)
obj->_class->deallocate(obj);
else
free(obj);
}
}
NPError
NPN_GetValueProc(NPP instance, NPNVariable variable, void *ret_value)
{
NPObject **retPtr;
logmsg("< NPN_GetValueProc %d\n", variable);
browserObject.referenceCount++;
retPtr = (NPObject**)ret_value;
*retPtr = &browserObject;
return NPERR_NO_ERROR;
}
#define AUTH_CALLBACK_SCRIPT "authDoCallback(\"UnityEngine.GameObject\");"
#define HOMEPAGE_CALLBACK_SCRIPT "HomePage(\"UnityEngine.GameObject\");"
#define PAGEOUT_CALLBACK_SCRIPT "PageOut(\"UnityEngine.GameObject\");"
#define NAVIGATE_SCRIPT "location.href=\""
#define TARGET_REGISTER "https://audience.fusionfall.com/ff/regWizard.do?_flowId=fusionfall-registration-flow"
#define TARGET_MANAGE_ACCOUNT "https://audience.fusionfall.com/ff/login.do"
#define TARGET_COMMUNITY "http://forums.fusionfall.com"
#define DISCORD_LINK "https://discord.gg/DYavckB"
void
handle_navigation(char *target)
{
if (strncmp(target, TARGET_REGISTER, sizeof(TARGET_REGISTER) - 2) == 0) {
show_error_dialog("The register page is currently unimplemented.\n\n" \
"You can still create an account: type your desired username and password into the provided boxes and click \"Log In\". " \
"Your account will then be automatically created on the server. \nBe sure to remember these details!");
} else if (strncmp(target, TARGET_MANAGE_ACCOUNT, sizeof(TARGET_MANAGE_ACCOUNT) - 2) == 0) {
show_error_dialog("Account management is not available.");
} else if (strncmp(target, TARGET_COMMUNITY, sizeof(TARGET_COMMUNITY) - 2) == 0) {
open_link(DISCORD_LINK);
} else {
logmsg("Unhandled navigation target: %s\n", target);
}
}
char *
get_navigation_target(const char *script)
{
char *found;
found = strstr(script, NAVIGATE_SCRIPT);
if (!found) {
return NULL;
}
return found + sizeof(NAVIGATE_SCRIPT) - 1;
}
void
unity_send_message(const char *class, const char *msg, NPVariant val)
{
NPVariant args[3];
NPVariant ret;
assert(scriptableObject->_class);
assert(scriptableObject->_class->hasMethod(scriptableObject, getNPIdentifier("SendMessage")));
STRINGZ_TO_NPVARIANT(class, args[0]);
STRINGZ_TO_NPVARIANT(msg, args[1]);
args[2] = val;
scriptableObject->_class->invoke(scriptableObject, getNPIdentifier("SendMessage"), args, ARRLEN(args), &ret);
}
void
auth(char *username, char *password)
{
NPVariant val;
logmsg("Auto-auth as %s\n", username);
STRINGZ_TO_NPVARIANT(username, val);
unity_send_message("GlobalManager", "SetTEGid", val);
STRINGZ_TO_NPVARIANT(password, val);
unity_send_message("GlobalManager", "SetAuthid", val);
INT32_TO_NPVARIANT(0, val);
unity_send_message("GlobalManager", "DoAuth", val);
}
bool
NPN_EvaluateProc(NPP npp, NPObject *obj, NPString *script, NPVariant *result)
{
char *navigationTarget;
logmsg("< NPN_EvaluateProc %s\n", script->UTF8Characters);
/* Evaluates JS calls, like MarkProgress(1), most of which doesn't need to do anything. */
if (strncmp(script->UTF8Characters, HOMEPAGE_CALLBACK_SCRIPT, sizeof(HOMEPAGE_CALLBACK_SCRIPT)) == 0
|| strncmp(script->UTF8Characters, PAGEOUT_CALLBACK_SCRIPT, sizeof(PAGEOUT_CALLBACK_SCRIPT)) == 0) {
/* Gracefully exit game. */
PostQuitMessage(0);
} else if (strncmp(script->UTF8Characters, AUTH_CALLBACK_SCRIPT, sizeof(AUTH_CALLBACK_SCRIPT)) == 0) {
/* Execute authentication callback */
if (args.tegId != NULL && args.authId != NULL) {
auth(args.tegId, args.authId);
}
} else {
/* If navigation, handle */
navigationTarget = get_navigation_target(script->UTF8Characters);
if (navigationTarget != NULL) {
handle_navigation(navigationTarget);
}
}
*result = (NPVariant){
.type = NPVariantType_Void
};
return true;
}
NPIdentifier
NPN_GetStringIdentifierProc(const NPUTF8* name)
{
logmsg("< NPN_GetStringIdentifierProc %s\n", name);
return getNPIdentifier(name);
}
void
NPN_GetStringIdentifiersProc(const NPUTF8** names, int32_t nameCount, NPIdentifier* identifiers)
{
int i;
logmsg("< NPN_GetStringIdentifiersProc %d\n", nameCount);
for (i = 0; i < nameCount; i++) {
identifiers[i] = getNPIdentifier(names[i]);
}
}
/*
* Browser Object methods below here.
*/
NPObject *
NPAllocateFunction(NPP instance, NPClass *aClass)
{
NPObject *npobj;
logmsg("< NPAllocateFunction %p\n", aClass);
assert(aClass);
if (aClass->allocate)
npobj = aClass->allocate(instance, aClass);
else
npobj = malloc(sizeof(*npobj));
if (npobj) {
npobj->_class = aClass;
npobj->referenceCount = 1;
}
return npobj;
}
void
NPDeallocateFunction(NPObject *npobj)
{
logmsg("< NPDeallocateFunction %p\n", npobj);
assert(npobj != &browserObject);
free(npobj);
}
void
NPInvalidateFunction(NPObject *npobj)
{
logmsg("< NPInvalidateFunction %p\n", npobj);
}
bool
NPHasMethodFunction(NPObject *npobj, NPIdentifier name)
{
logmsg("< NPHasMethodFunction %p %p\n", npobj, name);
return 0;
}
bool
NPInvokeFunction(NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
logmsg("< NPInvokeFunction %p %p\n", npobj, name);
return 0;
}
bool
NPInvokeDefaultFunction(NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
logmsg("< NPInvokeDefaultFunction %p\n", npobj);
return 0;
}
bool
NPHasPropertyFunction(NPObject *npobj, NPIdentifier name)
{
logmsg("< NPHasPropertyFunction %p\n", npobj);
return 0;
}
bool
NPGetPropertyFunction(NPObject *npobj, NPIdentifier name, NPVariant *result)
{
logmsg("< NPGetPropertyFunction %p\n", npobj);
return 0;
}
bool
NPSetPropertyFunction(NPObject *npobj, NPIdentifier name, const NPVariant *value)
{
logmsg("< NPSetPropertyFunction %p\n", npobj);
return 0;
}
bool
NPRemovePropertyFunction(NPObject *npobj, NPIdentifier name)
{
logmsg("< NPRemovePropertyFunction %p\n", npobj);
return 0;
}
bool
NPEnumerationFunction(NPObject *npobj, NPIdentifier **value, uint32_t *count)
{
logmsg("< NPEnumerationFunction %p\n", npobj);
return 0;
}
bool
NPConstructFunction(NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
logmsg("< NPConstructFunction %p\n", npobj);
return 0;
}
void
initBrowserObject(void)
{
browserObject._class = &browserClass;
browserObject.referenceCount = 1;
browserClass.structVersion = 3;
browserClass.allocate = NPAllocateFunction;
browserClass.deallocate = NPDeallocateFunction;
browserClass.invalidate = NPInvalidateFunction;
browserClass.hasMethod = NPHasMethodFunction;
browserClass.invoke = NPInvokeFunction;
browserClass.invokeDefault = NPInvokeDefaultFunction;
browserClass.hasProperty = NPHasPropertyFunction;
browserClass.getProperty = NPGetPropertyFunction;
browserClass.setProperty = NPSetPropertyFunction;
browserClass.removeProperty = NPRemovePropertyFunction;
browserClass.enumerate = NPEnumerationFunction;
browserClass.construct = NPConstructFunction;
}
void
initNetscapeFuncs(void)
{
netscapeFuncs.size = 224;
netscapeFuncs.version = 27;
netscapeFuncs.geturl = NPN_GetURLProc;
netscapeFuncs.posturl = NPN_PostURLProc;
netscapeFuncs.uagent = NPN_UserAgentProc;
netscapeFuncs.geturlnotify = NPN_GetURLNotifyProc;
netscapeFuncs.posturlnotify = NPN_PostURLNotifyProc;
netscapeFuncs.releaseobject = NPN_ReleaseObjectProc;
netscapeFuncs.invoke = NPN_InvokeProc;
netscapeFuncs.getproperty = NPN_GetPropertyProc;
netscapeFuncs.createobject = NPN_CreateObjectProc;
netscapeFuncs.retainobject = NPN_RetainObjectProc;
netscapeFuncs.releasevariantvalue = NPN_ReleaseVariantValueProc;
netscapeFuncs.getvalue = NPN_GetValueProc;
netscapeFuncs.evaluate = NPN_EvaluateProc;
netscapeFuncs.getstringidentifier = NPN_GetStringIdentifierProc;
netscapeFuncs.getstringidentifiers = NPN_GetStringIdentifiersProc;
}
void
parse_args(int argc, char **argv)
{
ARG_BEGIN {
if (ARG_LONG("verbose")) case 'v': {
args.verboseLogging = true;
ARG_FLAG();
} else if (ARG_LONG("main")) case 'm': {
args.mainPathOrAddress = ARG_VAL();
} else if (ARG_LONG("log")) case 'l': {
args.logPath = ARG_VAL();
} else if (ARG_LONG("address")) case 'a': {
args.serverAddress = ARG_VAL();
} else if (ARG_LONG("asseturl")) {
args.assetUrl = ARG_VAL();
} else if (ARG_LONG("endpoint")) case 'e': {
args.endpointHost = ARG_VAL();
} else if (ARG_LONG("username")) case 'u': {
args.tegId = ARG_VAL();
} else if (ARG_LONG("token")) case 't': {
args.authId = ARG_VAL();
} else if (ARG_LONG("width")) {
args.windowWidth = atoi(ARG_VAL());
} else if (ARG_LONG("height")) {
args.windowHeight = atoi(ARG_VAL());
} else if (ARG_LONG("loader-images")) {
args.useEndpointLoadingScreen = true;
} else if (ARG_LONG("force-vulkan")) {
args.forceVulkan = true;
} else if (ARG_LONG("force-opengl")) {
args.forceOpenGl = true;
} else if (ARG_LONG("help")) case 'h': {
puts("Usage: ffrunner.exe [OPTION...]");
puts(" -m, --main=STR The main URL to load");
puts(" -l, --log=STR The path to the log file");
puts(" -v, --verbose Enable verbose logging");
puts(" -a, --address=STR The address of the server");
puts(" --asseturl=STR The URL of the CDN for assets");
puts(" -e, --endpoint=STR The OFAPI endpoint URL");
puts(" -u, --username=STR Username for auto-login");
puts(" -t, --token=STR Password or token for auto-login");
puts(" --width=INT The width of the window");
puts(" --height=INT The height of the window");
puts(" --loader-images Use loading screen images from endpoint");
puts(" --force-vulkan Force Vulkan renderer");
puts(" --force-opengl Force OpenGL renderer");
puts(" -h, --help Display this help menu");
puts("");
exit(0);
}
} ARG_END;
if (args.mainPathOrAddress == NULL) {
args.mainPathOrAddress = FALLBACK_SRC_URL;
}
if (args.assetUrl == NULL) {
args.assetUrl = FALLBACK_ASSET_URL;
}
if (args.serverAddress == NULL) {
args.serverAddress = FALLBACK_SERVER_ADDRESS;
}
if (args.logPath == NULL) {
args.logPath = LOG_FILE_PATH;
}
if (args.windowWidth == 0) {
args.windowWidth = DEFAULT_WIDTH;
}
if (args.windowHeight == 0) {
args.windowHeight = DEFAULT_HEIGHT;
}
}
void
print_args()
{
printf("main: %s\n", args.mainPathOrAddress);
printf("log: %s\n", args.logPath);
printf("verbose: %s\n", args.verboseLogging ? "true" : "false");
printf("address: %s\n", args.serverAddress);
printf("asseturl: %s\n", args.assetUrl);
printf("endpoint: %s\n", args.endpointHost);
printf("username: %s\n", args.tegId);
printf("token: %s\n", args.authId == NULL ? "(null)" : "********");
printf("width: %d\n", args.windowWidth);
printf("height: %d\n", args.windowHeight);
printf("loader-images: %s\n", args.useEndpointLoadingScreen ? "true" : "false");
printf("force-vulkan: %s\n", args.forceVulkan ? "true" : "false");
printf("force-opengl: %s\n", args.forceOpenGl ? "true" : "false");
}
void
enable_dpi_awareness() {
HMODULE shcore = LoadLibraryA("shcore.dll");
if (shcore) {
SetProcessDpiAwarenessFunc setDpiAwareness =
(SetProcessDpiAwarenessFunc)GetProcAddress(shcore, "SetProcessDpiAwareness");
if (setDpiAwareness) {
if (setDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE) == S_OK) {
logmsg("Set DPI awareness to PROCESS_PER_MONITOR_DPI_AWARE\n");
} else {
logmsg("Failed to set DPI awareness: %d\n", GetLastError());
}
}
FreeLibrary(shcore);
} else {
// Fallback for older systems
SetProcessDPIAware();
}
}
int
main(int argc, char **argv)
{
char* srcUrl;
DWORD err;
wchar_t cwd[MAX_PATH];
NPError ret;
HMODULE loader;
RECT winRect;
parse_args(argc, argv);
print_args();
init_logging(args.logPath, args.verboseLogging);
enable_dpi_awareness();
char *winePrefix = getenv("WINEPREFIX");
if (winePrefix) {
logmsg("WINEPREFIX is set to: %s\n", winePrefix);
} else {
logmsg("WINEPREFIX is not set.\n");
}
if (args.serverAddress == NULL) {
logmsg("No server address provided.");
exit(1);
}
if (args.assetUrl == NULL) {
logmsg("No asset URL provided.");
exit(1);
}
if (GetCurrentDirectoryW(MAX_PATH, cwd)) {
logmsg("setenv(\"UNITY_HOME_DIR\", \"%ls\")\n", cwd);
SetEnvironmentVariableW(L"UNITY_HOME_DIR", cwd);
}
SetEnvironmentVariableA("UNITY_DISABLE_PLUGIN_UPDATES", "yes");
SetEnvironmentVariableA("LANG", NULL); // webplayer crashes if this is set
SetEnvironmentVariableA("UNITY_KEEP_LOG_FILES", "yes");
if (args.forceVulkan) {
SetEnvironmentVariableA("UNITY_FF_DX_DLL", "d3d9_vulkan.dll");
} else if (args.forceOpenGl) {
SetEnvironmentVariableA("UNITY_FF_DX_DLL", "lmao");
}
apply_vram_fix();
initNetscapeFuncs();
initBrowserObject();
logmsg("LoadLibraryW\n");
loader = LoadLibraryW(L"loader\\npUnity3D32.dll");
if (!loader) {
err = GetLastError();
logmsg("Failed to load plugin DLL: 0x%x\n", err);
exit(1);
}
logmsg("GetProcAddress\n");
NP_GetEntryPointsFuncOS NP_GetEntryPoints = (NP_GetEntryPointsFuncOS)GetProcAddress(loader, "NP_GetEntryPoints");
NP_InitializeFuncOS NP_Initialize = (NP_InitializeFuncOS)GetProcAddress(loader, "NP_Initialize");
NP_ShutdownFuncOS NP_Shutdown = (NP_ShutdownFuncOS)GetProcAddress(loader, "NP_Shutdown");
if (!NP_GetEntryPoints || !NP_Initialize || !NP_Shutdown) {
logmsg("Failed to find one or more plugin symbols. Invalid plugin DLL?\n");
exit(1);
}
prepare_window(args.windowWidth, args.windowHeight);
assert(hwnd);
srcUrl = args.mainPathOrAddress;
init_network(srcUrl);
logmsg("> NP_GetEntryPoints\n");
ret = NP_GetEntryPoints(&pluginFuncs);
logmsg("returned %d\n", ret);
logmsg("> NP_Initialize\n");
ret = NP_Initialize(&netscapeFuncs);
logmsg("returned %d\n", ret);
char width[16], height[16];
snprintf(width, sizeof(width), "%d", args.windowWidth);
snprintf(height, sizeof(height), "%d", args.windowHeight);
char *argn[] = {
"src",
"width",
"height",
"bordercolor",
"backgroundcolor",
"disableContextMenu",
"textcolor",
"logoimage",
"progressbarimage",
"progressframeimage",
};
char *argp[] = {
srcUrl,
width,
height,
"000000",
"000000",
"true",
"ccffff",
"assets/img/unity-dexlabs.png",
"assets/img/unity-loadingbar.png",
"assets/img/unity-loadingframe.png",
};
assert(ARRLEN(argn) == ARRLEN(argp));
savedPtr = &saved;
logmsg("> NPP_NewProc\n");
ret = pluginFuncs.newp("application/vnd.ffuwp", &npp, 1, ARRLEN(argn), argn, argp, savedPtr);
logmsg("returned %d\n", ret);
ShowWindow(hwnd, SW_SHOWDEFAULT);
UpdateWindow(hwnd);
npWin = (NPWindow){
.window = hwnd,
.x = 0, .y = 0,
.width = args.windowWidth, .height = args.windowHeight,
.clipRect = {
0, 0, args.windowHeight, args.windowWidth
},
.type = NPWindowTypeWindow
};
/* adjust plugin rect to the real inner size of the window */
if (GetClientRect(hwnd, &winRect)) {
npWin.x = winRect.left;
npWin.y = winRect.top;
npWin.clipRect.top = 0;
npWin.clipRect.left = 0;
npWin.clipRect.right = winRect.right;
npWin.clipRect.bottom = winRect.bottom;
npWin.width = winRect.right - winRect.left;
npWin.height = winRect.bottom - winRect.top;
}
logmsg("> NPP_SetWindowProc\n");
ret = pluginFuncs.setwindow(&npp, &npWin);
logmsg("returned %d\n", ret);
logmsg("> NPP_GetValueProc\n");
ret = pluginFuncs.getvalue(&npp, NPPVpluginScriptableNPObject, &scriptableObject);
logmsg("returned %d and NPObject %p\n", ret, scriptableObject);
assert(scriptableObject->_class);
logmsg("> scriptableObject.hasMethod style\n");
ret = scriptableObject->_class->hasMethod(scriptableObject, getNPIdentifier("style"));
logmsg("returned %d\n", ret);
message_loop();
logmsg("> NPP_DestroyProc\n");
ret = pluginFuncs.destroy(&npp, &savedPtr);
logmsg("returned %d\n", ret);
return 0;
}
int
WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
int argc;
char **argv;
argc = __argc;
argv = __argv;
return main(argc, argv);
}