Skip to content

Commit 86aa846

Browse files
committed
1.1.0
1 parent a7d9f8a commit 86aa846

File tree

3 files changed

+93
-16
lines changed

3 files changed

+93
-16
lines changed

RA3.Tools.Test/Program.cs

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
using RA3.Tools;
2+
using Con = System.Console;
3+
24

35
var ra3 = new RA3Instance();
6+
7+
Con.WriteLine("[Profiles]");
48
foreach (var i in ra3.Profiles)
59
{
6-
Console.WriteLine(i);
10+
Con.WriteLine(i);
711
}
8-
Console.WriteLine(ra3.GetCurrentProfile());
12+
Con.WriteLine();
13+
14+
Con.WriteLine("[Current Profile]");
15+
Con.WriteLine(ra3.GetCurrentProfile());
16+
Con.WriteLine();
17+
18+
Con.WriteLine("[RA3 Path] " + RA3.Tools.Registry.GetRA3Path());
19+
Con.WriteLine("[Registry Status] " + RA3.Tools.Registry.Status);
20+
21+
RA3.Tools.Registry.SetLanguage(RA3.Tools.Registry.GetRA3Path(), "chinese_t");
922

10-
Console.WriteLine("RA3 Path: " + RA3.Tools.Registry.GetRA3Path());
11-
Console.WriteLine("Registry Status: " + RA3.Tools.Registry.Status);
12-
Console.ReadKey();
23+
Con.ReadKey();

RA3.Tools/RA3Instance.cs

