PDA

View Full Version : Cant call anything in hooked HudUpdate



xmy
11-19-2010, 07:47 AM
Hey guys, i finally learned to hook functions.
I tried to hook the HudUpdate function, and it works.

But if i want to use my ISurface Variable i get with "CreateInterface" it thinks that this variable is NULL. Does someone have a clue why?

That's my Init Code:


AllocConsole();
console = (HANDLE)GetStdHandle(STD_OUTPUT_HANDLE);

while(!hmEngine) hmEngine = GetModuleHandle( "engine.dll" );
while(!hmCvar) hmCvar = GetModuleHandle( "vstdlib.dll");
while(!hmClient) hmClient = GetModuleHandle( "client.dll" );
while(!hmVgui) hmVgui = GetModuleHandle( "vgui2.dll" );
while(!hmatsurface) hmatsurface = GetModuleHandle( "vguimatsurface.dll" );
while(!vgui_factory) vgui_factory = ( CreateInterfaceFn ) GetProcAddress( hmVgui,"CreateInterface");
while(!mat_factory) mat_factory = ( CreateInterfaceFn ) GetProcAddress( hmatsurface,"CreateInterface");
while(!pfnEngine) pfnEngine = ( CreateInterfaceFn ) GetProcAddress( hmEngine, "CreateInterface" );
while(!pfncvar) pfncvar = ( CreateInterfaceFn ) GetProcAddress( hmCvar, "CreateInterface" );
while(!g_ClientFactory) g_ClientFactory = ( CreateInterfaceFn ) GetProcAddress( hmClient, "CreateInterface" );
BaseClient = ( IBaseClientDLL* ) g_ClientFactory( CLIENT_DLL_INTERFACE_VERSION, NULL );
Panel = ( vgui::IPanel* )vgui_factory(VGUI_PANEL_INTERFACE_VERSION, NULL);
Surface = ( vgui::ISurface* )mat_factory(VGUI_SURFACE_INTERFACE_VERSION, NULL);
ToConsole("hmvgui: %p vgui_factory: %p Surface: %p\n", hmVgui, vgui_factory, Surface);
MaterialSurface = ( IMatSystemSurface* )Surface->QueryInterface(MAT_SYSTEM_SURFACE_INTERFACE_VERSION);
ToConsole("hmvgui: %p vgui_factory: %p Surface: %p\n", hmVgui, vgui_factory, Surface);

// Surface is not NULL here.

EngineTrace = ( IEngineTrace* ) pfnEngine( INTERFACEVERSION_ENGINETRACE_CLIENT, NULL );
EngineClient = ( IVEngineClient* ) pfnEngine( VENGINE_CLIENT_INTERFACE_VERSION, NULL );
ModelInfoClient = ( IVModelInfoClient* )pfnEngine( VMODELINFO_CLIENT_INTERFACE_VERSION, NULL );
ClientEntlist = ( IClientEntityList* ) g_ClientFactory( VCLIENTENTITYLIST_INTERFACE_VERSION, NULL );
Cvar = ( ICvar * )pfncvar("VEngineCvar004", NULL);
vgui::HFont font = Surface->CreateFont();
Surface->SetFontGlyphSet( font, "Tahoma",11, 450, 0, 0, 0x200 );

// Hooking Part
unsigned long * BaseClientCpy = NULL;
memcpy(&BaseClientCpy, (void*)BaseClient, sizeof(IBaseClientDLL));
up = (new_HudUpdate_ty)DetourFunction((unsigned char*)BaseClientCpy[9], (unsigned char*)new_HudUpdate);

Cvar->ConsolePrintf("Loaded");
ToConsole("Loaded");


Here is the typedef and the function:



typedef void (__stdcall *new_HudUpdate_ty)(bool);
new_HudUpdate_ty up = NULL;
void __stdcall new_HudUpdate(bool bActive)
{

if(Surface){ CSS::ToConsole("Yes"); } else { CSS::ToConsole("No"); CSS::ToConsole("hmvgui: %p vgui_factory: %p Surface: %p\n", hmVgui, vgui_factory, Surface);}

}

