/// <summary> /// Runs a block of Lua code from a file, which may be archived. /// </summary> /// <param name="name">The name of the file with the code to run.</param> /// <param name="env">The Lua environment to run it in.</param> /// <returns>The script's return value, or False if an error occurred.</returns> public static LuaResult RunFile(string name, LuaGlobal env = null) { var ret = Run(Mix.GetString(name), env); var files = Mix.GetFilesWithPattern("*-" + name); if (files.Length > 0) { foreach (var extra in files) { ret = Run(Mix.GetString(extra), env); } } return(ret); }
public MainForm() { #if !DEBUG try #endif { this.Text = "Noxico"; this.BackColor = System.Drawing.Color.Black; this.DoubleBuffered = true; this.FormBorderStyle = FormBorderStyle.FixedSingle; this.MaximizeBox = false; //it's about time, too! this.FormClosing += new FormClosingEventHandler(this.Form1_FormClosing); this.KeyDown += new KeyEventHandler(this.Form1_KeyDown); this.KeyPress += new KeyPressEventHandler(this.Form1_KeyPress); this.KeyUp += new KeyEventHandler(this.Form1_KeyUp); this.Icon = global::Noxico.Properties.Resources.app; this.ClientSize = new Size(Program.Cols * cellWidth, Program.Rows * cellHeight); this.Controls.Add(new Label() { Text = "Loading...", AutoSize = true, Font = new System.Drawing.Font("Arial", 24, FontStyle.Bold | FontStyle.Italic), ForeColor = System.Drawing.Color.White, Visible = true, Location = new System.Drawing.Point(16, 16) }); foreach (var reqDll in new[] { "Neo.Lua.dll" }) { if (!File.Exists(reqDll)) { throw new FileNotFoundException("Required DLL " + reqDll + " is missing."); } } try { Mix.Initialize("Noxico"); } catch (UnauthorizedAccessException) { if (!UacHelper.IsProcessElevated) { var proc = new System.Diagnostics.ProcessStartInfo(); proc.UseShellExecute = true; proc.WorkingDirectory = Environment.CurrentDirectory; proc.FileName = Application.ExecutablePath; proc.Verb = "runas"; try { System.Diagnostics.Process.Start(proc); } catch { } } Close(); return; } if (!Mix.FileExists("credits.txt")) { SystemMessageBox.Show(this, "Could not find game data. Please redownload the game.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } var portable = false; IniPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "noxico.ini"); if (File.Exists("portable")) { portable = true; var oldIniPath = IniPath; IniPath = "noxico.ini"; Program.CanWrite(); /* * if (!Program.CanWrite()) * { * var response = SystemMessageBox.Show(this, "Trying to start in portable mode, but from a protected location. Use non-portable mode?" + Environment.NewLine + "Selecting \"no\" may cause errors.", Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); * if (response == DialogResult.Cancel) * { * Close(); * return; * } * else if (response == DialogResult.Yes) * { * IniPath = oldIniPath; * portable = false; * } * } */ } if (!File.Exists(IniPath)) { File.WriteAllText(IniPath, Mix.GetString("noxico.ini")); } IniFile.Load(IniPath); if (portable) { IniFile.SetValue("misc", "vistasaves", false); IniFile.SetValue("misc", "savepath", "./saves"); IniFile.SetValue("misc", "shotpath", "./screenshots"); } RestartGraphics(true); fourThirtySeven = IniFile.GetValue("misc", "437", false); Noxico = new NoxicoGame(); Noxico.Initialize(this); MouseUp += new MouseEventHandler(MainForm_MouseUp); MouseWheel += new MouseEventHandler(MainForm_MouseWheel); GotFocus += (s, e) => { Vista.GamepadFocused = true; }; LostFocus += (s, e) => { Vista.GamepadFocused = false; }; Vista.GamepadEnabled = IniFile.GetValue("misc", "xinput", true); Program.WriteLine("Environment: {0} {1}", Environment.OSVersion.Platform, Environment.OSVersion); Program.WriteLine("Application: {0}", Application.ProductVersion); if (Environment.OSVersion.Platform == PlatformID.Unix) { Program.WriteLine("*** You are running on a *nix system. ***"); Program.WriteLine("Key repeat delays exaggerated."); NoxicoGame.Mono = true; Vista.GamepadEnabled = false; } this.Controls.Clear(); starting = false; Running = true; Cursor = new Point(-1, -1); cursorPens = new Pen[3, 16]; cursorPens[0, 0] = cursorPens[1, 0] = cursorPens[2, 0] = Pens.Black; for (var i = 1; i < 9; i++) { cursorPens[0, i] = cursorPens[0, 16 - i] = new Pen(Color.FromArgb((i * 16) - 1, (i * 16) - 1, 0)); cursorPens[1, i] = cursorPens[1, 16 - i] = new Pen(Color.FromArgb(0, (i * 32) - 1, 0)); cursorPens[2, i] = cursorPens[2, 16 - i] = new Pen(Color.FromArgb((i * 32) - 1, (i * 32) - 1, (i * 32) - 1)); } fpsTimer = new Timer() { Interval = 1000, Enabled = true, }; fpsTimer.Tick += (s, e) => { this.Text = "Noxico - " + NoxicoGame.Updates + " updates, " + Frames + " frames"; NoxicoGame.Updates = 0; Frames = 0; }; #if GAMELOOP while (Running) { Noxico.Update(); Application.DoEvents(); } #else FormClosing += new FormClosingEventHandler(MainForm_FormClosing); var speed = IniFile.GetValue("misc", "speed", 15); if (speed <= 0) { speed = 15; } timer = new Timer() { Interval = speed, Enabled = true, }; timer.Tick += new EventHandler(timer_Tick); #endif } #if !DEBUG catch (Exception x) { new ErrorForm(x).ShowDialog(this); SystemMessageBox.Show(this, x.ToString(), Application.ProductName, MessageBoxButtons.OK); Running = false; fatal = true; Application.ExitThread(); } #endif if (!fatal) { Noxico.SaveGame(); } }
public static void ReadBook(string bookID) { var bookData = new string[0]; try { bookData = Mix.GetString("books\\" + bookID + ".txt").Split('\n'); } catch (FileNotFoundException) { bookData = i18n.GetString("book_404").Split('\n'); } var text = new StringBuilder(); var header = string.Empty; var identification = string.Empty; /* * var fonts = new Dictionary<string, int>() * { * { "Hand", 0x200 }, * { "Carve", 0x234 }, * { "Daedric", 0x24E }, * { "Alternian", 0x268 }, * { "Felin", 0x282 }, * }; */ for (var i = 0; i < bookData.Length; i++) { if (bookData[i].StartsWith("##")) { header = bookData[i].Substring(3); i++; if (bookData[i].StartsWith("##")) { i++; //skip author } if (bookData[i].StartsWith("##")) { identification = bookData[i].Substring(3); i++; } //var fontOffset = 0; //var fontHasLower = false; for (; i < bookData.Length; i++) { var line = bookData[i]; if (line.StartsWith("## ")) { break; } for (int j = 0; j < line.Length; j++) { if (j < line.Length - 2 && line.Substring(j, 3) == "<b>") { text.Append("<cYellow>"); j += 2; } else if (j < line.Length - 3 && line.Substring(j, 4) == "</b>") { text.Append(" <c>"); j += 3; } /* * else if (j < line.Length - 2 && line.Substring(j, 2) == "<f") * { * var fontName = line.Substring(j + 2); * fontName = fontName.Remove(fontName.IndexOf('>')); * j = j + fontName.Length + 2; * fontOffset = fonts.ContainsKey(fontName) ? fonts[fontName] : 0; * fontHasLower = fontName == "Hand"; * } * else * { * if (fontOffset == 0) */ text.Append(line[j]); /* * else * { * if (line[j] >= 'A' && line[j] <= 'Z') * { * text.Append((char)((line[j] - 'A') + fontOffset)); * } * else if (fontHasLower && line[j] >= 'a' && line[j] <= 'z') * { * text.Append((char)((line[j] - 'a') + fontOffset + 0x1A)); * } * else * { * text.Append(line[j]); * } * } * } */ } //text.Append(bookData[i]); //text.AppendLine(); } break; } } var player = NoxicoGame.Me.Player.Character; if (!identification.IsBlank()) { foreach (var item in NoxicoGame.KnownItems.Where(ki => ki.HasToken("identify") && ki.GetToken("identify").Text == identification && !NoxicoGame.Identifications.Contains(ki.ID))) { NoxicoGame.Identifications.Add(item.ID); } //text += "<cLime>(Your " + skillProper + " knowledge has gone up.)"; } Plain(text.ToString(), header); }
public static void Handler() { var host = NoxicoGame.HostForm; if (Subscreens.FirstDraw) { Subscreens.FirstDraw = false; UIManager.Initialize(); UIManager.Elements.Add(new UIWindow(i18n.GetString("pause_title")) { Left = 3, Top = 1, Width = 22, Height = pages.Count + 2 }); UIManager.Elements.Add(new UIWindow(string.Empty) { Left = 28, Top = 1, Width = 49, Height = 23 }); list = new UIList() { Width = 20, Height = pages.Count, Left = 4, Top = 2, Background = UIColors.WindowBackground }; list.Items.AddRange(pages.Keys); list.Change += (s, e) => { page = list.Index; text.Text = pages.Values.ElementAt(page); UIManager.Draw(); }; list.Enter += (s, e) => { if (list.Index == list.Items.Count - 1) //can't use absolute index because Debug might be missing. { host.Close(); } else if (list.Index == list.Items.Count - 2) //same { //System.Diagnostics.Process.Start(host.IniPath); Options.Open(); } else if (list.Index == 4) { TextScroller.Plain(Mix.GetString("credits.txt"), i18n.GetString("pause_credits"), false); } }; text = new UILabel("...") { Left = 30, Top = 2 }; UIManager.Elements.Add(list); UIManager.Elements.Add(text); list.Index = IniFile.GetValue("misc", "rememberpause", true) ? page : 0; UIManager.Highlight = list; Subscreens.Redraw = true; } if (Subscreens.Redraw) { Subscreens.Redraw = false; UIManager.Draw(); } if (NoxicoGame.IsKeyDown(KeyBinding.Back) || Vista.Triggers == XInputButtons.B) { NoxicoGame.ClearKeys(); NoxicoGame.Immediate = true; NoxicoGame.Me.CurrentBoard.Redraw(); NoxicoGame.Me.CurrentBoard.Draw(true); NoxicoGame.Mode = UserMode.Walkabout; Subscreens.FirstDraw = true; } else { UIManager.CheckKeys(); } }