Repository navigation
Decompile MsgRes_c
#133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Decompile MsgRes_c
#133
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,44 @@ | ||
| #pragma once | ||
|
|
||
| #include <types.h> | ||
| #include <egg/core/eggHeap.h> | ||
| #include <egg/core/eggMsgRes.h> | ||
| #include <game/bases/d_msg_res.hpp> | ||
| #include <game/bases/d_dvd.hpp> | ||
|
|
||
| class MsgRes_c : public EGG::MsgRes { | ||
| /// @brief Helper class for managing message resources. | ||
| /// @ingroup bases | ||
| class dMessage_c { | ||
| public: | ||
| u8 getFont(ulong messageGroup, ulong messageID); | ||
| u16 getScale(ulong messageGroup, ulong messageID); | ||
| }; | ||
| dMessage_c(); ///< Constructs a new @p dMessage_c instance. | ||
| ~dMessage_c(); ///< Destroys the @p dMessage_c instance. | ||
|
|
||
| private: | ||
| void buildMsgRes(EGG::Heap *heap); ///< Creates a new @p MsgRes_c instance from the loaded message resource file. | ||
|
|
||
| class dMessage_c { | ||
| public: | ||
| static bool create(EGG::Heap *heap); | ||
| static MsgRes_c *getMesRes(); | ||
| static bool create(EGG::Heap *heap); ///< Loads the message resource file from disk and initializes it. | ||
| static wchar_t *getMsg(ulong messageGroup, ulong messageID); ///< Gets a message from the group number and ID. | ||
| static MsgRes_c *getMesRes(); ///< Gets the @p MsgRes_c instance used. | ||
|
|
||
| /** | ||
| * @brief Writes @p num into @p dst with @p digitCount decimal digits, replacing | ||
| * suppressed leading zeros with spaces. At most @p writeLimit characters are | ||
| * written, followed by a null terminator. | ||
| * @unofficial | ||
| * | ||
| * @param num The number to convert. | ||
| * @param dst The destination buffer. | ||
| * @param writeLimit The maximum number of characters to write. | ||
| * @param digitCount The number of digits to write. | ||
| * @param suppressLeadingZero Whether to suppress leading zeros (1) or not (0). | ||
| */ | ||
| static void numToString(int num, wchar_t *dst, size_t writeLimit, int digitCount, int suppressLeadingZero); | ||
|
|
||
| /// @brief Same as ::numToString, but uses full-width characters. | ||
| /// @unofficial | ||
| static void numToFullWidth(int num, wchar_t *dst, size_t writeLimit, int digitCount, int suppressLeadingZero); | ||
|
|
||
| static void changetoFullSize(wchar_t *str); ///< Converts regular ASCII characters in @p str to full-width characters. | ||
|
|
||
| dDvd::loader_c mLoader; ///< The loader for loading the message resource file from disk. | ||
| void *mpFileData; ///< The raw message resource file data. | ||
| MsgRes_c *mpMsgRes; ///< The message resource instance used to retrieve messages. | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #pragma once | ||
|
|
||
| #include <egg/core/eggHeap.h> | ||
| #include <egg/core/eggMsgRes.h> | ||
|
|
||
| /// @brief A simple wrapper around EGG::MsgRes. | ||
| /// @ingroup bases | ||
| class MsgRes_c : public EGG::MsgRes { | ||
| public: | ||
| MsgRes_c(const void *p, EGG::Heap *heap); ///< Constructs a new message resource. | ||
| virtual ~MsgRes_c(); ///< Destroys the @p MsgRes_c instance. | ||
|
|
||
| u8 getFont(ulong messageGroup, ulong messageID); ///< Gets the font for a message. | ||
| u16 getScale(ulong messageGroup, ulong messageID); ///< Gets the scale for a message. | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #include <game/bases/d_message.hpp> | ||
| #include <game/bases/d_game_com.hpp> | ||
| #include <egg/core/eggArchive.h> | ||
| #include <wchar.h> | ||
|
|
||
| static dMessage_c l_dMessage_obj; | ||
|
|
||
| dMessage_c::dMessage_c() : mpFileData(nullptr), mpMsgRes(nullptr) {} | ||
|
|
||
| dMessage_c::~dMessage_c() { | ||
| delete mpMsgRes; | ||
| } | ||
|
|
||
| bool dMessage_c::create(EGG::Heap *heap) { | ||
| char path[100]; | ||
| if (l_dMessage_obj.mpFileData == nullptr) { | ||
| dGameCom::AreaLanguageFolder("Message/Message.arc", path); | ||
|
|
||
| void *buffer = l_dMessage_obj.mLoader.request(path, 0, heap); | ||
| if (buffer == nullptr) { | ||
| return false; | ||
| } | ||
|
|
||
| EGG::Archive *archive = EGG::Archive::mount(buffer, heap, 4); | ||
| EGG::Archive::FileInfo fileInfo; | ||
| l_dMessage_obj.mpFileData = archive->getFile("wii_mj2d.bmg", &fileInfo); | ||
| l_dMessage_obj.buildMsgRes(heap); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void dMessage_c::buildMsgRes(EGG::Heap *heap) { | ||
| mpMsgRes = new (heap, 4) MsgRes_c(mpFileData, nullptr); | ||
| } | ||
|
|
||
| wchar_t *dMessage_c::getMsg(ulong messageGroup, ulong messageID) { | ||
| return l_dMessage_obj.mpMsgRes->getMsg(messageGroup, messageID); | ||
| } | ||
|
|
||
| MsgRes_c *dMessage_c::getMesRes() { | ||
| return l_dMessage_obj.mpMsgRes; | ||
| } | ||
|
|
||
| void dMessage_c::numToString(int num, wchar_t *dst, size_t writeLimit, int digitCount, int suppressLeadingZero) { | ||
| size_t count = 0; | ||
| int digitPos = digitCount - 1; | ||
| bool skipOverZeros = suppressLeadingZero == 1; | ||
|
|
||
| while (digitPos >= 0) { | ||
| int pow10 = 1; | ||
| for (int exp = 0; exp < digitPos; exp++) { | ||
| pow10 *= 10; | ||
| } | ||
|
|
||
| int digit = (num % (pow10 * 10)) / pow10; | ||
|
|
||
| if (digit == 0 && skipOverZeros && digitPos != 0) { | ||
| dst[count] = L' '; | ||
| } else { | ||
| dst[count] = L'0' + digit; | ||
| skipOverZeros = false; | ||
| } | ||
|
|
||
| count++; | ||
| digitPos--; | ||
| if (writeLimit <= count) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| dst[count] = L'\0'; | ||
| } | ||
|
|
||
| void dMessage_c::numToFullWidth(int num, wchar_t *dst, size_t writeLimit, int digitCount, int suppressLeadingZero) { | ||
| numToString(num, dst, writeLimit, digitCount, suppressLeadingZero); | ||
| dMessage_c::changetoFullSize(dst); | ||
| } | ||
|
|
||
| void dMessage_c::changetoFullSize(wchar_t *str) { | ||
| size_t len = wcslen(str); | ||
| for (size_t i = 0; i < len; i++) { | ||
| if (str[i] == L' ') { | ||
| str[i] = 0x3000; | ||
| } else if (0x21 <= str[i] && str[i] <= 0x7E) { | ||
| str[i] = 0xFEE0 + str[i]; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include <game/bases/d_message.hpp> | ||
|
|
||
| MsgRes_c::MsgRes_c(const void *p, EGG::Heap *heap) : EGG::MsgRes(p) {} | ||
|
|
||
| MsgRes_c::~MsgRes_c() {} | ||
|
|
||
| u16 MsgRes_c::getScale(ulong messageGroup, ulong messageID) { | ||
| return getMsgEntry(messageGroup, messageID)->mScale; | ||
| } | ||
|
|
||
| u8 MsgRes_c::getFont(ulong messageGroup, ulong messageID) { | ||
| return getMsgEntry(messageGroup, messageID)->mFont; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.