-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandHandler.cs
More file actions
326 lines (273 loc) · 13.5 KB
/
Copy pathCommandHandler.cs
File metadata and controls
326 lines (273 loc) · 13.5 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
using System;
using PaxDrops.Patches;
using System.Collections.Generic;
using Il2CppScheduleOne.Economy;
using PaxDrops.Configs;
namespace PaxDrops
{
/// <summary>
/// Main command handler that manages initialization and registration of all PaxDrops console commands.
/// Uses Harmony patches to intercept the console system for reliable command registration.
/// TEMPORARILY DISABLED - focusing on core functionality first
/// </summary>
public static class CommandHandler
{
private static bool _initialized;
/// <summary>
/// Initialize all console commands for PaxDrops
/// </summary>
public static void Init()
{
if (_initialized) return;
try
{
Logger.Info("🔧 CommandHandler temporarily disabled", "CommandHandler");
// COMMENTED OUT - Focusing on core functionality first
// Initialize console patches to intercept commands
// ConsolePatch.Init();
// Commands["pd_info"] = () => ShowSystemInfo();
// Commands["pd_test_collection"] = () => TestCollectionDetection();
// Commands["pd_test_expiry"] = () => TestExpiryCleanup();
// Commands["pd_reset_orders"] = () => ResetDailyOrders();
// Commands["pd_show_orders"] = () => ShowOrderHistory();
// Commands["pd_cleanup_expired"] = () => CleanupExpiredDrops();
_initialized = true;
Logger.Info("✅ Core systems ready (commands disabled)", "CommandHandler");
}
catch (Exception ex)
{
Logger.Error("❌ Command handler initialization failed.", "CommandHandler");
Logger.Error(ex.Message, "CommandHandler");
}
}
/// <summary>
/// Shutdown all console commands and patches
/// </summary>
public static void Shutdown()
{
if (!_initialized) return;
try
{
// ConsolePatch.Shutdown(); // COMMENTED OUT
_initialized = false;
Logger.Info("🔌 Command handler shutdown (was disabled)", "CommandHandler");
}
catch (Exception ex)
{
Logger.Error("❌ Command shutdown failed.", "CommandHandler");
Logger.Error(ex.Message, "CommandHandler");
}
}
/// <summary>
/// Get initialization status
/// </summary>
public static bool IsInitialized => _initialized;
/*
// COMMENTED OUT - All command methods disabled for now
/// <summary>
/// Show comprehensive system information
/// </summary>
private static void ShowSystemInfo()
{
Logger.Debug("📊 PaxDrops System Information:", "CommandHandler");
Logger.Debug("═══════════════════════════════════════════", "CommandHandler");
// Player Detection Status
Logger.Debug($"Player Detection: {DropConfig.GetPlayerDetectionStatus()}", "CommandHandler");
// Current Game State
var currentDay = DropConfig.GetCurrentGameDay();
var currentRank = DropConfig.GetCurrentPlayerRank();
var currentTier = DropConfig.GetCurrentPlayerTier();
Logger.Debug($"Game Day: {currentDay}", "CommandHandler");
Logger.Debug($"Player Rank: {currentRank}", "CommandHandler");
Logger.Debug($"Player Tier: {TierConfig.GetTierName(currentTier)}", "CommandHandler");
Logger.Debug($"Organization: {TierConfig.GetOrganizationName(TierConfig.GetOrganization(currentTier))}", "CommandHandler");
// Daily Order Status
var ordersToday = SaveFileJsonDataStore.GetMrStacksOrdersToday(currentDay);
var highestOrderedTier = OrderedDropConfig.GetHighestUnlockedTierForCurrentPlayer();
var dailyLimit = OrderedDropConfig.GetCurrentDailyOrderLimit();
var remaining = DailyDropOrdering.GetRemainingOrdersToday();
Logger.Debug($"Orders Today: {ordersToday}/{dailyLimit} (Remaining: {remaining})", "CommandHandler");
if (highestOrderedTier.HasValue)
{
Logger.Debug($"Top Ordered Tier: {OrderedDropConfig.GetTierName(highestOrderedTier.Value)}", "CommandHandler");
}
// Active Drops
var pendingDrops = SaveFileJsonDataStore.GetAllDrops();
var activeDrops = pendingDrops.FindAll(d => !d.IsCollected);
var collectedDrops = pendingDrops.FindAll(d => d.IsCollected);
Logger.Debug($"Active Drops: {activeDrops.Count}", "CommandHandler");
Logger.Debug($"Collected Drops: {collectedDrops.Count}", "CommandHandler");
// Show save file info
var (saveId, saveName, steamId, isLoaded) = SaveFileJsonDataStore.GetCurrentSaveInfo();
if (isLoaded)
{
Logger.Debug($"Save File: {saveName} (ID: {saveId}, Steam: {steamId})", "CommandHandler");
}
else
{
Logger.Debug("Save File: No save loaded", "CommandHandler");
}
Logger.Debug("═══════════════════════════════════════════", "CommandHandler");
if (activeDrops.Count > 0)
{
Logger.Debug("Active Drop Details:", "CommandHandler");
foreach (var drop in activeDrops)
{
var (expiryDay, expiryHour) = DropConfig.ParseExpiryTime(drop.ExpiryTime);
string expiryText = expiryDay != -1 ? $"Day {expiryDay} at {DropConfig.FormatGameTime(expiryHour)}" : "Unknown";
Logger.Debug($" Day {drop.Day}: {drop.Org} at {drop.Location} (expires {expiryText})", "CommandHandler");
}
}
}
/// <summary>
/// Test collection detection manually
/// </summary>
private static void TestCollectionDetection()
{
Logger.Debug("🔍 Testing collection detection...", "CommandHandler");
var pendingDrops = SaveFileJsonDataStore.GetAllDrops();
var deadDrops = UnityEngine.Object.FindObjectsOfType<Il2CppScheduleOne.Economy.DeadDrop>();
Logger.Debug($"Found {pendingDrops.Count} pending drops and {deadDrops.Length} dead drop locations", "CommandHandler");
foreach (var drop in pendingDrops)
{
if (drop.IsCollected || string.IsNullOrEmpty(drop.Location)) continue;
// Find the dead drop by name
Il2CppScheduleOne.Economy.DeadDrop? targetDeadDrop = null;
foreach (var deadDrop in deadDrops)
{
if (deadDrop.DeadDropName == drop.Location)
{
targetDeadDrop = deadDrop;
break;
}
}
if (targetDeadDrop?.Storage != null)
{
int currentItemCount = targetDeadDrop.Storage.ItemCount;
float collectionPercentage = (float)currentItemCount / drop.InitialItemCount * 100f;
Logger.Debug($"Drop at {drop.Location}: {currentItemCount}/{drop.InitialItemCount} items ({collectionPercentage:F1}%)", "CommandHandler");
if (currentItemCount <= (drop.InitialItemCount * 0.5f))
{
Logger.Debug($" → Would mark as collected (≤50% items remaining)", "CommandHandler");
}
}
else
{
Logger.Warn($"Drop location {drop.Location} not found or no storage", "CommandHandler");
}
}
}
/// <summary>
/// Test expiry cleanup manually
/// </summary>
private static void TestExpiryCleanup()
{
Logger.Debug("🗑️ Testing expiry cleanup...", "CommandHandler");
var timeManager = Il2CppScheduleOne.GameTime.TimeManager.Instance;
int currentDay = timeManager?.ElapsedDays ?? 0;
int currentHour = timeManager?.CurrentTime ?? 0;
var allDrops = SaveFileJsonDataStore.GetAllDrops();
var expiredDrops = new List<SaveFileJsonDataStore.DropRecord>();
foreach (var drop in allDrops)
{
if (!string.IsNullOrEmpty(drop.ExpiryTime) &&
DropConfig.IsDropExpired(drop.ExpiryTime, currentDay, currentHour))
{
expiredDrops.Add(drop);
}
}
Logger.Debug($"Found {expiredDrops.Count} expired drops", "CommandHandler");
foreach (var drop in expiredDrops)
{
var (expiryDay, expiryHour) = DropConfig.ParseExpiryTime(drop.ExpiryTime);
string expiryText = expiryDay != -1 ? $"Day {expiryDay} at {DropConfig.FormatGameTime(expiryHour)}" : "Unknown";
Logger.Debug($"Expired: {drop.Org} at {drop.Location} (expired {expiryText})", "CommandHandler");
}
if (expiredDrops.Count > 0)
{
Logger.Debug("Use 'pd_cleanup_expired' to actually clean them up", "CommandHandler");
}
}
/// <summary>
/// Reset daily orders for current day (testing)
/// </summary>
private static void ResetDailyOrders()
{
var currentDay = DropConfig.GetCurrentGameDay();
SaveFileJsonDataStore.ResetMrStacksOrdersToday(currentDay);
Logger.Debug($"🔄 Reset daily orders for day {currentDay}", "CommandHandler");
}
/// <summary>
/// Show order history
/// </summary>
private static void ShowOrderHistory()
{
Logger.Debug("📋 Order History:", "CommandHandler");
var orderSummary = SaveFileJsonDataStore.GetMrStacksOrderSummary();
if (orderSummary.Count == 0)
{
Logger.Debug("No orders recorded yet.", "CommandHandler");
return;
}
var sortedOrders = new List<KeyValuePair<int, int>>(orderSummary);
sortedOrders.Sort((a, b) => a.Key.CompareTo(b.Key));
foreach (var kvp in sortedOrders)
{
Logger.Debug($"Day {kvp.Key}: {kvp.Value} order(s)", "CommandHandler");
}
}
/// <summary>
/// Manually cleanup expired drops
/// </summary>
private static void CleanupExpiredDrops()
{
Logger.Debug("🗑️ Manually cleaning up expired drops...", "CommandHandler");
var timeManager = Il2CppScheduleOne.GameTime.TimeManager.Instance;
int currentDay = timeManager?.ElapsedDays ?? 0;
int currentHour = timeManager?.CurrentTime ?? 0;
var allDrops = SaveFileJsonDataStore.GetAllDrops();
var expiredDrops = new List<SaveFileJsonDataStore.DropRecord>();
foreach (var drop in allDrops)
{
if (!string.IsNullOrEmpty(drop.ExpiryTime) &&
DropConfig.IsDropExpired(drop.ExpiryTime, currentDay, currentHour))
{
expiredDrops.Add(drop);
}
}
if (expiredDrops.Count == 0)
{
Logger.Debug("No expired drops to clean up.", "CommandHandler");
return;
}
var deadDrops = UnityEngine.Object.FindObjectsOfType<Il2CppScheduleOne.Economy.DeadDrop>();
int cleanedCount = 0;
foreach (var drop in expiredDrops)
{
Logger.Debug($"Cleaning up expired drop at {drop.Location}", "CommandHandler");
// Find the dead drop and clear its contents
foreach (var deadDrop in deadDrops)
{
if (deadDrop.DeadDropName == drop.Location && deadDrop.Storage != null)
{
try
{
deadDrop.Storage.ClearContents();
Logger.Debug($"✅ Cleared contents from {drop.Location}", "CommandHandler");
cleanedCount++;
}
catch (Exception ex)
{
Logger.Error($"Failed to clear contents from {drop.Location}: {ex.Message}", "CommandHandler");
}
break;
}
}
// Remove from pending drops
SaveFileJsonDataStore.RemoveSpecificDrop(drop.Day, drop.Location);
}
Logger.Debug($"✅ Cleaned up {cleanedCount}/{expiredDrops.Count} expired drops", "CommandHandler");
}
*/
}
}