Skip to content

Commit 3fc04a8

Browse files
committed
0.7.0.771 version support
1 parent 99fcf5d commit 3fc04a8

25 files changed

+616
-76
lines changed

Code/DynamicSun.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include "DynamicSun.hpp"
22

33
#include "GameInstanceData.hpp"
4+
#include <SmSdk/GameState.hpp>
45

56
#include "Utils/Console.hpp"
7+
#include "offsets.hpp"
68

79
float DynamicSun::GetSunAngle()
810
{
@@ -20,7 +22,7 @@ DirectX::XMVECTOR DynamicSun::ComputeQuatFromAngle(float angle)
2022

2123
DirectX::XMFLOAT3& DynamicSun::GetLightDirection()
2224
{
23-
return *Memory::Read<DirectX::XMFLOAT3*>(0x11D32C0);
25+
return *Memory::Read<DirectX::XMFLOAT3*>(DYNAMIC_SUN_DIRECTION_OFFSET);
2426
}
2527

2628
inline static float lerp_float(float a, float b, float f)

Code/GameInstanceData.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#pragma once
22

33
#include <SmSdk/Util/Memory.hpp>
4+
#include "offsets.hpp"
45

56
struct GameInstanceData
67
{
78
float time_of_day;
89

910
inline static GameInstanceData* GetInstance()
1011
{
11-
return *Memory::ReadPtr<GameInstanceData*>(0x128D790);
12+
return *Memory::ReadPtr<GameInstanceData*>(DYNAMIC_SUN_GAME_INSTANCE_PTR);
1213
}
1314
};

Code/GraphicsOptionsMenu.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "GameInstanceData.hpp"
88
#include "Utils/Console.hpp"
99
#include "DynamicSun.hpp"
10+
#include "offsets.hpp"
1011

1112
constexpr float g_minSunAngle = DirectX::XMConvertToRadians(-70.0f);
1213
constexpr float g_maxSunAngle = DirectX::XMConvertToRadians(70.0f);
@@ -52,7 +53,7 @@ class SunAngleSlider : public OptionsItemSlider
5253

5354
__int64 GraphicsOptionsMenu::h_CreateWidgets(GraphicsOptionsMenu* self)
5455
{
55-
if (Memory::ToLocalAddress(*reinterpret_cast<void**>(self)) == 0xF65600)
56+
if (Memory::ToLocalAddress(*reinterpret_cast<void**>(self)) == DYNAMIC_SUN_GRAPHICS_OPTIONS_MENU_VFTABLE)
5657
{
5758
DebugOutL(__FUNCTION__, " -> Injected custom game settings");
5859

Code/Utils/ConColors.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "win_include.hpp"
3+
#include <SmSdk/win_include.hpp>
44

55
class EngineConColor
66
{

Code/Utils/Console.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#if defined(_DEBUG) || !defined(_DEBUG)
44

5-
#include "win_include.hpp"
5+
#include <SmSdk/win_include.hpp>
66
#include "ConColors.hpp"
77

88
#include <sstream>

Code/main.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1-
#include "win_include.hpp"
1+
#include <SmSdk/TimestampCheck.hpp>
2+
#include <SmSdk/win_include.hpp>
23

34
#include "Utils/Console.hpp"
5+
#include "offsets.hpp"
46

57
#include "GraphicsOptionsMenu.hpp"
68
#include "DynamicSun.hpp"
79

810
#include <MinHook.h>
911

12+
#pragma comment(lib, "User32.lib")
13+
1014
static bool ms_mhInitialized = false;
1115
static bool ms_mhHooksAttached = false;
1216

1317
void process_attach()
1418
{
19+
if (!SmSdk::CheckTimestamp(_SM_TIMESTAMP_070_771))
20+
{
21+
MessageBoxA(
22+
NULL,
23+
"Your game version is unsupposed by Dynamic Sun. The current version of the mod has been built for Scrap Mechanic 0.7.0.771",
24+
"Unsupported Version",
25+
MB_ICONWARNING);
26+
return;
27+
}
28+
1529
AttachDebugConsole();
1630

1731
if (MH_Initialize() != MH_OK)
@@ -23,12 +37,11 @@ void process_attach()
2337
ms_mhInitialized = true;
2438

2539
const std::uintptr_t v_mod_base = std::uintptr_t(GetModuleHandle(NULL));
26-
MH_CreateHook((LPVOID)(v_mod_base + 0x909880),
40+
MH_CreateHook((LPVOID)(v_mod_base + DYNAMIC_SUN_UPDATE_FUNC_ADDR),
2741
(LPVOID)DynamicSun::Update,
2842
(LPVOID*)&DynamicSun::o_PresentFunction);
29-
30-
//0x35D8E0 - is the actual address, but i have to call the function before the end
31-
MH_CreateHook((LPVOID)(v_mod_base + 0x3CDFA0),
43+
// (0.6.6) 0x35D8E0 - is the actual address, but i have to call the function before the end
44+
MH_CreateHook((LPVOID)(v_mod_base + DYNAMIC_SUN_CREATE_WIDGETS_ADDR),
3245
(LPVOID)GraphicsOptionsMenu::h_CreateWidgets,
3346
(LPVOID*)&GraphicsOptionsMenu::o_CreateWidgets);
3447

Code/offsets.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <SmSdk/offsets.hpp>
4+
5+
#if defined(_SM_VERSION_070_771)
6+
# define DYNAMIC_SUN_UPDATE_FUNC_ADDR 0x915630
7+
# define DYNAMIC_SUN_CREATE_WIDGETS_ADDR 0x3C0390
8+
# define DYNAMIC_SUN_GRAPHICS_OPTIONS_MENU_VFTABLE 0xF7ACF8
9+
# define DYNAMIC_SUN_DIRECTION_OFFSET 0x11D5CB0
10+
# define DYNAMIC_SUN_GAME_INSTANCE_PTR 0x1267720
11+
#else
12+
# define DYNAMIC_SUN_UPDATE_FUNC_ADDR 0x909880
13+
# define DYNAMIC_SUN_CREATE_WIDGETS_ADDR 0x3CDFA0
14+
# define DYNAMIC_SUN_GRAPHICS_OPTIONS_MENU_VFTABLE 0xF65600
15+
# define DYNAMIC_SUN_DIRECTION_OFFSET 0x11D32C0
16+
# define DYNAMIC_SUN_GAME_INSTANCE_PTR 0x128D790
17+
#endif

Code/win_include.hpp

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#pragma once
2+
3+
#include "SmSdk/Physics/AreaTriggerProxy.hpp"
4+
#include "SmSdk/bullet_include.hpp"
5+
#include "SmSdk/Base/Task.hpp"
6+
7+
#include <DirectXMath.h>
8+
#include <concrt.h>
9+
10+
#include <unordered_map>
11+
#include <vector>
12+
13+
struct AreaTrigger
14+
{
15+
/* 0x0000 */ __int32 m_id;
16+
/* 0x0004 */ __int16 m_worldId;
17+
private:
18+
/* 0x0006 */ char pad_0x6[0xE];
19+
public:
20+
/* 0x0014 */ unsigned __int32 m_filter;
21+
private:
22+
/* 0x0018 */ char pad_0x18[0xC];
23+
public:
24+
/* 0x0024 */ unsigned __int32 m_someFlag;
25+
private:
26+
/* 0x0028 */ char pad_0x28[0x4];
27+
public:
28+
/* 0x002C */ bool m_bWaterTrigger;
29+
private:
30+
/* 0x002D */ char pad_0x2D[0x3];
31+
public:
32+
/* 0x0030 */ btBoxShape* m_pBoxShape;
33+
/* 0x0038 */ btPairCachingGhostObject* m_pGhostObject;
34+
/* 0x0040 */ AreaTriggerProxy* m_pPhysicsProxy;
35+
private:
36+
/* 0x0048 */ char pad_0x48[0x100];
37+
public:
38+
/* 0x0148 */ DirectX::XMFLOAT3 m_position;
39+
/* 0x0154 */ DirectX::XMFLOAT4 m_rotation;
40+
/* 0x0164 */ DirectX::XMFLOAT3 m_size;
41+
private:
42+
/* 0x0170 */ char pad_0x170[0x8];
43+
}; // Size: 0x178
44+
45+
static_assert(offsetof(AreaTrigger, AreaTrigger::m_id) == 0x0, "AreaTrigger::m_id: Incorrect offset");
46+
static_assert(offsetof(AreaTrigger, AreaTrigger::m_worldId) == 0x4, "AreaTrigger::m_worldId: Incorrect offset");
47+
static_assert(offsetof(AreaTrigger, AreaTrigger::m_filter) == 0x14, "AreaTrigger::m_filter: Incorrect offset");
48+
static_assert(offsetof(AreaTrigger, AreaTrigger::m_someFlag) == 0x24, "AreaTrigger::m_someFlag: Incorrect offset");
49+
static_assert(offsetof(AreaTrigger, AreaTrigger::m_bWaterTrigger) == 0x2C, "AreaTrigger::m_bWaterTrigger: Incorrect offset");
50+
static_assert(offsetof(AreaTrigger, AreaTrigger::m_pBoxShape) == 0x30, "AreaTrigger::m_pBoxShape: Incorrect offset");
51+
static_assert(offsetof(AreaTrigger, AreaTrigger::m_pGhostObject) == 0x38, "AreaTrigger::m_pGhostObject: Incorrect offset");
52+
static_assert(offsetof(AreaTrigger, AreaTrigger::m_pPhysicsProxy) == 0x40, "AreaTrigger::m_pPhysicsProxy: Incorrect offset");
53+
static_assert(offsetof(AreaTrigger, AreaTrigger::m_position) == 0x148, "AreaTrigger::m_position: Incorrect offset");
54+
static_assert(offsetof(AreaTrigger, AreaTrigger::m_rotation) == 0x154, "AreaTrigger::m_rotation: Incorrect offset");
55+
static_assert(offsetof(AreaTrigger, AreaTrigger::m_size) == 0x164, "AreaTrigger::m_size: Incorrect offset");
56+
57+
static_assert(sizeof(AreaTrigger) == 0x178, "AreaTrigger: Incorrect Size");
58+
59+
60+
61+
struct AreaTriggerWorld
62+
{
63+
/* 0x0000 */ unsigned __int16 m_worldId;
64+
private:
65+
/* 0x0002 */ char pad_0x2[0x6];
66+
public:
67+
/* 0x0008 */ std::map<int, AreaTrigger*> m_mapAreaTriggers;
68+
/* 0x0018 */ std::vector<AreaTrigger*> m_vecAreaTriggerQueue;
69+
private:
70+
/* 0x0030 */ char pad_0x30[0x18];
71+
}; // Size: 0x48
72+
73+
static_assert(offsetof(AreaTriggerWorld, AreaTriggerWorld::m_worldId) == 0x0, "AreaTriggerWorld::m_worldId: Incorrect offset");
74+
static_assert(offsetof(AreaTriggerWorld, AreaTriggerWorld::m_mapAreaTriggers) == 0x8, "AreaTriggerWorld::m_mapAreaTriggers: Incorrect offset");
75+
static_assert(offsetof(AreaTriggerWorld, AreaTriggerWorld::m_vecAreaTriggerQueue) == 0x18, "AreaTriggerWorld::m_vecAreaTriggerQueue: Incorrect offset");
76+
77+
static_assert(sizeof(AreaTriggerWorld) == 0x48, "AreaTriggerWorld: Incorrect Size");
78+
79+
80+
81+
struct AreaTriggerManager : public Task
82+
{
83+
static AreaTriggerManager* GetInstance();
84+
85+
/* 0x0008 */ Concurrency::event m_event;
86+
/* 0x0050 */ unsigned __int32 m_areaTriggerIdCounter;
87+
private:
88+
/* 0x0054 */ char pad_0x54[0x4];
89+
public:
90+
/* 0x0058 */ std::unordered_map<std::uint16_t, AreaTriggerWorld> m_mapAreaTriggerWorlds;
91+
/* 0x0098 */ std::vector<AreaTrigger*> m_vecAreaTriggers;
92+
private:
93+
/* 0x00B0 */ char pad_0xB0[0x10];
94+
95+
}; // Size: 0xC0
96+
97+
static_assert(offsetof(AreaTriggerManager, AreaTriggerManager::m_event) == 0x8, "AreaTriggerManager::m_event: Incorrect offset");
98+
static_assert(offsetof(AreaTriggerManager, AreaTriggerManager::m_areaTriggerIdCounter) == 0x50, "AreaTriggerManager::m_areaTriggerIdCounter: Incorrect offset");
99+
static_assert(offsetof(AreaTriggerManager, AreaTriggerManager::m_mapAreaTriggerWorlds) == 0x58, "AreaTriggerManager::m_mapAreaTriggerWorlds: Incorrect offset");
100+
static_assert(offsetof(AreaTriggerManager, AreaTriggerManager::m_vecAreaTriggers) == 0x98, "AreaTriggerManager::m_vecAreaTriggers: Incorrect offset");
101+
102+
static_assert(sizeof(AreaTriggerManager) == 0xC0, "AreaTriggerManager: Incorrect Size");

0 commit comments

Comments
 (0)