AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Extensions (https://forums.alliedmods.net/forumdisplay.php?f=134)
-   -   Left 4 Dead 2 - CreateSurvivorBot (https://forums.alliedmods.net/showthread.php?t=329183)

microleo 12-12-2020 07:43

Left 4 Dead 2 - CreateSurvivorBot
 
1 Attachment(s)
old version code:
PHP Code:

CreteSurvivorBot()
{
    
int bot =  CreateFakeClient("fake");
    
ChangeClientTeam(bot2);
    
KickClient(bot);
    
//the bot index is invalid. because bot was disconnected.
    //we can't write code, like that:
    
if(!IsPlayerAlive(bot))
    {
                 
//this is mistake, can't exec here
        //ba la ba la ...
    
}
}

public 
Action:OnClientPutInServer(int _iClientIndex)
{
    
//We need judgment this bot was created by we are
    
    //write code
    // ba la ba la ...


now. using my extensions.
PHP Code:

#include <CreateSurvivorBot>
int Test()
{
    
int index CreateSurvivorBot();
    if(
IsValidEntity(index))
    {
        
PrintToServer("Created SurvivorBot:%d"index);
        
//ba la ba la ... write code
        
return index;
    }
    return -
1;


inc file:
PHP Code:

#if defined _CreateSurvivorBot_included
 #endinput
#endif
#define _CreateSurvivorBot_included

enum TEAMNUMBER
{
    
TEAM_SPECTATOR 1,
    
TEAM_SURVIVORS,
    
TEAM_INFECTED
};

native int NextBotCreatePlayerBotSurvivorBot(const char[] _szName);

native bool HandleCommand_JoinTeam(int _iClientIndexTEAMNUMBER _iTeam,int _iSurvivorCharacterbool _bForcedJoinSurvivor);

native bool CTerrorPlayerRoundRespawn(int _iClientIndex);

stock int CreateSurvivorBot(bool _bForcedJoinSurvivor true)
{
    
int bot NextBotCreatePlayerBotSurvivorBot("");
    if(
IsValidEntity(bot))
    {
        if( 
HandleCommand_JoinTeam(botTEAM_SURVIVORS0_bForcedJoinSurvivor) )
        {
            if(!
IsPlayerAlive(bot))
            {
                
CTerrorPlayerRoundRespawn(bot);
            }
            return 
bot;
        }
    }
    return -
1;
}

#if !defined REQUIRE_EXTENSIONS
public __ext_rare_SetNTVOptional()
{
    
MarkNativeAsOptional("HandleCommand_JoinTeam");
    
MarkNativeAsOptional("NextBotCreatePlayerBotSurvivorBot");
    
MarkNativeAsOptional("CTerrorPlayerRoundRespawn");
}
#endif

/**
 * Do not edit below this line!
 */
public Extension __ext_CreateSurvivorBot =
{
    
name "CreateSurvivorBot",
    
file "CreateSurvivorBot.ext",
#if defined AUTOLOAD_EXTENSIONS
    
autoload 1,
#else
    
autoload 0,
#endif
#if defined REQUIRE_EXTENSIONS
    
required 1,
#else
    
required 0,
#endif
}; 

Game Signatures:
PHP Code:

"Games"
{
    
"left4dead2"
    
{
        
"Signatures"
        
{
            
/* IDA Tag:  */
            /* IDA Code:  */
            /* C++ Function:  */
            /* Search string:  */
            /* Windows signature:  */
            /* Finally:  */
            /* Version:  */
            /* 
            *    Where call this function: 
            *    
            */
            
"template"
            
{
                
"library"    ""
                "windows"    ""
                "linux"        "@"
            
}
            
            
/* IDA Tag:        CTerrorPlayer::HandleCommand_JoinTeam(int, SurvivorCharacterType, bool) */
            /* IDA Code:        int __cdecl CTerrorPlayer::HandleCommand_JoinTeam(CBaseEntity *a1, int a2, int a3, char a4) */
            /* C++ Function:    bool __thiscall CTerrorPlayer::HandleCommand_JoinTeam(CBaseEntity *_pEntity, int _iTeam, int _iSurvivorCharacter, bool _bForcedJoinSurvivorTeam) */
            /* Search string:     (SKIN) Survivor %s changed model from %s to %s via HandleCommand_JoinTeam */
            /* Windows signature:     55 8B EC 56 57 8B F1 E8 ?? ?? ?? ?? 8B 7D 08 3B C7 75 08 5F B0 01 5E 5D C2 0C 00 */
            /* Finally:         55 8B EC 56 57 8B F1 E8 ?? ?? ?? ?? 8B 7D 08 3B */
            /* Version:     2209 */
            /* 
            *    Where call this function: 
            *    CDirector::AddSurvivorBot(SurvivorCharacterType) 
            *    It's not explicit, virtual function: offset(2252)  (*(_DWORD *)v4 + 2252))(v4,2 * (v2 > 3) + 2,v2,0)
            */
            
"HandleCommand_JoinTeam"
            
{
                
"library"    "server"
                "windows"    "\x55\x8B\xEC\x56\x57\x8B\xF1\xE8****\x8B\x7D\x08\x3B"
                "linux"        "@_ZN13CTerrorPlayer22HandleCommand_JoinTeamEi21SurvivorCharacterTypeb"
            
}
            
            
/* IDA Tag:        NextBotCreatePlayerBot<SurvivorBot>(char const*) */
            /* IDA Code:        CBaseEntity* __cdecl NextBotCreatePlayerBot<SurvivorBot>(char *src)  */
            /*  C++ Function:    CBaseEntity* __cdecl NextBotCreatePlayerBotSurvivorBot(const char *src) */
            /* Search string:     CreatePlayerBot: Could not Instance() from the bot edict */
            /* Windows signature:     (so crazy->to long)55 8B EC 83 EC 28 A1 ?? ?? ?? ?? 33 C5 89 45 FC 56 57 8B 7D 08 68 ?? ?? ?? ?? E8 ?? ?? ?? ?? 8B 0D ?? ?? ?? ?? 8B 01 8B 90 DC 00 00 00 83 C4 04 57 FF D2 6A 00 8B F0 E8 ?? ?? ?? ?? 83 C4 04 85 F6 75 21 57 */
            /* Windows signature2:     33 C0 6A 00 68 FC ?? ?? ?? 68 ?? ?? ?? ?? 6A 00 50 E8 ?? ?? ?? ?? 8B F0 83 C4 14 85 F6 75 20 68 ?? ?? ?? ?? FF 15 */
            /*  Windows signature3:  E8 ?? ?? ?? ?? 83 C4 08 85 C0 74 1C 8B 10 8B 92  this  signature into <CDirector::AddSurvivorBot> */
            /* Finally:     33 C0 6A 00 68 FC (warning:0xFC may be change when next game version) */
            /* Version:     2209 */
            /* 
            *    Where call this function: 
            *    RestoreTransitionedSurvivorBots(void);    CDirector::AddSurvivorBot(SurvivorCharacterType)
            */
            
"NextBotCreatePlayerBot<SurvivorBot>"
            
{    
                
"library"    "server"
                "windows"    "\xE8****\x83\xC4\x08\x85\xC0\x74\x1C"
// (addr+5) + *(addr+1) = call function addr -> this  signature into <CDirector::AddSurvivorBot>
                
"linux"        "@_Z22NextBotCreatePlayerBotI11SurvivorBotEPT_PKc"
            
}
            
            
/* IDA Tag:          CTerrorPlayer::RoundRespawn(void) */
            /* IDA Code:          int __usercall CTerrorPlayer::RoundRespawn@<eax>(long double a1@<st0>, CTerrorPlayer *this) */
            /* C++ Function:      void* __thiscall  CTerrorPlayer::RoundRespawn(CBaseEntity*) */
            /* 
            *    Search string:      Through "playercontrolledzombies" to find function < CTerrorGameRules::HasPlayerControlledZombies > 
            *    function < CTerrorPlayer::RoundRespawn(void) > on the inside call the function < CTerrorGameRules::HasPlayerControlledZombies > 
            *    you need search this function < CTerrorGameRules::HasPlayerControlledZombies > ,  one by one for match linux's function < CTerrorPlayer::RoundRespawn(void) > 
            */
            /* Windows signature:      56 8B F1 E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 84 C0 75 07 8B CE E8 ?? ?? ?? ?? C6 86 75 3E 00 00 00 */
            /* Finally:      56 8B F1 E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 84 C0 75 */
            /* Version:      2209 */
            /* 
            *    Where call this function: 
            *    windows: 8B 06 8B 90 08 08 00 00 8B CE FF D2 B0 01 5E 5D C2 04 00 CC  < call edx > < edx = (*pEntity)+0x808 >  OllyDebug breakpoint
            */
            
"CTerrorPlayer::RoundRespawn"
            
{
                
"library"    "server"
                "windows"    "\x56\x8B\xF1\xE8****\xE8****\x84\xC0\x75"
                "linux"        "@_ZN13CTerrorPlayer12RoundRespawnEv"
            
}
        }
    }


Update 12/18/2020
For Windows:
Signature of NextBotCreatePlayerBot<SurvivorBot> changed.
The CreateSurvivorBot.ext.2.l4d2.dll changed.
The signature in the next version should not change. The premise is CDirector::AddSurvivorBot() function will not be modified by valve.


Game Version: 2209

build:
Visual Studio 2013

sdk:
amtl
sourcepawn-1.10-dev
metamod-source-1.11-dev
sourcemod-1.10-dev
hl2sdk-l4d2

if you need other version. you have to compile by yourself

microleo 12-12-2020 09:17

Re: Left 4 Dead 2 - CreateSurvivorBot
 
nothing

HarryPotter 12-14-2020 22:13

Re: Left 4 Dead 2 - CreateSurvivorBot
 
useful, thanks

E.4H 12-15-2020 08:17

Re: Left 4 Dead 2 - CreateSurvivorBot
 
Can you make a linux build file please?

Dragokas 12-16-2020 10:29

Re: Left 4 Dead 2 - CreateSurvivorBot
 
Quote:

Originally Posted by microleo
PHP Code:

    int bot =  CreateFakeClient("fake");
    
ChangeClientTeam(bot2);
    
KickClient(bot);
    
//the bot index is invalid. because bot was disconnected.
    //we can't write code, like that:
    
if(!IsPlayerAlive(bot)) 


So, why you kicking him? Surely, he can't be alive.
What's the practical difference of your extension comparing to:

PHP Code:

    int fakeclient CreateFakeClient("FakeClient")
    
    
// if entity is valid
    
if(fakeclient != 0)
    {
        
// move into survivor team
        
ChangeClientTeam(fakeclientTEAM_SURVIVORS)
        
        
// check if entity classname is survivorbot
        
if(DispatchKeyValue(fakeclient"classname""survivorbot") == true)
        {
            
// spawn the client
            
if(DispatchSpawn(fakeclient) == true)
            {
            }
        }
    } 


Spirit_12 12-16-2020 11:41

Re: Left 4 Dead 2 - CreateSurvivorBot
 
This seems completely backwards. Why use an extension for something as simple as this. Plus, using signatures which break with updates is not recommended for this.

HarryPotter 12-16-2020 23:25

Re: Left 4 Dead 2 - CreateSurvivorBot
 
I think the only benefit of this extension is
I can get the client id of survivor bot, instead of "FakeClient" id

For my example code,
PHP Code:

RegConsoleCmd("sm_join"JoinTeam"Spawn a bot and Attempt to join"); 

without ext.
Spoiler

with ext
Spoiler

Dragokas 12-17-2020 01:10

Re: Left 4 Dead 2 - CreateSurvivorBot
 
OMG, so difficult. My mind refuses to understand what is happening there.
Code:

int fakebot = FindBotToTakeOver(); //search fake bot again
Can you, please, show what is that?

HarryPotter 12-17-2020 06:11

Re: Left 4 Dead 2 - CreateSurvivorBot
 
Quote:

Originally Posted by Dragokas (Post 2729016)
OMG, so difficult. My mind refuses to understand what is happening there.
Code:

int fakebot = FindBotToTakeOver(); //search fake bot again
Can you, please, show what is that?

PHP Code:

int FindBotToTakeOver()
{
    for (
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i))
        {
            if (
IsFakeClient(i) && GetClientTeam(i)==TEAM_SURVIVORS && !HasIdlePlayer(i) && IsPlayerAlive(i))
                return 
i;
        }
    }
    return 
0;
}

bool HasIdlePlayer(int bot)
{
    if(
HasEntProp(botProp_Send"m_humanSpectatorUserID"))
    {
        
int client GetClientOfUserId(GetEntProp(botProp_Send"m_humanSpectatorUserID"));        
        if(
client && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client) && IsClientObserver(client))
        {
            return 
true;
        }
    }
    
    return 
false;



microleo 12-17-2020 23:21

Re: 左 4 死 2 - 创建幸存者机器人
 
Quote:

Originally Posted by Spirit_12 (Post 2728945)
This seems completely backwards. Why use an extension for something as simple as this. Plus, using signatures which break with updates is not recommended for this.

IF you build l4d2_multislots.smx. You'll know why I wrote this extension, i don't think that this simple.


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

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