internal static void CreateTile(Tile baseTile, Dictionary <Color, Color> replaceColorsWith, string newVariantTileCode, DirectoryManager directory, Blob overrides) { if (GameContext.TileDatabase.AllMaterials().Any(x => string.Equals(x.Code, newVariantTileCode, StringComparison.CurrentCultureIgnoreCase))) { return; } var file = Regex.Replace(baseTile.Configuration.Source, @"\/|\\", Path.DirectorySeparatorChar.ToString()); var stream = GameContext.ContentLoader.ReadStream(file).ReadAllText(); var blob = BlobAllocator.AcquireAllocator().NewBlob(false); blob.ReadJson(stream); var voxelFile = Regex.Replace(blob.GetString("voxels"), @"\/|\\", Path.DirectorySeparatorChar.ToString()); var output = ChangeColor(voxelFile, replaceColorsWith); directory.WriteQBFile(newVariantTileCode, output); blob.SetString("code", newVariantTileCode); blob.SetString("voxels", directory.GetPath('/') + newVariantTileCode + ".qb"); blob.MergeFrom(overrides); var wait = true; directory.WriteFile(newVariantTileCode + ".tile", blob, () => { wait = false; }, true); while (wait) { } }
public static Blob SerializeObject <T>(T data) { var blob = BlobAllocator.AcquireAllocator().NewBlob(true); blob.ObjectToBlob(null, data); return(blob); }
public void ReadFile <T>(string filename, Action <T> onLoad, bool inputIsText = false) { new Thread(() => { if (FileExists(filename)) { var stream = GameContext.ContentLoader.ReadLocalStream(Path.Combine(_localContentLocation, filename)); Blob input; if (!inputIsText) { input = stream.ReadBlob(); } else { input = BlobAllocator.AcquireAllocator().NewBlob(false); var sr = new StreamReader(stream); input.ReadJson(sr.ReadToEnd()); } stream.Seek(0L, SeekOrigin.Begin); if (typeof(T) == input.GetType()) { onLoad((T)(object)input); } onLoad(input.BlobToObject(null, (T)Activator.CreateInstance(typeof(T)))); } onLoad((T)Activator.CreateInstance(typeof(T))); }).Start(); }
public static List <TInterface> GetDependencies <TInterface>(string key) { var output = new List <TInterface>(); var assembly = Assembly.GetAssembly(typeof(Fox_Core)); var dir = assembly.Location.Substring(0, assembly.Location.LastIndexOf(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)); foreach (var file in new DirectoryInfo(dir).GetFiles("*.mod")) { var data = BlobAllocator.AcquireAllocator().NewBlob(true); data.ReadJson(File.ReadAllText(file.FullName)); if (data.Contains("fxdependencykeys")) { var current = data.GetStringList("fxdependencykeys"); if (current.Any(x => string.Equals(x, key, StringComparison.CurrentCultureIgnoreCase))) { var item = Assembly.Load(Assembly.LoadFile(file.FullName.Replace(".mod", ".dll")).GetName()); foreach (var module in item.DefinedTypes) { if (module.GetInterfaces().Contains(typeof(TInterface))) { output.Add((TInterface)Activator.CreateInstance(module)); } } } } } return(output); }
public void GameContextInitializeInit() { ToRender = new Dictionary <Guid, List <RenderItem> >(); ForbidEditing = new Dictionary <Guid, VectorCubeI>(); NextTick = 0; WorldEditManager.Init(); if (!WorldEditManager.FoxCore.ModDirectory.FileExists("ignore.flag")) { var msgBox = MessageBox.Show(@"Would you like to customise the selection region's colors?", @"Customize World Edit", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (msgBox == DialogResult.Yes) { var defaultPrimary = ColorMath.ParseString("F5C900"); var defaultSecondary = Color.Black; var colorPicker = new ColorPicker(); Application.Run(colorPicker); var primary = ColorMath.ToString(colorPicker.Primary).Substring(2); var secondary = ColorMath.ToString(colorPicker.Secondary).Substring(2); var blob = BlobAllocator.AcquireAllocator().NewBlob(false); var blob2 = blob.FetchBlob("Custom"); blob2.SetString(ColorMath.ToString(defaultPrimary).Substring(2), primary); blob2.SetString(ColorMath.ToString(defaultSecondary).Substring(2), secondary); var wait = true; WorldEditManager.FoxCore.ModDirectory.WriteFile("palettes.json", blob, () => { wait = false; }, true); while (wait) { } colorPicker.Dispose(); } var ms = new MemoryStream(); var sw = new StreamWriter(ms); sw.Write(""); sw.Flush(); var streamWait = true; WorldEditManager.FoxCore.ModDirectory.WriteFileStream("ignore.flag", ms, () => { streamWait = false; }); while (streamWait) { } } }
public static Blob SerializeObject <T>(T data) { if (data is Blob o) { return(o); } var blob = BlobAllocator.AcquireAllocator().NewBlob(true); blob.ReadJson(JsonConvert.SerializeObject(data)); return(blob); }
internal static void ReadSettings() { settings = new Classes.Settings(); if (!InitSettings) { var blob = BlobAllocator.AcquireAllocator().NewBlob(false); blob.ReadJson(File.ReadAllText("./Settings.json")); settings.FromBlob(blob); } }
public void ReadFile <T>(string fileName, Action <T> onLoad, bool inputIsText = false) { new Thread(() => { if (FileExists(fileName)) { var data = File.ReadAllBytes(Path.Combine(_localContentLocation, fileName)); var stream = new MemoryStream(data, 0, data.Length, false, true); stream.Seek(0, SeekOrigin.Begin); Blob input; if (!inputIsText) { input = BlobAllocator.Blob(false); input.Read(stream); } else { if (typeof(T) == typeof(string)) { onLoad((T)(object)stream.ReadAllText()); return; } input = BlobAllocator.AcquireAllocator().NewBlob(false); input.LoadJsonStream(stream); } stream.Close(); stream.Dispose(); if (typeof(T) == input.GetType()) { onLoad((T)(object)input); return; } using (var json = new MemoryStream()) { input.SaveJsonStream(json); json.Seek(0L, SeekOrigin.Begin); onLoad(JsonConvert.DeserializeObject <T>(json.ReadAllText())); Blob.Deallocate(ref input); } return; } onLoad(default);
internal static void CreateItem(Dictionary <Color, Color> replaceColorsWith, string kind, string newVariantTileCode, string source, DirectoryManager directory, Blob overrides) { if (!File.Exists(Path.GetFullPath(Path.Combine(GameContext.ContentLoader.RootDirectory, source)))) { return; } if (GameContext.ItemDatabase.GetConfigsByKind(kind).Any(x => string.Equals(x.Value.Code, newVariantTileCode, StringComparison.CurrentCultureIgnoreCase))) { return; } var file = Regex.Replace(source, @"\/|\\", Path.DirectorySeparatorChar.ToString()); var stream = GameContext.ContentLoader.ReadStream(file).ReadAllText(); var blob = BlobAllocator.AcquireAllocator().NewBlob(false); blob.ReadJson(stream); var voxelIconFile = Regex.Replace(blob.GetString("icon"), @"\/|\\", Path.DirectorySeparatorChar.ToString()); var voxelInHandFile = Regex.Replace(blob.GetString("inHand"), @"\/|\\", Path.DirectorySeparatorChar.ToString()); var iconOutput = ChangeColor(voxelIconFile, replaceColorsWith); var inHandOutput = ChangeColor(voxelInHandFile, replaceColorsWith); directory.WriteQBFile(newVariantTileCode + ".icon", iconOutput); directory.WriteQBFile(newVariantTileCode + ".inHand", inHandOutput); blob.SetString("code", newVariantTileCode); blob.SetString("icon", directory.GetPath('/') + newVariantTileCode + ".icon.qb"); blob.SetString("inHand", directory.GetPath('/') + newVariantTileCode + ".inHand.qb"); blob.MergeFrom(overrides); var wait = true; directory.WriteFile(newVariantTileCode + ".item", blob, () => { wait = false; }, true); while (wait) { } }
internal Blob ToBlob() { var blob = BlobAllocator.AcquireAllocator().NewBlob(true); blob.SetBool("Creative", Creative); blob.SetString("IP", IP); blob.SetString("Name", Name); blob.SetBool("UsePassword", UsePassword); blob.SetString("Password", Password); blob.SetLong("PlayerLimit", PlayerLimit); blob.SetLong("Port", Port); blob.SetBool("Public", Public); blob.SetString("WorldName", WorldName); blob.SetBool("Upnp", Upnp); blob.SetBool("WeakAuthentication", WeakAuthentication); return(blob); }