Rename PCKFile.FileData.name -> PCKFile.FileData.filepath

This commit is contained in:
miku-666
2022-07-31 02:10:51 +02:00
parent 415c1d5e8a
commit 6ba76b6a3f
17 changed files with 679 additions and 652 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace PckStudio.Classes.FileTypes
{
@@ -18,20 +19,54 @@ namespace PckStudio.Classes.FileTypes
DLCCapeFile = 1, // *.png
DLCTextureFile = 2, // *.png
DLCUIDataFile = 3, // *.fui ????
// DLCInfoFile = 4, // "0" file
// DLCTexturePackInfoFile = 5, // (x16|x32|...)Info.pck
DLCLocalisationFile = 6, // languages.loc/localisation.loc
DLCGameRulesFile = 7, // GameRiles.grf
DLCAudioFile = 8, // audio.pck
DLCColourTableFile = 9, // colours.col
DLCGameRulesHeader = 10, // GameRiles.grh
DLCSkinDataFile = 11, // *.pck made up name -Miku
DLCModelsFile = 12, // models.bin
DLCBehavioursFile = 13, // behaviours.bin
DLCMaterialFile = 14, // entityMaterials.bin
/// <summary>
/// "0" file
/// </summary>
DLCInfoFile = 4,
/// <summary>
/// (x16|x32|...)Info.pck
/// </summary>
DLCTexturePackInfoFile = 5,
/// <summary>
/// languages.loc/localisation.loc
/// </summary>
DLCLocalisationFile = 6,
/// <summary>
/// GameRules.grf
/// </summary>
DLCGameRulesFile = 7,
/// <summary>
/// audio.pck
/// </summary>
DLCAudioFile = 8,
/// <summary>
/// colours.col
/// </summary>
DLCColourTableFile = 9,
/// <summary>
/// GameRules.grh
/// </summary>
DLCGameRulesHeader = 10,
/// <summary>
/// Skins.pck
/// made up name - Miku
/// </summary>
DLCSkinDataFile = 11,
/// <summary>
/// models.bin
/// </summary>
DLCModelsFile = 12,
/// <summary>
/// behaviours.bin
/// </summary>
DLCBehavioursFile = 13,
/// <summary>
/// entityMaterials.bin
/// </summary>
DLCMaterialFile = 14,
}
public string name { get; set; }
public string filepath { get; set; }
public int type { get; set; }
public byte[] data => _data;
public int size => _size;
@@ -40,21 +75,19 @@ namespace PckStudio.Classes.FileTypes
private byte[] _data = new byte[0];
private int _size = 0;
public FileData(string name, int type)
public FileData(string path, int type)
{
this.type = type;
this.name = name;
filepath = path;
}
public FileData(string name, int type, int dataSize)
public FileData(string path, int type, int dataSize) : this(path, type)
{
this.type = type;
this.name = name;
_size = dataSize;
_data = new byte[dataSize];
}
public FileData(FileData file) : this(file.name, file.type)
public FileData(FileData file) : this(file.filepath, file.type)
{
properties = file.properties;
SetData(file.data);
@@ -73,7 +106,7 @@ namespace PckStudio.Classes.FileTypes
this.type = type;
}
public List<string> GatherMetaTags()
public List<string> GatherPropertiesList()
{
var LUT = new List<string>();
Files.ForEach(file => file.properties.ForEach(pair =>
@@ -85,16 +118,28 @@ namespace PckStudio.Classes.FileTypes
return LUT;
}
public bool HasFile(string name, int type)
/// <summary>
/// Checks wether a file with <paramref name="filepath"/> and <paramref name="type"/> exists
/// </summary>
/// <param name="filepath">Path to the file in the pck</param>
/// <param name="type">Type of the file to check</param>
/// <returns> when file exists, otherwise false </returns>
public bool HasFile(string filepath, int type)
{
return GetFile(name, type) != null;
return GetFile(filepath, type) != null;
}
public FileData GetFile(string name, int type)
/// <summary>
/// Gets the first file that Equals <paramref name="filepath"/> and <paramref name="type"/>
/// </summary>
/// <param name="filepath">file path of the file</param>
/// <param name="type">Type of the file</param>
/// <returns>FileData if found, otherwise null</returns>
public FileData GetFile(string filepath, int type)
{
foreach (var file in Files)
{
if (file.name == name && file.type == type)
if (file.filepath.Equals(filepath) && file.type.Equals(type))
return file;
}
return null;

View File

@@ -79,7 +79,7 @@ namespace PckStudio.Classes.IO
private string ReadString(Stream stream)
{
int len = ReadInt(stream);
string s = ReadString(stream, len, IsUsingLittleEndian ? Encoding.Unicode : Encoding.BigEndianUnicode);
string s = ReadString(stream, len, IsUsingLittleEndian ? Encoding.Unicode : Encoding.BigEndianUnicode);
ReadInt(stream); // padding
return s;
}

View File

@@ -22,7 +22,7 @@ namespace PckStudio.Classes.IO
private PCKFileWriter(PCKFile file, bool isLittleEndian) : base(isLittleEndian)
{
_pckfile = file;
LUT = _pckfile.GatherMetaTags();
LUT = _pckfile.GatherPropertiesList();
}
private void WriteToStream(Stream stream)
@@ -59,7 +59,7 @@ namespace PckStudio.Classes.IO
{
WriteInt(stream, file.size);
WriteInt(stream, file.type);
WriteString(stream, file.name);
WriteString(stream, file.filepath);
}
}

View File

@@ -122,19 +122,19 @@
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="addDisplayIDToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 22</value>
<value>162, 22</value>
</data>
<data name="addDisplayIDToolStripMenuItem.Text" xml:space="preserve">
<value>Add Display ID</value>
</data>
<data name="deleteDisplayIDToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 22</value>
<value>162, 22</value>
</data>
<data name="deleteDisplayIDToolStripMenuItem.Text" xml:space="preserve">
<value>Delete Display ID</value>
</data>
<data name="contextMenuStrip1.Size" type="System.Drawing.Size, System.Drawing">
<value>181, 70</value>
<value>163, 48</value>
</data>
<data name="&gt;&gt;contextMenuStrip1.Name" xml:space="preserve">
<value>contextMenuStrip1</value>

View File

@@ -61,7 +61,7 @@ namespace PckStudio
foreach (PCKFile.FileData mf in currentPCK.Files)
{
MemoryStream png = new MemoryStream(mf.data);
if (Path.GetExtension(mf.name) == ".png")
if (Path.GetExtension(mf.filepath) == ".png")
{
if (Image.FromStream(png).Size.Height == Image.FromStream(png).Size.Width)
{
@@ -84,7 +84,7 @@ namespace PckStudio
foreach (PCKFile.FileData mf in currentPCK.Files)
{
MemoryStream png = new MemoryStream(mf.data);
if (Path.GetExtension(mf.name) == ".png")
if (Path.GetExtension(mf.filepath) == ".png")
{
if (Image.FromStream(png).Size.Height == Image.FromStream(png).Size.Width / 2)
{
@@ -106,7 +106,7 @@ namespace PckStudio
{
foreach (PCKFile.FileData mf in currentPCK.Files)
{
if (Path.GetExtension(mf.name) == ".png")
if (Path.GetExtension(mf.filepath) == ".png")
{
mf.properties.Add(new ValueTuple<string, string>(treeMeta.Nodes[i].Text, treeMeta.Nodes[i].Tag.ToString() ));
}

View File

@@ -107,9 +107,6 @@ namespace PckStudio
{
comboBoxSkinType.Items.RemoveAt(0);
}
skinPictureBoxTexture.SizeMode = PictureBoxSizeMode.StretchImage;
skinPictureBoxTexture.InterpolationMode = InterpolationMode.NearestNeighbor;
skinPictureBoxTexture.Image = img;
buttonDone.Enabled = true;
@@ -200,8 +197,8 @@ namespace PckStudio
{
try
{
cape.name = $"dlccape{skinId}.png";
skin.properties.Add(new ValueTuple<string, string>("CAPEPATH", cape.name));
cape.filepath = $"dlccape{skinId}.png";
skin.properties.Add(new ValueTuple<string, string>("CAPEPATH", cape.filepath));
}
catch (Exception)
{
@@ -247,7 +244,7 @@ namespace PckStudio
skin.properties.Add(new ValueTuple<string, string>("GAME_FLAGS", "0x18"));
skin.properties.Add(new ValueTuple<string, string>("FREE", "1"));
skin.name = "dlcskin" + skinId + ".png";
skin.filepath = "dlcskin" + skinId + ".png";
DialogResult = DialogResult.OK;
Close();
}

View File

@@ -60,8 +60,6 @@
// treeView1
//
this.treeView1.AllowDrop = true;
this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.treeView1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.treeView1.ContextMenuStrip = this.contextMenuStrip1;
this.treeView1.ForeColor = System.Drawing.Color.White;
@@ -198,7 +196,7 @@
this.AnimationPlayBtn.Text = "Play Animation";
this.AnimationPlayBtn.Theme = MetroFramework.MetroThemeStyle.Dark;
this.AnimationPlayBtn.UseSelectable = true;
this.AnimationPlayBtn.Click += new System.EventHandler(this.metroButton1_Click);
this.AnimationPlayBtn.Click += new System.EventHandler(this.StartAnimationBtn_Click);
//
// timer1
//
@@ -216,7 +214,7 @@
this.AnimationStopBtn.Text = "Stop Animation";
this.AnimationStopBtn.Theme = MetroFramework.MetroThemeStyle.Dark;
this.AnimationStopBtn.UseSelectable = true;
this.AnimationStopBtn.Click += new System.EventHandler(this.metroButton2_Click);
this.AnimationStopBtn.Click += new System.EventHandler(this.StopAnimationBtn_Click);
//
// tileLabel
//
@@ -310,6 +308,7 @@
this.Controls.Add(this.treeView1);
this.Controls.Add(this.menuStrip);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MinimumSize = new System.Drawing.Size(412, 362);
this.Name = "AnimationEditor";
this.Style = MetroFramework.MetroColorStyle.Silver;
this.Text = "Animation Editor";

View File

@@ -2,153 +2,115 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PckStudio.Classes.FileTypes;
using PckStudio.Forms.Utilities.AnimationEditor;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PckStudio
{
public partial class AnimationEditor : MetroForm
{
PCKFile.FileData mf = null;
PCKFile.FileData animationFile = null;
List<Image> frames = new List<Image>();
int frameCount;
Newtonsoft.Json.Linq.JObject tileData = Newtonsoft.Json.Linq.JObject.Parse(System.Text.Encoding.Default.GetString(Properties.Resources.tileData));
Image texture;
int frameCount => frames.Count;
static JObject tileData = JObject.Parse(Properties.Resources.tileData);
Image texture = null;
bool isItem = false;
string lastFrameTime = "1";
string newTileName = "";
bool create = false;
int minimumFrameTime = 1;
string TileName = "";
int animCurrentFrame = 0;
Tuple<int, int> currentFrameData = new Tuple<int, int>(0, 1);
Image img = null;
Image imgB = null;
int nextFrame;
//int frameCounter = 0; // ported directly from Java Edition code -MattNL
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
Tuple<string, string> frameData = e.Node.Tag as Tuple<string, string>;
Console.WriteLine(frameData.Item1 + " --- " + frameData.Item2);
if (AnimationPlayBtn.Enabled)
{
pictureBoxWithInterpolationMode1.Image = frames[short.Parse(frameData.Item1)];
}
public AnimationEditor(Image imgage, string tileName, bool isItem)
{
InitializeComponent();
this.isItem = isItem;
TileName = tileName;
string filePath = $"res/textures/{(isItem ? "items" : "blocks")}/{tileName}.png";
animationFile = CreateNewAnimationFile(imgage, filePath);
CreateFrameList(imgage);
}
public AnimationEditor(PCKFile.FileData file_entry, string createdFileName = "")
public AnimationEditor(PCKFile.FileData file)
{
InitializeComponent();
if (string.IsNullOrEmpty(createdFileName))
isItem = file.filepath.Split('/').Contains("items");
TileName = Path.GetFileNameWithoutExtension(file.filepath);
animationFile = file;
if (TileName.EndsWith("MipMapLevel2") || TileName.EndsWith("MipMapLevel3"))
{
mf = file_entry;
newTileName = Path.GetFileNameWithoutExtension(file_entry.name);
if (file_entry.name.Split('/').Contains("items")) isItem = true;
if (newTileName.EndsWith("MipMapLevel2") || newTileName.EndsWith("MipMapLevel3"))
{
string mipMapLvl = newTileName.Last().ToString();
newTileName = newTileName.Substring(0, newTileName.Length - 12);
MipMapCheckbox.Checked = true;
MipMapNumericUpDown.Value = short.Parse(mipMapLvl);
}
string mipMapLvl = TileName.Last().ToString();
TileName = TileName.Substring(0, TileName.Length - 12);
MipMapCheckbox.Checked = true;
MipMapNumericUpDown.Value = short.Parse(mipMapLvl);
}
else
{
create = true;
PCKFile.FileData newMf = new PCKFile.FileData("", 2);
newMf.properties.Add(new ValueTuple<string, string>("ANIM", ""));
newMf.SetData(File.ReadAllBytes(createdFileName));
mf = newMf;
Forms.Utilities.AnimationEditor.ChangeTile diag = new Forms.Utilities.AnimationEditor.ChangeTile();
diag.ShowDialog(this);
Console.WriteLine(diag.SelectedTile);
newTileName = diag.SelectedTile;
if (newTileName == "") Close();
isItem = diag.IsItem;
diag.Dispose();
}
List<string> strEntries = new List<string>();
string anim = string.Empty;
foreach (var entry in mf.properties)
{
if (entry.Item1 == "ANIM") anim = entry.Item2;
strEntries.Add(entry.Item2);
}
animationFile.properties.FirstOrDefault(x => x.Item1.Equals("ANIM"));
MemoryStream textureMem = new MemoryStream(mf.data);
texture = Image.FromStream(textureMem);
createFrameList();
MemoryStream textureMem = new MemoryStream(animationFile.data);
texture = new Bitmap(textureMem);
CreateFrameList(texture);
Console.WriteLine(newTileName);
Console.WriteLine(TileName);
foreach (Newtonsoft.Json.Linq.JObject content in tileData[isItem ? "Items" : "Blocks"].Children())
foreach (JObject content in tileData[isItem ? "Items" : "Blocks"].Children())
{
foreach (JProperty prop in content.Properties())
{
if (prop.Name == newTileName) tileLabel.Text = (string)prop.Value;
if (prop.Name == TileName) tileLabel.Text = (string)prop.Value;
}
}
Console.WriteLine("ANIMATION DATA: " + anim);
if (InterpolationCheckbox.Checked = anim.StartsWith("#"))
{
anim = anim.Remove(0, 1);
}
frameCount = texture.Height / texture.Width;
if (!string.IsNullOrEmpty(anim))
{
string[] animData = anim.Split(',');
if (string.IsNullOrEmpty(animData.Last())) animData = animData.Take(animData.Length - 1).ToArray();
int lastFrameTime = 0;
foreach (string frame in animData)
{
string[] frameData = frame.Split('*');
string outFrame = "";
int i = 0;
string currentFrame = "";
string currentFrameTime = "";
foreach (string data in frameData)
{
string label;
string outData;
outData = data;
if (i == 0)
{
if (string.IsNullOrEmpty(data)) throw new Exception("Invalid animation data");
label = "Frame: ";
currentFrame = outData;
}
else
{
// Some textures like the Halloween 2015's Lava texture don't have a
// frame time parameter for certain frames. This will detect that and place the last frame time in its place.
// This is accurate to console edition behavior.
// - MattNL
if (string.IsNullOrEmpty(data)) outData = lastFrameTime;
label = ", Frame Time: ";
currentFrameTime = outData;
}
outFrame += label + outData;
i++;
}
Console.WriteLine(outFrame);
if (frameData.Length < 2)
continue; // shouldn't happen
int currentFrame = 0;
int currentFrameTime = 1;
TreeNode frameNode = new TreeNode();
Tuple<string, string> finalFrameData = new Tuple<string, string>(currentFrame, currentFrameTime);
lastFrameTime = currentFrameTime;
frameNode.Text = outFrame;
if (string.IsNullOrEmpty(frameData[0])) throw new Exception("Invalid animation data");
currentFrame = int.Parse(frameData[0]);
// Some textures like the Halloween 2015's Lava texture don't have a
// frame time parameter for certain frames.
// This will detect that and place the last frame time in its place.
// This is accurate to console edition behavior.
// - MattNL
currentFrameTime = string.IsNullOrEmpty(frameData[1]) ? lastFrameTime : int.Parse(frameData[1]);
string label = $"Frame: {currentFrame}, Frame Time: {currentFrameTime}";
Console.WriteLine(label);
TreeNode frameNode = new TreeNode(label);
var finalFrameData = new Tuple<int, int>(currentFrame, currentFrameTime);
frameNode.Tag = finalFrameData;
treeView1.Nodes.Add(frameNode);
lastFrameTime = currentFrameTime;
}
}
else
{
for (int i = 0; i < frameCount; i++)
{
TreeNode frameNode = new TreeNode();
Tuple<string, string> finalFrameData = new Tuple<string, string>(i.ToString(), "1");
frameNode.Text = "Frame: " + i.ToString() + ", Frame Time: 1";
TreeNode frameNode = new TreeNode($"Frame: {i}, Frame Time: {minimumFrameTime}");
var finalFrameData = new Tuple<int, int>(i, minimumFrameTime);
frameNode.Tag = finalFrameData;
treeView1.Nodes.Add(frameNode);
}
@@ -157,151 +119,166 @@ namespace PckStudio
pictureBoxWithInterpolationMode1.Image = frames[0]; //Sets image preview to the first frame of animation (0 for now)
Console.WriteLine("Animation Frame Count: " + frameCount);
}
private PCKFile.FileData CreateNewAnimationFile(Image imgageFile, string name = "")
{
PCKFile.FileData file = new PCKFile.FileData(name, 2);
file.properties.Add(("ANIM", ""));
using (var stream = new MemoryStream())
{
imgageFile.Save(stream, ImageFormat.Png);
file.SetData(stream.ToArray());
}
return file;
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
var frameData = e.Node.Tag as Tuple<int, int>;
Console.WriteLine(frameData.Item1 + " --- " + frameData.Item2);
if (AnimationPlayBtn.Enabled)
{
pictureBoxWithInterpolationMode1.Image = frames[frameData.Item1];
}
}
void createFrameList()
void CreateFrameList(Image texture)
{
frames.Clear();
int width = texture.Width;
int height = texture.Height;
int totalFrames = height / width;
for (int frameI = 0; frameI < totalFrames; frameI++)
frames.AddRange(SplitImageToFrames(texture));
}
private IEnumerable<Image> SplitImageToFrames(Image source)
{
for (int i = 0; i < source.Height / source.Width; i++)
{
Rectangle frameArea = new Rectangle(new Point(0, frameI * width), new Size(width, width));
Bitmap frameImage = new Bitmap(width, width);
using (Graphics gfx = Graphics.FromImage(frameImage))
Rectangle tileArea = new Rectangle(new Point(0, i * source.Width), new Size(source.Width, source.Width));
Bitmap tileImage = new Bitmap(source.Width, source.Width);
using (Graphics gfx = Graphics.FromImage(tileImage))
{
gfx.SmoothingMode = SmoothingMode.None;
gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
gfx.DrawImage(texture, new Rectangle(0, 0, frameImage.Width, frameImage.Height), frameArea, GraphicsUnit.Pixel);
gfx.DrawImage(source, new Rectangle(0, 0, source.Width, source.Width), tileArea, GraphicsUnit.Pixel);
}
frames.Add(new Bitmap(frameImage, new Size(width, width)));
yield return tileImage;
}
yield break;
}
private int mix(double ratio, int val1, int val2) // Ported from Java Edition code
{
return (int)(ratio * (double)val1 + (1.0D - ratio) * (double)val2);
return (int)(ratio * val1 + (1.0D - ratio) * val2);
}
int animCurrentFrame = 0;
Tuple<string, string> currentFrameData = new Tuple<string, string>("", "");
Image img = null;
int nextFrame;
//int frameCounter = 0; // ported directly from Java Edition code -MattNL
Image imgB = null;
void animate(object sender, EventArgs e)
{
//Console.WriteLine(frameCounter + " $$$ " + frameCount);
//frameCounter = (frameCounter + 1) % frameCount;
if (animCurrentFrame > (treeView1.Nodes.Count - 1)) animCurrentFrame = 0;
currentFrameData = treeView1.Nodes[animCurrentFrame].Tag as Tuple<string, string>;
pictureBoxWithInterpolationMode1.Image = frames[Int16.Parse(currentFrameData.Item1)];
currentFrameData = treeView1.Nodes[animCurrentFrame].Tag as Tuple<int, int>;
pictureBoxWithInterpolationMode1.Image = frames[currentFrameData.Item1];
//animCurrentTotalFrameTime = Int16.Parse(currentFrameData.Item2);
timer1.Interval = Int16.Parse(currentFrameData.Item2) * 50;
timer1.Interval = currentFrameData.Item2 * 50;
animCurrentFrame++;
if (InterpolationCheckbox.Checked)
{
img = frames[short.Parse(currentFrameData.Item1)];
img = frames[currentFrameData.Item1];
nextFrame = animCurrentFrame + 1;
if (nextFrame > frameCount - 1) nextFrame = 0;
Console.WriteLine(nextFrame);
imgB = frames[nextFrame];
}
#region interpolation code (unoptimized and unused at the moment)
// Interpolation Code (Very slow, messy, and resource heavy depending on the resolution!!!)
#region interpolation code (unoptimized and unused at the moment)
// Interpolation Code (Very slow, messy, and resource heavy depending on the resolution!!!)
/*else if(metroCheckBox1.Checked && (img != null && imgB != null))
{
double d0 = 1.0D - animCurrentFrame / animCurrentTotalFrameTime;
int i = animCurrentFrame;
int j = frameCount;
int k = (frameCounter + 1) % j;
else if (InterpolationCheckbox.Checked && (img != null && imgB != null))
{
double d0 = 1.0D - animCurrentFrame / frameCount;
int i = animCurrentFrame;
int j = frameCount;
int k = (frameCount + 1) % j;
for (int l = 0; l < (frames.Count() - 1); ++l)
{
int i1 = img.Width;
int j1 = img.Width;
for (int l = 0; l < (frameCount - 1); ++l)
{
int i1 = img.Width;
int j1 = img.Width;
Bitmap finalInterpolation = new Bitmap(pictureBoxWithInterpolationMode1.Image);
// pictureBoxWithInterpolationMode1.Image.Dispose();
// pictureBoxWithInterpolationMode1.Image = null;
Bitmap finalInterpolation = new Bitmap(pictureBoxWithInterpolationMode1.Image);
// pictureBoxWithInterpolationMode1.Image.Dispose();
// pictureBoxWithInterpolationMode1.Image = null;
for (int k1 = 0; k1 < j1; ++k1)
{
for (int l1 = 0; l1 < i1; ++l1)
{
//Get Both Colours at the pixel point
Bitmap imgC = new Bitmap(img);
Bitmap imgBC = new Bitmap(imgB);
Color col1 = imgC.GetPixel(l1, k1);
Color col2 = imgBC.GetPixel(l1, k1);
imgC.Dispose();
imgC = null;
imgBC.Dispose();
imgBC = null;
for (int k1 = 0; k1 < j1; ++k1)
{
for (int l1 = 0; l1 < i1; ++l1)
{
//Get Both Colours at the pixel point
Bitmap imgC = new Bitmap(img);
Bitmap imgBC = new Bitmap(imgB);
Color col1 = imgC.GetPixel(l1, k1);
Color col2 = imgBC.GetPixel(l1, k1);
imgC.Dispose();
imgC = null;
imgBC.Dispose();
imgBC = null;
int i2 = 0;
i2 |= col1.A << 24;
i2 |= col1.R << 16;
i2 |= col1.G << 8;
i2 |= col1.B;
int i2 = 0;
i2 |= col1.A << 24;
i2 |= col1.R << 16;
i2 |= col1.G << 8;
i2 |= col1.B;
int j2 = 0;
j2 |= col2.A << 24;
j2 |= col2.R << 16;
j2 |= col2.G << 8;
j2 |= col2.B;
int j2 = 0;
j2 |= col2.A << 24;
j2 |= col2.R << 16;
j2 |= col2.G << 8;
j2 |= col2.B;
int k2 = this.mix(d0, i2 >> 16 & 255, j2 >> 16 & 255);
int l2 = this.mix(d0, i2 >> 8 & 255, j2 >> 8 & 255);
int i3 = this.mix(d0, i2 & 255, j2 & 255);
int k2 = this.mix(d0, i2 >> 16 & 255, j2 >> 16 & 255);
int l2 = this.mix(d0, i2 >> 8 & 255, j2 >> 8 & 255);
int i3 = this.mix(d0, i2 & 255, j2 & 255);
// Create new grayscale RGB colour
uint finalColor = (uint)(i2 & -16777216 | k2 << 16 | l2 << 8 | i3);
// Create new grayscale RGB colour
uint finalColor = (uint)(i2 & -16777216 | k2 << 16 | l2 << 8 | i3);
byte[] values = BitConverter.GetBytes(finalColor);
byte[] values = BitConverter.GetBytes(finalColor);
int a = values[3];
int b = values[0];
int g = values[1];
int r = values[2];
int a = values[3];
int b = values[0];
int g = values[1];
int r = values[2];
Color newcol = Color.FromArgb(a, r, g, b);
Color newcol = Color.FromArgb(a, r, g, b);
finalInterpolation.SetPixel(l1, k1, newcol);
}
}
finalInterpolation.SetPixel(l1, k1, newcol);
}
}
pictureBoxWithInterpolationMode1.Image = finalInterpolation;
//finalInterpolation.Dispose();
finalInterpolation = null;
}
}
*/
#endregion
pictureBoxWithInterpolationMode1.Image = finalInterpolation;
//finalInterpolation.Dispose();
}
}
//Console.WriteLine(animCurrentFrame + " - " + animCurrentFrameTime + " - " + animCurrentTotalFrameTime + " - " + (treeView1.Nodes.Count - 1));
}
#endregion
private void metroButton1_Click(object sender, EventArgs e)
//Console.WriteLine(animCurrentFrame + " - " + animCurrentFrameTime + " - " + animCurrentTotalFrameTime + " - " + (treeView1.Nodes.Count - 1));
}
private void StartAnimationBtn_Click(object sender, EventArgs e)
{
animCurrentFrame = 0;
//animCurrentFrameTime = 0;
//animCurrentTotalFrameTime = -1;
//frameCounter = 0;
AnimationPlayBtn.Enabled = false;
AnimationStopBtn.Enabled = true;
AnimationPlayBtn.Enabled = !(AnimationStopBtn.Enabled = !AnimationStopBtn.Enabled);
timer1.Start();
}
private void metroButton2_Click(object sender, EventArgs e)
private void StopAnimationBtn_Click(object sender, EventArgs e)
{
AnimationPlayBtn.Enabled = true;
AnimationStopBtn.Enabled = false;
AnimationPlayBtn.Enabled = !(AnimationStopBtn.Enabled = !AnimationStopBtn.Enabled);
timer1.Stop();
}
@@ -320,16 +297,6 @@ namespace PckStudio
return null;
}
private TreeNode FindNodeByName(TreeView treeView, string name)
{
foreach (TreeNode node in treeView.Nodes)
{
if (node.Text.ToLower() == name.ToLower()) return node;
return FindNodeByName(node, name);
}
return null;
}
private void addNodeToAnimationsFolder(TreeNode newNode)
{
//TreeNode parent = FindNodeByName(treeViewMain, isItem ? "items" : "blocks");
@@ -380,35 +347,29 @@ namespace PckStudio
{
using (var stream = new MemoryStream())
{
texture.Save(stream, texture.RawFormat);
mf.SetData(stream.ToArray());
texture.Save(stream, ImageFormat.Png);
animationFile.SetData(stream.ToArray());
}
if (MipMapCheckbox.Checked)
{
newTileName += "MipMapLevel" + MipMapNumericUpDown.Value.ToString();
}
animationFile.filepath = $"res/textures/{(isItem ? "items" : "blocks")}/{TileName}{(MipMapCheckbox.Checked ? $"MipMapLevel{MipMapNumericUpDown.Value}" : string.Empty)}.png";
//if (!create && treeViewMain.SelectedNode.Tag != null) treeViewMain.SelectedNode.Text = newTileName + ".png";
string animationData = "";
if (InterpolationCheckbox.Checked) animationData += "#"; // does the animation interpolate?
string animationData = InterpolationCheckbox.Checked ? "#" : "";
foreach (TreeNode node in treeView1.Nodes)
{
Tuple<string, string> frameData = node.Tag as Tuple<string, string>;
animationData += frameData.Item1 + "*" + frameData.Item2 + ",";
var frameData = node.Tag as Tuple<int, int>;
animationData += $"{frameData.Item1}*{frameData.Item2},";
}
animationData.TrimEnd(',');
foreach (var pair in mf.properties)
foreach (var pair in animationFile.properties)
{
if (pair.Item1 == "ANIM")
{
//pair.Item2 = animationData; // TODO
break;
animationFile.properties[animationFile.properties.IndexOf(pair)] = ("ANIM", animationData);
break;
}
else
{
mf.properties.Add(new ValueTuple<string, string>("ANIM", animationData));
animationFile.properties.Add(("ANIM", animationData));
break;
}
};
@@ -442,7 +403,7 @@ namespace PckStudio
// addNodeToAnimationsFolder(newNode);
//}
if(MipMapCheckbox.Checked) newTileName = newTileName.Substring(0, newTileName.Length - 12);
if(MipMapCheckbox.Checked) TileName = TileName.Substring(0, TileName.Length - 12);
}
// Most of the code below is modified code from this link: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.treeview.itemdrag?view=windowsdesktop-6.0
@@ -543,7 +504,7 @@ namespace PckStudio
private void treeView1_doubleClick(object sender, EventArgs e)
{
Forms.Utilities.AnimationEditor.FrameEditor diag = new Forms.Utilities.AnimationEditor.FrameEditor(
FrameEditor diag = new FrameEditor(
treeView1, // animation editor tree
treeView1.SelectedNode.Tag as Tuple<string, string>, // the current selected frame data
frameCount - 1, // frame limit
@@ -556,7 +517,7 @@ namespace PckStudio
private void addFrameToolStripMenuItem_Click(object sender, EventArgs e)
{
Forms.Utilities.AnimationEditor.FrameEditor diag = new Forms.Utilities.AnimationEditor.FrameEditor(
FrameEditor diag = new FrameEditor(
treeView1,
new Tuple<string, string>("", ""),
frameCount - 1,
@@ -573,7 +534,7 @@ namespace PckStudio
private void bulkAnimationSpeedToolStripMenuItem_Click(object sender, EventArgs e)
{
Forms.Utilities.AnimationEditor.SetBulkSpeed diag = new Forms.Utilities.AnimationEditor.SetBulkSpeed(treeView1);
SetBulkSpeed diag = new SetBulkSpeed(treeView1);
diag.ShowDialog(this);
diag.Dispose();
}
@@ -604,12 +565,11 @@ namespace PckStudio
MemoryStream textureMem = new MemoryStream(File.ReadAllBytes(Path.GetDirectoryName(diag.FileName) + "\\/" + Path.GetFileNameWithoutExtension(diag.FileName)));
texture = Image.FromStream(textureMem);
frameCount = texture.Height / texture.Width;
createFrameList();
CreateFrameList(texture);
try
{
Newtonsoft.Json.Linq.JObject mcmeta = Newtonsoft.Json.Linq.JObject.Parse(File.ReadAllText(diag.FileName));
JObject mcmeta = JObject.Parse(File.ReadAllText(diag.FileName));
if (mcmeta["animation"] != null)
{
@@ -632,7 +592,7 @@ namespace PckStudio
Console.WriteLine((int)frame["index"] + "*" + (int)frame["time"]);
TreeNode frameNode = new TreeNode();
Tuple<string, string> finalFrameData = new Tuple<string, string>(((int)frame["index"]).ToString(), ((int)frame["time"]).ToString());
var finalFrameData = new Tuple<int, int>(((int)frame["index"]), ((int)frame["time"]));
frameNode.Text = "Frame: " + ((int)frame["index"]).ToString() + ", Frame Time: " + ((int)frame["time"]).ToString();
frameNode.Tag = finalFrameData;
treeView1.Nodes.Add(frameNode);
@@ -643,7 +603,7 @@ namespace PckStudio
Console.WriteLine((int)frame + "*" + frameTime);
TreeNode frameNode = new TreeNode();
Tuple<string, string> finalFrameData = new Tuple<string, string>(((int)frame).ToString(), frameTime.ToString());
var finalFrameData = new Tuple<int, int>(((int)frame), frameTime);
frameNode.Text = "Frame: " + ((int)frame).ToString() + ", Frame Time: " + frameTime.ToString();
frameNode.Tag = finalFrameData;
treeView1.Nodes.Add(frameNode);
@@ -655,7 +615,7 @@ namespace PckStudio
for (int i = 0; i < frameCount; i++)
{
TreeNode frameNode = new TreeNode();
Tuple<string, string> finalFrameData = new Tuple<string, string>(i.ToString(), frameTime.ToString());
var finalFrameData = new Tuple<int, int>(i, frameTime);
frameNode.Text = "Frame: " + i.ToString() + ", Frame Time: " + frameTime.ToString();
frameNode.Tag = finalFrameData;
treeView1.Nodes.Add(frameNode);
@@ -667,7 +627,6 @@ namespace PckStudio
{
MessageBox.Show(j_ex.Message, "Invalid animation");
texture = oldImage;
frameCount = oldFrameCount;
frames = oldFrames;
foreach (TreeNode node in oldAnimData)
{
@@ -675,7 +634,7 @@ namespace PckStudio
}
return;
}
pictureBoxWithInterpolationMode1.Image = frames[Int16.Parse((treeView1.Nodes[0].Tag as Tuple<string, string>).Item1)];
pictureBoxWithInterpolationMode1.Image = frames[(treeView1.Nodes[0].Tag as Tuple<int, int>).Item1];
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
@@ -689,25 +648,25 @@ namespace PckStudio
private void changeTileToolStripMenuItem_Click(object sender, EventArgs e)
{
PckStudio.Forms.Utilities.AnimationEditor.ChangeTile diag = new Forms.Utilities.AnimationEditor.ChangeTile(newTileName);
diag.ShowDialog(this);
Console.WriteLine(diag.SelectedTile);
if (newTileName != diag.SelectedTile) isItem = diag.IsItem;
newTileName = diag.SelectedTile;
diag.Dispose();
foreach (Newtonsoft.Json.Linq.JObject content in tileData[isItem ? "Items" : "Blocks"].Children())
{
foreach (Newtonsoft.Json.Linq.JProperty prop in content.Properties())
using (ChangeTile diag = new ChangeTile(TileName))
if (diag.ShowDialog(this) == DialogResult.OK)
{
if (prop.Name == newTileName) tileLabel.Text = (string)prop.Value;
Console.WriteLine(diag.SelectedTile);
if (TileName != diag.SelectedTile) isItem = diag.IsItem;
TileName = diag.SelectedTile;
foreach (JObject content in tileData[isItem ? "Items" : "Blocks"].Children())
{
foreach (JProperty prop in content.Properties())
{
if (prop.Name == TileName) tileLabel.Text = (string)prop.Value;
}
}
}
}
}
private void metroCheckBox2_CheckedChanged(object sender, EventArgs e)
{
metroLabel1.Visible = MipMapCheckbox.Checked;
MipMapNumericUpDown.Visible = MipMapCheckbox.Checked;
MipMapNumericUpDown.Visible = metroLabel1.Visible = MipMapCheckbox.Checked;
}
}
}

View File

@@ -28,8 +28,8 @@
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.acceptBtn = new System.Windows.Forms.Button();
this.CancelBtn = new System.Windows.Forms.Button();
this.treeView1 = new System.Windows.Forms.TreeView();
this.treeView2 = new System.Windows.Forms.TreeView();
this.metroLabel1 = new MetroFramework.Controls.MetroLabel();
@@ -43,31 +43,32 @@
this.Items.SuspendLayout();
this.SuspendLayout();
//
// button1
// acceptBtn
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.ForeColor = System.Drawing.Color.White;
this.button1.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.button1.Location = new System.Drawing.Point(55, 233);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 7;
this.button1.Text = "Save";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
this.acceptBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.acceptBtn.ForeColor = System.Drawing.Color.White;
this.acceptBtn.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.acceptBtn.Location = new System.Drawing.Point(55, 233);
this.acceptBtn.Name = "acceptBtn";
this.acceptBtn.Size = new System.Drawing.Size(75, 23);
this.acceptBtn.TabIndex = 7;
this.acceptBtn.Text = "Save";
this.acceptBtn.UseVisualStyleBackColor = true;
this.acceptBtn.Click += new System.EventHandler(this.button1_Click);
//
// button2
// CancelBtn
//
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.ForeColor = System.Drawing.Color.White;
this.button2.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.button2.Location = new System.Drawing.Point(135, 233);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 13;
this.button2.Text = "Cancel";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.CancelBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.CancelBtn.ForeColor = System.Drawing.Color.White;
this.CancelBtn.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.CancelBtn.Location = new System.Drawing.Point(135, 233);
this.CancelBtn.Name = "CancelBtn";
this.CancelBtn.Size = new System.Drawing.Size(75, 23);
this.CancelBtn.TabIndex = 13;
this.CancelBtn.Text = "Cancel";
this.CancelBtn.UseVisualStyleBackColor = true;
this.CancelBtn.Click += new System.EventHandler(this.button2_Click);
//
// treeView1
//
@@ -177,16 +178,18 @@
//
// ChangeTile
//
this.AcceptButton = this.acceptBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.CancelBtn;
this.ClientSize = new System.Drawing.Size(264, 264);
this.ControlBox = false;
this.Controls.Add(this.metroTabControl1);
this.Controls.Add(this.metroTextBox1);
this.Controls.Add(this.metroLabel2);
this.Controls.Add(this.metroLabel1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.CancelBtn);
this.Controls.Add(this.acceptBtn);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.MinimizeBox = false;
@@ -208,8 +211,8 @@
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button acceptBtn;
private System.Windows.Forms.Button CancelBtn;
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.TreeView treeView2;
private MetroFramework.Controls.MetroLabel metroLabel1;

View File

@@ -31,50 +31,56 @@ namespace PckStudio.Forms.Utilities.AnimationEditor
oldTileName = oldName;
InitializeComponent();
ImageList tiles = new ImageList();
tiles.ColorDepth = ColorDepth.Depth32Bit;
for (int i = 1; i < 545; i++)
{
int row = (i - 1) / 16;
int column = (i - 1) % 16;
//for (int i = 0; i < 545; i++)
//{
// int row = i / 16;
// int column = i % 16;
Rectangle tileArea = new Rectangle(new Point(column * 16, row * 16), new Size(16, 16));
// Rectangle tileArea = new Rectangle(new Point(column * 16, row * 16), new Size(16, 16));
Bitmap tileImage = new Bitmap(16, 16);
using (Graphics gfx = Graphics.FromImage(tileImage))
{
gfx.SmoothingMode = SmoothingMode.None;
gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
// Bitmap tileImage = new Bitmap(16, 16);
// using (Graphics gfx = Graphics.FromImage(tileImage))
// {
// gfx.SmoothingMode = SmoothingMode.None;
// gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
// gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
gfx.DrawImage(Properties.Resources.terrain_sheet, new Rectangle(0, 0, 16, 16), tileArea, GraphicsUnit.Pixel);
}
// gfx.DrawImage(Resources.terrain_sheet, new Rectangle(0, 0, 16, 16), tileArea, GraphicsUnit.Pixel);
// }
tiles.Images.Add(tileImage);
}
for (int i = 1; i < 273; i++)
{
int row = (i - 1) / 16;
int column = (i - 1) % 16;
// tiles.Images.Add(tileImage);
//}
//for (int i = 0; i < 273; i++)
//{
// int row = i / 16;
// int column = i % 16;
Rectangle tileArea = new Rectangle(new Point(column * 16, row * 16), new Size(16, 16));
// Rectangle tileArea = new Rectangle(new Point(column * 16, row * 16), new Size(16, 16));
Bitmap tileImage = new Bitmap(16, 16);
using (Graphics gfx = Graphics.FromImage(tileImage))
{
gfx.SmoothingMode = SmoothingMode.None;
gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
// Bitmap tileImage = new Bitmap(16, 16);
// using (Graphics gfx = Graphics.FromImage(tileImage))
// {
// gfx.SmoothingMode = SmoothingMode.None;
// gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
// gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
gfx.DrawImage(Resources.items_sheet, new Rectangle(0, 0, 16, 16), tileArea, GraphicsUnit.Pixel);
}
// gfx.DrawImage(Resources.items_sheet, new Rectangle(0, 0, 16, 16), tileArea, GraphicsUnit.Pixel);
// }
tiles.Images.Add(tileImage);
}
// tiles.Images.Add(tileImage);
//}
tiles.Images.AddRange(CreateImageList(Resources.terrain_sheet, 16, 16).ToArray());
tiles.Images.AddRange(CreateImageList(Resources.items_sheet, 16, 16).ToArray());
treeView1.ImageList = tiles;
treeView2.ImageList = tiles;
try
{
JObject tileData = JObject.Parse(Encoding.Default.GetString(Resources.tileData));
JObject tileData = JObject.Parse(Resources.tileData);
int i = 0;
if (tileData["Blocks"] != null)
@@ -120,10 +126,8 @@ namespace PckStudio.Forms.Utilities.AnimationEditor
}
}
treeView1.ImageList = tiles;
treeView2.ImageList = tiles;
Blocks.Controls.Add(treeView1);
Items.Controls.Add(treeView2);
//Blocks.Controls.Add(treeView1);
//Items.Controls.Add(treeView2);
}
catch (Newtonsoft.Json.JsonException j_ex)
{
@@ -132,15 +136,36 @@ namespace PckStudio.Forms.Utilities.AnimationEditor
}
}
private IEnumerable<Image> CreateImageList(Image source, int width, int height)
{
int img_row_count = source.Width / width;
int img_column_count = source.Height / height;
for (int i = 0; i < img_column_count * img_row_count; i++)
{
int row = i / width;
int column = i % height;
Rectangle tileArea = new Rectangle(new Point(column * width, row * height), new Size(16, 16));
Bitmap tileImage = new Bitmap(width, height);
using (Graphics gfx = Graphics.FromImage(tileImage))
{
gfx.SmoothingMode = SmoothingMode.None;
gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
gfx.DrawImage(source, new Rectangle(0, 0, width, height), tileArea, GraphicsUnit.Pixel);
}
yield return tileImage;
}
yield break;
}
private void treeViews_AfterSelect(object sender, TreeViewEventArgs e)
{
Tuple<string, int> tileData = e.Node.Tag as Tuple<string, int>;
Console.WriteLine(tileData.Item1 + " - " + tileData.Item2);
selectedTile = tileData.Item1;
Console.WriteLine(selectedTile);
if (e.Node.TreeView == treeView1) isItem = false;
if (e.Node.TreeView == treeView2) isItem = true;
isItem = e.Node.TreeView == treeView2;
}
void filter_TextChanged(object sender, EventArgs e)
@@ -194,7 +219,8 @@ namespace PckStudio.Forms.Utilities.AnimationEditor
private void button1_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(selectedTile)) return;
if (string.IsNullOrEmpty(selectedTile)) button2_Click(sender, e);
DialogResult = DialogResult.OK;
Close();
}
}

View File

@@ -127,7 +127,7 @@ namespace PckStudio.Forms.Utilities
{
Console.WriteLine("Duplicate category found, " + CatString + ". Combining...");
audioPCK.Files.Remove(categoryFile);
audioPCK.Files.Find(category => category.name == GetCategoryFromId(categoryFile.type)).properties = categoryFile.properties;
audioPCK.Files.Find(category => category.filepath == GetCategoryFromId(categoryFile.type)).properties = categoryFile.properties;
}
else
{
@@ -208,7 +208,7 @@ namespace PckStudio.Forms.Utilities
if (add.ShowDialog() == DialogResult.OK)
cats.Add(add.Category);
PCKFile.FileData file = new PCKFile.FileData(add.Category, GetCategoryId(add.Category));
TreeNode addNode = new TreeNode(file.name) { Tag = file };
TreeNode addNode = new TreeNode(file.filepath) { Tag = file };
audioPCK.Files.Add(file);
treeView1.Nodes.Add(addNode);
treeView1.Sort();

View File

@@ -451,9 +451,9 @@ namespace PckStudio.Forms.Utilities
foreach (PCKFile.FileData mf in Pck.Files)
{
System.IO.FileInfo file = new System.IO.FileInfo(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.name);
System.IO.FileInfo file = new System.IO.FileInfo(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.filepath);
file.Directory.Create(); // If the directory already exists, this method does nothing.
File.WriteAllBytes(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.name, mf.data); //writes minefile to file
File.WriteAllBytes(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.filepath, mf.data); //writes minefile to file
}
while (i <= ix)
{
@@ -476,9 +476,9 @@ namespace PckStudio.Forms.Utilities
foreach (PCKFile.FileData mf in Pck.Files)
{
System.IO.FileInfo file = new System.IO.FileInfo(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.name);
System.IO.FileInfo file = new System.IO.FileInfo(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.filepath);
file.Directory.Create(); // If the directory already exists, this method does nothing.
File.WriteAllBytes(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.name, mf.data); //writes minefile to file
File.WriteAllBytes(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.filepath, mf.data); //writes minefile to file
}
while (i <= ix)
{
@@ -501,9 +501,9 @@ namespace PckStudio.Forms.Utilities
foreach (PCKFile.FileData mf in Pck.Files)
{
FileInfo file = new FileInfo(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.name);
FileInfo file = new FileInfo(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.filepath);
file.Directory.Create(); // If the directory already exists, this method does nothing.
File.WriteAllBytes(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.name, mf.data); //writes minefile to file
File.WriteAllBytes(Environment.CurrentDirectory + "\\Temp\\" + @"\" + mf.filepath, mf.data); //writes minefile to file
}
while (i <= ix)
{

View File

@@ -30,7 +30,6 @@ namespace PckStudio.Forms
string ad;
int mode = 0;
string mod;
string appData = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/PCK Studio/";
MethodInvoker reloader;
bool IsVita;
string Pack;
@@ -134,23 +133,23 @@ namespace PckStudio.Forms
List<PCKFile.FileData> capesList = new List<PCKFile.FileData>();
PCKFile pck = null;
using (var stream = File.OpenRead(appData + "/PCK Center/myPcks/" + mod + ".pck"))
using (var stream = File.OpenRead(Program.Appdata + "/PCK-Center/myPcks/" + mod + ".pck"))
{
pck = PCKFileReader.Read(stream, false); //sets opened pck
pck = PCKFileReader.Read(stream, false); // sets opened pck
}
PCKFile currentPCK = pck; //sets opened pck
foreach (PCKFile.FileData skin in currentPCK.Files)
{
if (skin.name.Count() == 19)
if (skin.filepath.Count() == 19)
{
if (skin.name.Remove(7, skin.name.Count() - 7) == "dlcskin")
if (skin.filepath.Remove(7, skin.filepath.Count() - 7) == "dlcskin")
{
skinsList.Add(skin);
uuid = skin.name.Remove(12, 7);
uuid = skin.filepath.Remove(12, 7);
uuid = uuid.Remove(0, 7);
uuid = "abcdefa" + uuid;
}
if (skin.name.Remove(7, skin.name.Count() - 7) == "dlccape")
if (skin.filepath.Remove(7, skin.filepath.Count() - 7) == "dlccape")
{
capesList.Add(skin);
}
@@ -185,7 +184,7 @@ namespace PckStudio.Forms
if (entry.Item1 == "DISPLAYNAME")
{
skinName = entry.Item2;
skinDisplayNames.Add(new Item() { Id = newSkin.name.Remove(15, 4), Name = entry.Item2 });
skinDisplayNames.Add(new Item() { Id = newSkin.filepath.Remove(15, 4), Name = entry.Item2 });
}
if (entry.Item1 == "CAPEPATH")
{
@@ -195,15 +194,15 @@ namespace PckStudio.Forms
}
writeSkins.WriteLine(" {");
writeSkins.WriteLine(" \"localization_name\": " + "\"" + newSkin.name.Remove(15, 4) + "\",");
writeSkins.WriteLine(" \"localization_name\": " + "\"" + newSkin.filepath.Remove(15, 4) + "\",");
MemoryStream png = new MemoryStream(newSkin.data); //Gets image data from minefile data
Image skinPicture = Image.FromStream(png); //Constructs image data into image
if (skinPicture.Height == skinPicture.Width)
{
writeSkins.WriteLine(" \"geometry\": \"geometry." + packName + "." + newSkin.name.Remove(15, 4) + "\",");
writeSkins.WriteLine(" \"geometry\": \"geometry." + packName + "." + newSkin.filepath.Remove(15, 4) + "\",");
}
writeSkins.WriteLine(" \"texture\": " + "\"" + newSkin.name + "\",");
writeSkins.WriteLine(" \"texture\": " + "\"" + newSkin.filepath + "\",");
if (hasCape == true)
{
writeSkins.WriteLine(" \"cape\":" + "\"" + capePath + "\",");
@@ -367,7 +366,7 @@ namespace PckStudio.Forms
}
}
writeSkins.WriteLine(" \"" + "geometry." + packName + "." + newSkin.name.Remove(15, 4) + "\": {");
writeSkins.WriteLine(" \"" + "geometry." + packName + "." + newSkin.filepath.Remove(15, 4) + "\": {");
//makes skin model depending on what skin type the skin is
if (skinType == "custom")
@@ -448,7 +447,7 @@ namespace PckStudio.Forms
}
catch (Exception)
{
MessageBox.Show("A HEAD BOX tag in " + newSkin.name + " has an invalid value!");
MessageBox.Show("A HEAD BOX tag in " + newSkin.filepath + " has an invalid value!");
}
if (modelAmount != modelDataHead.Count)
{
@@ -539,7 +538,7 @@ namespace PckStudio.Forms
}
catch (Exception)
{
MessageBox.Show("A BODY BOX tag in " + newSkin.name + " has an invalid value!");
MessageBox.Show("A BODY BOX tag in " + newSkin.filepath + " has an invalid value!");
}
if (modelAmount != modelDataBody.Count)
{
@@ -630,7 +629,7 @@ namespace PckStudio.Forms
}
catch (Exception)
{
MessageBox.Show("A ARM0 BOX tag in " + newSkin.name + " has an invalid value!");
MessageBox.Show("A ARM0 BOX tag in " + newSkin.filepath + " has an invalid value!");
}
if (modelAmount != modelDataLeftArm.Count)
{
@@ -720,7 +719,7 @@ namespace PckStudio.Forms
}
catch (Exception)
{
MessageBox.Show("A ARM1 BOX tag in " + newSkin.name + " has an invalid value!");
MessageBox.Show("A ARM1 BOX tag in " + newSkin.filepath + " has an invalid value!");
}
if (modelAmount != modelDataRightArm.Count)
{
@@ -810,7 +809,7 @@ namespace PckStudio.Forms
}
catch (Exception)
{
MessageBox.Show("A LEG1 BOX tag in " + newSkin.name + " has an invalid value!");
MessageBox.Show("A LEG1 BOX tag in " + newSkin.filepath + " has an invalid value!");
}
if (modelAmount != modelDataLeftLeg.Count)
{
@@ -900,7 +899,7 @@ namespace PckStudio.Forms
}
catch (Exception)
{
MessageBox.Show("A LEG0 BOX tag in " + newSkin.name + " has an invalid value!");
MessageBox.Show("A LEG0 BOX tag in " + newSkin.filepath + " has an invalid value!");
}
if (modelAmount != modelDataRightLeg.Count)
{
@@ -1034,13 +1033,13 @@ namespace PckStudio.Forms
{
ResizeImage(saveSkin, 64, 64);
}
saveSkin.Save(root + "/" + skinTexture.name, ImageFormat.Png);
saveSkin.Save(root + "/" + skinTexture.filepath, ImageFormat.Png);
}
//adds cape textures
foreach (PCKFile.FileData capeTexture in capesList)
{
File.WriteAllBytes(root + "/" + capeTexture.name, capeTexture.data);
File.WriteAllBytes(root + "/" + capeTexture.filepath, capeTexture.data);
}
string startPath = root;
@@ -1103,9 +1102,9 @@ namespace PckStudio.Forms
{
try
{
File.Delete(appData + "/PCK Center/myPcks/" + mod + ".pck");
File.Delete(appData + "/PCK Center/myPcks/" + mod + ".png");
File.Delete(appData + "/PCK Center/myPcks/" + mod + ".desc");
File.Delete(Program.Appdata + "/PCK-Center/myPcks/" + mod + ".pck");
File.Delete(Program.Appdata + "/PCK-Center/myPcks/" + mod + ".png");
File.Delete(Program.Appdata + "/PCK-Center/myPcks/" + mod + ".desc");
reloader();
}
catch (Exception)
@@ -1125,7 +1124,7 @@ namespace PckStudio.Forms
{
try
{
File.Copy(appData + "/PCK Center/myPcks/" + mod + ".pck", export.FileName);
File.Copy(Program.Appdata + "/PCK-Center/myPcks/" + mod + ".pck", export.FileName);
MessageBox.Show("PCK Received from location!");
}catch (Exception)
{
@@ -1146,7 +1145,7 @@ namespace PckStudio.Forms
private void buttonInstallWiiU_Click(object sender, EventArgs e)
{
installWiiU install = new installWiiU(appData + "/PCK Center/myPcks/" + mod + ".pck");
installWiiU install = new installWiiU(Program.Appdata + "/PCK Center/myPcks/" + mod + ".pck");
install.ShowDialog();
}
}

View File

@@ -543,7 +543,6 @@
//
resources.ApplyResources(this.installationToolStripMenuItem, "installationToolStripMenuItem");
this.installationToolStripMenuItem.Name = "installationToolStripMenuItem";
this.installationToolStripMenuItem.Click += new System.EventHandler(this.installationToolStripMenuItem_Click);
//
// fAQToolStripMenuItem1
//

View File

@@ -88,9 +88,8 @@ namespace PckStudio
ofd.Filter = "PCK (Minecraft Console Package)|*.pck";
if (ofd.ShowDialog() == DialogResult.OK)
{
saveLocation = ofd.FileName;
currentPCK = openPck(ofd.FileName);
if (checkForPassword())
if (addPasswordToolStripMenuItem.Enabled = checkForPassword())
{
LoadEditorTab();
}
@@ -123,13 +122,11 @@ namespace PckStudio
private bool checkForPassword()
{
if (currentPCK.HasFile("0", 4))
foreach (var pair in currentPCK.GetFile("0", 4).properties)
{
addPasswordToolStripMenuItem.Enabled = pair.Item1 != "LOCK";
if (pair.Item1 == "LOCK")
return new pckLocked(pair.Item2).ShowDialog() == DialogResult.OK;
}
addPasswordToolStripMenuItem.Enabled = true;
{
var file = currentPCK.GetFile("0", 4);
if (file.properties.HasProperty("LOCK"))
return new pckLocked(file.properties.GetProperty("LOCK").Item2).ShowDialog() == DialogResult.OK;
}
return true;
}
@@ -201,7 +198,7 @@ namespace PckStudio
{
pckFile.Files.ForEach(file =>
{
TreeNode node = BuildNodeTreeBySeperator(root, file.name, '/');
TreeNode node = BuildNodeTreeBySeperator(root, file.filepath, '/');
node.Tag = file;
switch (file.type)
{
@@ -256,41 +253,33 @@ namespace PckStudio
private void selectNode(object sender, TreeViewEventArgs e)
{
treeMeta.Nodes.Clear();
ReloadMetaTreeView();
entryTypeTextBox.Text = entryDataTextBox.Text = labelImageSize.Text = "";
buttonEdit.Visible = false;
pictureBoxImagePreview.Image = Resources.NoImageFound;
pictureBoxImagePreview.Show();
var node = e.Node;
if (node.Tag == null || !(node.Tag is PCKFile.FileData)) return;
PCKFile.FileData file = node.Tag as PCKFile.FileData;
// Retrieves metadata for currently selected mineifile and displays it within metatreeview
foreach (var entry in file.properties)
if (file.properties.HasProperty("BOX"))
{
TreeNode meta = new TreeNode(entry.Item1);
meta.Tag = entry;
treeMeta.Nodes.Add(meta);
//Check for if file contains model data
if (entry.Item1 == "BOX")
{
buttonEdit.Text = "EDIT BOXES";
buttonEdit.Visible = true;
}
else if (entry.Item1 == "ANIM")
{
if ((entry.Item2 == "0x40000") || (entry.Item2 == "0x80000"))
{
buttonEdit.Text = "View Skin";
buttonEdit.Visible = true;
}
}
buttonEdit.Text = "EDIT BOXES";
buttonEdit.Visible = true;
}
else if (file.properties.HasProperty("ANIM") &&
(file.properties.GetProperty("ANIM").Item2 == "0x40000" ||
file.properties.GetProperty("ANIM").Item2 == "0x80000"))
{
buttonEdit.Text = "View Skin";
buttonEdit.Visible = true;
}
switch (file.type)
{
case 0:
case 1:
case 2 when (file.filepath.StartsWith("res/textures/blocks/") || file.filepath.StartsWith("res/textures/items/")) &&
!file.filepath.EndsWith("clock.png") && (!file.filepath.EndsWith("compass.png")):
buttonEdit.Text = "EDIT TEXTURE ANIMATION";
buttonEdit.Visible = true;
using (MemoryStream png = new MemoryStream(file.data))
{
Image skinPicture = Image.FromStream(png);
@@ -298,10 +287,10 @@ namespace PckStudio
labelImageSize.Text = $"{skinPicture.Size.Width}x{skinPicture.Size.Height}";
}
break;
case 2 when (file.name.StartsWith("res/textures/blocks/") || file.name.StartsWith("res/textures/items/")) &&
!file.name.EndsWith("clock.png") && (!file.name.EndsWith("compass.png")):
buttonEdit.Text = "EDIT TEXTURE ANIMATION";
buttonEdit.Visible = true;
case 0:
case 1:
case 2:
using (MemoryStream png = new MemoryStream(file.data))
{
Image skinPicture = Image.FromStream(png);
@@ -315,12 +304,12 @@ namespace PckStudio
buttonEdit.Visible = true;
break;
case 8 when file.name == "audio.pck":
case 8 when file.filepath == "audio.pck":
buttonEdit.Text = "EDIT MUSIC CUES";
buttonEdit.Visible = true;
break;
case 9 when file.name == "colours.col":
case 9 when file.filepath == "colours.col":
buttonEdit.Text = "EDIT COLORS";
buttonEdit.Visible = true;
break;
@@ -351,8 +340,8 @@ namespace PckStudio
{
var file = treeViewMain.SelectedNode.Tag as PCKFile.FileData;
using SaveFileDialog exFile = new SaveFileDialog();
exFile.FileName = Path.GetFileName(file.name);
exFile.Filter = Path.GetExtension(file.name).Replace(".", "") + " File|*" + Path.GetExtension(file.name);
exFile.FileName = Path.GetFileName(file.filepath);
exFile.Filter = Path.GetExtension(file.filepath).Replace(".", "") + " File|*" + Path.GetExtension(file.filepath);
if (exFile.ShowDialog() != DialogResult.OK ||
// Makes sure chosen directory isn't null or whitespace AKA makes sure its usable
string.IsNullOrWhiteSpace(Path.GetDirectoryName(exFile.FileName))) return;
@@ -377,10 +366,10 @@ namespace PckStudio
{
currentPCK.Files.ForEach(file =>
{
if (file.name.StartsWith(selectedFolder))
if (file.filepath.StartsWith(selectedFolder))
{
Directory.CreateDirectory($"{dialog.SelectedPath}/{Path.GetDirectoryName(file.name)}");
File.WriteAllBytes($"{dialog.SelectedPath}/{file.name}", file.data);
Directory.CreateDirectory($"{dialog.SelectedPath}/{Path.GetDirectoryName(file.filepath)}");
File.WriteAllBytes($"{dialog.SelectedPath}/{file.filepath}", file.data);
}
});
MessageBox.Show("Folder Extracted");
@@ -413,21 +402,21 @@ namespace PckStudio
private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!(treeViewMain.SelectedNode.Tag is PCKFile.FileData))
if (treeViewMain.SelectedNode.Tag is PCKFile.FileData)
{
// should never happen unless its a folder
MessageBox.Show("Can't replace a folder.");
PCKFile.FileData file = treeViewMain.SelectedNode.Tag as PCKFile.FileData;
using (var ofd = new OpenFileDialog())
{
if (ofd.ShowDialog() == DialogResult.OK)
{
file.SetData(File.ReadAllBytes(ofd.FileName));
saved = false;
}
}
return;
}
PCKFile.FileData file = treeViewMain.SelectedNode.Tag as PCKFile.FileData;
using (var ofd = new OpenFileDialog())
{
if (ofd.ShowDialog() == DialogResult.OK)
{
file.SetData(File.ReadAllBytes(ofd.FileName));
saved = false;
}
}
// should never happen unless its a folder
MessageBox.Show("Can't replace a folder.");
}
private void deleteFileToolStripMenuItem_Click(object sender, EventArgs e)
@@ -459,7 +448,7 @@ namespace PckStudio
MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
string pckFolderDir = node.FullPath;
currentPCK.Files.RemoveAll(file => file.name.StartsWith(pckFolderDir));
currentPCK.Files.RemoveAll(file => file.filepath.StartsWith(pckFolderDir));
node.Remove();
saved = false;
}
@@ -469,25 +458,25 @@ namespace PckStudio
{
TreeNode node = treeViewMain.SelectedNode;
if (node == null) return;
using (RenamePrompt diag = new RenamePrompt(node.FullPath))
if (diag.ShowDialog(this) == DialogResult.OK)
using RenamePrompt diag = new RenamePrompt(node.FullPath);
if (diag.ShowDialog(this) == DialogResult.OK)
{
if (node.Tag is PCKFile.FileData)
{
if (node.Tag is PCKFile.FileData)
{
var file = node.Tag as PCKFile.FileData;
file.name = diag.NewText;
}
else // folder
{
currentPCK.Files.ForEach(file =>
{
if (file.name.StartsWith(node.FullPath))
file.name = diag.NewText + file.name.Substring(node.FullPath.Length);
});
}
saved = false;
BuildMainTreeView();
var file = node.Tag as PCKFile.FileData;
file.filepath = diag.NewText;
}
else // folder
{
currentPCK.Files.ForEach(file =>
{
if (file.filepath.StartsWith(node.FullPath))
file.filepath = diag.NewText + file.filepath.Substring(node.FullPath.Length);
});
}
saved = false;
BuildMainTreeView();
}
}
private void createSkinToolStripMenuItem_Click(object sender, EventArgs e)
@@ -497,19 +486,18 @@ namespace PckStudio
MessageBox.Show("No .loc file found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
addNewSkin add = new addNewSkin(locFile);
if (add.ShowDialog() == DialogResult.OK)
{
if (add.useCape)
currentPCK.Files.Add(add.Cape);
if (!(treeViewMain.SelectedNode.Tag is PCKFile.FileData))
add.Skin.name = $"{treeViewMain.SelectedNode.FullPath}/{add.Skin.name}";
currentPCK.Files.Add(add.Skin);
TrySetLocFile(locFile);
saved = false;
BuildMainTreeView();
}
add.Dispose();
using (addNewSkin add = new addNewSkin(locFile))
if (add.ShowDialog() == DialogResult.OK)
{
if (add.useCape)
currentPCK.Files.Add(add.Cape);
if (!(treeViewMain.SelectedNode.Tag is PCKFile.FileData))
add.Skin.filepath = $"{treeViewMain.SelectedNode.FullPath}/{add.Skin.filepath}";
currentPCK.Files.Add(add.Skin);
TrySetLocFile(locFile);
saved = false;
BuildMainTreeView();
}
}
private void audiopckToolStripMenuItem_Click(object sender, EventArgs e)
@@ -539,12 +527,20 @@ namespace PckStudio
{
try
{
var animation_file = new PCKFile.FileData("", 2);
AnimationEditor diag = new AnimationEditor(animation_file, ofd.FileName);
diag.ShowDialog(this);
diag.Dispose();
treeMeta.Nodes.Clear();
saved = false;
using (Forms.Utilities.AnimationEditor.ChangeTile diag = new Forms.Utilities.AnimationEditor.ChangeTile())
if (diag.ShowDialog(this) == DialogResult.OK)
{
Console.WriteLine(diag.SelectedTile);
using (Image img = new Bitmap(ofd.FileName))
using (AnimationEditor animationEditor = new AnimationEditor(img, diag.SelectedTile, diag.IsItem))
{
if (animationEditor.ShowDialog() == DialogResult.OK)
{
treeMeta.Nodes.Clear();
saved = false;
}
}
}
}
catch
{
@@ -562,78 +558,75 @@ namespace PckStudio
!(treeViewMain.SelectedNode.Tag is PCKFile.FileData))
return;
PCKFile.FileData file = treeViewMain.SelectedNode.Tag as PCKFile.FileData;
if (file.type == 6) // .loc
switch (file.type)
{
LOCFile l = null;
using (var stream = new MemoryStream(file.data))
{
l = LOCFileReader.Read(stream);
}
var locedit = new LOCEditor(l);
locedit.ShowDialog(this);
if (locedit.WasModified)
{
using (var stream = new MemoryStream())
case 6:
LOCFile l = null;
using (var stream = new MemoryStream(file.data))
{
LOCFileWriter.Write(stream, l);
file.SetData(stream.ToArray());
l = LOCFileReader.Read(stream);
}
saved = false;
}
}
var locedit = new LOCEditor(l);
locedit.ShowDialog(this);
if (locedit.WasModified)
{
using (var stream = new MemoryStream())
{
LOCFileWriter.Write(stream, l);
file.SetData(stream.ToArray());
}
saved = false;
}
break;
if (Path.GetFileName(file.name) == "audio.pck" && file.type == 8)
{
try
{
if (!TryGetLocFile(out LOCFile locFile))
throw new Exception("No .loc File found.");
AudioEditor diag = new AudioEditor(file, locFile, LittleEndianCheckBox.Checked);
if (LittleEndianCheckBox.Checked) diag.Text += " (PS4/Vita)";
diag.ShowDialog(this);
case 7:
case 10 when (Path.GetExtension(file.filepath) == ".grf" && file.type == 7) ||
(Path.GetExtension(file.filepath) == ".grh" && file.type == 10):
using (GRFEditor grfEditor = new GRFEditor(file))
grfEditor.ShowDialog();
break;
case 8 when file.filepath == "audio.pck":
try
{
if (!TryGetLocFile(out LOCFile locFile))
throw new Exception("No .loc File found.");
AudioEditor audioEditor = new AudioEditor(file, locFile, LittleEndianCheckBox.Checked);
audioEditor.ShowDialog(this);
audioEditor.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("Error", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
break;
case 9 when file.filepath == "colours.col":
if (file.size == 0)
{
MessageBox.Show("No Color data found.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
COLFile colFile = new COLFile();
using (var stream = new MemoryStream(file.data))
{
colFile.Open(stream);
}
COLEditor diag = new COLEditor(colFile);
if (diag.ShowDialog(this) == DialogResult.OK && diag.data.Length > 0)
file.SetData(diag.data);
diag.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("Error", ex.Message, MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
}
if ((Path.GetExtension(file.name) == ".grf" && file.type == 7) ||
(Path.GetExtension(file.name) == ".grh" && file.type == 10))
{
using GRFEditor diag = new GRFEditor(file);
diag.ShowDialog();
}
//Checks to see if selected minefile is a col file
if (Path.GetExtension(file.name) == ".col" && file.type == 9)
{
if (file.size == 0)
{
MessageBox.Show("No Color data found.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
COLFile colFile = new COLFile();
using (var stream = new MemoryStream(file.data))
{
colFile.Open(stream);
}
COLEditor diag = new COLEditor(colFile);
if (diag.ShowDialog(this) == DialogResult.OK && diag.data.Length > 0)
file.SetData(diag.data);
diag.Dispose();
break;
}
//System.Threading.ThreadStart starter;
//System.Threading.Thread binkam;
//Checks to see if selected minefile is a binka file
if (Path.GetExtension(file.name) == ".binka")
if (Path.GetExtension(file.filepath) == ".binka")
{
MessageBox.Show(".binka Editor Coming Soon!");
}
@@ -670,26 +663,26 @@ namespace PckStudio
TreeNode node = treeViewMain.SelectedNode;
PCKFile.FileData mfO = node.Tag as PCKFile.FileData;
PCKFile.FileData mf = new PCKFile.FileData("", mfO.type);//Creates new minefile template
mf.SetData(mfO.data);//adds file data to minefile
String dirName = Path.GetDirectoryName(mfO.name).Replace("\\", "/");
PCKFile.FileData mf = new PCKFile.FileData("", mfO.type); // Creates new minefile template
mf.SetData(mfO.data); // adds file data to minefile
string dirName = Path.GetDirectoryName(mfO.filepath).Replace("\\", "/");
int clone_number = 0;
string old_clone_str = "_clone1";
String nameWithoutExt = Path.GetFileNameWithoutExtension(mfO.name);
String newFileName = mfO.name;
string prev_clone_str = "_clone1";
string nameWithoutExt = Path.GetFileNameWithoutExtension(mfO.filepath);
string newFileName = mfO.filepath;
do // Checks for existing clones and names it accordingly
{
clone_number++;
string clone_str = "_clone" + clone_number.ToString();
bool isClone = nameWithoutExt.Contains("_clone");
if(isClone) newFileName = nameWithoutExt.Remove(nameWithoutExt.Length - 7) + clone_str + Path.GetExtension(mfO.name);
else newFileName = nameWithoutExt + clone_str + Path.GetExtension(mfO.name);
old_clone_str = clone_str;
if(isClone) newFileName = nameWithoutExt.Remove(nameWithoutExt.Length - 7) + clone_str + Path.GetExtension(mfO.filepath);
else newFileName = nameWithoutExt + clone_str + Path.GetExtension(mfO.filepath);
prev_clone_str = clone_str;
}
while (currentPCK.HasFile(dirName + (String.IsNullOrEmpty(dirName) ? "" : "/") + newFileName, mf.type));
while (currentPCK.HasFile(dirName + (string.IsNullOrEmpty(dirName) ? "" : "/") + newFileName, mf.type));
mf.name = dirName + (String.IsNullOrEmpty(dirName) ? "" : "/") + newFileName; //sets minfile name to file name
mf.filepath = dirName + (string.IsNullOrEmpty(dirName) ? "" : "/") + newFileName; //sets minfile name to file name
foreach (var entry in mfO.properties)
{
var property = (ValueTuple<string, string>)entry;
@@ -704,7 +697,7 @@ namespace PckStudio
if (node.Parent == null) treeViewMain.Nodes.Insert(node.Index + 1, newNode); //adds generated minefile node
else node.Parent.Nodes.Insert(node.Index + 1, newNode);//adds generated minefile node to selected folder
currentPCK.Files.Insert(node.Index + 1, newNode.Tag as PCKFile.FileData);
currentPCK.Files.Insert(node.Index + 1, mf);
}
private void deleteEntryToolStripMenuItem_Click(object sender, EventArgs e)
@@ -869,23 +862,22 @@ namespace PckStudio
private void metaToolStripMenuItem_Click(object sender, EventArgs e)
{
meta edit = new meta(currentPCK.GatherMetaTags());
meta edit = new meta(currentPCK.GatherPropertiesList());
edit.TopMost = true;
edit.TopLevel = true;
edit.Show();
//saved = false;
}
private void addPresetToolStripMenuItem1_Click(object sender, EventArgs e)
{
PCKFile.FileData file = (PCKFile.FileData)treeViewMain.SelectedNode.Tag;
presetMeta add = new presetMeta(file);
if (!(treeViewMain.SelectedNode.Tag is PCKFile.FileData)) return;
PCKFile.FileData file = treeViewMain.SelectedNode.Tag as PCKFile.FileData;
using presetMeta add = new presetMeta(file);
if (add.ShowDialog() == DialogResult.OK)
{
ReloadMetaTreeView();
saved = false;
}
add.Dispose();
}
private void InitializeSkinPack(int packId, int packVersion, string packName)
@@ -909,9 +901,10 @@ namespace PckStudio
private void InitializeTexturePack(int packId, int packVersion, string packName)
{
InitializeSkinPack(packId, packVersion, packName);
var texturepackInfo = new PCKFile.FileData("x16/x16Info.pck", 5);
string res = "x16"; // TODO: add reselotions selection prompt
var texturepackInfo = new PCKFile.FileData($"{res}/{res}Info.pck", 5);
texturepackInfo.properties.Add(("PACKID", "0"));
texturepackInfo.properties.Add(("DATAPATH", "x16Data.pck"));
texturepackInfo.properties.Add(("DATAPATH", $"{res}Data.pck"));
currentPCK.Files.Add(texturepackInfo);
}
@@ -987,8 +980,7 @@ namespace PckStudio
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!saved)
SaveTemplate();
checkSaveState();
CloseEditorTab();
}
@@ -1017,8 +1009,8 @@ namespace PckStudio
try
{
//Extracts a chosen pck file to a chosen destincation
OpenFileDialog ofd = new OpenFileDialog();
FolderBrowserDialog sfd = new FolderBrowserDialog();
using OpenFileDialog ofd = new OpenFileDialog();
using FolderBrowserDialog sfd = new FolderBrowserDialog();
ofd.CheckFileExists = true;
ofd.Filter = "PCK (Minecraft Console Package)|*.pck";
@@ -1027,21 +1019,28 @@ namespace PckStudio
PCKFile pckfile = null;
using (var fs = File.OpenRead(ofd.FileName))
{
pckfile = PCKFileReader.Read(fs, LittleEndianCheckBox.Checked);
try
{
pckfile = PCKFileReader.Read(fs, LittleEndianCheckBox.Checked);
}
catch (OverflowException ex)
{
MessageBox.Show("Error", "Failed to open pck\nTry checking the 'Open/Save as Vita/PS4 pck' check box in the upper right corner.",
MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine(ex.Message);
}
}
if (pckfile.HasFile("0", 4) &&
pckfile.GetFile("0", 4).properties.HasProperty("LOCK") &&
new pckLocked(pckfile.GetFile("0", 4).properties.GetProperty("LOCK").Item2).ShowDialog() != DialogResult.OK)
return; // cancel extraction if password not provided
foreach (PCKFile.FileData mf in pckfile.Files)
{
foreach (var entry in mf.properties)
{
// Check for lock on PCK File
if (entry.Item1 == "LOCK" &&
new pckLocked(entry.Item2).ShowDialog() != DialogResult.OK)
return; // cancel extraction if password not provided
}
FileInfo file = new FileInfo(sfd.SelectedPath + @"\" + mf.name);
file.Directory.Create(); // If the directory already exists, this method does nothing.
File.WriteAllBytes(sfd.SelectedPath + @"\" + mf.name, mf.data); //writes minefile to file
//attempts to generate reimportable metadata file out of minefiles metadata
string filepath = $"{sfd.SelectedPath}/{mf.filepath}";
FileInfo file = new FileInfo(filepath);
file.Directory.Create();
File.WriteAllBytes(filepath, mf.data); // writes data to file
//attempts to generate reimportable metadata file out of minefiles metadata
string metaData = "";
foreach (var entry in mf.properties)
@@ -1049,7 +1048,7 @@ namespace PckStudio
metaData += $"{entry.Item1}: {entry.Item2}{Environment.NewLine}";
}
File.WriteAllText(sfd.SelectedPath + @"\" + mf.name + ".txt", metaData);
File.WriteAllText(sfd.SelectedPath + @"\" + Path.GetFileNameWithoutExtension(mf.filepath) + ".properties", metaData);
}
}
}
@@ -1059,17 +1058,10 @@ namespace PckStudio
}
}
private void treeMeta_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Delete && treeMeta.SelectedNode != null && treeViewMain.SelectedNode.Tag is PCKFile.FileData)
{
//removes selected treemeta entry
var file = treeViewMain.SelectedNode.Tag as PCKFile.FileData;
if (file.properties.Remove((ValueTuple<string, string>)treeMeta.SelectedNode.Tag))
treeMeta.Nodes.Remove(treeMeta.SelectedNode);
saved = false;
}
if (e.KeyData == Keys.Delete)
deleteEntryToolStripMenuItem_Click(sender, e);
}
#region imports a folder of skins to pck
@@ -1124,11 +1116,11 @@ namespace PckStudio
//Sets minefile directory based on pcks structure/type
if (mashupStructure == true)
{
mfNew.name = "Skins/" + Import.Text + ".png";
mfNew.filepath = "Skins/" + Import.Text + ".png";
}
else
{
mfNew.name = Import.Text + ".png";
mfNew.filepath = Import.Text + ".png";
}
skin.Text = Import.Text + ".png";//adds file extension to minefile
@@ -1275,9 +1267,7 @@ namespace PckStudio
else if (currentPCK.HasFile("languages.loc", 6))
locdata = currentPCK.GetFile("languages.loc", 6);
else
{
return false;
}
try
{
@@ -1300,51 +1290,52 @@ namespace PckStudio
{
using (OpenFileDialog contents = new OpenFileDialog())
{
contents.Title = "Select Extracted Skin Data File";
contents.Filter = "Text Files (*.txt)|*.txt";
contents.Title = "Select Extracted Skin File";
contents.Filter = "Skin File (*.png)|*.png";
if (contents.ShowDialog() == DialogResult.OK)
{
string skinNameImport = Path.GetFileName(contents.FileName); //Gets skin file name
string dataFilePath = contents.FileName.Remove(contents.FileName.Length - 4, 4);
if (!File.Exists(dataFilePath)) return;
byte[] data = File.ReadAllBytes(dataFilePath);
string skinNameImport = Path.GetFileName(contents.FileName);
byte[] data = File.ReadAllBytes(contents.FileName);
PCKFile.FileData mfNew = new PCKFile.FileData(skinNameImport, 0);
mfNew.SetData(data);
string[] txtProperties = File.ReadAllText(contents.FileName).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
LOCFile locFile = null;
if ((txtProperties.Contains("DISPLAYNAMEID") && txtProperties.Contains("DISPLAYNAME")) ||
string propertyFile = Path.GetFileNameWithoutExtension(contents.FileName) + ".properties";
if (File.Exists(propertyFile))
{
string[] txtProperties = File.ReadAllLines(propertyFile);
if ((txtProperties.Contains("DISPLAYNAMEID") && txtProperties.Contains("DISPLAYNAME")) ||
(txtProperties.Contains("THEMENAMEID") && txtProperties.Contains("THEMENAME")) &&
TryGetLocFile(out locFile))
{
// do stuff
//l.AddLocKey(locThemeId, locTheme);
//using (var stream = new MemoryStream())
//{
// LOCFileWriter.Write(stream, locFile);
// locdata.SetData(stream.ToArray());
//}
}
try
{
foreach (string prop in txtProperties)
TryGetLocFile(out LOCFile locFile))
{
string[] arg = prop.Split(':');
if (arg.Length < 2) continue;
string key = arg[0];
string value = arg[1];
if (key == "DISPLNAMEID" || key == "THEMENAMEID")
{
}
mfNew.properties.Add(new ValueTuple<string, string>(key, value));
// do stuff
//l.AddLocKey(locThemeId, locTheme);
//using (var stream = new MemoryStream())
//{
// LOCFileWriter.Write(stream, locFile);
// locdata.SetData(stream.ToArray());
//}
}
try
{
foreach (string prop in txtProperties)
{
string[] arg = prop.Split(':');
if (arg.Length < 2) continue;
string key = arg[0];
string value = arg[1];
if (key == "DISPLNAMEID" || key == "THEMENAMEID")
{
}
mfNew.properties.Add(new ValueTuple<string, string>(key, value));
}
saved = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
saved = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
@@ -1369,9 +1360,19 @@ namespace PckStudio
}
}
private void installationToolStripMenuItem_Click(object sender, EventArgs e)
private void addPasswordToolStripMenuItem_Click(object sender, EventArgs e)
{
//System.Diagnostics.Process.Start(hosturl + "pckStudio#install");
if (!currentPCK.HasFile("0", 4)) throw new Exception("0 file not found");
PCKFile.FileData file = currentPCK.GetFile("0", 4);
if (checkForPassword())
{
AddPCKPassword add = new AddPCKPassword();
if (add.ShowDialog() == DialogResult.OK)
file.properties.Add(("LOCK", add.Password));
add.Dispose();
ReloadMetaTreeView();
saved = false;
}
}
private void binkaConversionToolStripMenuItem_Click(object sender, EventArgs e)
@@ -2713,21 +2714,6 @@ namespace PckStudio
Process.Start("https://www.paypal.me/realnobledez");
}
private void addPasswordToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!currentPCK.HasFile("0", 4)) throw new Exception("0 file not found");
PCKFile.FileData file = currentPCK.GetFile("0", 4); // Sets minefile to selected node
if (checkForPassword())
{
AddPCKPassword add = new AddPCKPassword(); //sets metadata adding dialog
if (add.ShowDialog() == DialogResult.OK)
file.properties.Add(("LOCK", add.Password));
add.Dispose();
ReloadMetaTreeView();
saved = false;
}
}
private void joinDevelopmentDiscordToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start("https://discord.gg/aJtZNFVQTv");
@@ -2763,7 +2749,7 @@ namespace PckStudio
}
//Check for Animated Texture
if (file.name.StartsWith("res/textures/blocks/") || file.name.StartsWith("res/textures/items/"))
if (file.filepath.StartsWith("res/textures/blocks/") || file.filepath.StartsWith("res/textures/items/"))
{
try
{
@@ -2779,7 +2765,7 @@ namespace PckStudio
}
}
if (Path.GetFileName(file.name) == "audio.pck")
if (Path.GetFileName(file.filepath) == "audio.pck")
{
try
{
@@ -2797,7 +2783,7 @@ namespace PckStudio
}
}
if (file.type == 6 && (file.name == "languages.loc" || file.name == "localisation.loc"))
if (file.type == 6 && (file.filepath == "languages.loc" || file.filepath == "localisation.loc"))
{
LOCFile locFile = null;
using (var stream = new MemoryStream(file.data))
@@ -2814,7 +2800,7 @@ namespace PckStudio
}
// Checks to see if selected minefile is a col file
if (file.type == 9 && file.name == "colours.col") // .col file
if (file.type == 9 && file.filepath == "colours.col") // .col file
{
COLFile colFile = new COLFile();
using (var stream = new MemoryStream(file.data))
@@ -2827,7 +2813,6 @@ namespace PckStudio
}
}
private void OpenPck_MouseEnter(object sender, EventArgs e)
{
pckOpen.Image = Resources.pckOpen;
@@ -2880,7 +2865,7 @@ namespace PckStudio
if (FileList.Length > 1)
MessageBox.Show("Only one pck file at a time is currently supported");
currentPCK = openPck(FileList[0]);
if (checkForPassword())
if (addPasswordToolStripMenuItem.Enabled = checkForPassword())
{
LoadEditorTab();
}
@@ -2893,7 +2878,8 @@ namespace PckStudio
private void savePCK(object sender, EventArgs e)
{
checkSaveState();
if (!string.IsNullOrEmpty(saveLocation))
Save(saveLocation);
}
private void saveAsPCK(object sender, EventArgs e)
@@ -2911,7 +2897,7 @@ namespace PckStudio
TreeNode node = treeViewMain.SelectedNode;
if (node == null || node.Tag == null || !(node.Tag is PCKFile.FileData)) return;
var file = node.Tag as PCKFile.FileData;
Console.WriteLine("Setting {file.type} to {type}");
Console.WriteLine($"Setting {file.type} to {type}");
file.type = type;
}
}

View File

@@ -381,12 +381,26 @@ namespace PckStudio.Properties {
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// Looks up a localized string similar to {
/// &quot;COMMENT_1&quot;: &quot;Tile data research by MattNL&quot;,
/// &quot;COMMENT_2&quot;: &quot;JSON conversion by PhoenixARC&quot;,
/// &quot;Blocks&quot;: [
/// { &quot;grass_top&quot;: &quot;Grass Block (Top)&quot; },
/// { &quot;stone&quot;: &quot;Stone&quot; },
/// { &quot;dirt&quot;: &quot;Dirt&quot; },
/// { &quot;grass_side&quot;: &quot;Grass Block (Side)&quot; },
/// { &quot;planks_oak&quot;: &quot;Oak Planks&quot; },
/// { &quot;stoneslab_side&quot;: &quot;Stone Slab (Side)&quot; },
/// { &quot;stoneslab_top&quot;: &quot;Stone Slab (Top)&quot; },
/// { &quot;brick&quot;: &quot;Bricks&quot; },
/// { &quot;tnt_side&quot;: &quot;TNT (Side)&quot; },
/// { &quot;tnt_top&quot;: &quot;TNT (Top)&quot; },
/// { &quot;tnt_bottom&quot;: &quot;TNT (Bottom)&quot; },
/// { &quot;web&quot;: &quot;Cobw [rest of string was truncated]&quot;;.
/// </summary>
public static byte[] tileData {
public static string tileData {
get {
object obj = ResourceManager.GetObject("tileData", resourceCulture);
return ((byte[])(obj));
return ResourceManager.GetString("tileData", resourceCulture);
}
}

View File

@@ -140,7 +140,7 @@
<value>..\Resources\iconImageList\IMAGE ICON.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="tileData" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\tileData.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>..\Resources\tileData.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="ExportFile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ExportFile.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>