Skip to content

Commit

Permalink
initial support for latest steam version (v1.10)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronkirkham committed Aug 15, 2019
1 parent c7d0ce3 commit f1bd4b2
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/commands/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class EventCommand : public ICommand
return false;
}

hk::func_call<void>(0x147EF4A40, arguments.c_str(), nullptr);
hk::func_call<void>(0x1446EB790, arguments.c_str(), nullptr);
return true;
}

Expand Down
7 changes: 2 additions & 5 deletions src/commands/spawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,8 @@ class SpawnCommand : public ICommand
transform.m[3].y = aimpos.y + 1.0f;
transform.m[3].z = aimpos.z;

// TODO(aaronlad): figure out the flags, right now the game is holding the shared_ptr so we don't have to do it
jc::CSpawnSystem::instance().Spawn(arguments, transform, [](const jc::spawned_objects &objects, void *) {
//
});

// NOTE(aaronlad): spawn flag 0x8000 will prevent auto despawn
jc::CSpawnSystem::instance().Spawn(arguments, transform, [](const jc::spawned_objects &objects, void *) {});
return true;
}

Expand Down
10 changes: 5 additions & 5 deletions src/commands/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class WorldCommand : public ICommand

virtual bool Handler(const std::string& arguments) override
{
static auto World = *(void**)0x142C7FEF0;
static auto WorldTime = *(void**)0x142C4C1A0;
static auto hnpkWorld = *(void**)0x142CD6F70;
static auto WorldTime = *(void**)0x142CA2DA0;

// time
if (arguments.find("time ") != std::string::npos) {
float time = 0.0f;
if (sscanf_s(arguments.c_str(), "time %f", &time) == 1) {
time = std::clamp(time, -24.0f, 24.0f);
hk::func_call<void>(0x14031C800, WorldTime, time, 2);
hk::func_call<void>(0x14031F7D0, WorldTime, time, 2);
return true;
}
}
Expand All @@ -43,13 +43,13 @@ class WorldCommand : public ICommand
else if (arguments.find("gravity ") != std::string::npos) {
float gravity = -9.810f;
if (sscanf_s(arguments.c_str(), "gravity %f", &gravity) == 1) {
*(float*)((char*)World + 0x974) = std::clamp(gravity, -5000.0f, 5000.0f);
*(float*)((char*)hnpkWorld + 0x974) = std::clamp(gravity, -5000.0f, 5000.0f);
return true;
}
}
// reset gravity
else if (arguments.find("resetgravity") != std::string::npos) {
*(float*)((char*)World + 0x974) = -9.810f;
*(float*)((char*)hnpkWorld + 0x974) = -9.810f;
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CClock
public:
static CClock& instance()
{
return **(CClock**)0x142C20BA8;
return **(CClock**)0x142C776A8;
}

public:
Expand Down
6 changes: 3 additions & 3 deletions src/game/input_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ class CManagerBase
public:
static CManagerBase& instance()
{
return **(CManagerBase**)0x142C7DAF0;
return **(CManagerBase**)0x142CD4B30;
}

void LoseFocus()
{
hk::func_call<void>(0x140F7D3E0, this);
hk::func_call<void>(0x147C63280, this);
}

void GainFocus()
{
hk::func_call<void>(0x140F7D330, this);
hk::func_call<void>(0x147C630D0, this);
}
};
}; // namespace jc::NInput
Expand Down
2 changes: 1 addition & 1 deletion src/game/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CPlayer
public:
char _pad[0x68];
CCharacter* m_character;
char _pad2[0x140];
char _pad2[0x148];
CPlayerAimControl* m_aimControl;
};
}; // namespace jc
Expand Down
2 changes: 1 addition & 1 deletion src/game/player_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CPlayerManager
public:
static CPlayerManager& instance()
{
return **(CPlayerManager**)0x142C4E750;
return **(CPlayerManager**)0x142CA5378;
}

static CCharacter* GetLocalPlayerCharacter()
Expand Down
2 changes: 1 addition & 1 deletion src/game/render_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CRenderEngine
public:
static CRenderEngine& instance()
{
return **(CRenderEngine**)0x142C210D8;
return **(CRenderEngine**)0x142C77BD8;
}

public:
Expand Down
4 changes: 2 additions & 2 deletions src/game/spawn_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CSpawnSystem
public:
static CSpawnSystem& instance()
{
return **(CSpawnSystem**)0x142C4E0F0;
return **(CSpawnSystem**)0x142CA4D10;
}

