public static bool DoDraw(SpriteBatch __instance, Texture2D texture, Rectangle destinationRectangle, Rectangle sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) { if (texture is Texture2DWrapper wrapper) { sourceRectangle = Texture2DWrapper.MultiplyRect(sourceRectangle, wrapper.Scale); __instance.Draw(wrapper.Wrapped, destinationRectangle, sourceRectangle, color, rotation, origin * wrapper.Scale, effects, layerDepth); return(false); } return(true); }
public void Edit <T>(IAssetData asset) { IAssetDataForImage image = asset.AsImage(); string name = Normalize(asset.AssetName) + ".4x"; if (!ScaledAssets.ContainsKey(name)) { ScaledAssets[name] = new Texture2DWrapper(image.Data, 4, name); } Texture2DWrapper wrapper = ScaledAssets[name]; if (wrapper.Locale != asset.Locale) { Monitor.Log($"Upscaling {asset.AssetName} (Locale: {asset.Locale})"); wrapper.Wrapped = Texture2DWrapper.ScaleUp(image.Data, wrapper.Scale); wrapper.Locale = asset.Locale; } image.ReplaceWith(wrapper); Helper.Content.Load <Texture2D>(wrapper.Path, ContentSource.GameContent); }
public static bool PatchImage(IAssetDataForImage __instance, Texture2D source, Rectangle?sourceArea, Rectangle?targetArea, PatchMode patchMode) { if (__instance.Data is Texture2DWrapper wrapper) { if (sourceArea.HasValue) { source = Texture2DWrapper.Crop(source, sourceArea.Value); } source = Texture2DWrapper.ScaleUp(source, wrapper.Scale); if (targetArea.HasValue) { targetArea = Texture2DWrapper.MultiplyRect(targetArea.Value, wrapper.Scale); } PropertyInfo Data = __instance.GetType().GetProperty("Data"); Data.SetValue(__instance, wrapper.Wrapped); __instance.PatchImage(source, null, targetArea, patchMode); Data.SetValue(__instance, wrapper); return(false); } return(true); }
public T Load <T>(IAssetInfo asset) { Texture2DWrapper wrapper = ScaledAssets[Normalize(asset.AssetName)]; return((T)(object)wrapper.Wrapped); }