Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions GTA V Script Decompiler/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ public void decodeinstruction()
case Instruction.PushString:
tempstring = Stack.PopLit();

if (!Utils.intparse(tempstring, out tempint))
if (!Utils.IntParse(tempstring, out tempint))
Stack.Push("StringTable(" + tempstring + ")", Stack.DataType.StringPtr);
else if (!this.Scriptfile.StringTable.ContainsKey(tempint))
Stack.Push("StringTable(" + tempstring + ")", Stack.DataType.StringPtr);
Expand Down Expand Up @@ -1253,7 +1253,7 @@ public void returncheck(string temp)
return;
}
int tempint;
if (Utils.intparse(temp, out tempint))
if (Utils.IntParse(temp, out tempint))
{
ReturnType = Types.gettype(Stack.DataType.Int);
return;
Expand Down Expand Up @@ -1383,7 +1383,7 @@ public void decodeinsructionsforvarinfo()
if (Stack.TopType == Stack.DataType.Int)
{
tempstring = Stack.PopLit();
if (Utils.intparse(tempstring, out tempint))
if (Utils.IntParse(tempstring, out tempint))
{
Stack.PeekVar(0).Value = tempint;
}
Expand All @@ -1400,7 +1400,7 @@ public void decodeinsructionsforvarinfo()
if (Stack.TopType == Stack.DataType.Int)
{
tempstring = Stack.PopLit();
if (Utils.intparse(tempstring, out tempint))
if (Utils.IntParse(tempstring, out tempint))
{
Stack.PeekVar(0).Value = tempint;
}
Expand All @@ -1427,7 +1427,7 @@ public void decodeinsructionsforvarinfo()
case Instruction.pArray1:
case Instruction.pArray2:

if (!Utils.intparse(Stack.PeekItem(1), out tempint))
if (!Utils.IntParse(Stack.PeekItem(1), out tempint))
{
tempint = -1;
}
Expand All @@ -1436,14 +1436,14 @@ public void decodeinsructionsforvarinfo()
Stack.Op_ArrayGetP(ins.GetOperandsAsUInt); break;
case Instruction.ArrayGet1:
case Instruction.ArrayGet2:
if (!Utils.intparse(Stack.PeekItem(1), out tempint))
if (!Utils.IntParse(Stack.PeekItem(1), out tempint))
{
tempint = -1;
}
CheckArray(ins.GetOperandsAsUInt, tempint); Stack.Op_ArrayGet(ins.GetOperandsAsUInt); break;
case Instruction.ArraySet1:
case Instruction.ArraySet2:
if (!Utils.intparse(Stack.PeekItem(1), out tempint))
if (!Utils.IntParse(Stack.PeekItem(1), out tempint))
{
tempint = -1;
}
Expand Down Expand Up @@ -1482,7 +1482,7 @@ public void decodeinsructionsforvarinfo()
{
tempstring = Stack.PopLit();
if (ins.GetOperandsAsUInt > Pcount)
if (Utils.intparse(tempstring, out tempint))
if (Utils.IntParse(tempstring, out tempint))
{
GetFrameVar(ins.GetOperandsAsUInt).Value = tempint;
}
Expand Down
6 changes: 4 additions & 2 deletions GTA V Script Decompiler/GTA V Script Decompiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<ItemGroup>
<Reference Include="FastColoredTextBox">
<HintPath>..\FastColoredTextBox.dll</HintPath>
<Reference Include="FastColoredTextBox, Version=2.16.11.0, Culture=neutral, PublicKeyToken=fb8aa12b994ef61b, processorArchitecture=MSIL">
<HintPath>..\packages\FCTB.2.16.11.0\lib\FastColoredTextBox.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -132,6 +133,7 @@
<DesignTime>True</DesignTime>
</Compile>
<None Include="bin\Debug\natives.dat" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
4 changes: 2 additions & 2 deletions GTA V Script Decompiler/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -921,13 +921,13 @@ private void findHashFromStringsToolStripMenuItem_Click(object sender, EventArgs
updatestatus($"No Strings Found, Time taken: {DateTime.Now - Start}");
else
{
updatestatus($"Founs {FoundStrings.Count} strings, Time taken: {DateTime.Now - Start}");
updatestatus($"Found {FoundStrings.Count} strings, Time taken: {DateTime.Now - Start}");
FoundStrings.Sort((x, y) => x.Item1.CompareTo(y.Item1));
using (StreamWriter oFile = File.CreateText(Path.Combine(fsd.SelectedPath, "STRINGS.txt")))
{
foreach (Tuple<uint, string> Item in FoundStrings)
{
oFile.WriteLine($"0x{Utils.formathexhash(Item.Item1)} : \"{Item.Item2}\"");
oFile.WriteLine($"{Utils.FormatHexHash(Item.Item1)} : \"{Item.Item2}\"");
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions GTA V Script Decompiler/NativeFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public x64NativeFile(Stream Nativefile)
continue;
string val = data[0];
string nat = (Program.Show_Nat_Namespace ? (data[1] + "::") : "") + data[2];

// force uppercase
nat = nat.ToUpper();

ulong value;
if (ulong.TryParse(val, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out value))
{
Expand Down
2 changes: 1 addition & 1 deletion GTA V Script Decompiler/ScriptHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static ScriptHeader GeneratePcHeader(Stream scriptStream)
ScriptHeader header = new ScriptHeader();
IO.Reader reader = new IO.Reader(scriptStream, false);
scriptStream.Seek(0, SeekOrigin.Begin);
header.RSC7Offset = (reader.ReadUInt32() == 0x52534337) ? 0x10 : 0x0;
header.RSC7Offset = (reader.SReadUInt32() == 0x52534337) ? 0x10 : 0x0;
scriptStream.Seek(header.RSC7Offset, SeekOrigin.Begin);
header.Magic = reader.ReadInt32(); //0x0
reader.Advance();
Expand Down
35 changes: 27 additions & 8 deletions GTA V Script Decompiler/Stack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Push(params int[] values)
}
public void PushHexInt(uint value)
{
_stack.Add(new StackValue(StackValue.Type.Literal, Utils.formathexhash(value), DataType.Int));
_stack.Add(new StackValue(StackValue.Type.Literal, Utils.FormatHexHash(value), DataType.Int));
}
public void PushVar(string value, Vars_Info.Var Variable)
{
Expand Down Expand Up @@ -204,6 +204,13 @@ public void Dup()
else
Push(top);
}
public string PopString()
{
StackValue val = Pop();
if ((val.ItemType == StackValue.Type.Literal) || (val.ItemType == StackValue.Type.Pointer))
return val.Value;
throw new Exception("Not a string item received");
}
public string PopLit()
{
StackValue val = Pop();
Expand Down Expand Up @@ -815,7 +822,7 @@ public void Op_And()
throw new Exception("Not a literal item recieved");
if (s1.Datatype == DataType.Bool || s2.Datatype == DataType.Bool)
PushCond("(" + s2.Value + " && " + s1.Value + ")");
else if (Utils.intparse(s1.Value, out temp) || Utils.intparse(s2.Value, out temp))
else if (Utils.IntParse(s1.Value, out temp) || Utils.IntParse(s2.Value, out temp))
Push(s2.Value + " & " + s1.Value, DataType.Int);
else
Push("(" + s2.Value + " && " + s1.Value + ")");
Expand All @@ -829,7 +836,7 @@ public void Op_Or()
throw new Exception("Not a literal item recieved");
if (s1.Datatype == DataType.Bool || s2.Datatype == DataType.Bool)
PushCond("(" + s2.Value + " || " + s1.Value + ")");
else if (Utils.intparse(s1.Value, out temp) || Utils.intparse(s2.Value, out temp))
else if (Utils.IntParse(s1.Value, out temp) || Utils.IntParse(s2.Value, out temp))
Push(s2.Value + " | " + s1.Value, DataType.Int);
else
Push("(" + s2.Value + " || " + s1.Value + ")");
Expand Down Expand Up @@ -888,7 +895,7 @@ public void Op_GetImmP()
{
string immediate = PopLit();
int temp;
if (Utils.intparse(immediate, out temp))
if (Utils.IntParse(immediate, out temp))
{
if (Peek().ItemType == StackValue.Type.Pointer)
Push(new StackValue(StackValue.Type.Pointer, PopPointerRef() + ".f_" + (Program.Hex_Index ? temp.ToString("X") : temp.ToString())));
Expand Down Expand Up @@ -965,7 +972,7 @@ public void Op_ToStack()
pointer = PopPointerRef();
count = PopLit();

if (!Utils.intparse(count, out amount))
if (!Utils.IntParse(count, out amount))
throw new Exception("Expecting the amount to push");
PushString(pointer, amount);
}
Expand All @@ -974,7 +981,7 @@ public void Op_ToStack()
pointer = PopPointerRef();
count = PopLit();

if (!Utils.intparse(count, out amount))
if (!Utils.IntParse(count, out amount))
throw new Exception("Expecting the amount to push");
PushStruct(pointer, amount);
}
Expand Down Expand Up @@ -1098,7 +1105,7 @@ public string Op_FromStack()
pointer = PopPointerRef();
count = PopLit();
int amount;
if (!Utils.intparse(count, out amount))
if (!Utils.IntParse(count, out amount))
throw new Exception("Expecting the amount to push");
string res = pointer + " = {";
foreach (StackValue val in PopList(amount))
Expand Down Expand Up @@ -1147,21 +1154,33 @@ public void Op_Hash()
}
public string op_strcopy(int size)
{
return $"{PopString()} /*{size}*/ = {PopString()};";

/*
string pointer = PopPointer();
string pointer2 = PopPointer();
return "StringCopy(" + pointer + ", " + pointer2 + ", " + size.ToString() + ");";
*/
}
public string op_stradd(int size)
{
return $"{PopString()} /*{size}*/ += {PopString()};";

/*
string pointer = PopPointer();
string pointer2 = PopPointer();
return "StringConCat(" + pointer + ", " + pointer2 + ", " + size.ToString() + ");";
*/
}
public string op_straddi(int size)
{
return op_stradd(size);

/*
string pointer = PopPointer();
string inttoadd = PopLit();
return "StringIntConCat(" + pointer + ", " + inttoadd + ", " + size.ToString() + ");";
*/
}
public string op_itos(int size)
{
Expand All @@ -1175,7 +1194,7 @@ public string op_sncopy()
string value = PopLit();
string count = PopLit();
int amount;
if (!Utils.intparse(count, out amount))
if (!Utils.IntParse(count, out amount))
throw new Exception("Int Stack value expected");
return "MemCopy(" + pointer + ", " + "{" + PopListForCall(amount) + "}, " + value + ");";
}
Expand Down
73 changes: 54 additions & 19 deletions GTA V Script Decompiler/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -23,63 +24,97 @@ public static uint jenkins_one_at_a_time_hash(string str)
hash += (hash << 15);
return hash;
}
public static string formathexhash(uint hash)
public static string FormatHexHash(uint hash)
{
string hashres = hash.ToString("X");
while (hashres.Length < 8)
hashres = "0" + hashres;
return hashres;
return $"0x{hash:X8}";
}
public static float SwapEndian(float num)
{
var b = BitConverter.GetBytes(num);

return (float)((b[3] << 0) | (b[2] << 8) | (b[1] << 16) | (b[0] << 24));
/*
byte[] data = BitConverter.GetBytes(num);
Array.Reverse(data);
return BitConverter.ToSingle(data, 0);
}
*/
}
public static uint SwapEndian(uint num)
{
var b = BitConverter.GetBytes(num);

return (uint)((b[3] << 0) | (b[2] << 8) | (b[1] << 16) | (b[0] << 24));
/*
byte[] data = BitConverter.GetBytes(num);
Array.Reverse(data);
return BitConverter.ToUInt32(data, 0);
}
*/
}
public static int SwapEndian(int num)
{
var b = BitConverter.GetBytes(num);

return (int)((b[3] << 0) | (b[2] << 8) | (b[1] << 16) | (b[0] << 24));
/*
byte[] data = BitConverter.GetBytes(num);
Array.Reverse(data);
return BitConverter.ToInt32(data, 0);
}
*/
}
public static ulong SwapEndian(ulong num)
{
var b = BitConverter.GetBytes(num);

return (ulong)((b[7] << 0) | (b[6] << 8) | (b[5] << 16) | (b[4] << 24) |
(b[3] << 32) | (b[2] << 40) | (b[1] << 48) | (b[0] << 56));
/*
byte[] data = BitConverter.GetBytes(num);
Array.Reverse(data);
return BitConverter.ToUInt64(data, 0);
}
*/
}
public static long SwapEndian(long num)
{
var b = BitConverter.GetBytes(num);

return (long)((b[7] << 0) | (b[6] << 8) | (b[5] << 16) | (b[4] << 24) |
(b[3] << 32) | (b[2] << 40) | (b[1] << 48) | (b[0] << 56));

/*
byte[] data = BitConverter.GetBytes(num);
Array.Reverse(data);
return BitConverter.ToInt64(data, 0);
}
*/
}
public static ushort SwapEndian(ushort num)
{
var b = BitConverter.GetBytes(num);

return (ushort)((b[1] << 0) | (b[0] << 8));
/*
byte[] data = BitConverter.GetBytes(num);
Array.Reverse(data);
return BitConverter.ToUInt16(data, 0);
}
*/
}
public static short SwapEndian(short num)
{
var b = BitConverter.GetBytes(num);

return (short)((b[1] << 0) | (b[0] << 8));
/*
byte[] data = BitConverter.GetBytes(num);
Array.Reverse(data);
return BitConverter.ToInt16(data, 0);
}
public static bool intparse(string temp, out int value)
*/
}
public static bool IntParse(string temp, out int value)
{
if (Program.getIntType == Program.IntType._hex)
{
return int.TryParse(temp.Substring(2), System.Globalization.NumberStyles.HexNumber, new System.Globalization.CultureInfo("en-gb"), out value);
}
else
return int.TryParse(temp, out value);
var isHex = (Program.getIntType == Program.IntType._hex);
var numberStyle = (isHex) ? NumberStyles.HexNumber : NumberStyles.Integer;
var str = (isHex) ? temp.Substring(2) : temp;

return int.TryParse(str, numberStyle, new CultureInfo("en-US"), out value);
}

}
Expand Down
4 changes: 4 additions & 0 deletions GTA V Script Decompiler/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FCTB" version="2.16.11.0" targetFramework="net45" />
</packages>
Binary file added packages/FCTB.2.16.11.0/FCTB.2.16.11.0.nupkg
Binary file not shown.
Loading