Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Commit

Permalink
Quick-and-dirty fix for model loading in PAK files
Browse files Browse the repository at this point in the history
  • Loading branch information
LogicAndTrick committed Dec 22, 2013
1 parent 08e33fb commit 63b9b79
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions Sledge.DataStructures/Models/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void PreprocessModel()
/// </summary>
private void CombineTextures()
{
if (!Textures.Any()) return;
// Calculate the dimension of the combined texture
var width = 0;
var height = 0;
Expand Down
1 change: 1 addition & 0 deletions Sledge.FileSystem/PakFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ protected override void Dispose(bool disposing)
_stream.Dispose();
_package.Dispose();
HLLib.Shutdown();
_open = false;
}
base.Dispose(disposing);
}
Expand Down
9 changes: 6 additions & 3 deletions Sledge.Libs/HLLib/HLLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,13 @@ public byte[] Read(uint size)
return buffer;
}

public override void Close()
private bool _disposed = false;
protected override void Dispose(bool disposing)
{
if (!IsOpened) return;
if (_disposed || !IsOpened) return;
_disposed = true;
Close(StreamPtr);
base.Dispose(disposing);
}

public override long Seek(long offset, SeekOrigin origin)
Expand Down Expand Up @@ -902,7 +905,7 @@ public override long Length

public override long Position
{
get { return Pointer; }
get { return GetStreamPointer(StreamPtr); }
set { Seek(value, SeekMode.Beginning); }
}

Expand Down
6 changes: 4 additions & 2 deletions Sledge.Providers/Model/MdlProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override DataStructures.Models.Model LoadFromFile(IFile file)
// Model loader for MDL files. Reference Valve's studiohdr_t struct definition for the most part.
public DataStructures.Models.Model LoadMDL(IFile file, ModelLoadItems loadItems)
{
using (var fs = file.Open())
using (var fs = new MemoryStream(file.ReadAll()))
{
using(var br = new BinaryReader(fs))
{
Expand Down Expand Up @@ -341,8 +341,10 @@ private static void ReadTextureInfo(IFile file, BinaryReader br, ModelData data,
if (data.Version == MDLVersionGoldsource)
{
var tempBr = br;
var disp = false;
if (numTextures == 0)
{
disp = true;
var texFile = file.Parent.GetFile(file.NameWithoutExtension + "T." + file.Extension);
br = new BinaryReader(texFile.Open());
br.BaseStream.Position = 180; // skip all the unused nonsense in the T file
Expand Down Expand Up @@ -393,7 +395,7 @@ private static void ReadTextureInfo(IFile file, BinaryReader br, ModelData data,
br.BaseStream.Position = savedPosition;
}
//
if (numTextures == 0)
if (disp)
{
br.BaseStream.Dispose();
br.Dispose();
Expand Down

0 comments on commit 63b9b79

Please sign in to comment.