mirror of
https://github.com/ACreTeam/ac-decomp
synced 2026-08-21 21:40:36 -04:00
repo structure overhaul
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#include "JSystem/JSupport/JSUStream.h"
|
||||
|
||||
JSUFileInputStream::JSUFileInputStream(JKRFile* file)
|
||||
: mObject(file), mPosition(0) {}
|
||||
|
||||
int JSUFileInputStream::readData(void* buf, s32 len) {
|
||||
int read = 0;
|
||||
|
||||
if (((JKRFile*)this->mObject)->isAvailable()) {
|
||||
/* Check if need to clamp length to EOF */
|
||||
if ((u32)(this->mPosition + len) >
|
||||
((JKRFile*)this->mObject)->getFileSize()) {
|
||||
len = ((JKRFile*)this->mObject)->getFileSize() - this->mPosition;
|
||||
}
|
||||
|
||||
if (len > 0) {
|
||||
read = ((JKRFile*)this->mObject)->readData(buf, len, this->mPosition);
|
||||
this->mPosition += read;
|
||||
}
|
||||
}
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
int JSUFileInputStream::seekPos(s32 offset, JSUStreamSeekFrom from) {
|
||||
int pos = this->mPosition;
|
||||
|
||||
switch (from) {
|
||||
case SEEK_SET:
|
||||
this->mPosition = offset;
|
||||
break;
|
||||
|
||||
case SEEK_END:
|
||||
this->mPosition = ((JKRFile*)this->mObject)->getFileSize() - offset;
|
||||
break;
|
||||
|
||||
case SEEK_CUR:
|
||||
this->mPosition = pos + offset;
|
||||
break;
|
||||
}
|
||||
|
||||
if (this->mPosition < 0) {
|
||||
this->mPosition = 0;
|
||||
}
|
||||
|
||||
if (this->mPosition > (s32)((JKRFile*)this->mObject)->getFileSize()) {
|
||||
this->mPosition = ((JKRFile*)this->mObject)->getFileSize();
|
||||
}
|
||||
|
||||
return this->mPosition - pos;
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
#include "JSystem/JSupport/JSUStream.h"
|
||||
|
||||
JSUInputStream::~JSUInputStream() { }
|
||||
|
||||
int JSUInputStream::read(void* buf, s32 size) {
|
||||
int len = this->readData(buf, size);
|
||||
if (len != size) {
|
||||
this->setState(EOF);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
char* JSUInputStream::read(char* str) {
|
||||
u16 size;
|
||||
int len = this->readData(&size, sizeof(size));
|
||||
if (len != sizeof(size)) {
|
||||
str[0] = '\0';
|
||||
this->setState(EOF);
|
||||
str = nullptr;
|
||||
}
|
||||
else {
|
||||
int strRead = this->readData(str, size);
|
||||
str[strRead] = '\0';
|
||||
if (strRead != size) {
|
||||
this->setState(EOF);
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/* @fabricated -- this method is confirmed to exist, but goes unused in AC */
|
||||
char* JSUInputStream::readString() {
|
||||
u16 len;
|
||||
int r = this->readData(&len, sizeof(len));
|
||||
if (r != sizeof(len)) {
|
||||
this->setState(EOF);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char* buf = new char[len+1];
|
||||
r = this->readData(buf, len);
|
||||
if (r != len) {
|
||||
delete[] buf;
|
||||
this->setState(EOF);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
buf[len] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* @fabricated -- this method is confirmed to exist, but goes unused in AC */
|
||||
char* JSUInputStream::readString(char* buf, u16 len) {
|
||||
int r = this->readData(buf, len);
|
||||
if (r != len) {
|
||||
this->setState(EOF);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
buf[len] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
int JSUInputStream::skip(s32 amount) {
|
||||
u8 _p;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < amount; i++) {
|
||||
if (this->readData(&_p, sizeof(_p)) != sizeof(_p)) {
|
||||
this->setState(EOF);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/* JSURandomInputStream */
|
||||
|
||||
int JSURandomInputStream::skip(s32 amount) {
|
||||
int s = this->seekPos(amount, SEEK_CUR);
|
||||
if (s != amount) {
|
||||
this->setState(EOF);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/* This method is confirmed to exist, but goes unused in AC. Retrieved from TP debug. */
|
||||
int JSURandomInputStream::align(s32 alignment) {
|
||||
int pos = this->getPosition();
|
||||
int aligned = ((alignment-1) + pos) & ~(alignment-1);
|
||||
int change = aligned - pos;
|
||||
|
||||
if (change != 0) {
|
||||
int s = this->seekPos(aligned, SEEK_SET);
|
||||
if (s != change) {
|
||||
this->setState(EOF);
|
||||
}
|
||||
}
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
/* This method is confirmed to exist, but goes unused in AC. Retrieved from TP debug. */
|
||||
int JSURandomInputStream::peek(void* buf, s32 len) {
|
||||
int pos = this->getPosition();
|
||||
int r = this->read(buf, len);
|
||||
if (r != 0) {
|
||||
this->seekPos(pos, SEEK_SET);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int JSURandomInputStream::seek(s32 offset, JSUStreamSeekFrom from) {
|
||||
int s = this->seekPos(offset, from);
|
||||
this->clrState(EOF);
|
||||
return s;
|
||||
}
|
||||
Reference in New Issue
Block a user