1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* rmarchiv.tk |
5
|
|
|
* (c) 2016-2017 by Marcel 'ryg' Hering |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace App\Http\Controllers; |
9
|
|
|
|
10
|
|
|
use App\Models\GamesFile; |
11
|
|
|
use Illuminate\Http\Request; |
12
|
|
|
use App\Helpers\PlayerHelper; |
13
|
|
|
use App\Models\GamesSavegame; |
14
|
|
|
use PhpBinaryReader\BinaryReader; |
15
|
|
|
|
16
|
|
|
class SavegameManagerController extends Controller |
17
|
|
|
{ |
18
|
|
|
public function index() |
19
|
|
|
{ |
20
|
|
|
$savegames = GamesSavegame::whereUserId(\Auth::id()) |
|
|
|
|
21
|
|
|
->groupBy('gamefile_id') |
22
|
|
|
->orderBy('updated_at', 'desc') |
23
|
|
|
->get(); |
24
|
|
|
|
25
|
|
|
return view('savegamemanager.index', [ |
26
|
|
|
'games' => $savegames, |
27
|
|
|
]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function show($gamefile_id) |
31
|
|
|
{ |
32
|
|
|
if (\Auth::check()) { |
33
|
|
|
$savegames = GamesSavegame::whereUserId(\Auth::id()) |
34
|
|
|
->where('gamefile_id', '=', $gamefile_id) |
35
|
|
|
->orderBy('slot_id', 'asc') |
36
|
|
|
->get(); |
37
|
|
|
|
38
|
|
|
$gamefile = GamesFile::whereId($gamefile_id)->first(); |
39
|
|
|
|
40
|
|
|
$array = []; |
41
|
|
|
|
42
|
|
|
foreach ($savegames as $savegame) { |
43
|
|
|
$t['id'] = $savegame->id; |
|
|
|
|
44
|
|
|
$t['slot'] = $savegame->slot_id; |
45
|
|
|
$t['data'] = $this->get_lsd_headerdata($savegame->save_data, $gamefile_id); |
46
|
|
|
$t['date'] = $savegame->updated_at; |
47
|
|
|
|
48
|
|
|
$array[] = $t; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return view('savegamemanager.show', [ |
52
|
|
|
'savegames' => $array, |
53
|
|
|
'gamefile_id' => $gamefile_id, |
54
|
|
|
'gamefile' => $gamefile, |
55
|
|
|
]); |
56
|
|
|
} else { |
57
|
|
|
return redirect()->action('IndexController@index'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function get_lsd_headerdata($data, $gamefile_id) |
62
|
|
|
{ |
63
|
|
|
$data = base64_decode($data); |
64
|
|
|
|
65
|
|
|
$br = new BinaryReader($data); |
66
|
|
|
|
67
|
|
|
$array = []; |
68
|
|
|
$br->setPosition(0); |
69
|
|
|
|
70
|
|
|
$array['header']['length'] = $br->readInt8(); |
71
|
|
|
$array['header']['data'] = $br->readString($array['header']['length']); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$cat = $br->readInt8(); |
74
|
|
|
$br->readInt8(); |
75
|
|
|
$br->readInt8(); |
76
|
|
|
$array[$cat]['date']['length'] = $br->readInt8(); |
77
|
|
|
$array[$cat]['date']['data'] = $br->readString($array[$cat]['date']['length']); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$array[$cat]['char1_name']['idx'] = $br->readInt8(); |
|
|
|
|
80
|
|
|
$array[$cat]['char1_name']['length'] = $br->readInt8(); |
81
|
|
|
$array[$cat]['char1_name']['data'] = $br->readString($array[$cat]['char1_name']['length']); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$array[$cat]['char1_level']['idx'] = $br->readInt8(); |
|
|
|
|
84
|
|
|
$array[$cat]['char1_level']['length'] = $br->readInt8(); |
85
|
|
|
$array[$cat]['char1_level']['data'] = $br->readInt8(); |
|
|
|
|
86
|
|
|
|
87
|
|
|
$array[$cat]['char1_hp']['idx'] = $br->readInt8(); |
|
|
|
|
88
|
|
|
$array[$cat]['char1_hp']['length'] = $br->readInt8(); |
89
|
|
|
if ($array[$cat]['char1_hp']['length'] == 2) { |
90
|
|
|
$array[$cat]['char1_hp']['data'] = $br->readInt16(); |
91
|
|
|
} else { |
92
|
|
|
$array[$cat]['char1_hp']['data'] = $br->readInt8(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$array[$cat]['char1_face']['idx'] = $br->readInt8(); |
|
|
|
|
96
|
|
|
$array[$cat]['char1_face']['length'] = $br->readInt8(); |
|
|
|
|
97
|
|
|
$array[$cat]['char1_face']['data'] = $br->readString($array[$cat]['char1_face']['length']); |
|
|
|
|
98
|
|
|
$array[$cat]['char1_face']['img_idx'] = $br->readInt8(); |
99
|
|
|
|
100
|
|
|
if (! is_null($array[$cat]['char1_face']['img_idx'])) { |
101
|
|
|
$pc = new Player2kController(); |
|
|
|
|
102
|
|
|
$files = json_decode($pc->deliver_indexjson($gamefile_id), true); |
103
|
|
|
|
104
|
|
|
$file = $files['faceset/'.strtolower($array[$cat]['char1_face']['data'])]; |
105
|
|
|
|
106
|
|
|
$file = action('Player2kController@deliver_files', [$gamefile_id, $file]); |
107
|
|
|
|
108
|
|
|
$array[$cat]['char1_face']['url'] = $file; |
109
|
|
|
} else { |
110
|
|
|
$array[$cat]['char1_face']['url'] = ''; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $array; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function delete($savegame_id) |
117
|
|
|
{ |
118
|
|
|
if (\Auth::check()) { |
119
|
|
|
$save = GamesSavegame::whereId($savegame_id)->where('user_id', '=', \Auth::id())->first(); |
120
|
|
|
$save->forceDelete(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return redirect()->back(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function download($savegame_id) |
127
|
|
|
{ |
128
|
|
|
if (\Auth::check()) { |
129
|
|
|
$save = GamesSavegame::whereId($savegame_id)->where('user_id', '=', \Auth::id())->first(); |
130
|
|
|
$data = base64_decode($save->save_data); |
131
|
|
|
|
132
|
|
|
$filename = 'Save'.str_pad($save->slot_id, 2, '0', STR_PAD_LEFT).'.lsd'; |
133
|
|
|
$headers = [ |
|
|
|
|
134
|
|
|
'Content-type' => 'application/octet-stream', |
135
|
|
|
'Content-Disposition' => sprintf('attachment; filename="%s"', $filename), |
136
|
|
|
]; |
137
|
|
|
|
138
|
|
|
return \Response::make($data, 200, $headers); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function store(Request $request) |
143
|
|
|
{ |
144
|
|
|
if (\Auth::check()) { |
145
|
|
|
$this->validate($request, [ |
146
|
|
|
'slot' => 'required', |
147
|
|
|
'file' => 'required', |
148
|
|
|
'gamefile_id' => 'required', |
149
|
|
|
]); |
150
|
|
|
|
151
|
|
|
$data = file_get_contents($request->file('file')->getRealPath()); |
152
|
|
|
|
153
|
|
|
if (PlayerHelper::getSavegameValidation($data) == true) { |
|
|
|
|
154
|
|
|
$check = GamesSavegame::whereGamefileId($request->get('gamefile_id')) |
155
|
|
|
->where('user_id', '=', \Auth::id()) |
156
|
|
|
->where('slot_id', '=', $request->get('slot')) |
157
|
|
|
->first(); |
158
|
|
|
|
159
|
|
|
if (! $check) { |
160
|
|
|
$save = new GamesSavegame(); |
|
|
|
|
161
|
|
|
$save->gamefile_id = $request->get('gamefile_id'); |
162
|
|
|
$save->user_id = \Auth::id(); |
|
|
|
|
163
|
|
|
$save->save_data = base64_encode($data); |
|
|
|
|
164
|
|
|
$save->slot_id = $request->get('slot'); |
|
|
|
|
165
|
|
|
$save->save(); |
166
|
|
|
} else { |
167
|
|
|
$check->save_data = base64_encode($data); |
168
|
|
|
$check->save(); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
return redirect()->action('SavegameManagerController@show', $request->get('gamefile_id')); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: