public Singletons(IMetadataInfo metadataInfo, IReadOnlyDictionary <string, GameReferenceTables> gameReferenceTables, int copyLimit = 40000) { MetadataInfo = metadataInfo; GameReferenceTables = gameReferenceTables; WorkDispatcher = InstantDispatch.Instance; CopyLimit = copyLimit; }
/// <summary> /// /// </summary> /// <param name="metadataInfo"></param> /// <returns></returns> static public PixelFormat GetPixelFormat(IMetadataInfo metadataInfo) { PixelFormat retVal = PixelFormat.Undefined; PropertyItem description = null; foreach (PropertyItem propertyItem in metadataInfo.PropertyItems) { if (propertyItem.Id == PropertyTag.ImageDescription) { description = propertyItem; break; } } // if no/corrupted description => default to 32bits if (description == null) { retVal = PixelFormat.Format32bppArgb; } else { string originalDepth = System.Text.ASCIIEncoding.ASCII.GetString(description.Value); if (System.Text.RegularExpressions.Regex.IsMatch(originalDepth, @"^\D*\d+\D*?") == false) { retVal = PixelFormat.Format32bppArgb; } else { originalDepth = System.Text.RegularExpressions.Regex.Replace(originalDepth, @"^\D*(\d+)\D*?", "$1"); retVal = (PixelFormat)System.Convert.ToInt32(originalDepth); } } return(retVal); }
public StoredMetadata( IReadOnlyList <StoredAnchor> anchors = null, IReadOnlyList <StoredUnmappedPointer> unmappedPointers = null, IReadOnlyList <StoredMatchedWord> matchedWords = null, IReadOnlyList <StoredOffsetPointer> offsetPointers = null, IReadOnlyList <StoredList> lists = null, IReadOnlyList <StoredUnmappedConstant> unmappedConstants = null, IReadOnlyList <StoredGotoShortcut> gotoShortcuts = null, IReadOnlyList <TableGroup> tableGroups = null, IMetadataInfo generalInfo = null, StoredMetadataFields fields = null ) { NamedAnchors = anchors ?? new List <StoredAnchor>(); UnmappedPointers = unmappedPointers ?? new List <StoredUnmappedPointer>(); MatchedWords = matchedWords ?? new List <StoredMatchedWord>(); OffsetPointers = offsetPointers ?? new List <StoredOffsetPointer>(); Lists = lists ?? new List <StoredList>(); UnmappedConstants = unmappedConstants ?? new List <StoredUnmappedConstant>(); GotoShortcuts = gotoShortcuts ?? new List <StoredGotoShortcut>(); TableGroups = tableGroups ?? new List <TableGroup>(); Version = generalInfo?.VersionNumber; if (fields == null) { fields = new StoredMetadataFields(); } FreeSpaceSearch = fields.FreeSpaceSearch; FreeSpaceBuffer = fields.FreeSpaceBuffer; NextExportID = fields.NextExportID; ShowRawIVByteForTrainer = fields.ShowRawIVByteForTrainer; }
private RunnableStep[] ProvideSteps(IMetadataInfo parent, IEnumerable <StepDescriptor> stepDescriptors, object context, IDependencyContainer container, string groupPrefix, Func <Exception, bool> shouldAbortSubStepExecutionFn) { var descriptors = stepDescriptors.ToArray(); if (!descriptors.Any()) { throw new InvalidOperationException("At least one step has to be provided"); } var metadataProvider = _context.IntegrationContext.MetadataProvider; var totalSteps = descriptors.Length; var steps = new RunnableStep[totalSteps]; string previousStepTypeName = null; var extensions = _context.IntegrationContext.ExecutionExtensions; var stepContext = new RunnableStepContext(_context.ExceptionProcessor, _context.ProgressNotifier, container, context, ProvideSteps, shouldAbortSubStepExecutionFn); for (var stepIndex = 0; stepIndex < totalSteps; ++stepIndex) { var descriptor = descriptors[stepIndex]; var stepInfo = new StepInfo(parent, metadataProvider.GetStepName(descriptor, previousStepTypeName), stepIndex + 1, totalSteps, groupPrefix); var arguments = descriptor.Parameters.Select(p => new MethodArgument(p, metadataProvider.GetValueFormattingServiceFor(p.ParameterInfo))).ToArray(); steps[stepIndex] = new RunnableStep(stepContext, stepInfo, descriptor, arguments, extensions.StepDecorators.Concat(metadataProvider.GetStepDecorators(descriptor))); previousStepTypeName = stepInfo.Name.StepTypeName?.OriginalName; } return(steps); }
public AboutWindow(IMetadataInfo metadata) { InitializeComponent(); Version.Text = $"Version {metadata.VersionNumber}"; #if STABLE Usage.Text = "This is a preview release. Please report any bugs via GitHub or Discord."; #endif }
internal void SetMetadata(IMetadataInfo metadataInfo) { if (metadataInfo == null) { return; } _metadataInfo = (IMetadataInfo)metadataInfo.Clone(); }
public StepInfo(IMetadataInfo parent, IStepNameInfo name, int number, int total, string groupPrefix) { Parent = parent; Name = name; Number = number; Total = total; GroupPrefix = groupPrefix; }
private void InternalConstructor(Bitmap bmp) { if (bmp == null) { throw new ArgumentNullException("Bitmap passed in is null"); } _colors = new IColor[bmp.Width, bmp.Height]; _metadataInfo = new MetadataInfo(bmp.PropertyItems); //Verify that metadata correctly set the DPI //In the case where no dpi meta is stored with the image it defaults to the screen resolution //we fix that here in the metadata info Point metaDpi = MetadataInfoHelper.GetDpi(_metadataInfo); Point bmpDpi = new Point((int)Math.Round(bmp.HorizontalResolution), (int)Math.Round(bmp.VerticalResolution)); if (!metaDpi.Equals(bmpDpi)) { MetadataInfoHelper.SetDpi(_metadataInfo, bmpDpi); } ImageUtility image = null; try { image = new ImageUtility(bmp); // Conversion to 32 bits done internally. image.GetSetPixelUnsafeBegin(); byte[] BGRAStream = image.GetStreamBufferBGRA(); image.GetSetPixelUnsafeRollBack(); int size = BGRAStream.Length; for (int index = 0, x = 0, y = 0; index < size; index += 4, x++) // flat array to remove the cost of the computation (x + y *x) { if (x >= Width) { x = 0; y++; } _colors[x, y] = new ColorByte(BGRAStream[index + 3], BGRAStream[index + 2], BGRAStream[index + 1], BGRAStream[index]); if (_colors[x, y].ARGB == 0) { _colors[x, y].IsEmpty = true; } } BGRAStream = null; } finally { if (image != null) { image.Dispose(); image = null; } GC.Collect(GC.MaxGeneration); } }
public static string GetUsageText(IMetadataInfo metadata) { if (metadata != null && metadata.IsPublicRelease) { return("This is a preview release. Please report bugs via GitHub / Discord."); } else { return("This is an unstable version: use at your own risk!"); } }
/// <summary> /// Get the machineInfo associated with this object /// </summary> /// <param name="metadataInfo"></param> /// <returns></returns> static private string GetMachineInfo(IMetadataInfo metadataInfo) { // throw new NotImplementedException("GetMachineInfo API Not implemented yet"); /* * PropertyItem propertyItem = metadataInfo.PropertyItems[(int)PropertyTag.HostComputer]; * if (propertyItem == null) { return string.Empty; } * return System.Text.ASCIIEncoding.ASCII.GetString(propertyItem.Value); */ }
public StoredMetadata( IReadOnlyList <StoredAnchor> anchors, IReadOnlyList <StoredUnmappedPointer> unmappedPointers, IReadOnlyList <StoredMatchedWord> matchedWords, IReadOnlyList <StoredOffsetPointer> offsetPointers, IReadOnlyList <StoredList> lists, IReadOnlyList <StoredUnmappedConstant> unmappedConstants, IReadOnlyList <StoredGotoShortcut> gotoShortcuts, IMetadataInfo generalInfo, StoredMetadataFields fields ) : this(anchors, unmappedPointers, matchedWords, offsetPointers, lists, unmappedConstants, gotoShortcuts, null, generalInfo, fields) { }
// for backwards compatibility for tests public StoredMetadata( IReadOnlyList <StoredAnchor> anchors, IReadOnlyList <StoredUnmappedPointer> unmappedPointers, IReadOnlyList <StoredMatchedWord> matchedWords, IReadOnlyList <StoredOffsetPointer> offsetPointers, IReadOnlyList <StoredList> lists, IReadOnlyList <StoredUnmappedConstant> unmappedConstants, IMetadataInfo generalInfo, int freeSpaceSearch, int freeSpaceBuffer, int nextExportID ) : this(anchors, unmappedPointers, matchedWords, offsetPointers, lists, unmappedConstants, null, null, generalInfo, new StoredMetadataFields { FreeSpaceSearch = freeSpaceSearch, FreeSpaceBuffer = freeSpaceBuffer, NextExportID = nextExportID }) { }
/// <summary> /// Build an ImageAdapter based on an existing IImageAdapter /// </summary> /// <param name="imageAdapterToClone"></param> public ImageAdapter(IImageAdapter imageAdapterToClone) { // Check argument if (imageAdapterToClone == null) { throw new ArgumentNullException("imageAdapterToClone", "Argument passed in must be set to valid instanceof the object (null was passed in)"); } if (imageAdapterToClone.Width <= 0 || imageAdapterToClone.Height <= 0) { string errorMessage = string.Empty; string actualValue = string.Empty; if (imageAdapterToClone.Width <= 0) { errorMessage += "ImageAdapter Width is invalid (should be strictly > 0)\n"; actualValue += "Width=" + imageAdapterToClone.Width + "\n"; } if (imageAdapterToClone.Height <= 0) { errorMessage += "ImageAdapter Height is invalid (should be strictly > 0)"; actualValue += "Height=" + imageAdapterToClone.Height; } throw new ArgumentOutOfRangeException("imageAdapterToClone", actualValue, errorMessage); } _colors = new IColor[imageAdapterToClone.Width, imageAdapterToClone.Height]; for (int y = 0; y < imageAdapterToClone.Height; y++) { for (int x = 0; x < imageAdapterToClone.Width; x++) { if (imageAdapterToClone[x, y] != null) { _colors[x, y] = (IColor)imageAdapterToClone[x, y].Clone(); } } } if (imageAdapterToClone.Metadata != null) { _metadataInfo = (IMetadataInfo)imageAdapterToClone.Metadata.Clone(); } }
static internal void SetDpi(IMetadataInfo metadataInfo, Point dpi) { foreach (PropertyItem pItem in metadataInfo.PropertyItems) { if (pItem.Id == PropertyTag.PixelPerUnitX) { pItem.Value[0] = (byte)dpi.X; pItem.Value[1] = pItem.Value[2] = pItem.Value[3] = 0; } else if (pItem.Id == PropertyTag.PixelPerUnitY) { pItem.Value[0] = (byte)dpi.Y; pItem.Value[1] = pItem.Value[2] = pItem.Value[3] = 0; } else if (pItem.Id == PropertyTag.PixelUnit) { //setting unit to dots per inch pItem.Value[0] = (byte)2; //1: dots per cm; 2: dots per inch } } }
/// <summary> /// Get the x and y DPI setting associate with this object /// </summary> /// <param name="metadataInfo"></param> /// <returns></returns> static internal Point GetDpi(IMetadataInfo metadataInfo) { Hashtable map = new Hashtable(); foreach (PropertyItem item in metadataInfo.PropertyItems) { map.Add(item.Id, item); } // ArrayList list = new ArrayList(metadataInfo.PropertyItems); if (map.Contains((int)PropertyTag.PixelUnit) == false) { // throw new NotSupportedException("This image does not have any embedded DPI information"); } if (map.Contains((int)PropertyTag.PixelPerUnitX) == false || map.Contains((int)PropertyTag.PixelPerUnitY) == false) { throw new InvalidOperationException("PixelPerUnitX and PixelPerUnitY must always be set when PixelUnit is set"); } byte[] buffer = ((PropertyItem)map[(int)PropertyTag.PixelPerUnitX]).Value; float xDpi = buffer[0] + (buffer[1] << 8) + (buffer[2] << 16) + (buffer[3] << 24); buffer = ((PropertyItem)map[(int)PropertyTag.PixelPerUnitY]).Value; float yDpi = buffer[0] + (buffer[1] << 8) + (buffer[2] << 16) + (buffer[3] << 24); if (((PropertyItem)map[(int)PropertyTag.PixelUnit]).Value[0] == (byte)0x1) // 1 : dots/meter -- 2 : dots/inch { xDpi *= 2.54f / 100; // 1 inch = 2.54 cm ( in dots/meter so need to divide by 100 to get dot/cm) yDpi *= 2.54f / 100; } xDpi = (float)Math.Round(xDpi); yDpi = (float)Math.Round(yDpi); return(new Point((int)xDpi, (int)yDpi)); }
public StoredMetadata( IReadOnlyList <StoredAnchor> anchors, IReadOnlyList <StoredUnmappedPointer> unmappedPointers, IReadOnlyList <StoredMatchedWord> matchedWords, IReadOnlyList <StoredOffsetPointer> offsetPointers, IReadOnlyList <StoredList> lists, IReadOnlyList <StoredUnmappedConstant> unmappedConstants, IMetadataInfo generalInfo, int freeSpaceSearch, int freeSpaceBuffer, int nextExportID ) { NamedAnchors = anchors ?? new List <StoredAnchor>(); UnmappedPointers = unmappedPointers ?? new List <StoredUnmappedPointer>(); MatchedWords = matchedWords ?? new List <StoredMatchedWord>(); OffsetPointers = offsetPointers ?? new List <StoredOffsetPointer>(); Lists = lists ?? new List <StoredList>(); UnmappedConstants = unmappedConstants ?? new List <StoredUnmappedConstant>(); Version = generalInfo?.VersionNumber; FreeSpaceSearch = freeSpaceSearch; FreeSpaceBuffer = freeSpaceBuffer; NextExportID = nextExportID; }
public static StoredMetadata DecodeConstantsFromReference(IReadOnlyList <byte> model, IMetadataInfo info, StoredMetadata metadata, GameReferenceConstants constants) { if (metadata == null) { return(metadata); } var words = metadata.MatchedWords.ToList(); var constantSet = new Dictionary <string, IList <StoredMatchedWord> >(); foreach (var constant in constants.SelectMany(c => c.ToStoredMatchedWords())) { if (!constantSet.ContainsKey(constant.Name)) { constantSet[constant.Name] = new List <StoredMatchedWord>(); } constantSet[constant.Name].Add(constant); } foreach (var constant in constantSet.Values) { if (constant.Any(c => c.Address + c.Length > model.Count)) { continue; } var virtualValues = constant.Select(c => (model.ReadMultiByteValue(c.Address, c.Length) - c.AddOffset) / c.MultOffset).ToList(); var match = virtualValues.All(vv => vv == virtualValues[0]); if (match) { words.AddRange(constant); } } return(new StoredMetadata(metadata.NamedAnchors, metadata.UnmappedPointers, words, metadata.OffsetPointers, metadata.Lists, metadata.UnmappedConstants, metadata.GotoShortcuts, info, new StoredMetadataFields { FreeSpaceSearch = metadata.FreeSpaceSearch, FreeSpaceBuffer = metadata.FreeSpaceBuffer, NextExportID = metadata.NextExportID, ShowRawIVByteForTrainer = metadata.ShowRawIVByteForTrainer })); }
public MetadataTypeCatalog(IMetadataInfo metadataInfo, ICompositionElement definitionOrigin) { this.metadataInfo = metadataInfo; this._definitionOrigin = definitionOrigin ?? this; this._contractPartIndex = new Lazy <IDictionary <string, List <ComposablePartDefinition> > >(this.CreateIndex, true); }
public AboutWindow(IMetadataInfo metadata) { InitializeComponent(); Version.Text = $"Version {metadata.VersionNumber}"; Usage.Text = GetUsageText(metadata); }
public StoredMetadata(IReadOnlyList <StoredAnchor> anchors, IReadOnlyList <StoredUnmappedPointer> unmappedPointers, IReadOnlyList <StoredMatchedWord> matchedWords, IReadOnlyList <StoredList> lists, IMetadataInfo generalInfo, int freeSpaceSearch) { NamedAnchors = anchors ?? new List <StoredAnchor>(); UnmappedPointers = unmappedPointers ?? new List <StoredUnmappedPointer>(); MatchedWords = matchedWords ?? new List <StoredMatchedWord>(); Lists = lists ?? new List <StoredList>(); Version = generalInfo.VersionNumber; FreeSpaceSearch = freeSpaceSearch; }
/// <summary> /// Marked as private to block the default constructor /// </summary> internal protected ImageAdapter() { _metadataInfo = new MetadataInfo(); }
public MetadataTypeCatalog(IMetadataInfo metadataInfo, ICompositionElement definitionOrigin) { this.metadataInfo = metadataInfo; this._definitionOrigin = definitionOrigin ?? this; this._contractPartIndex = new Lazy<IDictionary<string, List<ComposablePartDefinition>>>(this.CreateIndex, true); }