diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj
index 60a4a6e0a..ff326faf3 100644
--- a/ClassicalSharp/ClassicalSharp.csproj
+++ b/ClassicalSharp/ClassicalSharp.csproj
@@ -148,6 +148,7 @@
+
@@ -155,7 +156,6 @@
-
diff --git a/ClassicalSharp/Entities/Player.Shadows.cs b/ClassicalSharp/Entities/Components/ShadowComponent.cs
similarity index 87%
rename from ClassicalSharp/Entities/Player.Shadows.cs
rename to ClassicalSharp/Entities/Components/ShadowComponent.cs
index 8cef05c4c..6ad571f62 100644
--- a/ClassicalSharp/Entities/Player.Shadows.cs
+++ b/ClassicalSharp/Entities/Components/ShadowComponent.cs
@@ -5,11 +5,19 @@ using OpenTK;
namespace ClassicalSharp {
- partial class Player {
+ /// Entity component that draws square and circle shadows beneath entities.
+ public unsafe sealed class ShadowComponent {
- internal static bool boundShadowTex = false;
+ Game game;
+ Entity entity;
+ public ShadowComponent( Game game, Entity entity ) {
+ this.game = game;
+ this.entity = entity;
+ }
- internal unsafe void DrawShadow( EntityShadow mode ) {
+ internal void Draw() {
+ EntityShadow mode = game.Players.ShadowMode;
+ Vector3 Position = entity.Position;
float posX = Position.X, posZ = Position.Z;
int posY = Math.Min( (int)Position.Y, game.Map.Height - 1 );
int index = 0, vb = 0;
@@ -49,7 +57,7 @@ namespace ClassicalSharp {
}
if( index == 0 ) return;
- CheckShadowTexture();
+ CheckShadowTexture( game.Graphics );
if( !boundShadowTex ) {
game.Graphics.BindTexture( shadowTex );
@@ -58,11 +66,12 @@ namespace ClassicalSharp {
game.Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, verts, index, index * 6 / 4 );
}
- unsafe bool CalculateShadow( Vector3I* coords, ref int coordsCount, float x, float z, int posY, ref ShadowData data ) {
+ bool CalculateShadow( Vector3I* coords, ref int coordsCount, float x, float z, int posY, ref ShadowData data ) {
data = new ShadowData();
int blockX = Utils.Floor( x ), blockZ = Utils.Floor( z );
Vector3I p = new Vector3I( blockX, 0, blockZ );
BlockInfo info = game.BlockInfo;
+ Vector3 Position = entity.Position;
if( Position.Y < 0 ) return false;
for( int i = 0; i < 4; i++ )
@@ -96,26 +105,7 @@ namespace ClassicalSharp {
return game.Map.GetBlock( x, y, z );
}
- int shadowTex = -1;
- unsafe void CheckShadowTexture() {
- if( shadowTex != -1 ) return;
- const int size = 128, half = size / 2;
- using( Bitmap bmp = new Bitmap( size, size ) )
- using( FastBitmap fastBmp = new FastBitmap( bmp, true, false ) )
- {
- int inPix = new FastColour( 0, 0, 0, 200 ).ToArgb();
- int outPix = inPix & 0xFFFFFF;
- for( int y = 0; y < fastBmp.Height; y++ ) {
- int* row = fastBmp.GetRowPtr( y );
- for( int x = 0; x < fastBmp.Width; x++ ) {
- double dist = (half - (x + 0.5)) * (half - (x + 0.5)) +
- (half - (y + 0.5)) * (half - (y + 0.5));
- row[x] = dist < half * half ? inPix : outPix;
- }
- }
- shadowTex = game.Graphics.CreateTexture( fastBmp );
- }
- }
+
void DraqSquareShadow( VertexPos3fTex2fCol4b[] verts, ref int index, float y, byte alpha, float x, float z ) {
FastColour col = FastColour.White; col.A = alpha;
@@ -163,5 +153,28 @@ namespace ClassicalSharp {
static bool lequal(float a, float b) {
return a < b || Math.Abs(a - b) < 0.001f;
}
+
+
+ internal static bool boundShadowTex = false;
+ internal static int shadowTex = -1;
+ static void CheckShadowTexture( IGraphicsApi graphics ) {
+ if( shadowTex != -1 ) return;
+ const int size = 128, half = size / 2;
+ using( Bitmap bmp = new Bitmap( size, size ) )
+ using( FastBitmap fastBmp = new FastBitmap( bmp, true, false ) )
+ {
+ int inPix = new FastColour( 0, 0, 0, 200 ).ToArgb();
+ int outPix = inPix & 0xFFFFFF;
+ for( int y = 0; y < fastBmp.Height; y++ ) {
+ int* row = fastBmp.GetRowPtr( y );
+ for( int x = 0; x < fastBmp.Width; x++ ) {
+ double dist = (half - (x + 0.5)) * (half - (x + 0.5)) +
+ (half - (y + 0.5)) * (half - (y + 0.5));
+ row[x] = dist < half * half ? inPix : outPix;
+ }
+ }
+ shadowTex = graphics.CreateTexture( fastBmp );
+ }
+ }
}
}
\ No newline at end of file
diff --git a/ClassicalSharp/Entities/EntityList.cs b/ClassicalSharp/Entities/EntityList.cs
index 12b0c5cce..cc81f6b8c 100644
--- a/ClassicalSharp/Entities/EntityList.cs
+++ b/ClassicalSharp/Entities/EntityList.cs
@@ -142,12 +142,12 @@ namespace ClassicalSharp {
public void DrawShadows() {
if( ShadowMode == EntityShadow.None ) return;
- Player.boundShadowTex = false;
+ ShadowComponent.boundShadowTex = false;
game.Graphics.AlphaArgBlend = true;
game.Graphics.DepthWrite = false;
game.Graphics.AlphaBlending = true;
- Players[255].DrawShadow( ShadowMode );
+ Players[255].shadow.Draw();
if( ShadowMode == EntityShadow.CircleAll )
DrawOtherShadows();
game.Graphics.AlphaArgBlend = false;
@@ -158,7 +158,7 @@ namespace ClassicalSharp {
void DrawOtherShadows() {
for( int i = 0; i < 255; i++) {
if( Players[i] == null ) continue;
- Players[i].DrawShadow( ShadowMode );
+ Players[i].shadow.Draw();
}
}
}
diff --git a/ClassicalSharp/Entities/Player.cs b/ClassicalSharp/Entities/Player.cs
index df0fb293b..11b149bab 100644
--- a/ClassicalSharp/Entities/Player.cs
+++ b/ClassicalSharp/Entities/Player.cs
@@ -15,12 +15,14 @@ namespace ClassicalSharp {
public string DisplayName, SkinName, SkinIdentifier;
public SkinType SkinType;
internal AnimatedComponent anim;
+ internal ShadowComponent shadow;
public Player( Game game ) : base( game ) {
this.game = game;
StepSize = 0.5f;
SkinType = game.DefaultPlayerSkinType;
anim = new AnimatedComponent( game, this );
+ shadow = new ShadowComponent( game, this );
SetModel( "humanoid" );
}
@@ -38,8 +40,6 @@ namespace ClassicalSharp {
public override void Despawn() {
game.Graphics.DeleteTexture( ref PlayerTextureId );
game.Graphics.DeleteTexture( ref nameTex.ID );
- if( shadowTex != -1 )
- game.Graphics.DeleteTexture( ref shadowTex );
}
protected void InitRenderingData() {
diff --git a/ClassicalSharp/Map/Formats/MapCw.Importer.cs b/ClassicalSharp/Map/Formats/MapCw.Importer.cs
index 58325492f..2fabc1915 100644
--- a/ClassicalSharp/Map/Formats/MapCw.Importer.cs
+++ b/ClassicalSharp/Map/Formats/MapCw.Importer.cs
@@ -162,6 +162,10 @@ namespace ClassicalSharp {
info.InitLightOffsets();
game.Events.RaiseBlockDefinitionChanged();
info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F));
+
+ game.Inventory.CanPlace.SetNotOverridable( true, id );
+ game.Inventory.CanDelete.SetNotOverridable( true, id );
+ game.Events.RaiseBlockPermissionsChanged();
}
}
}
\ No newline at end of file
diff --git a/Launcher2/Gui/Screens/UpdatesScreen.cs b/Launcher2/Gui/Screens/UpdatesScreen.cs
index 11f8e8667..78129e1eb 100644
--- a/Launcher2/Gui/Screens/UpdatesScreen.cs
+++ b/Launcher2/Gui/Screens/UpdatesScreen.cs
@@ -124,6 +124,7 @@ namespace Launcher {
string path = dx ? build.DirectXPath : build.OpenGLPath;
Utils.LogDebug( "Updating to: " + path );
+ Patcher.PatchTime = build.TimeBuilt;
Patcher.Update( path );
game.ShouldExit = true;
game.ShouldUpdate = true;
diff --git a/Launcher2/Updater/Patcher.cs b/Launcher2/Updater/Patcher.cs
index 85fa78fcd..287868565 100644
--- a/Launcher2/Updater/Patcher.cs
+++ b/Launcher2/Updater/Patcher.cs
@@ -4,12 +4,15 @@ using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
+using ClassicalSharp;
using ClassicalSharp.TexturePack;
namespace Launcher.Updater {
public static class Patcher {
+ public static DateTime PatchTime;
+
public static void Update( string dir ) {
using( WebClient client = new WebClient() ) {
byte[] zipData = client.DownloadData( UpdateCheckTask.UpdatesUri + dir );
@@ -25,9 +28,9 @@ namespace Launcher.Updater {
info = new ProcessStartInfo( "cmd.exe", "/c update.bat" );
} else {
string path = Path.Combine( Program.AppDirectory, "update.sh" );
- File.WriteAllText( path, Scripts.BashFile.Replace( "\r\n", "\n" ) );
+ File.WriteAllText( path, Scripts.BashFile.Replace( "\r\n", "\n" ) );
const int flags = 0x7;// read | write | executable
- int code = chmod( path, (flags << 6) | (flags << 3) | 4 );
+ int code = chmod( path, (flags << 6) | (flags << 3) | 4 );
if( code != 0 )
throw new InvalidOperationException( "chmod returned : " + code );
info = new ProcessStartInfo( "xterm", '"' + path + '"');
@@ -50,11 +53,19 @@ namespace Launcher.Updater {
reader.Extract( stream );
}
}
-
+
static void ProcessZipEntry( string filename, byte[] data, ZipEntry entry ) {
string path = Path.Combine( Program.AppDirectory, "CS_Update" );
path = Path.Combine( path, Path.GetFileName( filename ) );
File.WriteAllBytes( path, data );
+
+ try {
+ File.SetLastWriteTimeUtc( path, PatchTime );
+ } catch( IOException ex ) {
+ ErrorHandler.LogError( "I/O exception when trying to set modified time for: " + filename, ex );
+ } catch( UnauthorizedAccessException ex ) {
+ ErrorHandler.LogError( "Permissions exception when trying to set modified time for: " + filename, ex );
+ }
}
}
}