-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixed timestamp issue when extracting RFx files (thanks Cyrem!) - Added AI Data and Cornering data loading and saving - Added TRK track loading, track info display and track thumbnail - Optimized some code, bugfixes
- Loading branch information
1 parent
20e69b0
commit 9eec79f
Showing
21 changed files
with
1,231 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Security.Cryptography; | ||
|
||
/// <summary> | ||
/// A class for loading Embedded Assembly | ||
/// </summary> | ||
public class EmbeddedAssembly | ||
{ | ||
// Version 1.3 | ||
|
||
static Dictionary<string, Assembly> dic = null; | ||
|
||
/// <summary> | ||
/// Load Assembly, DLL from Embedded Resources into memory. | ||
/// </summary> | ||
/// <param name="embeddedResource">Embedded Resource string. Example: WindowsFormsApplication1.SomeTools.dll</param> | ||
/// <param name="fileName">File Name. Example: SomeTools.dll</param> | ||
public static void Load(string embeddedResource, string fileName) | ||
{ | ||
if (dic == null) | ||
dic = new Dictionary<string, Assembly>(); | ||
|
||
byte[] ba = null; | ||
Assembly asm = null; | ||
Assembly curAsm = Assembly.GetExecutingAssembly(); | ||
|
||
using (Stream stm = curAsm.GetManifestResourceStream(embeddedResource)) | ||
{ | ||
// Either the file is not existed or it is not mark as embedded resource | ||
if (stm == null) | ||
throw new Exception(embeddedResource + " is not found in Embedded Resources."); | ||
|
||
// Get byte[] from the file from embedded resource | ||
ba = new byte[(int)stm.Length]; | ||
stm.Read(ba, 0, (int)stm.Length); | ||
try | ||
{ | ||
asm = Assembly.Load(ba); | ||
|
||
// Add the assembly/dll into dictionary | ||
dic.Add(asm.FullName, asm); | ||
return; | ||
} | ||
catch | ||
{ | ||
// Purposely do nothing | ||
// Unmanaged dll or assembly cannot be loaded directly from byte[] | ||
// Let the process fall through for next part | ||
} | ||
} | ||
|
||
bool fileOk = false; | ||
string tempFile = ""; | ||
|
||
using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider()) | ||
{ | ||
// Get the hash value from embedded DLL/assembly | ||
string fileHash = BitConverter.ToString(sha1.ComputeHash(ba)).Replace("-", string.Empty); | ||
|
||
// Define the temporary storage location of the DLL/assembly | ||
tempFile = Path.GetTempPath() + fileName; | ||
|
||
// Determines whether the DLL/assembly is existed or not | ||
if (File.Exists(tempFile)) | ||
{ | ||
// Get the hash value of the existed file | ||
byte[] bb = File.ReadAllBytes(tempFile); | ||
string fileHash2 = BitConverter.ToString(sha1.ComputeHash(bb)).Replace("-", string.Empty); | ||
|
||
// Compare the existed DLL/assembly with the Embedded DLL/assembly | ||
if (fileHash == fileHash2) | ||
{ | ||
// Same file | ||
fileOk = true; | ||
} | ||
else | ||
{ | ||
// Not same | ||
fileOk = false; | ||
} | ||
} | ||
else | ||
{ | ||
// The DLL/assembly is not existed yet | ||
fileOk = false; | ||
} | ||
} | ||
|
||
// Create the file on disk | ||
if (!fileOk) | ||
{ | ||
System.IO.File.WriteAllBytes(tempFile, ba); | ||
} | ||
|
||
// Load it into memory | ||
asm = Assembly.LoadFile(tempFile); | ||
|
||
// Add the loaded DLL/assembly into dictionary | ||
dic.Add(asm.FullName, asm); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieve specific loaded DLL/assembly from memory | ||
/// </summary> | ||
/// <param name="assemblyFullName"></param> | ||
/// <returns></returns> | ||
public static Assembly Get(string assemblyFullName) | ||
{ | ||
if (dic == null || dic.Count == 0) | ||
return null; | ||
|
||
if (dic.ContainsKey(assemblyFullName)) | ||
return dic[assemblyFullName]; | ||
|
||
return null; | ||
|
||
// Don't throw Exception if the dictionary does not contain the requested assembly. | ||
// This is because the event of AssemblyResolve will be raised for every | ||
// Embedded Resources (such as pictures) of the projects. | ||
// Those resources wil not be loaded by this class and will not exist in dictionary. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SRtoolbox | ||
{ | ||
class AIData | ||
{ | ||
public AIFile load(string filename) | ||
{ | ||
AIFile ai = new AIFile(); | ||
|
||
FileStream file = File.Open(filename, FileMode.Open, FileAccess.Read); | ||
using (BinaryReader reader = new BinaryReader(file)) | ||
{ | ||
reader.ReadBytes(4); | ||
ai.RacingLine = reader.ReadUInt16(); | ||
ai.Braking = reader.ReadUInt16(); | ||
ai.Overtaking = reader.ReadUInt16(); | ||
ai.Speed = reader.ReadUInt16(); | ||
ai.Reflex = reader.ReadUInt16(); | ||
reader.ReadBytes(2); | ||
ai.Blocking = reader.ReadByte(); | ||
ai.CutsCorners = reader.ReadByte(); | ||
ai.Intelligence = reader.ReadByte(); | ||
ai.Craziness = reader.ReadByte(); | ||
} | ||
|
||
return ai; | ||
} | ||
|
||
public void save(string filename, AIFile ai) | ||
{ | ||
using (BinaryWriter writer = new BinaryWriter(File.Open(filename, FileMode.Create))) | ||
{ | ||
writer.Write(new byte[] { 0, 0, 0, 0 }); | ||
writer.Write(ai.RacingLine); | ||
writer.Write(ai.Braking); | ||
writer.Write(ai.Overtaking); | ||
writer.Write(ai.Speed); | ||
writer.Write(ai.Reflex); | ||
writer.Write(new byte[] { 0, 0 }); | ||
writer.Write(ai.Blocking); | ||
writer.Write(ai.CutsCorners); | ||
writer.Write(ai.Intelligence); | ||
writer.Write(ai.Craziness); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SRtoolbox | ||
{ | ||
class Cornering | ||
{ | ||
public CorneringFile load(string filename) | ||
{ | ||
CorneringFile cor = new CorneringFile(); | ||
|
||
FileStream file = File.Open(filename, FileMode.Open, FileAccess.Read); | ||
using (BinaryReader reader = new BinaryReader(file)) | ||
{ | ||
cor.Small = reader.ReadSingle(); | ||
cor.Big = reader.ReadSingle(); | ||
cor.SmallSmall_Same = reader.ReadSingle(); | ||
cor.SmallSmall_Opp = reader.ReadSingle(); | ||
cor.BigBig_Same = reader.ReadSingle(); | ||
cor.BigBig_Opp = reader.ReadSingle(); | ||
cor.BigSmall_Same = reader.ReadSingle(); | ||
cor.SmallBig_Same = reader.ReadSingle(); | ||
cor.BigSmall_Opp = reader.ReadSingle(); | ||
cor.SmallBig_Opp = reader.ReadSingle(); | ||
} | ||
|
||
return cor; | ||
} | ||
|
||
public void save(string filename, CorneringFile cor) | ||
{ | ||
using (BinaryWriter writer = new BinaryWriter(File.Open(filename, FileMode.Create))) | ||
{ | ||
writer.Write(cor.Small); | ||
writer.Write(cor.Big); | ||
writer.Write(cor.SmallSmall_Same); | ||
writer.Write(cor.SmallSmall_Opp); | ||
writer.Write(cor.BigBig_Same); | ||
writer.Write(cor.BigBig_Opp); | ||
writer.Write(cor.BigSmall_Same); | ||
writer.Write(cor.SmallBig_Same); | ||
writer.Write(cor.BigSmall_Opp); | ||
writer.Write(cor.SmallBig_Opp); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.