//Surface is NULL here.


If i reinit the Surface variable in the hooked HudUpdate, Surface is not NULL but i can't draw on it.
I don't see anything in Css then.

Greetings

lilneo
11-20-2010, 08:35 PM
Just a shot in the dark, as I don't see anything wrong with your code. But you could be getting it from the wrong dll, did that a few times. And just to confirm, your hudupdate is index 9 right? (I'm doing same thing, just an aimbot)
~lilneo

xmy
11-21-2010, 05:44 AM
Dll Should be right, HudUpdate is 9, yes.

hellhound1337
11-21-2010, 08:06 AM
Just a shot in the dark, as I don't see anything wrong with your code. But you could be getting it from the wrong dll, did that a few times. And just to confirm, your hudupdate is index 9 right? (I'm doing same thing, just an aimbot)
~lilneo

from this i undestood you call your FindTarget in HUD_Update .. why?

kolbybrooks
11-21-2010, 05:47 PM
Don't try calling ISurface functions in HudUpdate, You'll be disappointed. Just create your own panel.

xmy
11-22-2010, 10:29 AM
Allright, i will ;)

Thanks

syntroniks
11-22-2010, 02:18 PM
Be cautious -- when my panel attempted to use g_pVGuiSurface to paint itself, it crashed. (I inserted no code -- I had inherited from vgui::Frame IIRC.)

Kolby -- I've heard you or someone else has had no vgui problems at all. I can get a surface interface from the vgui factory, except DrawSetColor (a VERY basic function) results in a crash. Yes I've debugged it, yes I've tried calling other functions. Can you lend a hand?

kolbybrooks
11-22-2010, 04:17 PM
Getting ISurface to draw with..


vgui::ISurface *g_Surface;

...
CreateInterfaceFn MatSurfaceFn = GetFactory("vguimatsurface.dll");
...
g_Surface = GetInterface<vgui::ISurface*>( MatSurfaceFn, VGUI_SURFACE_INTERFACE_VERSION );


Generic Initialize..


static BOOL InitOnce = FALSE;

if (InitOnce == FALSE)
{
MathLib_Init();

ConnectTier1Libraries(&g_appSystemFactory, 1);
ConnectTier2Libraries(&g_appSystemFactory, 1);
ConnectTier3Libraries(&g_appSystemFactory, 1);

if (vgui::VGui_InitInterfacesList("dScreen", &g_appSystemFactory, 1))
DPanel = new dPanel(g_EngineVgui->GetPanel(PANEL_INGAMESCREENS));

InitOnce = TRUE;
}


My panel class..


class dPanel : public vgui::Panel
{
dPanel(vgui::VPANEL parent);

virtual void Paint(void);
}

...

dPanel::dPanel(vgui::VPANEL parent) : vgui::Panel(NULL, "dPanel")
{
SetParent(parent);
SetPos(0, 0);
SetVisible(true);
SetCursor(NULL);
}


The ISurface class I'm using


