What's new

Solved Need help with shaders in dll (C++)

  • Thread starter MarsupialLizard
  • Start date
  • Views 490
Status
Not open for further replies.
M

MarsupialLizard

Enthusiast
Messages
47
Reaction score
20
Is it even possible to do this without C#? If so, can anyone help?

Here is the code, everytime I launch the xex I get a fatal crash.
Code:
#include "stdafx.h"
#include <stdio.h>
#include <string>
using std::string;
 
struct hudelem_color_t
{
byte r;
byte g;
byte b;
byte a;
};
 
struct hudelem_s
{
int type;                    // 0x00-0x04
float y;                      // 0x04-0x08
float x;                      // 0x08-0x0C
float z;                      // 0x0C-0x10
int targetEntNum;            // 0x10-0x14
float fontScale;              // 0x14-0x18
float fromFontScale;          // 0x18-0x1C
int fontScaleStartTime;      // 0x1C-0x20
int fontScaleTime;            // 0x20-0x24
int label;                    // 0x24-0x28
int font;                    // 0x28-0x2C
int alignOrg;                // 0x2C-0x30
int alignScreen;              // 0x30-0x34
hudelem_color_t color;        // 0x34-0x38
hudelem_color_t fromColor;    // 0x38-0x3C
int fadeStartTime;            // 0x3C-0x40
int fadeTime;                // 0x40-0x44
int height;                  // 0x44-0x48
int width;                    // 0x48-0x4C
int materialIndex;            // 0x4C-0x50
int fromHeight;              // 0x50-0x54
int fromWidth;                // 0x54-0x58
int scaleStartTime;          // 0x58-0x5C
int scaleTime;                // 0x5C-0x60
float fromY;                  // 0x60-0x64
float fromX;                  // 0x64-0x68
int fromAlignOrg;            // 0x68-0x6C
int fromAlignScreen;          // 0x6C-0x70
int moveStartTime;            // 0x70-0x74
int moveTime;                // 0x74-0x78
float value;                  // 0x78-0x7C
int time;                    // 0x7C-0x80
int duration;                // 0x80-0x84
int text;                    // 0x84-0x88
float sort;                  // 0x88-0x8C
hudelem_color_t glowColor;    // 0x8C-0x90
int fxBirthTime;              // 0x90-0x94
int fxLetterTime;            // 0x94-0x98
int fxDecayStartTime;        // 0x98-0x9C
int fxDecayDuration;          // 0x9C-0xA0
int soundID;                  // 0xA0-0xA4
int flags;                    // 0xA4-0xA8
};
 
struct game_hudelem_s
{
hudelem_s elem;              // 0x00-0xA8
int clientNum;                // 0xA8-0xAC
int teamNum;                  // 0xAC-0xB0
int archived;                // 0xB0-0xB4
};
 
typedef game_hudelem_s * (__cdecl * HudElem_Alloc_t)(int clietNum, int teamNum);
HudElem_Alloc_t HudElem_Alloc = (HudElem_Alloc_t)0x821DF9C0;
 
typedef int (__cdecl * G_LocalizedStringIndex_t)(const char * string);
G_LocalizedStringIndex_t G_LocalizedStringIndex = (G_LocalizedStringIndex_t)0x8220C838;
 
typedef int (__cdecl * G_MaterialIndex_t)(const char * name);
G_MaterialIndex_t G_MaterialIndex = (G_MaterialIndex_t)0x8220C9F8;
 
game_hudelem_s * spawnElem(int clientNum)
{
game_hudelem_s * elem = HudElem_Alloc(0, 0);
elem->clientNum = clientNum;
return elem;
}
 
void setText(game_hudelem_s * elem, const char * text, int font, float fontScale, float x, float y, int alignOrg, int alignScreen, float sort = 1, byte r = 255, byte g = 255, byte b = 255, byte a = 255)
{
elem->elem.type = 0x01;
elem->elem.alignOrg = alignOrg;
elem->elem.alignScreen = alignScreen;
elem->elem.font = font;
elem->elem.fontScale = fontScale;
elem->elem.x = x;
elem->elem.y = y;
elem->elem.color.r = r;
elem->elem.color.g = g;
elem->elem.color.b = b;
elem->elem.color.a = a;
elem->elem.sort = sort;
elem->elem.text = G_LocalizedStringIndex(text);
}
 
