1
1
using BepInEx ;
2
2
using BepInEx . Configuration ;
3
3
using System . IO ;
4
+ using System . Threading . Tasks ;
4
5
using UnityEngine ;
5
6
6
7
namespace BotCMDs
@@ -11,11 +12,10 @@ public class BotCommands : BaseUnityPlugin
11
12
{
12
13
// Config
13
14
private static ConfigEntry < string > Cmdpath { get ; set ; }
14
-
15
15
private string botcmd_path ;
16
16
17
17
[ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Code Quality" , "IDE0051:Remove unused private members" ) ]
18
- public void Awake ( )
18
+ private void Awake ( )
19
19
{
20
20
Cmdpath = Config . Bind < string > (
21
21
"Config" ,
@@ -26,26 +26,50 @@ public void Awake()
26
26
botcmd_path = Cmdpath . Value ;
27
27
28
28
Debug . Log ( "Created by Rayss and InfernalPlacebo." ) ;
29
+
30
+ }
31
+
32
+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Code Quality" , "IDE0051:Remove unused private members" ) ]
33
+ private void Start ( )
34
+ {
35
+ Reading ( ) ;
29
36
}
30
37
38
+ /**
31
39
[System.Diagnostics.CodeAnalysis.SuppressMessage("Code Quality", "IDE0051:Remove unused private members")]
32
40
private void Update()
33
41
{
34
- using ( StreamReader reader = new StreamReader ( new FileStream ( botcmd_path , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) ) )
42
+
43
+ }
44
+ **/
45
+
46
+ private async void Reading ( )
47
+ {
48
+ using ( StreamReader reader = new StreamReader ( new FileStream ( botcmd_path ,
49
+ FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) ) )
35
50
{
36
51
//start at the end of the file
37
52
long lastMaxOffset = reader . BaseStream . Length ;
38
53
39
- System . Threading . Thread . Sleep ( 20 ) ;
54
+ while ( true )
55
+ {
56
+ await Task . Delay ( 1000 ) ;
57
+
58
+ //if the file size has not changed, idle (RAYSS NOTE: MAY NOT BE NEEDED)
59
+ if ( reader . BaseStream . Length == lastMaxOffset )
60
+ continue ;
40
61
41
- //seek to the last max offset
42
- reader . BaseStream . Seek ( lastMaxOffset , SeekOrigin . Begin ) ;
62
+ //seek to the last max offset
63
+ reader . BaseStream . Seek ( lastMaxOffset , SeekOrigin . Begin ) ;
43
64
44
- //read out of the file until the EOF
45
- string line = "" ;
65
+ //read out of the file until the EOF
66
+ string line = "" ;
67
+ while ( ( line = reader . ReadLine ( ) ) != null )
68
+ RoR2 . Console . instance . SubmitCmd ( null , line ) ;
46
69
47
- while ( ( line = reader . ReadLine ( ) ) != null )
48
- RoR2 . Console . instance . SubmitCmd ( null , line ) ;
70
+ //update the last max offset
71
+ lastMaxOffset = reader . BaseStream . Position ;
72
+ }
49
73
}
50
74
}
51
75
}
0 commit comments