Created
January 30, 2018 16:41
-
-
Save MainMemory/bd93633d770384d74516417b03c71faf to your computer and use it in GitHub Desktop.
SA2 Transparent Chao
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
// SA2TransparentChao.cpp : Defines the exported functions for the DLL application. | |
// | |
#include "stdafx.h" | |
#include "..\sa2-mod-loader\SA2ModLoader\include\SA2ModLoader.h" | |
// void __usercall(NJS_CNK_MODEL *a1@<eax>) | |
static const void *const GetChunkTextureIndexPtr = (void*)0x56D1F0; | |
static inline int GetChunkTextureIndex(NJS_CNK_MODEL *a1) | |
{ | |
__asm | |
{ | |
mov eax, [a1] | |
call GetChunkTextureIndexPtr | |
} | |
} | |
// void __usercall(int a1@<eax>, int a2@<ebx>, int a3) | |
static const void *const SetChunkTextureIndexPtr = (void*)0x56E3D0; | |
static inline void SetChunkTextureIndex(int a1, int a2, int a3) | |
{ | |
__asm | |
{ | |
push[a3] | |
mov ebx, [a2] | |
mov eax, [a1] | |
call SetChunkTextureIndexPtr | |
add esp, 4 | |
} | |
} | |
DataPointer(unsigned int, ChunkColor, 0x1A275A4); | |
DataPointer(int, UseChunkMaterialFlags, 0x1AED2CC); | |
DataPointer(int, ChunkMaterialFlags, 0x1A27594); | |
unsigned int *const ChaoColors = (unsigned int *)0x129844C; | |
unsigned int ShinyJewelColors[] = { | |
0, | |
0x8080FF80u, | |
0xFFFFFFFFu, | |
0x8080FFFFu, | |
0xFF80FF80u, | |
0x80FF8080u, | |
0, | |
0x8000FFFFu, | |
0xC000FF00u, | |
0, | |
0xC0FF4040u, | |
0xC000FFFFu, | |
0x80FFFFFFu | |
}; | |
void SetChaoColorTexture_i(int texture, int color, int shiny, int highlights, NJS_CNK_MODEL *model) | |
{ | |
int flags = 0; | |
if (!model) | |
return; | |
if (shiny) | |
{ | |
flags = 6; | |
SetChunkTextureIndex(GetChunkTextureIndex(model), 1, 1); | |
SetChunkTextureIndex(34, 1, 1); | |
if (texture > 0) | |
{ | |
flags |= 8; | |
ChunkColor = ShinyJewelColors[color - 1]; | |
} | |
} | |
else if (texture > 0) | |
{ | |
ChunkColor = -1; | |
flags = 12; | |
SetChunkTextureIndex(texture + 17, 1, 1); | |
} | |
if (texture == 0) | |
{ | |
if (color > 0) | |
{ | |
flags |= 8u; | |
ChunkColor = ChaoColors[color - 1]; | |
} | |
if (highlights) | |
flags |= 1u; | |
else | |
SetChunkTextureIndex(GetChunkTextureIndex(model), 1, 1); | |
} | |
if (flags) | |
{ | |
UseChunkMaterialFlags = 1; | |
ChunkMaterialFlags = flags; | |
} | |
else | |
{ | |
UseChunkMaterialFlags = 0; | |
ChunkMaterialFlags = 0; | |
} | |
} | |
static void __declspec(naked) SetChaoColorTexture() | |
{ | |
__asm | |
{ | |
push[esp + 10h] // model | |
push[esp + 10h] // highlights | |
push[esp + 10h] // shiny | |
push[esp + 10h] // color | |
push edi // texture | |
// Call your __cdecl function here: | |
call SetChaoColorTexture_i | |
pop edi // texture | |
add esp, 4 // color | |
add esp, 4 // shiny | |
add esp, 4 // highlights | |
add esp, 4 // model | |
retn | |
} | |
} | |
extern "C" | |
{ | |
__declspec(dllexport) void Init(const char *path, const HelperFunctions &helperFunctions) | |
{ | |
WriteJump((void*)0x56D470, SetChaoColorTexture); | |
} | |
__declspec(dllexport) ModInfo SA2ModInfo { ModLoaderVer }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment