Skip to content

Commit

Permalink
Merge branch 'dev' into dev-work
Browse files Browse the repository at this point in the history
  • Loading branch information
Offline-R503B committed Jan 24, 2021
2 parents 2c2d4c4 + 988b7eb commit 4e55366
Show file tree
Hide file tree
Showing 44 changed files with 3,023 additions and 44 deletions.
16 changes: 10 additions & 6 deletions CP77.CR2W/Archive/Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

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

Expand All @@ -37,25 +37,27 @@ public Archive()
/// <param name="path"></param>
public Archive(string path)
{
Filepath = path;
ArchiveAbsolutePath = path;

ReadTables();
}

#endregion

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

public ArHeader Header { get; set; }
public ArTable Table { get; set; }
public string Filepath { get; set; }
public string ArchiveAbsolutePath { get; set; }

[JsonIgnore]
public Dictionary<ulong, ArchiveItem> Files => Table?.FileInfo;

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

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

#region methods
Expand All @@ -78,7 +80,7 @@ private void ReadTables()
// _table = new ArTable(new BinaryReader(vs), this);
// }

using var vs = new FileStream(Filepath, FileMode.Open, FileAccess.Read);
using var vs = new FileStream(ArchiveAbsolutePath, FileMode.Open, FileAccess.Read);
Header = new ArHeader(new BinaryReader(vs));
vs.Seek((long) Header.Tableoffset, SeekOrigin.Begin);
Table = new ArTable(new BinaryReader(vs), this);
Expand Down Expand Up @@ -146,7 +148,7 @@ byte[] ExtractFile(OffsetEntry offsetentry, bool decompress)
using var ms = new MemoryStream();
using var bw = new BinaryWriter(ms);

using var stream = new FileStream(Filepath, FileMode.Open, FileAccess.Read);
using var stream = new FileStream(ArchiveAbsolutePath, FileMode.Open, FileAccess.Read);
using var binaryReader = new BinaryReader(stream);
binaryReader.BaseStream.Seek((long) offsetentry.Offset, SeekOrigin.Begin);

Expand All @@ -171,6 +173,8 @@ byte[] ExtractFile(OffsetEntry offsetentry, bool decompress)


#endregion


}


Expand Down
8 changes: 3 additions & 5 deletions CP77.CR2W/Archive/ArchiveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ public class ArchiveItem : IGameFile
public string FileName => string.IsNullOrEmpty(_nameStr) ? $"{NameHash64}.bin" : _nameStr;
public string Extension => Path.GetExtension(FileName);

