Skip to content

Commit 70b8eb3

Browse files
committed
runcode() fixed
1 parent 4f5585b commit 70b8eb3

48 files changed

Lines changed: 246 additions & 97 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vs/7Sharp/v15/.suo

-15 KB
Binary file not shown.
36 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8d61c4734d20788d13ec3543d7fb14759d1e227e
1+
57dd7c445d99dcf31ef5fab90b50f85a41b53d62

7Sharp/API/7sEnvironment.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,24 @@ public static class _7sEnvironment
1313
public static string Input = "";
1414
public static bool Echo = true;
1515
public static StreamReader CurrentScriptStream = null;
16-
public static List<VarString> Strings;
17-
public static List<VarInt> Ints;
16+
public static List<_7sString> Strings;
17+
public static List<_7sInt> Ints;
1818
public static List<Command> Commands;
19+
public static bool ForceRunningCode = false;
20+
public static string[] CodeBeingForceRun = null;
21+
public static int ForceRunningCodeIndex = 0;
22+
23+
public static void RunCode(string code)
24+
{
25+
if (Program.RunningEnvCode)
26+
{
27+
Techcraft7_DLL_Pack.ColorConsoleMethods.WriteLineColor("Already force running code!", ConsoleColor.Red);
28+
return;
29+
}
30+
string[] list = code.Split('\n');
31+
Program.RunningEnvCode = true;
32+
Program.EnvCode = list;
33+
Program.UpdateEnvironment();
34+
}
1935
}
2036
}

7Sharp/API/Command.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public override string ToString()
1212
{
1313
return string.Format("{0} - {1}", call, help);
1414
}
15-
protected string call { get; set; }
16-
protected string help { get; set; }
15+
protected internal string call { get; set; }
16+
protected internal string help { get; set; }
1717
public virtual void Parse()
1818
{
1919
throw new Exception("Use me only in child classes!");

7Sharp/API/InternalEnv.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ internal class InternalEnv
1616
public static bool parsed = false;
1717
public static string input = "";
1818
public static bool has_args = false;
19-
public static List<VarInt> ints = new List<VarInt>();
20-
public static List<VarString> strings = new List<VarString>();
19+
public static List<_7sInt> ints = new List<_7sInt>();
20+
public static List<_7sString> strings = new List<_7sString>();
2121
public static StreamReader srr = null;
2222
public static int times = 1;
2323
public static List<Command> commands = new List<Command>();
2424
public static bool echo = true;
25+
public static bool RunningEnvCode = false;
26+
public static string[] EnvCode = null;
27+
public static int EnvCodeIndex = 0;
2528
}
2629
}

7Sharp/Program.cs

