0

I found a problem on a game. The game has an already existing xml file, which is always forgets the changes I write to it, and stand back to a wrong version.
I want to make a .exe file, to simply click it, and the program overwrite one single line in the xml file, and save it. Can anyone help me how to do it?
The xml file's name is: "hardwaresettings.xml" and I want to change the fullscreen="false", to fullscreen="true"

<?xml version="1.0" encoding="UTF-8" ?>
<hardware_settings_config version="53" deviceId="0x1086">
    <cpu>
        <threadStrategy parallelUpdateRender="true" workerMapFile="system/workerMap4Core.xml" forceFeedbackProcessor="3" dvdStorageProcessor="3" dataSetMonitorProcessor="1" renderProcessor="0" updateProcessor="2" fileStreamProcessor="3" />
    </cpu>
    <audio_card>
        <audio mixing="rapture3D" />
    </audio_card>
    <graphics_card>
        <directx forcedx9="false" />
        <resolution width="1920" height="1080" aspect="auto" fullscreen="false" vsync="1" multisampling="8xmsaa">
            <refreshRate rate="120" />
        </resolution>
        <gamma level="1.0" />
    </graphics_card>
    <graphics_detail level="high" />
    <shadows enabled="true" size="2048" maskQuality="2" />
    <particles enabled="true" wind="true" dynamicRes="false" />
    <crowd enabled="true" detail="1" />
    <cloth enabled="true" tessellation="true" />
    <postprocess quality="2" />
    <groundcover mode="blended" clutter="true" />
    <objects lod="1.5" maxlod="0" />
    <trees lod="1.5" maxlod="0" />
    <vehicles characterQuality="2" lodQuality="2" />
    <envmap faces="6" size="1024" forceBilinear="false" />
    <water update="true" detail="2" tessellation="true" />
    <mirrors enabled="true" forceBilinear="false" width="1536" height="512" car_maxlod="0" car_culldist="500.0" />
    <skidmarks enabled="true" />
    <dynamic_ambient_occ enabled="true" quality="2" />
    <night_lighting volumes="true" lights="0" shadows="true" />
    <physics environmentalDamage="true" vehicleDamage="true" />
    <input device_type="auto" />
    <motion enabled="true" ip="dbox" port="20777" delay="1" extradata="0" />
</hardware_settings_config>
Filburt
  • 17,626
  • 12
  • 64
  • 115
  • You could cut some corners and just use a powershell script to achieve this. See [How to change the value of XML Element attribute using PowerShell?](https://stackoverflow.com/q/24679454/205233) – Filburt Mar 15 '22 at 17:29
  • https://stackoverflow.com/questions/1487653/update-xml-with-c-sharp-using-linq – Pavan Chandaka Mar 15 '22 at 17:33
  • I just tried this method, but it doesn't work for me :c What did I write wrong? `$xml=New-Object XML $xml.Load("D:\hardware_settings_config.xml") $nodes = $xml.SelectNodes("/hardware_settings_config/graphics_card/resolution"); foreach($node in $nodes) { $node.SetAttribute("fullscreen", "true"); }` – Bálint Mózer Mar 15 '22 at 18:35
  • Seems like the better approach would be to report it as a bug to the game developer so they can fix the issue. – Tu deschizi eu inchid Mar 15 '22 at 19:29
  • XElement doc = XElement.Load("path to file"); var result = doc.Descendants("graphics_card") .Select(m => m.Element("resolution")); var attr = result.Attributes("fullscreen").FirstOrDefault().Value; if (attr == "false") { result.Attributes("fullscreen").FirstOrDefault().Value = "true"; } else { result.Attributes("fullscreen").FirstOrDefault().Value = "false"; } doc.Save("path to file"); – duerzd696 Mar 15 '22 at 20:03

1 Answers1

0

Powershell solution:

[xml]$xmldata = Get-Content "D:\hardware_settings_config.xml"

$xmldata.hardware_settings_config.graphics_card.resolution.fullscreen = "true"

$xmldata.Save("D:\hardware_settings_config.xml")

Make sure you save your file after modifying and don't fall for not using the complete path when saving.

Filburt
  • 17,626
  • 12
  • 64
  • 115