Skip to content

Commit

Permalink
Implemented scaling for standard ingame hud
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-fadely committed Feb 12, 2016
1 parent 3eb0e6e commit 5e96c6a
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
81 changes: 81 additions & 0 deletions SADXModLoader/HudScale.cpp
@@ -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();
}
6 changes: 6 additions & 0 deletions SADXModLoader/HudScale.h
@@ -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();
2 changes: 2 additions & 0 deletions SADXModLoader/SADXModLoader.vcxproj
Expand Up @@ -18,6 +18,7 @@
<ClCompile Include="FileMap.cpp" />
<ClCompile Include="FileReplacement.cpp" />
<ClCompile Include="FixFOV.cpp" />
<ClCompile Include="HudScale.cpp" />
<ClCompile Include="IniFile.cpp" />
<ClCompile Include="MediaFns.cpp" />
<ClCompile Include="stdafx.cpp">
Expand All @@ -37,6 +38,7 @@
<ClInclude Include="FileReplacement.h" />
<ClInclude Include="FixFOV.h" />
<ClInclude Include="git.h" />
<ClInclude Include="HudScale.h" />
<ClInclude Include="include\ModLoader\MemAccess.h" />
<ClInclude Include="include\ninja.h" />
<ClInclude Include="include\SADXModLoader.h" />
Expand Down
6 changes: 6 additions & 0 deletions SADXModLoader/SADXModLoader.vcxproj.filters
Expand Up @@ -60,6 +60,9 @@
<ClCompile Include="AutoMipmap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HudScale.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MediaFns.hpp">
Expand Down Expand Up @@ -128,6 +131,9 @@
<ClInclude Include="D3DCommon.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HudScale.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="SADXModLoader.rc">
Expand Down
6 changes: 4 additions & 2 deletions SADXModLoader/dllmain.cpp
@@ -1,4 +1,3 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

#include <deque>
Expand All @@ -8,7 +7,6 @@
#include <unordered_map>
#include <vector>
#include <sstream>
#include "AutoMipmap.h"

using std::deque;
using std::ifstream;
Expand Down Expand Up @@ -37,6 +35,8 @@ using std::vector;
#include "TextureReplacement.h"
#include "FileReplacement.h"
#include "Events.h"
#include "AutoMipmap.h"
#include "HudScale.h"
#include "FixFOV.h"

/**
Expand Down Expand Up @@ -1987,6 +1987,8 @@ static void __cdecl InitMods(void)
WriteData((uint8_t*)0x0078B7EC, (uint8_t)0x02);
}

SetupHudScale();

sadx_fileMap.scanSoundFolder("system\\sounddata\\bgm\\wma");

// Map of files to replace and/or swap.
Expand Down

0 comments on commit 5e96c6a

Please sign in to comment.