Add option to download Mojang assets
Also fixes a bug with texture pack loading in the client. Note: we cannot distribute Mojang assets, but some players might want to use them. To that end, the launcher now has a button that allows the user to download them him or herself. Since we download them directly from Mojang, we're be good to go.
This commit is contained in:
parent
8d16467ac0
commit
386d8f7328
@ -94,8 +94,11 @@ namespace TrueCraft.Client.Rendering
|
||||
foreach (var entry in archive.Entries)
|
||||
{
|
||||
var key = entry.FileName;
|
||||
using (var stream = entry.OpenReader())
|
||||
AddTexture(key, Texture2D.FromStream(Device, stream));
|
||||
if (Path.GetExtension(key) == ".png")
|
||||
{
|
||||
using (var stream = entry.OpenReader())
|
||||
AddTexture(key, Texture2D.FromStream(Device, stream));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { return; }
|
||||
|
@ -45,6 +45,9 @@
|
||||
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<Commandlineparameters>localhost TestUser</Commandlineparameters>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Ionic.Zip.Reduced">
|
||||
<HintPath>..\lib\Ionic.Zip.Reduced.dll</HintPath>
|
||||
|
@ -86,7 +86,7 @@ namespace TrueCraft.Client
|
||||
var centerX = GraphicsDevice.Viewport.Width / 2;
|
||||
var centerY = GraphicsDevice.Viewport.Height / 2;
|
||||
Mouse.SetPosition(centerX, centerY);
|
||||
Camera = new Camera(GraphicsDevice.Viewport.AspectRatio, 70.0f, 0.5f, 1000.0f);
|
||||
Camera = new Camera(GraphicsDevice.Viewport.AspectRatio, 70.0f, 0.25f, 1000.0f);
|
||||
UpdateCamera();
|
||||
Window.ClientSizeChanged += (sender, e) => CreateRenderTarget();
|
||||
MouseComponent.Move += OnMouseComponentMove;
|
||||
|
@ -20,11 +20,9 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<CustomCommands>
|
||||
<Command>
|
||||
<Command type="AfterBuild" command="rm ${TargetDir}/MonoGame.Framework.dll" />
|
||||
<Command type="AfterBuild" command="cp ${SolutionDir}/packages/MonoGame.Framework.Linux.3.4.0.459/lib/net40/MonoGame.Framework.dll ${TargetDir}/MonoGame.Framework.Linux.dll" />
|
||||
<Command type="AfterBuild" command="cp ${SolutionDir}/packages/MonoGame.Framework.WindowsGL.3.4.0.459/lib/net40/MonoGame.Framework.dll ${TargetDir}/MonoGame.Framework.Windows.dll" />
|
||||
</CustomCommands>
|
||||
</Command>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
@ -33,11 +31,9 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<CustomCommands>
|
||||
<Command>
|
||||
<Command type="AfterBuild" command="rm ${TargetDir}/MonoGame.Framework.dll" />
|
||||
<Command type="AfterBuild" command="cp ${SolutionDir}/packages/MonoGame.Framework.Linux.3.4.0.459/lib/net40/MonoGame.Framework.dll ${TargetDir}/MonoGame.Framework.Linux.dll" />
|
||||
<Command type="AfterBuild" command="cp ${SolutionDir}/packages/MonoGame.Framework.WindowsGL.3.4.0.459/lib/net40/MonoGame.Framework.dll ${TargetDir}/MonoGame.Framework.Windows.dll" />
|
||||
</CustomCommands>
|
||||
</Command>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
@ -47,6 +43,9 @@
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Ionic.Zip.Reduced">
|
||||
<HintPath>..\lib\Ionic.Zip.Reduced.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
|
@ -5,6 +5,10 @@ using System.Collections.Generic;
|
||||
using TrueCraft.Core;
|
||||
using Xwt;
|
||||
using Xwt.Drawing;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net;
|
||||
using Ionic.Zip;
|
||||
using System.Linq;
|
||||
|
||||
namespace TrueCraft.Launcher.Views
|
||||
{
|
||||
@ -21,6 +25,8 @@ namespace TrueCraft.Launcher.Views
|
||||
public DataField<string> TexturePackTextField { get; set; }
|
||||
public ListStore TexturePackStore { get; set; }
|
||||
public ListView TexturePackListView { get; set; }
|
||||
public Button OfficialAssetsButton { get; set; }
|
||||
public ProgressBar OfficialAssetsProgress { get; set; }
|
||||
public Button OpenFolderButton { get; set; }
|
||||
public Button BackButton { get; set; }
|
||||
|
||||
@ -122,6 +128,10 @@ namespace TrueCraft.Launcher.Views
|
||||
Window.MainContainer.PackEnd(Window.MainMenuView);
|
||||
};
|
||||
|
||||
OfficialAssetsButton = new Button("Download Minecraft assets") { Visible = false };
|
||||
OfficialAssetsButton.Clicked += OfficialAssetsButton_Clicked;
|
||||
OfficialAssetsProgress = new ProgressBar() { Visible = false, Indeterminate = true };
|
||||
|
||||
LoadTexturePacks();
|
||||
|
||||
this.PackStart(OptionLabel);
|
||||
@ -130,10 +140,83 @@ namespace TrueCraft.Launcher.Views
|
||||
this.PackStart(FullscreenCheckBox);
|
||||
this.PackStart(TexturePackLabel);
|
||||
this.PackStart(TexturePackListView);
|
||||
this.PackStart(OfficialAssetsProgress);
|
||||
this.PackStart(OfficialAssetsButton);
|
||||
this.PackStart(OpenFolderButton);
|
||||
this.PackEnd(BackButton);
|
||||
}
|
||||
|
||||
void OfficialAssetsButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
var result = MessageDialog.AskQuestion("Download Mojang assets",
|
||||
"This will download the official Minecraft assets from Mojang.\n\n" +
|
||||
"By proceeding you agree to the Mojang asset guidelines:\n\n" +
|
||||
"https://account.mojang.com/terms#brand\n\n" +
|
||||
"Proceed?",
|
||||
Command.Yes, Command.No);
|
||||
if (result == Command.Yes)
|
||||
{
|
||||
OfficialAssetsButton.Visible = false;
|
||||
OfficialAssetsProgress.Visible = true;
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var stream = new WebClient().OpenRead("http://s3.amazonaws.com/Minecraft.Download/versions/b1.7.3/b1.7.3.jar");
|
||||
var ms = new MemoryStream();
|
||||
CopyStream(stream, ms);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
stream.Dispose();
|
||||
var jar = ZipFile.Read(ms);
|
||||
var zip = new ZipFile();
|
||||
zip.AddEntry("pack.txt", "Minecraft textures");
|
||||
CopyBetweenZips("pack.png", jar, zip);
|
||||
CopyBetweenZips("terrain.png", jar, zip);
|
||||
// TODO: Items, windows, etc
|
||||
zip.Save(Path.Combine(TexturePack.TexturePackPath, "Minecraft.zip"));
|
||||
Application.Invoke(() =>
|
||||
{
|
||||
OfficialAssetsProgress.Visible = false;
|
||||
LoadTexturePacks();
|
||||
var texturePack = TexturePack.FromArchive(Path.Combine(TexturePack.TexturePackPath, "Minecraft.zip"));
|
||||
AddTexturePackRow(texturePack);
|
||||
});
|
||||
ms.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Application.Invoke(() =>
|
||||
{
|
||||
MessageDialog.ShowError("Error retrieving assets", ex.ToString());
|
||||
OfficialAssetsProgress.Visible = false;
|
||||
OfficialAssetsButton.Visible = true;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyBetweenZips(string name, ZipFile source, ZipFile destination)
|
||||
{
|
||||
using (var stream = source.Entries.SingleOrDefault(f => f.FileName == name).OpenReader())
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
CopyStream(stream, ms);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
destination.AddEntry(name, ms);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyStream(Stream input, Stream output)
|
||||
{
|
||||
byte[] buffer = new byte[16*1024];
|
||||
int read;
|
||||
while((read = input.Read (buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
output.Write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadTexturePacks()
|
||||
{
|
||||
// We load the default texture pack specially.
|
||||
@ -145,10 +228,13 @@ namespace TrueCraft.Launcher.Views
|
||||
Directory.CreateDirectory(TexturePack.TexturePackPath);
|
||||
|
||||
var zips = Directory.EnumerateFiles(TexturePack.TexturePackPath);
|
||||
bool officialPresent = false;
|
||||
foreach (var zip in zips)
|
||||
{
|
||||
if (!zip.EndsWith(".zip"))
|
||||
continue;
|
||||
if (Path.GetFileName(zip) == "Minecraft.zip")
|
||||
officialPresent = true;
|
||||
|
||||
var texturePack = TexturePack.FromArchive(zip);
|
||||
if (texturePack != null)
|
||||
@ -157,6 +243,8 @@ namespace TrueCraft.Launcher.Views
|
||||
AddTexturePackRow(texturePack);
|
||||
}
|
||||
}
|
||||
if (!officialPresent)
|
||||
OfficialAssetsButton.Visible = true;
|
||||
}
|
||||
|
||||
private void AddTexturePackRow(TexturePack pack)
|
||||
|
Loading…
x
Reference in New Issue
Block a user