Skip to content

Instantly share code, notes, and snippets.

@blluv
Created August 18, 2022 02:36
Show Gist options
  • Save blluv/caf1e9ea5329b0f9ea26a907a26a00bc to your computer and use it in GitHub Desktop.
Save blluv/caf1e9ea5329b0f9ea26a907a26a00bc to your computer and use it in GitHub Desktop.
#include "pch.h"
#include <windows.h>
#include "D:\\Detours-master\\include\\detours.h"
#pragma comment(lib, "D:\\Detours-master\\lib.X86\\detours.lib")
#pragma warning(disable : 4996)
#include <stdio.h>
/*
typedef LPDIRECT3DDEVICE9(*GetDeviceFunc)();
GetDeviceFunc getDevice = (GetDeviceFunc)0x49F0A0;
*/
typedef void(*DrawTextFunc)(char* text, float pos_x, float pos_y, float scale, int flag, int argb, float shadow);
DrawTextFunc origDrawText = (DrawTextFunc)0x481A70;
typedef void(*RenderObjFunc)(float dstX, float dstY, float dstW, float dstH, int* shader, int srcX, int srcY, int width, int height, int flag, int color);
RenderObjFunc origRenderObj = (RenderObjFunc)0x454C10;
int** fontShader = (int**)0xF27EE8;
UINT16 table[] = { 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 32, 32, 33409, 33410, 33411, 33412, 33413, 33414, 33415, 33416, 33417, 33418, 33419, 33420, 33421, 33422, 33423, 33424, 33425, 33426, 33427, 33428, 33429, 33430, 33431, 33432, 33433, 33434, 33376, 33377, 33378, 33379, 33380, 33381, 33382, 33383, 33384, 33385, 33386, 33387, 33388, 33389, 33390, 33391, 33392, 33393, 33394, 33395, 33396, 33397, 33398, 33399, 33400, 33401, 33359, 33360, 33361, 33362, 33363, 33364, 33365, 33366, 33367, 33368, 33088, 33088, 33440, 33442, 33444, 33446, 33448, 33449, 33451, 33453, 33455, 33457, 33459, 33461, 33463, 33465, 33467, 33469, 33471, 33474, 33476, 33478, 33480, 33481, 33482, 33483, 33484, 33485, 33488, 33491, 33494, 33497, 33500, 33501, 33502, 33503, 33504, 33506, 33508, 33510, 33511, 33512, 33513, 33514, 33515, 33517, 33520, 33521, 33439, 33441, 33443, 33445, 33447, 33473, 33505, 33507, 33509, 33450, 33452, 33454, 33456, 33458, 33460, 33462, 33464, 33466, 33468, 33470, 33472, 33475, 33477, 33479, 33486, 33489, 33492, 33495, 33498, 33487, 33490, 33493, 33496, 33499, 33115, 33120, 33098, 33099, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33601, 33603, 33605, 33607, 33609, 33610, 33612, 33614, 33616, 33618, 33620, 33622, 33624, 33626, 33628, 33630, 33632, 33635, 33637, 33639, 33641, 33642, 33643, 33644, 33645, 33646, 33649, 33652, 33655, 33658, 33661, 33662, 33664, 33665, 33666, 33668, 33670, 33672, 33673, 33674, 33675, 33676, 33677, 33679, 33682, 33683, 33600, 33602, 33604, 33606, 33608, 33634, 33667, 33669, 33671, 33611, 33613, 33615, 33617, 33619, 33621, 33623, 33625, 33627, 33629, 33631, 33633, 33636, 33638, 33640, 33647, 33650, 33653, 33656, 33659, 33648, 33651, 33654, 33657, 33660, 33684, 33089, 33090, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33, 63, 43, 45, 46, 44, 58, 59, 47, 40, 41, 91, 93, 95, 60, 62, 34, 38, 37, 61, 33190, 33097, 33096, 33147, 33148, 33092, 33091, 33094, 33095, 33118, 33129, 33130, 33133, 33134, 33105, 33155, 33156, 33127, 33128, 33173, 33171, 33153, 33268, 33179, 33180, 33181, 33188, 33189, 33186, 33187, 33184, 33185, 33183, 33177, 33178, 33141, 33142, 33143, 33144, 33249, 33250, 33093, 33124, 33123, 33194, 33195, 33193, 33192, 33951, 33145, 33146, 39, 42, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 33088, 35302, 38602, 37085, 37608, 38363, 37302, 36536, 38003, 38351, 36184, 35402, 36462, 37193, 37360, 36211, 36846, 38385, 35429, 36589, 36681, 38841, 36027, 36317, 35648, 37324, 37578, 36845, 35209, 36719, 36708, 36491, 36851, 37332, 38623, 38346, 37080, 37334, 36695, 35958, 37261, 36231, 37203, 35018, 38236, 36518, 37012, 37484, 37884, 37743, 39006, 36743, 36257, 35313, 36510, 35540, 37822, 37994, 35315, 37703, 35542, 38977, 38588, 35976, 38061, 36555, 35230, 37806, 36332, 37510, 35231, 36745, 35578, 35016, 35407, 36544, 36030, 36074, 36088, 35274, 35257, 38395, 36526, 38823, 37076, 37058, 38219, 38774, 38579, 36842, 35050, 37752, 38792, 38558, 38300, 37782, 38075, 35311, 39010, 35399, 37199, 35261, 37856, 38757, 36950, 37277, 35265, 36455, 38768, 35266, 37980, 35965, 35970, 37882, 38523, 35184, 37031, 38641, 38133, 36204, 35219, 35735, 38819, 36181, 37309, 35437, 37958, 35034, 36746, 37294, 37786, 35922, 36543, 38626, 38798, 37509, 36781, 35827, 35046, 36080, 37101, 36562, 37088, 38590, 37756, 36947, 38010, 36567, 38530, 35651, 35252, 37330, 36521, 38314, 37026, 35397, 36293, 35757, 36241, 35270, 35990, 35292, 38020, 38617, 37256, 38813, 37242, 37705, 35312, 38464, 37258, 36584, 36972, 35398, 37830, 35263, 35535, 36509, 35041, 37046, 37308, 38327, 36484, 37050, 35033, 35729, 38107, 38881, 35734, 34987, 38260, 37727, 36470, 35669, 37200, 36967, 37825, 37541, 36054, 37539, 36279, 35031, 35936, 38281, 37349, 35934, 38724, 37082, 38356, 36452, 37317, 38493, 37554, 36465, 36838, 38259, 37804, 36067, 38907, 36683, 37711, 37610, 35963, 37545, 38594, 36421, 35027, 38561, 35233, 35927, 36034, 36262, 37789, 38822, 36582, 36009, 36313, 35207, 36076, 37496, 37344, 37559, 35918, 36164, 36835, 36457, 37322, 37770, 36222, 38367, 38840, 34997, 38589, 36303, 34980, 35064, 36595, 35138, 37499, 37802, 35979, 35783, 35439, 36069, 37456, 37485, 37013, 35522, 35755, 35527, 36068, 38499, 35675, 36503, 35433, 37326, 37037, 36340, 38292, 38794, 35394, 37998, 36525, 38640, 38618, 38479, 38312, 35014, 36757, 36941, 38007, 38304, 37347, 34995, 38898, 37728, 35828, 37202, 37807, 35785, 37467, 37094, 36767, 35771, 37442, 35748, 37116, 36036, 38828, 37477, 36557, 35533, 35728, 35173, 35807, 36935, 37747, 36467, 38066, 36969, 38984, 36761, 33112, 36996, 35950, 37707, 38750, 37292, 36949, 37035, 37445, 37575, 36751, 35993, 35166, 38080, 36162, 37817, 36168, 35814, 36092, 38231, 36433, 35743, 37249, 37981, 36804, 38042, 36188, 36511, 37350, 36765, 36780, 35565, 38532, 36254, 38077, 38130, 38644, 35680, 37291, 37090, 37871, 37036, 36087, 37966, 37448, 36494, 38861, 37466, 38592, 38567, 35674, 36720, 35763, 36965, 38275, 35943, 35502, 37068, 36481, 37043, 36812, 37809, 36032, 35697, 37617, 37075, 37955, 36004, 35718, 37965, 37482, 35259, 35713, 37790, 38110, 37098, 38629, 38636, 38746, 37564, 37248, 38305, 37051, 36929, 35548, 35766, 36472, 36833, 35300, 35258, 35760, 38268, 38392, 36256, 36942, 38338, 35952, 38112, 36801, 38597, 37517, 36258, 37444, 38581, 36738, 36759, 38504, 35185, 36480, 35042, 36603, 35498, 35662, 37269, 36194, 37071, 36461, 38738, 37460, 38370, 35723, 38394, 35528, 35008, 35765, 36000, 33088, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
void colorDivide(int color, int* a, int* r, int* g, int* b) {
*a = (color >> 24) & 0xff;
*r = (color >> 16) & 0xff;
*g = (color >> 8) & 0xff;
*b = (color) & 0xff;
}
int colorCombine(int a, int r, int g, int b) {
return b | ((g | (((a << 8) | r) << 8)) << 8);
}
void hookDrawText(UINT8* text, float posX, float posY, float scale, int flag, int argb, float shadow) {
int i = 0;
int n = 0;
float px = posX;
float py = posY;
do {
UINT16 chara = 0;
float offY = 0.0;
float offX = 0.0;
float nextCharSpace = 0.0;
float fontWidth = 0.0;
if (text[i] <= 0x7f) {
chara = text[i];
i += 1;
nextCharSpace += scale * 10.0;
fontWidth = 16.0;
}
else {
chara = (text[i] << 8) | text[i + 1];
i += 2;
nextCharSpace += scale * 16.0;
fontWidth = 19.0;
}
if (chara == ' ') {
px += scale * 10.0;
continue;
}
if (chara == '\n' || chara == '|') {
px = posX;
py += scale * 18.0;
continue;
}
// find font pos
int ii;
int find = 0;
for (ii = 0; ii < sizeof(table) / sizeof(UINT16); ii++) {
if (table[ii] == chara) {
find = 1;
break;
}
}
if (!find) {
ii = 0;
}
int fontPosX = ii % 32;
int fontPosY = ii / 32;
float pre = 6.0 - ((double)n - (shadow - 6.0));
if (pre > 0.0) {
switch (chara)
{
case 'O':
nextCharSpace += 2.0;
case 'g':
offY = 1.0;
break;
case 'm':
offX = 2.0;
nextCharSpace += 3.0;
case 't':
nextCharSpace += -2.0;
break;
default:
break;
}
float per = pre / 6.0;
if (per > 1.0) {
per = 1.0;
}
int a, r, g, b;
colorDivide(argb, &a, &r, &g, &b);
argb = colorCombine(a * per, r, g, b);
origRenderObj(px + offX, py + offY, scale * fontWidth, scale * 20.0, *fontShader, fontPosX * 32, fontPosY * 32, 32, 32, flag, argb);
}
px += scale + nextCharSpace;
n += 1;
} while (text[i]);
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD dwReason,
LPVOID lpReserved
)
{
if (DetourIsHelperProcess()) {
return TRUE;
}
if (dwReason == DLL_PROCESS_ATTACH)
{
AllocConsole();
freopen("CON", "w", stdout);
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)origDrawText, (PVOID)hookDrawText);
DetourTransactionCommit();
}
if (dwReason == DLL_PROCESS_DETACH)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourTransactionCommit();
}
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment