Skip to content

Commit a6c69a1

Browse files
author
Luckyheat
authored
Update Dleks.cpp
Fix crashing when changing to turn off anticheat Prevent bugs with protocol mixing Changed Logical Structure Other some fixes Minus: Code is HARD for reading, FUC-
1 parent db6d0e9 commit a6c69a1

File tree

1 file changed

+67
-22
lines changed

1 file changed

+67
-22
lines changed

hooks/Dleks.cpp

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,76 @@
1414
return orig_return;
1515
}*/
1616

17+
//Full Code from KillNetwork source code:
18+
19+
constexpr int32_t AnticheatPenalty = 25; // Prevent rare crashing
20+
21+
void LogIfEnabled(const std::string& message) {
22+
if (State.ShowHookLogs) {
23+
LOG_DEBUG(message.c_str());
24+
}
25+
}
26+
27+
int32_t GetAdjustedBroadcastVersion(MethodInfo* method) {
28+
LogIfEnabled("Hook dConstants_1_GetBroadcastVersion executed");
29+
int32_t baseVersion = Constants_1_GetBroadcastVersion(method);
30+
return baseVersion + (State.DisableHostAnticheat ? AnticheatPenalty : 0); // Prevents bugs with protocol mixing
31+
}
32+
33+
bool IsVersionModded(MethodInfo* method) {
34+
LogIfEnabled("Hook dConstants_1_IsVersionModded executed");
35+
return State.DisableHostAnticheat || Constants_1_IsVersionModded(method);
36+
}
37+
38+
AsyncOperationHandle_1_UnityEngine_GameObject_ InstantiateAssetAsync(
39+
AssetReference* assetRef,
40+
Transform* parent,
41+
bool instantiateInWorldSpace,
42+
MethodInfo* method)
43+
{
44+
LOG_DEBUG(std::format("AssetReference_InstantiateAsync executed with scene {}", State.CurrentScene).c_str());
45+
46+
bool isHost = IsHost();
47+
bool isInGame = IsInGame();
48+
auto amongUsClient = *Game::pAmongUsClient;
49+
50+
// Check for special asset instantiation case
51+
if (isHost && !isInGame && amongUsClient && parent == nullptr && !instantiateInWorldSpace) {
52+
il2cpp::List shipPrefabs = amongUsClient->fields.ShipPrefabs;
53+
54+
if (assetRef == shipPrefabs[0] && State.FlipSkeld) {
55+
auto asyncHandle = AssetReference_InstantiateAsync_1(shipPrefabs[3], parent, instantiateInWorldSpace, method);
56+
amongUsClient->fields.ShipLoadingAsyncHandle = asyncHandle;
57+
return asyncHandle;
58+
}
59+
}
60+
61+
try {
62+
return AssetReference_InstantiateAsync_1(assetRef, parent, instantiateInWorldSpace, method);
63+
}
64+
catch (const std::exception& e) {
65+
LOG_ERROR(std::format("Exception caught: {}", e.what()).c_str());
66+
}
67+
catch (...) {
68+
LOG_ERROR("Unknown exception caught");
69+
}
70+
71+
return {}; // Return default constructed handle on failure
72+
}
73+
1774
int32_t dConstants_1_GetBroadcastVersion(MethodInfo* method) {
18-
if (State.ShowHookLogs) LOG_DEBUG("Hook dConstants_1_GetBroadcastVersion executed");
19-
int32_t orig_return = Constants_1_GetBroadcastVersion(method);
20-
if (State.DisableHostAnticheat) orig_return += 25;
21-
return orig_return;
75+
return GetAdjustedBroadcastVersion(method);
2276
}
2377

2478
bool dConstants_1_IsVersionModded(MethodInfo* method) {
25-
if (State.ShowHookLogs) LOG_DEBUG("Hook dConstants_1_IsVersionModded executed");
26-
if (State.DisableHostAnticheat) return true; //this helps to bypass anticheat in our hosted lobbies
27-
//return false;
28-
return Constants_1_IsVersionModded(method);
79+
return IsVersionModded(method);
2980
}
3081

31-
AsyncOperationHandle_1_UnityEngine_GameObject_ dAssetReference_InstantiateAsync_1(AssetReference* __this, Transform* parent, bool instantiateInWorldSpace, MethodInfo* method) {
32-
LOG_DEBUG(std::format("AssetReference_InstantiateAsync executed with scene {}", State.CurrentScene).c_str());
33-
try {
34-
if (IsHost() && !IsInGame() && (*Game::pAmongUsClient) != NULL && parent == NULL && !instantiateInWorldSpace) {
35-
il2cpp::List shipPrefabs = (*Game::pAmongUsClient)->fields.ShipPrefabs;
36-
if (__this == shipPrefabs[0] && State.FlipSkeld) {
37-
(*Game::pAmongUsClient)->fields.ShipLoadingAsyncHandle = AssetReference_InstantiateAsync_1(shipPrefabs[3], parent, instantiateInWorldSpace, method);
38-
return AssetReference_InstantiateAsync_1(shipPrefabs[3], parent, instantiateInWorldSpace, method);
39-
}
40-
}
41-
}
42-
catch (...) {}
43-
return AssetReference_InstantiateAsync_1(__this, parent, instantiateInWorldSpace, method);
44-
}
82+
AsyncOperationHandle_1_UnityEngine_GameObject_ dAssetReference_InstantiateAsync_1(
83+
AssetReference* __this,
84+
Transform* parent,
85+
bool instantiateInWorldSpace,
86+
MethodInfo* method)
87+
{
88+
return InstantiateAssetAsync(__this, parent, instantiateInWorldSpace, method);
89+
}

0 commit comments

Comments
 (0)