Skip to content

Commit

Permalink
Merge pull request #1 from WolvenKit/master
Browse files Browse the repository at this point in the history
Sync/Update
  • Loading branch information
TarekJor authored Feb 8, 2021
2 parents 32e65f5 + 2b4a905 commit 85f8536
Show file tree
Hide file tree
Showing 14,775 changed files with 284,464 additions and 20,970 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 7 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
# CA1712: Do not prefix enum values with type name
dotnet_diagnostic.CA1712.severity = none

vc_generate_documentation_comments = xml
vc_generate_documentation_comments = xml

# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = none

# IDE0052: Remove unread private members
dotnet_diagnostic.IDE0052.severity = suggestion
12 changes: 3 additions & 9 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# These are supported funding model platforms
# We also welcome written motivational letters for our devs :D anyway thanks to anyone supporting this project in advance <3

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: traderain
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
ko_fi: traderain
custom: ['http://paypal.me/traderain']
17 changes: 6 additions & 11 deletions .github/workflows/Nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ jobs:
steps:
- name: Checkout github repo (+ download lfs dependencies)
uses: actions/checkout@v2
with:
lfs: true
- name: Checkout LFS objects
run: git lfs checkout
- name: Setup NuGet.exe for use with actions
- name: Setup Nuget.exe
uses: NuGet/[email protected]
with:
nuget-version: latest
Expand All @@ -29,15 +25,14 @@ jobs:
run: msbuild WolvenKit.sln -p:Configuration=Release -p:Platform=x64 -m
- name: Zip Release
run: |
cd $Env:GITHUB_WORKSPACE\\WolvenKit\bin
Compress-Archive -Path ./x64/Release/ -DestinationPath WolvenKit.zip
Compress-Archive -Path $Env:GITHUB_WORKSPACE\\WolvenKit\\bin\\Release\\net5.0-windows\\ -DestinationPath $Env:GITHUB_WORKSPACE\\WolvenKit.zip
- name: Deploy Nightly
uses: Maxzor/deploy-nightly@v1.0.4
uses: WebFreak001/deploy-nightly@v1.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: https://uploads.github.com/repos/Traderain/Wolven-kit/releases/11743470/assets{?name,label}
upload_url: https://uploads.github.com/repos/WolvenKit/Wolven-kit/releases/11743470/assets{?name,label}
release_id: 11743470
asset_path: WolvenKit\bin\WolvenKit.zip
asset_path: WolvenKit.zip
asset_name: WolvenKit-Nightly-$$.zip
asset_content_type: application/zip
asset_content_type: application/zip
4 changes: 0 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ jobs:
steps:
- name: Checkout github repo (+ download lfs dependencies)
uses: actions/checkout@v2
with:
lfs: true
- name: Checkout LFS objects
run: git lfs checkout
- name: Setup Nuget.exe
uses: NuGet/[email protected]
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ paket-files/
.idea/
*.sln.iml

#macOS
.DS_Store

# Ignore folders
W3Edit.Render/Models/**
!W3Edit.Render/Models/**
Expand All @@ -270,3 +273,4 @@ Wolven-kit.wiki
WolvenKit.IrrlichtLime/Debug-x64
WolvenKit.IrrlichtLime/Release-x64
Libs/Irrlicht.dll
WolvenKit.IrrlichtLime/Release-x86
176 changes: 176 additions & 0 deletions CP77.CR2W/Archive/Archive.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Catel.IoC;
using WolvenKit.Common.Services;
using CP77.CR2W.Extensions;
using CP77Tools.Model;
using Newtonsoft.Json;
using WolvenKit.Common;
using WolvenKit.Common.Extensions;
using CP77.CR2W.Types;
using WolvenKit.Common.Oodle;
using Index = CP77Tools.Model.Index;

namespace CP77.CR2W.Archive
{
public class Archive : IGameArchive
{
#region constructors

public Archive()
{
Header = new Header();
Index = new Index();
}

/// <summary>
/// Creates and reads an archive from a path
/// </summary>
/// <param name="path"></param>
public Archive(string path)
{
ArchiveAbsolutePath = path;

ReadTables();
}

#endregion

#region properties
public EArchiveType TypeName => EArchiveType.Archive;

public Header Header { get; set; }


public Index Index { get; set; }


public string ArchiveAbsolutePath { get; set; }

[JsonIgnore]
public Dictionary<ulong, FileEntry> Files => Index?.FileEntries;

public int FileCount => Files?.Count ?? 0;

[JsonIgnore]
public string Name => Path.GetFileName(ArchiveAbsolutePath);
#endregion

#region methods

/// <summary>
/// Reads the tables info to the archive.
/// </summary>
private void ReadTables()
{
//using var mmf = MemoryMappedFile.CreateFromFile(Filepath, FileMode.Open, Mmfhash, 0, MemoryMappedFileAccess.Read);

// using (var vs = mmf.CreateViewStream(0, ArHeader.SIZE, MemoryMappedFileAccess.Read))
// {
// _header = new ArHeader(new BinaryReader(vs));
// }

// using (var vs = mmf.CreateViewStream((long)_header.Tableoffset, (long)_header.Tablesize,
// MemoryMappedFileAccess.Read))
// {
// _table = new Index(new BinaryReader(vs), this);
// }

using var vs = new FileStream(ArchiveAbsolutePath, FileMode.Open, FileAccess.Read);
Header = new Header(new BinaryReader(vs));
vs.Seek((long) Header.IndexPosition, SeekOrigin.Begin);
Index = new Index(new BinaryReader(vs), this);
vs.Close();
}

/// <summary>
/// Serializes this archive to a redengine .archive file
/// </summary>
public void Serialize()
{




}


public bool CanUncook(ulong hash)
{
if (!Files.ContainsKey(hash))
return false;
var archiveItem = Files[hash];
string name = archiveItem.FileName;
var hasBuffers = (archiveItem.SegmentsEnd - archiveItem.SegmentsStart) > 1;

var values = Enum.GetNames(typeof(ECookedFileFormat));
var b = values.Any(e => e == Path.GetExtension(name)[1..]) || hasBuffers ;
return b;
}

public void CopyFileToStream(Stream stream, ulong hash, bool decompressBuffers)
{
if (!Files.ContainsKey(hash)) return;

var entry = Files[hash];
var startindex = (int)entry.SegmentsStart;
var nextindex = (int)entry.SegmentsEnd;

// decompress main file
CopyFileSegmentToStream(stream, this.Index.FileSegments[startindex], true);

// get buffers, optionally decompressing them
for (int j = startindex + 1; j < nextindex; j++)
{
var offsetentry = this.Index.FileSegments[j];
CopyFileSegmentToStream(stream, offsetentry, decompressBuffers);
}
}

/// <summary>
/// Extracts a FileSegment to a stream
/// </summary>
/// <param name="outstream"></param>
/// <param name="offsetentry"></param>
/// <param name="decompress"></param>
private void CopyFileSegmentToStream(Stream outstream, FileSegment offsetentry, bool decompress)
{
using var fs = new FileStream(ArchiveAbsolutePath, FileMode.Open, FileAccess.Read);
using var br = new BinaryReader(fs);
br.BaseStream.Seek((long)offsetentry.Offset, SeekOrigin.Begin);


var zSize = offsetentry.ZSize;
var size = offsetentry.Size;

if (!decompress)
{
var buffer = br.ReadBytes((int)zSize);
outstream.Write(buffer);
}
else
{
br.DecompressBuffer(outstream, zSize, size);
}
}


#endregion


}


}



Loading

0 comments on commit 85f8536

Please sign in to comment.