+36-10
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,43 @@ namespace RA3.Tools
1010
{
1111
public class RA3Instance
1212
{
13+
/// <summary>
14+
/// Private pre-defined name of QuickLoader.
15+
/// </summary>
16+
/// TODO: Download to AppData automatically.
1317
private static readonly string _quickLoaderPath = "RA3.QuickLoader.exe";
14-
//
18+
19+
/// <summary>
20+
/// Game install folder.
21+
/// </summary>
1522
public string GamePath;
23+
24+
/// <summary>
25+
/// Parameter passes to game.
26+
/// </summary>
1627
public string LaunchParamter;
28+
29+
/// <summary>
30+
/// Whether to use RA3BarLauncher to launch game.
31+
/// </summary>
1732
public bool UseBarLauncher;
33+
34+
/// <summary>
35+
/// Avaliable profiles of game user.
36+
/// </summary>
1837
public List<string> Profiles
1938
{
2039
get { return GetProfilesList(); }
2140
}
22-
//
2341
public readonly ResourceFolder ModFolder = new ResourceFolder(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Red Alert 3", "Mods"));
2442
public readonly ResourceFolder ReplayFolder = new ResourceFolder(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Red Alert 3", "Replays"));
2543
public readonly ResourceFolder MapFolder = new ResourceFolder(Path.Combine(Environment.GetEnvironmentVariable("appdata"), "Red Alert 3", "Maps"));
2644
public readonly ResourceFolder ProfileFolder = new ResourceFolder(Path.Combine(Environment.GetEnvironmentVariable("appdata"), "Red Alert 3", "Profiles"));
45+
2746
/// <summary>
28-
/// 红警3进程实例
47+
/// Red-Alert 3 Game Instance.
2948
/// </summary>
30-
/// <param name="gamePath">游戏路径(可选,为空则从注册表读取)</param>
49+
/// <param name="gamePath">Game install folder. Will Read from Registry if empty.</param>
3150
public RA3Instance(string gamePath = "")
3251
{
3352
//Read GamePath
@@ -39,8 +58,8 @@ public RA3Instance(string gamePath = "")
3958
{
4059
GamePath = gamePath;
4160
}
42-
//Check RA3.QuickLoader
43-
if (File.Exists($".\\{_quickLoaderPath}"))
61+
//Check if RA3.QuickLoader is avaliable.
62+
if (File.Exists(Path.GetFullPath(_quickLoaderPath)))
4463
{
4564
UseBarLauncher = true;
4665
}
@@ -59,7 +78,7 @@ public bool IsRA3PathValid()
5978

6079
public bool IsRA3FileValid()
6180
{
62-
return false;
81+
throw new NotImplementedException();
6382
}
6483
#endregion
6584

@@ -82,7 +101,7 @@ public static void LaunchUsingSkudef(string executablePath, string skudefPath)
82101

83102
public void Register()
84103
{
85-
if (IsRA3PathValid() && IsRA3FileValid() && Registry.Status != Registry.RegistryStatus.Correct)
104+
if (IsRA3PathValid() && Registry.Status != Registry.RegistryStatus.Correct)
86105
{
87106
Registry.SetRA3Path(GamePath);
88107
Registry.EnableMapSync();
@@ -156,7 +175,11 @@ public void _GeneratePatchedParFile()
156175
#endregion
157176

158177
#region Profile Operations
159-
// Parse string encoded by EA similar to UTF-8 in directory.ini
178+
/// <summary>
179+
/// Parse string encoded by EA similar to UTF-8 in directory.ini
180+
/// </summary>
181+
/// <param name="s">string</param>
182+
/// <returns></returns>
160183
private string ParseDirectoryString(string s)
161184
{
162185
var bytes = new List<byte>();
@@ -177,7 +200,10 @@ private string ParseDirectoryString(string s)
177200
}
178201
return Encoding.Unicode.GetString(bytes.ToArray());
179202
}
180-
203+
/// <summary>
204+
/// Get list of avaliable profiles list.
205+
/// </summary>
206+
/// <returns>List of avaliable game profiles.</returns>
181207
private List<string> GetProfilesList()
182208
{
183209
var original = ParseDirectoryString(File.ReadAllLines($"{ProfileFolder.Path}\\directory.ini")[0]);

RA3.Tools/Registry.cs

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Win32;
2+
using System.IO;
23

34
namespace RA3.Tools
45
{
@@ -9,7 +10,8 @@ public enum RegistryStatus
910
Correct,
1011
NotExist,
1112
MissingPath,
12-
MissingMapSync
13+
MissingMapSync,
14+
MissingLanguage,
1315
}
1416

1517
public static RegistryStatus Status
@@ -34,6 +36,13 @@ private static RegistryStatus IsRegistryValid()
3436
{
3537
return RegistryStatus.MissingMapSync;
3638
}
39+
40+
using var viewUser = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default);
41+
using var languageRa3 = view32.OpenSubKey("Software\\Electronic Arts\\Electronic Arts\\Red Alert 3", writable: true);
42+
if (languageRa3 == null || languageRa3.GetValue("Language") == null)
43+
{
44+
return RegistryStatus.MissingLanguage;
45+
}
3746
return RegistryStatus.Correct;
3847
}
3948

@@ -57,6 +66,37 @@ public static void SetRA3Path(string path)
5766
ra3.SetValue("Install Dir", path, RegistryValueKind.String);
5867
}
5968

69+
/// <summary>
70+
///
71+
/// </summary>
72+
/// <param name="gamePath">Game install folder.</param>
73+
/// <param name="value">Language string.</param>
74+
/// <returns>true if succeed. false if failed (language not find in game folder).</returns>
75+
public static bool SetLanguage(string gamePath, string value)
76+
{
77+
try
78+
{
79+
// verify if v1.12 skudef file of this value exists.
80+
var isTargetSkudefExists = File.Exists(Path.Combine(gamePath, $"RA3_{value}_1.12.skudef"));
81+
var isTargetCsfExists = File.Exists(Path.Combine(gamePath, "Launcher", $"{value}.csf"));
82+
if (isTargetSkudefExists && isTargetCsfExists)
83+
{
84+
using var view32 = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default);
85+
using var ra3 = view32.OpenSubKey("Software\\Electronic Arts\\Electronic Arts\\Red Alert 3", writable: true);
86+
if (ra3 == null)
87+
{
88+
using var newRa3 = view32.CreateSubKey("Software\\Electronic Arts\\Electronic Arts\\Red Alert 3", writable: true);
89+
newRa3.SetValue("Language", value, RegistryValueKind.String);
90+
return true;
91+
}
92+
ra3.SetValue("Language", value, RegistryValueKind.String);
93+
return true;
94+
}
95+
}
96+
catch { }
97+
return false;
98+
}
99+
60100
public static void EnableMapSync()
61101
{
62102
using var view32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);

0 commit comments

Comments
 (0)