void setShader(game_hudelem_s * elem, const char * materialName, float x, float y, int width, int height, int alignOrg, int alignScreen, float sort = 0, byte r = 255, byte g = 255, byte b = 255, byte a = 255)
{
elem->elem.type = 0x04;
elem->elem.alignOrg = alignOrg;
elem->elem.alignScreen = alignScreen;
elem->elem.x = x;
elem->elem.y = y;
elem->elem.color.r = r;
elem->elem.color.g = g;
elem->elem.color.b = b;
elem->elem.color.a = a;
elem->elem.width = width;
elem->elem.height = height;
elem->elem.sort = sort;
elem->elem.materialIndex = G_MaterialIndex(materialName);
}
 
typedef void (*SV_GameSendServerCommand_t)(int clientNum, int type, const char *text);
SV_GameSendServerCommand_t SV = (SV_GameSendServerCommand_t)0x822548C8;
typedef int (*Key_IsDown)(int ClientNum, int ButtonEnum);
Key_IsDown button_Pressed = (Key_IsDown)0x82141308;
typedef bool (*Dvar_GetBool_t)(const char *dvarName);
Dvar_GetBool_t Dvar_GetBool = (Dvar_GetBool_t)0x8229EF58;
 
 
int RightStick()
{
    Key_IsDown Key_Down = (Key_IsDown)0x82141308;
    if (Key_Down(0,0x11))
    {
        return 1;
    }
    else
        return 0;
}
 
DWORD WINAPI commands(LPVOID)
{
       
 
        for(;;)
        {
            int rs = RightStick();
                       
            if (Dvar_GetBool("cl_ingame"))
            {
                if(rs == 1)
                {
                    setShader(0, "ac130_overlay_grain", 0x11, 0x06, 0x4A, 0x46, 0x2E, 0x32, 0x8A, 0, 0, 255, 150);
                   
                }
 
               
            }
            Sleep(100);
 
        }
        Sleep(100);
}

I have even tried it without setting putting setShader in the menu and it still crashes when i load the xex.
 
Last edited:
W

w159

Gold Record Host
Messages
4,987
Reaction score
3,161
Is it a default_mp issue or does the default_mp load without it? BTW those hudelem shaders don't work to well if you plan on using that online.
 
M

MarsupialLizard

Enthusiast
Messages
47
Reaction score
20
Is it a default_mp issue or does the default_mp load without it? BTW those hudelem shaders don't work to well if you plan on using that online.
Im guessing it might be a problem with the xex, it loads other dlls just fine, but if i try to load a dll with shaders it will crash before loading the game.
Also, what kind of shaders (if any) would work good online?
 
Last edited:
W

w159

Gold Record Host
Messages
4,987
Reaction score
3,161
Ive been using some of the menus already made. Only just began giving making my own a shot.
 
M

MarsupialLizard

Enthusiast
Messages
47
Reaction score
20
Ive been using some of the menus already made. Only just began giving making my own a shot.
Same here, its easy to make one with just different colored text. But shaders make the menu look so nice.
 
I

ImJtagModz

Well Known JTAG
Messages
1,455
Reaction score
660
lol. your thinking too deep. the reason for thuis not working is because look at the first paramater in the setShader.

instead of using a actual hudelem hes just put 0 meaning it wont work. to Fix Do This

There. done :smile:
if(rs == 1)
{
setShader(spawnElem(0), "ac130_overlay_grain", 0x11, 0x06, 0x4A, 0x46, 0x2E, 0x32, 0x8A, 0, 0, 255, 150);

{
 
M

MarsupialLizard

Enthusiast
Messages
47
Reaction score
20
lol. your thinking too deep. the reason for thuis not working is because look at the first paramater in the setShader.

instead of using a actual hudelem hes just put 0 meaning it wont work. to Fix Do This

There. done :smile:
if(rs == 1)
{
setShader(spawnElem(0), "ac130_overlay_grain", 0x11, 0x06, 0x4A, 0x46, 0x2E, 0x32, 0x8A, 0, 0, 255, 150);

{
I got it working. The main problem was that I was using a default patched to TU7 with TU8 offsets in my dll :rolleyes: but this was the second problem.
Anyways thanks for everyone that helped.
 
Status
Not open for further replies.
Top Bottom