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
| #import "Command.h"
#include <cube.h>
@implementation Command
- (instancetype)initWithName:(OFString *)name
function:(void (*)())function
argumentsTypes:(int)argumentsTypes
{
self = [super initWithName:name];
_function = function;
_argumentsTypes = argumentsTypes;
return self;
}
- (int)callWithArguments:(OFArray<OFString *> *)arguments isDown:(bool)isDown
{
switch (_argumentsTypes) {
case ARG_1INT:
if (isDown)
((void(__cdecl *)(int))_function)(
(int)[arguments[1] longLongValueWithBase:0]);
break;
case ARG_2INT:
if (isDown)
((void(__cdecl *)(int, int))_function)(
(int)[arguments[1] longLongValueWithBase:0],
(int)[arguments[2] longLongValueWithBase:0]);
break;
case ARG_3INT:
if (isDown)
((void(__cdecl *)(int, int, int))_function)(
(int)[arguments[1] longLongValueWithBase:0],
(int)[arguments[2] longLongValueWithBase:0],
(int)[arguments[3] longLongValueWithBase:0]);
break;
case ARG_4INT:
if (isDown)
((void(__cdecl *)(int, int, int, int))_function)(
(int)[arguments[1] longLongValueWithBase:0],
(int)[arguments[2] longLongValueWithBase:0],
(int)[arguments[3] longLongValueWithBase:0],
(int)[arguments[4] longLongValueWithBase:0]);
break;
case ARG_NONE:
if (isDown)
((void(__cdecl *)())_function)();
break;
case ARG_1STR:
if (isDown)
((void(__cdecl *)(OFString *))_function)(arguments[1]);
break;
case ARG_2STR:
if (isDown)
((void(__cdecl *)(OFString *, OFString *))_function)(
arguments[1], arguments[2]);
break;
case ARG_3STR:
if (isDown)
((void(__cdecl *)(
OFString *, OFString *, OFString *))_function)(
arguments[1], arguments[2], arguments[3]);
break;
case ARG_5STR:
if (isDown)
((void(__cdecl *)(OFString *, OFString *, OFString *,
OFString *, OFString *))_function)(arguments[1],
arguments[2], arguments[3], arguments[4],
arguments[5]);
break;
case ARG_DOWN:
((void(__cdecl *)(bool))_function)(isDown);
break;
case ARG_DWN1:
((void(__cdecl *)(bool, OFString *))_function)(
isDown, arguments[1]);
break;
case ARG_1EXP:
if (isDown)
return ((int(__cdecl *)(int))_function)(
execute(arguments[1]));
break;
case ARG_2EXP:
if (isDown)
return ((int(__cdecl *)(int, int))_function)(
execute(arguments[1]), execute(arguments[2]));
break;
case ARG_1EST:
if (isDown)
return ((int(__cdecl *)(OFString *))_function)(
arguments[1]);
break;
case ARG_2EST:
if (isDown)
return ((int(__cdecl *)(OFString *,
OFString *))_function)(arguments[1], arguments[2]);
break;
case ARG_VARI:
if (isDown)
// limit, remove
((void(__cdecl *)(OFString *))_function)([[arguments
objectsInRange:OFMakeRange(1, arguments.count - 1)]
componentsJoinedByString:@" "]);
break;
}
return 0;
}
@end
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
|
>
>
|
>
>
|
>
>
|
>
>
|
>
>
|
>
>
|
>
>
>
|
>
>
|
>
>
|
>
>
|
>
>
| 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
| #import "Command.h"
#include <cube.h>
static OFArray<OFString *> *
padArguments(OFArray<OFString *> *arguments, size_t count)
{
OFMutableArray<OFString *> *copy;
if (arguments.count >= count)
return arguments;
copy = [arguments mutableCopy];
while (copy.count < count)
[copy addObject:@""];
[copy makeImmutable];
return copy;
}
@implementation Command
- (instancetype)initWithName:(OFString *)name
function:(void (*)())function
argumentsTypes:(int)argumentsTypes
{
self = [super initWithName:name];
_function = function;
_argumentsTypes = argumentsTypes;
return self;
}
- (int)callWithArguments:(OFArray<OFString *> *)arguments isDown:(bool)isDown
{
switch (_argumentsTypes) {
case ARG_1INT:
if (isDown) {
arguments = padArguments(arguments, 2);
((void(__cdecl *)(int))_function)(
(int)[arguments[1] longLongValueWithBase:0]);
}
break;
case ARG_2INT:
if (isDown) {
arguments = padArguments(arguments, 3);
((void(__cdecl *)(int, int))_function)(
(int)[arguments[1] longLongValueWithBase:0],
(int)[arguments[2] longLongValueWithBase:0]);
}
break;
case ARG_3INT:
if (isDown) {
arguments = padArguments(arguments, 4);
((void(__cdecl *)(int, int, int))_function)(
(int)[arguments[1] longLongValueWithBase:0],
(int)[arguments[2] longLongValueWithBase:0],
(int)[arguments[3] longLongValueWithBase:0]);
}
break;
case ARG_4INT:
if (isDown) {
arguments = padArguments(arguments, 5);
((void(__cdecl *)(int, int, int, int))_function)(
(int)[arguments[1] longLongValueWithBase:0],
(int)[arguments[2] longLongValueWithBase:0],
(int)[arguments[3] longLongValueWithBase:0],
(int)[arguments[4] longLongValueWithBase:0]);
}
break;
case ARG_NONE:
if (isDown)
((void(__cdecl *)())_function)();
break;
case ARG_1STR:
if (isDown) {
arguments = padArguments(arguments, 2);
((void(__cdecl *)(OFString *))_function)(arguments[1]);
}
break;
case ARG_2STR:
if (isDown) {
arguments = padArguments(arguments, 3);
((void(__cdecl *)(OFString *, OFString *))_function)(
arguments[1], arguments[2]);
}
break;
case ARG_3STR:
if (isDown) {
arguments = padArguments(arguments, 4);
((void(__cdecl *)(
OFString *, OFString *, OFString *))_function)(
arguments[1], arguments[2], arguments[3]);
}
break;
case ARG_5STR:
if (isDown) {
arguments = padArguments(arguments, 6);
((void(__cdecl *)(OFString *, OFString *, OFString *,
OFString *, OFString *))_function)(arguments[1],
arguments[2], arguments[3], arguments[4],
arguments[5]);
}
break;
case ARG_DOWN:
((void(__cdecl *)(bool))_function)(isDown);
break;
case ARG_DWN1:
arguments = padArguments(arguments, 2);
((void(__cdecl *)(bool, OFString *))_function)(
isDown, arguments[1]);
break;
case ARG_1EXP:
if (isDown) {
arguments = padArguments(arguments, 2);
return ((int(__cdecl *)(int))_function)(
execute(arguments[1]));
}
break;
case ARG_2EXP:
if (isDown) {
arguments = padArguments(arguments, 3);
return ((int(__cdecl *)(int, int))_function)(
execute(arguments[1]), execute(arguments[2]));
}
break;
case ARG_1EST:
if (isDown) {
arguments = padArguments(arguments, 2);
return ((int(__cdecl *)(OFString *))_function)(
arguments[1]);
}
break;
case ARG_2EST:
if (isDown) {
arguments = padArguments(arguments, 3);
return ((int(__cdecl *)(OFString *,
OFString *))_function)(arguments[1], arguments[2]);
}
break;
case ARG_VARI:
if (isDown)
// limit, remove
((void(__cdecl *)(OFString *))_function)([[arguments
objectsInRange:OFMakeRange(1, arguments.count - 1)]
componentsJoinedByString:@" "]);
break;
}
return 0;
}
@end
|