Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some cleanup.
  • Loading branch information
michael-fadely committed Sep 6, 2015
1 parent 7f4db3f commit 741c083
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
22 changes: 14 additions & 8 deletions SADXModLoader/AutoMipmap.cpp
Expand Up @@ -3,38 +3,44 @@
#include <SADXModLoader.h>
#include "AutoMipmap.h"

IDirect3DTexture8* __fastcall GenerateMipmaps_c(IDirect3DTexture8* d3d_texture, NJS_TEXMEMLIST* njs_texture)
static IDirect3DTexture8* __fastcall GenerateMipmaps_c(IDirect3DTexture8* d3d_texture, NJS_TEXMEMLIST* njs_texture)
{
if (d3d_texture == nullptr)
if (d3d_texture == nullptr || njs_texture == nullptr)
return nullptr;

D3DSURFACE_DESC info;
d3d_texture->GetLevelDesc(0, &info);
Uint32 format = njs_texture->texinfo.texsurface.PixelFormat;

// TODO: Figure out how Chao palettized textures are handled.
if (format == NJD_PIXELFORMAT_PALETTIZED_4BPP || format == NJD_PIXELFORMAT_PALETTIZED_8BPP)
PrintDebug("Palettized texture detected.\n");

// TODO: Consider different filtering. By default, it's D3DX_FILTER_BOX | D3DX_FILTER_DITHER
D3DXFilterTexture(d3d_texture, nullptr, D3DX_DEFAULT, D3DX_DEFAULT);
HRESULT result = D3DXFilterTexture(d3d_texture, nullptr, D3DX_DEFAULT, D3DX_DEFAULT);

if (result != 0)
PrintDebug("Mipmap generation failed with error code 0x%08X\n", result);

D3DSURFACE_DESC info;
d3d_texture->GetLevelDesc(0, &info);

njs_texture->texinfo.texsurface.pSurface = (Uint32*)d3d_texture;
njs_texture->texinfo.texsurface.TextureSize = info.Size;

return d3d_texture;
}

void* ret_addr = (void*)0x0078CD37;
void __declspec(naked) GenerateMipmaps_asm()
static void __declspec(naked) GenerateMipmaps_asm()
{
// This could probably use some optimizing.
__asm
{
mov edx, esi
mov ecx, eax

push esi
push eax
call GenerateMipmaps_c
pop eax
pop esi

jmp ret_addr
}
Expand Down
12 changes: 6 additions & 6 deletions SADXModLoader/FixFOV.cpp
Expand Up @@ -29,7 +29,7 @@ int last_bams = bams_default;
double fov_rads;
double fov_scale = 1.0;

void __cdecl SetClippingRelatedThing_hook(int bams)
static void __cdecl SetClippingRelatedThing_hook(int bams)
{
// We're scaling here because this function
// can be called independently of SetHorizontalFOV_BAMS
Expand All @@ -40,12 +40,12 @@ void __cdecl SetClippingRelatedThing_hook(int bams)
ClippingRelated = (float)((double)VerticalResolution / tan);
}

int __cdecl GetHorizontalFOV_BAMS_hook()
static int __cdecl GetHorizontalFOV_BAMS_hook()
{
return last_bams;
}

void __cdecl SetHorizontalFOV_BAMS_hook(int bams)
static void __cdecl SetHorizontalFOV_BAMS_hook(int bams)
{
fov_scale = (double)bams_default / bams;
int scaled = (bams == fov_bams) ? fov_bams : (int)(fov_bams * fov_scale);
Expand All @@ -62,7 +62,7 @@ void __cdecl SetHorizontalFOV_BAMS_hook(int bams)
#pragma region assembly

void* setfov_return = (void*)0x00791251;
void __declspec(naked) SetFOV()
static void __declspec(naked) SetFOV()
{
__asm
{
Expand All @@ -81,7 +81,7 @@ void __declspec(naked) SetFOV()
void* fix_to = (void*)0x00781529;
float dummy;

void __declspec(naked) FixFloatStackPls()
static void __declspec(naked) FixFloatStackPls()
{
__asm
{
Expand All @@ -91,7 +91,7 @@ void __declspec(naked) FixFloatStackPls()
}

void* dothething_return = (void*)0x0040872F;
void __declspec(naked) dothething()
static void __declspec(naked) dothething()
{
__asm
{
Expand Down

0 comments on commit 741c083

Please sign in to comment.