Skip to content

Commit f7c3b87

Browse files
committed
Various improvements and cleanup
1 parent 860d2ca commit f7c3b87

3 files changed

Lines changed: 64 additions & 24 deletions

File tree

C2ModLoader/Input/MidAirTurning.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace Input::MidAirTurning {
1919

2020
bool midAirTurning;
2121

22+
const int turnSpeed = 64 << 12;
23+
2224
void __stdcall doMidAirTurning() {
2325
if (!midAirTurning || GetControlScheme() != CTRL_TYPE_2)
2426
return;
@@ -28,9 +30,9 @@ void __stdcall doMidAirTurning() {
2830
if (croc->localVars[CROC_VAR_IN_AIR] == 4096) {
2931
Inputs inputs = api->GetInputs();
3032
if (inputs.stepLeft)
31-
croc->newRotPos.rotation.y += 0x40000;
33+
croc->newRotPos.rotation.y += turnSpeed;
3234
if (inputs.stepRight)
33-
croc->newRotPos.rotation.y -= 0x40000;
35+
croc->newRotPos.rotation.y -= turnSpeed;
3436
}
3537
}
3638
}

C2ModLoader/Overlay/Components/Minimap.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ constexpr double PI = 3.14159265358979323846;
1717
constexpr float MINIMAP_ZOOM_MIN = 0.05f;
1818
constexpr float MINIMAP_ZOOM_MAX = 1.0f;
1919
constexpr float MINIMAP_ZOOM_SCROLL_STEP = 0.05f;
20+
constexpr float MINIMAP_ZOOM_INTERPOLATION_SPEED = 12.0f;
2021
constexpr float MINIMAP_DRAG_HANDLE_HEIGHT = 12.0f;
2122

2223
float ClampMinimapZoom(float zoom) {
@@ -57,10 +58,22 @@ MapDot getMapDot(const StratEntity *object) {
5758

5859
// Crystals
5960
if (strncmp(object->name, "crystal", 7) == 0)
60-
return MapDot{ImVec4(0.25f, 0.75f, 1.0f, 1.0f), MapDotShape::Diamond, 5.0f, false};
61-
62-
if (strncmp(object->name, "bonus crystal", 13) == 0)
63-
return MapDot{ImVec4(0.45f, 0.95f, 1.0f, 1.0f), MapDotShape::Diamond, 8.0f, true};
61+
return MapDot{ImVec4(0.5f, 0.75f, 1.0f, 1.0f), MapDotShape::Diamond, 5.0f, false};
62+
63+
if (strncmp(object->name, "bonus crystal", 13) == 0) {
64+
switch (object->localVars[0] >> 12) {
65+
case 0: // Red Crystal
66+
return MapDot{ImVec4(1.0f, 0.25f, 0.25f, 1.0f), MapDotShape::Diamond, 8.0f, true};
67+
case 1: // Green Crystal
68+
return MapDot{ImVec4(0.25f, 1.0f, 0.25f, 1.0f), MapDotShape::Diamond, 8.0f, true};
69+
case 2: // Purple Crystal
70+
return MapDot{ImVec4(1.0f, 0.25f, 1.0f, 1.0f), MapDotShape::Diamond, 8.0f, true};
71+
case 3: // Blue Crystal
72+
return MapDot{ImVec4(0.25f, 0.25f, 1.0f, 1.0f), MapDotShape::Diamond, 8.0f, true};
73+
case 4: // Yellow Crystal
74+
return MapDot{ImVec4(1.0f, 1.0f, 0.25f, 1.0f), MapDotShape::Diamond, 8.0f, true};
75+
}
76+
}
6477

6578
if (strncmp(object->name, "Smash Box", 9) == 0)
6679
return MapDot{ImVec4(0.95f, 0.5f, 0.25f, 1.0f), MapDotShape::Square, 8.0f, false};
@@ -118,6 +131,7 @@ namespace Overlay::Minimap {
118131

119132
bool showMinimap;
120133
float minimapZoom;
134+
float minimapRenderZoom;
121135
bool minimapAutoRotate;
122136

123137
enum class MinimapStyle {
@@ -129,6 +143,7 @@ MinimapStyle minimapStyle;
129143
void Setup() {
130144
showMinimap = api->SetupIniBool(L"GUI", L"ShowMinimap", false);
131145
minimapZoom = ClampMinimapZoom(api->SetupIniFloat(L"GUI", L"MinimapZoom", MINIMAP_ZOOM_MAX));
146+
minimapRenderZoom = minimapZoom;
132147
minimapAutoRotate = api->SetupIniBool(L"GUI", L"MinimapAutoRotate", true);
133148
minimapStyle = static_cast<MinimapStyle>(api->SetupIniInt(L"GUI", L"MinimapStyle", static_cast<int>(MinimapStyle::Circle)));
134149
}
@@ -184,7 +199,16 @@ void RenderMinimap() {
184199
cameraDistanceMultiplier = cameraDistance / baselineCameraDistance;
185200
}
186201

187-
const float zoom = (std::max)(minimapZoom / cameraDistanceMultiplier, MINIMAP_ZOOM_MIN);
202+
const float safeCameraDistanceMultiplier = (std::max)(cameraDistanceMultiplier, 0.001f);
203+
const float targetZoom = (std::max)(minimapZoom / safeCameraDistanceMultiplier, MINIMAP_ZOOM_MIN);
204+
const float deltaTime = (std::max)(ImGui::GetIO().DeltaTime, 0.0f);
205+
const float interpolationAlpha = 1.0f - std::exp(-MINIMAP_ZOOM_INTERPOLATION_SPEED * deltaTime);
206+
minimapRenderZoom += (targetZoom - minimapRenderZoom) * interpolationAlpha;
207+
208+
minimapRenderZoom = (std::min)(minimapRenderZoom, MINIMAP_ZOOM_MAX);
209+
minimapRenderZoom = (std::max)(minimapRenderZoom, MINIMAP_ZOOM_MIN);
210+
211+
const float zoom = minimapRenderZoom;
188212
const float scale = mapRadius * zoom / worldRadius;
189213
const float crocRotationRadians = hasCroc ? (float)GameRotationToRadians(crocObject->newRotPos.rotation.y >> 12) : 0.0f;
190214
const float cameraYawRadians = (cameraRot != nullptr) ? (float)GameRotationToRadians(cameraRot->y) : -crocRotationRadians;

C2ModLoader/Overlay/Components/ObjectList.cpp

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ std::string formatAddress(uintptr_t addr) {
7676
return ss.str();
7777
}
7878

79-
void RenderObjectDetailsContent(StratEntity *entity, StratEntity *playerObject) {
79+
void RenderObjectDetailsContent(StratEntity *entity, StratEntity *croc) {
8080
if (entity == nullptr) {
8181
ImGui::Text("Object no longer valid");
8282
return;
@@ -102,6 +102,10 @@ void RenderObjectDetailsContent(StratEntity *entity, StratEntity *playerObject)
102102

103103
ImGui::Spacing();
104104

105+
ImGui::InputInt("Vertical Velocity##vertvel_", &(entity->verticalVelocity), 0, 0);
106+
107+
ImGui::Spacing();
108+
105109
ImGui::Text((std::string("Distance from player: ") + std::to_string(entity->distanceToPlayer)).c_str());
106110

107111
ImGui::Separator();
@@ -116,34 +120,34 @@ void RenderObjectDetailsContent(StratEntity *entity, StratEntity *playerObject)
116120

117121
ImGui::Text("Actions");
118122
if (ImGui::Button((std::string("Teleport Here##tphere_") + idSuffix).c_str())) {
119-
if (playerObject != nullptr) {
120-
entity->newPosition.x = playerObject->newPosition.x;
121-
entity->newPosition.y = playerObject->newPosition.y;
122-
entity->newPosition.z = playerObject->newPosition.z;
123+
if (croc != nullptr) {
124+
entity->newPosition.x = croc->newPosition.x;
125+
entity->newPosition.y = croc->newPosition.y;
126+
entity->newPosition.z = croc->newPosition.z;
123127
}
124128
}
125129
ImGui::SameLine();
126130
if (ImGui::Button((std::string("Teleport Start Here##tpstarthere_") + idSuffix).c_str())) {
127-
if (playerObject != nullptr) {
128-
entity->StartRotPos.position.x = playerObject->newPosition.x;
129-
entity->StartRotPos.position.y = playerObject->newPosition.y;
130-
entity->StartRotPos.position.z = playerObject->newPosition.z;
131+
if (croc != nullptr) {
132+
entity->StartRotPos.position.x = croc->newPosition.x;
133+
entity->StartRotPos.position.y = croc->newPosition.y;
134+
entity->StartRotPos.position.z = croc->newPosition.z;
131135
}
132136
}
133137

134138
if (ImGui::Button((std::string("Teleport To##tptot_") + idSuffix).c_str())) {
135-
if (playerObject != nullptr) {
136-
playerObject->newPosition.x = entity->newPosition.x;
137-
playerObject->newPosition.y = entity->newPosition.y;
138-
playerObject->newPosition.z = entity->newPosition.z;
139+
if (croc != nullptr) {
140+
croc->newPosition.x = entity->newPosition.x;
141+
croc->newPosition.y = entity->newPosition.y;
142+
croc->newPosition.z = entity->newPosition.z;
139143
}
140144
}
141145
ImGui::SameLine();
142146
if (ImGui::Button((std::string("Teleport To Start##tptostart_") + idSuffix).c_str())) {
143-
if (playerObject != nullptr) {
144-
playerObject->newPosition.x = entity->StartRotPos.position.x;
145-
playerObject->newPosition.y = entity->StartRotPos.position.y;
146-
playerObject->newPosition.z = entity->StartRotPos.position.z;
147+
if (croc != nullptr) {
148+
croc->newPosition.x = entity->StartRotPos.position.x;
149+
croc->newPosition.y = entity->StartRotPos.position.y;
150+
croc->newPosition.z = entity->StartRotPos.position.z;
147151
}
148152
}
149153

@@ -217,6 +221,16 @@ void RenderObjectDetailsContent(StratEntity *entity, StratEntity *playerObject)
217221

218222
int localVarCount = ((int32_t *)entity->triggers - (int32_t *)entity->localVars) - 20;
219223
if (ImGui::CollapsingHeader((std::string("Local Variables(") + std::to_string(localVarCount) + ")##localvars_" + idSuffix).c_str())) {
224+
225+
if (entity == croc && strcmp(entity->name, "WalkingCroc") == 0) {
226+
ImGui::InputInt("Hazard Bounce Count##hazardbounce_", &(entity->localVars[CROC_VAR_HAZARD_BOUNCE_COUNT]), 0, 0);
227+
ImGui::InputInt("State##state_", &(entity->localVars[CROC_VAR_STATE]), 0, 0);
228+
ImGui::InputInt("In Air ##inair_", &(entity->localVars[CROC_VAR_IN_AIR]), 0, 0);
229+
ImGui::InputInt("Fall Timer##falltimer_", &(entity->localVars[CROC_VAR_FALL_TIMER]), 0, 0);
230+
231+
ImGui::Spacing();
232+
}
233+
220234
float availWidth = ImGui::GetContentRegionAvail().x;
221235
float spacing = ImGui::GetStyle().ItemSpacing.x;
222236

0 commit comments

Comments
 (0)