Skip to content

Commit

Permalink
Improved code quality, fixed memory leaks, added new feactures
Browse files Browse the repository at this point in the history
1) Code quality has been improved.
2) Some memory leaks has been fixed.
3) Updated WSE version to 4.7.7.
4) Update to .NET Framework v4.7.2.
  • Loading branch information
cuellius committed Mar 26, 2020
1 parent bb62c7b commit a5fc4e7
Show file tree
Hide file tree
Showing 68 changed files with 1,519 additions and 1,536 deletions.
28 changes: 28 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[*.cs]

# CA1060: Move pinvokes to native methods class
dotnet_diagnostic.CA1060.severity = none

# CA1806: Do not ignore method results
dotnet_diagnostic.CA1806.severity = none

# CA1822: Mark members as static
dotnet_diagnostic.CA1822.severity = none

# CA1031: Do not catch general exception types
dotnet_diagnostic.CA1031.severity = none

# CA1724: Type names should not match namespaces
dotnet_diagnostic.CA1724.severity = none

# CA1034: Nested types should not be visible
dotnet_diagnostic.CA1034.severity = none

# CA3075: Insecure DTD processing in XML
dotnet_diagnostic.CA3075.severity = none

# CA3075: Mark assemblies with NeutralResourcesLanguageAttribute
dotnet_diagnostic.CA1824.severity = none

# CA1303: Do not pass literals as localized parameters
dotnet_diagnostic.CA1303.severity = none
6 changes: 3 additions & 3 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
</configuration>
</configuration>
8 changes: 6 additions & 2 deletions Application.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
Expand Down Expand Up @@ -48,17 +49,20 @@ private void ApplicationStartup(object sender, StartupEventArgs e)
if (language == "Russian" || language == "English") Language = language;
}

public static string[] CommandLineArgs;
public static IList<string> CommandLineArgs { get; private set; }

public static string StartupPath => Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()?.Location);