Lines changed: 108 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace _7Sharp
1212
{
13+
using System.Linq;
1314
using static ColorConsoleMethods;
1415
using static Console;
1516
internal class Program
@@ -21,14 +22,18 @@ internal class Program
2122
public static bool parsed = false;
2223
public static string input = "";
2324
public static bool has_args = false;
24-
public static List<VarInt> ints = new List<VarInt>();
25-
public static List<VarString> strings = new List<VarString>();
25+
public static List<_7sInt> ints = new List<_7sInt>();
26+
public static List<_7sString> strings = new List<_7sString>();
2627
public static StreamReader srr = null;
2728
public static List<Assembly> PluginAssemblies = new List<Assembly>();
2829
public static int times = 1;
2930
public static List<Command> commands = new List<Command>();
3031
public static bool echo = true;
31-
static void Main(string[] args)
32+
public static bool RunningEnvCode = false;
33+
internal static string NoEnvCode = "\0";
34+
public static string[] EnvCode = null;
35+
public static int EnvCodeIndex = 0;
36+
static void Main(string[] args)
3237
{
3338
//title
3439
Title = "7Sharp";
@@ -70,6 +75,7 @@ static void Main(string[] args)
7075
{
7176
try
7277
{
78+
WriteLineColor("Loading plugin " + Path.GetFileName(path), ConsoleColor.Green);
7379
//load dll
7480
Assembly asm = Assembly.LoadFrom(path);
7581
//load assembly of dll
@@ -79,6 +85,8 @@ static void Main(string[] args)
7985
{
8086
if (t.IsSubclassOf(typeof(Command)))
8187
{
88+
Command instance = (Command)Activator.CreateInstance(t);
89+
WriteLineColor("Found command " + t, ConsoleColor.Cyan);
8290
//check for no parameter constructor
8391
if (t.GetConstructor(Type.EmptyTypes) == null)
8492
{
@@ -89,12 +97,19 @@ static void Main(string[] args)
8997
{
9098
throw new PluginIntializationException("Plugin " + Path.GetFileName(path) + ": Command " + t.Name + " did not have a parse method!");
9199
}
100+
//check for exisiting call
101+
if (GetCalls().Contains(instance.call))
102+
{
103+
throw new PluginIntializationException("Plugin " + Path.GetFileName(path) + ": Command " + t.Name + " has a conflicting call!");
104+
}
92105
//create instance
93-
commands.Add((Command)Activator.CreateInstance(t));
106+
commands.Add(instance);
94107
//woo hoo it works!
95-
successes++;
96108
}
97109
}
110+
successes++;
111+
WriteLineColor("Successfully registered plugin " + Path.GetFileName(path), ConsoleColor.Green);
112+
WriteLineColor("Successfully registered " + successes + " plugin(s)!", ConsoleColor.Green);
98113
}
99114
catch (Exception e)
100115
{
@@ -116,27 +131,53 @@ static void Main(string[] args)
116131
UpdateEnvironment();
117132
while (true)
118133
{
119-
if (!has_args)
134+
if (!RunningEnvCode)
120135
{
121-
input = ReadLine();
122-
input_split = input.Split(' ', '\n');
123-
UpdateEnvironment();
124-
ParseCommands();
136+
if (!has_args)
137+
{
138+
input = ReadLine();
139+
input_split = input.Split(' ', '\n');
140+
UpdateEnvironment();
141+
ParseCommands();
142+
}
143+
else
144+
{
145+
while (srr.EndOfStream == false)
146+
{
147+
input = srr.ReadLine();
148+
input_split = input.Split(' ', '\n');
149+
UpdateEnvironment();
150+
ParseCommands();
151+
}
152+
srr.Close();
153+
UpdateEnvironment();
154+
}
125155
}
126156
else
127157
{
128-
while (srr.EndOfStream == false)
158+
while (EnvCodeIndex < EnvCode.Length)
129159
{
130-
input = srr.ReadLine();
131-
input_split = input.Split(' ', '\n');
132-
UpdateEnvironment();
133160
ParseCommands();
161+
EnvCodeIndex++;
162+
UpdateEnvironment();
134163
}
135-
srr.Close();
164+
RunningEnvCode = false;
165+
EnvCodeIndex = 0;
136166
UpdateEnvironment();
137167
}
138168
}
139169
}
170+
171+
private static List<string> GetCalls()
172+
{
173+
List<string> o = new List<string>();
174+
foreach (Command i in commands)
175+
{
176+
o.Add(i.call);
177+
}
178+
return o;
179+
}
180+
140181
private static void ParseCommands()
141182
{
142183
foreach (Command i in commands)
@@ -145,8 +186,12 @@ private static void ParseCommands()
145186
}
146187
}
147188

148-
private static void UpdateEnvironment()
189+
internal static void UpdateEnvironment()
149190
{
191+
if (RunningEnvCode && EnvCodeIndex < EnvCode.Length)
192+
{
193+
input = EnvCode[EnvCodeIndex];
194+
}
150195
InternalEnv.commands = commands;
151196
InternalEnv.echo = echo;
152197
InternalEnv.exit = exit;
@@ -160,13 +205,60 @@ private static void UpdateEnvironment()
160205
InternalEnv.strings = strings;
161206
InternalEnv.times = times;
162207
InternalEnv._inputs = _inputs;
208+
InternalEnv.EnvCode = EnvCode;
209+
InternalEnv.EnvCodeIndex = EnvCodeIndex;
210+
InternalEnv.RunningEnvCode = RunningEnvCode;
163211
_7sEnvironment.Commands = commands;
164212
_7sEnvironment.Echo = echo;
165213
_7sEnvironment.Input = input;
166214
_7sEnvironment.Ints = ints;
167215
_7sEnvironment.SplitInput = input.Split(' ', '\n');
168216
_7sEnvironment.Strings = strings;
169217
_7sEnvironment.CurrentScriptStream = srr;
218+
_7sEnvironment.ForceRunningCode = RunningEnvCode;
219+
_7sEnvironment.CodeBeingForceRun = EnvCode;
220+
_7sEnvironment.ForceRunningCodeIndex = EnvCodeIndex;
221+
}
222+
internal static void UpdateEnvironment(bool force)
223+
{
224+
if (RunningEnvCode && EnvCodeIndex < EnvCode.Length && !force)
225+
{
226+
input = EnvCode[EnvCodeIndex];
227+
}
228+
InternalEnv.commands = commands;
229+
InternalEnv.echo = echo;
230+
InternalEnv.exit = exit;
231+
InternalEnv.has_args = has_args;
232+
InternalEnv.input = input;
233+
InternalEnv.input_split = input.Split(' ', '\n');
234+
InternalEnv.ints = ints;
235+
InternalEnv.loop = loop;
236+
InternalEnv.parsed = parsed;
237+
InternalEnv.srr = srr;
238+
InternalEnv.strings = strings;
239+
InternalEnv.times = times;
240+
InternalEnv._inputs = _inputs;
241+
InternalEnv.EnvCode = EnvCode;
242+
InternalEnv.EnvCodeIndex = EnvCodeIndex;
243+
InternalEnv.RunningEnvCode = RunningEnvCode;
244+
_7sEnvironment.Commands = commands;
245+
_7sEnvironment.Echo = echo;
246+
_7sEnvironment.Input = input;
247+
_7sEnvironment.Ints = ints;
248+
_7sEnvironment.SplitInput = input.Split(' ', '\n');
249+
_7sEnvironment.Strings = strings;
250+
_7sEnvironment.CurrentScriptStream = srr;
251+
_7sEnvironment.ForceRunningCode = RunningEnvCode;
252+
_7sEnvironment.CodeBeingForceRun = EnvCode;
253+
_7sEnvironment.ForceRunningCodeIndex = EnvCodeIndex;
254+
}
255+
256+
internal static void UpdateInputFromEnvCode()
257+
{
258+
bool last = EnvCodeIndex == EnvCode.Length;
259+
input = has_args == true ? srr.ReadLine() : (RunningEnvCode ? (last ? NoEnvCode : EnvCode[EnvCodeIndex + 1]) : ReadLine());
260+
EnvCodeIndex++;
261+
UpdateEnvironment();
170262
}
171263
}
172264
}

7Sharp/bin/Debug/7Sharp.exe

44.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)