public IGameArchive Archive { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public IGameArchive Archive { get; set; }
public string Name { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public uint Size { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public uint ZSize { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public long PageOffset { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

public string CompressionType => throw new NotImplementedException();

private Archive _parentArchive;

public ArchiveItem(BinaryReader br, Archive parent)
public ArchiveItem(BinaryReader br, IGameArchive parent)
{
_parentArchive = parent;
Archive = parent;
var mainController = ServiceLocator.Default.ResolveType<IHashService>();

Read(br, mainController);
Expand Down
14 changes: 5 additions & 9 deletions CP77.CR2W/Archive/ArchiveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ namespace CP77.CR2W.Archive
{
public class ArchiveManager : CyberArchiveManager
{

public Dictionary<string, Archive> Archives { get; set; }

public static string SerializationVersion = "1.1";

public ArchiveManager()
{
}

public ArchiveManager(DirectoryInfo indir)
{
_parentDirectoryInfo = indir;
Expand All @@ -33,15 +34,10 @@ public ArchiveManager(DirectoryInfo indir)
Reload(indir);
}


public ArchiveManager()
{
}

private DirectoryInfo _parentDirectoryInfo;

#region properties

public Dictionary<string, Archive> Archives { get; set; }
public Dictionary<ulong, List<ArchiveItem>> Files { get; }
public Dictionary<string, List<ArchiveItem>> GroupedFiles =>

Expand Down
2 changes: 1 addition & 1 deletion CP77.CR2W/Modkit/Pack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static Archive.Archive Pack(DirectoryInfo infolder, DirectoryInfo outpath
var outfile = Path.Combine(outpath.FullName, $"basegame_{infolder.Name}.archive");
var ar = new Archive.Archive
{
Filepath = outfile,
ArchiveAbsolutePath = outfile,
Table = new ArTable()
};
using var fs = new FileStream(outfile, FileMode.Create);
Expand Down
12 changes: 3 additions & 9 deletions CP77.CR2W/Modkit/Uncook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,11 @@ public static int Uncook(CR2WFile cr2w, List<byte[]> buffers, ECookedFileFormat
{
var di = new FileInfo(infile.FullName).Directory;
TexconvWrapper.Convert(di.FullName, $"{newpath}", uncookext);
uncooksuccess = true;
}
catch (Exception e)
{
// silent
uncooksuccess = false;
}
}

Expand All @@ -275,12 +276,11 @@ public static int Uncook(CR2WFile cr2w, List<byte[]> buffers, ECookedFileFormat
using var nstream = new FileStream($"{newpath}", FileMode.Create, FileAccess.Write);
redcsv.ToCsvStream(nstream);


uncooksuccess = true;
break;
}
case ECookedFileFormat.json:
{

break;
}
case ECookedFileFormat.mlmask:
Expand All @@ -301,8 +301,6 @@ public static int Uncook(CR2WFile cr2w, List<byte[]> buffers, ECookedFileFormat
}
case ECookedFileFormat.cubemap:
{


if (!(cr2w.Chunks.FirstOrDefault()?.data is CCubeTexture ctex) ||
!(cr2w.Chunks[1]?.data is rendRenderTextureBlobPC blob))
return -1;
Expand Down Expand Up @@ -351,8 +349,6 @@ public static int Uncook(CR2WFile cr2w, List<byte[]> buffers, ECookedFileFormat
}
case ECookedFileFormat.envprobe:
{


if (!(cr2w.Chunks.FirstOrDefault()?.data is CReflectionProbeDataResource probe) ||
!(cr2w.Chunks[1]?.data is rendRenderTextureBlobPC blob))
return -1;
Expand Down Expand Up @@ -391,8 +387,6 @@ public static int Uncook(CR2WFile cr2w, List<byte[]> buffers, ECookedFileFormat
}
case ECookedFileFormat.texarray:
{


if (!(cr2w.Chunks.FirstOrDefault()?.data is CTextureArray texa) ||
!(cr2w.Chunks[1]?.data is rendRenderTextureBlobPC blob))
return -1;
Expand Down
1 change: 1 addition & 0 deletions CP77.CR2W/Types/cp77/animAnimNode_Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace CP77.CR2W.Types
public class animAnimNode_Base : ISerializable
{
[Ordinal(0)] [RED("id")] public CUInt32 Id { get; set; }
[Ordinal(1)] [RED("poseInfoLogger")] public animPoseInfoLogger PoseInfoLogger { get; set; }

public animAnimNode_Base(CR2WFile cr2w, CVariable parent, string name) : base(cr2w, parent, name) { }
}
Expand Down
1 change: 1 addition & 0 deletions CP77.CR2W/Types/cp77/animAnimNode_MathExpressionFloat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace CP77.CR2W.Types
public class animAnimNode_MathExpressionFloat : animAnimNode_FloatValue
{
[Ordinal(0)] [RED("expressionData")] public animMathExpressionNodeData ExpressionData { get; set; }
[Ordinal(1)] [RED("expressionString")] public CString ExpressionString { get; set; }

public animAnimNode_MathExpressionFloat(CR2WFile cr2w, CVariable parent, string name) : base(cr2w, parent, name) { }
}
Expand Down
3 changes: 3 additions & 0 deletions CP77.CR2W/Types/cp77/animAnimNode_OnePoseInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace CP77.CR2W.Types
public class animAnimNode_OnePoseInput : animAnimNode_Base
{
[Ordinal(0)] [RED("inputLink")] public animPoseLink InputLink { get; set; }
[Ordinal(1)] [RED("VisMask", 0, 0)] public CArray<animTransformIndex> VisMask { get; set; }
[Ordinal(2)] [RED("VisAxes", 0, 0)] public CBool VisAxes { get; set; }
[Ordinal(3)] [RED("VisNames", 0, 0)] public CBool VisNames { get; set; }

public animAnimNode_OnePoseInput(CR2WFile cr2w, CVariable parent, string name) : base(cr2w, parent, name) { }
}
Expand Down
2 changes: 2 additions & 0 deletions CP77.CR2W/Types/cp77/animAnimNode_StackTracksShrinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace CP77.CR2W.Types
public class animAnimNode_StackTracksShrinker : animAnimNode_OnePoseInput
{
[Ordinal(0)] [RED("tag")] public CName Tag { get; set; }
[Ordinal(1)] [RED("extenderNodeId")] public CUInt32 ExtenderNodeId { get; set; }


public animAnimNode_StackTracksShrinker(CR2WFile cr2w, CVariable parent, string name) : base(cr2w, parent, name) { }
}
Expand Down
12 changes: 12 additions & 0 deletions CP77.CR2W/WolvenKit.Cyberformats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Hambalkó Bence, Moritz Baron</Authors>
<Company>WolvenKit</Company>
<Description>File formats (Cyberpunk 2077) for the WolvenKit Mod Editor.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/WolvenKit/Wolven-kit</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/WolvenKit/Wolven-kit</RepositoryUrl>
<PackageTags>wolvenkit, cyberpunk2077</PackageTags>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.1.0</FileVersion>
<Version>1.0.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
51 changes: 51 additions & 0 deletions CP77.MSTests/ArchiveTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Catel.IoC;
using WolvenKit.Common.Services;
using CP77.CR2W;
using CP77.CR2W.Archive;
using CP77.CR2W.Resources;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using WolvenKit.Common;

namespace CP77.MSTests
{
[TestClass]
public class ArchiveTests : GameUnitTest
{
[TestMethod]
public void Test_Unbundle()
{

}

[TestMethod]
public void Test_Uncook()
{

}


private void test_archive(string extension = null)
{
var resultDir = Path.Combine(Environment.CurrentDirectory, TestResultsDirectory);
Directory.CreateDirectory(resultDir);

var success = true;

List<Archive> archives;



}
}
}
38 changes: 38 additions & 0 deletions CP77.MSTests/CP77.MSTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
<None Remove="appsettings.json" />
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CP77.CR2W\WolvenKit.Cyberformats.csproj" />
<ProjectReference Include="..\WolvenKit.Common\WolvenKit.Common.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="C:\Users\ghost\.nuget\packages\wolvenkit.common\1.0.0\contentFiles\any\net5.0-windows7.0\DDS\texconv.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="C:\Users\ghost\.nuget\packages\wolvenkit.cyberformats\1.0.0\contentFiles\any\net5.0-windows7.0\Resources\archivehashes.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
Loading

0 comments on commit 4e55366

Please sign in to comment.