generated from Martinii89/BakkesmodPluginTemplateV2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chain.cpp
192 lines (157 loc) · 4.63 KB
/
Chain.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
#include "pch.h"
#include "Chain.h"
#include "glfw3.h"
#include "glfw3native.h"
BAKKESMOD_PLUGIN(Chain, "Chaindash on wall", plugin_version, PLUGINTYPE_FREEPLAY)
std::shared_ptr<CVarManagerWrapper> _globalCvarManager;
void Chain::onLoad()
{
//variables
_globalCvarManager = cvarManager;
cvarManager->log("Chain loaded!");
//initialize glfw
glfwInit();
//checks if joystick 0 is connected
//why did i do it like this
if (glfwJoystickPresent(GLFW_JOYSTICK_1))
{
cvarManager->log("Controller detected :)");
useController = true;
//maps settings
SettingsWrapper settings = gameWrapper->GetSettings();
std::vector<std::pair<std::string, std::string>> binds = settings.GetAllPCBindings();
controlArr[0] = (char)binds.at(0).first[0]; //forward key into int
controlArr[1] = (char)binds.at(2).first[0]; //steer right
controlArr[2] = (char)binds.at(12).first[0];//air roll right
controlArr[3] = (char)binds.at(13).first[0];//air roll left
controlArr[4] = (char)binds.at(15).first[0];//jump
}
else
{
useController = false;
SettingsWrapper settings = gameWrapper->GetSettings();
std::vector<std::pair<std::string, std::string>> binds = settings.GetAllPCBindings();
controlArr[0] = (char)binds.at(0).first[0]; //forward key into int
controlArr[1] = (char)binds.at(2).first[0]; //steer right
controlArr[2] = (char)binds.at(12).first[0];//air roll right
controlArr[3] = (char)binds.at(13).first[0];//air roll left
controlArr[4] = (char)binds.at(15).first[0];//jump
}
//starts thread and hooks every frame you are playing
t = this->startT();
gameWrapper->HookEvent("Function TAGame.Car_TA.SetVehicleInput",
[&](std::string eventName) {
car = gameWrapper->GetLocalCar();
roll = car.GetRotation().Roll;
isOnWall = car.IsOnWall();
isOnGround = car.IsOnGround();
hasFlip = car.HasFlip();
});
}
void Chain::gameLoop()
{
while (looping)
{
if (car)
{
//could reorganize this
if (glfwJoystickPresent(GLFW_JOYSTICK_1))
{
int buttonCount;
const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttonCount);
if (buttons[2] == GLFW_PRESS)
{
if (isOnWall && (roll < 0))
{
cvarManager->log("Chain dash right");
//air roll right if < 0
func.chainDashRight(controlArr[0], controlArr[2], controlArr[4], useController);
}
else if (isOnWall && (roll > 0))
{
cvarManager->log("Chain dash left");
//air roll left if > 0
func.chainDashLeft(controlArr[0], controlArr[3], controlArr[4], useController);
}
else if (!isOnGround && !isOnWall /* && hasFlip*/)
{
//hasflip doesnt work in game must patch binary
cvarManager->log("Stall");
//stall if not on ground and not on wall and has flip
func.stall(controlArr[1], controlArr[3], controlArr[4], useController);
}
}
}
else
{
//set to f by default
if (GetAsyncKeyState(0x46))
{
if (isOnWall && (roll < 0))
{
cvarManager->log("Chain dash right");
//air roll right if < 0
func.chainDashRight(controlArr[0], controlArr[2], controlArr[4], useController);
//worker = std::thread(&funcs::chainDashRight, func, controlArr[0], controlArr[2], controlArr[4]);
}
else if (isOnWall && (roll > 0))
{
cvarManager->log("Chain dash left");
//air roll left if > 0
func.chainDashLeft(controlArr[0], controlArr[3], controlArr[4], useController);
}
else if (!isOnGround && !isOnWall /* && hasFlip*/ )
{
cvarManager->log("Stall");
//stall if not on ground and not on wall and has flip
func.stall(controlArr[1], controlArr[3], controlArr[4], useController);
}
}
}
}
}
}
void Chain::testing()
{
while (looping)
{
//cvarManager->log("inside");
if (car)
{
int buttonCount;
const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttonCount);
if (buttons[2] == GLFW_PRESS)
{
cvarManager->log("IsOnWall: " + std::to_string(isOnWall));
cvarManager->log("isOnGround: " + std::to_string(isOnGround));
cvarManager->log("Car Roll: " + std::to_string(roll));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
}
//std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
while (true)
{
CarWrapper car = gameWrapper->GetLocalCar();
if (car)
{
std::string roll = std::to_string(car.GetRotation().Roll);
cvarManager->log(roll);
}
else
{
cvarManager->log("Car is NULL");
}
}
}
std::thread Chain::startT()
{
return std::thread(&Chain::gameLoop, this);
}
void Chain::onUnload()
{
//unload everything
looping = false;
t.join();
glfwTerminate();
}