Skip to content

Commit

Permalink
Feat: Possession && Chat box for mod info
Browse files Browse the repository at this point in the history
  • Loading branch information
ArjixWasTaken committed Apr 28, 2022
1 parent a826c1b commit 2bfdc7e
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# IDE0005: Using directive is unnecessary.
dotnet_diagnostic.IDE0005.severity = none
Binary file modified .vs/CloneDroneInTheDangerZone/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified .vs/CloneDroneInTheDangerZone/v17/.futdcache.v1
Binary file not shown.
Binary file modified .vs/CloneDroneInTheDangerZone/v17/.suo
Binary file not shown.
2 changes: 2 additions & 0 deletions CloneDroneInTheDangerZone.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
<PackageReference Include="SteamworksSharp" Version="1.0.8" />
<PackageReference Include="SteamworksSharp.Native.Windows_x86" Version="1.0.8" />
<PackageReference Include="System.Collections" Version="4.3.0" />
<PackageReference Include="UnityEngine.Modules" Version="2018.4.31.2174630" IncludeAssets="compile" />
</ItemGroup>
Expand Down
142 changes: 131 additions & 11 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Plugin : BaseUnityPlugin
private const string modName = "BlaBla";
private const string modVersion = "69.4.20";
private readonly Harmony harmony = new Harmony(modGUID);

private static Dictionary<KeyCode, Action> keybindsUp = new();
private static Dictionary<KeyCode, Action> keybindsDown = new();

Expand All @@ -29,7 +29,8 @@ private void Awake()
// Register all the keybinds
keybindsUp.Add(KeyCode.B, AddFiveSP);
keybindsUp.Add(KeyCode.J, ToggleInfiniteEnergy);
keybindsUp.Add(KeyCode.E, KillClosestEnemy);
keybindsUp.Add(KeyCode.E, KillAllEnemies);
keybindsUp.Add(KeyCode.R, Reincarnate);
keybindsUp.Add(KeyCode.T, ToggleTimestop);

keybindsDown.Add(KeyCode.Space, Fly);
Expand All @@ -38,27 +39,46 @@ private void Awake()
Logger.LogInfo($"Plugin '{modGUID}' is loaded!");
}

private class Message
{
public long time;
public string content;

public Message(string msg)
{
this.time = DateTimeOffset.Now.ToUnixTimeMilliseconds();
this.content = msg;
}
}

private void SendMessageInConsole(string message)
{
scrollPosition.y = messages.Count * 20;
messages.Add(new Message(message));
}

private void AddFiveSP()
{
Singleton<UpgradeManager>.Instance.SetAvailableSkillPoints(
Singleton<UpgradeManager>.Instance.GetAvailableSkillPoints() + 5
);
Logger.LogMessage("Gave 5 skill points to the player");
SendMessageInConsole("Gave 5 skill points to the player");
}

private void ToggleInfiniteEnergy()
{
Data.HasInfiniteEnergy = !Data.HasInfiniteEnergy;
player.GetEnergySource().HasInfiniteEnergy = Data.HasInfiniteEnergy;
Logger.LogMessage($"Infinite Energy: {Data.HasInfiniteEnergy}!");
SendMessageInConsole($"Infinite Energy: {Data.HasInfiniteEnergy}!");
}

private void ToggleTimestop()
{
if (Data.TimestopEnabled)
{
Singleton<AIManager>.Instance.DeactivateEnemyAI();
} else
}
else
{
Singleton<AIManager>.Instance.ActivateEnemyAI();
}
Expand All @@ -74,26 +94,80 @@ private void Fly()
}
}

private void KillClosestEnemy()
private void KillAllEnemies()
{
CharacterTracker.Instance.GetEnemyCharacters().ForEach(c => c.Kill((Character)player, DamageSourceType.EnergyBeam));
}

private void Reincarnate()
{
Character target = Singleton<CharacterTracker>.Instance.GetClosestLivingEnemyCharacter(player.transform.position);
Character target = CharacterTracker.Instance.GetClosestLivingEnemyCharacter(player.transform.position);
if (target != null)
{
target.Kill((Character)player, DamageSourceType.EnergyBeam);
player.TransferConsciousnessTo((FirstPersonMover)target);
Data.HasTransferredConsciousness = true;
}
}

public static FirstPersonMover player;

