mirror of
https://github.com/zeldaret/ss
synced 2026-09-07 11:01:45 -04:00
sized_string (can we fix libc headers yet?)
This commit is contained in:
@@ -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