AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [CSGO] Doing stuff with TheNavAreas and navarea_count (https://forums.alliedmods.net/showthread.php?t=305236)

Pelipoika 02-12-2018 12:17

[CSGO] Doing stuff with TheNavAreas and navarea_count
 
Gamedata

Code:

"Games"
{
        "csgo"
        {
                "Addresses"
                {
                        "navarea_count"
                        {
                                "windows"
                                {
                                        "signature" "nav_update_lighting"
                                        "read" "92"
                                }
                                "linux"
                                {
                                        "signature" "nav_update_lighting"
                                        "read" "18"
                                }
                        }
                }
                "Signatures"
                {
                        "nav_update_lighting"        //nav_update_lighting(CCommand const&) | STR "Computed lighting for %d/%d areas\n"
                        {
                                "windows"        "\x55\x8B\xEC\x8B\x45\x08\x57\x33\xFF"
                                "linux"                "\x55\x89\xE5\x56\x53\x83\xEC\x10\x8B\x45\x08\x83\x38\x02"
                        }
                }
        }
}

Plugin
PHP Code:

Address TheNavAreas;
Address navarea_count;

//You want to do this in OnMapStart or else after a map change you will have a bad address
public void OnMapStart()
{
    
Handle hConf LoadGameConfigFile("yourgamedata.txt");
    
    
navarea_count GameConfGetAddress(hConf"navarea_count");
    
PrintToServer("Found \"navarea_count\" @ 0x%X"navarea_count);
    
    
//TheNavAreas is nicely above navarea_count
    
TheNavAreas view_as<Address>(LoadFromAddress(navarea_count view_as<Address>(0x4), NumberType_Int32));
    
PrintToServer("Found \"TheNavAreas\" @ 0x%X"TheNavAreas);
    
    
delete hConf;


Useful things you may do with this
PHP Code:

//Get areas that are bigger than 50 units wide and maybe spawn stuff on them
//Say you were making a hunger games gamemode or a true random spawns deathmatch mode, 
//you could use this to always have a truly random spawn for your player or hunger games loot.
//Yes this is the exact code CS:GO uses to keep the map populated with chickens

void DoStuff()
{
    
int iAreaCount LoadFromAddress(navarea_countNumberType_Int32);

    
int iValidAreaCount 0;
    
    
//Check that this map has any nav areas
    
if ( iAreaCount )
    {
        
//Get a random area 10 times
        
for (int i 0<= 10i++)
        {
            
//Get random area
            
Address RandomArea view_as<Address>(LoadFromAddress(TheNavAreas view_as<Address>(GetRandomInt(0iAreaCount 1)), NumberType_Int32));
            
            
float m_nwCorner[3];
            
m_nwCorner[0] = view_as<float>(LoadFromAddress(RandomArea view_as<Address>(4), NumberType_Int32));
            
m_nwCorner[1] = view_as<float>(LoadFromAddress(RandomArea view_as<Address>(8), NumberType_Int32));
            
m_nwCorner[2] = view_as<float>(LoadFromAddress(RandomArea view_as<Address>(12), NumberType_Int32));
            
            
float m_seCorner[3];
            
m_seCorner[0] = view_as<float>(LoadFromAddress(RandomArea view_as<Address>(16), NumberType_Int32));
            
m_seCorner[1] = view_as<float>(LoadFromAddress(RandomArea view_as<Address>(20), NumberType_Int32));
            
m_seCorner[2] = view_as<float>(LoadFromAddress(RandomArea view_as<Address>(24), NumberType_Int32));
            
            
//Check that the area is bigger than 50 units wide on both sides.
            
if((m_seCorner[0] - m_nwCorner[0]) <= 50.0)
                continue;
            
            if((
m_seCorner[1] - m_nwCorner[1]) <= 50.0)
                continue;
            
            
//Calculate area center position.
            
float vecPos[3];
            
AddVectors(m_nwCornerm_seCornervecPos);
            
ScaleVector(vecPos0.5);
            
            
//Check if any player can see this place
            
if(UTIL_IsVisibleToTeam(vecPos2))
                continue;
            
            if(
UTIL_IsVisibleToTeam(vecPos3))
                continue;
            
            
CreateEntity(vecPos);
            
iValidAreaCount++;
        }
    }
}

stock bool UTIL_IsVisibleToTeam(float vecPos[3], int team)
{
    for (
int i 1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i))
            continue;
            
        if(!
IsPlayerAlive(i))
            continue;
            
        if(
GetClientTeam(i) != team)
            continue;
        
        if(!
IsLineOfFireClear(vecPosGetEyePosition(i)))
            continue;
            
        return 
true;
    }
    
    return 
false;
}

