From fd99822d25a7d110468b571ca25fdf46200453ea Mon Sep 17 00:00:00 2001 From: Reece W Date: Wed, 10 Jul 2019 23:55:34 +0100 Subject: [PATCH] Public Release? --- HavokHelper.csproj | 28 ++- src/Form/Form.Designer.cs | 12 +- src/Form/Form.cs | 5 + src/Form/NodeHelper.cs | 123 +++++++++++ src/Form/NodeHelper.designer.cs | 235 +++++++++++++++++++++ src/Form/NodeHelper.resx | 126 +++++++++++ src/Lua/Instructions/CallIInstruction.cs | 72 +++---- src/Lua/Instructions/CallIR1Instruction.cs | 134 ++++++------ src/Lua/Instructions/ClosureInstruction.cs | 140 ++++++------ src/Lua/Instructions/DivBkInstruction.cs | 72 +++---- src/Lua/Instructions/DivInstruction.cs | 72 +++---- src/Lua/Instructions/Helpers/CallHelper.cs | 13 +- src/Lua/Instructions/PowInstruction.cs | 130 ++++++------ src/Lua/Instructions/SelfInstruction.cs | 140 ++++++------ src/Parser/JSParserPort.cs | 32 ++- 15 files changed, 932 insertions(+), 402 deletions(-) create mode 100644 src/Form/NodeHelper.cs create mode 100644 src/Form/NodeHelper.designer.cs create mode 100644 src/Form/NodeHelper.resx diff --git a/HavokHelper.csproj b/HavokHelper.csproj index 00f5a6f..9812363 100644 --- a/HavokHelper.csproj +++ b/HavokHelper.csproj @@ -17,7 +17,7 @@ true full false - bin\Debug\ + ..\..\..\..\Game\Nevis\DevTools\ DEBUG;TRACE prompt 4 @@ -26,11 +26,14 @@ AnyCPU pdbonly true - bin\Release\ + ..\..\..\..\Game\Nevis\ModTools\Havok\ TRACE prompt 4 + + bin\Development\ + @@ -46,18 +49,24 @@ - - True - True - Form.resx - - Form Form.cs + + Form.resx + True + True + + + Form + + + NodeHelper.cs + + @@ -174,6 +183,9 @@ PublicResXFileCodeGenerator Form1.Designer.cs + + NodeHelper.cs + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/src/Form/Form.Designer.cs b/src/Form/Form.Designer.cs index 5757a47..28356aa 100644 --- a/src/Form/Form.Designer.cs +++ b/src/Form/Form.Designer.cs @@ -88,6 +88,7 @@ this.SavePseudocodeItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); @@ -551,7 +552,8 @@ // this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripButton1, - this.toolStripButton2}); + this.toolStripButton2, + this.toolStripLabel1}); this.toolStrip1.Location = new System.Drawing.Point(0, 0); this.toolStrip1.Name = "toolStrip1"; this.toolStrip1.Size = new System.Drawing.Size(1318, 25); @@ -620,6 +622,13 @@ // this.openFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog1_FileOk); // + // toolStripLabel1 + // + this.toolStripLabel1.Name = "toolStripLabel1"; + this.toolStripLabel1.Size = new System.Drawing.Size(116, 22); + this.toolStripLabel1.Text = "Havok Kore Backend"; + this.toolStripLabel1.Click += new System.EventHandler(this.toolStripLabel1_Click); + // // Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -713,6 +722,7 @@ private System.Windows.Forms.ColumnHeader RegColumn; private System.Windows.Forms.ColumnHeader InstIndexColumn; private System.Windows.Forms.GroupBox groupBox4; + private System.Windows.Forms.ToolStripLabel toolStripLabel1; } } diff --git a/src/Form/Form.cs b/src/Form/Form.cs index c10fbae..730a0be 100644 --- a/src/Form/Form.cs +++ b/src/Form/Form.cs @@ -165,5 +165,10 @@ namespace HavokHelper { } + + private void toolStripLabel1_Click(object sender, EventArgs e) + { + new NodeHelper().Show(); + } } } diff --git a/src/Form/NodeHelper.cs b/src/Form/NodeHelper.cs new file mode 100644 index 0000000..8b16f8b --- /dev/null +++ b/src/Form/NodeHelper.cs @@ -0,0 +1,123 @@ +using HavokHelper.Lua; +using HavokHelper.Lua.Instructions; +using HavokHelper.src.Parser; +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace HavokHelper +{ + public partial class NodeHelper : Form + { + private Stub SelectedStub; + + public NodeHelper() + { + InitializeComponent(); + } + + private void NodeHelper_Load(object sender, EventArgs e) + { + + } + + private void button1_Click(object sender, EventArgs e) + { + openFileDialog1.ShowDialog(); + } + + private void button2_Click(object sender, EventArgs e) + { + openFileDialog2.ShowDialog(); + } + + private void openFileDialog1_FileOk(object sender, CancelEventArgs e) + { + textBox1.Text = openFileDialog1.FileName; + textBox2.Text = openFileDialog1.FileName; + + if (textBox1.Text.EndsWith(".lua")) + textBox2.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 3) + "asm"; + } + + private void openFileDialog2_FileOk(object sender, CancelEventArgs e) + { + textBox2.Text = openFileDialog2.FileName; + } + + private void destCompiled_CheckedChanged(object sender, EventArgs e) + { + if (textBox2.Text.Length < 4) + return; + textBox2.Text = textBox2.Text.Substring(0, textBox2.Text.Length - 3) + (destCompiled.Checked ? "lua" : "asm"); + } + + private void appendText(string text) + { + if (richTextBox1.InvokeRequired) + richTextBox1.Invoke(new System.Action(() => appendText(text))); + else + richTextBox1.AppendText(text); + } + + private void button3_Click(object sender, EventArgs e) + { + System.IO.File.WriteAllText(@"fuck.js", string.Empty); + String buffer = ""; + + buffer += "var hks = require(\"" + textBox3.Text.Replace(@"\", @"\\") + "index.js\")\n"; + buffer += "var test = new hks.Context();\n"; + + if (srcCompiled.Checked) + { + buffer += "test.fromFile(\"" + textBox1.Text.Replace(@"\", @"\\") + "\")\n"; + } + else + { + buffer += "test.assembleFile(\"" + textBox1.Text.Replace(@"\", @"\\") + "\")\n"; + } + + + if (destCompiled.Checked) + { + buffer += "test.save(\"" + textBox2.Text.Replace(@"\", @"\\") + "\")\n"; + } + else + { + buffer += "test.disassembleFile(\"" + textBox2.Text.Replace(@"\", @"\\") + "\")\n"; + } + + System.IO.File.WriteAllText(@"fuck.js", buffer); + using (Process nodejs = new Process()) + { + nodejs.StartInfo.FileName = @"C:\Program Files\nodejs\node.exe"; + nodejs.StartInfo.Arguments = "fuck.js"; + nodejs.StartInfo.CreateNoWindow = true; + nodejs.StartInfo.UseShellExecute = false; + nodejs.StartInfo.RedirectStandardOutput = true; + nodejs.StartInfo.RedirectStandardError = true; + + nodejs.OutputDataReceived += (object sender2, DataReceivedEventArgs e2) => + { + appendText(e2.Data); + appendText(Environment.NewLine); + }; + + nodejs.ErrorDataReceived += (object sender2, DataReceivedEventArgs e2) => + { + appendText(e2.Data); + appendText(Environment.NewLine); + }; + + nodejs.Start(); + nodejs.BeginOutputReadLine(); + nodejs.BeginErrorReadLine(); + // nodejs.WaitForExit(); + } + } + } +} diff --git a/src/Form/NodeHelper.designer.cs b/src/Form/NodeHelper.designer.cs new file mode 100644 index 0000000..7814927 --- /dev/null +++ b/src/Form/NodeHelper.designer.cs @@ -0,0 +1,235 @@ +namespace HavokHelper +{ + partial class NodeHelper + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.srcAssembly = new System.Windows.Forms.RadioButton(); + this.srcCompiled = new System.Windows.Forms.RadioButton(); + this.button1 = new System.Windows.Forms.Button(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.destAssembly = new System.Windows.Forms.RadioButton(); + this.destCompiled = new System.Windows.Forms.RadioButton(); + this.button2 = new System.Windows.Forms.Button(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.button3 = new System.Windows.Forms.Button(); + this.textBox3 = new System.Windows.Forms.TextBox(); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.openFileDialog2 = new System.Windows.Forms.OpenFileDialog(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.SuspendLayout(); + // + // richTextBox1 + // + this.richTextBox1.Location = new System.Drawing.Point(1, 196); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.Size = new System.Drawing.Size(418, 342); + this.richTextBox1.TabIndex = 0; + this.richTextBox1.Text = ""; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.srcAssembly); + this.groupBox1.Controls.Add(this.srcCompiled); + this.groupBox1.Controls.Add(this.button1); + this.groupBox1.Controls.Add(this.textBox1); + this.groupBox1.Location = new System.Drawing.Point(1, 13); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(418, 74); + this.groupBox1.TabIndex = 1; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Source"; + // + // srcAssembly + // + this.srcAssembly.AutoSize = true; + this.srcAssembly.Location = new System.Drawing.Point(74, 47); + this.srcAssembly.Name = "srcAssembly"; + this.srcAssembly.Size = new System.Drawing.Size(69, 17); + this.srcAssembly.TabIndex = 3; + this.srcAssembly.Text = "Assembly"; + this.srcAssembly.UseVisualStyleBackColor = true; + // + // srcCompiled + // + this.srcCompiled.AutoSize = true; + this.srcCompiled.Checked = true; + this.srcCompiled.Location = new System.Drawing.Point(0, 47); + this.srcCompiled.Name = "srcCompiled"; + this.srcCompiled.Size = new System.Drawing.Size(68, 17); + this.srcCompiled.TabIndex = 2; + this.srcCompiled.TabStop = true; + this.srcCompiled.Text = "Compiled"; + this.srcCompiled.UseVisualStyleBackColor = true; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(373, 18); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(39, 23); + this.button1.TabIndex = 1; + this.button1.Text = "..."; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(0, 20); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(366, 20); + this.textBox1.TabIndex = 0; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.destAssembly); + this.groupBox2.Controls.Add(this.destCompiled); + this.groupBox2.Controls.Add(this.button2); + this.groupBox2.Controls.Add(this.textBox2); + this.groupBox2.Location = new System.Drawing.Point(1, 93); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(418, 68); + this.groupBox2.TabIndex = 2; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Dest"; + // + // destAssembly + // + this.destAssembly.AutoSize = true; + this.destAssembly.Checked = true; + this.destAssembly.Location = new System.Drawing.Point(74, 47); + this.destAssembly.Name = "destAssembly"; + this.destAssembly.Size = new System.Drawing.Size(69, 17); + this.destAssembly.TabIndex = 5; + this.destAssembly.TabStop = true; + this.destAssembly.Text = "Assembly"; + this.destAssembly.UseVisualStyleBackColor = true; + // + // destCompiled + // + this.destCompiled.AutoSize = true; + this.destCompiled.Location = new System.Drawing.Point(0, 47); + this.destCompiled.Name = "destCompiled"; + this.destCompiled.Size = new System.Drawing.Size(68, 17); + this.destCompiled.TabIndex = 4; + this.destCompiled.Text = "Compiled"; + this.destCompiled.UseVisualStyleBackColor = true; + this.destCompiled.CheckedChanged += new System.EventHandler(this.destCompiled_CheckedChanged); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(373, 19); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(39, 23); + this.button2.TabIndex = 3; + this.button2.Text = "..."; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(0, 21); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(366, 20); + this.textBox2.TabIndex = 2; + // + // button3 + // + this.button3.Location = new System.Drawing.Point(338, 167); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(75, 23); + this.button3.TabIndex = 3; + this.button3.Text = "Execute"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // textBox3 + // + this.textBox3.Location = new System.Drawing.Point(1, 169); + this.textBox3.Name = "textBox3"; + this.textBox3.Size = new System.Drawing.Size(331, 20); + this.textBox3.TabIndex = 4; + this.textBox3.Text = "N:\\Project\\Master\\Havok\\DsmAsm\\"; + // + // openFileDialog1 + // + this.openFileDialog1.FileName = "openFileDialog1"; + this.openFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog1_FileOk); + // + // openFileDialog2 + // + this.openFileDialog2.FileName = "openFileDialog2"; + this.openFileDialog2.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog2_FileOk); + // + // NodeHelper + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(416, 535); + this.Controls.Add(this.textBox3); + this.Controls.Add(this.button3); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.richTextBox1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "NodeHelper"; + this.Text = "Havok Kore Script Helper"; + this.Load += new System.EventHandler(this.NodeHelper_Load); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.RichTextBox richTextBox1; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.RadioButton srcAssembly; + private System.Windows.Forms.RadioButton srcCompiled; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.RadioButton destAssembly; + private System.Windows.Forms.RadioButton destCompiled; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.TextBox textBox3; + private System.Windows.Forms.OpenFileDialog openFileDialog1; + private System.Windows.Forms.OpenFileDialog openFileDialog2; + } +} + diff --git a/src/Form/NodeHelper.resx b/src/Form/NodeHelper.resx new file mode 100644 index 0000000..fae01cd --- /dev/null +++ b/src/Form/NodeHelper.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 157, 17 + + \ No newline at end of file diff --git a/src/Lua/Instructions/CallIInstruction.cs b/src/Lua/Instructions/CallIInstruction.cs index 167b67a..24efe9e 100644 --- a/src/Lua/Instructions/CallIInstruction.cs +++ b/src/Lua/Instructions/CallIInstruction.cs @@ -1,71 +1,71 @@ using HavokHelper.Lua.Instructions.Helpers; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace HavokHelper.Lua.Instructions -{ - public class CallIInstruction : BaseInstruction +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HavokHelper.Lua.Instructions +{ + public class CallIInstruction : BaseInstruction { - public override RegisterUsage GetAUsage() + public override RegisterUsage GetAUsage() { - return RegisterUsage.Register; + return RegisterUsage.Register; } - public override RegisterUsage GetBUsage() + public override RegisterUsage GetBUsage() { - return RegisterUsage.Numeric; + return RegisterUsage.Numeric; } - public override RegisterUsage GetCUsage() + public override RegisterUsage GetCUsage() { - return RegisterUsage.Numeric; + return RegisterUsage.Numeric; } public override String AStringify(Stub Stub) { - return null; + return null; } public override String BStringify(Stub Stub) { - return null; + return null; } public override String CStringify(Stub Stub) { - return null; + return null; } - public override bool HasC() - { - return true; - } - - public override String GetFullName() - { - return "HKS_OPCODE_CALL_I"; + public override bool HasC() + { + return true; + } + + public override String GetFullName() + { + return "HKS_OPCODE_CALL_I"; } public override bool Implemented() { - return true; + return true; } public override void Decompile(StringBuilder Buf, Stub OwnerStub, ref int Index) { - CallHelper.DecompileCall(false, this, Buf, OwnerStub, Index); + CallHelper.DecompileCall(false, this, Buf, OwnerStub, Index); } public override void AttainPseudoCode(StringBuilder Buf) - { - Buf.Append("TODO:"); - } - } + { + Buf.Append("TODO:"); + } + } } \ No newline at end of file diff --git a/src/Lua/Instructions/CallIR1Instruction.cs b/src/Lua/Instructions/CallIR1Instruction.cs index 892c149..74bb843 100644 --- a/src/Lua/Instructions/CallIR1Instruction.cs +++ b/src/Lua/Instructions/CallIR1Instruction.cs @@ -1,71 +1,71 @@ using HavokHelper.Lua.Instructions.Helpers; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace HavokHelper.Lua.Instructions -{ - public class CallIR1Instruction : BaseInstruction - { - public override RegisterUsage GetAUsage() - { - return RegisterUsage.Register; - } - - public override RegisterUsage GetBUsage() - { - return RegisterUsage.Numeric; - } - - public override RegisterUsage GetCUsage() - { - return RegisterUsage.Numeric; - } - - public override String AStringify(Stub Stub) - { - return null; - } - - public override String BStringify(Stub Stub) - { - return null; - } - - public override String CStringify(Stub Stub) - { - return null; - } - - public override bool HasC() - { - return true; - } - - public override String GetFullName() - { - return "HKS_OPCODE_CALL_I_R1"; - } - - public override bool Implemented() - { - return true; - } - +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HavokHelper.Lua.Instructions +{ + public class CallIR1Instruction : BaseInstruction + { + public override RegisterUsage GetAUsage() + { + return RegisterUsage.Register; + } + + public override RegisterUsage GetBUsage() + { + return RegisterUsage.Numeric; + } + + public override RegisterUsage GetCUsage() + { + return RegisterUsage.Numeric; + } + + public override String AStringify(Stub Stub) + { + return null; + } + + public override String BStringify(Stub Stub) + { + return null; + } + + public override String CStringify(Stub Stub) + { + return null; + } + + public override bool HasC() + { + return true; + } + + public override String GetFullName() + { + return "HKS_OPCODE_CALL_I_R1"; + } + + public override bool Implemented() + { + return true; + } + public override void Decompile(StringBuilder Buf, Stub OwnerStub, ref int Index) { - CallHelper.DecompileCall(true, this, Buf, OwnerStub, Index); - } - - public override void AttainPseudoCode(StringBuilder Buf) - { - Buf.Append("TODO:"); - } - } + CallHelper.DecompileCall(true, this, Buf, OwnerStub, Index); + } + + public override void AttainPseudoCode(StringBuilder Buf) + { + Buf.Append("TODO:"); + } + } } \ No newline at end of file diff --git a/src/Lua/Instructions/ClosureInstruction.cs b/src/Lua/Instructions/ClosureInstruction.cs index ab664d4..bd9ad7b 100644 --- a/src/Lua/Instructions/ClosureInstruction.cs +++ b/src/Lua/Instructions/ClosureInstruction.cs @@ -1,70 +1,70 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace HavokHelper.Lua.Instructions -{ - public class ClosureInstruction : BaseInstruction - { - public override RegisterUsage GetAUsage() - { - return RegisterUsage.Register; - } - - public override RegisterUsage GetBUsage() - { - return RegisterUsage.Numeric; - } - - public override RegisterUsage GetCUsage() - { - return RegisterUsage.NotImplemented; - } - - public override String AStringify(Stub Stub) - { - return null; - } - - public override String BStringify(Stub Stub) - { - return null; - } - - public override String CStringify(Stub Stub) - { - return null; - } - - public override bool HasC() - { - return false; - } - - public override String GetFullName() - { - return "HKS_OPCODE_CLOSURE"; - } - - public override bool Implemented() - { - return true; - } - - public override void Decompile(StringBuilder Buf, Stub OwnerStub, ref int Index) +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HavokHelper.Lua.Instructions +{ + public class ClosureInstruction : BaseInstruction + { + public override RegisterUsage GetAUsage() + { + return RegisterUsage.Register; + } + + public override RegisterUsage GetBUsage() + { + return RegisterUsage.Numeric; + } + + public override RegisterUsage GetCUsage() + { + return RegisterUsage.NotImplemented; + } + + public override String AStringify(Stub Stub) + { + return null; + } + + public override String BStringify(Stub Stub) + { + return null; + } + + public override String CStringify(Stub Stub) + { + return null; + } + + public override bool HasC() { - Buf.Append(String.Format("var_{0}\t= {1}", A, OwnerStub.Closures[B].AsFnString())); - } - - public override void AttainPseudoCode(StringBuilder Buf) + return false; + } + + public override String GetFullName() { - String ahh = @" + return "HKS_OPCODE_CLOSURE"; + } + + public override bool Implemented() + { + return true; + } + + public override void Decompile(StringBuilder Buf, Stub OwnerStub, ref int Index) + { + Buf.Append(String.Format("var_{0}\t= {1}", A, OwnerStub.Closures[B].AsFnString())); + } + + public override void AttainPseudoCode(StringBuilder Buf) + { + String ahh = @" a = R[a] = dest b = PROTO(R[b]) = closure @@ -100,9 +100,9 @@ namespace HavokHelper.Lua.Instructions a->m_method->m_upvals[i] = target; // R[nextInstruction b] I think ip ++; - } -"; - Buf.Append(ahh); - } - } + } +"; + Buf.Append(ahh); + } + } } \ No newline at end of file diff --git a/src/Lua/Instructions/DivBkInstruction.cs b/src/Lua/Instructions/DivBkInstruction.cs index 70c0a50..ed00bf4 100644 --- a/src/Lua/Instructions/DivBkInstruction.cs +++ b/src/Lua/Instructions/DivBkInstruction.cs @@ -1,70 +1,70 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace HavokHelper.Lua.Instructions -{ - public class DivBkInstruction : BaseInstruction +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HavokHelper.Lua.Instructions +{ + public class DivBkInstruction : BaseInstruction { - public override RegisterUsage GetAUsage() + public override RegisterUsage GetAUsage() { - return RegisterUsage.Register; + return RegisterUsage.Register; } - public override RegisterUsage GetBUsage() + public override RegisterUsage GetBUsage() { - return RegisterUsage.Constant; + return RegisterUsage.Constant; } - public override RegisterUsage GetCUsage() + public override RegisterUsage GetCUsage() { - return RegisterUsage.ConstantRegister; + return RegisterUsage.ConstantRegister; } public override String AStringify(Stub Stub) { - return null; + return null; } public override String BStringify(Stub Stub) { - return null; + return null; } public override String CStringify(Stub Stub) { - return null; + return null; } - public override bool HasC() - { - return true; - } - - public override String GetFullName() - { - return "HKS_OPCODE_DIV_BK"; + public override bool HasC() + { + return true; + } + + public override String GetFullName() + { + return "HKS_OPCODE_DIV_BK"; } public override bool Implemented() { - return true; + return true; } public override void Decompile(StringBuilder Buf, Stub OwnerStub, ref int Index) { - Buf.Append(String.Format("{0}\t= {1} / {2}", OwnerStub.DecompileInstruction_A(this), OwnerStub.DecompileInstruction_B(this), OwnerStub.DecompileInstruction_C(this))); + Buf.Append(String.Format("{0}\t= {1} / {2}", OwnerStub.DecompileInstruction_A(this), OwnerStub.DecompileInstruction_B(this), OwnerStub.DecompileInstruction_C(this))); } public override void AttainPseudoCode(StringBuilder Buf) - { - Buf.Append("TODO:"); - } - } + { + Buf.Append("TODO:"); + } + } } \ No newline at end of file diff --git a/src/Lua/Instructions/DivInstruction.cs b/src/Lua/Instructions/DivInstruction.cs index 8e91bd7..682f872 100644 --- a/src/Lua/Instructions/DivInstruction.cs +++ b/src/Lua/Instructions/DivInstruction.cs @@ -1,70 +1,70 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace HavokHelper.Lua.Instructions -{ - public class DivInstruction : BaseInstruction +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HavokHelper.Lua.Instructions +{ + public class DivInstruction : BaseInstruction { - public override RegisterUsage GetAUsage() + public override RegisterUsage GetAUsage() { - return RegisterUsage.Register; + return RegisterUsage.Register; } - public override RegisterUsage GetBUsage() + public override RegisterUsage GetBUsage() { - return RegisterUsage.ConstantRegister; + return RegisterUsage.ConstantRegister; } - public override RegisterUsage GetCUsage() + public override RegisterUsage GetCUsage() { - return RegisterUsage.ConstantRegister; + return RegisterUsage.ConstantRegister; } public override String AStringify(Stub Stub) { - return null; + return null; } public override String BStringify(Stub Stub) { - return null; + return null; } public override String CStringify(Stub Stub) { - return null; + return null; } - public override bool HasC() - { - return true; - } - - public override String GetFullName() - { - return "HKS_OPCODE_DIV"; + public override bool HasC() + { + return true; + } + + public override String GetFullName() + { + return "HKS_OPCODE_DIV"; } public override bool Implemented() { - return true; + return true; } public override void Decompile(StringBuilder Buf, Stub OwnerStub, ref int Index) { - Buf.Append(String.Format("{0}\t= {1} / {2}", OwnerStub.DecompileInstruction_A(this), OwnerStub.DecompileInstruction_B(this), OwnerStub.DecompileInstruction_C(this))); + Buf.Append(String.Format("{0}\t= {1} / {2}", OwnerStub.DecompileInstruction_A(this), OwnerStub.DecompileInstruction_B(this), OwnerStub.DecompileInstruction_C(this))); } public override void AttainPseudoCode(StringBuilder Buf) - { - Buf.Append("TODO:"); - } - } + { + Buf.Append("TODO:"); + } + } } \ No newline at end of file diff --git a/src/Lua/Instructions/Helpers/CallHelper.cs b/src/Lua/Instructions/Helpers/CallHelper.cs index 62a2124..3e1983e 100644 --- a/src/Lua/Instructions/Helpers/CallHelper.cs +++ b/src/Lua/Instructions/Helpers/CallHelper.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; namespace HavokHelper.Lua.Instructions.Helpers { @@ -21,11 +22,11 @@ namespace HavokHelper.Lua.Instructions.Helpers if (Cur.C > 1) { int ReturnParameters; - ReturnParameters = Cur.C - 1; + ReturnParameters = Cur.C - 1; // TODO: could be -2 if (ReturnParameters != 0) { for (int I = 0; I < ReturnParameters; I++) - ReturnVals.Append("val_" + I + ", "); + ReturnVals.Append("var_" + (I + Cur.A) + ", "); ReturnVals.Remove(ReturnVals.Length - 2, 2); ReturnVals.Append("\t= "); } @@ -34,11 +35,11 @@ namespace HavokHelper.Lua.Instructions.Helpers { ReturnVals.Append("--[[top = last_result+1]]"); } - - for (int Reg = Cur.A + 1; Reg < Cur.A + Cur.B; Reg++) - Parameters.Append(String.Format("val_{0}, ", Reg)); - if (Parameters.Length != 0) + for (int Reg = Cur.A + 1; Reg < Cur.A + Cur.B; Reg++) + Parameters.Append(String.Format("var_{0}, ", Reg)); + + if (Parameters.Length != 0) Parameters.Remove(Parameters.Length - 2, 2); Buf.Append(String.Format("{0}{1}({2})", ReturnVals.ToString(), FuncName, Parameters.ToString())); diff --git a/src/Lua/Instructions/PowInstruction.cs b/src/Lua/Instructions/PowInstruction.cs index 34e8adc..e8a2e1d 100644 --- a/src/Lua/Instructions/PowInstruction.cs +++ b/src/Lua/Instructions/PowInstruction.cs @@ -1,70 +1,70 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace HavokHelper.Lua.Instructions -{ - public class PowInstruction : BaseInstruction - { - public override RegisterUsage GetAUsage() - { - return RegisterUsage.Register; - } - - public override RegisterUsage GetBUsage() - { - return RegisterUsage.ConstantRegister; - } - - public override RegisterUsage GetCUsage() - { - return RegisterUsage.ConstantRegister; - } - - public override String AStringify(Stub Stub) - { - return null; - } - - public override String BStringify(Stub Stub) - { - return null; - } - - public override String CStringify(Stub Stub) - { - return null; - } - - public override bool HasC() - { - return true; - } - - public override String GetFullName() - { - return "HKS_OPCODE_POW"; - } - - public override bool Implemented() - { - return true; - } - - public override void Decompile(StringBuilder Buf, Stub OwnerStub, ref int Index) +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HavokHelper.Lua.Instructions +{ + public class PowInstruction : BaseInstruction + { + public override RegisterUsage GetAUsage() + { + return RegisterUsage.Register; + } + + public override RegisterUsage GetBUsage() + { + return RegisterUsage.ConstantRegister; + } + + public override RegisterUsage GetCUsage() + { + return RegisterUsage.ConstantRegister; + } + + public override String AStringify(Stub Stub) + { + return null; + } + + public override String BStringify(Stub Stub) + { + return null; + } + + public override String CStringify(Stub Stub) + { + return null; + } + + public override bool HasC() + { + return true; + } + + public override String GetFullName() + { + return "HKS_OPCODE_POW"; + } + + public override bool Implemented() + { + return true; + } + + public override void Decompile(StringBuilder Buf, Stub OwnerStub, ref int Index) { Buf.Append(String.Format("{0}\t= {1} ^ {2}", OwnerStub.DecompileInstruction_A(this), OwnerStub.DecompileInstruction_B(this), OwnerStub.DecompileInstruction_C(this))); } - public override void AttainPseudoCode(StringBuilder Buf) - { - - } - } + public override void AttainPseudoCode(StringBuilder Buf) + { + + } + } } \ No newline at end of file diff --git a/src/Lua/Instructions/SelfInstruction.cs b/src/Lua/Instructions/SelfInstruction.cs index d6e95ac..19d48ac 100644 --- a/src/Lua/Instructions/SelfInstruction.cs +++ b/src/Lua/Instructions/SelfInstruction.cs @@ -1,72 +1,72 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace HavokHelper.Lua.Instructions -{ - public class SelfInstruction : BaseInstruction - { - public override RegisterUsage GetAUsage() - { - return RegisterUsage.Register; - } - - public override RegisterUsage GetBUsage() - { - return RegisterUsage.Register; - } - - public override RegisterUsage GetCUsage() - { - return RegisterUsage.ConstantRegister; - } - - public override String AStringify(Stub Stub) - { - return null; - } - - public override String BStringify(Stub Stub) - { - return null; - } - - public override String CStringify(Stub Stub) - { - return null; - } - - public override bool HasC() - { - return true; - } - - public override String GetFullName() - { - return "HKS_OPCODE_SELF"; - } - - public override bool Implemented() - { - return true; - } - - public override void Decompile(StringBuilder Buf, Stub OwnerStub, ref int Index) +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HavokHelper.Lua.Instructions +{ + public class SelfInstruction : BaseInstruction + { + public override RegisterUsage GetAUsage() + { + return RegisterUsage.Register; + } + + public override RegisterUsage GetBUsage() + { + return RegisterUsage.Register; + } + + public override RegisterUsage GetCUsage() + { + return RegisterUsage.ConstantRegister; + } + + public override String AStringify(Stub Stub) + { + return null; + } + + public override String BStringify(Stub Stub) + { + return null; + } + + public override String CStringify(Stub Stub) + { + return null; + } + + public override bool HasC() + { + return true; + } + + public override String GetFullName() + { + return "HKS_OPCODE_SELF"; + } + + public override bool Implemented() + { + return true; + } + + public override void Decompile(StringBuilder Buf, Stub OwnerStub, ref int Index) { Buf.Append( String.Format("var_{0}\t= {1}\n", A + 1, OwnerStub.DecompileInstruction_B(this)) + - String.Format("{0}\t= {1}[{2}]\n", OwnerStub.DecompileInstruction_A(this), OwnerStub.DecompileInstruction_B(this), OwnerStub.DecompileInstruction_C(this)) + - String.Format("R1\t\t= {0}", OwnerStub.DecompileInstruction_A(this))); - } - - public override void AttainPseudoCode(StringBuilder Buf) - { - Buf.Append( + String.Format("{0}\t= {1}[{2}]\n", OwnerStub.DecompileInstruction_A(this), OwnerStub.DecompileInstruction_B(this), OwnerStub.DecompileInstruction_C(this)) + + String.Format("R1\t\t= {0}", OwnerStub.DecompileInstruction_A(this))); + } + + public override void AttainPseudoCode(StringBuilder Buf) + { + Buf.Append( "R1\t\t= dest_r1 \n" + "A\t= R[A]\t= dest_a \n" + "A_one\t= R[A + 1]= dest_a_one \n" + @@ -75,7 +75,7 @@ namespace HavokHelper.Lua.Instructions " \n" + "dest_a_one\t= table \n" + "dest_a\t\t= table[key] \n" + - "dest_r1\t\t= dest_a"); - } - } + "dest_r1\t\t= dest_a"); + } + } } \ No newline at end of file diff --git a/src/Parser/JSParserPort.cs b/src/Parser/JSParserPort.cs index 034163c..74c0876 100644 --- a/src/Parser/JSParserPort.cs +++ b/src/Parser/JSParserPort.cs @@ -12,7 +12,7 @@ namespace HavokHelper.src.Parser { // port of https://bitbucket.org/codt6/luadsm/src/master/asm/assembler.js // asm derived from https://bitbucket.org/codt6/luadsm/src/master/asm/disassembler.js - // this shit is ugly as fuck lol + // this really needs to be rewritten public class JSParserPort { @@ -32,8 +32,8 @@ namespace HavokHelper.src.Parser protected static LineData[] ParseLine(String line) { - if (line.IndexOf(';') != -1) - line = line.Substring(0, line.IndexOf(';')); + //if (line.IndexOf(';') != -1) + // line = line.Substring(0, line.IndexOf(';')); String[] strs = line.Replace('\t', ' ') // convert tabs into spaces .Replace(',', ' ') // convert ,'s into spaces @@ -49,11 +49,20 @@ namespace HavokHelper.src.Parser bool Hack = false; int I = 0; - strs.ToArray().ToList().ForEach((item) => + StringBuilder sb = new StringBuilder(); + foreach (var item in strs) { - if (Hack) return; LineData data = new LineData(); - if (item.Length == 0) return; + + if (item.Length == 0) + continue; + + if (Hack) + { + sb.Append(item); + continue; + } + ret[I++] = data; data.Raw = item; @@ -68,8 +77,17 @@ namespace HavokHelper.src.Parser data.BoolVal = item.Equals("true"); data.BoolPresent = true; } + else if (item.StartsWith("\"")) + { + sb.Append(item.Substring(1)); + Hack = true; + } + } - }); + if (Hack) + { + ret[I - 1].Raw = sb.ToString().Substring(0, sb.Length - 1); + } if (0 == I) return null;