-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
299 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.IO; | ||
|
||
namespace BinderTool.Core.Bdt5 | ||
{ | ||
public class Bdt5InnerStream : Stream | ||
{ | ||
public const int MAX_STREAM_LEN = 1_000_000; | ||
|
||
private List<MemoryStream> streams; | ||
|
||
private long length; | ||
|
||
|
||
public override long Length => length; | ||
|
||
public override long Position { get; set; } | ||
|
||
public override bool CanRead => true; | ||
|
||
public override bool CanSeek => true; | ||
|
||
public override bool CanWrite => true; | ||
|
||
public Bdt5InnerStream(Stream from, long length, long offset) | ||
{ | ||
this.length = length; | ||
this.streams = new List<MemoryStream>(); | ||
long startPos = from.Position; | ||
for (long pos = 0; pos < length; pos += MAX_STREAM_LEN) | ||
{ | ||
byte[] buf = new byte[MAX_STREAM_LEN]; | ||
from.Seek(offset + pos, SeekOrigin.Begin); | ||
from.Read(buf, 0, (int)Math.Min(length - pos, MAX_STREAM_LEN)); | ||
streams.Add(new MemoryStream(buf)); | ||
} | ||
from.Seek(startPos, SeekOrigin.Begin); | ||
} | ||
public Bdt5InnerStream(Stream from, long length) : this(from, length, 0) {} | ||
public Bdt5InnerStream(long length) | ||
{ | ||
this.length = length; | ||
this.streams = new List<MemoryStream>(); | ||
for (long pos = 0; pos < length; pos += MAX_STREAM_LEN) | ||
{ | ||
byte[] buf = new byte[MAX_STREAM_LEN]; | ||
streams.Add(new MemoryStream(buf)); | ||
} | ||
} | ||
|
||
public override void Flush() {} | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
if (this.Position >= this.length) return 0; | ||
long startPos = this.Position; | ||
long end = Math.Min(this.Position + count, this.length); | ||
while (this.Position < end) | ||
{ | ||
var s = this.streams[(int)(this.Position / MAX_STREAM_LEN)]; | ||
s.Seek(this.Position % MAX_STREAM_LEN, SeekOrigin.Begin); | ||
var read = s.Read(buffer, offset, count); | ||
this.Position += read; | ||
offset += read; | ||
count -= read; | ||
} | ||
return (int)(end - startPos); | ||
} | ||
|
||
public override long Seek(long offset, SeekOrigin origin) | ||
{ | ||
if (origin == SeekOrigin.Begin) this.Position = offset; | ||
if (origin == SeekOrigin.Current) this.Position += offset; | ||
if (origin == SeekOrigin.End) this.Position = this.length + offset; | ||
return this.Position; | ||
} | ||
|
||
public override void SetLength(long value) | ||
{ | ||
this.length = value; | ||
} | ||
|
||
public override void Write(byte[] buffer, int offset, int count) | ||
{ | ||
long end = this.Position + count; | ||
while (this.Position < end) | ||
{ | ||
var s = this.streams[(int)(this.Position / MAX_STREAM_LEN)]; | ||
s.Seek(this.Position % MAX_STREAM_LEN, SeekOrigin.Begin); | ||
var toWrite = (int)Math.Min(s.Length - s.Position, count); | ||
s.Write(buffer, offset, toWrite); | ||
this.Position += toWrite; | ||
offset += toWrite; | ||
count -= toWrite; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ public enum GameVersion | |
DarkSouls2, | ||
DarkSouls3, | ||
Bloodborne, | ||
Sekiro | ||
Sekiro, | ||
EldenRing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.