-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
223 lines (201 loc) · 5.49 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include "nvse/nvse/PluginAPI.h"
#include "nvse/nvse/nvse_version.h"
#include "nvse/nvse/SafeWrite.h"
#include "GameObjects.h"
void patchOpenPipboy();
bool versionCheck(const NVSEInterface* nvse);
void handleIniOptions();
HMODULE stewieTweakHandle;
int g_bShowMessage = 1;
int g_bPipboyUseActionPoints = 0;
int g_iPipboyAPCost = 50;
/* credits to JazzIsParis */
enum ActorValueCode
{
kAVCode_Aggression,
kAVCode_Confidence,
kAVCode_Energy,
kAVCode_Responsibility,
kAVCode_Mood,
kAVCode_Strength,
kAVCode_Perception,
kAVCode_Endurance,
kAVCode_Charisma,
kAVCode_Intelligence,
kAVCode_Agility,
kAVCode_Luck,
kAVCode_ActionPoints,
kAVCode_CarryWeight,
kAVCode_CritChance,
kAVCode_HealRate,
kAVCode_Health,
kAVCode_MeleeDamage,
kAVCode_DamageResist,
kAVCode_PoisonResist,
kAVCode_RadResist,
kAVCode_SpeedMult,
kAVCode_Fatigue,
kAVCode_Karma,
kAVCode_XP,
kAVCode_PerceptionCondition,
kAVCode_EnduranceCondition,
kAVCode_LeftAttackCondition,
kAVCode_RightAttackCondition,
kAVCode_LeftMobilityCondition,
kAVCode_RightMobilityCondition,
kAVCode_BrainCondition,
kAVCode_Barter,
kAVCode_BigGuns,
kAVCode_EnergyWeapons,
kAVCode_Explosives,
kAVCode_Lockpick,
kAVCode_Medicine,
kAVCode_MeleeWeapons,
kAVCode_Repair,
kAVCode_Science,
kAVCode_Guns,
kAVCode_Sneak,
kAVCode_Speech,
kAVCode_Survival,
kAVCode_Unarmed,
kAVCode_InventoryWeight,
kAVCode_Paralysis,
kAVCode_Invisibility,
kAVCode_Chameleon,
kAVCode_NightEye,
kAVCode_Turbo,
kAVCode_FireResist,
kAVCode_WaterBreathing,
kAVCode_RadiationRads,
kAVCode_BloodyMess,
kAVCode_UnarmedDamage,
kAVCode_Assistance,
kAVCode_ElectricResist,
kAVCode_FrostResist,
kAVCode_EnergyResist,
kAVCode_EmpResist,
kAVCode_Variable01,
kAVCode_Variable02,
kAVCode_Variable03,
kAVCode_Variable04,
kAVCode_Variable05,
kAVCode_Variable06,
kAVCode_Variable07,
kAVCode_Variable08,
kAVCode_Variable09,
kAVCode_Variable10,
kAVCode_IgnoreCrippledLimbs,
kAVCode_Dehydration,
kAVCode_Hunger,
kAVCode_SleepDeprivation,
kAVCode_DamageThreshold,
};
extern "C" {
BOOL WINAPI DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) {
if (dwReason == DLL_PROCESS_ATTACH)
stewieTweakHandle = (HMODULE)hDllHandle;
return TRUE;
}
bool NVSEPlugin_Query(const NVSEInterface *nvse, PluginInfo *info) {
/* fill out the info structure */
info->infoVersion = PluginInfo::kInfoVersion;
info->name = "No Pipboy In Combat";
info->version = 1;
handleIniOptions();
return versionCheck(nvse);
}
bool NVSEPlugin_Load(const NVSEInterface *nvse) {
patchOpenPipboy();
return true;
}
};
void handleIniOptions() {
char filename[MAX_PATH];
GetModuleFileNameA(stewieTweakHandle, filename, MAX_PATH);
strcpy((char *)(strrchr(filename, '\\') + 1), "nvse_no_pipboy_in_combat.ini");
g_bShowMessage = GetPrivateProfileIntA("Main", "bShowMessage", 1, filename);
g_bPipboyUseActionPoints = GetPrivateProfileIntA("Main", "bAllowPipboyUsingActionPoints", 0, filename);
g_iPipboyAPCost = GetPrivateProfileIntA("Main", "bPipboyAPCost", 50, filename);
}
bool __stdcall playerInDanger() {
PlayerCharacter* g_thePlayer = *(PlayerCharacter**)0x11DEA3C;
return g_thePlayer->pcInCombat && !g_thePlayer->pcUnseen;
}
/* credits to JazzIsParis */
__declspec(naked) float GetPCActionPoints() {
static const UInt32 kAddr_GetActorValue = 0x66EF50;
static PlayerCharacter* g_thePlayer = *(PlayerCharacter**)0x11DEA3C;
__asm
{
push kAVCode_ActionPoints
mov ecx, g_thePlayer
add ecx, 0xA4
mov eax, kAddr_GetActorValue
call eax
retn
}
}
bool __stdcall tryDecreaseAP() {
PlayerCharacter* g_thePlayer = *(PlayerCharacter**)0x11DEA3C;
if (GetPCActionPoints() >= g_iPipboyAPCost) {
g_thePlayer->DamageActorValue(kAVCode_ActionPoints, -g_iPipboyAPCost, NULL);
return true;
}
return false;
}
__declspec(naked) void hookCheckTabKey() {
static const UInt32 retnAddr = 0x70E913;
static const UInt32 skipAddr = 0x70E91D;
if (playerInDanger() && !(g_bPipboyUseActionPoints && tryDecreaseAP())) {
if (g_bShowMessage) {
if (g_bPipboyUseActionPoints) QueueUIMessage("Not enough AP to use pipboy in combat!", pain, NULL, NULL, 1.0F, false);
else QueueUIMessage("You cannot use your PipBoy in combat!", pain, NULL, NULL, 1.0F, false);
}
_asm {
jmp skipAddr
}
}
else {
_asm {
originalcode:
push 00
push 00
mov ecx, [ebp - 0xCC]
jmp retnAddr
}
}
}
__declspec(naked) void hookCheckFunctionKeys() {
static const UInt32 retnAddr = 0x70EA2E;
static const UInt32 skipAddr = 0x70EA39;
if (playerInDanger() && !(g_bPipboyUseActionPoints && tryDecreaseAP())) {
if (g_bShowMessage) {
if(g_bPipboyUseActionPoints) QueueUIMessage("Not enough AP to use pipboy in combat!", pain, NULL, NULL, 1.0F, false);
else QueueUIMessage("You cannot use your PipBoy in combat!", pain, NULL, NULL, 1.0F, false);
}
_asm {
jmp skipAddr
}
}
else {
_asm {
originalcode:
mov ecx, [ebp - 0x28]
push ecx
push 00
jmp retnAddr
}
}
}
void patchOpenPipboy() {
WriteRelJump(0x70E909, (UInt32)hookCheckTabKey);
WriteRelJump(0x70EA28, (UInt32)hookCheckFunctionKeys);
}
bool versionCheck(const NVSEInterface* nvse) {
if (nvse->isEditor) return false;
if (nvse->nvseVersion < NVSE_VERSION_INTEGER) {
_ERROR("NVSE version too old (got %08X expected at least %08X)", nvse->nvseVersion, NVSE_VERSION_INTEGER);
return false;
}
return true;
}