forked from UnknownX7/Cammy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cammy.cs
156 lines (136 loc) · 5.38 KB
/
Cammy.cs
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
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
namespace Cammy;
public class Cammy : DalamudPlugin<Configuration>, IDalamudPlugin
{
public Cammy(DalamudPluginInterface pluginInterface) : base(pluginInterface) { }
protected override void Initialize()
{
Game.Initialize();
IPC.Initialize();
DalamudApi.ClientState.Login += Login;
}
protected override void ToggleConfig() => PluginUI.IsVisible ^= true;
private const string cammySubcommands = "/cammy [ help | preset | zoom | fov | spectate | nocollide | freecam ]";
[PluginCommand("/cammy", HelpMessage = "Opens / closes the config. Additional usage: " + cammySubcommands)]
private unsafe void ToggleConfig(string command, string argument)
{
if (string.IsNullOrEmpty(argument))
{
ToggleConfig();
return;
}
var regex = Regex.Match(argument, "^(\\w+) ?(.*)");
var subcommand = regex.Success && regex.Groups.Count > 1 ? regex.Groups[1].Value : string.Empty;
switch (subcommand.ToLower())
{
case "preset":
{
if (regex.Groups.Count < 2 || string.IsNullOrEmpty(regex.Groups[2].Value))
{
PresetManager.CurrentPreset = null;
DalamudApi.PrintEcho("Removed preset override.");
return;
}
var arg = regex.Groups[2].Value;
var preset = Config.Presets.FirstOrDefault(preset => preset.Name == arg);
if (preset == null)
{
DalamudApi.PrintError($"Failed to find preset \"{arg}\"");
return;
}
PresetManager.CurrentPreset = preset;
DalamudApi.PrintEcho($"Preset set to \"{arg}\"");
break;
}
case "zoom":
{
if (regex.Groups.Count < 2 || !float.TryParse(regex.Groups[2].Value, out var amount))
{
DalamudApi.PrintError("Invalid amount.");
return;
}
Common.CameraManager->worldCamera->currentZoom = amount;
break;
}
case "fov":
{
if (regex.Groups.Count < 2 || !float.TryParse(regex.Groups[2].Value, out var amount))
{
DalamudApi.PrintError("Invalid amount.");
return;
}
Common.CameraManager->worldCamera->currentFoV = amount;
break;
}
case "spectate":
{
Game.EnableSpectating ^= true;
DalamudApi.PrintEcho($"Spectating is now {(Game.EnableSpectating ? "enabled" : "disabled")}!");
break;
}
case "nocollide":
{
Config.EnableCameraNoClippy ^= true;
if (!FreeCam.Enabled)
Game.cameraNoClippyReplacer.Toggle();
Config.Save();
DalamudApi.PrintEcho($"Camera collision is now {(Config.EnableCameraNoClippy ? "disabled" : "enabled")}!");
break;
}
case "freecam":
{
FreeCam.Toggle();
break;
}
case "help":
{
DalamudApi.PrintEcho("Subcommands:" +
"\npreset <name> - Applies a preset to override automatic presets, specified by name. Use without a name to disable." +
"\nzoom <amount> - Sets the current zoom level." +
"\nfov <amount> - Sets the current FoV level." +
"\nspectate - Toggles the \"Spectate Focus / Soft Target\" option." +
"\nnocollide - Toggles the \"Disable Camera Collision\" option." +
"\nfreecam - Toggles the \"Free Cam\" option.");
break;
}
default:
{
DalamudApi.PrintError("Invalid usage: " + cammySubcommands);
break;
}
}
}
protected override void Update()
{
FreeCam.Update();
PresetManager.Update();
}
protected override void Draw() => PluginUI.Draw();
private static void Login()
{
DalamudApi.Framework.Update += UpdateDefaultPreset;
PresetManager.DisableCameraPresets();
PresetManager.CheckCameraConditionSets(true);
}
private static void UpdateDefaultPreset(IFramework framework)
{
if (DalamudApi.Condition[ConditionFlag.BetweenAreas]) return;
PresetManager.DefaultPreset = new();
DalamudApi.Framework.Update -= UpdateDefaultPreset;
}
protected override void Dispose(bool disposing)
{
if (!disposing) return;
IPC.Dispose();
PresetManager.DefaultPreset.Apply();
DalamudApi.ClientState.Login -= Login;
if (FreeCam.Enabled)
FreeCam.Toggle();
Game.Dispose();
}
}