Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes radio issues #7

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 59 additions & 53 deletions projects/client/mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,31 @@ void mod_install() {

librg_event_trigger(ctx, M2O_CAR_ENTER, &event);
});

M2::C_Player2_Hooks::HookAddSpecCommand([&](M2::E_SpecCommand type) {
switch (type)
{
case M2::E_SpecCommand::HOLSTER:
mod_log("holster trigger\n");
break;

case M2::E_SpecCommand::RELOAD:
mod_log("player reloading\n");
break;

case M2::E_SpecCommand::SHOT:
mod_log("player shot\n");
break;

case M2::E_SpecCommand::SWITCH_NEXT:
mod_log("player switched next\n");
break;

case M2::E_SpecCommand::SWITCH_PREV:
mod_log("Player switched prev\n");
break;
}
});
}

void mod_connect(const char *host, int port) {
Expand Down Expand Up @@ -215,8 +240,13 @@ void m2o_module::init(M2::I_TickedModuleCallEventContext &) {

librg_event_add(ctx, LIBRG_CONNECTION_ACCEPT, [](librg_event_t *event) {
mod_log("[info] connected to the server\n");

/* This enable the ingame sound */
M2::Wrappers::lua::Execute("game.game:SoundFadeIn(1000)");




/* setup default timeout */
enet_peer_timeout(event->peer, 10, 5000, 10000);

Expand All @@ -235,6 +265,12 @@ void m2o_module::init(M2::I_TickedModuleCallEventContext &) {
mod_log("[info] disconnected form the server\n");
M2::Wrappers::lua::Execute("game.game:SoundFadeOut(1000)");

M2::C_RangeMeter::Get()->OpenSeason(50);
M2::C_SpeechSlotManager::Get()->LoadStage(50);
M2::Wrappers::Radio::SetContent("Empire", "all", "Empire_07010");
M2::Wrappers::Radio::SetContent("Classic", "all", "Classic_07010");
M2::Wrappers::Radio::SetContent("Delta", "all", "Delta_07010");


M2::C_Game::Get()->GetLocalPed()->LockControls(true);
// object->SetPosition(zplm_vec3_zero()); // creates black textures :O
Expand Down Expand Up @@ -357,11 +393,6 @@ void m2o_module::tick(M2::I_TickedModuleCallEventContext &) {
input_block_set(!input_block_get());
}

/* create a car */
if (input_key_down(VK_F2)) {
mod_message_send(ctx, M2O_CAR_CREATE, nullptr);
}

/* connect to the server */
if (input_key_down(VK_F5) && !mod.spawned) {
mod_connect("localhost", 27010);
Expand All @@ -370,6 +401,14 @@ void m2o_module::tick(M2::I_TickedModuleCallEventContext &) {


static M2::C_Entity *ent;
static M2::C_Command* moveCommand = nullptr;
if (input_key_down(VK_F2)) {
if (ent) {
((M2::C_Human2*)ent)->CleanMoveCommands();
moveCommand = nullptr;
}
}

if (input_key_down(VK_F3)) {
if (!ent) {
ent = M2::Wrappers::CreateEntity(M2::eEntityType::MOD_ENTITY_PED, 10);
Expand All @@ -383,70 +422,37 @@ void m2o_module::tick(M2::I_TickedModuleCallEventContext &) {
pos.y += 1.f;
pos.z -= 2.f;
ent->SetPosition(pos);

mod_log("remote ped address = 0x%x\n", ((uintptr_t)ent));
mod_log("my ped address = 0x%x\n", ((uintptr_t)(M2::C_Game::Get()->GetLocalPed())));
}
}

if (input_key_down(VK_F4) && mod.spawned) {

if (ent) {
static void* moveCommand = nullptr;
if (!moveCommand) {
//moveCommand = zpl_malloc(0x58);
// zpl_zero_size(moveCommand, 0x58);
//mod_log("moveCommand address = 0x%x size: %d\n", ((uintptr_t)moveCommand), sizeof(moveCommand));
moveCommand = CIE_Alloc(0x58);
//moveCommand = new char[0x58];
((M2::C_Human2*)ent)->AddCommand(M2::E_Command::COMMAND_MOVEDIR, moveCommand);
}

if(!moveCommand){
moveCommand = (M2::C_Command*)CIE_Alloc(sizeof(M2::S_HumanCommandMoveDir));

mod_log("moveCommand address = 0x%x size: %d\n", ((uintptr_t)moveCommand), sizeof(char[0x58]));
ZeroMemory(moveCommand, sizeof(M2::S_HumanCommandMoveDir));
*(uintptr_t*)moveCommand = 0x19661BC;
moveCommand->countUsed = 1;

if (((M2::C_Command*)moveCommand)->m_iCommandID == 1) {
M2::S_HumanCommandMoveDir* cmd = (M2::S_HumanCommandMoveDir*)moveCommand;
cmd->moveSpeed = 0;
cmd->speedMultiplier = 0.1f;
cmd->potentialMoveVector = { 1.f, 1.f };
((M2::C_Human2*)ent)->AddCommand(M2::E_Command::COMMAND_MOVEDIR, moveCommand);
((M2::C_Human2*)ent)->m_aCommandsArray[((M2::C_Human2*)ent)->m_iNextCommand].m_pCommand = moveCommand;
}

((M2::C_Human2*)ent)->m_iCurrentCommand = 1;
((M2::C_Human2*)ent)->m_aCommandsArray[1].m_pCommand = moveCommand;
mod_log("moveCommand address = 0x%x\n", ((uintptr_t)moveCommand));
}

//M2::Wrappers::lua::Execute("game.sds:ActivateStreamMapLine(\"11_galante_load\")");
//M2::Wrappers::lua::Execute("icon = game.entitywrapper:GetEntityByName(\"RTR_POUTA1_00\")");
//M2::Wrappers::lua::Execute("icon:Activate()");
//M2::Wrappers::lua::Executef("icon:SetPos(Math:newVector(%f, %f, %f))", pos.x, pos.y, pos.z);
}

if (GetAsyncKeyState(VK_F7) & 0x1) {
M2::C_Entity *test = M2::C_WrappersList::Get()->GetEntityByName("RTR_POUTA1_00");
if (test) {
mod_log("entity : 0x%p\n", test);
}
else {
mod_log("null ptr\n");
}
reinterpret_cast<M2::C_Human2*>(M2::C_Game::Get()->GetLocalPed())->GetInventory()->AddWeapon(12, 120);
}

if (GetAsyncKeyState(VK_F6) & 0x1) {
char *fileName = M2::C_Tables::Get()->GetModelFileName(M2::EntityTypes::Entity_Car, 5);
mod_log("Veh file : %s\n", fileName);

M2::CModelManager::Get().OpenModel(M2::EntityTypes::Entity_Car, fileName);
M2::C_Model* model = M2::CModelManager::Get().m_pModel;
mod_log("Model ptr: 0x%X", model);
M2::Wrappers::Dialogs::ShowQuestDialog();
}

if (input_key_down(VK_F9)) {
vec3_t curpos, tarpos;
curpos = reinterpret_cast<M2::C_Entity*>(M2::C_Game::Get()->GetLocalPed())->GetDirection();
tarpos = reinterpret_cast<M2::C_Entity*>(M2::C_Game::Get()->GetLocalPed())->GetPosition();

static M2::C_SyncObject *sync = NULL;
((M2::C_Human2 *)ent)->GetScript()->ScrMoveV(&sync, tarpos, M2::HUMAN_MOVE_MODE_SPRINT, curpos, true);

print_posm(curpos, "direction");
mod_log("moving ped to your location");
if (input_key_down(VK_F9) & 0x1) {
M2::Wrappers::lua::Execute("game.gui:ShowQuestDialog(\"pinup01_ps\",\"Text1\",\"\Text2\",\"Text3\")");
}
}
14 changes: 9 additions & 5 deletions projects/client/mod/pedestrian.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,16 @@ void m2o_callback_ped_update(librg_event_t *event) {
ped->tasks.init = true;
mod_log("[info] calling late init for ped tasks...");

//ped->tasks.stand = CIE_Alloc(0x1E); // zpl_zero_item(ped->tasks.stand);
//ped->CHuman->AddCommand(M2::E_Command::COMMAND_STAND, ped->tasks.stand);

// ped->tasks.movedir = CIE_Alloc(0x58); //zpl_zero_item(ped->tasks.movedir);
ped->tasks.movedir = new char[0x58]; //zpl_zero_item(ped->tasks.movedir);
/* Init move command */
ped->tasks.movedir = (M2::C_Command*)CIE_Alloc(sizeof(M2::S_HumanCommandMoveDir));
*(uintptr_t*)ped->tasks.movedir = 0x19661BC;
ped->tasks.movedir->countUsed = 1;

ped->CHuman->AddCommand(M2::E_Command::COMMAND_MOVEDIR, ped->tasks.movedir);

/* Tag the first command the player will use */
ped->CHuman->m_aCommandsArray[ped->CHuman->m_iNextCommand].m_pCommand = ped->tasks.movedir;
}

if (ped->state == PED_ON_GROUND && ped->tasks.init) {
Expand All @@ -184,7 +188,7 @@ void m2o_callback_ped_update(librg_event_t *event) {
cmd->potentialMoveVector = { ped->stream.dirx, ped->stream.diry };
}

ped->CHuman->m_iCurrentCommand = 1;
ped->CHuman->m_iNextCommand = 1;
ped->CHuman->m_aCommandsArray[1].m_pCommand = ped->tasks.movedir;
} else {
// ped->CHuman->m_iCurrentCommand = 0;
Expand Down
4 changes: 2 additions & 2 deletions projects/shared/m2o_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ typedef struct m2o_ped {
struct {
bool init;
int counter;
void *stand;
void *movedir;
M2::C_Command *stand;
M2::C_Command *movedir;
} tasks;

struct {
Expand Down
4 changes: 4 additions & 0 deletions vendor/m2sdk/include/classes/CAIController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ namespace M2
class C_AIController : public ICAIController
{
public:
void NewCommand(void *cmd)
{
Mem::InvokeFunction<Mem::call_this, int>(0xF9F880, this, cmd);
}
};
};
20 changes: 20 additions & 0 deletions vendor/m2sdk/include/classes/CBaseDaemon.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "CRefPtr.hpp"
namespace M2
{
class ICBaseDaemon
{
public:
};

class C_BaseDaemon : public ICBaseDaemon
{
public:
template <typename T>
C_RefPtr<T> GetHelper(C_HashName *name)
{
return Mem::InvokeFunction<Mem::call_this, C_RefPtr<T>>(0x878380, this, name);
}
};
};
10 changes: 10 additions & 0 deletions vendor/m2sdk/include/classes/CCar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ namespace M2
{
return Mem::InvokeFunction<Mem::call_this, double>(0x46AC70, this);
}

float GetTransparency()
{
return Mem::InvokeFunction<Mem::call_this, double>(0x9A1DC0, this);
}

Vector3 GetWheelPos(int index)
{
Expand Down Expand Up @@ -250,6 +255,11 @@ namespace M2
Mem::InvokeFunction<Mem::call_this, int>(0x9A01A0, this, speed);
}

void SetTransparency(float transparency)
{
Mem::InvokeFunction<Mem::call_this, unsigned int>(0x9CCCC0, this, transparency);
}

void Setup()
{
Mem::InvokeFunction<Mem::call_this, int>(0x0A151F0, this);
Expand Down
4 changes: 2 additions & 2 deletions vendor/m2sdk/include/classes/CCarActionThrowFrom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace M2
{
inline bool TestAction(C_Car *car)
{
if (FunctionPointers::testAction != nullptr) {
if (FunctionPointers::testAction != nullptr && car != nullptr) {
return FunctionPointers::testAction(car);
}
return false;
Expand Down Expand Up @@ -61,7 +61,7 @@ namespace M2
void HookTestAction(std::function<bool(C_Car *)> ptr)
{
FunctionPointers::testAction = ptr;
Mem::Hooks::InstallJmpPatch(0xA3F173, (DWORD)NakedFunctions::CCarActionThrowFrom__TestAction__Hook);
Mem::Hooks::InstallJmpPatch(0xA3F189, (DWORD)NakedFunctions::CCarActionThrowFrom__TestAction__Hook);
}
};
#endif
Expand Down
5 changes: 4 additions & 1 deletion vendor/m2sdk/include/classes/CGameGuiModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

#pragma once

#include "CGameGuiScriptW.hpp"

namespace M2
{
class ICGameGuiModule
{
public:
void *m_pVFTable;
pad(ICGameGuiModule, pad0, 0x1758); //0000 - 1758
C_GameGuiScriptW *m_pGuiScriptW; //1758 - 175C
};

class C_GameGuiModule : public GameClassWrapperStatic<C_GameGuiModule, ICGameGuiModule, 0x1AB64F0>
Expand Down
19 changes: 19 additions & 0 deletions vendor/m2sdk/include/classes/CGameGuiScriptW.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @file CGameGuiScriptW.cpp
* @brief Game's GameGuiModule wrapper
*
* @author Tyldar ([email protected])
*/

#pragma once

namespace M2
{
class ICGameGuiScriptW
{
public:
};

class C_GameGuiScriptW : public ICGameGuiScriptW
{
};
}
13 changes: 11 additions & 2 deletions vendor/m2sdk/include/classes/CHuman2Commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ namespace M2
{
class C_Command {
public:
pad(C_Command, pad0, 0xC);//0x0000
uint8_t m_iCommandID; //0x000C
pad(C_Command, pad0, 0x4);//0x0000
uint32_t countUsed; //0x0004
pad(C_Command, pad1, 0x4);//0x0008
uint8_t m_iCommandID; //0x000C
};

class S_HumanCommandMoveDir : public C_Command
Expand All @@ -30,6 +32,13 @@ namespace M2
uint32_t int32_0x54; //0x0054
}; //Size=0x0058

class S_HumanCommandStand : public C_Command
{
public:
zpl_vec2 standingDirVector; //0000 - 0010
pad(S_HumanCommandStand, pad0, 0x8); //0010 - 0018
}; //Size=0x0058

class C_CommandDescription
{
public:
Expand Down
15 changes: 15 additions & 0 deletions vendor/m2sdk/include/classes/CHumanWeaponController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,20 @@ namespace M2
{
Mem::InvokeFunction<Mem::call_this, unsigned int>(0x432020, this);
}

void GetShotPosDir(zplm_vec3 *pos, zplm_vec3 *rot)
{
Mem::InvokeFunction<Mem::call_this, bool>(0x004277C0, this, pos, rot);
}

void SetAnimationMatrices(const void *matrix)
{
Mem::InvokeFunction<Mem::call_this, void>(0x42DDF0, this, matrix);
}

void ThrowItem(int item)
{
Mem::InvokeFunction<Mem::call_this, bool>(0x436380, this, item);
}
};
};
Loading