public void Initialize(StateInitDesc initDesc) { Kernel = initDesc.Kernel; _dataContent = initDesc.DataContent; _archiveManager = initDesc.ArchiveManager; _graphics = initDesc.GraphicsDevice; _input = initDesc.InputManager; _stateChange = initDesc.StateChange; _shader = new KingdomShader(initDesc.ContentManager); _camera = new Camera() { CameraPosition = new Vector3(0, 100, 200), CameraRotationYawPitchRoll = new Vector3(90, 0, 10), }; _menuState = new MenuState(this); Kernel.World = initDesc.StateSettings.GetInt("WorldId", Kernel.World); Kernel.Area = initDesc.StateSettings.GetInt("PlaceId", Kernel.Area); Kernel.Entrance = initDesc.StateSettings.GetInt("SpawnId", Kernel.Entrance); Field = new Kh2Field( Kernel, _camera, initDesc.StateSettings, _graphics.GraphicsDevice, _shader, _input); BasicallyForceToReloadEverything(); _menuState.Initialize(initDesc); }
public async Task SaveThumbnail(int id, string fileName, IDataContent content) { try { TransactionOptions topts = new TransactionOptions() { Timeout = TimeSpan.FromSeconds(60), IsolationLevel = IsolationLevel.Serializable }; using (TransactionScope trxScope = new TransactionScope(TransactionScopeOption.Required, topts, TransactionScopeAsyncFlowOption.Enabled)) using (System.Data.Common.DbConnection conn = _connectionFactory.GetRIAppDemoConnection()) { DbContextOptionsBuilder <AdventureWorksLT2012Context> dbOptionsBuilder = new DbContextOptionsBuilder <AdventureWorksLT2012Context>(); dbOptionsBuilder.UseSqlServer(conn); // Create in the same transaction !!! using (AdventureWorksLT2012Context db = new AdventureWorksLT2012Context(dbOptionsBuilder.Options)) { Product product = await db.Product.Where(a => a.ProductId == id).FirstOrDefaultAsync(); if (product == null) { throw new Exception(string.Format("Product {0} is Not Found", id)); } using (BlobStream blobStream = new BlobStream(conn as SqlConnection, "[SalesLT].[Product]", "ThumbNailPhoto", string.Format("WHERE [ProductID]={0}", id))) using (BufferedStream bufferedStream = new BufferedStream(blobStream, 128 * 1024)) { await blobStream.InitColumnAsync(); blobStream.Open(); Task delayTask = Task.Delay(TimeSpan.FromSeconds(15)); Task completedTask = await Task.WhenAny(content.CopyToAsync(bufferedStream), delayTask); if (completedTask == delayTask) { throw new Exception("Saving Image took longer than expected"); } await bufferedStream.FlushAsync(); } product.ThumbnailPhotoFileName = fileName; await db.SaveChangesAsync(); trxScope.Complete(); } } } catch (Exception ex) { string msg = ""; if (ex != null) { msg = ex.GetFullMessage(); } _logger.LogError(ex, msg); throw; } }
public void Initialize(StateInitDesc initDesc) { Kernel = initDesc.Kernel; _dataContent = initDesc.DataContent; _archiveManager = initDesc.ArchiveManager; _graphics = initDesc.GraphicsDevice; _input = initDesc.InputManager; _stateChange = initDesc.StateChange; _shader = new KingdomShader(initDesc.ContentManager); _camera = new Camera() { CameraPosition = new Vector3(0, 100, 200), CameraRotationYawPitchRoll = new Vector3(90, 0, 10), }; _menuState = new MenuState(this); _worldId = initDesc.StateSettings.GetInt("WorldId", 2); _placeId = initDesc.StateSettings.GetInt("PlaceId", 4); _spawnId = initDesc.StateSettings.GetInt("SpawnId", 99); _spawnScriptMap = initDesc.StateSettings.GetInt("SpawnScriptMap", 0x06); _spawnScriptBtl = initDesc.StateSettings.GetInt("SpawnScriptBtl", 0x01); _spawnScriptEvt = initDesc.StateSettings.GetInt("SpawnScriptEvt", 0x16); BasicallyForceToReloadEverything(); _menuState.Initialize(initDesc); }
public Kh2Map(GraphicsDevice graphics, IDataContent content, string path) { _graphics = graphics; var binarc = content.FileOpen(path).Using(Bar.Read); _skybox0MeshGroup = FromMdlx(graphics, binarc, "SK0") ?? Empty; _skybox1MeshGroup = FromMdlx(graphics, binarc, "SK1") ?? Empty; _mapMeshGroup = FromMdlx(graphics, binarc, "MAP") ?? Empty; _bobEntities = binarc.ForEntry("out", Bar.EntryType.BgObjPlacement, BobDescriptor.Read)? .Select(x => new BobEntity(x))?.ToList() ?? new List <BobEntity>(); var bobModels = binarc.ForEntries("BOB", Bar.EntryType.Model, Mdlx.Read).ToList(); var bobTextures = binarc.ForEntries("BOB", Bar.EntryType.ModelTexture, ModelTexture.Read).ToList(); _bobModels = new List <MeshGroup>(bobModels.Count); for (var i = 0; i < bobModels.Count; i++) { _bobModels.Add(new MeshGroup { MeshDescriptors = MeshLoader.FromKH2(bobModels[i]).MeshDescriptors, Textures = bobTextures[i].LoadTextures(graphics).ToArray() }); } }
public IdxMultipleDataContent(IDataContent baseDataContent, Stream imgStream) { var dataContents = Constants.WorldIds .Select(worldId => $"000{worldId}.idx") .Select(fileName => baseDataContent.FileOpen(fileName)) .Where(stream => stream != null) .Select(stream => stream.Using(s => new IdxDataContent(s, imgStream))) .ToArray(); _dataContent = new MultipleDataContent(dataContents); }
public OpenKhGame(string[] args) { var contentPath = args.FirstOrDefault() ?? Config.DataPath; _dataContent = CreateDataContent(contentPath, Config.IdxFilePath, Config.ImgFilePath); _dataContent = new MultipleDataContent(new ModDataContent(), _dataContent); if (Kernel.IsReMixFileHasHdAssetHeader(_dataContent, "fm")) { Log.Info("ReMIX files with HD asset header detected"); _dataContent = new HdAssetContent(_dataContent); } _dataContent = new SafeDataContent(_dataContent); _kernel = new Kernel(_dataContent); var resolutionWidth = GetResolutionWidth(); var resolutionHeight = GetResolutionHeight(); Log.Info($"Internal game resolution set to {resolutionWidth}x{resolutionHeight}"); graphics = new GraphicsDeviceManager(this) { PreferredBackBufferWidth = (int)Math.Round(resolutionWidth * Config.ResolutionBoost), PreferredBackBufferHeight = (int)Math.Round(resolutionHeight * Config.ResolutionBoost), IsFullScreen = Config.IsFullScreen, }; Content.RootDirectory = "Content"; IsMouseVisible = true; archiveManager = new ArchiveManager(_dataContent); inputManager = new InputManager(); _debugOverlay = new DebugOverlay(this); Config.OnConfigurationChange += () => { var resolutionWidth = GetResolutionWidth(); var resolutionHeight = GetResolutionHeight(); var backBufferWidth = (int)Math.Round(resolutionWidth * Config.ResolutionBoost); var backBufferHeight = (int)Math.Round(resolutionHeight * Config.ResolutionBoost); if (graphics.PreferredBackBufferWidth != backBufferWidth || graphics.PreferredBackBufferHeight != backBufferHeight || graphics.IsFullScreen != Config.IsFullScreen) { graphics.PreferredBackBufferWidth = backBufferWidth; graphics.PreferredBackBufferHeight = backBufferHeight; graphics.IsFullScreen = Config.IsFullScreen; _isResolutionChanged = true; Log.Info($"Internal game resolution set to {resolutionWidth}x{resolutionHeight}"); } }; }
private static int DetectRegion(IDataContent dataContent) { for (var i = 0; i < Constants.Regions.Length; i++) { var testFileName = $"menu/{Constants.Regions[i]}/title.2ld"; if (dataContent.FileExists(testFileName)) { return(i); } } throw new Exception("Unable to detect any region for the game. Some files are potentially missing."); }
public void Initialize(StateInitDesc initDesc) { _kernel = initDesc.Kernel; _dataContent = initDesc.DataContent; _archiveManager = initDesc.ArchiveManager; _graphics = initDesc.GraphicsDevice; _input = initDesc.InputManager; _shader = new KingdomShader(initDesc.ContentManager); _camera = new Camera() { CameraPosition = new Vector3(0, 100, 200), CameraRotationYawPitchRoll = new Vector3(90, 0, 10), }; BasicallyForceToReloadEverything(); }
public void LogData <T>(IDataContent <T> data) { Log log = new Log(); log.ErrorMessage = data.Message; log.Status = data.Status; log.LogDate = DateTime.Now; log.HttpHeader = data.Headers; try { ISession session = NHibernateManager.BeginSessionTransaction(); LogDAO.Instance.Save(log, session); NHibernateManager.CommitTransactionAndClose(); } catch (Exception e) { NHibernateManager.RollBackTransaction(); throw new Exception(e.Message); } }
public OpenKhGame() { _dataContent = new SafeDataContent(CreateDataContent(".", "KH2.IDX", "KH2.IMG")); _kernel = new Kernel(_dataContent); var resolutionWidth = _kernel.IsReMix ? Global.ResolutionRemixWidth : Global.ResolutionWidth; graphics = new GraphicsDeviceManager(this) { PreferredBackBufferWidth = (int)Math.Round(resolutionWidth * Global.ResolutionBoostRatio), PreferredBackBufferHeight = (int)Math.Round(Global.ResolutionHeight * Global.ResolutionBoostRatio) }; Content.RootDirectory = "Content"; IsMouseVisible = true; archiveManager = new ArchiveManager(_dataContent); inputManager = new InputManager(); _debugOverlay = new DebugOverlay(this); }
public Kernel(IDataContent dataContent) { _dataContent = dataContent; FontContext = new FontContext(); MessageProvider = new Kh2MessageProvider(); RegionId = DetectRegion(dataContent); IsReMix = DetectReMix(dataContent, Region); // Load files in the same order as KH2 does ObjEntries = LoadFile("00objentry.bin", stream => Objentry.Read(stream)); // 00progress LoadSystem("03system.bin"); LoadBattle("00battle.bin"); // 00common // 00worldpoint // 07localset // 12soundinfo // 14mission LoadFontImage($"msg/{Language}/fontimage.bar"); LoadFontInfo($"msg/{Language}/fontinfo.bar"); Places = LoadFile($"msg/{Language}/place.bin", stream => Place.Read(stream)); LoadMessage("sys"); // 15jigsaw if (Language == "jp") { SystemMessageContext = FontContext.ToKh2JpSystemTextContext(); EventMessageContext = FontContext.ToKh2JpEventTextContext(); } else { SystemMessageContext = FontContext.ToKh2EuSystemTextContext(); EventMessageContext = FontContext.ToKh2EuEventTextContext(); } }
public HdAssetContent(IDataContent innerDataContext) { _innerDataContext = innerDataContext; }
public OpenKhGame(OpenKhGameStartup startup) { _startup = startup; GlobalSettings = new Dictionary <string, string>(); TryAddSetting("WorldId", startup.InitialMap); TryAddSetting("PlaceId", startup.InitialPlace); //TryAddSetting("SpawnId", ); TryAddSetting("SpawnScriptMap", startup.InitialSpawnScriptMap); TryAddSetting("SpawnScriptBtl", startup.InitialSpawnScriptBtl); TryAddSetting("SpawnScriptEvt", startup.InitialSpawnScriptEvt); var contentPath = startup.ContentPath ?? Config.DataPath; _dataContent = CreateDataContent(contentPath, Config.IdxFilePath, Config.ImgFilePath); _dataContent = new MultipleDataContent(new ModDataContent(), _dataContent); if (Kernel.IsReMixFileHasHdAssetHeader(_dataContent, "fm")) { Log.Info("ReMIX files with HD asset header detected"); _dataContent = new HdAssetContent(_dataContent); } _dataContent = new SafeDataContent(_dataContent); _kernel = new Kernel(_dataContent); if (startup.InitialState != 0) { _kernel.LoadSaveData(Config.LastSave); } var resolutionWidth = GetResolutionWidth(); var resolutionHeight = GetResolutionHeight(); Log.Info("Internal game resolution set to {0}x{1}", resolutionWidth, resolutionHeight); graphics = new GraphicsDeviceManager(this) { PreferredBackBufferWidth = (int)Math.Round(resolutionWidth * Config.ResolutionBoost), PreferredBackBufferHeight = (int)Math.Round(resolutionHeight * Config.ResolutionBoost), IsFullScreen = Config.IsFullScreen, }; Content.RootDirectory = "Content"; IsMouseVisible = true; archiveManager = new ArchiveManager(_dataContent); inputManager = new InputManager(); _debugOverlay = new DebugOverlay(this); Config.OnConfigurationChange += () => { var resolutionWidth = GetResolutionWidth(); var resolutionHeight = GetResolutionHeight(); var backBufferWidth = (int)Math.Round(resolutionWidth * Config.ResolutionBoost); var backBufferHeight = (int)Math.Round(resolutionHeight * Config.ResolutionBoost); if (graphics.PreferredBackBufferWidth != backBufferWidth || graphics.PreferredBackBufferHeight != backBufferHeight || graphics.IsFullScreen != Config.IsFullScreen) { graphics.PreferredBackBufferWidth = backBufferWidth; graphics.PreferredBackBufferHeight = backBufferHeight; graphics.IsFullScreen = Config.IsFullScreen; _isResolutionChanged = true; Log.Info($"Internal game resolution set to {resolutionWidth}x{resolutionHeight}"); } }; }
public void Initialize(StateInitDesc initDesc) { _kernel = initDesc.Kernel; _content = initDesc.DataContent; _archiveManager = initDesc.ArchiveManager; Input = initDesc.Input; var viewport = initDesc.GraphicsDevice.GraphicsDevice.Viewport; _shader = new KingdomShader(initDesc.ContentManager); _drawing = new MonoSpriteDrawing(initDesc.GraphicsDevice.GraphicsDevice, _shader); _drawing.SetProjection( viewport.Width, viewport.Height, Global.ResolutionWidth, Global.ResolutionHeight, 1.0f); initDesc.GraphicsDevice.GraphicsDevice.DepthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState { DepthBufferEnable = false, StencilEnable = false, }; var messageContext = _kernel.SystemMessageContext; _messageRenderer = new Kh2MessageRenderer(_drawing, messageContext); _archiveManager.LoadArchive($"menu/{_kernel.Region}/camp.2ld"); (_campLayout, _textures) = GetLayoutResources("camp", "camp"); _layoutRenderer = new LayoutRenderer(_campLayout, _drawing, _textures) { SelectedSequenceGroupIndex = 0 }; SequenceFactory = new AnimatedSequenceFactory( _drawing, initDesc.Kernel.MessageProvider, _messageRenderer, _kernel.SystemMessageContext.Encoder, _campLayout.SequenceItems[1], _textures.First()); _backgroundSeq = SequenceFactory.Create(new List <AnimatedSequenceDesc> { new AnimatedSequenceDesc { SequenceIndexStart = 107, SequenceIndexLoop = 108, SequenceIndexEnd = 109, }, new AnimatedSequenceDesc { SequenceIndexStart = 110, SequenceIndexLoop = 111, SequenceIndexEnd = 112, }, new AnimatedSequenceDesc { SequenceIndexStart = 113, SequenceIndexLoop = 114, SequenceIndexEnd = 115, } }); _subMenuDescriptionSeq = SequenceFactory.Create(new List <AnimatedSequenceDesc>()); }
private static bool DetectReMix(IDataContent dataContent, string region) { var testFileName = $"menu/{region}/titlejf.2ld"; return(dataContent.FileExists(testFileName)); }
public SafeDataContent(IDataContent innerDataContext) { _innerDataContext = innerDataContext; }