Skip to content

Commit

Permalink
+ CR2WToYml: Optimization for big files
Browse files Browse the repository at this point in the history
  • Loading branch information
nikich340 committed Apr 30, 2022
1 parent 958f1cd commit 967e9e2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 60 deletions.
85 changes: 43 additions & 42 deletions WolvenKit/Forms/frmCR2WtoText.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 35 additions & 18 deletions WolvenKit/Forms/frmCR2WtoText.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.WindowsAPICodePack.Dialogs;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
Expand All @@ -11,7 +10,6 @@
using WolvenKit.Common.Model;
using WolvenKit.Common.Services;
using WolvenKit.CR2W;
using static WolvenKit.Forms.frmChunkProperties;
using MessageBoxButtons = System.Windows.Forms.MessageBoxButtons;
using MessageBoxIcon = System.Windows.Forms.MessageBoxIcon;

Expand Down Expand Up @@ -342,6 +340,11 @@ private void frmCR2WtoText_FormClosing(object sender, FormClosingEventArgs e)
else
e.Cancel = false;
}

private void frmCR2WtoText_Load(object sender, EventArgs e)
{

}
}
internal class StatusController
{
Expand Down Expand Up @@ -708,6 +711,7 @@ internal class LoggerCR2W
private List<CR2WExportWrapper> Chunks { get; }
private List<CR2WEmbeddedWrapper> Embedded { get; }
private HashSet<string> wasDumped = new HashSet<string>();
private Dictionary<string, CR2WExportWrapper> chunkByREDName = new Dictionary<string, CR2WExportWrapper>();
private List<List<string>> mapInArray = new List<List<string>>();
private HashSet<string> enumTypes = new HashSet<string> { "EDrawableFlags", "ELightChannel", "EInterpMethodType", "EInterpCurveMode", "ECompareOp", "ESpaceFillMode", "EComboAttackResponse", "ECameraState", "ECameraShakeState", "ECameraShakeMagnitude", "EDismembermentEffectTypeFlag", "ETriggerChannel", "EDayPart", "EGameplayMimicMode", "EPlayerGameplayMimicMode", "ESoundGameState", "ESoundEventSaveBehavior", "EStaticCameraAnimState", "EStaticCameraGuiEffect", "ECharacterPowerStats", "ECharacterRegenStats", "EDirection", "EDirectionZ", "EMoonState", "EWeatherEffect", "EScriptedEventCategory", "EScriptedEventType", "EInputDeviceType", "EncumbranceBoyMode", "EActorImmortalityMode", "EActorImmortalityChanel", "ETerrainType", "EAreaName", "EDlcAreaName", "EZoneName", "EHitReactionType", "EFocusHitReaction", "EAttackSwingType", "EAttackSwingDirection",
"EManageGravity", "ECounterAttackSwitch", "EAttitudeGroupPriority", "ETimescaleSource", "EMonsterCategory", "EButtonStage", "EStaminaActionType", "EFocusModeSoundEffectType", "EStatistic", "EAchievement", "ETutorialHintDurationType", "ETutorialHintPositionType", "ESpeedType", "EBloodType", "EStatOwner", "ETestSubject", "ETargetName", "EMonsterTactic", "EOperator", "ESpawnPositionPattern", "ESpawnRotation", "EFlyingCheck", "ECriticalEffectCounterType", "EFairytaleWitchAction", "EActionInfoType", "EBossAction", "EBossSpecialAttacks", "EEredinPhaseChangeAction", "ESpawnCondition", "ENPCCollisionStance", "ENPCBaseType", "EGuardState", "ENPCType", "EChosenTarget", "ETeleportType", "ECameraAnimPriority", "ECameraBlendSpeedMode", "EMerchantMapPinType", "EScriptedDetroyableComponentState", "EFoodGroup", "EClimbProbeUsed", "ESideSelected", "EPlayerCollisionStance", "EMovementCorrectionType", "EGameplayContextInput", "EExplorationStateType",
Expand Down Expand Up @@ -744,7 +748,23 @@ internal LoggerCR2W(CR2WFile cr2wFile, string filePath,
Options = options;
if (Options.LocalizeStrings)
CR2W.LocalizedStringSource = MainController.Get();

setupYmlMapCases();
foreach (var chunk in Chunks)
{
try
{
chunkByREDName.Add(chunk.REDName, chunk);
}
catch (ArgumentNullException)
{
Console.WriteLine("processCR2W::Null chunk!");
}
catch (ArgumentException)
{
Console.WriteLine("processCR2W::Already existing chunk name!");
}
}
}
private void setupYmlMapCases()
{
Expand Down Expand Up @@ -788,11 +808,12 @@ public void processCR2W(int overrideLevel = 0)
ProcessEmbedded(level);
}
Writer.Write("Chunks:", level);

foreach (var chunk in Chunks)
{
var dumpYml = Options.DumpYML && !wasDumped.Contains(chunk.REDName);
wasDumped.Add(chunk.REDName);
var dumpYml = Options.DumpYML && chunkByREDName.ContainsKey(chunk.REDName);
chunkByREDName.Remove(chunk.REDName);

//var node = GetNodes(chunk);
if (Options.DumpTXT)
{
Expand Down Expand Up @@ -1380,14 +1401,10 @@ private void ProcessNodeYml(IEditableVariable node, int level, bool isArrayEleme
/* CHUNK-REFERENCE TYPE (ptr, handle) */
if (value.Contains("#") && !isMeArray)
{
bool chunkFound = false;
foreach (var chunk in Chunks)
if (chunkByREDName.ContainsKey(value))
{
if (wasDumped.Contains(chunk.REDName) || chunk.REDName != value)
continue;

chunkFound = true;
wasDumped.Add(chunk.REDName);
var chunk = chunkByREDName[value];
chunkByREDName.Remove(chunk.REDName);

if (!isArrayElement) // avoid "0" excess chunks
{
Expand All @@ -1413,10 +1430,7 @@ private void ProcessNodeYml(IEditableVariable node, int level, bool isArrayEleme
}
}
}

break;
}
if (!chunkFound)
} else
{
WriterYml.Write("#" + prepareName(node.REDName) + ": (looped reference) " + value, level);
}
Expand Down Expand Up @@ -1469,8 +1483,11 @@ private void ProcessNodeYml(IEditableVariable node, int level, bool isArrayEleme
}
else
{
WriterYml.Write(prepareName(node.REDName) + ": #" + node.REDType, level);
}
if (isMeArray && children.Count() < 1)
WriterYml.Write("# " + prepareName(node.REDName) + ": <null value> #" + node.REDType, level);
else
WriterYml.Write(prepareName(node.REDName) + ": #" + node.REDType, level);
}
}
} else
{ // chunk header - write type/name
Expand Down

0 comments on commit 967e9e2

Please sign in to comment.