forked from wermipls/pj64-wiiu-gcn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
202 lines (168 loc) · 4.87 KB
/
Copy pathmain.c
File metadata and controls
202 lines (168 loc) · 4.87 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
#define WIN32_LEAN_AND_MEAN
#define PLUGIN_NAME "pj64-wiiu-gcn"
#define PLUGIN_VERSION "0.2.2"
#define PLUGIN_NAMEVER PLUGIN_NAME " v" PLUGIN_VERSION
#define PLUGIN_REPO "https://github.com/wermipls/pj64-wiiu-gcn"
#include <Windows.h>
#include <Shlwapi.h>
#include "zilmar_controller_1.0.h"
#include "gc_adapter.h"
#include "config.h"
#include "gui.h"
#include "util.h"
HINSTANCE hInstance;
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
hInstance = hinstDLL;
log_open();
config_load();
InitializeCriticalSection(&gc_critical);
break;
case DLL_PROCESS_DETACH:
log_close();
DeleteCriticalSection(&gc_critical);
break;
}
return TRUE;
}
EXPORT void CALL CloseDLL(void)
{
gc_deinit();
}
EXPORT void CALL DllAbout(HWND hParent)
{
MessageBox(
hParent,
"Proof of concept Wii U Gamecube adapter plugin\n"
"Version " PLUGIN_VERSION "\n"
"Compiled on " __DATE__ "\n\n"
PLUGIN_REPO,
"About " PLUGIN_NAMEVER,
MB_OK | MB_ICONINFORMATION
);
}
EXPORT void CALL DllConfig(HWND hParent)
{
config_window(hInstance, hParent);
}
//EXPORT void CALL DllTest(HWND hParent);
EXPORT void CALL GetDllInfo(PLUGIN_INFO *PluginInfo)
{
PluginInfo->Version = 0x0100;
PluginInfo->Type = PLUGIN_TYPE_CONTROLLER;
strncpy(
PluginInfo->Name,
PLUGIN_NAMEVER,
sizeof(PluginInfo->Name)
);
}
EXPORT void CALL GetKeys(int Control, BUTTONS *Keys)
{
gc_inputs i;
int err = gc_get_inputs(Control, &i);
if (err)
return;
Keys->Value = 0;
if (!gc_is_present(i.status)) {
return;
}
Keys->X_AXIS = deadzone(i.ay, cfg.dz) * cfg.range / 100;
Keys->Y_AXIS = deadzone(i.ax, cfg.dz) * cfg.range / 100;
Keys->A_BUTTON = i.a;
Keys->B_BUTTON = i.b;
int lt = cfg.analog_trig ? i.lt > cfg.trig_thres
: 0;
int rt = cfg.analog_trig ? i.rt > cfg.trig_thres
: 0;
if (!cfg.zl_as_z) {
if (cfg.swap_zl) {
Keys->Z_TRIG = i.l || lt;
Keys->L_TRIG = i.z;
} else {
Keys->Z_TRIG = i.z;
Keys->L_TRIG = i.l || lt;
}
} else {
Keys->Z_TRIG = i.z || i.l || lt;
}
Keys->R_TRIG = i.r || rt;
Keys->START_BUTTON = i.start;
Keys->L_DPAD = i.dleft;
Keys->R_DPAD = i.dright;
Keys->U_DPAD = i.dup;
Keys->D_DPAD = i.ddown;
struct Vec2 cstick = circle_to_square(i.cx, i.cy);
Keys->L_CBUTTON = cstick.x < -cfg.cstick_thres;
Keys->R_CBUTTON = cstick.x > cfg.cstick_thres;
Keys->D_CBUTTON = cstick.y < -cfg.cstick_thres;
Keys->U_CBUTTON = cstick.y > cfg.cstick_thres;
if (cfg.xy_mode == XY_CBUTTONS) {
Keys->L_CBUTTON |= i.y;
Keys->R_CBUTTON |= i.x;
} else if (cfg.xy_mode == XY_L_4CBUTTONS) {
Keys->L_TRIG |= i.y;
Keys->L_CBUTTON |= i.x;
Keys->R_CBUTTON |= i.x;
Keys->D_CBUTTON |= i.x;
Keys->U_CBUTTON |= i.x;
} else if (cfg.xy_mode == XY_TONYHAWK) {
Keys->D_CBUTTON |= i.a;
Keys->L_CBUTTON |= i.b;
Keys->R_CBUTTON |= i.x;
Keys->U_CBUTTON |= i.y;
}
}
EXPORT void CALL InitiateControllers(HWND hMainWindow, CONTROL Controls[4])
{
dlog(LOG_INFO, "InitiateControllers()");
gc_init(cfg.async);
gc_inputs gc[4];
// workaround for incorrect status being reported
// when trying to use the adapter directly after it's been plugged in.
// i < 2 works for my official adapter, but i've put in i < 10 to be safe
// (which should stall for only 80ms with the default 125hz pollrate)
if (!gc_is_async()) {
for (int i = 0; i < 10; ++i) {
int err = gc_get_all_inputs(gc);
if (err) return;
}
} else {
Sleep(80);
int err = gc_get_all_inputs(gc);
if (err) return;
}
int concount = 0;
for (int i = 0; i < 4; ++i) {
int status = gc[i].status;
if (gc_is_present(status)) {
Controls[i].Present = TRUE;
dlog(LOG_INFO, "Controller %d present, status 0x%X", i, status);
++concount;
} else {
Controls[i].Present = FALSE;
dlog(LOG_INFO, "Controller %d not available, status 0x%X", i, status);
}
Controls[i].RawData = FALSE;
Controls[i].Plugin = PLUGIN_NONE;
}
if (concount == 0) {
MessageBox(
hMainWindow,
"No controllers detected.\n\n"
"Please plug in a controller, then restart the emulator.",
PLUGIN_NAME " info", MB_OK | MB_ICONINFORMATION
);
}
}
//EXPORT void CALL ReadController(int Control, BYTE *Command);
EXPORT void CALL RomClosed(void)
{
// something in here
}
EXPORT void CALL RomOpen(void)
{
gc_init(cfg.async);
}