-
Notifications
You must be signed in to change notification settings - Fork 4
/
Super Mario War.sh
381 lines (336 loc) · 12.7 KB
/
Super Mario War.sh
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
#!/bin/bash
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
export HOME=/root
if [ -d "/opt/system/Tools/PortMaster/" ]; then
controlfolder="/opt/system/Tools/PortMaster"
elif [ -d "/opt/tools/PortMaster/" ]; then
controlfolder="/opt/tools/PortMaster"
elif [ -d "$XDG_DATA_HOME/PortMaster/" ]; then
controlfolder="$XDG_DATA_HOME/PortMaster"
else
controlfolder="/roms/ports/PortMaster"
fi
SHDIR=$(dirname "$0")
source $controlfolder/control.txt
source $controlfolder/device_info.txt
get_controls
GAMEDIR="$SHDIR/smw"
> "$GAMEDIR/log.txt" && exec > >(tee "$GAMEDIR/log.txt") 2>&1
$ESUDO rm -rf ~/.smw
$ESUDO ln -s $GAMEDIR/conf/.smw ~/
if [ "$CFW_NAME" = "ArkOS" ]; then
ESUDO="sudo"
if [ -f "/storage/.config/.OS_ARCH" ]; then
ESUDO=""
LANG=""
fi
$ESUDO chmod 666 /dev/tty0
export TERM=linux
export XDG_RUNTIME_DIR=/run/user/$UID/
printf "\033c" > /dev/tty0
dialog --clear
hotkey="Select"
height="15"
width="55"
if [[ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-joystick" ]]; then
param_device="anbernic"
export LD_LIBRARY_PATH=/usr/local/bin
if [ -f "/opt/system/Advanced/Switch to main SD for Roms.sh" ] || [ -f "/opt/system/Advanced/Switch to SD2 for Roms.sh" ] || [ -f "/boot/rk3326-rg351v-linux.dtb" ]; then
$ESUDO setfont /usr/share/consolefonts/Lat7-Terminus20x10.psf.gz
height="20"
width="60"
fi
elif [[ -e "/dev/input/by-path/platform-odroidgo2-joypad-event-joystick" ]]; then
if [[ ! -z $(cat /etc/emulationstation/es_input.cfg | grep "190000004b4800000010000001010000") ]]; then
param_device="oga"
hotkey="Minus"
else
param_device="rk2020"
fi
elif [[ -e "/dev/input/by-path/platform-odroidgo3-joypad-event-joystick" ]]; then
param_device="ogs"
if [[ -e "/opt/.retrooz/device" ]]; then
param_device="$(cat /opt/.retrooz/device)"
if [[ "$param_device" == *"rgb10max2native"* ]]; then
param_device="rgb10maxnative"
elif [[ "$param_device" == *"rgb10max2top"* ]]; then
param_device="rgb10maxtop"
fi
fi
$ESUDO setfont /usr/share/consolefonts/Lat7-Terminus20x10.psf.gz
height="20"
width="60"
elif [[ "$(cat /sys/firmware/devicetree/base/model)" == "Anbernic RG552" ]] || [[ -e "/dev/input/by-path/platform-singleadc-joypad-event-joystick" ]]; then
param_device="rg552"
$ESUDO setfont /usr/share/consolefonts/Lat7-Terminus20x10.psf.gz
height="20"
width="60"
else
param_device="chi"
hotkey="1"
$ESUDO setfont /usr/share/consolefonts/Lat7-Terminus20x10.psf.gz
height="20"
width="60"
fi
SaveSettings() {
for j in "${settings[@]}"
do
echo $j
done > $GAMEDIR/conf/.smw/servers.yml
}
MPSettings() {
mapfile settings < $GAMEDIR/conf/.smw/servers.yml
playername=$(echo ${settings[0]} | cut -c 14-)
server1=$(echo ${settings[2]} | cut -c 3-)
server2=$(echo ${settings[3]} | cut -c 3-)
server3=$(echo ${settings[4]} | cut -c 3-)
cmd=(dialog --clear --backtitle "Super Mario War Netplay" --title "[ Settings ]" --menu "Select option from the list:" "12" "55" "15")
options=(
Back "Back to main menu"
"1)" "Player Name: $playername"
"2)" "Server 1: $server1"
"3)" "Server 2: $server2"
"4)" "server 3: $server3"
)
choices=$("${cmd[@]}" "${options[@]}" 2>&1 > /dev/tty0)
case $choices in
"1)")
if [[ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-joystick" ]]; then
$ESUDO kill -9 $(pidof rg351p-js2xbox)
$ESUDO rg351p-js2xbox --silent -t oga_joypad &
sleep 0.5
if [[ -e "/dev/input/by-path/platform-rg351v-keys-event" ]]; then
$ESUDO ln -s /dev/input/event5 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
else
$ESUDO ln -s /dev/input/event4 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
sleep 0.5
$ESUDO chmod 777 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
newname=`osk "Enter your player name" | tail -n 1`
if [ ! -z "$newname" ]; then
settings[0]="player_name: $newname"
SaveSettings
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Sucessfully saved your new name, $newname" "15" "55" 2>&1 > /dev/tty0
else
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Did not set or save a new name." "15" "55" 2>&1 > /dev/tty0
fi
if [[ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-joystick" ]]; then
$ESUDO kill -9 $(pidof rg351p-js2xbox)
$ESUDO rm /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
;;
"2)")
dialog --clear --backtitle "Super Mario War netplay" --title "" --clear \
--yesno "\nWould you like to set server 1 as your internal ip of ${intip}?" $height $width 2>&1 > /dev/tty0
case $? in
0)
newserver1="$intip"
if [ ! -z "$newserver1" ]; then
settings[2]="- $newserver1"
SaveSettings
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Sucessfully saved your new Server 1, $newserver1" "15" "55" 2>&1 > /dev/tty0
else
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Did not set or save a new Server 1." "15" "55" 2>&1 > /dev/tty0
fi
;;
1)
if [[ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-joystick" ]]; then
$ESUDO kill -9 $(pidof rg351p-js2xbox)
$ESUDO rg351p-js2xbox --silent -t oga_joypad &
sleep 0.5
if [[ -e "/dev/input/by-path/platform-rg351v-keys-event" ]]; then
$ESUDO ln -s /dev/input/event5 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
else
$ESUDO ln -s /dev/input/event4 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
sleep 0.5
$ESUDO chmod 777 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
newserver1=`osk "Enter server IP or URL" | tail -n 1`
if [ ! -z "$newserver1" ]; then
settings[2]="- $newserver1"
SaveSettings
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Sucessfully saved your new Server 1, $newserver1" "15" "55" 2>&1 > /dev/tty0
else
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Did not set or save a new Server 1." "15" "55" 2>&1 > /dev/tty0
fi
if [[ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-joystick" ]]; then
$ESUDO kill -9 $(pidof rg351p-js2xbox)
$ESUDO rm /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
;;
esac
;;
"3)")
dialog --clear --backtitle "Super Mario War netplay" --title "" --clear \
--yesno "\nWould you like to set server 1 as your external ip of ${extip}?" $height $width 2>&1 > /dev/tty0
case $? in
0)
newserver2="$extip"
if [ ! -z "$newserver2" ]; then
settings[3]="- $newserver2"
SaveSettings
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Sucessfully saved your new Server 2, $newserver2" "15" "55" 2>&1 > /dev/tty0
else
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Did not set or save a new Server 2." "15" "55" 2>&1 > /dev/tty0
fi
;;
1)
if [[ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-joystick" ]]; then
$ESUDO kill -9 $(pidof rg351p-js2xbox)
$ESUDO rg351p-js2xbox --silent -t oga_joypad &
sleep 0.5
if [[ -e "/dev/input/by-path/platform-rg351v-keys-event" ]]; then
$ESUDO ln -s /dev/input/event5 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
else
$ESUDO ln -s /dev/input/event4 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
sleep 0.5
$ESUDO chmod 777 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
newserver2=`osk "Enter server IP or URL" | tail -n 1`
if [ ! -z "$newserver2" ]; then
settings[3]="- $newserver2"
SaveSettings
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Sucessfully saved your new Server 2, $newserver2" "15" "55" 2>&1 > /dev/tty0
else
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Did not set or save a new Server 2." "15" "55" 2>&1 > /dev/tty0
fi
if [[ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-joystick" ]]; then
$ESUDO kill -9 $(pidof rg351p-js2xbox)
$ESUDO rm /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
;;
esac
;;
"4)")
if [[ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-joystick" ]]; then
$ESUDO kill -9 $(pidof rg351p-js2xbox)
$ESUDO rg351p-js2xbox --silent -t oga_joypad &
sleep 0.5
if [[ -e "/dev/input/by-path/platform-rg351v-keys-event" ]]; then
$ESUDO ln -s /dev/input/event5 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
else
$ESUDO ln -s /dev/input/event4 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
sleep 0.5
$ESUDO chmod 777 /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
newserver3=`osk "Enter server IP or URL" | tail -n 1`
if [ ! -z "$newserver3" ]; then
settings[4]="- $newserver3"
SaveSettings
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Sucessfully saved your new Server 3, $newserver3" "15" "55" 2>&1 > /dev/tty0
else
dialog --clear --title "Super Mario War Netplay settings" --msgbox "Did not set or save a new Server 3." "15" "55" 2>&1 > /dev/tty0
fi
if [[ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-joystick" ]]; then
$ESUDO kill -9 $(pidof rg351p-js2xbox)
$ESUDO rm /dev/input/by-path/platform-odroidgo2-joypad-event-joystick
fi
;;
esac
}
cd $GAMEDIR/conf
runit() {
cd $GAMEDIR
$ESUDO chmod 666 /dev/tty1
$ESUDO kill -9 $(pidof oga_controls)
$ESUDO $controlfolder/oga_controls smw $param_device &
./smw
$ESUDO kill -9 $(pidof oga_controls)
if [ ! -z $(pgrep smw-server) ]; then
$ESUDO kill -9 $(pidof smw-server)
fi
$ESUDO systemctl restart oga_events &
printf "\033c" >> /dev/tty1
printf "\033c" >> /dev/tty0
}
MPMenu() {
extip="$(curl checkip.amazonaws.com)"
if [ -f "/storage/.config/.OS_ARCH" ]; then
intip="$(ip route | awk '/src/ { print $7 }')"
else
intip="$(ip route | awk '/src/ { print $9 }')"
fi
while true; do
selection=(dialog \
--backtitle "Super Mario War netplay" \
--title "Main Menu" \
--no-collapse \
--clear \
--cancel-label "$hotkey + Start to Exit" \
--menu "Your Internal IP is: ${intip}\nYour External IP is: ${extip}" 13 55 9)
options=(
"1)" "Start server"
"2)" "Stop server"
"3)" "Start game"
"4)" "Settings"
"5)" "Quit"
)
choices=$("${selection[@]}" "${options[@]}" 2>&1 > /dev/tty0)
for choice in $choices; do
case $choice in
"1)")
if [ ! -z $(pgrep smw-server) ]; then
$ESUDO kill -9 $(pidof smw-server)
fi
cd $GAMEDIR
./smw-server &
if [ "$?" == "0" ]; then
dialog --clear --backtitle "Super Mario War netplay" --title "" --clear --msgbox "\n\nThe server has been started successfully." $height $width 2>&1 > /dev/tty0
else
dialog --clear --backtitle "Super Mario War netplay" --title "" --clear --msgbox "\n\nThe server has failed to start." $height $width 2>&1 > /dev/tty0
fi
cd $GAMEDIR/conf
;;
"2)")
$ESUDO kill -9 $(pidof smw-server)
if [ "$?" == "0" ]; then
dialog --clear --backtitle "Super Mario War netplay" --title "" --clear --msgbox "\n\nThe server has been stopped successfully." $height $width 2>&1 > /dev/tty0
else
dialog --clear --backtitle "Super Mario War netplay" --title "" --clear --msgbox "\n\nThe server wasn't running." $height $width 2>&1 > /dev/tty0
fi
;;
"3)")
runit
$ESUDO kill -9 $(pidof oga_controls)
printf "\033c" >> /dev/tty0
unset LD_LIBRARY_PATH
exit 0
;;
"4)")
MPSettings
;;
"5)")
$ESUDO kill -9 $(pidof oga_controls)
if [ ! -z $(pgrep smw-server) ]; then
$ESUDO kill -9 $(pidof smw-server)
fi
printf "\033c" >> /dev/tty0
unset LD_LIBRARY_PATH
exit 0
;;
esac
done
done
}
$ESUDO $controlfolder/oga_controls Mario $param_device &
dialog --clear --backtitle "Super Mario War" --title "" --clear \
--yesno "\nWould you like to start a netplay session?" $height $width 2>&1 > /dev/tty0
case $? in
0) MPMenu;;
1) runit;;
*) $ESUDO kill -9 $(pidof oga_controls)
unset LD_LIBRARY_PATH
printf "\033c" >> /dev/tty0
;;
esac
else
cd $GAMEDIR
$ESUDO chmod 666 /dev/uinput
$GPTOKEYB "smw" -c "./smw.gptk" &
./smw
$ESUDO kill -9 $(pidof gptokeyb)
fi