mirror of
https://github.com/zeldaret/ss
synced 2026-08-20 06:06:16 -04:00
sized_string (can we fix libc headers yet?)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include <d/d_rawarchive.h>
|
||||
#include <inline_string.h>
|
||||
#include <rvl/VI.h>
|
||||
|
||||
class UnkManager {
|
||||
@@ -36,7 +35,6 @@ extern "C" void fn_80061BE0(UnkManager *mgr, const char *name, size_t len) {
|
||||
}
|
||||
|
||||
dRawArcEntry_c::dRawArcEntry_c() {
|
||||
mArcName[0] = '\0';
|
||||
mRefCount = 0;
|
||||
mpDvdReq = nullptr;
|
||||
mpArc = nullptr;
|
||||
@@ -136,7 +134,7 @@ bool dRawArcEntry_c::loadArcFromDisk(const char *arcName, const char *arcPath, u
|
||||
if (mpDvdReq == nullptr) {
|
||||
return false;
|
||||
}
|
||||
inline_strncpy(mArcName, arcName, sizeof(mArcName));
|
||||
mArcName = arcName;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -161,7 +159,7 @@ bool dRawArcEntry_c::checkArcExistsOnDiskInner(char *outBuf, const char *fileNam
|
||||
}
|
||||
|
||||
int dRawArcEntry_c::mount(const char *name, void *data, void *callbackArg, u8 mountDirection, EGG::Heap *heap) {
|
||||
inline_strncpy(mArcName, name, sizeof(mArcName));
|
||||
mArcName = name;
|
||||
mpArc = EGG::Archive::mount(data, heap, (mountDirection == 0 || mountDirection == 1) ? 4 : -4);
|
||||
if (mpArc == nullptr) {
|
||||
return -1;
|
||||
@@ -201,7 +199,7 @@ int dRawArcEntry_c::ensureLoadedMaybe(void *callbackArg) {
|
||||
if (mpArc == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
mpFrmHeap = mHeap::makeHeapOnCurrentGameHeap(-1, this->mArcName, 0x20, 0);
|
||||
mpFrmHeap = mHeap::makeHeapOnCurrentGameHeap(-1, name(), 0x20, 0);
|
||||
if (mpFrmHeap == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -2,54 +2,9 @@
|
||||
#include <d/d_rawarchive.h>
|
||||
#include <egg/core/eggHeap.h>
|
||||
// clang-format off
|
||||
#include <MSL_C/string.h>
|
||||
#include <sized_string.h>
|
||||
// clang-format on
|
||||
|
||||
template <size_t Size>
|
||||
struct SizedString {
|
||||
SizedString() {
|
||||
mChars[0] = '\0';
|
||||
}
|
||||
|
||||
char mChars[Size];
|
||||
|
||||
char *operator&() {
|
||||
return mChars;
|
||||
}
|
||||
|
||||
const char *operator&() const {
|
||||
return mChars;
|
||||
}
|
||||
|
||||
inline void set(const char *src) {
|
||||
if (src != mChars) {
|
||||
mChars[0] = '\0';
|
||||
append(src);
|
||||
}
|
||||
}
|
||||
|
||||
inline void append(const char *src) {
|
||||
if (src != nullptr) {
|
||||
size_t destLen = strlen(mChars);
|
||||
size_t copyLen = strlen(src);
|
||||
|
||||
// Make sure copy length isnt more than destination length
|
||||
if (destLen + copyLen + 1 >= Size) {
|
||||
size_t tmpLen = Size - destLen;
|
||||
copyLen = tmpLen - 1;
|
||||
}
|
||||
|
||||
strncpy(mChars + destLen, src, copyLen);
|
||||
|
||||
// make sure string is null terminated
|
||||
size_t offset = destLen + copyLen;
|
||||
mChars[offset] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void sprintf(const char *fmt, ...);
|
||||
};
|
||||
|
||||
class CurrentStageArcManager {
|
||||
CurrentStageArcManager();
|
||||
virtual ~CurrentStageArcManager();
|
||||
@@ -103,7 +58,7 @@ void CurrentStageArcManager::init(EGG::Heap *heap) {
|
||||
extern "C" void fn_8001F820(char *str, const char *src, ...);
|
||||
|
||||
bool CurrentStageArcManager::setStage(const char *newStage) {
|
||||
mStageName.set(newStage);
|
||||
mStageName = newStage;
|
||||
|
||||
mCurrentLoadingStageArcName.sprintf("%s_stg_l0", mStageName);
|
||||
if (dRawArcEntry_c::checkArcExistsOnDisk(&mCurrentLoadingStageArcName, getCurrentStageDirectory())) {
|
||||
@@ -181,8 +136,8 @@ EGG::ExpHeap *getHeap() {
|
||||
|
||||
const char *CurrentStageArcManager::getCurrentStageDirectory() {
|
||||
static SizedString<64> sStageDirTmp;
|
||||
sStageDirTmp.set("Stage/");
|
||||
sStageDirTmp.append(&mStageName);
|
||||
sStageDirTmp = "Stage/";
|
||||
sStageDirTmp += &mStageName;
|
||||
|
||||
return &sStageDirTmp;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "toBeSorted/file_manager.h"
|
||||
#include "f/f_base.h"
|
||||
#include <m/m_heap.h>
|
||||
#include <inline_string.h>
|
||||
// clang-format off
|
||||
#include <sized_string.h>
|
||||
// clang-format on
|
||||
|
||||
// This class here makes no sense and the name might
|
||||
// be a total misnomer, but this gets the sinit section correct
|
||||
@@ -116,10 +118,9 @@ u16 *FileManager::getStoryFlagsMut() {
|
||||
file->selectedDowsingSlot = 0x8;
|
||||
file->lastUsedPouchItemSlot = 0x8;
|
||||
|
||||
char buf[0x20];
|
||||
buf[0] = '\0';
|
||||
inline_strncpy(buf, "F405", sizeof(buf));
|
||||
file->setAreaT1(buf);
|
||||
SizedString<32> buf;
|
||||
buf = "F405";
|
||||
file->setAreaT1(&buf);
|
||||
file->room_id_t1 = 0;
|
||||
file->forced_layer_t1 = 0;
|
||||
file->entrance_t1_load_flag = 1;
|
||||
|
||||
Reference in New Issue
Block a user