private static string _language = "";
public static string Language
{
get => _language;
set
{
_language = value;
var newDict = new ResourceDictionary { Source = new Uri($"Languages/{value}.xaml", UriKind.Relative) };

var oldDict = (from d in Current.Resources.MergedDictionaries where d.Source != null && d.Source.OriginalString.StartsWith("Languages/") select d).First();
var oldDict = (from d in Current.Resources.MergedDictionaries where d.Source != null && d.Source.OriginalString.StartsWith("Languages/", StringComparison.OrdinalIgnoreCase) select d).First();

if (oldDict != null)
{
Expand Down
24 changes: 12 additions & 12 deletions Core/Animations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public static class Animations
{
public static string[] Initialize()
{
if(!File.Exists(Path.Combine(Common.InputPath, "actions.txt"))) return new string[0];
if(!File.Exists(Path.Combine(Common.InputPath, "actions.txt"))) return Array.Empty<string>();

var fId = new Win32FileReader(Path.Combine(Common.InputPath, "actions.txt"));
var n = Convert.ToInt32(fId.ReadLine());
var n = Convert.ToInt32(fId.ReadLine(), CultureInfo.GetCultureInfo(1033));
var aAnimations = new string[n];
for (int i = 0; i < n; i++)
{
Expand All @@ -22,7 +22,7 @@ public static string[] Initialize()

aAnimations[i] = animation.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];

var j = Convert.ToInt32(animation.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[3]);
var j = Convert.ToInt32(animation.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[3], CultureInfo.GetCultureInfo("en-US"));
while (j != 0)
{
fId.ReadLine();
Expand All @@ -38,16 +38,16 @@ public static string DecompileFlags(DWORD dwFlag)
{
var sbFlag = new StringBuilder(2048);
var dwAnimFlagsLength = dwFlag & 0xFF000000;
string[] strAnimFlags = { "acf_synch_with_horse", "acf_align_with_ground", "acf_enforce_lowerbody", "acf_enforce_rightside", "acf_enforce_all",
"acf_parallels_for_look_slope", "acf_lock_camera", "acf_displace_position", "acf_ignore_slope", "acf_thrust", "acf_right_cut",
string[] strAnimFlags = { "acf_synch_with_horse", "acf_align_with_ground", "acf_enforce_lowerbody", "acf_enforce_rightside", "acf_enforce_all",
"acf_lock_rotation", "acf_parallels_for_look_slope", "acf_lock_camera", "acf_displace_position", "acf_ignore_slope", "acf_thrust", "acf_right_cut",
"acf_left_cut", "acf_overswing", "acf_rot_vertical_bow", "acf_rot_vertical_sword" };
DWORD[] dwAnimFlags = { 0x00000001, 0x00000002, 0x00000100, 0x00000200, 0x00000400, 0x00001000, 0x00002000, 0x00004000, 0x00008000, 0x00010000,
DWORD[] dwAnimFlags = { 0x00000001, 0x00000002, 0x00000100, 0x00000200, 0x00000400, 0x00000800, 0x00001000, 0x00002000, 0x00004000, 0x00008000, 0x00010000,
0x00020000, 0x00040000, 0x00080000, 0x00100000, 0x00200000 };
if (dwAnimFlagsLength != 0)
{
dwAnimFlagsLength = dwAnimFlagsLength >> 24;
dwAnimFlagsLength >>= 24;
dwFlag ^= 0xFF000000;
sbFlag.AppendFormat("acf_anim_length({0})", dwAnimFlagsLength);
sbFlag.AppendFormat(CultureInfo.GetCultureInfo(1033), "acf_anim_length({0})", dwAnimFlagsLength);
}

for (int f = 0; f < dwAnimFlags.Length; f++)
Expand Down Expand Up @@ -116,7 +116,7 @@ public static string DecompileSequenceFlags(DWORD dwFlag)
{
var sbFlag = new StringBuilder(2048);
DWORD dwSequenceBlend = dwFlag & 0xFF;
if (dwSequenceBlend != 0) sbFlag.AppendFormat("arf_blend_in_{0}", dwSequenceBlend - 1);
if (dwSequenceBlend != 0) sbFlag.AppendFormat(CultureInfo.GetCultureInfo("en-US"), "arf_blend_in_{0}", dwSequenceBlend - 1);

string[] strAnimSequenceFlags = { "arf_make_walk_sound", "arf_make_custom_sound", "arf_two_handed_blade", "arf_lancer", "arf_stick_item_to_left_hand",
"arf_cyclic", "arf_use_walk_progress", "arf_use_stand_progress", "arf_use_inv_walk_progress" };
Expand Down Expand Up @@ -169,9 +169,9 @@ public static void Decompile()
var iActions = fActions.GetInt();
for (int a = 0; a < iActions; a++)
{
string strAnimId = fActions.GetWord();
DWORD dwAnimFlags = fActions.GetDWord();
DWORD dwMasterAnimFlags = fActions.GetDWord();
var strAnimId = fActions.GetWord();
var dwAnimFlags = fActions.GetDWord();
var dwMasterAnimFlags = fActions.GetDWord();
fSource.WriteLine(" [\"{0}\", {1}, {2},", strAnimId, DecompileFlags(dwAnimFlags), DecompileMasterFlags(dwMasterAnimFlags));
var iAnimSequences = fActions.GetInt();
for (int s = 0; s < iAnimSequences; s++)
Expand Down
9 changes: 5 additions & 4 deletions Core/Caribbean/Skins.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System;
using System.Globalization;
using System.IO;

namespace Decomp.Core.Caribbean
Expand All @@ -7,7 +8,7 @@ public static class Skins
{
public static string[] Initialize()
{
if (!File.Exists(Path.Combine(Common.InputPath, "skins.txt"))) return new string[0];
if (!File.Exists(Path.Combine(Common.InputPath, "skins.txt"))) return Array.Empty<string>();

var fId = new Text(Path.Combine(Common.InputPath, "skins.txt"));
fId.GetString();
Expand Down Expand Up @@ -180,8 +181,8 @@ public static void Decompile()
int ixParticleSystem1 = fSkins.GetInt(),
ixParticleSystem2 = fSkins.GetInt();
fSource.WriteLine(" {0}, {1},",
ixParticleSystem1 < Common.ParticleSystems.Length ? "psys_" + Common.ParticleSystems[ixParticleSystem1] : ixParticleSystem1.ToString(),
ixParticleSystem2 < Common.ParticleSystems.Length ? "psys_" + Common.ParticleSystems[ixParticleSystem2] : ixParticleSystem2.ToString());
ixParticleSystem1 < Common.ParticleSystems.Count ? "psys_" + Common.ParticleSystems[ixParticleSystem1] : ixParticleSystem1.ToString(CultureInfo.GetCultureInfo("en-US")),
ixParticleSystem2 < Common.ParticleSystems.Count ? "psys_" + Common.ParticleSystems[ixParticleSystem2] : ixParticleSystem2.ToString(CultureInfo.GetCultureInfo("en-US")));

var iConstraints = fSkins.GetInt();
fSource.Write(" [");
Expand Down
33 changes: 16 additions & 17 deletions Core/Caribbean/Troops.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -11,7 +12,7 @@ public static class Troops
{
public static string[] Initialize()
{
if (!File.Exists(Path.Combine(Common.InputPath, "troops.txt"))) return new string[0];
if (!File.Exists(Path.Combine(Common.InputPath, "troops.txt"))) return Array.Empty<string>();

var fId = new Text(Path.Combine(Common.InputPath, "troops.txt"));
fId.GetString();
Expand All @@ -31,31 +32,29 @@ public static string[] Initialize()
return aTroops;
}

public static string DecompileCharacterAttribute(DWORD dwAttribute)
public static string DecompileCharacterAttribute(DWORD dwAttribute) => dwAttribute switch
{
switch (dwAttribute)
{
case 0: return "ca_strength";
case 1: return "ca_agility";
case 2: return "ca_intelligence";
case 3: return "ca_charisma";
default: return dwAttribute.ToString();
}
}
0 => "ca_strength",
1 => "ca_agility",
2 => "ca_intelligence",
3 => "ca_charisma",
_ => dwAttribute.ToString(CultureInfo.GetCultureInfo("en-US")),
};


public static string GetScene(DWORD dwScene)
{
DWORD dwEntry = (dwScene & 0xFFFF0000) >> 16;
DWORD dwId = dwScene & 0xFFFF;
return dwId < Common.Scenes.Length ? $"scn_{Common.Scenes[dwId]}|entry({dwEntry})" : $"{dwId}|entry({dwEntry})";
return dwId < Common.Scenes.Count ? $"scn_{Common.Scenes[(int)dwId]}|entry({dwEntry})" : $"{dwId}|entry({dwEntry})";
}

public static string DecompileFlags(DWORD dwFlag)
{
var sbFlag = new StringBuilder(1024);

DWORD dwSkin = dwFlag & 0xF;
if (dwSkin > 0) sbFlag.Append(dwSkin < Common.Skins.Length ? "tf_" + Common.Skins[dwSkin] + "|" : $"{dwSkin}|");
if (dwSkin > 0) sbFlag.Append(dwSkin < Common.Skins.Count ? "tf_" + Common.Skins[(int)dwSkin] + "|" : $"{dwSkin}|");

if ((dwFlag & 0x7F00000) - 0x7F00000 == 0)
{
Expand Down Expand Up @@ -117,7 +116,7 @@ public static void Decompile()
fSource.WriteLine(Header.Standard);
fSource.WriteLine(Header.Troops);

for (int s = 0; s < Common.Skins.Length; s++) fSource.WriteLine("tf_" + Common.Skins[s] + " = " + s);
for (int s = 0; s < Common.Skins.Count; s++) fSource.WriteLine("tf_" + Common.Skins[s] + " = " + s);

fSource.WriteLine("\r\ntroops = [");

Expand All @@ -141,7 +140,7 @@ public static void Decompile()
fSource.Write(" {0},", fTroops.GetWord()); // reserved "0"

var iFaction = fTroops.GetInt();
if (iFaction > 0 && iFaction < Common.Factions.Length)
if (iFaction > 0 && iFaction < Common.Factions.Count)
fSource.WriteLine(" fac_{0},", Common.Factions[iFaction]);
else
fSource.WriteLine(" {0},", iFaction);
Expand Down Expand Up @@ -170,7 +169,7 @@ public static void Decompile()
}
fSource.WriteLine(" [{0}],", String.Join(",", itemList.Select(item =>
{
var u = item.Key < Common.Items.Length ? $"itm_{Common.Items[item.Key]}" : $"{item.Key}";
var u = item.Key < Common.Items.Count ? $"itm_{Common.Items[item.Key]}" : $"{item.Key}";
return item.Value <= 0 || item.Value >= aImods.Count ? u : $"({u}, {aImods[item.Value]})";
})));

Expand Down Expand Up @@ -200,7 +199,7 @@ public static void Decompile()
for (int q = 0; q < 8; q++)
{
DWORD dwKnow = 0xF & (dword >> (q << 2));
if (dwKnow != 0 && (x << 3) + q < Common.Skills.Length) strKnow.Append($"knows_{Common.Skills[(x << 3) + q]}_{dwKnow}|");
if (dwKnow != 0 && (x << 3) + q < Common.Skills.Count) strKnow.Append($"knows_{Common.Skills[(x << 3) + q]}_{dwKnow}|");
}
}
if (strKnow.Length == 0) strKnow.Append('0'); else strKnow.Length--;
Expand Down
Loading

0 comments on commit a5fc4e7

Please sign in to comment.