Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes and additions #5

Merged
merged 5 commits into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions WolvenKit.CR2W/CR2W/CR2WExport.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//using RED.CRC32;
//using RED.CRC32;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -138,14 +138,14 @@ public CR2WExportWrapper ParentChunk
public List<CR2WExportWrapper> VirtualChildrenChunks => cr2w.chunks.Where(_ => _.VirtualParentChunk == this).ToList();

/// <summary>
/// Playing with latin here, ab means toward, ab away from.
/// Playing with latin here, ad means toward, ab away from.
/// This is the directed-graph in-edge list :
/// CVariables, being CPtr or CHandle, which reference this chunk.
/// </summary>
public List<IChunkPtrAccessor> AdReferences;

/// <summary>
/// Playing with latin here, ab means toward, ab away from.
/// Playing with latin here, ad means toward, ab away from.
/// This is the directed-graph out-edge list :
/// CVariables, being CPtr or CHandle, which are referenced by this chunk.
/// </summary>
Expand Down
38 changes: 37 additions & 1 deletion WolvenKit.CR2W/CR2W/CR2WFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using RED.CRC32;
using RED.CRC32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -110,6 +110,22 @@ public CR2WFile(LoggerService logger=null)
#endregion

#region Supporting Functions
/// <summary>
/// Creates dictionary of chunks by it's REDNames.
/// </summary>
/// <param name="name_prefix">Includes only chunks with the same prefix in name (useful to filter by type). Leave empty to include all chunks.</param>
/// <returns>Dictionary[REDName] = CR2WExportWrapper</returns>
public Dictionary<string, CR2WExportWrapper> GetChunksMapByPrefix(string name_prefix)
{
Dictionary<string, CR2WExportWrapper> ret = new Dictionary<string, CR2WExportWrapper>();
foreach (var chunk in chunks)
{
if (string.IsNullOrEmpty(name_prefix) || chunk.REDName.StartsWith(name_prefix)) {
ret[chunk.REDName] = chunk;
}
}
return ret;
}
// Does not reindex /TODO
public CR2WExportWrapper CreateChunk(string type, int chunkindex=0, CR2WExportWrapper parent = null, CR2WExportWrapper virtualparent = null, CVariable cvar = null)
{
Expand Down Expand Up @@ -854,6 +870,26 @@ uint CalculateHeaderCRC32()
}
}

public void Write(CByteArray ba)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
Write(bw);
ba.Bytes = ms.ToArray();
}
}

public void Write(byte[] ba)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
Write(bw);
ba = ms.ToArray();
}
}

/// <summary>
/// How a REDEngine entity is to be serialized
/// </summary>
Expand Down
16 changes: 15 additions & 1 deletion WolvenKit.CR2W/Types/Generic/CHandle.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization;
Expand Down Expand Up @@ -124,10 +124,24 @@ public override void Write(BinaryWriter file)
file.Write(val);
}

/// <summary>
/// Sets new handle: string if depot path (must be "classname:path"), CR2WExportWrapper or chunkIndex if chunk handle
/// </summary>
public override CVariable SetValue(object val)
{
switch (val)
{
case string s:
string[] parts = s.Split(':');
this.ClassName = parts[0];
this.DepotPath = parts[1];
this.ChunkHandle = false;
SetIsSerialized();
break;
case CR2WExportWrapper wrapper:
SetValueInternal(wrapper.ChunkIndex + 1); // TODO check why +1 is needed
SetIsSerialized();
break;
case int o:
SetValueInternal(o);
break;
Expand Down
2 changes: 1 addition & 1 deletion WolvenKit/Forms/frmSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private void btSave_Click(object sender, EventArgs e)
RequestApplyTheme?.Invoke();
}

/// debug console enabling
// debug console enabling
try
{
//TODO:UPDATE
Expand Down