Skip to content

Commit

Permalink
Added more things, renamed more things.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-fadely committed Jan 5, 2016
1 parent 0aee0d2 commit 5f1d68b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
14 changes: 7 additions & 7 deletions SADXModLoader/FixFOV.cpp
Expand Up @@ -46,25 +46,25 @@ static void __cdecl SetupScreenFix(NJS_MATRIX* m)
SetupScreen(m);
}

static void __cdecl SetScreenDist_hook(Angle bams)
static void __cdecl njSetScreenDist_hook(Angle bams)
{
// We're scaling here because this function
// can be called independently of SetHorizontalFOV_BAMS
// can be called independently of njSetPerspective
double m = (double)bams_default / bams;
bams = (Angle)(fov_bams / m);

double tan = njTan(bams / 2) * 2;
_nj_screen_.dist = (float)((double)_nj_screen_.h / tan);
}

static void __cdecl SetHorizontalFOV_BAMS_hook(Angle bams)
static void __cdecl njSetPerspective_hook(Angle bams)
{
fov_scale = (double)bams_default / bams;
Angle scaled = (bams == fov_bams) ? fov_bams : (Angle)(fov_bams * fov_scale);

int* _24 = (int*)&ProjectionMatrix._24;

SetScreenDist_hook(bams);
njSetScreenDist_hook(bams);

HorizontalFOV_BAMS = scaled;
*_24 = scaled;
Expand Down Expand Up @@ -105,16 +105,16 @@ void ConfigureFOV()
fov_bams = NJM_RAD_ANG(fov_rads);

// Function hooks
WriteJump(SetHorizontalFOV_BAMS, SetHorizontalFOV_BAMS_hook);
WriteJump(SetScreenDist, SetScreenDist_hook);
WriteJump(njSetPerspective, njSetPerspective_hook);
WriteJump(njSetScreenDist, njSetScreenDist_hook);

// Code patches
WriteJump((void*)0x0079124A, SetFOV);
WriteData((float**)0x00781525, &dummy); // Dirty hack to disable a write to ClippingRelated and keep the floating point stack balanced.
WriteData((Angle**)0x0040872B, &last_bams); // Fixes a case of direct access to HorizontalFOV_BAMS
WriteData((Angle**)0x00402F01, &last_bams); // Changes return value of GetHorizontalFOV_BAMS

SetHorizontalFOV_BAMS_hook(bams_default);
njSetPerspective_hook(bams_default);

// Stops the Pause Menu from using horizontal stretch in place of vertical stretch in coordinate calculation
// Main Pause Menu
Expand Down
17 changes: 15 additions & 2 deletions SADXModLoader/include/SADXModLoader/SADXFunctions.h
Expand Up @@ -382,9 +382,22 @@ FastcallFunctionPointer(Sint32, njSetTextureNum, (Uint32 n), 0x0077F440);
FastcallFunctionPointer(void, njAddVector, (NJS_VECTOR *vd, NJS_VECTOR *vs), 0x00785170);
FunctionPointer(void, njSetConstantMaterial, (NJS_ARGB *mat), 0x0077FF90);

FunctionPointer(void, SetHorizontalFOV_BAMS, (Angle bams), 0x00402ED0);
/// <summary>
/// Draws 2D sprite with animations if available.
/// </summary>
/// <param name="sp">Pointer for sprite structure.</param>
/// <param name="n">Sprite number.</param>
/// <param name="pri">Priority (Z value). Can be -1.0 through -65535.0. When in doubt, use -1.0</param>
/// <param name="attr">Attributes. See the <c>NJD_SPRITE_*</c> preprocessor definitions in ninja.h.</param>
/// <param name="zfunc_type">When in doubt, use 1. Also commonly used is 4. To be detailed once it's figured out.</param>
FunctionPointer(void, Draw2DSprite, (NJS_SPRITE *sp, Int n, Float pri, Uint32 attr, char zfunc_type), 0x00404660);
FunctionPointer(void, SetSpriteColor, (NJS_ARGB *a1), 0x00402F40);
FunctionPointer(Bool, IsControllerEnabled, (Uint8 index), 0x0040EFD0);
FunctionPointer(char, IsVisible, (NJS_VECTOR *v), 0x004CD730);

FunctionPointer(void, njSetPerspective, (Angle bams), 0x00402ED0);
FunctionPointer(Angle, GetHorizontalFOV_BAMS, (void), 0x00402F00);
FunctionPointer(void, SetScreenDist, (Angle bams), 0x007815C0);
FunctionPointer(void, njSetScreenDist, (Angle bams), 0x007815C0);

#ifdef _MSC_VER

Expand Down

0 comments on commit 5f1d68b

Please sign in to comment.