Skip to content

filedevice: Implement BufferFileDevice(Write/Read)Stream#263

Merged
MonsterDruide1 merged 4 commits into
open-ead:masterfrom
german77:buffer
May 16, 2026
Merged

filedevice: Implement BufferFileDevice(Write/Read)Stream#263
MonsterDruide1 merged 4 commits into
open-ead:masterfrom
german77:buffer

Conversation

@german77
Copy link
Copy Markdown
Contributor

@german77 german77 commented May 13, 2026

Originally the scope of this PR was to implement BufferFileDeviceWriteStream and BufferFileDeviceReadStream. However due some issues I ended up implementing BufferReadStreamSrc, BufferWriteStreamSrc, BufferWriteStream, BufferReadStream, IndirectResource and IndirectResourceFactoryBase as well.

BufferFileDeviceReadStream dtor is not matching. The asm says it shouldn't be inlined but my dtor is fully inlined. I can't move it to another cpp file because the ctor is fully inlined. Decompme doesn't want to generate this scratch so there's no link this time. fixed


This change is Reviewable

@german77 german77 force-pushed the buffer branch 3 times, most recently from 4fe55db to a8164b3 Compare May 13, 2026 01:11
@german77
Copy link
Copy Markdown
Contributor Author

I narrowed down the mismatch to compile order. IndirectResourceFactoryBase needs to be compiled before BufferFileDeviceReadStream. Since compile order is based on filename location this means either filedevice or resource folders are incorrect or IndirectResource is not in the resource folder

@german77
Copy link
Copy Markdown
Contributor Author

Found the mistake in the file location with asserts from other games. Now everything matches!

Copy link
Copy Markdown
Contributor

@MonsterDruide1 MonsterDruide1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MonsterDruide1 partially reviewed 9 files and all commit messages, and made 6 comments.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on german77).


include/prim/seadPtrUtil.h line 39 at r2 (raw file):

    static void* align(const void* ptr, u64 n)
    {
        const uintptr_t result = (uintptr_t(ptr) + n - 1) & -n;

I'm not sure if this is equivalent

Suggestion:

const uintptr_t result = (uintptr_t(ptr) + n - 1) & ~n;

include/resource/seadResource.h line 61 at r2 (raw file):

public:
    IndirectResource();
    ~IndirectResource() override;

compiler-generated

Suggestion:

    IndirectResource();

modules/src/stream/seadBufferStream.cpp line 45 at r2 (raw file):

}

u32 BufferReadStreamSrc::skip(s32 offset)

Suggestion:

// NOTE: cannot take negative `offset`, but expects `mSrc->skip(X)` to work with negatives
s32 BufferReadStreamSrc::skip(s32 offset)

modules/src/stream/seadBufferStream.cpp line 133 at r2 (raw file):

    bool isDone = mSrc->write(mBuffer, mCurrentPos) >= mCurrentPos;
    mCurrentPos = 0;
    return isDone;

Suggestion:

    bool success = mSrc->write(mBuffer, mCurrentPos) >= mCurrentPos;
    mCurrentPos = 0;
    return success;

include/stream/seadFileDeviceStream.h line 47 at r2 (raw file):

    void setFileHandle(sead::FileHandle* fileHandle);

    FileDeviceStreamSrc* getSrc() { return &src; }

Suggestion:

FileDeviceStreamSrc* getSrc() const { return &src; }

include/stream/seadFileDeviceStream.h line 64 at r2 (raw file):

    void setFileHandle(sead::FileHandle* fileHandle);

    FileDeviceStreamSrc* getSrc() { return &src; }

Suggestion:

FileDeviceStreamSrc* getSrc() const { return &src; }

Copy link
Copy Markdown
Contributor Author

@german77 german77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@german77 made 5 comments.
Reviewable status: 2 of 9 files reviewed, 6 unresolved discussions (waiting on MonsterDruide1).


include/prim/seadPtrUtil.h line 39 at r2 (raw file):

Previously, MonsterDruide1 wrote…

I'm not sure if this is equivalent

Done. ~n is not equivalent but (~n + 1) is


include/resource/seadResource.h line 61 at r2 (raw file):

Previously, MonsterDruide1 wrote…

compiler-generated

Done.


modules/src/stream/seadBufferStream.cpp line 45 at r2 (raw file):

}

u32 BufferReadStreamSrc::skip(s32 offset)

Done.


include/stream/seadFileDeviceStream.h line 47 at r2 (raw file):

    void setFileHandle(sead::FileHandle* fileHandle);

    FileDeviceStreamSrc* getSrc() { return &src; }

I need a non const reference as this object is passed to another to be read or written.


include/stream/seadFileDeviceStream.h line 64 at r2 (raw file):

    void setFileHandle(sead::FileHandle* fileHandle);

    FileDeviceStreamSrc* getSrc() { return &src; }

I need a non const reference as this object is passed to another to be read or written.

Copy link
Copy Markdown
Contributor

@MonsterDruide1 MonsterDruide1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MonsterDruide1 partially reviewed 7 files and all commit messages, made 1 comment, and resolved 4 discussions.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on german77).


include/prim/seadPtrUtil.h line 39 at r2 (raw file):

Previously, german77 (Narr the Reg) wrote…

Done. ~n is not equivalent but (~n + 1) is

Ah, I think the logic is best described by ~(n - 1) then (subtract one to turn for example 8 to 0b111, then invert all bits to effectively set the lowest three bits to zero).

Copy link
Copy Markdown
Contributor Author

@german77 german77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@german77 made 1 comment.
Reviewable status: 8 of 9 files reviewed, 2 unresolved discussions (waiting on MonsterDruide1).


include/prim/seadPtrUtil.h line 39 at r2 (raw file):

Previously, MonsterDruide1 wrote…

Ah, I think the logic is best described by ~(n - 1) then (subtract one to turn for example 8 to 0b111, then invert all bits to effectively set the lowest three bits to zero).

Done.

Copy link
Copy Markdown
Contributor

@MonsterDruide1 MonsterDruide1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MonsterDruide1 reviewed 1 file and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on german77).


modules/src/stream/seadBufferStream.cpp line 133 at r2 (raw file):

    bool isDone = mSrc->write(mBuffer, mCurrentPos) >= mCurrentPos;
    mCurrentPos = 0;
    return isDone;

Here's still a comment ^
isDone seems like it could be finished later - which is wrong, the function rather indicates whether it was successful or failed in the process of writing.

@german77 german77 force-pushed the buffer branch 2 times, most recently from 12ce676 to e6ef469 Compare May 15, 2026 19:43
Copy link
Copy Markdown
Contributor Author

@german77 german77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@german77 made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on MonsterDruide1).


modules/src/stream/seadBufferStream.cpp line 133 at r2 (raw file):

Previously, MonsterDruide1 wrote…

Here's still a comment ^
isDone seems like it could be finished later - which is wrong, the function rather indicates whether it was successful or failed in the process of writing.

Done. Not sure what's up with reviewable is hiding review comments

Copy link
Copy Markdown
Contributor

@MonsterDruide1 MonsterDruide1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MonsterDruide1 reviewed 2 files and all commit messages, and resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on german77).

@MonsterDruide1 MonsterDruide1 merged commit be37f62 into open-ead:master May 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants