From f0516a9467adf49a1ebf01b59f5491e5d642fb1d Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Sun, 22 Oct 2023 17:08:53 +0800 Subject: [PATCH] [bot] Add few CNetGame stubs --- bot/bot.vcproj | 12 ++++ bot/main.cpp | 46 +++++++++++- bot/main.h | 8 +++ bot/net/netgame.cpp | 165 ++++++++++++++++++++++++++++++++++++++++++++ bot/net/netgame.h | 55 +++++++++++++++ 5 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 bot/net/netgame.cpp create mode 100644 bot/net/netgame.h diff --git a/bot/bot.vcproj b/bot/bot.vcproj index 17532db..42b4eed 100644 --- a/bot/bot.vcproj +++ b/bot/bot.vcproj @@ -31,6 +31,7 @@ Name="VCCustomBuildTool"/> + + + + + + diff --git a/bot/main.cpp b/bot/main.cpp index 0f1c2e2..fc084d4 100644 --- a/bot/main.cpp +++ b/bot/main.cpp @@ -2,6 +2,7 @@ #include "main.h" GAME_SETTINGS tSettings; +CNetGame *pNetGame=0; void InitSettingsFromCommandLine(char * szCmdLine); @@ -16,8 +17,11 @@ void InitSettingsFromCommandLine(char * szCmdLine); -n -> NPC's name -m -> script name */ +// Absolutely no indication it is named npc or bot... int main (int argc, char** argv) { + logprintf("----- NPC Starting -----"); + char szCmdLine[1024]; memset(szCmdLine,0,1024); @@ -31,14 +35,54 @@ int main (int argc, char** argv) } InitSettingsFromCommandLine(szCmdLine); + pNetGame = new CNetGame(); + pNetGame->Init(tSettings.szConnectHost,atoi(tSettings.szConnectPort), + tSettings.szNickName,tSettings.szConnectPass,tSettings.szModeName); + +#ifdef WIN32 + timeBeginPeriod(5); +#endif + // TODO: main - // Absolutely no indication it is named npc or bot... + + while(1) { + pNetGame->Process(); + SLEEP(5); + + /* + v5 = sub_80AC1DC(pNetGame); + if(sub_80AC1E6(pNetGame) == 2 || + !(unsigned __int8)(*(int (__cdecl **)(int))(*(_DWORD *)v5 + 76))(v5)) + break; + */ + } + + delete pNetGame; + + logprintf("----- NPC: End -----"); return 0; } //---------------------------------------------------- +void logprintf(char* format, ...) +{ + va_list ap; + va_start(ap, format); + + char buffer[2048]; + vsprintf(buffer, format, ap); + +#ifdef WIN32 + OutputDebugString(buffer); +#endif + + va_end(ap); +} + +//---------------------------------------------------- + void SetStringFromCommandLine(char* szCmdLine, char* szString); void InitSettingsFromCommandLine(char * szCmdLine) diff --git a/bot/main.h b/bot/main.h index 76479dd..a5e26b2 100644 --- a/bot/main.h +++ b/bot/main.h @@ -2,9 +2,14 @@ #ifdef WIN32 #define WIN32_LEAN_AND_MEAN + #define SLEEP(x) { Sleep(x); } #include + #include #else + #define SLEEP(x) { usleep(x * 1000); } + + #include #endif #define MAX_SETTINGS_STRING 256 @@ -20,3 +25,6 @@ typedef struct _GAME_SETTINGS { #include #include +#include "net/netgame.h" + +void logprintf(char* format, ...); diff --git a/bot/net/netgame.cpp b/bot/net/netgame.cpp new file mode 100644 index 0000000..351e3ae --- /dev/null +++ b/bot/net/netgame.cpp @@ -0,0 +1,165 @@ + +#include "../main.h" + +//---------------------------------------------------- + +CNetGame::CNetGame() +{ + +} + +//---------------------------------------------------- + +CNetGame::~CNetGame() +{ + // TODO: ~CNetGame (W: 00416D50 L: 080ACFDE) + /* + (*(void (__cdecl **)(int, _DWORD, _DWORD))(*(_DWORD *)this->field_0 + 12))(this->field_0, 0, 0); + sub_80B1B18(this->field_0); + sub_80B7942(this->field_0); + sub_80712C8(this->field_0); + if ( this->field_386 ) + { + s = (void *)this->field_386; + if ( s ) + { + sub_80A9434(s); + operator delete(s); + } + this->field_386 = 0; + } + if ( this->field_38A ) + { + v4 = (void *)this->field_38A; + if ( v4 ) + { + sub_80B8160(v4); + operator delete(v4); + } + this->field_38A = 0; + } + if ( this->field_4 ) + { + v3 = (void *)this->field_4; + if ( v3 ) + { + sub_80B1FF8(v3); + operator delete(v3); + } + this->field_4 = 0; + } + if ( this->field_8 ) + { + v2 = (void *)this->field_8; + if ( v2 ) + { + sub_80B9470(v2); + operator delete(v2); + } + this->field_8 = 0; + }*/ +} + +//---------------------------------------------------- + +void CNetGame::Init(char *a2, int a3, char *a4, char *a5, char *a6) +{ + // TODO: CNetGame::Init (W: 00416490 L: 080AD126) + + /* + strcpy(this->field_202, "San Andreas Multiplayer"); + strncpy(this->field_302, src, 0x80u); + this->field_382 = a3; + v6 = (void *)operator new(0x6Eu); + sub_80A940C(v6); + this->field_386 = (int)v6; + v7 = (void *)operator new(0x19u); + sub_80B8036(v7); + this->field_38A = (int)v7; + v8 = (void *)operator new(0xA04Bu); + sub_80B1F4E(v8); + this->field_4 = (int)v8; + sub_80AFBA2(this->field_4, a4); + v9 = (void *)operator new(0x1BD50u); + sub_80B9408(v9); + this->field_8 = (int)v9; + this->field_0 = sub_8070E80(); + sub_8094DD0((unsigned __int16)a3); + sub_80B1714(this->field_0); + sub_80B7032(this->field_0); + sprintf(byte_810A720, "npcmodes/%s.amx", a6); + if ( !(unsigned __int8)sub_80A9448((void *)this->field_386, byte_810A720) ) + exit(1); + (*(void (__cdecl **)(int, char *))(*(_DWORD *)this->field_0 + 20))(this->field_0, a5); + (*(void (__cdecl **)(int, char *, _DWORD, _DWORD, _DWORD, signed int))(*(_DWORD *)this->field_0 + 8))( + this->field_0, + src, + (unsigned __int16)a3, + 0, + 0, + 10); + this->field_C = 1; + this->field_14 = 0; + this->field_1E = 12; + this->field_1F = 0; + this->field_20 = 10; + this->field_34 = 1006834287; + this->field_38 = 0; + this->field_10 = 0; + this->field_3C = 1; + this->field_40 = 0; + for ( i = 0; i <= 99; ++i ) + this->field_4A[i] = 0; + this->field_31 = 1; + this->field_3E = 0; + this->field_3D = 0; + memset(&word_80E1600, 0, 0x44u); + memset(&word_80E1660, 0, 0x3Fu); + memset(&word_80E16C0, 0, 0x109A0u); + memset(&word_80F2060, 0, 0xF618u); + memset(&word_8101680, 0, 0x5DC0u); + memset(&dword_8107440, 0, 0xFA0u); + memset(&dword_81083E0, 0, 0x1F40u); + memset(&byte_810A320, 0, 0x3E8u); + this->field_1DE = 0; + this->field_1E2 = 0; + this->field_1F2 = sub_80AC0BE(); + byte_80E16B7 = 0; + this->field_1FA = -1; + this->field_1FE = -1; + srand(0); + */ +} + +//---------------------------------------------------- + +//---------------------------------------------------- + +void CNetGame::Process() +{ + // TODO: CNetGame::Process (W: 00418370 L: 080AD6A4) + /* + v2 = sub_80AC130(); + sub_80AE6A4(this); + if ( this->field_C == 2 ) + { + if ( this->field_386 ) + sub_80A969E(this->field_386, v2); + if ( this->field_38A ) + sub_80B8610(this->field_38A, (signed __int64)(v2 * 1000.0)); + if ( byte_810A708 ) + { + if ( this->field_1DE ) + { + sub_80ADFDE(this); + } + else + { + sub_80AD770(this); + byte_80E16B7 = 1; + } + } + }*/ +} + +//---------------------------------------------------- diff --git a/bot/net/netgame.h b/bot/net/netgame.h new file mode 100644 index 0000000..69e083d --- /dev/null +++ b/bot/net/netgame.h @@ -0,0 +1,55 @@ + +#pragma once + +//---------------------------------------------------- + +class CNetGame // size: 910 bytes +{ +private: + int field_0; // highly m_pRakClient + int field_4; + int field_8; + int field_C; + int field_10; + int field_14; + char _gap18[6]; + char field_1E; // m_byteWorldTime ? + char field_1F; + char field_20; + char _gap21[16]; + char field_31; + char _gap32[2]; + int field_34; + int field_38; + char field_3C; + char field_3D; + char field_3E; + char _gap3F; + char field_40; + char _gap41[9]; + int field_4A[100]; + char _gap1DA[4]; + int field_1DE; + int field_1E2; + char _gap1E6[12]; + int field_1F2; + char _gap1F6[4]; + int field_1FA; + int field_1FE; + char field_202[256]; + char field_302[128]; + int field_382; + int field_386; + int field_38A; + +public: + + CNetGame(); + ~CNetGame(); + + void Init(char *a2, int a3, char *a4, char *a5, char *a6); + void Process(); + +}; + +//----------------------------------------------------