Skip to content

Commit

Permalink
Merge pull request #77 from x64dbg/more-hotloading
Browse files Browse the repository at this point in the history
More hotloading
  • Loading branch information
ZehMatt authored Jan 16, 2023
2 parents 5796a49 + ac2c64c commit 5357b16
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
13 changes: 12 additions & 1 deletion src/Dotx64Managed/Plugins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ static Guid SeededGuid(int seed)
random.Next(0, 0xffff), random.Next(0, 0xffff), random.Next(0, 0xffff)));
}

static uint FNV1a(string str)
{
uint hash = 0x811C9DC5;
foreach (var ch in Encoding.UTF8.GetBytes(str))
{
hash ^= (byte)ch;
hash *= 0x1000193;
}
return hash;
}

public static void GenerateProject(Plugin plugin)
{
var binaryPathX86 = Path.Combine(Utils.GetRootPath(), "x86", "plugins");
Expand Down Expand Up @@ -187,7 +198,7 @@ public static void GenerateProject(Plugin plugin)

projGen.Save(projectFilePath);

var guid = SeededGuid(plugin.Info.Name.GetHashCode()).ToString().ToUpper();
var guid = SeededGuid((int)FNV1a(plugin.Info.Name)).ToString().ToUpper();
var solutionText = $@"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
Expand Down
14 changes: 7 additions & 7 deletions src/Dotx64Managed/ProjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,21 @@ void AppendTextNode(string name, string innerText)
}

// Only write a new project file if the contents have changed
using (var ms = new MemoryStream())
using (var sw = new StringWriter())
{
doc.Save(ms);
var data = ms.ToArray();
doc.Save(sw);
var text = sw.ToString();
if (File.Exists(file))
{
var existingData = File.ReadAllBytes(file);
if (existingData != data)
var existingText = File.ReadAllText(file);
if (text != existingText)
{
File.WriteAllBytes(file, data);
File.WriteAllText(file, text);
}
}
else
{
File.WriteAllBytes(file, data);
File.WriteAllText(file, text);
}
}
}
Expand Down

0 comments on commit 5357b16

Please sign in to comment.