Beispiel #1
0
        private unsafe byte ReadSqpackHandler(IntPtr pFileHandler, SeFileDescriptor *pFileDesc, int priority, bool isSync)
        {
            var gameFsPath = Marshal.PtrToStringAnsi(new IntPtr(pFileDesc->ResourceHandle->FileName));

            var isRooted = Path.IsPathRooted(gameFsPath);

            if (gameFsPath == null || gameFsPath.Length >= 260 || !isRooted)
            {
                return(ReadSqpackHook.OriginalFunction(pFileHandler, pFileDesc, priority, isSync));
            }

#if DEBUG
            PluginLog.Log("loading modded file: {GameFsPath}", gameFsPath);
#endif

            pFileDesc->FileMode = FileMode.LoadUnpackedResource;

            // note: must be utf16
            var utfPath = Encoding.Unicode.GetBytes(gameFsPath);

            Marshal.Copy(utfPath, 0, new IntPtr(&pFileDesc->UtfFileName), utfPath.Length);

            var fd = stackalloc byte[0x20 + utfPath.Length + 0x16];
            Marshal.Copy(utfPath, 0, new IntPtr(fd + 0x21), utfPath.Length);

            pFileDesc->FileDescriptor = fd;

            return(ReadFile(pFileHandler, pFileDesc, priority, isSync));
        }