class ISurface : public IAppSystem
{
public:
// call to Shutdown surface; surface can no longer be used after this is called
virtual void Shutdown() = 0;

// frame
virtual void RunFrame() = 0;

// hierarchy root
virtual VPANEL GetEmbeddedPanel() = 0;
virtual void SetEmbeddedPanel( VPANEL pPanel ) = 0;

// drawing context
virtual void PushMakeCurrent(VPANEL panel, bool useInsets) = 0;
virtual void PopMakeCurrent(VPANEL panel) = 0;

// rendering functions
virtual void DrawSetColor(int r, int g, int b, int a) = 0;
virtual void DrawSetColor(Color col) = 0;

virtual void DrawFilledRect(int x0, int y0, int x1, int y1) = 0;
virtual void DrawFilledRectArray( IntRect *pRects, int numRects ) = 0;
virtual void DrawOutlinedRect(int x0, int y0, int x1, int y1) = 0;

virtual void DrawLine(int x0, int y0, int x1, int y1) = 0;
virtual void DrawPolyLine(int *px, int *py, int numPoints) = 0;

virtual void DrawSetTextFont(HFont font) = 0;
virtual void DrawSetTextColor(int r, int g, int b, int a) = 0;
virtual void DrawSetTextColor(Color col) = 0;
virtual void DrawSetTextPos(int x, int y) = 0;
virtual void DrawGetTextPos(int& x,int& y) = 0;
virtual void DrawPrintText(const wchar_t *text, int textLen, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
virtual void DrawUnicodeChar(wchar_t wch, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;

virtual void DrawFlushText() = 0; // flushes any buffered text (for rendering optimizations)
virtual IHTML *CreateHTMLWindow(vgui::IHTMLEvents *events,VPANEL context)=0;
virtual void PaintHTMLWindow(vgui::IHTML *htmlwin) =0;
virtual void DeleteHTMLWindow(IHTML *htmlwin)=0;

virtual int DrawGetTextureId( char const *filename ) = 0;
virtual bool DrawGetTextureFile(int id, char *filename, int maxlen ) = 0;
virtual void DrawSetTextureFile(int id, const char *filename, int hardwareFilter, bool forceReload) = 0;
virtual void DrawSetTextureRGBA(int id, const unsigned char *rgba, int wide, int tall, int hardwareFilter, bool forceReload)=0;
virtual void DrawSetTexture(int id) = 0;
virtual void DrawGetTextureSize(int id, int &wide, int &tall) = 0;
virtual void DrawTexturedRect(int x0, int y0, int x1, int y1) = 0;
virtual bool IsTextureIDValid(int id) = 0;

virtual int CreateNewTextureID( bool procedural = false ) = 0;
#ifdef _X360
virtual void DestroyTextureID( int id ) = 0;
virtual void UncacheUnusedMaterials() = 0;
#endif

virtual void GetScreenSize(int &wide, int &tall) = 0;
virtual void SetAsTopMost(VPANEL panel, bool state) = 0;
virtual void BringToFront(VPANEL panel) = 0;
virtual void SetForegroundWindow (VPANEL panel) = 0;
virtual void SetPanelVisible(VPANEL panel, bool state) = 0;
virtual void SetMinimized(VPANEL panel, bool state) = 0;
virtual bool IsMinimized(VPANEL panel) = 0;
virtual void FlashWindow(VPANEL panel, bool state) = 0;
virtual void SetTitle(VPANEL panel, const wchar_t *title) = 0;
virtual void SetAsToolBar(VPANEL panel, bool state) = 0; // removes the window's task bar entry (for context menu's, etc.)

// windows stuff
virtual void CreatePopup(VPANEL panel, bool minimised, bool showTaskbarIcon = true, bool disabled = false, bool mouseInput = true , bool kbInput = true) = 0;
virtual void SwapBuffers(VPANEL panel) = 0;
virtual void Invalidate(VPANEL panel) = 0;
virtual void SetCursor(HCursor cursor) = 0;
virtual bool IsCursorVisible() = 0;
virtual void ApplyChanges() = 0;
virtual bool IsWithin(int x, int y) = 0;
virtual bool HasFocus() = 0;

// returns true if the surface supports minimize & maximize capabilities
enum SurfaceFeature_e
{
ANTIALIASED_FONTS = 1,
DROPSHADOW_FONTS = 2,
ESCAPE_KEY = 3,
OPENING_NEW_HTML_WINDOWS = 4,
FRAME_MINIMIZE_MAXIMIZE = 5,
OUTLINE_FONTS = 6,
DIRECT_HWND_RENDER = 7,
};
virtual bool SupportsFeature(SurfaceFeature_e feature) = 0;

// restricts what gets drawn to one panel and it's children
// currently only works in the game
virtual void RestrictPaintToSinglePanel(VPANEL panel) = 0;

// these two functions obselete, use IInput::SetAppModalSurface() instead
virtual void SetModalPanel(VPANEL ) = 0;
virtual VPANEL GetModalPanel() = 0;

virtual void UnlockCursor() = 0;
virtual void LockCursor() = 0;
virtual void SetTranslateExtendedKeys(bool state) = 0;
virtual VPANEL GetTopmostPopup() = 0;

// engine-only focus handling (replacing WM_FOCUS windows handling)
virtual void SetTopLevelFocus(VPANEL panel) = 0;

// fonts
// creates an empty handle to a vgui font. windows fonts can be add to this via SetFontGlyphSet().
virtual HFont CreateFont() = 0;

// adds to the font
enum EFontFlags
{
FONTFLAG_NONE,
FONTFLAG_ITALIC = 0x001,
FONTFLAG_UNDERLINE = 0x002,
FONTFLAG_STRIKEOUT = 0x004,
FONTFLAG_SYMBOL = 0x008,
FONTFLAG_ANTIALIAS = 0x010,
FONTFLAG_GAUSSIANBLUR = 0x020,
FONTFLAG_ROTARY = 0x040,
FONTFLAG_DROPSHADOW = 0x080,
FONTFLAG_ADDITIVE = 0x100,
FONTFLAG_OUTLINE = 0x200,
FONTFLAG_CUSTOM = 0x400, // custom generated font - never fall back to asian compatibility mode
FONTFLAG_BITMAP = 0x800, // compiled bitmap font - no fallbacks
};

virtual bool SetFontGlyphSet(HFont font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin = 0, int nRangeMax = 0) = 0;

// adds a custom font file (only supports true type font files (.ttf) for now)
virtual bool AddCustomFontFile(const char *fontFileName) = 0;

// returns the details about the font
virtual int GetFontTall(HFont font) = 0;
virtual int GetFontAscent(HFont font, wchar_t wch) = 0;
virtual bool IsFontAdditive(HFont font) = 0;
virtual void GetCharABCwide(HFont font, int ch, int &a, int &b, int &c) = 0;
virtual int GetCharacterWidth(HFont font, int ch) = 0;
virtual void GetTextSize(HFont font, const wchar_t *text, int &wide, int &tall) = 0;

// notify icons?!?
virtual VPANEL GetNotifyPanel() = 0;
virtual void SetNotifyIcon(VPANEL context, HTexture icon, VPANEL panelToReceiveMessages, const char *text) = 0;

// plays a sound
virtual void PlaySound(const char *fileName) = 0;

//!! these functions should not be accessed directly, but only through other vgui items
//!! need to move these to seperate interface
virtual int GetPopupCount() = 0;
virtual VPANEL GetPopup(int index) = 0;
virtual bool ShouldPaintChildPanel(VPANEL childPanel) = 0;
virtual bool RecreateContext(VPANEL panel) = 0;
virtual void AddPanel(VPANEL panel) = 0;
virtual void ReleasePanel(VPANEL panel) = 0;
virtual void MovePopupToFront(VPANEL panel) = 0;
virtual void MovePopupToBack(VPANEL panel) = 0;

virtual void SolveTraverse(VPANEL panel, bool forceApplySchemeSettings = false) = 0;
virtual void PaintTraverse(VPANEL panel) = 0;

virtual void EnableMouseCapture(VPANEL panel, bool state) = 0;

// returns the size of the workspace
virtual void GetWorkspaceBounds(int &x, int &y, int &wide, int &tall) = 0;

// gets the absolute coordinates of the screen (in windows space)
virtual void GetAbsoluteWindowBounds(int &x, int &y, int &wide, int &tall) = 0;

// gets the base resolution used in proportional mode
virtual void GetProportionalBase( int &width, int &height ) = 0;

virtual void CalculateMouseVisible() = 0;
virtual bool NeedKBInput() = 0;

virtual bool HasCursorPosFunctions() = 0;
virtual void SurfaceGetCursorPos(int &x, int &y) = 0;
virtual void SurfaceSetCursorPos(int x, int y) = 0;


// SRC only functions!!!
virtual void DrawTexturedLine( const Vertex_t &a, const Vertex_t &b ) = 0;
virtual void DrawOutlinedCircle(int x, int y, int radius, int segments) = 0;
virtual void DrawTexturedPolyLine( const Vertex_t *p,int n ) = 0; // (Note: this connects the first and last points).
virtual void DrawTexturedSubRect( int x0, int y0, int x1, int y1, float texs0, float text0, float texs1, float text1 ) = 0;
virtual void DrawTexturedPolygon(int n, Vertex_t *pVertices) = 0;
virtual const wchar_t *GetTitle(VPANEL panel) = 0;
virtual bool IsCursorLocked( void ) const = 0;
virtual void SetWorkspaceInsets( int left, int top, int right, int bottom ) = 0;

// Lower level char drawing code, call DrawGet then pass in info to DrawRender
virtual bool DrawGetUnicodeCharRenderInfo( wchar_t ch, CharRenderInfo& info ) = 0;
virtual void DrawRenderCharFromInfo( const CharRenderInfo& info ) = 0;

// global alpha setting functions
// affect all subsequent draw calls - shouldn't normally be used directly, only in Panel::PaintTraverse()
virtual void DrawSetAlphaMultiplier( float alpha /* [0..1] */ ) = 0;
virtual float DrawGetAlphaMultiplier() = 0;

// web browser
virtual void SetAllowHTMLJavaScript( bool state ) = 0;

// video mode changing
virtual void OnScreenSizeChanged( int nOldWidth, int nOldHeight ) = 0;

virtual vgui::HCursor CreateCursorFromFile( char const *curOrAniFile, char const *pPathID = 0 ) = 0;

// create IVguiMatInfo object ( IMaterial wrapper in VguiMatSurface, NULL in CWin32Surface )
virtual IVguiMatInfo *DrawGetTextureMatInfoFactory( int id ) = 0;

virtual void PaintTraverseEx(VPANEL panel, bool paintPopups = false ) = 0;

virtual float GetZPos() const = 0;

// From the Xbox
virtual void SetPanelForInput( VPANEL vpanel ) = 0;
virtual void DrawFilledRectFade( int x0, int y0, int x1, int y1, unsigned int alpha0, unsigned int alpha1, bool bHorizontal ) = 0;
virtual void DrawSetTextureRGBAEx(int id, const unsigned char *rgba, int wide, int tall, ImageFormat imageFormat ) = 0;
virtual void DrawSetTextScale(float sx, float sy) = 0;
virtual bool SetBitmapFontGlyphSet(HFont font, const char *windowsFontName, float scalex, float scaley, int flags) = 0;
// adds a bitmap font file
virtual bool AddBitmapFontFile(const char *fontFileName) = 0;
// sets a symbol for the bitmap font
virtual void SetBitmapFontName( const char *pName, const char *pFontFilename ) = 0;
// gets the bitmap font filename
virtual const char *GetBitmapFontName( const char *pName ) = 0;
virtual void ClearTemporaryFontCache( void ) = 0;

virtual IImage *GetIconImageForFullPath( char const *pFullPath ) = 0;
virtual void DrawUnicodeString( const wchar_t *pwString, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
virtual void PrecacheFontCharacters(HFont font, wchar_t *pCharacters) = 0;
// Console-only. Get the string to use for the current video mode for layout files.
virtual const char *GetResolutionKey( void ) const = 0;
};

...

#define VGUI_SURFACE_INTERFACE_VERSION "VGUI_Surface030"



Hope that helps..

syntroniks
11-22-2010, 04:25 PM
I'm sure it will -- do you link against the vanilla vgui_controls.lib that comes from valve or do you (re)build your own? I'll have another whack at this

kolbybrooks
11-22-2010, 05:58 PM
Vanilla, also make sure your project properties are correct and that you're including vgui_controls.cpp and memoverride.cpp into your project..

xmy
11-24-2010, 07:24 AM
Thank you!
It's great to see, that beginners get useful help here :)

greetings

wav
12-02-2010, 12:17 AM
You're likely smashing the contents of the registers.

xmy
12-02-2010, 05:35 AM
Well, after some researching i just hooked the EndScene and the IDirect3DDevice Pointer. Drawing works fine now :)