Skip to content

Commit

Permalink
Fix code regex, include packages manifest, and fix some other things
Browse files Browse the repository at this point in the history
  • Loading branch information
heinermann committed Aug 3, 2022
1 parent 5cd4209 commit 15e7eb0
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ValheimExportHelper.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32630.192
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ValheimExportHelper", "ValheimExportHelper\ValheimExportHelper.csproj", "{B007D18E-3042-4E49-90EE-3E822FC319A8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ValheimExportHelper", "ValheimExportHelper\ValheimExportHelper.csproj", "{B007D18E-3042-4E49-90EE-3E822FC319A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
4 changes: 1 addition & 3 deletions ValheimExportHelper/AddPostProcessingPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ public void DoPostExport(Ripper ripper)
{
Logger.Info(LogCategory.Plugin, "[ValheimExportHelper] Adding old PostProcessing package");

string postProcessingDir = Path.Join(ripper.Settings.AssetsPath, "PostProcessing");

using (var zip = new ZipArchive(new MemoryStream(Resource.PostProcessing)))
{
zip.ExtractToDirectory(postProcessingDir);
zip.ExtractToDirectory(ripper.Settings.AssetsPath);
}
}
}
Expand Down
28 changes: 17 additions & 11 deletions ValheimExportHelper/FixCodeFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,28 @@ private void FixSteamworks()
{
string basePath = Path.Join(MonoScriptDir, "assembly_steamworks", "Steamworks");

string callbackSourceFile = Path.Join(basePath, "Callback.cs");
if (File.Exists(callbackSourceFile))
{
string filename = Path.Join(basePath, "Callback.cs");
string file = File.ReadAllText(filename);

// Match the declaration of m_Func, capture the spacing for the brace, and match everything between it and its closing brace (non-greedy everything: [\s\S]+?)
file = Regex.Replace(file, @"event DispatchDelegate m_Func\n(\s+)\{[\s\S]+?^\1\}", "event DispatchDelegate m_Func;", RegexOptions.Multiline);
File.WriteAllText(filename, file);
string file = File.ReadAllText(callbackSourceFile);

// 1. event DispatchDelegate m_Func Match the declaration of m_Func
// 2. \r?\n Newline (both Windows and Linux)
// 3. (\s+)\{ Save the indentation for the brace into a capture group
// 4. [\s\S]+? Everything else (non-greedy, so it stops when it matches the next thing)
// 5. ^\1\} Closing brace with the same indentation as the opening brace
file = Regex.Replace(file, @"event DispatchDelegate m_Func\r?\n(\s+)\{[\s\S]+?^\1\}", "event DispatchDelegate m_Func;", RegexOptions.Multiline);
File.WriteAllText(callbackSourceFile, file);
}

string callResultSourceFile = Path.Join(basePath, "CallResult.cs");
if (File.Exists(callResultSourceFile))
{
string filename = Path.Join(basePath, "CallResult.cs");
string file = File.ReadAllText(filename);
string file = File.ReadAllText(callResultSourceFile);

// Match the declaration of m_Func, capture the spacing for the brace, and match everything between it and its closing brace (non-greedy everything: [\s\S]+?)
file = Regex.Replace(file, @"event APIDispatchDelegate m_Func\n(\s+)\{[\s\S]+?^\1\}", "event APIDispatchDelegate m_Func;", RegexOptions.Multiline);
File.WriteAllText(filename, file);
// Similar regex as above
file = Regex.Replace(file, @"event APIDispatchDelegate m_Func\r?\n(\s+)\{[\s\S]+?^\1\}", "event APIDispatchDelegate m_Func;", RegexOptions.Multiline);
File.WriteAllText(callResultSourceFile, file);
}
}

Expand Down
22 changes: 14 additions & 8 deletions ValheimExportHelper/FixUnityProjectSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ class FixUnityProjectSettings : IPostExporter
--- !u!129 &1";

private string ProjectSettingsFile { get; set; } = string.Empty;
private string ProjectPackagePath { get; set; } = string.Empty;

public void DoPostExport(Ripper ripper)
{
Logger.Info(LogCategory.Plugin, "[ValheimExportHelper] Fixing Unity project settings");

ProjectSettingsFile = Path.Join(ripper.Settings.ProjectSettingsPath, "ProjectSettings.asset");
ProjectPackagePath = Path.Join(ripper.Settings.ProjectRootPath, "Packages");

dynamic settings = ReadSettings(ripper);

//var serializer = new SerializerBuilder().Build();
//Logger.Warning(serializer.Serialize(settings));

dynamic settings = ReadSettings();
ApplySettingsChanges(settings);
WriteSettings(ripper, settings);
WriteSettings(settings);

RemoveCollabPackage();
}

private void RemoveCollabPackage()
{
Directory.CreateDirectory(ProjectPackagePath);
File.WriteAllBytes(Path.Join(ProjectPackagePath, "manifest.json"), Resource.manifest);
}

private void ApplySettingsChanges(dynamic settings)
Expand All @@ -44,7 +50,7 @@ private void ApplySettingsChanges(dynamic settings)
};
}

private dynamic ReadSettings(Ripper ripper)
private dynamic ReadSettings()
{
dynamic? yaml = null;
string? yamlText = null;
Expand Down Expand Up @@ -75,7 +81,7 @@ private dynamic ReadSettings(Ripper ripper)
return yaml;
}

private void WriteSettings(Ripper ripper, dynamic settings)
private void WriteSettings(dynamic settings)
{
var serializer = new SerializerBuilder().Build();
string result = serializer.Serialize(settings);
Expand Down
10 changes: 10 additions & 0 deletions ValheimExportHelper/Resource.Designer.cs

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

3 changes: 3 additions & 0 deletions ValheimExportHelper/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<data name="Editor" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\Editor.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="manifest" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\manifest.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="PostProcessing" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\PostProcessing.zip;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand Down
42 changes: 42 additions & 0 deletions ValheimExportHelper/Resources/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"dependencies": {
"com.unity.ide.rider": "2.0.7",
"com.unity.ide.visualstudio": "2.0.14",
"com.unity.ide.vscode": "1.2.5",
"com.unity.test-framework": "1.1.31",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.4.8",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
}

0 comments on commit 15e7eb0

Please sign in to comment.