Advertisement
khhs167

FS functions

Jan 2nd, 2024
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | Source Code | 0 0
  1. private static readonly ReferenceTable<WrappingStream> Files = new ReferenceTable<WrappingStream>();
  2.  
  3. private static RESULT FSUserSeek(IntPtr handle, uint pos, IntPtr userdata)
  4. {
  5.     WrappingStream? stream = Files.TryGet(handle);
  6.     if (stream == null)
  7.         return RESULT.ERR_FILE_BAD;
  8.        
  9.     if (!stream.Underlying.CanSeek)
  10.     {
  11.         stream.Underlying = new MemoryStream(Content.LoadBytes(stream.ContentPath));
  12.     }
  13.    
  14.     stream.Position = pos;
  15.     return RESULT.OK;
  16. }
  17.  
  18. private static unsafe RESULT FSUserRead(IntPtr handle, IntPtr buffer, uint sizebytes, ref uint bytesread, IntPtr userdata)
  19. {
  20.     WrappingStream? stream = Files.TryGet(handle);
  21.     if (stream == null)
  22.         return RESULT.ERR_FILE_BAD;
  23.        
  24.     Span<byte> readSpan = new ((byte*)buffer, (int)sizebytes);
  25.     bytesread = (uint)stream.Read(readSpan);
  26.     return bytesread < sizebytes ? RESULT.ERR_FILE_EOF : RESULT.OK;
  27. }
  28.  
  29. private static RESULT FSUserClose(IntPtr handle, IntPtr userdata)
  30. {
  31.     WrappingStream? stream = Files.TryGet(handle);
  32.     if (stream == null)
  33.         return RESULT.ERR_FILE_BAD;
  34.    
  35.     stream.Close();
  36.     Files.Free(handle);
  37.     return RESULT.OK;
  38. }
  39.  
  40. private static RESULT FSUserOpen(IntPtr name, ref uint filesize, ref IntPtr handle, IntPtr userdata)
  41. {
  42.     ContentLump? lump = Content.Load(name.GetString());
  43.    
  44.     if (lump == null)
  45.         return RESULT.ERR_FILE_NOTFOUND;
  46.        
  47.     WrappingStream stream = new WrappingStream(Content.LoadStream(lump));
  48.     stream.ContentPath = name.GetString();
  49.     handle = Files.Create(stream);
  50.     return RESULT.OK;
  51. }
Tags: fmod
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement