Skip to content

Instantly share code, notes, and snippets.

@Scobalula
Created October 18, 2017 09:13
Show Gist options
  • Save Scobalula/049ab82e99f857d4342c6c0c29e26868 to your computer and use it in GitHub Desktop.
Save Scobalula/049ab82e99f857d4342c6c0c29e26868 to your computer and use it in GitHub Desktop.
Call of Duty Weapon File Loader
// Weapon Class
class Weapon
{
public string WeaponName { get; set; }
public string WeaponType = "bulletweapon";
public List<WeaponSetting> weapon_settings = new List<WeaponSetting>();
public override string ToString()
{
return WEAPONFILE;
}
}
// Weapon Settings Class
public class WeaponSetting
{
public string key { get; set; }
public string val { get; set; }
}
// Weapon Loader
static Weapon LoadWeaponFile(string file)
{
string[] weaponfile = System.IO.File.ReadAllText(file).Split('\\');
// Check for WEAPONFILE
if (weaponfile[0] != "WEAPONFILE")
return;
Weapon weapon = new Weapon();
weapon.WeaponName = System.IO.Path.GetFileNameWithoutExtension(file);
// Settings grouped with key/val, so loop but increment 2
// Start at 1 to skip WEAPONFILE
for (int i = 1; i < weaponfile.Length; i+=2)
weapon.weapon_settings.Add(new WeaponSetting { key = weaponfile[i], val = weaponfile[i + 1]});
return weapon;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment