From 13d9bcb5b4550f877fb2c257c5be3252d2029023 Mon Sep 17 00:00:00 2001 From: Daren Gordon Date: Tue, 9 Aug 2022 10:47:49 -0400 Subject: [PATCH] This is me learning how to use git i'm running into constant errors and having a hard time but hopefully i'll get there in the end okay here we go into my local ocdizzle branch we go! --- Test.txt | 1 + data/dynos.c.h | 28 + data/dynos.cpp.h | 714 ++++++ data/dynos.h | 40 + data/dynos_c.cpp | 36 + data/dynos_gfx_init.cpp | 63 + data/dynos_gfx_load.cpp | 278 +++ data/dynos_gfx_read.cpp | 1884 ++++++++++++++++ data/dynos_gfx_texture.cpp | 285 +++ data/dynos_gfx_update.cpp | 200 ++ data/dynos_gfx_write.cpp | 318 +++ data/dynos_level.cpp | 826 +++++++ data/dynos_main.cpp | 133 ++ data/dynos_misc.cpp | 509 +++++ data/dynos_opt.cpp | 847 ++++++++ data/dynos_opt_config.cpp | 62 + data/dynos_opt_cont.cpp | 70 + data/dynos_opt_render.cpp | 311 +++ data/dynos_opt_vanilla.cpp | 155 ++ data/dynos_opt_vanilla_c.c | 71 + data/dynos_sanity.c | 34 + data/dynos_warps.cpp | 475 ++++ dynos.mk | 27 + dynos/cheater_menu.txt | 34 + enhancements/60fps_ex.patch_installed | 0 enhancements/DynOS.1.0.patch_installed | 0 .../exit_course_50_coin_fix.patch_installed | 0 .../increase_delay_on_credits.patch_installed | 0 ...rease_delay_on_star_select.patch_installed | 0 .../leave_ending_screen.patch_installed | 0 .../time_trials.2.4.hotfix.patch_installed | 0 enhancements/v11.5.ex.patch_installed | 0 include/libc/time.h | 234 ++ include/text_cheats_strings.h.in | 220 ++ src/game/cheats_menu.h | 215 ++ src/game/mario_cheats.c | 1790 +++++++++++++++ src/game/mario_cheats.h | 42 + src/game/time_trials.c | 1283 +++++++++++ src/game/time_trials.h | 15 + src/game/time_trials_ghost_geo.inl | 1931 +++++++++++++++++ 40 files changed, 13131 insertions(+) create mode 100644 Test.txt create mode 100644 data/dynos.c.h create mode 100644 data/dynos.cpp.h create mode 100644 data/dynos.h create mode 100644 data/dynos_c.cpp create mode 100644 data/dynos_gfx_init.cpp create mode 100644 data/dynos_gfx_load.cpp create mode 100644 data/dynos_gfx_read.cpp create mode 100644 data/dynos_gfx_texture.cpp create mode 100644 data/dynos_gfx_update.cpp create mode 100644 data/dynos_gfx_write.cpp create mode 100644 data/dynos_level.cpp create mode 100644 data/dynos_main.cpp create mode 100644 data/dynos_misc.cpp create mode 100644 data/dynos_opt.cpp create mode 100644 data/dynos_opt_config.cpp create mode 100644 data/dynos_opt_cont.cpp create mode 100644 data/dynos_opt_render.cpp create mode 100644 data/dynos_opt_vanilla.cpp create mode 100644 data/dynos_opt_vanilla_c.c create mode 100644 data/dynos_sanity.c create mode 100644 data/dynos_warps.cpp create mode 100644 dynos.mk create mode 100644 dynos/cheater_menu.txt create mode 100644 enhancements/60fps_ex.patch_installed create mode 100644 enhancements/DynOS.1.0.patch_installed create mode 100644 enhancements/exit_course_50_coin_fix.patch_installed create mode 100644 enhancements/increase_delay_on_credits.patch_installed create mode 100644 enhancements/increase_delay_on_star_select.patch_installed create mode 100644 enhancements/leave_ending_screen.patch_installed create mode 100644 enhancements/time_trials.2.4.hotfix.patch_installed create mode 100644 enhancements/v11.5.ex.patch_installed create mode 100644 include/libc/time.h create mode 100644 include/text_cheats_strings.h.in create mode 100644 src/game/cheats_menu.h create mode 100644 src/game/mario_cheats.c create mode 100644 src/game/mario_cheats.h create mode 100644 src/game/time_trials.c create mode 100644 src/game/time_trials.h create mode 100644 src/game/time_trials_ghost_geo.inl diff --git a/Test.txt b/Test.txt new file mode 100644 index 00000000..0f3d06ca --- /dev/null +++ b/Test.txt @@ -0,0 +1 @@ +blahblahblah \ No newline at end of file diff --git a/data/dynos.c.h b/data/dynos.c.h new file mode 100644 index 00000000..35a62412 --- /dev/null +++ b/data/dynos.c.h @@ -0,0 +1,28 @@ +#ifndef DYNOS_C_H +#define DYNOS_C_H +#ifndef __cplusplus + +#include "dynos.h" + +// The action signature is "bool (*) (const char *)" +// The input is the button internal name (not label) +// The output is the result of the action +#define DYNOS_DEFINE_ACTION(func) \ +DYNOS_AT_STARTUP static void dynos_opt_add_action_##func() { \ + dynos_opt_add_action(#func, func, false); \ +} + +s32 dynos_opt_get_value (const char *name); +void dynos_opt_set_value (const char *name, s32 value); +void dynos_opt_add_action (const char *funcname, bool (*funcptr)(const char *), bool overwrite); + +void *dynos_update_cmd (void *cmd); +void dynos_update_gfx (); +void dynos_update_opt (void *pad); +bool dynos_sanity_check_geo (s16 graphNodeType); +bool dynos_sanity_check_seq (u8 loBits); +s32 dynos_gfx_import_texture (void **output, void *ptr, s32 tile, void *grapi, void **hashmap, void *pool, s32 *poolpos, s32 poolsize); +void dynos_gfx_swap_animations (void *ptr); + +#endif +#endif diff --git a/data/dynos.cpp.h b/data/dynos.cpp.h new file mode 100644 index 00000000..febce95b --- /dev/null +++ b/data/dynos.cpp.h @@ -0,0 +1,714 @@ +#ifndef DYNOS_CPP_H +#define DYNOS_CPP_H +#ifdef __cplusplus + +#include "dynos.h" + +#define FUNCTION_CODE (u32) 0x434E5546 +#define POINTER_CODE (u32) 0x52544E50 + +// +// Enums +// + +enum { + DATA_TYPE_NONE = 0, + DATA_TYPE_LIGHT, + DATA_TYPE_TEXTURE, + DATA_TYPE_VERTEX, + DATA_TYPE_DISPLAY_LIST, + DATA_TYPE_GEO_LAYOUT, + DATA_TYPE_ANIMATION_VALUE, + DATA_TYPE_ANIMATION_INDEX, + DATA_TYPE_ANIMATION, + DATA_TYPE_ANIMATION_TABLE, + DATA_TYPE_GFXDYNCMD, + DATA_TYPE_UNUSED, +}; + +enum { + DOPT_NONE = 0, + + DOPT_TOGGLE, + DOPT_CHOICE, + DOPT_SCROLL, + DOPT_BIND, + DOPT_BUTTON, + DOPT_SUBMENU, + + // These ones are used by the Warp to Level built-in submenu + DOPT_CHOICELEVEL, + DOPT_CHOICEAREA, + DOPT_CHOICESTAR, +#ifndef DYNOS_COOP + DOPT_CHOICEPARAM, +#endif +}; + +#ifdef DYNOS_COOP +enum { + DYNOS_COOP_COMMAND_NONE, + DYNOS_COOP_COMMAND_WARP_TO_LEVEL, + DYNOS_COOP_COMMAND_WARP_TO_CASTLE, + DYNOS_COOP_COMMAND_RESTART_LEVEL, + DYNOS_COOP_COMMAND_EXIT_LEVEL, +}; +#endif + +// +// DynOS Array +// A vector-like array, implemented to be processed really fast, but cannot handle C++ complex classes like std::string +// + +template +class Array { +public: + inline Array() : mBuffer(NULL), mCount(0), mCapacity(0) { + } + + inline Array(const std::initializer_list &aList) : mBuffer(NULL), mCount(0), mCapacity(0) { + Resize(aList.size()); + memcpy(mBuffer, aList.begin(), mCount * sizeof(T)); + } + + inline Array(const T *aBegin, const T *aEnd) : mBuffer(NULL), mCount(0), mCapacity(0) { + Resize(aEnd - aBegin); + memcpy(mBuffer, aBegin, mCount * sizeof(T)); + } + + inline Array(const Array &aOther) : mBuffer(NULL), mCount(0), mCapacity(0) { + Resize(aOther.mCount); + memcpy(mBuffer, aOther.mBuffer, mCount * sizeof(T)); + } + + inline void operator=(const Array &aOther) { + Resize(aOther.mCount); + memcpy(mBuffer, aOther.mBuffer, mCount * sizeof(T)); + } + + inline ~Array() { + Clear(); + } + +public: + void Resize(s32 aCount) { + if (aCount > mCapacity) { + mCapacity = MAX(aCount, MAX(16, mCapacity * 2)); + T *_Buffer = (T *) calloc(mCapacity, sizeof(T)); + if (mBuffer) { + memcpy(_Buffer, mBuffer, mCount * sizeof(T)); + free(mBuffer); + } + mBuffer = _Buffer; + } + mCount = aCount; + } + + void Add(const T& aItem) { + Resize(mCount + 1); + mBuffer[mCount - 1] = aItem; + } + + void Remove(s32 aIndex) { + memmove(mBuffer + aIndex, mBuffer + aIndex + 1, (mCount - aIndex - 1) * sizeof(T)); + mCount--; + } + + void Pop() { + mCount--; + } + + void RemoveAll() { + mCount = 0; + } + + void Clear() { + if (mBuffer) free(mBuffer); + mBuffer = NULL; + mCount = 0; + mCapacity = 0; + } + + s32 Find(const T& aItem) const { + for (s32 i = 0; i != mCount; ++i) { + if (mBuffer[i] == aItem) { + return i; + } + } + return -1; + } + + template + s32 FindIf(Predicate aPredicate) const { + for (s32 i = 0; i != mCount; ++i) { + if (aPredicate(mBuffer[i])) { + return i; + } + } + return -1; + } + +public: + inline const T *begin() const { return mBuffer; } + inline const T *end() const { return mBuffer + mCount; } + inline T *begin() { return mBuffer; } + inline T *end() { return mBuffer + mCount; } + + inline const T &operator[](s32 aIndex) const { return mBuffer[aIndex]; } + inline T &operator[](s32 aIndex) { return mBuffer[aIndex]; } + + inline s32 Count() const { return mCount; } + inline bool Empty() const { return mCount == 0; } + +public: + void Read(FILE *aFile) { + s32 _Length = 0; fread(&_Length, sizeof(s32), 1, aFile); + Resize(_Length); + fread(mBuffer, sizeof(T), _Length, aFile); + } + + void Write(FILE *aFile) const { + fwrite(&mCount, sizeof(s32), 1, aFile); + fwrite(mBuffer, sizeof(T), mCount, aFile); + } + +private: + T *mBuffer; + s32 mCount; + s32 mCapacity; +}; + +// +// DynOS String +// A fixed-size string that doesn't require heap memory allocation +// + +#define STRING_SIZE 95 +class String { +public: + inline String() : mCount(0) { + mBuffer[0] = 0; + } + + inline String(const char *aString) : mCount(0) { + if (aString) { + u64 _Length = strlen(aString); + mCount = MIN(_Length, STRING_SIZE - 1); + memcpy(mBuffer, aString, _Length); + } + mBuffer[mCount] = 0; + } + + template + inline String(const char *aFmt, Args... aArgs) : mCount(0) { + snprintf(mBuffer, STRING_SIZE, aFmt, aArgs...); + mCount = (u8) strlen(mBuffer); + mBuffer[mCount] = 0; + } + + inline String(const String &aOther) : mCount(0) { + mCount = aOther.mCount; + memcpy(mBuffer, aOther.mBuffer, mCount); + mBuffer[mCount] = 0; + } + + inline void operator=(const String &aOther) { + mCount = aOther.mCount; + memcpy(mBuffer, aOther.mBuffer, mCount); + mBuffer[mCount] = 0; + } + +public: + void Add(char aChar) { + if (mCount == STRING_SIZE - 1) return; + mBuffer[mCount++] = aChar; + mBuffer[mCount] = 0; + } + + void Remove(s32 aIndex) { + memmove(mBuffer + aIndex, mBuffer + aIndex + 1, (mCount-- - aIndex - 1)); + mBuffer[mCount] = 0; + } + + void RemoveAll() { + mCount = 0; + mBuffer[0] = 0; + } + + void Clear() { + mCount = 0; + mBuffer[0] = 0; + } + + s32 Find(char aChar, s32 aStart = 0) const { + for (u8 i = (u8) aStart; i < mCount; ++i) { + if (mBuffer[i] == aChar) { + return (s32) i; + } + } + return -1; + } + + s32 Find(const char *aString, s32 aStart = 0) const { + const char *_Ptr = strstr(mBuffer + aStart, aString); + if (_Ptr) return (s32) (_Ptr - mBuffer); + return -1; + } + + s32 FindLast(char aChar) const { + for (u8 i = mCount; i != 0; --i) { + if (mBuffer[i - 1] == aChar) { + return (s32) (i - 1); + } + } + return -1; + } + + String SubString(s32 aStart, s32 aCount = STRING_SIZE - 1) const { + if (aStart >= mCount) return String(); + if (aCount < 0) aCount = STRING_SIZE - 1; + aCount = MIN(aCount, mCount - aStart); + String _String; + _String.mCount = aCount; + memcpy(_String.mBuffer, mBuffer + aStart, aCount); + _String.mBuffer[aCount] = 0; + return _String; + } + +public: + inline const char *begin() const { return mBuffer; } + inline const char *end() const { return mBuffer + mCount; } + inline char *begin() { return mBuffer; } + inline char *end() { return mBuffer + mCount; } + + inline const char &operator[](s32 aIndex) const { return mBuffer[aIndex]; } + inline char &operator[](s32 aIndex) { return mBuffer[aIndex]; } + + inline s32 Length() const { return (s32) mCount; } + inline bool Empty() const { return mCount == 0; } + +public: + bool operator==(const char *aString) const { + if (strlen(aString) != mCount) return false; + for (u8 i = 0; i != mCount; ++i) { + if (aString[i] != mBuffer[i]) { + return false; + } + } + return true; + } + + bool operator==(const String &aOther) const { + if (aOther.mCount != mCount) return false; + for (u8 i = 0; i != mCount; ++i) { + if (aOther.mBuffer[i] != mBuffer[i]) { + return false; + } + } + return true; + } + + bool operator!=(const char *aString) const { + if (strlen(aString) != mCount) return true; + for (u8 i = 0; i != mCount; ++i) { + if (aString[i] != mBuffer[i]) { + return true; + } + } + return false; + } + + bool operator!=(const String &aOther) const { + if (aOther.mCount != mCount) return true; + for (u8 i = 0; i != mCount; ++i) { + if (aOther.mBuffer[i] != mBuffer[i]) { + return true; + } + } + return false; + } + +public: + void Read(FILE *aFile) { + fread(&mCount, sizeof(u8), 1, aFile); + fread(mBuffer, sizeof(char), mCount, aFile); + mBuffer[mCount] = 0; + } + + void Write(FILE *aFile) const { + fwrite(&mCount, sizeof(u8), 1, aFile); + fwrite(mBuffer, sizeof(char), mCount, aFile); + } + + s32 ParseInt() const { + s32 i = 0; + if (mBuffer[1] == 'x') { + sscanf(mBuffer + 2, "%x", &i); + } else { + sscanf(mBuffer, "%d", &i); + } + return i; + } + + f32 ParseFloat() const { + f32 f = 0.f; + sscanf(mBuffer, "%f", &f); + return f; + } + +private: + char mBuffer[STRING_SIZE]; + u8 mCount; +}; +static_assert(sizeof(String) == (STRING_SIZE + 1), "sizeof(String) must be (STRING_SIZE + 1)"); + +// +// Types +// + +template +using Pair = std::pair; + +typedef std::string SysPath; + +class NoCopy { + protected: + NoCopy() {} + ~NoCopy() {} + private: + NoCopy(const NoCopy &) = delete; + void operator=(const NoCopy &) = delete; +}; + +struct TexData : NoCopy { + Array mPngData; + Array mRawData; + s32 mRawWidth = -1; + s32 mRawHeight = -1; + s32 mRawFormat = -1; + s32 mRawSize = -1; + bool mUploaded = false; +}; + +struct AnimData : NoCopy { + s16 mFlags = 0; + s16 mUnk02 = 0; + s16 mUnk04 = 0; + s16 mUnk06 = 0; + s16 mUnk08 = 0; + Pair mUnk0A; + Pair> mValues; + Pair> mIndex; + u32 mLength = 0; +}; + +template +struct DataNode : NoCopy { + String mName; + T* mData = NULL; + u32 mSize = 0; + Array mTokens; + u64 mModelIdentifier = 0; + u64 mLoadIndex = 0; +}; +template +using DataNodes = Array*>; + +struct GfxContext { + DataNode* mCurrentTexture = NULL; + DataNode* mCurrentPalette = NULL; +}; + +template +using AnimBuffer = Pair>; +struct GfxData : NoCopy { + + // Model data + DataNodes mLights; + DataNodes mTextures; + DataNodes mVertices; + DataNodes mDisplayLists; + DataNodes mGeoLayouts; + + // Animation data + Array *> mAnimValues; + Array *> mAnimIndices; + DataNodes mAnimations; + Array> mAnimationTable; + + // Current + u64 mLoadIndex = 0; + s32 mErrorCount = 0; + u32 mModelIdentifier = 0; + SysPath mPackFolder; + Array mPointerList; + GfxContext mGfxContext; + Array mGeoNodeStack; +}; + +struct ActorGfx { + GfxData *mGfxData = NULL; + GraphNode *mGraphNode = NULL; + s32 mPackIndex = 0; +}; + +struct PackData { + SysPath mPath; +}; + +typedef Pair Label; +struct DynosOption : NoCopy { + String mName; + String mConfigName; // Name used in the config file + Label mLabel; + Label mTitle; // Full caps label, displayed with colored font + DynosOption *mPrev; + DynosOption *mNext; + DynosOption *mParent; + bool mDynos; // true from create, false from convert + u8 mType; + + // TOGGLE + struct Toggle : NoCopy { + bool *mTog; + } mToggle; + + // CHOICE + struct Choice : NoCopy { + Array