-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDSPSaveGameSorter.cs
More file actions
111 lines (98 loc) · 4.38 KB
/
DSPSaveGameSorter.cs
File metadata and controls
111 lines (98 loc) · 4.38 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
//
// Copyright (c) 2021, Aaron Shumate
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE.txt file in the root directory of this source tree.
//
// Dyson Sphere Program is developed by Youthcat Studio and published by Gamera Game.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using System.Security;
using System.Security.Permissions;
[module: UnverifiableCode]
#pragma warning disable CS0618 // Type or member is obsolete
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
#pragma warning restore CS0618 // Type or member is obsolete
namespace DSPSaveGameSorter
{
[BepInPlugin(pluginGuid, pluginName, pluginVersion)]
[BepInProcess("DSPGAME.exe")]
public class DSPSaveGameSorter : BaseUnityPlugin
{
public const string pluginGuid = "greyhak.dysonsphereprogram.savegamesorter";
public const string pluginName = "DSP Save Game Sorter";
public const string pluginVersion = "1.0.3";
new internal static ManualLogSource Logger;
Harmony harmony;
public static BepInEx.Configuration.ConfigEntry<bool> configSortLoadScreen;
public static BepInEx.Configuration.ConfigEntry<bool> configSortSaveScreen;
public void Awake()
{
Logger = base.Logger; // "C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\LogOutput.log"
configSortLoadScreen = Config.Bind<bool>("Config", "SortLoadScreen", true, "Sort load-game screen list.");
configSortSaveScreen = Config.Bind<bool>("Config", "SortSaveScreen", true, "Sort save-game screen list.");
harmony = new Harmony(pluginGuid);
harmony.PatchAll(typeof(DSPSaveGameSorter));
}
public class GameSaveEntryReverseSorter : IComparer<UIGameSaveEntry>
{
public int Compare(UIGameSaveEntry x, UIGameSaveEntry y)
{
if (x.fileDate < y.fileDate)
return 1;
if (x.fileDate > y.fileDate)
return -1;
return 0;
}
}
[HarmonyPostfix, HarmonyPatch(typeof(UILoadGameWindow), "RefreshList")]
public static void UILoadGameWindow_RefreshList_Postfix(ref UILoadGameWindow __instance)
{
if (configSortLoadScreen.Value)
{
//List<UIGameSaveEntry> sorted = __instance.entries.OrderByDescending(e => e.fileDate).ToList();
__instance.entries.Sort(new GameSaveEntryReverseSorter());
int displayIndex = 1;
for (int i = 0; i < __instance.entries.Count;)
{
UIGameSaveEntry entry = __instance.entries[i++];
if (entry.fileInfo.Name.Equals(GameSave.LastExitFullName))
entry.SetEntry(i, 0, entry.fileInfo);
else if (entry.fileInfo.Name.Equals(GameSave.AutoSave0FullName))
entry.SetEntry(i, -1, entry.fileInfo);
else if (entry.fileInfo.Name.Equals(GameSave.AutoSave1FullName))
entry.SetEntry(i, -2, entry.fileInfo);
else if (entry.fileInfo.Name.Equals(GameSave.AutoSave2FullName))
entry.SetEntry(i, -3, entry.fileInfo);
else if (entry.fileInfo.Name.Equals(GameSave.AutoSave3FullName))
entry.SetEntry(i, -4, entry.fileInfo);
else
entry.SetEntry(i, displayIndex++, entry.fileInfo);
}
__instance.OnSelectedChange();
}
}
[HarmonyPostfix, HarmonyPatch(typeof(UISaveGameWindow), "RefreshList")]
public static void UISaveGameWindow_RefreshList_Postfix(ref UISaveGameWindow __instance)
{
if (configSortSaveScreen.Value)
{
__instance.entries.Sort(new GameSaveEntryReverseSorter());
for (int i = 0; i < __instance.entries.Count;)
{
UIGameSaveEntry entry = __instance.entries[i++];
entry.SetEntry(i, i, entry.fileInfo);
}
__instance.OnSelectedChange();
}
}
}
}