@@ -48,7 +48,7 @@ struct PS1PackerOptions {
48
48
bool binaryLoaderLoad (LuaFile * src , LuaFile * dest , struct BinaryLoaderInfo * info );
49
49
void ps1PackerPack (LuaFile * src , LuaFile * dest , uint32_t addr , uint32_t pc , uint32_t gp , uint32_t sp ,
50
50
struct PS1PackerOptions options );
51
- uint32_t uclPack ( LuaFile * src , LuaFile * dest );
51
+ uint32_t uclWrapper ( const uint8_t * in , uint32_t size , uint8_t * out );
52
52
uint32_t writeUclDecomp (LuaFile * dest );
53
53
54
54
]]
146
146
if type (PCSX .Misc ) ~= ' table' then PCSX .Misc = {} end
147
147
148
148
PCSX .Misc .uclPack = function (src , dest )
149
- if type (src ) ~= ' table' or src ._type ~= ' File' then error (' Expected a File object as first argument' ) end
150
- if type (dest ) ~= ' table' or dest ._type ~= ' File' then error (' Expected a File object as second argument' ) end
151
- return C .uclPack (src ._wrapper , dest ._wrapper )
149
+ local srcPtr
150
+ local srcSize
151
+ if type (src ) == ' table' and src ._type == ' File' then
152
+ src = src :read (src :size ())
153
+ srcPtr = ffi .cast (' uint8_t*' , src .data )
154
+ srcSize = src .size
155
+ elseif type (src ) == ' string' then
156
+ srcPtr = ffi .cast (' uint8_t*' , src )
157
+ srcSize = # src
158
+ elseif Support .isLuaBuffer (src ) then
159
+ srcPtr = ffi .cast (' uint8_t*' , src .data )
160
+ srcSize = src .size
161
+ elseif type (src ) == ' table' and src ._type == ' Slice' then
162
+ srcPtr = src .data
163
+ srcSize = src .size
164
+ else
165
+ error (' Expected a File object, string, LuaBuffer, or Slice as first argument' )
166
+ end
167
+
168
+ local bufferSize = srcSize * 1.2 + 2048
169
+
170
+ local retIsDest = false
171
+ local destPtr
172
+ local destSlice
173
+ if not dest then
174
+ dest = Support .File .createEmptySlice ()
175
+ dest :resize (bufferSize )
176
+ destPtr = dest .mutable
177
+ retIsDest = true
178
+ elseif type (dest ) == ' table' and dest ._type == ' File' then
179
+ destSlice = Support .File .createEmptySlice ()
180
+ destSlice :resize (bufferSize )
181
+ destPtr = destSlice .mutable
182
+ elseif Support .isLuaBuffer (dest ) then
183
+ destPtr = ffi .cast (' uint8_t*' , dest .data )
184
+ dest :resize (bufferSize )
185
+ elseif type (dest ) == ' table' and dest ._type == ' Slice' then
186
+ destPtr = dest .mutable
187
+ dest :resize (bufferSize )
188
+ else
189
+ error (' Expected a File object, string, LuaBuffer, or Slice as second argument' )
190
+ end
191
+
192
+ local outSize = C .uclWrapper (srcPtr , srcSize , destPtr )
193
+
194
+ if outSize == 0 then
195
+ error (' Fatal error during data compression.' )
196
+ end
197
+
198
+ if type (dest ) == ' table' and dest ._type == ' File' then
199
+ destSlice :resize (outSize )
200
+ dest :writeMoveSlice (destSlice )
201
+ else
202
+ dest :resize (outSize )
203
+ end
204
+
205
+ return retIsDest and dest or outSize
152
206
end
153
207
154
208
PCSX .Misc .writeUclDecomp = function (dest )
0 commit comments