Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM module detected on pc with hostname containing special characters #1578

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Base/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,17 @@ public static string GetLastFolderName(this string path)
DirectoryInfo directoryInfo = new DirectoryInfo(path);
return directoryInfo.Name;
}

public static int GenerateSimpleHash(this string s, int maxint)
{
// Simple hash algorithm, folding on a string, summed 4 bytes at a time
long sum = 0, mul = 1;
for (int i = 0; i < s.Length; i++)
{
mul = (i % 4 == 0) ? 1 : mul * 256;
sum += (long)s[i] * mul;
}
return (int)(Math.Abs(sum) % maxint);
}
}
}
19 changes: 4 additions & 15 deletions MobiFlight/MidiBoard/MidiBoard.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using M;
using MobiFlight.Base;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -61,33 +62,21 @@ public bool HasMidiOutput


public MidiBoard(MidiInputDevice midiInput, MidiOutputDevice midiOutput, string name, MidiBoardDefinition def)
{
{
this.MidiInput = midiInput;
this.MidiOutput = midiOutput;
this.name = name;
// Two boards of the same type get a different postfix to their name in windows
this.serial = GenerateSerial(name, int.MaxValue).ToString();
this.serial = name.GenerateSimpleHash(int.MaxValue).ToString();
this.Definition = def;
if (def != null)
{
EncoderNeutral = def.EncoderNeutralPosition;
if (!string.IsNullOrEmpty(def.InitialLayer))
ActiveLayer = def.InitialLayer;
}
}
EncoderRightFast = EncoderNeutral + 3;
EncoderLeftFast = EncoderNeutral - 3;
}

private int GenerateSerial(string s, int maxint)
{
// Simple hash algorithm, folding on a string, summed 4 bytes at a time
long sum = 0, mul = 1;
for (int i = 0; i < s.Length; i++)
{
mul = (i % 4 == 0) ? 1 : mul * 256;
sum += (long)s[i] * mul;
}
return (int)(Math.Abs(sum) % maxint);
}

private void SendInputEvent(InputEventArgs inputEventArgs)
Expand Down
4 changes: 3 additions & 1 deletion SimConnectMSFS/SimConnectCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.InteropServices;
using HidSharp.Utility;
using Microsoft.FlightSimulator.SimConnect;
using MobiFlight.Base;

namespace MobiFlight.SimConnectMSFS
{
Expand Down Expand Up @@ -73,9 +74,10 @@ public SimConnectCache()
RESPONSE_OFFSET = 0
};

string hashMachineName = Environment.MachineName.GenerateSimpleHash(int.MaxValue).ToString();
WasmRuntimeClientData = new WasmModuleClientData()
{
NAME = $"Client_{Environment.MachineName}",
NAME = $"Client_{hashMachineName}",
AREA_SIMVAR_ID = SIMCONNECT_CLIENT_DATA_ID.RUNTIME_LVARS,
AREA_COMMAND_ID = SIMCONNECT_CLIENT_DATA_ID.RUNTIME_CMD,
AREA_RESPONSE_ID = SIMCONNECT_CLIENT_DATA_ID.RUNTIME_RESPONSE,
Expand Down