private void OnLevelDefeated()
{
if (Data.HasTransferredConsciousness)
{
int count = 0;
Character ally = CharacterTracker.Instance.GetPlayerAlly();
while (ally != null)
{
count++;
ally.Kill((Character)player, DamageSourceType.EnergyBeam);
ally = CharacterTracker.Instance.GetPlayerAlly();
}
Data.HasTransferredConsciousness = false;
if (count > 1)
{
SendMessageInConsole($"Killed {count} allies");
}
else
{
SendMessageInConsole($"Killed an ally");
}
}
}

void Update()
{
newTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();

try
{
player = (FirstPersonMover)CharacterTracker.Instance.GetPlayer();
}
catch (Exception e) { }

for (int i = 0; i < messages.Count; i++)
{
if (messages[i].time + 5000 < newTime)
{
messages.RemoveAt(i);
i--;
}
}

if (!Data.HasSetEventListeners)
{
try
{
if (GlobalEventManager.Instance != null)
{
// set the event listeners
GlobalEventManager.Instance.AddEventListener("LevelDefeated", OnLevelDefeated);
Data.HasSetEventListeners = true;
}
}
catch (Exception e) { }
}

if (Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl))
{
foreach (KeyValuePair<KeyCode, Action> keybind in keybindsUp)
Expand All @@ -114,7 +188,17 @@ void Update()
}
}

static Rect windowRect = new(25, 25, 300, 70);
public static GUIStyle style = new()
{
fontSize = 18,
normal = new()
{
textColor = Color.white
}
};
static Rect windowRect = new(25, 25, 300, 800);
private static List<Message> messages = new();
public Vector2 scrollPosition = Vector2.zero;
void OnGUI()
{
if (Data.showGUI)
Expand All @@ -131,6 +215,40 @@ void OnGUI()
Data.HasInfiniteEnergy = GUILayout.Toggle(Data.HasInfiniteEnergy, "Infinite Energy");
GUILayout.EndArea();
}

if (player != null)
{
float height = 280;
float width = Screen.width * 0.18f;
GUILayout.BeginHorizontal();

Rect rectBox = new Rect(0, (Screen.height * 0.75f) - height, width, height);
Rect viewRect = new Rect(rectBox.x, rectBox.y, rectBox.width, messages.Count * 20f);

GUI.Box(rectBox, GUIContent.none);

scrollPosition = GUI.BeginScrollView(rectBox, scrollPosition, viewRect, false, true, GUIStyle.none, GUI.skin.verticalScrollbar);

int viewCount = 15;
int maxCharacterLength = ((int)width / 20) * 2;
int firstIndex = (int)scrollPosition.y / 20;

Rect contentPos = new Rect(rectBox.x, viewRect.y + (firstIndex * 20f), rectBox.width, 20f);

for (int i = firstIndex; i < Mathf.Min(messages.Count, firstIndex + viewCount); i++)
{
string text = messages[i].content;
if (text.Length > maxCharacterLength)
{
text = text.Substring(0, maxCharacterLength - 3) + "...";
}
GUI.Label(contentPos, text, style);
contentPos.y += 20f;
}

GUI.EndScrollView();
GUILayout.EndHorizontal();
}
}
}

Expand All @@ -140,15 +258,17 @@ public static class Data
public static float AimTimeScale = 0.05f;
public static bool showGUI = false;
public static bool TimestopEnabled = false;
public static bool HasSetEventListeners = false;
public static bool HasTransferredConsciousness = false;
}

[HarmonyPatch]
class Steam_patcher
class SteamManager_patcher
{
// Disables the steam integration with the game.
[HarmonyPrefix]
[HarmonyPatch(typeof(SteamManager), "Initialize")]
static bool Start(ref bool __result)
static bool Initialize(ref bool __result)
{
__result = true;
return false;
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ It targets the version (5/12/2021), so if it doesn't work, it's probably because
Current features are:
- Infinite Energy (can be toggled on/off using Ctrl+J)
- Get 5 skill points every time you press Ctrl+B
- Change the AimTime (slowmo) to 0.2, will only work if you have the upgrade.
- Change the AimTime (slowmo) to 0.05, will only work if you have the upgrade.
- Fly! Just press Ctrl+Space and it will launch you up a bit, do that a lot and you can fly!
- Kill nearest enemy by pressing Ctrl+E!
- Insta win (kills all the enemies) Ctrl+E!
- Timestop! Disables all the enemy AIs. (the keybind is Ctrl+T)
- Possession! You can take over the body of an enemy by pressing Ctrl+R (your original body becomes an ally and will die at the end of the round)

I disabled the steam integration to avoid any Anti-Cheat detection.

Expand Down

0 comments on commit 2bfdc7e

Please sign in to comment.