add the ability to add weapons from within the application

This commit is contained in:
Li 2023-03-08 10:27:17 +13:00
parent 0edb1d8918
commit 226df9737a
16 changed files with 187 additions and 24 deletions

View File

@ -13,6 +13,11 @@ namespace LibW4M.Data.Highscores
{ {
} }
public override void Create()
{
throw new NotImplementedException();
}
public override void Load() public override void Load()
{ {
// highscore data is stored after teams data section of TeamDataCollective. // highscore data is stored after teams data section of TeamDataCollective.

View File

@ -2,6 +2,7 @@
using LibXom.Data; using LibXom.Data;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -14,6 +15,11 @@ namespace LibW4M.Data.InputMapping
{ {
} }
public override void Create()
{
throw new NotImplementedException();
}
public override void Load() public override void Load()
{ {
int[] collective = mainContainer.Decompress(); int[] collective = mainContainer.Decompress();
@ -39,5 +45,10 @@ namespace LibW4M.Data.InputMapping
} }
mainContainer.CompressAndUpdate(collective); mainContainer.CompressAndUpdate(collective);
} }
private string GetDebuggerDisplay()
{
return ToString();
}
} }
} }

View File

@ -48,7 +48,7 @@ namespace LibW4M.Data
} }
} }
} }
public abstract void Create();
public abstract override void Load(); public abstract override void Load();
public abstract override void Save(); public abstract override void Save();

View File

@ -29,7 +29,7 @@ namespace LibW4M.Data
public virtual string FriendlyName public virtual string FriendlyName
{ get { get
{ {
return mainContainer.Type.Name; return this.mainContainer.Type.Name;
} }
} }
public override int GetHashCode() public override int GetHashCode()
@ -44,16 +44,24 @@ namespace LibW4M.Data
public abstract void Load(); public abstract void Load();
public abstract void Save(); public abstract void Save();
internal virtual void loadDefaults()
{
//this.Save();
}
public virtual void DeleteEntries() public virtual void DeleteEntries()
{ {
this.mainContainer.Delete(); this.mainContainer.Delete();
} }
public SaveDataEntry (W4SaveFile fileBelongs, XomContainer mainContainer) internal SaveDataEntry (W4SaveFile fileBelongs, XomContainer mainContainer, bool load=true)
{ {
this.fileBelongs = fileBelongs; this.fileBelongs = fileBelongs;
this.mainContainer = mainContainer; this.mainContainer = mainContainer;
this.Load(); if (load)
this.Load();
else
this.loadDefaults();
} }
} }
} }

View File

@ -14,6 +14,11 @@ namespace LibW4M.Data.Schemes
{ {
} }
public override void Create()
{
throw new NotImplementedException();
}
public override void Load() public override void Load()
{ {
int[] collective = mainContainer.Decompress(); int[] collective = mainContainer.Decompress();

View File

@ -16,6 +16,11 @@ namespace LibW4M.Data.Stats
{ {
} }
public override void Create()
{
throw new NotImplementedException();
}
public override void Load() public override void Load()
{ {
int[] decompressedCollective = mainContainer.Decompress(); int[] decompressedCollective = mainContainer.Decompress();

View File

@ -105,5 +105,10 @@ namespace LibW4M.Data.Stats
mainContainer.CompressAndUpdate(newCollective); mainContainer.CompressAndUpdate(newCollective);
} }
public override void Create()
{
throw new NotImplementedException();
}
} }
} }

View File

