public static string GetSteamIdFromConfig(string userName) { dynamic steamId = null; try { string steamPath = new IniFile(SAMSettings.FILE_NAME).Read(SAMSettings.STEAM_PATH, SAMSettings.SECTION_STEAM); // Attempt to find Steam Id from steam config. dynamic config = VdfConvert.Deserialize(File.ReadAllText(steamPath + "config\\config.vdf")); dynamic accounts = config.Value.Software.Valve.Steam.Accounts; VObject accountsObj = accounts; VToken value; accountsObj.TryGetValue(userName, out value); dynamic user = value; VValue userId = user.SteamID; steamId = userId.Value.ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(Convert.ToString(steamId)); }
private static IObservable <IInstall> FindSteamInstall() { return(Observable .Create <SteamInstall>(obs => { var steamDirectory = "C:/Program Files (x86)/Steam"; if (!Directory.Exists(steamDirectory)) { throw new Exception("Unable to find steam install"); } // Find all game libraries steam knows about. var libraryFoldersVdfPath = "C:/Program Files (x86)/Steam/steamapps/libraryfolders.vdf"; var allLibraryFolders = new List <string> { steamDirectory }; if (File.Exists(libraryFoldersVdfPath)) { var libraries = VdfConvert.Deserialize(File.ReadAllText(libraryFoldersVdfPath)); if (libraries.Key == "LibraryFolders") { foreach (var item in libraries.Value.Where(v => v.Type == VTokenType.Property)) { var prop = item as VProperty; var value = prop.Value as VValue; if (Directory.Exists(value.Value as string)) { allLibraryFolders.Add(value.Value as string); } } } } // Check for SMNCs APPID folder in all the linstall directories foreach (var library in allLibraryFolders) { var steamapps = Path.Combine(library, "steamapps"); foreach (var file in Directory.GetFiles(steamapps, "*.acf")) { dynamic acf = VdfConvert.Deserialize(File.ReadAllText(file)); VValue appid = acf.Value.appid; if (appid.Value as string == "104700") { VValue installdir = acf.Value.installdir; obs.OnNext(new SteamInstall(Path.Combine(steamapps, "common", installdir.Value as string))); obs.OnCompleted(); return Disposable.Empty; } } } obs.OnError(new DirectoryNotFoundException("Unable to find a steam install of SMNC")); return Disposable.Empty; })); }
private VObject ReadObject(VdfReader reader) { VObject result = new VObject(); if (!reader.ReadToken()) { throw new VdfException("Incomplete VDF data."); } while (!(reader.CurrentState == VdfReader.State.Object && reader.Value == VdfStructure.ObjectEnd.ToString())) { if (reader.CurrentState == VdfReader.State.Comment) { result.Add(VValue.CreateComment(reader.Value)); } else { result.Add(ReadProperty(reader)); } if (!reader.ReadToken()) { throw new VdfException("Incomplete VDF data."); } } return(result); }
public void DeepEqualsSucceedsCorrectly() { VValue val1 = new VValue("value1"); VValue val2 = new VValue("value1"); Assert.True(VToken.DeepEquals(val1, val2)); }
public void CommentsDeserializeCorrectly() { const string vdf = @" // Comment type A (at the start of the file) ""root"" { // Comment type B (as a child to an object) key1 ""value1"" ""key2"" // Comment type C (to the right of a property name) { ""key3"" ""value3"" // Comment type D (to the right of a property value) } } // Comment type E (at the end of the file) "; VProperty result = VdfConvert.Deserialize(vdf); VProperty expected = new VProperty("root", new VObject { VValue.CreateComment(" Comment type B (as a child to an object)"), new VProperty("key1", new VValue("value1")), new VProperty("key2", new VObject { new VProperty("key3", new VValue("value3")), VValue.CreateComment(" Comment type D (to the right of a property value)"), }), }); Assert.True(VToken.DeepEquals(result, expected)); }
public override void WriteValue(VValue value) { AutoComplete(State.Value); _writer.Write(VdfStructure.Quote); WriteEscapedString(value.ToString()); _writer.Write(VdfStructure.Quote); }
public void DeepEqualsFailsCorrectly() { VValue val1 = new VValue("value1"); VValue val2 = new VValue("value2"); Assert.False(VToken.DeepEquals(val1, val2)); }
public TextureAxis(VValue axis) { Axis = new VValue(axis); // break down the string into its parts // format // "[0 1 0 0] 0.25" string axisString = Axis.ToString(); string[] delims = { "[", "] " }; string[] parts = axisString.Split(delims, StringSplitOptions.RemoveEmptyEntries); string[] xyz = parts[0].Split(' '); x = float.Parse(xyz[0]); y = float.Parse(xyz[1]); z = float.Parse(xyz[2]); translation = float.Parse(xyz[3]); totalScale = float.Parse(parts[1]); }
void SetColumnsAndRows() { _rows = VValue_MaxValue / VValue_InterValue; for (int i = Rows; i >= 0; i--) { VValue.Add(Convert.ToString(i * VValue_InterValue)); } }
static public VProperty InsertValueIntoMaterial <T>(dynamic Material, string parameter, T value) { VValue vvalue = new VValue(value); VProperty propertyToWrite = CaseInsensitiveParameterCheck(Material.Value, parameter); propertyToWrite.Value = vvalue; Material.Value.Add(propertyToWrite); return(RemoveProxiesWithOverridingMaterialParameters(Material, parameter)); }
static public VProperty InsertVector3IntoMaterial(dynamic Material, string parameter, float[] values) { VValue vvalue = new VValue("[" + string.Join(" ", values) + "]"); VProperty propertyToWrite = CaseInsensitiveParameterCheck(Material.Value, parameter); propertyToWrite.Value = vvalue; Material.Value.Add(propertyToWrite); return(RemoveProxiesWithOverridingMaterialParameters(Material, parameter)); }
public void DeepCloneWorksCorrectly() { VValue original = new VValue("value1"); VValue clone = original.DeepClone() as VValue; clone.Value = "value2"; Assert.True(original.Value.Equals("value1")); }
public void DeepCloneWorksCorrectly() { VObject original = new VObject { new VProperty("key1", new VValue("value1")), }; VObject clone = original.DeepClone() as VObject; clone["key1"] = new VValue("value2"); Assert.True(((VValue)original["key1"]).Value.Equals("value1")); }
public static async Task <dynamic> GetUserInfoFromConfigAndWebApi(string userName) { dynamic userJson = null; dynamic steamId = null; try { string steamPath = new IniFile("SAMSettings.ini").Read("Steam", "Settings"); // Attempt to find Steam Id from steam config. dynamic config = VdfConvert.Deserialize(File.ReadAllText(steamPath + "config\\config.vdf")); dynamic accounts = config.Value.Software.Valve.steam.Accounts; VObject accountsObj = accounts; VToken value; accountsObj.TryGetValue(userName, out value); dynamic user = value; VValue userId = user.SteamID; steamId = userId.Value.ToString(); } catch (Exception ex) { // Attempt to find Steam Id from web api. Uri vanityUri = new Uri("http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=" + apiKey + "&vanityurl=" + userName); using (WebClient client = new WebClient()) { string vanityJson = await client.DownloadStringTaskAsync(vanityUri); dynamic vanityValue = JValue.Parse(vanityJson); steamId = vanityValue.response.steamid; } } if (steamId != null) { using (WebClient client = new WebClient()) { userJson = await GetUserInfoFromWebApiBySteamId(Convert.ToString(steamId)); } } return(userJson); }
public Plane(VValue value) { // get the reference TreeValue = new VValue(value); string s = value.ToString(); string[] delims = { "(", ") ", ")" }; string[] points = s.Split(delims, StringSplitOptions.RemoveEmptyEntries); // each one of the points contains a 3 floats seperated by a space - seperate these bottomLeft = Array.ConvertAll(points[0].Split(' '), float.Parse); topLeft = Array.ConvertAll(points[1].Split(' '), float.Parse); topRight = Array.ConvertAll(points[2].Split(' '), float.Parse); }
internal static void EditVDF(SDVMMSettings Settings) { try { var files = Directory.GetFiles(Path.Combine(Settings.SteamFolder, "userdata"), "localconfig.vdf", SearchOption.AllDirectories).ToArray(); // find game settings int i = 0; for (i = 0; i < files.Length; i++) { // read file var fileText = File.ReadAllText(files[i]); if (fileText == null) { continue; } VdfSerializerSettings ste = new VdfSerializerSettings(); ste.UsesEscapeSequences = true; raw = VdfConvert.Deserialize(fileText, ste); VObject data = (VObject)raw.Value.Software.Valve.Steam.Apps; if (data.ContainsKey("413150")) { game = (VObject)raw.Value.Software.Valve.Steam.Apps["413150"]; break; } } // check fail conditions if (game == null) { MessageBox.Show(MainWindow.Translation.SDVInstalled, "error"); return; } if (game.ContainsKey("LaunchOptions")) { MessageBox.Show(MainWindow.Translation.LaunchOptionExist, "error"); return; } if (File.Exists(Path.Combine(files[i], "localconfig-sdvmm.vdf.bak"))) { MessageBox.Show(MainWindow.Translation.LaunchOptionApplied, "error"); return; } // kill steam foreach (var process in Process.GetProcessesByName("Steam")) { process.Kill(); } // apply launch options if (!File.Exists(Path.Combine(Path.GetDirectoryName(files[i]), "localconfig-sdvmm.vdf.bak"))) { File.Copy(files[i], Path.Combine(Path.GetDirectoryName(files[i]), "localconfig-sdvmm.vdf.bak")); } //VValue launchOptions = new VValue(@String.Join(""," ","\\\"",MainWindow.SDVMMSettings.GameFolder.Replace("\\","\\\\"),"\\\\" ,"StardewModdingAPI.exe","\\\" ", "%command%")); string path = Path.Combine(MainWindow.SDVMMSettings.GameFolder, "StardewModdingAPI.exe").Replace(@"\", @"\\"); VValue launchOptions = new VValue($" \\\"{path}\\\" %command%"); game.Add("LaunchOptions", launchOptions); File.WriteAllText(files[i], raw.ToString()); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "error"); } }
public object RunInterpreter(MethodDefinition methodDef) { Instruction instruction = methodDef.Body.Instructions[0]; while (instruction != null) { Code code = instruction.OpCode.Code; switch (code) { case Code.Nop: case Code.Volatile: case Code.Castclass: case Code.Readonly: break; case Code.Ldc_I4: { System.Console.WriteLine("instruction.Operand:" + instruction.Operand.GetType().Name); //将提供的 int32 值作为 int32 推送到计算堆栈上(短格式)。 VValue vValue = new VValue(); vValue.valueType = ValueType.TYPE_INT; vValue.IValue = (int)instruction.Operand; Push(vValue); } break; case Code.Ldc_I4_S: { System.Console.WriteLine("instruction.Operand:" + instruction.Operand.GetType().Name); //将提供的 int8 值作为 int32 推送到计算堆栈上(短格式)。 VValue vValue = new VValue(); vValue.valueType = ValueType.TYPE_INT; vValue.BValue = (SByte)instruction.Operand; Push(vValue); } break; case Code.Ldc_I4_0: case Code.Ldc_I4_1: case Code.Ldc_I4_2: case Code.Ldc_I4_3: case Code.Ldc_I4_4: case Code.Ldc_I4_5: case Code.Ldc_I4_6: case Code.Ldc_I4_7: case Code.Ldc_I4_8: { //将整数值 x 作为 int32 推送到计算堆栈上。 VValue vValue = new VValue(); vValue.valueType = ValueType.TYPE_INT; vValue.IValue = (int)(code - Code.Ldc_I4_0); Push(vValue); } break; case Code.Ldc_R4: { //将整数值 x 作为 int32 推送到计算堆栈上。 VValue vValue = new VValue(); vValue.valueType = ValueType.TYPE_FLOAT; vValue.FValue = (float)instruction.Operand; Push(vValue); } break; case Code.Stloc_S: { //从计算堆栈的顶部弹出当前值并将其存储在局部变量列表中的 index 处 VariableDefinition vardef = (VariableDefinition)instruction.Operand; localVar[vardef.Index] = Pop(); } break; case Code.Stloc_0: case Code.Stloc_1: case Code.Stloc_2: case Code.Stloc_3: { //从计算堆栈的顶部弹出当前值并将其存储到索引 x 处的局部变量列表中。 Byte idx = (Byte)(code - Code.Stloc_0); localVar[idx] = Pop(); } break; case Code.Add: { VValue v2 = (VValue)Pop(); VValue v1 = (VValue)Pop(); Push(v2 + v1); } break; case Code.Sub: { VValue v2 = (VValue)Pop(); VValue v1 = (VValue)Pop(); Push(v1 - v2); } break; case Code.Cgt: { //比较两个值。如果第一个值大于第二个值,则将整数值 1 (int32) 推送到计算堆栈上;反之,将 0 (int32) 推送到计算堆栈上。 VValue v2 = (VValue)Pop(); VValue v1 = (VValue)Pop(); bool res = v1 > v2; if (res) { Push(1); } else { Push(0); } } break; case Code.Beq: case Code.Beq_S: { //如果两个值相等,则将控制转移到目标指令(短格式)。 VValue v2 = (VValue)Pop(); VValue v1 = (VValue)Pop(); bool res = v1 == v2; if (res) { instruction = (Instruction)instruction.Operand; continue; } } break; case Code.Clt: { //比较两个值。如果第一个值大于第二个值,则将整数值 1 (int32) 推送到计算堆栈上;反之,将 0 (int32) 推送到计算堆栈上。 VValue v2 = (VValue)Pop(); VValue v1 = (VValue)Pop(); bool res = v1 < v2; if (res) { Push(1); } else { Push(0); } } break; case Code.Ldloc_S: { //将指定索引处的局部变量加载到计算堆栈上。 VariableDefinition vardef = (VariableDefinition)instruction.Operand; Push(localVar[vardef.Index]); } break; case Code.Ldloc_0: case Code.Ldloc_1: case Code.Ldloc_2: case Code.Ldloc_3: //将索引 0 处的局部变量加载到计算堆栈上 Push(localVar[code - Code.Ldloc_0]); break; case Code.Conv_I1: { Push(((VValue)Pop()).ChangeType(ValueType.TYPE_BYTE)); } break; case Code.Conv_I2: { Push(((VValue)Pop()).ChangeType(ValueType.TYPE_SHORT)); } break; case Code.Conv_I4: { Push(((VValue)Pop()).ChangeType(ValueType.TYPE_INT)); } break; case Code.Conv_I8: { Push(((VValue)Pop()).ChangeType(ValueType.TYPE_LONG)); } break; case Code.Conv_R4: { Push(((VValue)Pop()).ChangeType(ValueType.TYPE_FLOAT)); } break; case Code.Conv_R8: { Push(((VValue)Pop()).ChangeType(ValueType.TYPE_DOUBLE)); } break; case Code.Ldstr: //推送对元数据中存储的字符串的新对象引用。 Push(instruction.Operand); break; case Code.Br_S: { //无条件地将控制转移到目标指令(短格式)。 instruction = (Instruction)instruction.Operand; continue; } break; case Code.Brfalse: case Code.Brfalse_S: { int res = (int)Pop(); if (res == 0) { instruction = (Instruction)instruction.Operand; continue; } } break; case Code.Brtrue: case Code.Brtrue_S: { int res = (int)Pop(); if (res == 1) { instruction = (Instruction)instruction.Operand; continue; } } break; case Code.Ret: //从当前方法返回,并将返回值(如果存在)从调用方的计算堆栈推送到被调用方的计算堆栈上。 TypeReference returnType = methodDef.ReturnType; if (returnType.Name != Type.GetType("System.Void").Name) { return(Pop()); } break; case Code.Box: object o = Pop(); Push(o); break; case Code.Call: { MethodReference methodReference = (MethodReference)instruction.Operand; /* * MethodDefinition methDef; * methodDefDic.TryGetValue(methodReference.DeclaringType.FullName, out methDef); * if(methDef != null) * { * Execute * } */ #if true //方式一 直接通过制定参数查找 Type[] types = new Type[methodReference.Parameters.Count]; object[] values = new object[methodReference.Parameters.Count]; for (int i = methodReference.Parameters.Count - 1; i >= 0; i--) { values[i] = Pop(); types[i] = values[i].GetType(); } Type t = Type.GetType(methodReference.DeclaringType.FullName); var methodInfo = t.GetMethod(methodReference.Name, types); object res; if (methodInfo.IsStatic) { res = methodInfo.Invoke(null, values); } else { res = methodInfo.Invoke(t, values); } if (res != null) { Push(res); } #else //方式二, 遍历函数,通过参数对比 List <object> param = new List <object>(); for (int i = 0; i < methodReference.Parameters.Count; i++) { param.Add(Pop()); } foreach (var methodDef in t.GetMethods()) { if (methodDef.GetParameters().Length == methodReference.Parameters.Count && methodDef.Name == methodReference.Name && methodDef.GetParameters()[0].ParameterType == typeof(string)) { methodDef.Invoke(null, param.ToArray()); } } #endif //AppDomain.CurrentDomain.CreateInstance(a.FullName,Test2.Class1); } break; case Code.Newobj: { MethodReference methodReference = (MethodReference)instruction.Operand; //方式一 直接通过制定参数查找 Type[] types = new Type[methodReference.Parameters.Count]; object[] values = new object[methodReference.Parameters.Count]; for (int i = methodReference.Parameters.Count - 1; i >= 0; i--) { values[i] = Pop(); types[i] = values[i].GetType(); } Type t = Type.GetType(methodReference.DeclaringType.FullName); object inst = t.Assembly.CreateInstance(t.FullName); Push(inst); } break; case Code.Stfld: { object newData = Pop(); object obj = Pop(); FieldDefinition fieldDefinition = (FieldDefinition)instruction.Operand; FieldInfo fieldInfo = obj.GetType().GetField(fieldDefinition.Name); if (newData is VValue) { fieldInfo.SetValue(obj, ((VValue)newData).ToObject()); } else { fieldInfo.SetValue(obj, newData); } } break; case Code.Callvirt: { //对对象调用后期绑定方法,并且将返回值推送到计算堆栈上。 object obj = Pop(); MethodReference methodReference = (MethodReference)instruction.Operand; Type[] types = new Type[methodReference.Parameters.Count]; object[] values = new object[methodReference.Parameters.Count]; for (int i = methodReference.Parameters.Count - 1; i >= 0; i--) { values[i] = Pop(); types[i] = values[i].GetType(); } var methodInfo = obj.GetType().GetMethod(methodReference.Name, types); object res = methodInfo.Invoke(obj, values); if (res != null) { if (res is int) { VValue vValue = new VValue(); vValue.IValue = (int)res; vValue.valueType = ValueType.TYPE_INT; Push(vValue); } else if (res is float) { VValue vValue = new VValue(); vValue.FValue = (float)res; vValue.valueType = ValueType.TYPE_FLOAT; Push(vValue); } else if (res is long) { VValue vValue = new VValue(); vValue.LValue = (long)res; vValue.valueType = ValueType.TYPE_LONG; Push(vValue); } else if (res is SByte) { VValue vValue = new VValue(); vValue.BValue = (SByte)res; vValue.valueType = ValueType.TYPE_BYTE; Push(vValue); } else if (res is double) { VValue vValue = new VValue(); vValue.DValue = (double)res; vValue.valueType = ValueType.TYPE_DOUBLE; Push(vValue); } else { Push(res); } } } break; default: throw new NotSupportedException("Not supported opcode " + code); } instruction = instruction.Next; } return(null); }
public static JValue ToJson(this VValue val) { return(new JValue(val.Value)); }
public abstract void WriteValue(VValue value);