1
1
using Celeste . Mod . Core ;
2
2
using Celeste . Mod . TASHelper . Utils ;
3
+ using Microsoft . Xna . Framework ;
3
4
using Microsoft . Xna . Framework . Input ;
4
5
using Mono . Cecil . Cil ;
5
6
using Monocle ;
6
7
using MonoMod . Cil ;
7
8
using TAS ;
9
+ using TAS . EverestInterop ;
8
10
using CMCore = Celeste . Mod . Core ;
9
11
10
12
namespace Celeste . Mod . TASHelper . Gameplay ;
@@ -17,8 +19,13 @@ public static class ConsoleEnhancement {
17
19
18
20
private static int historyLineShift = 0 ;
19
21
22
+ private const int extraExtraHistoryLines = 1000 ;
23
+
20
24
private static int origValue ;
21
25
26
+ public static float ScrollBarWidth = 10f ;
27
+ public static float ScrollBarHeight = 20f ;
28
+
22
29
private static bool historyScrollEnabled => TasHelperSettings . EnableScrollableHistoryLog ;
23
30
public static void SetOpenConsole ( ) {
24
31
if ( Manager . Running && ! lastOpen ) {
@@ -29,16 +36,13 @@ public static bool GetOpenConsole() { // openConsole.getter may not be called (e
29
36
return openConsole ;
30
37
}
31
38
32
- public static void GoBackToBottom ( ) {
33
- historyLineShift = 0 ;
34
- }
35
-
36
39
[ Load ]
37
40
public static void Load ( ) {
38
41
IL . Monocle . Commands . UpdateClosed += ILCommandUpdateClosed ;
39
42
On . Celeste . Level . BeforeRender += OnLevelBeforeRender ;
40
43
IL . Monocle . Commands . Render += ILCommandsRender ;
41
44
On . Monocle . Commands . UpdateOpen += OnCommandUpdateOpen ;
45
+ IL . Monocle . Commands . Log_object_Color += ILCommandsLog ;
42
46
}
43
47
44
48
[ Unload ]
@@ -47,12 +51,37 @@ public static void Unload() {
47
51
On . Celeste . Level . BeforeRender -= OnLevelBeforeRender ;
48
52
IL . Monocle . Commands . Render -= ILCommandsRender ;
49
53
On . Monocle . Commands . UpdateOpen -= OnCommandUpdateOpen ;
54
+ IL . Monocle . Commands . Log_object_Color -= ILCommandsLog ;
50
55
}
51
56
52
57
[ Initialize ]
53
58
public static void Initialize ( ) {
54
59
typeof ( Manager ) . GetMethod ( "Update" ) . HookAfter ( UpdateCommands ) ;
55
60
typeof ( Manager ) . GetMethod ( "DisableRun" ) . HookAfter ( MinorBugFixer ) ;
61
+ typeof ( CenterCamera ) . GetMethod ( "ZoomCamera" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Static ) . IlHook ( il => {
62
+ ILCursor cursor = new ILCursor ( il ) ;
63
+ if ( cursor . TryGotoNext ( MoveType . After , ins => ins . MatchCallOrCallvirt ( typeof ( MouseButtons ) . FullName , "get_Wheel" ) ) ) {
64
+ cursor . EmitDelegate ( PreventZoomCamera ) ;
65
+ cursor . Emit ( OpCodes . Mul ) ;
66
+ }
67
+ } ) ;
68
+ }
69
+
70
+ private static int PreventZoomCamera ( ) {
71
+ return Engine . Commands . Open && historyScrollEnabled && Engine . Commands . drawCommands . Count > ( Engine . ViewHeight - 100 ) / 30 ? 0 : 1 ;
72
+ }
73
+
74
+ private static int ExtraExtraHistoryLines ( ) {
75
+ return historyScrollEnabled ? extraExtraHistoryLines : 0 ;
76
+ }
77
+
78
+ private static void ILCommandsLog ( ILContext il ) {
79
+ // allow to store more history logs than default setting of Everest, which is not editable in game (can only be editted in savefile)
80
+ ILCursor cursor = new ILCursor ( il ) ;
81
+ if ( cursor . TryGotoNext ( MoveType . After , ins => ins . MatchCallOrCallvirt < CoreModuleSettings > ( "get_ExtraCommandHistoryLines" ) ) ) {
82
+ cursor . EmitDelegate ( ExtraExtraHistoryLines ) ;
83
+ cursor . Emit ( OpCodes . Add ) ;
84
+ }
56
85
}
57
86
58
87
private static void ILCommandsRender ( ILContext context ) {
@@ -75,34 +104,63 @@ private static void ILCommandsRender(ILContext context) {
75
104
}
76
105
77
106
private static void BeforeAction ( Monocle . Commands commands ) {
78
- origValue = commands . firstLineIndexToDraw ;
79
- commands . firstLineIndexToDraw = Calc . Clamp ( commands . firstLineIndexToDraw + historyLineShift , 0 , Math . Max ( commands . drawCommands . Count - 1 , 0 ) ) ;
107
+ if ( historyScrollEnabled ) {
108
+ origValue = commands . firstLineIndexToDraw ;
109
+ commands . firstLineIndexToDraw = Calc . Clamp ( commands . firstLineIndexToDraw + historyLineShift , 0 , Math . Max ( commands . drawCommands . Count - ( Engine . ViewHeight - 100 ) / 30 , 0 ) ) ;
110
+ }
80
111
}
81
112
82
113
private static void AfterAction ( Monocle . Commands commands ) {
114
+ if ( ! historyScrollEnabled ) {
115
+ return ;
116
+ }
117
+ if ( commands . drawCommands . Count > ( Engine . ViewHeight - 100 ) / 30 ) {
118
+ int num3 = Math . Min ( ( Engine . ViewHeight - 100 ) / 30 , commands . drawCommands . Count - commands . firstLineIndexToDraw ) ;
119
+ float num4 = 10f + 30f * ( float ) num3 ;
120
+ Draw . Rect ( ( float ) Engine . ViewWidth - 15f - ScrollBarWidth , ( float ) Engine . ViewHeight - num4 - 60f , ScrollBarWidth , num4 , Color . Gray * 0.8f ) ;
121
+ Draw . Rect ( ( float ) Engine . ViewWidth - 15f - ScrollBarWidth + 1f , ( float ) Engine . ViewHeight - 60f - ( float ) ( num4 - ScrollBarHeight ) * ( float ) commands . firstLineIndexToDraw / ( float ) Math . Max ( commands . drawCommands . Count - ( Engine . ViewHeight - 100 ) / 30 , 1 ) - ScrollBarHeight , ScrollBarWidth - 2f , ScrollBarHeight , Color . Silver * 0.8f ) ;
122
+ }
83
123
if ( commands . drawCommands . Count > 0 ) {
84
124
historyLineShift = commands . firstLineIndexToDraw - origValue ; // this automatically bounds our shift
85
125
commands . firstLineIndexToDraw = origValue ;
86
126
}
87
127
}
88
128
89
- private static int repeatCounter = 0 ;
90
-
91
129
private static void OnCommandUpdateOpen ( On . Monocle . Commands . orig_UpdateOpen orig , Monocle . Commands commands ) {
92
130
orig ( commands ) ;
93
131
if ( historyScrollEnabled ) {
94
132
bool controlPressed = commands . currentState [ Keys . LeftControl ] == KeyState . Down || commands . currentState [ Keys . RightControl ] == KeyState . Down ;
133
+
134
+ // btw, mouseScroll is already used by Everest to adjust cursor scale
135
+ MouseState mouseState = Mouse . GetState ( ) ;
136
+ int mouseScrollDelta = mouseState . ScrollWheelValue - commands . mouseScroll ;
137
+ if ( mouseScrollDelta / 120 != 0 ) {
138
+ // i dont know how ScrollWheelValue is calculated, for me, it's always a multiple of 120
139
+ // in case for other people, it's lower than 120, we provide Math.Sign as a compensation
140
+ historyLineShift += mouseScrollDelta / 120 ;
141
+ }
142
+ else {
143
+ historyLineShift += Math . Sign ( mouseScrollDelta ) ;
144
+ }
145
+
95
146
if ( commands . currentState [ Keys . PageUp ] == KeyState . Down && commands . oldState [ Keys . PageUp ] == KeyState . Up ) {
96
- historyLineShift += ( Engine . ViewHeight - 100 ) / 30 ;
147
+ if ( controlPressed ) {
148
+ historyLineShift = 99999 ;
149
+ }
150
+ else {
151
+ historyLineShift += ( Engine . ViewHeight - 100 ) / 30 ;
152
+ }
97
153
}
98
154
else if ( commands . currentState [ Keys . PageDown ] == KeyState . Down && commands . oldState [ Keys . PageDown ] == KeyState . Up ) {
99
155
if ( controlPressed ) {
100
- historyLineShift = 0 ;
156
+ historyLineShift = - 99999 ;
101
157
}
102
158
else {
103
159
historyLineShift -= ( Engine . ViewHeight - 100 ) / 30 ;
104
160
}
105
161
}
162
+ /*
163
+ * this already exists
106
164
else if (commands.currentState[Keys.Up] == KeyState.Down && controlPressed) {
107
165
repeatCounter += 1;
108
166
while (repeatCounter >= 6) {
@@ -120,6 +178,7 @@ private static void OnCommandUpdateOpen(On.Monocle.Commands.orig_UpdateOpen orig
120
178
else {
121
179
repeatCounter = 0;
122
180
}
181
+ */
123
182
}
124
183
}
125
184
0 commit comments