Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented scaling for standard ingame hud
- Loading branch information
1 parent
3eb0e6e
commit 5e96c6a
Showing
5 changed files
with
99 additions
and
2 deletions.
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "stdafx.h" | ||
#include "SADXModLoader.h" | ||
#include "Trampoline.h" | ||
#include "HudScale.h" | ||
|
||
// TODO: Pause menu, misc. 2D things (i.e lens flare), main menu, character select | ||
|
||
Trampoline trampoline(0x00404660, 0x00404666, (DetourFunction)Draw2DSpriteHax); | ||
Trampoline scaleRingLife(0x00425F90, 0x00425F95, (DetourFunction)ScaleA); | ||
Trampoline scaleScoreTime(0x00427F50, 0x00427F55, (DetourFunction)ScaleB); | ||
|
||
static bool doScale = false; | ||
static float scale = 1.0f; | ||
static float last_h = 0.0f; | ||
static float last_v = 0.0f; | ||
|
||
void SetupHudScale() | ||
{ | ||
scale = min(HorizontalStretch, VerticalStretch); | ||
} | ||
|
||
void Draw2DSpriteHax(NJS_SPRITE* sp, Int n, Float pri, Uint32 attr, char zfunc_type) | ||
{ | ||
if (sp == nullptr) | ||
return; | ||
|
||
FunctionPointer(void, original, (NJS_SPRITE* sp, Int n, Float pri, Uint32 attr, char zfunc_type), trampoline.Target()); | ||
if (!doScale) | ||
{ | ||
original(sp, n, pri, attr, zfunc_type); | ||
return; | ||
} | ||
|
||
NJS_POINT2 old_scale = { sp->sx, sp->sy }; | ||
NJS_POINT3 old_pos = sp->p; | ||
|
||
sp->sx *= scale; | ||
sp->sy *= scale; | ||
sp->p.x *= scale; | ||
sp->p.y *= scale; | ||
|
||
original(sp, n, pri, attr | NJD_SPRITE_SCALE, zfunc_type); | ||
|
||
sp->p = old_pos; | ||
sp->sx = old_scale.x; | ||
sp->sy = old_scale.y; | ||
} | ||
|
||
void SaveScale() | ||
{ | ||
doScale = true; | ||
|
||
last_h = HorizontalStretch; | ||
last_v = VerticalStretch; | ||
|
||
HorizontalStretch = 1.0f; | ||
VerticalStretch = 1.0f; | ||
} | ||
|
||
void RestoreScale() | ||
{ | ||
HorizontalStretch = last_h; | ||
VerticalStretch = last_v; | ||
doScale = false; | ||
} | ||
|
||
void ScaleA() | ||
{ | ||
SaveScale(); | ||
VoidFunc(original, scaleRingLife.Target()); | ||
original(); | ||
RestoreScale(); | ||
} | ||
|
||
void ScaleB() | ||
{ | ||
SaveScale(); | ||
VoidFunc(original, scaleScoreTime.Target()); | ||
original(); | ||
RestoreScale(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
#include "SADXModLoader.h" | ||
void SetupHudScale(); | ||
void __cdecl Draw2DSpriteHax(NJS_SPRITE *sp, Int n, Float pri, Uint32 attr, char zfunc_type); | ||
void __cdecl ScaleA(); | ||
void __cdecl ScaleB(); |
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
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
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