Skip to content

Commit

Permalink
Added current game location & improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunoo16 committed Jan 1, 2019
1 parent 47c5d32 commit 9116246
Show file tree
Hide file tree
Showing 3 changed files with 496 additions and 257 deletions.
1 change: 1 addition & 0 deletions discord-plugin/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID lpReserved)
if (reason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(module);
Game::module = module;
Game::Functions::Initialize();
}
else if (reason == DLL_PROCESS_DETACH)
Expand Down
297 changes: 44 additions & 253 deletions discord-plugin/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,289 +2,80 @@

namespace Game
{
HMODULE module = NULL;

namespace Functions
{
void Initialize()
{
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Functions::PluginThread, 0, 0, 0); // Thread because we don't want to end up in a deadlock when initializing on dllmain.
CreateThread(0, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(Functions::PluginThread), 0, 0, 0);
}

void Shutdown()
{
Discord_Shutdown();
}

std::string GetWeaponName(int id)
std::string GetCurrentZone()
{
std::string weapon_name;
switch (id)
const float position_x = *reinterpret_cast<float*>(0xB6F2E4), position_y = *reinterpret_cast<float*>(0xB6F2E8), position_z = *reinterpret_cast<float*>(0x8CCC44);

for (int i = 0; i < sizeof(zone) / sizeof(zone[0]); i++)
{
case 311:
{
weapon_name = "Brass Knuckles";
break;
}
case 333:
{
weapon_name = "Golf Club";
break;
}
case 334:
{
weapon_name = "Nightstick";
break;
}
case 335:
{
weapon_name = "Knife";
break;
}
case 336:
{
weapon_name = "Baseball Bat";
break;
}
case 337:
{
weapon_name = "Shovel";
break;
}
case 338:
{
weapon_name = "Pool Cue";
break;
}
case 339:
{
weapon_name = "Katana";
break;
}
case 341:
{
weapon_name = "Chainsaw";
break;
}
case 321:
{
weapon_name = "Purple Dildo";
break;
}
case 322:
{
weapon_name = "Dildo";
break;
}
case 323:
{
weapon_name = "Vibrator";
break;
}
case 324:
{
weapon_name = "Silver Vibrator";
break;
}
case 325:
{
weapon_name = "Flowers";
break;
}
case 326:
{
weapon_name = "Cane";
break;
}
case 342:
{
weapon_name = "Grenade";
break;
}
case 343:
{
weapon_name = "Tear Gas";
break;
}
case 344:
{
weapon_name = "Molotov Cocktail";
break;
}
case 346:
{
weapon_name = "9mm";
break;
}
case 347:
{
weapon_name = "Silenced 9mm";
break;
}
case 348:
{
weapon_name = "Desert Eagle";
break;
}
case 349:
{
weapon_name = "Shotgun";
break;
}
case 350:
{
weapon_name = "Sawnoff Shotgun";
break;
}
case 351:
{
weapon_name = "Combat Shotgun";
break;
}
case 352:
if (position_x > zone[i].min_x && position_y > zone[i].min_y && position_z > zone[i].min_z && position_x < zone[i].max_x && position_y < zone[i].max_y && position_z < zone[i].max_z)
{
weapon_name = "Micro SMG";
break;
}
case 353:
{
weapon_name = "MP5";
break;
}
case 355:
{
weapon_name = "AK-47";
break;
}
case 356:
{
weapon_name = "M4";
break;
}
case 372:
{
weapon_name = "Tec-9";
break;
}
case 357:
{
weapon_name = "Country Rifle";
break;
}
case 358:
{
weapon_name = "Sniper Rifle";
break;
}
case 359:
{
weapon_name = "Rocket Launcher";
break;
}
case 360:
{
weapon_name = "Heat Seeker";
break;
}
case 361:
{
weapon_name = "Flamethrower";
break;
}
case 362:
{
weapon_name = "Minigun";
break;
}
case 363:
{
weapon_name = "Satchel Charge";
break;
}
case 364:
{
weapon_name = "Detonator";
break;
}
case 365:
{
weapon_name = "Spraycan";
break;
}
case 366:
{
weapon_name = "Fire Extinguisher";
break;
}
case 367:
{
weapon_name = "Camera";
break;
}
case 368:
{
weapon_name = "NV Googles";
break;
}
case 369:
{
weapon_name = "Thermal Googles";
break;
}
case 371:
{
weapon_name = "Parachute";
break;
}
default:
{
weapon_name = "None";
break;
return zone[i].zone_name;
}
}
return weapon_name;

return std::string("San Andreas");
}

void PluginThread()
{
Discord_Initialize("424599965164371968", 0, 1, 0);
if (GetModuleHandle("samp.dll")) // This plugin is not supposed to be used with SA-MP.
{
FreeLibraryAndExitThread(Game::module, 0);
}
else
{
Discord_Initialize(APPLICATION_ID, 0, 0, 0);

std::string details, state, small_img, large_img;
std::string details, state, small_img, large_img;

DiscordRichPresence drp;
DiscordRichPresence drp;

time_t start_timestamp = time(0);
drp = { 0 };
drp.largeImageKey = "game_icon";
drp.startTimestamp = time(0);

while (1)
{
if (*(int*)0xB6F5F0) // Player pointer.
while (1)
{
memset(&drp, 0, sizeof(drp));

drp.largeImageKey = "game_icon";
drp.startTimestamp = start_timestamp;

if (*(unsigned char*)(*(int*)0xB6F5F0 + 0x46C) == 1) // Player is on vehicle, let's consider other states as "on-foot".
{
drp.smallImageKey = "player_on_vehicle";
small_img = "On vehicle - Wanted level: " + std::to_string(*(int*)0xBAA420);
}
else
if (*reinterpret_cast<int*>(0xB6F5F0))
{
small_img = "On foot - Wanted level: " + std::to_string(*(int*)0xBAA420);
drp.smallImageKey = "player_on_foot";
}
if (*reinterpret_cast<unsigned char*>(*reinterpret_cast<int*>(0xB6F5F0) + 0x46C) == 1) // Player is on vehicle, let's consider other states as "on-foot".
{
drp.smallImageKey = "player_on_vehicle";
}
else
{
drp.smallImageKey = "player_on_foot";
}

details = "Money: $" + std::to_string(*(int*)0xB7CE50);
state = "Weapon: " + GetWeaponName(*(int*)(*(int*)0xB6F5F0 + 0x740));
large_img = std::to_string(*(int*)0xB79038) + " day(s) passed.";
details = "Money: $" + std::to_string(*reinterpret_cast<int*>(0xB7CE50));
state = "Weapon: " + WeaponNames[*reinterpret_cast<int*>(0xBAA410)];
large_img = std::to_string(*reinterpret_cast<int*>(0xB79038)) + " day(s) passed.";
small_img = "Location: " + GetCurrentZone();

drp.smallImageText = small_img.c_str();
drp.details = details.c_str();
drp.state = state.c_str();
drp.largeImageText = large_img.c_str();
drp.smallImageText = small_img.c_str();
drp.details = details.c_str();
drp.state = state.c_str();
drp.largeImageText = large_img.c_str();

Discord_UpdatePresence(&drp);
Discord_UpdatePresence(&drp);

Sleep(15000);
Sleep(15000);
}
}
}
}
Expand Down
Loading

0 comments on commit 9116246

Please sign in to comment.