@ -14,6 +14,11 @@ namespace LibW4M.Data.Teams
{ {
} }
public override void Create()
{
throw new NotImplementedException();
}
public override void Load() public override void Load()
{ {
int[] decompressedCollective = mainContainer.Decompress(); int[] decompressedCollective = mainContainer.Decompress();

View File

@ -45,7 +45,7 @@ namespace LibW4M.Data.WeaponFactory
public float ClusterSpread; public float ClusterSpread;
public float ClusterMaxSpeed; public float ClusterMaxSpeed;
public WeaponData(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer) public WeaponData(W4SaveFile fileBelongs, XomContainer mainContainer, bool load=true) : base(fileBelongs, mainContainer, load)
{ {
} }
@ -122,7 +122,46 @@ namespace LibW4M.Data.WeaponFactory
} }
} }
} }
internal override void loadDefaults()
{
this.Name = this.fileBelongs.LookupString("Untitled Weapon");
this.Type = 0;
this.DetonationType = DetonationType.Impact;
this.Homing = false;
this.HomingAvoidLand = false;
this.Poison = false;
this.EffectedByWind = true;
this.FireOnGround = false;
this.RetreatTime = -1;
this.WormDamageRadius = 0.75f;
this.WormDamageMagnitude = 0.5f;
this.LandDamageRadius = 0.5f;
this.Push = 0.5f;
this.ProjectileCollisionRadius = 1.0f;
this.FuseTime = -1;
this.GraphicalResources = new XomString[4] { this.fileBelongs.LookupString("Factory.TankGunBody"), this.fileBelongs.LookupString("Factory.TankGunBarrel"), this.fileBelongs.LookupString("Factory.TankGunButt"), this.fileBelongs.LookupString("Factory.TankGunSight") };
this.GraphicalLocators = new XomString[4] { this.fileBelongs.LookupString("TANK_body_locator"), this.fileBelongs.LookupString("TANK_barrel_root_locator"), this.fileBelongs.LookupString("TANK_butt_root_locator"), this.fileBelongs.LookupString("TANK_sight_root_locator") };
this.LaunchFX = this.fileBelongs.LookupString("");
this.ArielFX = this.fileBelongs.LookupString("WXP_BazookaTrailPack");
this.DetonationFX = this.fileBelongs.LookupString("WXP_ExplosionX_Med");
this.PayloadResourceId = 55;
this.ProjectileLaunchType = ProjectileLaunchType.Launched;
this.ProjectilePowersUp = true;
this.ProjectileNumClusters = 0;
this.ProjectileMaxPower = 0.5f;
this.ClusterSpread = 0.300000012f;
this.ClusterMaxSpeed = 0.0f;
base.loadDefaults();
}
public override void Load() public override void Load()
{ {
using (XomStreamReader reader = new XomStreamReader(new MemoryStream(this.mainContainer.GetData()))) using (XomStreamReader reader = new XomStreamReader(new MemoryStream(this.mainContainer.GetData())))

View File

@ -17,38 +17,91 @@ namespace LibW4M.Data.WeaponFactory
public WeaponData Cluster; public WeaponData Cluster;
public bool StockWeapon; public bool StockWeapon;
internal XomContainer weaponContainer;
internal XomContainer clusterContainer;
public WeaponStore(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer) internal WeaponStore(W4SaveFile fileBelongs, XomContainer mainContainer, bool load=true) : base(fileBelongs, mainContainer, load)
{ {
} }
public override void Load() public override void Load()
{ {
int[] weaponStore = this.mainContainer.Decompress(); using (XomStreamReader reader = new XomStreamReader(new MemoryStream(mainContainer.GetData())))
this.StockWeapon = (weaponStore[0] == 1); {
this.weaponContainer = this.fileBelongs.LookupContainerById(weaponStore[1]); reader.Skip(3);
this.clusterContainer = this.fileBelongs.LookupContainerById(weaponStore[2]);
this.Weapon = new WeaponData(this.fileBelongs, this.weaponContainer); this.StockWeapon = reader.ReadBool();
this.Cluster = new WeaponData(this.fileBelongs, this.clusterContainer); this.Weapon = new WeaponData(this.fileBelongs, this.fileBelongs.LookupContainerById(reader.ReadCompressedInt()));
this.Cluster = new WeaponData(this.fileBelongs, this.fileBelongs.LookupContainerById(reader.ReadCompressedInt()));
}
} }
public override void Save() public override void Save()
{ {
this.Weapon.Save(); this.Weapon.Save();
this.Cluster.Save(); this.Cluster.Save();
using (MemoryStream ms = new MemoryStream())
{
using (XomStreamWriter writer = new XomStreamWriter(ms))
{
writer.Skip(3);
int[] weaponStore = this.mainContainer.Decompress(); writer.WriteBool(this.StockWeapon);
weaponStore[0] = (this.StockWeapon ? 1 : 0); writer.WriteCompressedInt(this.Weapon.mainContainer.Id);
weaponStore[1] = this.weaponContainer.Id; writer.WriteCompressedInt(this.Cluster.mainContainer.Id);
weaponStore[2] = this.clusterContainer.Id;
this.mainContainer.CompressAndUpdate(weaponStore); ms.Seek(0x00, SeekOrigin.Begin);
mainContainer.SetData(ms.ToArray());
}
}
} }
internal override void loadDefaults()
{
this.StockWeapon = false;
this.Weapon = new WeaponData(this.fileBelongs, this.fileBelongs.CreateContainer("WeaponFactoryContainer"), false);
this.Cluster = new WeaponData(this.fileBelongs, this.fileBelongs.CreateContainer("WeaponFactoryContainer"), false);
// Clusters should have different defaults, lets just go fix that :)
this.Cluster.Name = this.fileBelongs.LookupString("");
this.Cluster.Type = 1;
this.Cluster.DetonationType = DetonationType.Impact;
this.Cluster.Homing = false;
this.Cluster.HomingAvoidLand = false;
this.Cluster.Poison = false;
this.Cluster.EffectedByWind = false;
this.Cluster.FireOnGround = false;
this.Cluster.RetreatTime = 0;
this.Cluster.WormDamageRadius = 0.75f;
this.Cluster.WormDamageMagnitude = 0.5f;
this.Cluster.LandDamageRadius = 0.5f;
this.Cluster.Push = 0.5f;
this.Cluster.ProjectileCollisionRadius = 1.0f;
this.Cluster.FuseTime = -1;
this.Cluster.GraphicalResources = new XomString[0];
this.Cluster.GraphicalLocators = new XomString[0];
this.Cluster.LaunchFX = this.fileBelongs.LookupString("");
this.Cluster.ArielFX = this.fileBelongs.LookupString("");
this.Cluster.DetonationFX = this.fileBelongs.LookupString("WXP_ExploCluster");
this.Cluster.PayloadResourceId = 16;
this.Cluster.ProjectileLaunchType = ProjectileLaunchType.Thrown;
this.Cluster.ProjectilePowersUp = false;
this.Cluster.ProjectileNumClusters = 0;
this.Cluster.ProjectileMaxPower = 0.0f;
this.Cluster.ClusterSpread = 0.5f;
this.Cluster.ClusterMaxSpeed = 0.0f;
base.loadDefaults();
}
public override void DeleteEntries() public override void DeleteEntries()
{ {

View File

@ -25,6 +25,12 @@ namespace LibW4M.Data.WeaponFactory
} }
return null; return null;
} }
public override void Create()
{
this.collectiveEntries.Add(new WeaponStore(this.fileBelongs, this.fileBelongs.CreateContainer("StoreWeaponFactory"), false));
}
public override void Load() public override void Load()
{ {
int[] collective = mainContainer.Decompress(); int[] collective = mainContainer.Decompress();

View File

@ -215,6 +215,10 @@ namespace LibW4M
return strings; return strings;
} }
public XomContainer CreateContainer(string type)
{
return xomFile.CreateContainer(type);
}
public XomContainer LookupContainerById(int id) public XomContainer LookupContainerById(int id)
{ {
return xomFile.GetContainerById(id); return xomFile.GetContainerById(id);

View File

@ -54,6 +54,13 @@ namespace LibXom.Data
return xomStrings.Count - 1; return xomStrings.Count - 1;
} }
public XomContainer CreateContainer(string typeName)
{
XomType type = GetTypeByName(typeName);
return type.NewContainer();
}
public void ClearAllStrings() public void ClearAllStrings()
{ {
xomStrings.Clear(); xomStrings.Clear();
@ -181,9 +188,9 @@ namespace LibXom.Data
XomBlock[] containerBlocks = XomBlockHandler.GetBlocksByName(xomBlocks, "CTNR"); XomBlock[] containerBlocks = XomBlockHandler.GetBlocksByName(xomBlocks, "CTNR");
if (moikBlock is not MoikBlock) throw new XomBlockNotFoundException("XOM contained no MOIK block!, Is it corrupted?"); if (moikBlock is not MoikBlock) throw new XomBlockNotFoundException("XOM contained no MOIK block!, Is the XOM corrupted?");
if (schemeBlock is not SchmBlock) throw new XomBlockNotFoundException("XOM contained no SCHM block!, Is it corrupted?"); if (schemeBlock is not SchmBlock) throw new XomBlockNotFoundException("XOM contained no SCHM block!, Is the XOM corrupted?");
if (stringBlock is not StrsBlock) throw new XomBlockNotFoundException("XOM contained no STRS block!, Is it corrupted?"); if (stringBlock is not StrsBlock) throw new XomBlockNotFoundException("XOM contained no STRS block!, Is the XOM corrupted?");
version = moikBlock.Version; version = moikBlock.Version;
unk0 = schemeBlock.Unk0; unk0 = schemeBlock.Unk0;

View File

@ -60,6 +60,14 @@ namespace LibXom.Data
int indx = this.getContainerIndex(container); int indx = this.getContainerIndex(container);
this.xomContainers[indx].data = newData; this.xomContainers[indx].data = newData;
} }
public XomContainer NewContainer()
{
XomContainer xomContainer = new XomContainer(this.fileBelongs, this.Name, new byte[0x3]);
this.xomContainers.Add(xomContainer);
return xomContainer;
}
public void DeleteContainer(XomContainer container) public void DeleteContainer(XomContainer container)
{ {
int indx = this.getContainerIndex(container); int indx = this.getContainerIndex(container);

View File

@ -72,7 +72,7 @@
// btnAdd // btnAdd
// //
this.btnAdd.Dock = System.Windows.Forms.DockStyle.Fill; this.btnAdd.Dock = System.Windows.Forms.DockStyle.Fill;
this.btnAdd.Enabled = false; this.btnAdd.Enabled = true;
this.btnAdd.Location = new System.Drawing.Point(3, 3); this.btnAdd.Location = new System.Drawing.Point(3, 3);
this.btnAdd.Name = "btnAdd"; this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(116, 26); this.btnAdd.Size = new System.Drawing.Size(116, 26);

View File

@ -54,7 +54,9 @@ namespace W4Gui.Tabs
private void weaponList_NewButton(object sender, EventArgs e) private void weaponList_NewButton(object sender, EventArgs e)
{ {
throw new NotImplementedException("Adding new weapons from here not implemented yet ;)"); DataManager.SaveFile.WeaponFactoryCollective.Create();
weaponList.List.Add(DataManager.SaveFile.WeaponFactoryCollective.Last().FriendlyName);
weaponList.List.SelectedIndex = (weaponList.List.Items.Count - 1);
} }
private void weaponList_DeleteButton(object sender, EventArgs e) private void weaponList_DeleteButton(object sender, EventArgs e)