stock bool IsLineOfFireClear(float from[3], float to[3])
{
    
Handle trace TR_TraceRayFilterEx(fromtoCONTENTS_SOLID|CONTENTS_MOVEABLE|0x40|CONTENTS_MONSTERRayType_EndPointFilterPlayers);
    
    
float flFraction TR_GetFraction(trace);
    
    
delete trace;
    
    if (
flFraction >= 1.0/* && !trace.allsolid*/
    {
        return !(
flFraction == 0.0);    //allsolid
    
}
    
    return 
false;


WINDOWS Gamedata has been tested and confirmed working
LINUX Gamedata also works according to Rachnus

Franc1sco 02-12-2018 13:13

Re: [CSGO] Doing stuff with TheNavAreas and navarea_count
 
Nice work!

8guawong 02-16-2018 09:55

Re: [CSGO] Doing stuff with TheNavAreas and navarea_count
 
awesome~

8guawong 07-18-2018 13:25

Re: [CSGO] Doing stuff with TheNavAreas and navarea_count
 
Code:

L 07/18/2018 - 10:13:57: Info (map "de_dust2") (file "errors_20180718.log")
L 07/18/2018 - 10:13:57: [SM] Exception reported: Invalid address 0x4 is pointing to reserved memory.
L 07/18/2018 - 10:13:57: [SM] Blaming: test.smx
L 07/18/2018 - 10:13:57: [SM] Call stack trace:
L 07/18/2018 - 10:13:57: [SM]  [0] LoadFromAddress
L 07/18/2018 - 10:13:57: [SM]  [1] Line 43, C:\Users\test\sm 1.8\test.sp::OnMapStart
L 07/18/2018 - 10:14:03: Error log file session closed.

whats wrong?

hmmmmm 07-18-2018 14:35

Re: [CSGO] Doing stuff with TheNavAreas and navarea_count
 
PHP Code:

navarea_count GameConfGetAddress(hConf"navarea_count"); 

This is returning 0, which is not a valid address. This could be because it failed to read the gamedata or because the gamedata is outdated.

Pelipoika 07-18-2018 18:53

Re: [CSGO] Doing stuff with TheNavAreas and navarea_count
 
Quote:

Originally Posted by hmmmmm (Post 2604585)
PHP Code:

navarea_count GameConfGetAddress(hConf"navarea_count"); 

This is returning 0, which is not a valid address. This could be because it failed to read the gamedata or because the gamedata is outdated.

Nice OS

EDIT:
Still works fine on Windows 19.07.2018

8guawong 07-23-2018 21:25

Re: [CSGO] Doing stuff with TheNavAreas and navarea_count
 
Quote:

Originally Posted by Pelipoika (Post 2604681)
Nice OS

EDIT:
Still works fine on Windows 19.07.2018

still can't get it to work

Code:

Found "navarea_count" @ 0x0
L 07/23/2018 - 18:23:44: [SM] Exception reported: Invalid address 0x4 is pointing to reserved memory.
L 07/23/2018 - 18:23:44: [SM] Blaming: test.smx
L 07/23/2018 - 18:23:44: [SM] Call stack trace:
L 07/23/2018 - 18:23:44: [SM]  [0] LoadFromAddress
L 07/23/2018 - 18:23:44: [SM]  [1] Line 13, C:\Users\test\Dropbox\sm 1.8\test.sp::OnMapStart
[SM] Loaded plugin test.smx successfully.
 
 
 SourceMod Version Information:
    SourceMod Version: 1.9.0.6245
    SourcePawn Engine: 1.9.0.6245, jit-x86 (build 1.9.0.6245)
    SourcePawn API: v1 = 4, v2 = 12
    Compiled on: Jul 13 2018 04:50:03
    Built from: https://github.com/alliedmodders/sourcemod/commit/50b5bb19
    Build ID: 6245:50b5bb19
    http://www.sourcemod.net/
 
 
Metamod:Source version 1.10.7-dev
Built from: https://github.com/alliedmodders/metamod-source/commit/20c72b5
Build ID: 963:20c72b5
Loaded As: Valve Server Plugin
Compiled on: Jul  7 2018
Plugin interface version: 15:14
SourceHook version: 5:5
http://www.metamodsource.net/

PHP Code:

Address TheNavAreas;
Address navarea_count;

//You want to do this in OnMapStart or else after a map change you will have a bad address
public void OnMapStart()
{
    
Handle hConf LoadGameConfigFile("yourgamedata");
    
    
navarea_count GameConfGetAddress(hConf"navarea_count");
    
PrintToServer("Found \"navarea_count\" @ 0x%X"navarea_count);
    
    
//TheNavAreas is nicely above navarea_count
    
TheNavAreas view_as<Address>(LoadFromAddress(navarea_count view_as<Address>(0x4), NumberType_Int32));
    
PrintToServer("Found \"TheNavAreas\" @ 0x%X"TheNavAreas);
    
    
delete hConf;



Pelipoika 07-23-2018 21:50

Re: [CSGO] Doing stuff with TheNavAreas and navarea_count
 
Quote:

Originally Posted by 8guawong (Post 2605760)
still can't get it to work

Sooo... linux?

I've never tested Linux but try "read 17" instead of "read 18"

8guawong 07-23-2018 22:10

Re: [CSGO] Doing stuff with TheNavAreas and navarea_count
 
Quote:

Originally Posted by Pelipoika (Post 2605762)
Sooo... linux?

I've never tested Linux but try "read 17" instead of "read 18"

well i'm pretty sure the server is running windows....

162.251.167.84:27019 is the server in question

hostname: [BM] Zombie Riot RPG
version : 1.36.4.2 secure
os : Windows
type : community dedicated
gotv[0]: port 27219, delay 30.0s, rate 32.0

Pelipoika 07-23-2018 22:18

Re: [CSGO] Doing stuff with TheNavAreas and navarea_count
 
Quote:

Originally Posted by 8guawong (Post 2605765)
well i'm pretty sure the server is running windows....

162.251.167.84:27019 is the server in question

hostname: [BM] Zombie Riot RPG
version : 1.36.4.2 secure
os : Windows
type : community dedicated
gotv[0]: port 27219, delay 30.0s, rate 32.0

Does that happen instantly when you load the plugin?
Does that happen after a map change?
Does the map have a navmesh?


All times are GMT -4. The time now is 19:48.

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