forked from cleolibrary/CLEO4
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Update CGameMenu.cpp #139
Open
PrIzRaKDev
wants to merge
1
commit into
cleolibrary:master
Choose a base branch
from
PrIzRaKDev:patch-4
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Update CGameMenu.cpp #139
Changes from all commits
Commits
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 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,119 +1,110 @@ | ||
#include "stdafx.h" | ||
#include "CGameMenu.h" | ||
#include "cleo.h" | ||
#include "CleoBase.h" | ||
#include "CDebug.h" | ||
#include "CFont.h" | ||
#include "plugin.h" | ||
#include <sstream> | ||
|
||
namespace CLEO | ||
{ | ||
const char CLEO_VERSION_STR[] = VERSION_STRING; | ||
CMenuManager* MenuManager; | ||
|
||
void(__cdecl * TextDraw) (float x, float y, const char* text); | ||
void(__cdecl * SetTextAlign) (BYTE nAlign); | ||
void(__cdecl * SetTextFont) (BYTE nFont); | ||
void(__cdecl* SetTextEdge) (char nEdge); | ||
void(__cdecl * SetLetterSize) (float w, float h); | ||
void(__cdecl * SetLetterColor) (RGBA color); | ||
|
||
// thiscalls dont work with memory_pointer operator overload template | ||
DWORD CMenuManager__ScaleX; | ||
DWORD CMenuManager__ScaleY; | ||
DWORD CTexture__DrawInRect; | ||
//void (__thiscall * CTexture__DrawInRect) (void *texture, RwRect2D *rect, RwRGBA color); | ||
|
||
CMenuManager * MenuManager; | ||
|
||
float CGameMenu_ScaleX(CMenuManager *pMenu, float w) | ||
void __declspec(naked) CTexture_DrawInRect_Hook() | ||
{ | ||
float fReturn; | ||
_asm | ||
__asm | ||
{ | ||
mov ecx, pMenu | ||
push w | ||
call CMenuManager__ScaleX | ||
fstp fReturn | ||
push ebp | ||
mov ebp, esp | ||
push ecx | ||
push dword ptr [ebp + 0x08] | ||
push dword ptr [ebp + 0x04] | ||
mov ecx, dword ptr [ebp + 0x0C] | ||
call CTexture__DrawInRect | ||
pop ebp | ||
ret 0x04 | ||
} | ||
return fReturn; | ||
} | ||
|
||
float CGameMenu_ScaleY(CMenuManager *pMenu, float w) | ||
void __fastcall OnDrawMenuBackground(void *texture, int dummy, RwRect2D *rect, RwRGBA *color) | ||
{ | ||
float fReturn; | ||
_asm | ||
{ | ||
mov ecx, pMenu | ||
push w | ||
call CMenuManager__ScaleY | ||
fstp fReturn | ||
} | ||
return fReturn; | ||
} | ||
_asm push ebp | ||
_asm mov ebp, esp | ||
|
||
void CTexture_DrawInRect(void *pTexture, RwRect2D *rect, RwRGBA *colour) | ||
{ | ||
// Call original CTexture_DrawInRect function | ||
_asm | ||
{ | ||
push colour | ||
push color | ||
push rect | ||
mov ecx, pTexture | ||
mov ecx, texture | ||
call CTexture__DrawInRect | ||
} | ||
} | ||
|
||
void __fastcall OnDrawMenuBackground(void *texture, int dummy, RwRect2D *rect, RwRGBA *color) | ||
{ | ||
CTexture_DrawInRect(texture, rect, color); | ||
// Set font properties | ||
CFont::SetBackground(false, false); | ||
CFont::SetWrapx(640.0f); | ||
CFont::SetFontStyle(FONT_MENU); | ||
CFont::SetProportional(true); | ||
CFont::SetOrientation(ALIGN_LEFT); | ||
|
||
CFont::SetColor({ 0xAD, 0xCE, 0xC4, 0xFF }); | ||
CFont::SetEdge(1); | ||
CFont::SetDropColor({ 0x00, 0x00, 0x00, 0xFF }); | ||
|
||
// Calculate font size and positioning | ||
const float fontSize = 0.5f / 448.0f; | ||
const float aspect = (float)RsGlobal.maximumWidth / RsGlobal.maximumHeight; | ||
const float subtextHeight = 0.75f; // factor of first line height | ||
float sizeX = fontSize * 0.5f / aspect * RsGlobal.maximumWidth; | ||
float sizeY = fontSize * RsGlobal.maximumHeight; | ||
|
||
float posX = 25.0f * sizeX; // left margin | ||
float posY = RsGlobal.maximumHeight - 15.0f * sizeY; // bottom margin | ||
|
||
// Check if any scripts or plugins are active | ||
auto cs_count = GetInstance().ScriptEngine.WorkingScriptsCount(); | ||
auto plugin_count = GetInstance().PluginSystem.GetNumPlugins(); | ||
std::ostringstream cleo_text; | ||
cleo_text << "CLEO v" << CLEO_VERSION_STR; | ||
if (cs_count || plugin_count) | ||
{ | ||
posY -= 15.0f * sizeY; // add space for bottom text | ||
} | ||
|
||
// Draw CLEO version text | ||
std::ostringstream text; | ||
text << "CLEO v" << CLEO_VERSION_STR; | ||
#ifdef _DEBUG | ||
cleo_text << " DEBUG"; | ||
text << " ~r~~h~DEBUG"; | ||
#endif | ||
SetTextAlign(1); | ||
SetTextFont(2); | ||
if (SetTextEdge) SetTextEdge(1); | ||
SetLetterSize(CGameMenu_ScaleX(MenuManager, 0.23f), CGameMenu_ScaleY(MenuManager, 0.4f)); | ||
|
||
SetLetterColor(RGBA(/*0xE1, 0xE1, 0xE1, 0xFF*/0xAD, 0xCE, 0xC4, 0xFF)); | ||
TextDraw(CGameMenu_ScaleX(MenuManager, 6.0f), CGameMenu_ScaleY(MenuManager, 428.0f), cleo_text.str().c_str()); | ||
cleo_text.str(""); | ||
CFont::SetScale(sizeX, sizeY); | ||
CFont::PrintString(posX, posY - 15.0f * sizeY, text.str().c_str()); | ||
|
||
if (cs_count || plugin_count) | ||
{ | ||
if (plugin_count) cleo_text << plugin_count << (plugin_count > 1 ? " plugins" : " plugin"); | ||
if (cs_count && plugin_count) cleo_text << " / "; | ||
if (cs_count) cleo_text << cs_count << (cs_count > 1 ? " scripts" : " script"); | ||
//plugin_text << plugin_count << (plugin_count > 1 ? " plugins" : " plugin"); | ||
SetTextAlign(1); | ||
//SetTextFont(2); | ||
|
||
SetLetterSize(CGameMenu_ScaleX(MenuManager, 0.18f), CGameMenu_ScaleY(MenuManager, 0.34f)); | ||
|
||
SetLetterColor(RGBA(/*0xE1, 0xE1, 0xE1, 0xFF*/0xAD, 0xCE, 0xC4, 0xFF)); | ||
TextDraw(CGameMenu_ScaleX(MenuManager, 6.0f), CGameMenu_ScaleY(MenuManager, 436.0f), cleo_text.str().c_str()); | ||
text.str(""); | ||
if (plugin_count) text << plugin_count << (plugin_count > 1 ? " plugins" : " plugin"); | ||
if (cs_count && plugin_count) text << " / "; | ||
if (cs_count) text << cs_count << (cs_count > 1 ? " scripts" : " script"); | ||
|
||
posY += 15.0f * sizeY; | ||
sizeX *= subtextHeight; | ||
sizeY *= subtextHeight; | ||
CFont::SetScale(sizeX, sizeY); | ||
CFont::PrintString(posX, posY - 15.0f * sizeY, text.str().c_str()); | ||
} | ||
|
||
_asm pop ebp | ||
_asm ret 0x04 | ||
} | ||
|
||
void CGameMenu::Inject(CCodeInjector& inj) | ||
void CGameMenu::Inject(CCodeInjector& inj) | ||
{ | ||
TRACE("Injecting MenuStatusNotifier..."); | ||
CGameVersionManager& gvm = GetInstance().VersionManager; | ||
CGameVersionManager& gvm = GetInstance().VersionManager; | ||
MenuManager = gvm.TranslateMemoryAddress(MA_MENU_MANAGER); | ||
TextDraw = gvm.TranslateMemoryAddress(MA_DRAW_TEXT_FUNCTION); | ||
SetTextAlign = gvm.TranslateMemoryAddress(MA_SET_TEXT_ALIGN_FUNCTION); | ||
SetTextFont = gvm.TranslateMemoryAddress(MA_SET_TEXT_FONT_FUNCTION); | ||
SetTextEdge = gvm.TranslateMemoryAddress(MA_SET_TEXT_EDGE_FUNCTION); | ||
|
||
// Meh... | ||
CMenuManager__ScaleX = gvm.TranslateMemoryAddress(MA_CMENU_SCALE_X_FUNCTION); | ||
CMenuManager__ScaleY = gvm.TranslateMemoryAddress(MA_CMENU_SCALE_Y_FUNCTION); | ||
|
||
SetLetterSize = gvm.TranslateMemoryAddress(MA_SET_LETTER_SIZE_FUNCTION); | ||
SetLetterColor = gvm.TranslateMemoryAddress(MA_SET_LETTER_COLOR_FUNCTION); | ||
inj.MemoryNop(gvm.TranslateMemoryAddress(MA_CALL_CTEXTURE_DRAW_BG_RECT).address + 1, 5); | ||
inj.MemoryJump(gvm.TranslateMemoryAddress(MA_CALL_CTEXTURE_DRAW_BG_RECT).address + 1, (void*)CTexture_DrawInRect_Hook, true); | ||
|
||
inj.MemoryReadOffset(gvm.TranslateMemoryAddress(MA_CALL_CTEXTURE_DRAW_BG_RECT).address + 1, CTexture__DrawInRect, true); | ||
//gvm.TranslateMemoryAddress(MA_CTEXTURE_DRAW_IN_RECT_FUNCTION); | ||
inj.ReplaceFunction(OnDrawMenuBackground, gvm.TranslateMemoryAddress(MA_CALL_CTEXTURE_DRAW_BG_RECT)); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these
&