Blood
Известный
- 45
- 1
Пытаюсь сделать перенести функци на диалог, но после того, как жму D+C или пишу /dialog
Диалог не срабатывает (делал по примеру фипа[nocols])
Диалог не срабатывает (делал по примеру фипа[nocols])
Код:
#include <windows.h>
#include <string>
#include <assert.h>
#include <process.h>
#include "bass.h"
#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "bass.lib")
HSTREAM str;
HSTREAM stream;
stFontInfo *pFont;
SAMPFUNCS *SF = new SAMPFUNCS();
#define _copyright "Multi"
void ShowSettingsDialog( void );
bool update = false, _enabled = false, hitsound = false;
float damage, target_pos[3];
bool _dialog = false;
bool _showDialog = false;
const uint16_t _settingsDialogID = 100;
bool _enabled1 = false;
bool CALLBACK outcomingData1(stRakNetHookParams *params)
{
if (params->packetId == RPCEnumeration::RPC_GiveTakeDamage)
{
if (_enabled)
{
bool bGiveOrTake;
short int iPlayerID;
float fAmmount;
int iWeaponID, iBodyPart;
params->bitStream->ResetReadPointer();
params->bitStream->Read(bGiveOrTake);
params->bitStream->Read(iPlayerID);
params->bitStream->Read(fAmmount);
params->bitStream->Read(iWeaponID);
params->bitStream->Read(iBodyPart);
params->bitStream->ResetReadPointer();
if (!bGiveOrTake)
damage = fAmmount;
update = true;
}
}
return true;
}
bool CALLBACK Present(CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride,
CONST RGNDATA *pDirtyRegion)
{
if (SUCCEEDED(SF->getRender()->BeginRender())) // если рендерер готов к рисованию
{
if (_enabled)
{
if (update && damage > 0.0f)
{
float xf, yf;
SF->getGame()->convert3DCoordsToScreen(target_pos[0], target_pos[1], target_pos[2], &xf, &yf);
char buffer[228];
sprintf(buffer, "%.f", damage);
pFont->Print(buffer, D3DCOLOR_ARGB(255, 255, 255, 0), xf, yf, false);
static bool state = false;
static DWORD dwTime = 0;
if (!state)
{
state = true;
dwTime = GetTickCount();
}
else if (state && GetTickCount() - dwTime > 3000)
{
update = false;
state = false;
}
}
SF->getRender()->EndRender();
};
};
return true;
}
bool CALLBACK outcomingData(stRakNetHookParams *params)
{
if (params->packetId == PacketEnumeration::ID_BULLET_SYNC && _enabled)
{
{
stBulletData data;
memset(&data, 0, sizeof(stBulletData));
byte packet;
params->bitStream->ResetReadPointer();
params->bitStream->Read(packet);
params->bitStream->Read((PCHAR)&data, sizeof(stBulletData));
params->bitStream->ResetReadPointer();
if (data.byteType != 0)
{
for(int i = 0; i < 3; i++)
target_pos[i] = data.fTarget[i];
}
if(hitsound == true && data.byteType == 1)
{
PlaySound("SAMPFUNCS\\hitsound.wav", NULL, SND_ASYNC);
}
params->bitStream->ResetWritePointer();
params->bitStream->Write(packet);
params->bitStream->Write((PCHAR)&data, sizeof(stBulletData));
}
};
return true;
};
/*void CALLBACK paramfunction1(std:: string param)
{
hitsound ^= true;
if(hitsound == true)
GAME->GetAudio()->PlayFrontEndSound(1);
else
GAME->GetAudio()->PlayFrontEndSound(2);
}*/
/*void CALLBACK paramfunction(std:: string param)
{
_enabled ^= true;
if(_enabled == true)
GAME->GetAudio()->PlayFrontEndSound(1);
else
GAME->GetAudio()->PlayFrontEndSound(2);
}*/
void CALLBACK OnDialogRespond( int dialogId, int buttonId, int listItem, const char *input )
{
if ( _dialog == false || dialogId != _settingsDialogID || buttonId == 0 )
return;
_dialog = false;
switch ( listItem )
{
case 0: hitsound ^= true; break;
case 1: _enabled ^= true; break;
}
_showDialog = true;
}
void CALLBACK radio(std:: string param)
{
bool radioon = false;
radioon ^= true;
if(radioon == true && !BASS_Init (-1, 44100, 0 , NULL, NULL))
{
char url[] = "http://air.radiorecord.ru:8102/sd90_320";
stream = BASS_StreamCreateURL(url, 0, 0, NULL, 0);
BASS_ChannelPlay(stream,TRUE);
}
else
{
BASS_ChannelStop(stream);
}
}
void CALLBACK cmd_menu( std::string str )
{
ShowSettingsDialog();
}
void CALLBACK mainloop()
{
static bool init = false;
if (!init)
{
if (GAME == nullptr)
return;
if (GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME)
return;
if (!SF->getSAMP()->IsInitialized())
return;
SF->getSAMP()->getChat()->AddChatMessage( D3DCOLOR_XRGB( 0, 0xAA, 0 ), _copyright );
pFont = SF->getRender()->CreateNewFont("Tahoma", 10, FCR_BORDER);
SF->getRakNet()->registerRakNetCallback(RakNetScriptHookType::RAKHOOK_TYPE_OUTCOMING_PACKET, outcomingData);
SF->getRakNet()->registerRakNetCallback(RakNetScriptHookType::RAKHOOK_TYPE_OUTCOMING_RPC, outcomingData1);
SF->getRender()->registerD3DCallback(eDirect3DDeviceMethods::D3DMETHOD_PRESENT, Present);
SF->getSAMP()->registerChatCommand( "radio", radio);
//SF->registerConsoleCommand("dmg_3d", paramfunction);
//SF->registerConsoleCommand("dmg_hit", paramfunction1);
SF->registerConsoleCommand("dialog", cmd_menu );
SF->getSAMP()->registerDialogCallback(OnDialogRespond);
init = true;
}
else
{
static bool keyDown = false;
if ( SF->getGame()->isKeyDown( 'D' ) && SF->getGame()->isKeyDown( 'C' ) )
{
if ( !keyDown )
_enabled1 ^= true, keyDown = true;
}
else if ( keyDown )
{
keyDown = false;
}
if ( _showDialog )
{
ShowSettingsDialog();
_showDialog = false;
}
}
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
{
switch (dwReasonForCall)
{
case DLL_PROCESS_ATTACH:
SF->initPlugin(mainloop, hModule);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
void ShowSettingsDialog( void )
{
const char *on = "{00DD00}On", *off = "{AAAAAA}Off", *white = "{FFFFFF}";
char str[0x100];
sprintf_s( str, "%shitsound: %s\n%sRENDER: \n%sState: %s",
white, ( hitsound ? on : off ),
white, ( _enabled ? on : off ),
white, ( _enabled1 ? "{00DD00}Enabled" : "{AAAAAA}Disabled" ) );
SF->getSAMP()->getDialog()->ShowDialog( _settingsDialogID, DIALOG_STYLE_LIST, (char *)_copyright, str, "Toggle", "Close");
_dialog = true;
}