Raised This Month: $32 Target: $400
 8% 

How to print to health using source-sdk-2013?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
verideth
Junior Member
Join Date: Jun 2016
Old 12-27-2016 , 15:49   How to print to health using source-sdk-2013?
Reply With Quote #1

Hey guys, I've recently gotten into gmod modding in C++ and am just wondering how I could print out my health to console.

So far, printing to console is working completely fine, and I have a lot of history with modding source engine and c++. But when I do something like this it crashes:
Here is my code

PHP Code:
#pragma once

#include <iostream>
#include <Windows.h>
#include "GarrysMod/Lua/Interface.h"
#include "GarrysMod/Lua/Types.h"
#include "GarrysMod/Lua/UserData.h"
#include "GarrysMod/Lua/LuaBase.h"
#include "cbase.h"

using namespace GarrysMod::Lua;

#define LOADINTERFACE(_module_, _version_, _out_) Sys_LoadInterface(_module_, _version_, NULL, reinterpret_cast<void**>(& _out_ ))

namespace GOGL
{
    
void GOGL_Print(const charmsg, ...)
    {
        
ConColorMsg(Color(2525245255), msg);
    }

    
int GOGL_HealthPrint()
    {
        
IClientEntityListentList = (IClientEntityList*)LOADINTERFACE("client.dll"VCLIENTENTITYLIST_INTERFACE_VERSIONentList);
        
IVEngineClienteng = (IVEngineClient*)LOADINTERFACE("engine.dll"VENGINE_CLIENT_INTERFACE_VERSION_13eng);
        
CBaseEntitybaseEnt = (CBaseEntity*)entList->GetClientEntity(eng->GetLocalPlayer());

        
GOGL::GOGL_Print("%i\n"baseEnt->GetHealth());

        return 
1;
    }

It causes an error, and that error is (from visual studios 2013 debugger):

PHP Code:
First-chance exception at 0x359C1303 (gmcl_gogl5_win32.dllin hl2.exe0xC0000005Access violation reading location 0x00000001
It should be working, but its obviously not. Thanks! All helps appreciated!
__________________
Love programming!
Add me if you need any help http://steamcommunity.com/id/desslian/
verideth is offline
verideth
Junior Member
Join Date: Jun 2016
Old 12-27-2016 , 16:19   Re: How to print to health using source-sdk-2013?
Reply With Quote #2

UPDATE:

I just checked to see if entList and eng are nullptr. They are not. This is very strange.
__________________
Love programming!
Add me if you need any help http://steamcommunity.com/id/desslian/
verideth is offline
psychonic

BAFFLED
Join Date: May 2008
Old 12-27-2016 , 20:36   Re: How to print to health using source-sdk-2013?
Reply With Quote #3

Garry's Mod probably doesn't match the 2013 SDK close enough for what you're doing.

"Access violation reading location 0x00000001."

One of the functions you're calling is probably not the function you're expecting it to be, and returning 1/true instead of a pointer, so not NULL, but not what you want either.
psychonic is offline
verideth
Junior Member
Join Date: Jun 2016
Old 12-27-2016 , 22:53   Re: How to print to health using source-sdk-2013?
Reply With Quote #4

Quote:
Originally Posted by psychonic View Post
Garry's Mod probably doesn't match the 2013 SDK close enough for what you're doing.

"Access violation reading location 0x00000001."

One of the functions you're calling is probably not the function you're expecting it to be, and returning 1/true instead of a pointer, so not NULL, but not what you want either.
Yea, I've heard it uses the 2007 SDK. Maybe I should use that?
__________________
Love programming!
Add me if you need any help http://steamcommunity.com/id/desslian/
verideth is offline
verideth
Junior Member
Join Date: Jun 2016
Old 12-28-2016 , 01:04   Re: How to print to health using source-sdk-2013?
Reply With Quote #5

UPDATE:

I changed my function to
PHP Code:
        IVEngineServerengine = (IVEngineServer*)LOADINTERFACE("engine"INTERFACEVERSION_VENGINESERVERengine);

        
GOGL::GOGL_Print("%i\n"engine->GetServerTime()); 
I'm using hl2sdk. You're right, I think the function is different from gmod, which isn't good. What would you recommend?

(This is also not working, once again returning 0x1)
__________________
Love programming!
Add me if you need any help http://steamcommunity.com/id/desslian/
verideth is offline
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 12-28-2016 , 01:55   Re: How to print to health using source-sdk-2013?
Reply With Quote #6

Quote:
Originally Posted by verideth View Post
UPDATE:

I changed my function to
PHP Code:
        IVEngineServerengine = (IVEngineServer*)LOADINTERFACE("engine"INTERFACEVERSION_VENGINESERVERengine);

        
GOGL::GOGL_Print("%i\n"engine->GetServerTime()); 
I'm using hl2sdk. You're right, I think the function is different from gmod, which isn't good. What would you recommend?

(This is also not working, once again returning 0x1)
PHP Code:
bool loaded = !!(LOADINTERFACE("engine.dll"VENGINE_CLIENT_INTERFACE_VERSION_13engine));
if (
loaded)
    
GOGL::GOGL_Print("%i\n"engine->GetServerTime()); 
KyleS is offline
psychonic

BAFFLED
Join Date: May 2008
Old 12-28-2016 , 07:55   Re: How to print to health using source-sdk-2013?
Reply With Quote #7

Quote:
Originally Posted by verideth View Post
Yea, I've heard it uses the 2007 SDK. Maybe I should use that?
It doesn't use either of them. It would be closer to 2013. The engine headers may be close enough, but server classes like C_BaseEntity, etc. are not going to be near matching. You'd have to reverse it on your own.
psychonic is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode