Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Feb 17, 2024
1 parent e72ecd3 commit 3c1b38a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 21 deletions.
37 changes: 34 additions & 3 deletions src/modules/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "level/Event.h"
#include "input/Input.h"
#include "game/Player.h"
#include "file/FileSystem.h"
#include "modules/Log.h"

void MainMenu::OnDraw()
{
Expand All @@ -19,7 +21,7 @@ void MainMenu::OnDraw()

if (ImGui::Button("Load unit"))
{
GAMELOOP_RequestLevelChangeByName(unit, Game::GetGameTracker(), 4);
SwitchUnit(unit);
}

// Birth instance
Expand Down Expand Up @@ -116,8 +118,15 @@ void MainMenu::OnDraw()
ImGui::End();
}

void MainMenu::BirthObject(char* name)
void MainMenu::BirthObject(char* name) const noexcept
{
// Make sure the object exists
if (!CheckDataFile(name) || OBTABLE_GetObjectID(name) == 0)
{
Hook::GetInstance().GetModule<Log>()->WriteLine("Not birthing %s, object does not exists", name);
return;
}

auto game = Game::GetGameTracker();
auto player = Game::GetPlayerInstance();

Expand All @@ -134,7 +143,19 @@ void MainMenu::BirthObject(char* name)
INSTANCE_BirthObjectNoParent(game->StreamUnitID, &player->position, &player->rotation, nullptr, tracker->object, 0, 1);
}

void MainMenu::SwitchPlayerCharacter(char* name)
void MainMenu::SwitchUnit(char* name) const noexcept
{
// Make sure the unit exists, this only checks if a file with the same name exists
if (!CheckDataFile(name))
{
Hook::GetInstance().GetModule<Log>()->WriteLine("Not switching to unit %s, level does not exist", name);
return;
}

GAMELOOP_RequestLevelChangeByName(name, Game::GetGameTracker(), 4);
}

void MainMenu::SwitchPlayerCharacter(char* name) noexcept
{
auto game = Game::GetGameTracker();

Expand Down Expand Up @@ -197,4 +218,14 @@ void MainMenu::OnInput(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
INSTANCE_Post(gameTracker->playerInstance, 4, 3);
#endif
}
}

bool MainMenu::CheckDataFile(char* name) noexcept
{
auto fileSystem = GetFS();

char fileName[256];
LOAD_UnitFileName(fileName, name, "drm");

return fileSystem->FileExists(fileName);
}
9 changes: 6 additions & 3 deletions src/modules/MainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ class MainMenu : public Module

Option<bool> m_noWatermark{ "NoWatermark", false };

void BirthObject(char* name);
void SwitchPlayerCharacter(char* name = nullptr);
void BirthObject(char* name) const noexcept;
void SwitchUnit(char* name) const noexcept;
void SwitchPlayerCharacter(char* name = nullptr) noexcept;

static bool CheckDataFile(char* name) noexcept;

public:
bool IsNoDeathFade() { return m_noDeathFade; }
bool IsNoDeathFade() const noexcept { return m_noDeathFade; }

void OnDraw();
void OnFrame();
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Patches::Patches()
MH_EnableHook(MH_ALL_HOOKS);
}

void Patches::RemoveIntro()
void Patches::RemoveIntro() const noexcept
{
auto match = hook::pattern("8D 0C 8D 03 00 00 00 89 0D").count(1);
auto mainState = *match.get_first<int>(9);
Expand Down
6 changes: 3 additions & 3 deletions src/modules/Patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Patches : public Module
Option<bool> m_noCinematicBars{ "NoCinematicBars", true };
Option<bool> m_noMotionBlur{ "NoMotionBlur", false };

void RemoveIntro();
void RemoveIntro() const noexcept;

public:
Patches();

bool IsNoMotionBlur() { return m_noMotionBlur.GetValue(); }
bool IsNoCinematicBars() { return m_noCinematicBars.GetValue(); }
bool IsNoMotionBlur() const noexcept { return m_noMotionBlur.GetValue(); }
bool IsNoCinematicBars() const noexcept { return m_noCinematicBars.GetValue(); }

void OnInput(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
};
29 changes: 23 additions & 6 deletions src/modules/Skew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
#include "instance/Instances.h"
#include "game/Game.h"

void Skew::ToggleSkew()
Skew::Skew()
{
UpdateLayout();
}

void Skew::ToggleSkew() const noexcept
{
auto tracker = Game::GetGameTracker();

Expand All @@ -22,21 +27,20 @@ void Skew::ToggleSkew()
#endif
}

void Skew::Process(UINT msg, WPARAM wParam)
void Skew::Process(UINT msg, WPARAM wParam) const noexcept
{
// TODO different keyboard layouts

auto player = Game::GetPlayerInstance();
auto tracker = Game::GetGameTracker();

auto speed = m_speed.GetValue() * tracker->timeMult;

if (msg == WM_KEYDOWN && wParam == 0x51)
// TODO less hacky way? use game input system perhaps
if (msg == WM_KEYDOWN && wParam == (m_isAzerty ? 0x41 /* A */ : 0x51 /* Q */))
{
player->position.z += speed;
}

if (msg == WM_KEYDOWN && wParam == 0x5A)
if (msg == WM_KEYDOWN && wParam == (m_isAzerty ? 0x57 /* W */ : 0x5A /* Z */))
{
player->position.z -= speed;
}
Expand All @@ -49,10 +53,23 @@ void Skew::OnInput(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
ToggleSkew();
}

if (msg == WM_INPUTLANGCHANGE)
{
UpdateLayout();
}

auto tracker = Game::GetGameTracker();

if (tracker->cheatMode)
{
Process(msg, wParam);
}
}

void Skew::UpdateLayout() noexcept
{
auto layout = GetKeyboardLayout(0);
auto id = LOWORD(layout);

m_isAzerty = id == 2060 || id == 1036;
}
9 changes: 7 additions & 2 deletions src/modules/Skew.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
class Skew : public Module
{
private:
void ToggleSkew();
void Process(UINT msg, WPARAM wParam);
bool m_isAzerty = false;

void ToggleSkew() const noexcept;
void Process(UINT msg, WPARAM wParam) const noexcept;
void UpdateLayout() noexcept;

Option<float> m_speed{ "SkewSpeed", 300.f };

public:
Skew();

virtual void OnInput(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
};
7 changes: 4 additions & 3 deletions src/render/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ void DrawLine(cdc::Vector3* v0, cdc::Vector3* v1, int color)
auto v2 = *v1;
auto v3 = *v0;

v2.z += 50.f;
v3.z += 50.f;
v3.x += 50.f;
v2.z += 20.f;
v3.z += 20.f;
v2.y += 20.f;
v3.y += 20.f;

TRANS_TransToDrawVertexV4f(verts, v0);
TRANS_TransToDrawVertexV4f(&verts[1], &v2);
Expand Down

0 comments on commit 3c1b38a

Please sign in to comment.