void Spawn(const std::string& model_name, const CMatrix4f& transform,
Expand All @@ -30,7 +30,7 @@ class CSpawnSystem

auto request = new SpawnReq{callback, userdata};
hk::func_call<void>(
0x140B71C00, this, model_name.c_str(), transform, 0x597Cu,
0x140BA62E0, this, model_name.c_str(), transform, 0x597Cu,
(success_t)[](const spawned_objects& objects, void* userdata) {
auto spawn_req = (SpawnReq*)userdata;
spawn_req->callback(objects, spawn_req->userdata);
Expand Down
2 changes: 1 addition & 1 deletion src/game/ui_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CUIManager
public:
static CUIManager& instance()
{
return **(CUIManager**)0x142C54038;
return **(CUIManager**)0x142CAADA8;
}

CUIBase* GetUI(uint32_t name_hash)
Expand Down
45 changes: 22 additions & 23 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include "game/render_engine.h"
#include "game/ui_manager.h"

static const int32_t _numHintsPerPage = 10;
static constexpr int32_t NUM_HINTS_PER_PAGE = 10;
static constexpr float HINT_ITEM_HEIGHT = 0.02f;
static constexpr float FONT_SIZE_INPUT = 0.0155f;
static constexpr float FONT_SIZE_HINT = 0.0133f;

void Input::EnableInput(bool toggle)
{
Expand All @@ -21,13 +24,13 @@ void Input::EnableInput(bool toggle)
m_selectedHint = -1;
m_hintPage = 0;

static const auto hud_vehicle_hash = "hud_vehicle"_hash_little;
static const auto hud_bottom_left_hash = "hud_bottom_left"_hash_little;
static const uint32_t HUD_VEHICLE_HASH = "hud_vehicle"_hash_little;
static const uint32_t HUD_BOTTOM_LEFT_HASH = "hud_bottom_left"_hash_little;

// toggle hud which might get in the way (bottomleft)
auto &ui_manager = jc::CUIManager::instance();
auto hud_vehicle = ui_manager.GetUI(hud_vehicle_hash);
auto hud_bottom_left = ui_manager.GetUI(hud_bottom_left_hash);
auto ui_manager = &jc::CUIManager::instance();
auto hud_vehicle = ui_manager->GetUI(HUD_VEHICLE_HASH);
auto hud_bottom_left = ui_manager->GetUI(HUD_BOTTOM_LEFT_HASH);

if (hud_vehicle && hud_bottom_left) {
hud_vehicle->m_state = toggle ? 1 : 2;
Expand All @@ -43,40 +46,36 @@ void Input::EnableInput(bool toggle)
}
}

void Input::Draw(jc::HDevice_t *device)
void Input::Draw()
{
auto debug_renderer = jc::CRenderEngine::instance().m_debugRenderer;

static const float _hintItemHeight = 0.02f;
static const float _fontSizeInput = 0.0155f;
static const float _fontSizeHint = 0.0133f;

if (m_drawInput && (device && debug_renderer)) {
if (m_drawInput && debug_renderer) {
// draw hints
if (m_cmd && m_hints.size() > 0) {
const auto count = std::clamp<uint32_t>((m_hints.size() - m_hintPage), 0, _numHintsPerPage);
const float total_height = (_hintItemHeight * count);
const auto count = std::clamp<uint32_t>((m_hints.size() - m_hintPage), 0, NUM_HINTS_PER_PAGE);
const float total_height = (HINT_ITEM_HEIGHT * count);

debug_renderer->DebugRectGradient({0, (0.94f - total_height - 0.02f)}, {0.5f, 0.94f}, 0xB4000000,
0x00000000);

for (uint32_t i = 0; i < count; ++i) {
// draw current hint
const float y = (0.9325f - total_height + (_hintItemHeight * i));
Graphics::Get()->DrawString(m_hints[i + m_hintPage], 0.0195f, y, _fontSizeHint, 0xFFFFFFFF);
const float y = (0.9325f - total_height + (HINT_ITEM_HEIGHT * i));
Graphics::Get()->DrawString(m_hints[i + m_hintPage], 0.0195f, y, FONT_SIZE_HINT, 0xFFFFFFFF);

if ((i + m_hintPage) == m_selectedHint) {
Graphics::Get()->DrawString("> ", 0.0078f, y, _fontSizeHint, 0xFFFFFFFF);
Graphics::Get()->DrawString("> ", 0.0078f, y, FONT_SIZE_HINT, 0xFFFFFFFF);
}
}
}

// draw current input text
debug_renderer->DebugRectGradient({0, 0.95f}, {0.5f, 1}, 0xE1000000, 0x00000000);
Graphics::Get()->DrawString(m_history[0], 0.0195f, 0.965f, _fontSizeInput, 0xFFFFFFFF);
Graphics::Get()->DrawString(m_history[0], 0.0195f, 0.965f, FONT_SIZE_INPUT, 0xFFFFFFFF);

if (m_selectedHint == -1) {
Graphics::Get()->DrawString("> ", 0.0078f, 0.965f, _fontSizeInput, 0xFFFFFFFF);
Graphics::Get()->DrawString("> ", 0.0078f, 0.965f, FONT_SIZE_INPUT, 0xFFFFFFFF);
}
}
}
Expand Down Expand Up @@ -144,8 +143,8 @@ bool Input::WndProc(uint32_t message, WPARAM wParam, LPARAM lParam)
}
// previous hint item
else {
if ((m_selectedHint % _numHintsPerPage) == 0) {
m_hintPage = std::max((m_hintPage - _numHintsPerPage), 0);
if ((m_selectedHint % NUM_HINTS_PER_PAGE) == 0) {
m_hintPage = std::max((m_hintPage - NUM_HINTS_PER_PAGE), 0);
}

m_selectedHint = std::max(--m_selectedHint, 0);
Expand Down Expand Up @@ -174,8 +173,8 @@ bool Input::WndProc(uint32_t message, WPARAM wParam, LPARAM lParam)
if (m_selectedHint != (size - 1)) {
++m_selectedHint;

if (size > _numHintsPerPage && (m_selectedHint % _numHintsPerPage) == 0) {
m_hintPage += _numHintsPerPage;
if (size > NUM_HINTS_PER_PAGE && (m_selectedHint % NUM_HINTS_PER_PAGE) == 0) {
m_hintPage += NUM_HINTS_PER_PAGE;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Input : public Singleton<Input>
using command_t = std::function<void(const std::string& arguments)>;

private:
bool m_drawInput = false;
bool m_drawInput = false;
std::vector<std::string> m_history = {""};
int32_t m_currentHistory = 0;
ICommand* m_cmd = nullptr;
Expand Down Expand Up @@ -57,6 +57,6 @@ class Input : public Singleton<Input>
return m_drawInput;
}

void Draw(jc::HDevice_t* device);
void Draw();
bool WndProc(uint32_t message, WPARAM wParam, LPARAM lParam);
};
18 changes: 9 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
}

// if we are running on the wrong version, don't continue
if (*(uint32_t *)0x141E28818 != 0x6c617641) {
if (*(uint32_t *)0x141E732B8 != 0x6c617641) {
#ifdef DEBUG
MessageBox(nullptr, "Wrong version.", nullptr, MB_ICONERROR | MB_OK);
#endif
Expand All @@ -64,19 +64,19 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
// enable quick start
if (quick_start) {
// quick start
hk::put<bool>(0x142C55374, true);
hk::put<bool>(0x142CABF28, true);

// IsIntroSequenceComplete always returns true
hk::put<uint32_t>(0x140E4D670, 0x90C301B0);
hk::put<uint32_t>(0x140E8B1D0, 0x90C301B0);

// IsIntroMovieComplete always returns true
hk::put<uint32_t>(0x140E4D5F0, 0x90C301B0);
hk::put<uint32_t>(0x140E8B150, 0x90C301B0);
}

static hk::inject_jump<LRESULT, HWND, UINT, WPARAM, LPARAM> wndproc(0x140C3F100);
static hk::inject_jump<LRESULT, HWND, UINT, WPARAM, LPARAM> wndproc(0x140C77880);
wndproc.inject([](HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -> LRESULT {
auto game_state = *(uint32_t *)0x142C5532C;
auto suspend_game = *(bool *)0x142C59B68;
auto game_state = *(uint32_t *)0x142CABF0C;
auto suspend_game = *(bool *)0x142CB0B48;
auto clock = &jc::Base::CClock::instance();

if (game_state == 3 && clock) {
Expand All @@ -95,12 +95,12 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
return wndproc.call(hwnd, uMsg, wParam, lParam);
});

static hk::inject_jump<void, jc::HDevice_t *> flip(0x140F57AF0);
static hk::inject_jump<void, jc::HDevice_t *> flip(0x140F97DC0);
flip.inject([](jc::HDevice_t *device) -> void {
Graphics::Get()->BeginDraw(device);

// draw input
Input::Get()->Draw(device);
Input::Get()->Draw();

Graphics::Get()->EndDraw();

Expand Down

0 comments on commit f1bd4b2

Please sign in to comment.