From 56083c3bc66c97ee1190e7d2593a847efc1be184 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 4 Apr 2019 10:22:02 +0800 Subject: [PATCH] Updated sfall debug editor (from Mr.Stalin) Formatted the code of sfall debug editor. --- MPClient/DebugEditor.Designer.cs | 62 ++-- MPClient/DebugEditor.cs | 302 ++++++++++-------- MPClient/EditorConnection.cs | 74 +++-- MPClient/EditorWindow.Designer.cs | 19 +- MPClient/EditorWindow.cs | 37 ++- MPClient/EditorWindow.resx | 9 - MPClient/Program.cs | 15 +- MPClient/Properties/AssemblyInfo.cs | 10 +- ...PClient.csproj => SfallDebugEditor.csproj} | 37 ++- .../{MPClient.sln => SfallDebugEditor.sln} | 2 +- sfall/Modules/DebugEditor.cpp | 58 ++-- sfall/Modules/Scripting/Arrays.cpp | 30 +- sfall/Modules/Scripting/Arrays.h | 2 +- 13 files changed, 395 insertions(+), 262 deletions(-) rename MPClient/{MPClient.csproj => SfallDebugEditor.csproj} (65%) rename MPClient/{MPClient.sln => SfallDebugEditor.sln} (84%) diff --git a/MPClient/DebugEditor.Designer.cs b/MPClient/DebugEditor.Designer.cs index 1ecd8fc4..bc8b6839 100644 --- a/MPClient/DebugEditor.Designer.cs +++ b/MPClient/DebugEditor.Designer.cs @@ -29,11 +29,11 @@ this.bCritters = new System.Windows.Forms.Button(); this.bSGlobals = new System.Windows.Forms.Button(); this.bArrays = new System.Windows.Forms.Button(); + this.bEdit = new System.Windows.Forms.Button(); this.Column0 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.bEdit = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // @@ -41,25 +41,30 @@ // this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.AllowUserToDeleteRows = false; - this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.AllowUserToResizeRows = false; + this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Column0, this.Column1, this.Column2, this.Column3}); this.dataGridView1.Location = new System.Drawing.Point(12, 12); + this.dataGridView1.MultiSelect = false; this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.Size = new System.Drawing.Size(444, 215); + this.dataGridView1.RowHeadersVisible = false; + this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView1.Size = new System.Drawing.Size(443, 233); this.dataGridView1.TabIndex = 0; + this.dataGridView1.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellDoubleClick); this.dataGridView1.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEndEdit); // // bGlobals // this.bGlobals.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.bGlobals.Location = new System.Drawing.Point(12, 233); + this.bGlobals.Location = new System.Drawing.Point(12, 251); this.bGlobals.Name = "bGlobals"; this.bGlobals.Size = new System.Drawing.Size(100, 23); this.bGlobals.TabIndex = 1; @@ -70,7 +75,7 @@ // bMapVars // this.bMapVars.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.bMapVars.Location = new System.Drawing.Point(118, 233); + this.bMapVars.Location = new System.Drawing.Point(118, 251); this.bMapVars.Name = "bMapVars"; this.bMapVars.Size = new System.Drawing.Size(100, 23); this.bMapVars.TabIndex = 2; @@ -81,7 +86,7 @@ // bCritters // this.bCritters.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.bCritters.Location = new System.Drawing.Point(118, 262); + this.bCritters.Location = new System.Drawing.Point(12, 280); this.bCritters.Name = "bCritters"; this.bCritters.Size = new System.Drawing.Size(100, 23); this.bCritters.TabIndex = 3; @@ -91,8 +96,8 @@ // // bSGlobals // - this.bSGlobals.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.bSGlobals.Location = new System.Drawing.Point(225, 233); + this.bSGlobals.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.bSGlobals.Location = new System.Drawing.Point(249, 251); this.bSGlobals.Name = "bSGlobals"; this.bSGlobals.Size = new System.Drawing.Size(100, 23); this.bSGlobals.TabIndex = 4; @@ -102,8 +107,8 @@ // // bArrays // - this.bArrays.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.bArrays.Location = new System.Drawing.Point(12, 262); + this.bArrays.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.bArrays.Location = new System.Drawing.Point(355, 251); this.bArrays.Name = "bArrays"; this.bArrays.Size = new System.Drawing.Size(100, 23); this.bArrays.TabIndex = 5; @@ -111,14 +116,27 @@ this.bArrays.UseVisualStyleBackColor = true; this.bArrays.Click += new System.EventHandler(this.bArrays_Click); // + // bEdit + // + this.bEdit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.bEdit.Location = new System.Drawing.Point(355, 280); + this.bEdit.Name = "bEdit"; + this.bEdit.Size = new System.Drawing.Size(100, 23); + this.bEdit.TabIndex = 6; + this.bEdit.Text = "Edit"; + this.bEdit.UseVisualStyleBackColor = true; + this.bEdit.Click += new System.EventHandler(this.bEdit_Click); + // // Column0 // this.Column0.HeaderText = "ID"; this.Column0.Name = "Column0"; this.Column0.ReadOnly = true; + this.Column0.Width = 50; // // Column1 // + this.Column1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.Column1.HeaderText = "Name"; this.Column1.Name = "Column1"; this.Column1.ReadOnly = true; @@ -133,22 +151,11 @@ this.Column3.HeaderText = "Value (Float)"; this.Column3.Name = "Column3"; // - // bEdit - // - this.bEdit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.bEdit.Location = new System.Drawing.Point(225, 262); - this.bEdit.Name = "bEdit"; - this.bEdit.Size = new System.Drawing.Size(100, 23); - this.bEdit.TabIndex = 6; - this.bEdit.Text = "Edit"; - this.bEdit.UseVisualStyleBackColor = true; - this.bEdit.Click += new System.EventHandler(this.bEdit_Click); - // // DebugEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(468, 297); + this.ClientSize = new System.Drawing.Size(467, 315); this.Controls.Add(this.bEdit); this.Controls.Add(this.bArrays); this.Controls.Add(this.bSGlobals); @@ -156,8 +163,9 @@ this.Controls.Add(this.bMapVars); this.Controls.Add(this.bGlobals); this.Controls.Add(this.dataGridView1); + this.MinimumSize = new System.Drawing.Size(450, 300); this.Name = "DebugEditor"; - this.Text = "DebugEditor"; + this.Text = "sfall Debug Editor"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.DebugEditor_FormClosing); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.ResumeLayout(false); @@ -172,11 +180,11 @@ private System.Windows.Forms.Button bCritters; private System.Windows.Forms.Button bSGlobals; private System.Windows.Forms.Button bArrays; + private System.Windows.Forms.Button bEdit; private System.Windows.Forms.DataGridViewTextBoxColumn Column0; private System.Windows.Forms.DataGridViewTextBoxColumn Column1; private System.Windows.Forms.DataGridViewTextBoxColumn Column2; private System.Windows.Forms.DataGridViewTextBoxColumn Column3; - private System.Windows.Forms.Button bEdit; } } \ No newline at end of file diff --git a/MPClient/DebugEditor.cs b/MPClient/DebugEditor.cs index d419bfb6..b6d909c5 100644 --- a/MPClient/DebugEditor.cs +++ b/MPClient/DebugEditor.cs @@ -4,14 +4,16 @@ using System.ComponentModel; using System.Drawing; using System.Text; using System.Windows.Forms; -using File=System.IO.File; -using StreamReader=System.IO.StreamReader; -using MemoryStream=System.IO.MemoryStream; -using BinaryReader=System.IO.BinaryReader; -using BinaryWriter=System.IO.BinaryWriter; +using File = System.IO.File; +using StreamReader = System.IO.StreamReader; +using MemoryStream = System.IO.MemoryStream; +using BinaryReader = System.IO.BinaryReader; +using BinaryWriter = System.IO.BinaryWriter; namespace FalloutClient { - public partial class DebugEditor : Form { + + public partial class DebugEditor : Form + { [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit)] private struct ByteConverter { [System.Runtime.InteropServices.FieldOffset(0)] @@ -20,86 +22,91 @@ namespace FalloutClient { private float f; public int GetAsInt(float f) { - this.f=f; + this.f = f; return i; } public float GetAsFloat(int i) { - this.i=i; + this.i = i; return f; } public byte[] GetAsBytes(ulong ul) { - byte[] b=new byte[8]; - for(int i=0;i<8;i++) b[i]=(byte)((ul&((ulong)0xff<<(i*8)))>>(i*8)); + byte[] b = new byte[8]; + for (int i = 0; i < 8; i++) b[i] = (byte)((ul & ((ulong)0xff << (i * 8))) >> (i * 8)); return b; } } - private static ByteConverter converter=new ByteConverter(); + private static ByteConverter converter = new ByteConverter(); private enum Mode { Globals, MapVars, SGlobals, Arrays, Critters } private readonly EditorConnection connection; private Mode mode; - private readonly Dictionary GlobNames=new Dictionary(); - private readonly Dictionary CritNames=new Dictionary(); + private readonly Dictionary GlobNames = new Dictionary(); + private readonly Dictionary CritNames = new Dictionary(); private void Redraw() { dataGridView1.SuspendLayout(); dataGridView1.Rows.Clear(); - switch(mode) { + switch (mode) { case Mode.Globals: - Column2.ReadOnly=false; - Column3.ReadOnly=false; - Column2.HeaderText="Value (Int)"; - Column3.HeaderText="Value (Float)"; - bEdit.Enabled=false; - for(int i=0;i0xffffffff?new string(System.Text.ASCIIEncoding.ASCII.GetChars(converter.GetAsBytes(connection.SGlobalKeys[i]))):("0x"+connection.SGlobalKeys[i].ToString("x")); + Column2.ReadOnly = false; + Column3.ReadOnly = false; + Column2.HeaderText = "Value (Int)"; + Column3.HeaderText = "Value (Float)"; + bEdit.Enabled = false; + for (int i = 0; i < connection.SGlobalKeys.Length; i++) { + string s = connection.SGlobalKeys[i] > 0xffffffff + ? new string(System.Text.ASCIIEncoding.ASCII.GetChars(converter.GetAsBytes(connection.SGlobalKeys[i]))) + : (connection.SGlobalKeys[i].ToString()); dataGridView1.Rows.Add(s, "", connection.sGlobals[i], converter.GetAsFloat(connection.sGlobals[i])); } break; case Mode.Arrays: - Column2.ReadOnly=true; - Column3.ReadOnly=true; - Column2.HeaderText="Array length"; - Column3.HeaderText="Element size"; - bEdit.Enabled=true; - for(int i=0;i(bytes, 0)); + byte[] bytes = br.ReadBytes(lenType[j]); + strings[j] = System.Text.Encoding.ASCII.GetString(bytes, 0, lenType[j] - 1); //Array.IndexOf(bytes, 0) break; } } br.Close(); - strings=EditorWindow.ShowEditor(null, types, strings); - if(strings!=null) { + strings = EditorWindow.ShowEditor(null, types, strings); + if (strings != null) { // save connection.WriteDataType(DataTypeSend.SetArray); connection.WriteInt(i); - ms=new MemoryStream(connection.ArrayLengths[i]*connection.ArrayDataSizes[i]); + ms = new MemoryStream(connection.ArrayLengths[i] * connection.ArrayDataSizes[i]); BinaryWriter bw=new BinaryWriter(ms); - for(int j=0;j True - - True - - - True - - - True - \ No newline at end of file diff --git a/MPClient/Program.cs b/MPClient/Program.cs index 73f84324..a1afae60 100644 --- a/MPClient/Program.cs +++ b/MPClient/Program.cs @@ -12,7 +12,7 @@ namespace FalloutClient { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - if(args.Length==1&&args[0]=="-debugedit") { + if (args.Length == 1 && args[0] == "-debugedit") { Application.Run(new DebugEditor(new EditorConnection())); } else { throw new Exception("Multiplayer is no longer supported"); @@ -21,8 +21,13 @@ namespace FalloutClient { } enum DataTypeSend { - Mouse=0, LMouseDown=1, LMouseUp=2, RMouseDown=3, RMouseUp=4, TakeChar=5, ReleaseChar=6, - SetGlobal=0, SetMapVar=1, RetrieveCritter=2, SetCritter=3, SetSGlobal=4, GetArray=9, SetArray=10, - Exit=254 - } + SetGlobal = 0, + SetMapVar = 1, + RetrieveCritter = 2, + SetCritter = 3, + SetSGlobal = 4, + GetArray = 9, + SetArray = 10, + Exit = 254 + } } diff --git a/MPClient/Properties/AssemblyInfo.cs b/MPClient/Properties/AssemblyInfo.cs index 85abd150..814746b2 100644 --- a/MPClient/Properties/AssemblyInfo.cs +++ b/MPClient/Properties/AssemblyInfo.cs @@ -5,12 +5,12 @@ using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("FalloutClient")] +[assembly: AssemblyTitle("Fallout sfall Debug Editor")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("FalloutClient")] -[assembly: AssemblyCopyright("Copyright © 2009")] +[assembly: AssemblyProduct("sfall")] +[assembly: AssemblyCopyright("Copyright © 2019")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("4.1.7.0")] +[assembly: AssemblyFileVersion("4.1.7.0")] diff --git a/MPClient/MPClient.csproj b/MPClient/SfallDebugEditor.csproj similarity index 65% rename from MPClient/MPClient.csproj rename to MPClient/SfallDebugEditor.csproj index ab9f78f5..a74293c0 100644 --- a/MPClient/MPClient.csproj +++ b/MPClient/SfallDebugEditor.csproj @@ -16,6 +16,21 @@ v2.0 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true true @@ -33,6 +48,8 @@ TRACE prompt 4 + true + true @@ -62,6 +79,23 @@ EditorWindow.cs + + + False + Клиентский профиль .NET Framework 3.5 SP1 + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Установщик Windows 3.1 + true + + - copy "$(TargetPath)" "C:\Games\Fallout2\$(TargetName)$(TargetExt)" + + \ No newline at end of file diff --git a/MPClient/MPClient.sln b/MPClient/SfallDebugEditor.sln similarity index 84% rename from MPClient/MPClient.sln rename to MPClient/SfallDebugEditor.sln index 14e5dc69..134147ff 100644 --- a/MPClient/MPClient.sln +++ b/MPClient/SfallDebugEditor.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MPClient", "MPClient.csproj", "{80ED0DCE-100E-4EC9-A79D-2FBFA4CAD1E3}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SfallDebugEditor", "SfallDebugEditor.csproj", "{80ED0DCE-100E-4EC9-A79D-2FBFA4CAD1E3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/sfall/Modules/DebugEditor.cpp b/sfall/Modules/DebugEditor.cpp index 21ebafd9..cda17442 100644 --- a/sfall/Modules/DebugEditor.cpp +++ b/sfall/Modules/DebugEditor.cpp @@ -48,6 +48,13 @@ static const char* debugGnw = "GNW"; static DWORD debugEditorKey = 0; +struct sArray { + DWORD id; + long isMap; + long size; + long flag; +}; + static bool SetBlocking(SOCKET s, bool block) { DWORD d = !block; ioctlsocket(s, FIONBIO, &d); @@ -113,15 +120,16 @@ static void RunEditorInternal(SOCKET &s) { GlobalVar* sglobals = new GlobalVar[numSGlobals]; GetGlobals(sglobals); - int* arrays = new int[numArrays * 3]; - script::GetArrays(arrays); + sArray* arrays = new sArray[numArrays]; + script::GetArrays((int*)arrays); InternalSend(s, reinterpret_cast(fo::var::game_global_vars), 4 * numGlobals); InternalSend(s, reinterpret_cast(fo::var::map_global_vars), 4 * numMapVars); InternalSend(s, sglobals, sizeof(GlobalVar)*numSGlobals); - InternalSend(s, arrays, numArrays * 3 * 4); + InternalSend(s, arrays, numArrays * sizeof(sArray)); for (int i = 0; i < numCritters; i++) { InternalSend(s, &vec[i][25], 4); + InternalSend(s, &vec[i], 4); } while (true) { @@ -140,38 +148,44 @@ static void RunEditorInternal(SOCKET &s) { InternalRecv(s, &val, 4); fo::var::map_global_vars[id] = val; break; - case 2: + case 2: // Retrieve Critter InternalRecv(s, &id, 4); - InternalSend(s, vec[id], 0x74); + InternalSend(s, vec[id], 0x84); break; - case 3: + case 3: // Set Critter InternalRecv(s, &id, 4); - InternalRecv(s, vec[id], 0x74); + InternalRecv(s, vec[id], 0x84); break; case 4: InternalRecv(s, &id, 4); InternalRecv(s, &val, 4); sglobals[id].val = val; break; - case 9: + case 9: // get array values { - InternalRecv(s, &id, 4); - DWORD *types = new DWORD[arrays[id * 3 + 1]]; - char *data = new char[arrays[id * 3 + 1] * arrays[id * 3 + 2]]; - script::DEGetArray(arrays[id * 3], types, data); - InternalSend(s, types, arrays[id * 3 + 1] * 4); - InternalSend(s, data, arrays[id * 3 + 1] * arrays[id * 3 + 2]); - delete[] data; - delete[] types; + InternalRecv(s, &id, 4); + DWORD *types = new DWORD[arrays[id].size * 2]; // type, len + script::DEGetArray(arrays[id].id, types, nullptr); + int dataLen = 0; + for (long i = 0; i < arrays[id].size; i++) { + dataLen += types[i * 2 + 1]; + } + char *data = new char[dataLen]; + script::DEGetArray(arrays[id].id, nullptr, data); + InternalSend(s, types, arrays[id].size * 8); + InternalSend(s, data, dataLen); + delete[] data; + delete[] types; } break; - case 10: + case 10: // set array values { - InternalRecv(s, &id, 4); - char *data = new char[arrays[id * 3 + 1] * arrays[id * 3 + 2]]; - InternalRecv(s, data, arrays[id * 3 + 1] * arrays[id * 3 + 2]); - script::DESetArray(arrays[id * 3], 0, data); - delete[] data; + //InternalRecv(s, &id, 4); + //InternalRecv(s, &val, 4); + //char *data = new char[arrays[id].size * arrays[id * 3 + 2]]; + //InternalRecv(s, data, arrays[id].size * arrays[id * 3 + 2]); + //script::DESetArray(arrays[id].id, 0, data); + //delete[] data; } break; } diff --git a/sfall/Modules/Scripting/Arrays.cpp b/sfall/Modules/Scripting/Arrays.cpp index ae55bb4d..c8801f79 100644 --- a/sfall/Modules/Scripting/Arrays.cpp +++ b/sfall/Modules/Scripting/Arrays.cpp @@ -310,19 +310,37 @@ void GetArrays(int* _arrays) { int pos = 0; array_citr itr = arrays.begin(); while (itr != arrays.end()) { - _arrays[pos++] = itr->first; - _arrays[pos++] = itr->second.size(); + _arrays[pos++] = itr->first; // array id + _arrays[pos++] = itr->second.isAssoc() ? 1 : 0; + _arrays[pos++] = itr->second.val.size(); _arrays[pos++] = itr->second.flags; itr++; } } -// those too are not really used yet in FalloutClient (AFAIK) -- phobos2077 -void DEGetArray(int id, DWORD* types, void* data) { - //memcpy(types, arrays[id].types, arrays[id].len*4); - //memcpy(data, arrays[id].data, arrays[id].len*arrays[id].datalen); +void DEGetArray(int id, DWORD* types, char* data) { + int pos = 0; + if (types != nullptr) { + for (size_t i = 0; i < arrays[id].val.size(); i++) { + const auto& arVal = arrays[id].val[i]; + types[pos++] = (DWORD)arVal.type; + types[pos++] = (arVal.type == DataType::STR) ? arVal.len : 4; // in bytes + } + } else { + for (size_t i = 0; i < arrays[id].val.size(); i++) { + const auto& arVal = arrays[id].val[i]; + if (arVal.type != DataType::STR) { + *(long*)(data + pos) = arVal.intVal; + pos += 4; + } else { + strcpy(data + pos, arVal.strVal); + pos += arVal.len; + } + } + } } +// those too are not really used yet in FalloutClient (AFAIK) -- phobos2077 void DESetArray(int id, const DWORD* types, const void* data) { //if (types) memcpy(arrays[id].types, types, arrays[id].len * 4); //memcpy(arrays[id].data, data, arrays[id].len*arrays[id].datalen); diff --git a/sfall/Modules/Scripting/Arrays.h b/sfall/Modules/Scripting/Arrays.h index 41138b72..3a745b85 100644 --- a/sfall/Modules/Scripting/Arrays.h +++ b/sfall/Modules/Scripting/Arrays.h @@ -160,7 +160,7 @@ void SaveArrays(HANDLE h); int GetNumArrays(); void GetArrays(int* arrays); -void DEGetArray(int id, DWORD* types, void* data); +void DEGetArray(int id, DWORD* types, char* data); void DESetArray(int id, const DWORD* types, const void* data); // creates new normal (persistent) array. len == -1 specifies associative array (map)