Beispiel #1
0
 public void Dispose()
 {
     lock (XEditLibWrapper.LockObject)
     {
         XEditLibWrapper.Release(_handle);
     }
 }
Beispiel #2
0
 public static void Shutdown()
 {
     lock (XEditLibWrapper.LockObject)
     {
         XEditLibWrapper.CloseXEdit();
     }
 }
Beispiel #3
0
 public static void SetGameMode(XEditGame game)
 {
     lock (XEditLibWrapper.LockObject)
     {
         XEditLibWrapper.SetGameMode((int)game);
     }
 }
Beispiel #4
0
 public static uint GetElementUIntValue(ElementHandle element, string valuePath)
 {
     lock (XEditLibWrapper.LockObject)
     {
         ThrowOnError(XEditLibWrapper.GetUIntValue(element, valuePath, out var value));
         return(value);
     }
 }
Beispiel #5
0
 public void AddMaster(string name)
 {
     if (!XEditLib.LoadOrderNames.Contains((RelativePath)name))
     {
         throw new Exception("Cannot add {name} as master, file is not loaded");
     }
     XEditLibWrapper.AddMaster(this, name);
 }
Beispiel #6
0
 public static ElementHandle CopyTo(ElementHandle src, FileHandle file, bool asNew = false)
 {
     lock (XEditLibWrapper.LockObject)
     {
         ThrowOnError(XEditLibWrapper.CopyElement(src, file, asNew, out ElementHandle other));
         return(other);
     }
 }
Beispiel #7
0
 public void Save(string filename)
 {
     lock (XEditLibWrapper.LockObject)
     {
         var order = XEditLib.GetFileLoadOrder(this);
         XEditLib.ThrowOnError(XEditLibWrapper.SaveFile(this, filename));
     }
 }
Beispiel #8
0
 public static ElementHandle GetElement(string path)
 {
     lock (XEditLibWrapper.LockObject)
     {
         ThrowOnError(XEditLibWrapper.GetElement(0, path, out var res), path);
         return(res);
     }
 }
Beispiel #9
0
 public static int GetFileLoadOrder(FileHandle file)
 {
     lock (XEditLibWrapper.LockObject)
     {
         ThrowOnError(XEditLibWrapper.GetFileLoadOrder(file, out var pos));
         return(pos);
     }
 }
Beispiel #10
0
 public static FileHandle GetElementFile(ElementHandle element)
 {
     lock (XEditLibWrapper.LockObject)
     {
         ThrowOnError(XEditLibWrapper.GetElementFile(element, out var file));
         return(file);
     }
 }
Beispiel #11
0
 public static void SetElementStringValue(string elementPath, string valuePath, string value)
 {
     lock (XEditLibWrapper.LockObject)
     {
         using var element = GetElement(elementPath);
         ThrowOnError(XEditLibWrapper.SetValue(element, valuePath, value));
     }
 }
Beispiel #12
0
 public static uint ElementCount(string elementPath, string valuePath)
 {
     lock (XEditLibWrapper.LockObject)
     {
         using var element = GetElement(elementPath + "\\" + valuePath);
         ThrowOnError(XEditLibWrapper.ElementCount(element, out var value));
         return(value);
     }
 }
Beispiel #13
0
 public static double GetElementFloatValue(string elementPath, string valuePath)
 {
     lock (XEditLibWrapper.LockObject)
     {
         using var element = GetElement(elementPath);
         ThrowOnError(XEditLibWrapper.GetFloatValue(element, valuePath, out var value));
         return(value);
     }
 }
Beispiel #14
0
 public static string GetGlobal(string name)
 {
     lock (XEditLibWrapper.LockObject)
     {
         ThrowOnError(XEditLibWrapper.GetGlobal(name, out var len));
         var sb = new StringBuilder((int)len);
         ThrowOnError(XEditLibWrapper.GetResultString(sb, (int)len));
         return(sb.ToString(0, (int)len));
     }
 }
Beispiel #15
0
 public static string GetElementStringValue(ElementHandle element, string valuePath)
 {
     lock (XEditLibWrapper.LockObject)
     {
         ThrowOnError(XEditLibWrapper.GetValue(element, valuePath, out var len));
         var sb = new StringBuilder((int)len);
         ThrowOnError(XEditLibWrapper.GetResultString(sb, (int)len));
         return(sb.ToString(0, (int)len));
     }
 }
Beispiel #16
0
 public static FileHandle AddFile(RelativePath myfileEsp, bool ignoreExists = true)
 {
     lock (XEditLibWrapper.LockObject)
     {
         ThrowOnError(XEditLibWrapper.AddFile((string)myfileEsp.FileName, ignoreExists, out var handle));
         LoadOrderNames.Add(myfileEsp.FileName);
         ThrowOnError(XEditLibWrapper.FileByLoadOrder(LoadOrderNames.IndexOf(myfileEsp.FileName), out FileHandle handle2));
         handle.Dispose();
         return(handle2);
     }
 }
Beispiel #17
0
        public static Cursor GetCursorFromFormId(uint form)
        {
            lock (XEditLibWrapper.LockObject)
            {
                ThrowOnError(XEditLibWrapper.GetRecord(0, form, true, out uint record));

                XEditLibWrapper.GetElement(record, "Record Header\\FormID", out ElementHandle elementHandle);
                using var handle = GetElementFile(elementHandle);
                var pos = GetFileLoadOrder(handle);
                return(new Cursor((uint)pos, form));
            }
        }
Beispiel #18
0
 public static void LoadPlugins(IEnumerable <RelativePath> plugins)
 {
     lock (XEditLibWrapper.LockObject)
     {
         LoadOrderNames = plugins.ToList();
         XEditLibWrapper.LoadPlugins(string.Join("\r\n", plugins.Select(p => p.ToString())));
         byte status = 0;
         while (status < 2)
         {
             ThrowOnError(XEditLibWrapper.GetLoaderStatus(out status));
             Thread.Sleep(100);
         }
     }
 }
Beispiel #19
0
        public static void Init()
        {
            lock (XEditLibWrapper.LockObject)
            {
                XEditLibWrapper.InitXEdit();
                var ext       = new Extension(".dat");
                var srcFolder = "native-libs"
                                .RelativeTo(((AbsolutePath)Assembly.GetExecutingAssembly().Location).Parent);
                var destFolder = ((AbsolutePath)GetGlobal("ProgramPath"));
                foreach (var file in srcFolder.EnumerateFiles().Where(f => f.Extension == ext))
                {
                    var dest = file.RelativeTo(srcFolder).RelativeTo(destFolder);
                    if (dest.Exists)
                    {
                        continue;
                    }

                    file.CopyToAsync(file.RelativeTo(srcFolder).RelativeTo(destFolder)).Wait();
                }
                ListenToMessages();
            }
        }
Beispiel #20
0
        private static void ListenToMessages()
        {
            var th = new Thread(() =>
            {
                while (true)
                {
                    lock (XEditLibWrapper.LockObject)
                    {
                        XEditLibWrapper.GetMessagesLength(out int len);
                        if (len > 0)
                        {
                            var sb = new StringBuilder(len);
                            XEditLibWrapper.GetMessages(sb, len);
                            Utils.Log(sb.ToString(0, len));
                        }
                    }
                    Thread.Sleep(100);
                }
            });

            th.IsBackground = true;
            th.Name         = "XEdit Logging Thread";
            th.Start();
        }