2022-04-24 16:05:27 -07:00
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.Drawing ;
using System.Globalization ;
using System.IO ;
using System.IO.Compression ;
using System.Linq ;
using System.Runtime.CompilerServices ;
using System.Text ;
using System.Threading ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
using DarkUI.Controls ;
using DarkUI.Forms ;
internal class ClassEditor
{
2022-04-27 04:52:09 -07:00
public List < string > Ecus_Definitions_Compatible = new List < string > ( ) ;
//Variables for loaded rom definition
public List < string > DefinitionsLocationsX = new List < string > ( ) ;
public List < string > DefinitionsLocationsY = new List < string > ( ) ;
public List < string > DefinitionsLocationsTable = new List < string > ( ) ;
public List < string > DefinitionsMathX = new List < string > ( ) ;
public List < string > DefinitionsMathY = new List < string > ( ) ;
public List < string > DefinitionsMathTable = new List < string > ( ) ;
2022-05-07 17:39:50 -07:00
public List < string > DefinitionsMathXInverted = new List < string > ( ) ;
public List < string > DefinitionsMathYInverted = new List < string > ( ) ;
public List < string > DefinitionsMathTableInverted = new List < string > ( ) ;
2022-04-27 04:52:09 -07:00
public List < string > DefinitionsFormatX = new List < string > ( ) ;
public List < string > DefinitionsFormatY = new List < string > ( ) ;
public List < string > DefinitionsFormatTable = new List < string > ( ) ;
public List < bool > DefinitionsIsSingleByteX = new List < bool > ( ) ;
public List < bool > DefinitionsIsSingleByteY = new List < bool > ( ) ;
public List < bool > DefinitionsIsSingleByteTable = new List < bool > ( ) ;
public List < string > DefinitionsName = new List < string > ( ) ;
public List < string > DefinitionsUnit1 = new List < string > ( ) ;
public List < string > DefinitionsUnit2 = new List < string > ( ) ;
public List < string > DefinitionsTableSize = new List < string > ( ) ;
public List < float > DefinitionsValueMin = new List < float > ( ) ;
public List < float > DefinitionsValueMax = new List < float > ( ) ;
public List < double > DefinitionsChangeAmount = new List < double > ( ) ;
public List < string > DefinitionsHeaders = new List < string > ( ) ;
2022-05-03 09:25:40 -07:00
public List < bool > DefinitionsIsXYInverted = new List < bool > ( ) ;
public List < bool > DefinitionsIsTableInverted = new List < bool > ( ) ;
2022-05-07 17:39:50 -07:00
public List < bool > DefinitionsIsReadOnly = new List < bool > ( ) ;
public List < bool > DefinitionsIsUntested = new List < bool > ( ) ;
public List < bool > DefinitionsIsNotDefined = new List < bool > ( ) ;
public int SelectedROMLocation ;
public int SelectedTableSize ;
public int SelectedTableIndexInDefinitions ;
public bool IsTableLoadedCorrectly = false ;
public bool CanReloadTablesValues = false ;
public string string_ECU_Name ;
public byte [ ] ROM_Bytes ;
public string AllROMDifferences ;
public string AllROMDifferencesRedo ;
public bool ValuesChanged = false ;
public bool IsSingleByteX = false ;
public bool IsSingleByteY = false ;
public bool IsSingleByteTable = false ;
public int [ ] BufferValuesArray = new int [ 200 ] ;
public int [ ] BufferTableSize = new int [ 2 ] ;
public string BufferMath = "" ;
private string LastMathDoneCheck = "" ;
2022-04-24 16:05:27 -07:00
private Editortable Editortable_0 ;
internal ClassEditor ( ref Editortable Editortable_1 )
{
Editortable_0 = Editortable_1 ;
}
public float smethod_1 ( )
{
return Editortable . float_0 ;
}
2022-04-27 04:52:09 -07:00
public string ValueIncDec ( int RowIndex , int CellIndex , bool Increasing , bool Multiply4x )
2022-04-24 16:05:27 -07:00
{
float num = this . smethod_1 ( ) ;
string format = "0" ;
2022-04-27 04:52:09 -07:00
string text = Editortable_0 . dataGridView_0 . Rows [ RowIndex ] . Cells [ CellIndex ] . Value . ToString ( ) ;
2022-05-07 17:39:50 -07:00
if ( text . Contains ( "." ) | | text . Contains ( "," ) )
2022-04-24 16:05:27 -07:00
{
2022-05-07 17:39:50 -07:00
string [ ] SplittedCmd = new string [ 0 ] ;
if ( text . Contains ( "." ) ) SplittedCmd = text . Split ( '.' ) ;
if ( text . Contains ( "," ) ) SplittedCmd = text . Split ( ',' ) ;
int FormatLenght = SplittedCmd [ 1 ] . Length ;
if ( FormatLenght = = 0 ) format = "0.0" ;
if ( FormatLenght = = 1 ) format = "0.0" ;
if ( FormatLenght = = 2 ) format = "0.00" ;
if ( FormatLenght = = 3 ) format = "0.000" ;
if ( FormatLenght = = 4 ) format = "0.0000" ;
2022-04-24 16:05:27 -07:00
}
2022-04-27 04:52:09 -07:00
if ( Multiply4x )
2022-04-24 16:05:27 -07:00
{
num * = 4f ;
}
2022-04-27 04:52:09 -07:00
if ( Increasing )
2022-04-24 16:05:27 -07:00
{
return ( float . Parse ( text ) + num ) . ToString ( format ) ;
}
return ( float . Parse ( text ) - num ) . ToString ( format ) ;
}
2022-04-27 04:52:09 -07:00
public void IncDecreaseSelection ( bool Decreasing , bool HoldShift )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
if ( ! Decreasing )
2022-04-24 16:05:27 -07:00
{
int num3 = 0 ;
int num4 = 0 ;
int j = 0 ;
while ( j < Editortable_0 . dataGridView_0 . Rows . Count )
{
if ( Editortable_0 . dataGridView_0 . Rows [ j ] . Cells [ num4 ] . Selected )
{
2022-04-27 04:52:09 -07:00
Editortable_0 . dataGridView_0 . Rows [ j ] . Cells [ num4 ] . Value = this . ValueIncDec ( j , num4 , true , HoldShift ) ;
2022-04-24 16:05:27 -07:00
}
if ( num4 = = Editortable_0 . dataGridView_0 . Columns . Count - 1 )
{
num4 = 0 ;
j + + ;
}
else
{
num4 + + ;
}
num3 + + ;
}
}
2022-04-27 04:52:09 -07:00
else
2022-04-24 16:05:27 -07:00
{
int num5 = 0 ;
int num6 = 0 ;
int k = 0 ;
while ( k < Editortable_0 . dataGridView_0 . Rows . Count )
{
if ( Editortable_0 . dataGridView_0 . Rows [ k ] . Cells [ num6 ] . Selected )
{
2022-04-27 04:52:09 -07:00
Editortable_0 . dataGridView_0 . Rows [ k ] . Cells [ num6 ] . Value = this . ValueIncDec ( k , num6 , false , HoldShift ) ;
2022-04-24 16:05:27 -07:00
}
if ( num6 = = Editortable_0 . dataGridView_0 . Columns . Count - 1 )
{
num6 = 0 ;
k + + ;
}
else
{
num6 + + ;
}
num5 + + ;
}
}
2022-04-27 04:52:09 -07:00
}
public void ShortcutsCommand ( KeyEventArgs keyEventArgs_0 , int int_232 )
{
bool bool_ = false ;
if ( Control . ModifierKeys = = Keys . Shift )
{
bool_ = true ;
}
if ( keyEventArgs_0 . KeyCode = = Keys . Delete | | int_232 = = 1 )
{
int num = 0 ;
int num2 = 0 ;
int i = 0 ;
//if (Editortable_0.frmOBD2Scan_0 != null)
//{
while ( i < Editortable_0 . dataGridView_0 . Rows . Count )
{
if ( Editortable_0 . dataGridView_0 . Rows [ i ] . Cells [ num2 ] . Selected )
{
Editortable_0 . dataGridView_0 . Rows [ i ] . Cells [ num2 ] . Value = 0 ;
}
if ( num2 = = Editortable_0 . dataGridView_0 . Columns . Count - 1 )
{
num2 = 0 ;
i + + ;
}
else
{
num2 + + ;
}
num + + ;
}
//}
}
if ( keyEventArgs_0 . KeyCode = = Keys . W | | int_232 = = 2 )
{
IncDecreaseSelection ( false , bool_ ) ;
}
if ( keyEventArgs_0 . KeyCode = = Keys . S | | int_232 = = 3 )
{
IncDecreaseSelection ( true , bool_ ) ;
}
2022-05-07 17:39:50 -07:00
//Class40 class40_0 = new Class40();
2022-04-24 16:05:27 -07:00
//this.smethod_4(200).ContinueWith(new Action<Task>(this.<> c.<> 9.method_0));
2022-05-07 17:39:50 -07:00
//this.smethod_4(200, class40_0).ContinueWith(new Action<Task>(class40_0.method_0));
2022-04-24 16:05:27 -07:00
}
private Task smethod_4 ( int int_232 , Class40 class40_0 )
{
//Class40 class40_0 = new Class40();
class40_0 . taskCompletionSource_0 = new TaskCompletionSource < object > ( ) ;
new System . Threading . Timer ( new TimerCallback ( class40_0 . method_0 ) ) . Change ( int_232 , - 1 ) ;
return class40_0 . taskCompletionSource_0 . Task ;
}
2022-04-27 04:52:09 -07:00
public void GetChanges ( )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
int num = this . SelectedROMLocation ;
int multiplier = 2 ;
if ( this . IsSingleByteX | | this . IsSingleByteY | | this . IsSingleByteTable ) multiplier = 1 ; //###############################
2022-04-24 16:05:27 -07:00
2022-04-30 09:08:54 -07:00
Editortable_0 . GForm_Main_0 . method_1 ( "Checking for differences..." ) ;
2022-04-27 04:52:09 -07:00
//Get all Tables values
2022-04-30 09:08:54 -07:00
double [ , ] ReadBufferarray = new double [ this . BufferTableSize [ 0 ] , this . BufferTableSize [ 1 ] ] ;
for ( int i = 0 ; i < this . BufferTableSize [ 0 ] ; i + + ) //10columns
2022-04-24 16:05:27 -07:00
{
2022-04-30 09:08:54 -07:00
for ( int j = 0 ; j < this . BufferTableSize [ 1 ] ; j + + ) //20rows
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
//calculate value inversed to make bytes
2022-04-30 09:08:54 -07:00
double ThisValue = double . Parse ( Editortable_0 . dataGridView_0 . Rows [ j ] . Cells [ i ] . Value . ToString ( ) . Replace ( ',' , '.' ) , CultureInfo . InvariantCulture ) ;
2022-05-07 17:39:50 -07:00
ThisValue = DoMath ( ThisValue , BufferMath , true , "Table" ) ;
2022-04-30 09:08:54 -07:00
ReadBufferarray [ i , j ] = ( Int16 ) ThisValue ;
2022-04-24 16:05:27 -07:00
}
}
2022-04-27 04:52:09 -07:00
2022-04-30 09:08:54 -07:00
//#############
double [ ] ValuesBufferarray = new double [ this . SelectedTableSize ] ;
for ( int i = 0 ; i < this . BufferTableSize [ 0 ] ; i + + )
{
for ( int j = 0 ; j < this . BufferTableSize [ 1 ] ; j + + )
{
ValuesBufferarray [ i * this . BufferTableSize [ 1 ] + j ] = ReadBufferarray [ i , j ] ;
}
}
//#############
byte [ ] BytesBufferarray = new byte [ this . SelectedTableSize * multiplier ] ;
for ( int i = 0 ; i < this . SelectedTableSize ; i + + )
{
if ( multiplier = = 2 )
{
byte [ ] ThisBytesToChange = BitConverter . GetBytes ( ( Int16 ) ValuesBufferarray [ i ] ) ;
BytesBufferarray [ ( i * 2 ) ] = ThisBytesToChange [ 1 ] ;
BytesBufferarray [ ( i * 2 ) + 1 ] = ThisBytesToChange [ 0 ] ;
}
else
{
BytesBufferarray [ i ] = ( byte ) ValuesBufferarray [ i ] ;
}
}
//#############
2022-04-27 04:52:09 -07:00
byte [ ] array = new byte [ this . SelectedTableSize * multiplier ] ;
for ( int i = 0 ; i < this . SelectedTableSize * multiplier ; i + + )
2022-04-24 16:05:27 -07:00
{
2022-05-07 17:39:50 -07:00
array [ i ] = this . ROM_Bytes [ num + i ] ;
2022-04-27 04:52:09 -07:00
//Apply Changes
2022-05-07 17:39:50 -07:00
this . ROM_Bytes [ num + i ] = BytesBufferarray [ i ] ;
2022-04-24 16:05:27 -07:00
}
int num3 = 0 ;
string text = null ;
2022-04-30 09:08:54 -07:00
bool DiffDetected = false ;
foreach ( int num4 in BytesBufferarray )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
if ( num4 . ToString ( ) ! = array [ num3 ] . ToString ( ) )
2022-04-24 16:05:27 -07:00
{
2022-04-30 09:08:54 -07:00
string BufText = "Change at line: " + num3 . ToString ( ) + "[" + array [ num3 ] . ToString ( "X2" ) + "->" + num4 . ToString ( "X2" ) + "] | At: 0x" + ( this . SelectedROMLocation + num3 ) . ToString ( "X" ) ;
2022-04-27 04:52:09 -07:00
text = text + BufText + Environment . NewLine ;
Editortable_0 . GForm_Main_0 . method_1 ( BufText ) ;
2022-04-30 09:08:54 -07:00
DiffDetected = true ;
2022-04-24 16:05:27 -07:00
}
num3 + + ;
}
2022-04-30 09:08:54 -07:00
if ( ! DiffDetected ) Editortable_0 . GForm_Main_0 . method_1 ( "No differences detected" ) ;
2022-05-07 17:39:50 -07:00
if ( DiffDetected )
{
this . AllROMDifferencesRedo = "" ;
this . Editortable_0 . redoToolStripMenuItem . Enabled = false ;
}
this . AllROMDifferences = this . AllROMDifferences + text ;
//this.string_3 = this.string_3 + "Address: " + this.SelectedROMLocation.ToString() + Environment.NewLine + text;
2022-04-27 04:52:09 -07:00
//this.string_3 = this.string_3 + "Table: " + TableSize + Environment.NewLine + "Address: " + this.SelectedROMLocation.ToString() + Environment.NewLine + text;
2022-04-24 16:05:27 -07:00
}
2022-04-27 04:52:09 -07:00
public void SaveROMBytes ( string string_4 )
2022-04-24 16:05:27 -07:00
{
try
{
2022-05-07 17:39:50 -07:00
if ( this . ValuesChanged & & this . SelectedTableSize ! = 0 & & this . SelectedROMLocation ! = 0 )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
this . GetChanges ( ) ;
2022-04-24 16:05:27 -07:00
}
2022-05-07 17:39:50 -07:00
this . ValuesChanged = false ;
2022-04-24 16:05:27 -07:00
//################################################
2022-05-07 17:39:50 -07:00
byte [ ] SavingBytes = this . ROM_Bytes ;
2022-04-24 16:05:27 -07:00
2022-04-27 04:52:09 -07:00
//Remove fake bootloader section if it's a partial firmware .bin file
2022-04-24 16:05:27 -07:00
if ( ! this . Editortable_0 . IsFullBinary )
{
byte [ ] BufferBytes = new byte [ SavingBytes . Length - 0x8000 ] ;
for ( int i = 0 ; i < SavingBytes . Length ; i + + ) BufferBytes [ i ] = SavingBytes [ i + 0x8000 ] ;
SavingBytes = BufferBytes ;
}
//Fix Checksums
2022-04-30 09:08:54 -07:00
FixChecksums ( ) ;
2022-04-24 16:05:27 -07:00
File . Create ( string_4 ) . Dispose ( ) ;
File . WriteAllBytes ( string_4 , SavingBytes ) ;
2022-05-07 17:39:50 -07:00
//Set LastFileOpened
string LastOpenFilePath = Application . StartupPath + @"\LastFileOpened.txt" ;
File . Create ( LastOpenFilePath ) . Dispose ( ) ;
File . WriteAllText ( LastOpenFilePath , string_4 ) ;
//################################################
//Save rom differences changes to logs
string text = string_4 + "-logs.txt" ;
File . Create ( text ) . Dispose ( ) ;
File . WriteAllText ( text , AllROMDifferences ) ;
2022-04-24 16:05:27 -07:00
//################################################
//string text = string_4 + "~temp";
//string text2 = string_4 + "~temp2";
/ * File . WriteAllBytes ( text , this . byte_0 ) ;
File . WriteAllText ( text2 , this . string_2 ) ;
using ( FileStream fileStream = new FileStream ( string_4 , FileMode . OpenOrCreate ) )
{
FlashGUI . smethod_1 ( this . string_0 + Environment . NewLine + this . string_1 , fileStream ) ;
}
using ( ZipArchive zipArchive = ZipFile . Open ( string_4 , ZipArchiveMode . Update ) )
{
zipArchive . CreateEntryFromFile ( text , this . string_1 ) ;
zipArchive . CreateEntryFromFile ( text2 , "CLOG" ) ;
}
File . Delete ( text ) ;
File . Delete ( text2 ) ; * /
DarkMessageBox . Show ( "Successfully Saved File!." , "Success" , MessageBoxButtons . OK , MessageBoxIcon . Asterisk ) ;
}
catch
{
DarkMessageBox . Show ( "Failed to save file!." , "Fail" , MessageBoxButtons . OK , MessageBoxIcon . Hand ) ;
}
}
2022-04-30 09:08:54 -07:00
public void FixChecksums ( )
{
2022-05-07 17:39:50 -07:00
if ( ! this . Editortable_0 . IsFullBinary ) this . ROM_Bytes = this . Editortable_0 . GForm_Main_0 . VerifyChecksumFWBin ( this . ROM_Bytes ) ;
if ( this . Editortable_0 . IsFullBinary ) this . ROM_Bytes = this . Editortable_0 . GForm_Main_0 . VerifyChecksumFullBin ( this . ROM_Bytes ) ;
2022-04-30 09:08:54 -07:00
}
2022-05-07 17:39:50 -07:00
public void SetTableValues ( int [ ] TableSize , int ROMLocationX , string TopLeftString , string RowHeaderString , string [ ] HeaderStringList , string ThisMathX , string ThisFormatX , bool IsXYInverted , int ROMLocationTable , string ThisMathTable , string ThisTableFormat , bool IsTableInverted , bool IsReadOnly )
2022-04-24 16:05:27 -07:00
{
try
{
2022-04-27 04:52:09 -07:00
this . SelectedTableSize = TableSize [ 0 ] * TableSize [ 1 ] ;
BufferValuesArray = new int [ SelectedTableSize ] ;
BufferTableSize = TableSize ;
2022-04-24 16:05:27 -07:00
Editortable_0 . dataGridView_0 . Rows . Clear ( ) ;
Editortable_0 . dataGridView_0 . Columns . Clear ( ) ;
Editortable_0 . dataGridView_0 . RowTemplate . DefaultCellStyle . Alignment = DataGridViewContentAlignment . MiddleCenter ;
2022-04-27 04:52:09 -07:00
Editortable_0 . dataGridView_0 . TopLeftHeaderCell . Value = TopLeftString ;
Editortable_0 . dataGridView_0 . AllowUserToAddRows = false ;
//Correct the Table Orientation if Bad
2022-05-03 09:25:40 -07:00
/ * if ( ( TableSize [ 1 ] = = 1 & & IsInverted ) | | ( TableSize [ 0 ] = = 1 & & ! IsInverted ) )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
int Buf0 = TableSize [ 1 ] ;
int Buf1 = TableSize [ 0 ] ;
TableSize [ 0 ] = Buf0 ;
TableSize [ 1 ] = Buf1 ;
2022-05-03 09:25:40 -07:00
} * /
2022-04-27 04:52:09 -07:00
2022-05-03 09:25:40 -07:00
SelectedROMLocation = ROMLocationTable ;
BufferMath = ThisMathTable ;
2022-04-27 04:52:09 -07:00
2022-05-03 09:25:40 -07:00
//Apply Columns(Y)
if ( IsXYInverted )
2022-04-24 16:05:27 -07:00
{
2022-05-03 09:25:40 -07:00
for ( int i = 0 ; i < TableSize [ 1 ] ; i + + )
2022-04-24 16:05:27 -07:00
{
2022-05-03 09:25:40 -07:00
if ( ROMLocationX ! = 0 )
2022-04-24 16:05:27 -07:00
{
2022-05-03 09:25:40 -07:00
double num = 0 ;
if ( IsSingleByteX ) num = ( double ) this . GetSingleByteValue ( ROMLocationX + i ) ;
else num = ( double ) this . GetIntValue ( ROMLocationX + i * 2 ) ;
string HeaderStr = "" ;
2022-05-07 17:39:50 -07:00
if ( ThisFormatX ! = "" ) HeaderStr = DoMath ( num , ThisMathX , false , "X" ) . ToString ( ThisFormatX ) ;
if ( ThisFormatX = = "" ) HeaderStr = DoMath ( num , ThisMathX , false , "X" ) . ToString ( ) ;
2022-05-03 09:25:40 -07:00
Editortable_0 . dataGridView_0 . Columns . Add ( HeaderStr , HeaderStr ) ;
}
else
{
Editortable_0 . dataGridView_0 . Columns . Add ( RowHeaderString , RowHeaderString ) ;
2022-04-24 16:05:27 -07:00
}
}
2022-05-03 09:25:40 -07:00
}
else
{
for ( int j = 0 ; j < TableSize [ 0 ] ; j + + ) Editortable_0 . dataGridView_0 . Columns . Add ( HeaderStringList [ j ] , HeaderStringList [ j ] ) ;
}
2022-04-27 04:52:09 -07:00
2022-05-03 09:25:40 -07:00
int index = 0 ;
while ( true )
{
if ( index > = SelectedTableSize ) // More than TableSize (ex: 10x20.. more than 200)
2022-04-27 04:52:09 -07:00
{
2022-05-03 09:25:40 -07:00
int [ , ] numArray2 = smethod_35 < int > ( BufferValuesArray , TableSize [ 0 ] , TableSize [ 1 ] ) ;
int rowIndex = 0 ;
while ( true )
2022-04-24 16:05:27 -07:00
{
2022-05-03 09:25:40 -07:00
if ( ( rowIndex > = TableSize [ 1 ] & & ! IsXYInverted ) | | ( rowIndex > = TableSize [ 0 ] & & IsXYInverted ) ) //More than Y (make the 3D table)
2022-04-24 16:05:27 -07:00
{
2022-05-03 09:25:40 -07:00
int num10 = 0 ;
while ( true )
2022-04-24 16:05:27 -07:00
{
2022-05-03 09:25:40 -07:00
if ( ( num10 > = TableSize [ 1 ] & & ! IsXYInverted ) | | ( num10 > = TableSize [ 0 ] & & IsXYInverted ) ) //Another More than Y (set X Header)
2022-04-24 16:05:27 -07:00
{
2022-05-03 09:25:40 -07:00
if ( ! IsXYInverted ) SetBackColor ( TableSize [ 0 ] , Editortable . float_1 [ 0 ] , Editortable . float_1 [ 1 ] ) ;
if ( IsXYInverted ) SetBackColor ( TableSize [ 1 ] , Editortable . float_1 [ 0 ] , Editortable . float_1 [ 1 ] ) ;
break ;
}
//Rows(X) Math
if ( IsXYInverted )
{
string ThisHeaderVal = HeaderStringList [ num10 ] ;
if ( ThisHeaderVal = = "" ) ThisHeaderVal = RowHeaderString ;
Editortable_0 . dataGridView_0 . Rows [ num10 ] . HeaderCell . Value = ThisHeaderVal ;
}
else
{
if ( ROMLocationX ! = 0 )
2022-04-27 04:52:09 -07:00
{
2022-05-03 09:25:40 -07:00
double num = 0 ;
if ( IsSingleByteX ) num = ( double ) this . GetSingleByteValue ( ROMLocationX + num10 ) ;
else num = ( double ) this . GetIntValue ( ROMLocationX + num10 * 2 ) ;
2022-05-07 17:39:50 -07:00
if ( ThisFormatX ! = "" ) Editortable_0 . dataGridView_0 . Rows [ num10 ] . HeaderCell . Value = DoMath ( num , ThisMathX , false , "X" ) . ToString ( ThisFormatX ) ;
if ( ThisFormatX = = "" ) Editortable_0 . dataGridView_0 . Rows [ num10 ] . HeaderCell . Value = DoMath ( num , ThisMathX , false , "X" ) . ToString ( ) ;
2022-04-27 04:52:09 -07:00
}
else
{
2022-05-03 09:25:40 -07:00
Editortable_0 . dataGridView_0 . Rows [ num10 ] . HeaderCell . Value = RowHeaderString ;
2022-04-27 04:52:09 -07:00
}
2022-04-24 16:05:27 -07:00
}
2022-05-03 09:25:40 -07:00
num10 + + ;
2022-04-24 16:05:27 -07:00
}
2022-05-03 09:25:40 -07:00
break ;
}
2022-04-27 04:52:09 -07:00
2022-05-03 09:25:40 -07:00
//TableMath (Get full 1full row of value at a time)
2022-05-07 17:39:50 -07:00
string [ ] values = new string [ 0 ] ;
2022-05-03 09:25:40 -07:00
if ( IsXYInverted )
{
2022-05-07 17:39:50 -07:00
values = new string [ TableSize [ 1 ] ] ;
2022-05-03 09:25:40 -07:00
for ( int i = 0 ; i < TableSize [ 1 ] ; i + + )
2022-04-24 16:05:27 -07:00
{
2022-05-07 17:39:50 -07:00
if ( ThisTableFormat . Contains ( "X" ) )
{
//Display Values in Hexadecimals
string Mathhh = DoMath ( ( double ) numArray2 [ rowIndex , i ] , ThisMathTable , false , "Table" ) . ToString ( ) ;
try
{
if ( ThisTableFormat = = "X4" ) values [ i ] = Int16 . Parse ( Mathhh ) . ToString ( ThisTableFormat ) ;
else if ( ThisTableFormat = = "X8" ) values [ i ] = Int32 . Parse ( Mathhh ) . ToString ( ThisTableFormat ) ;
else values [ i ] = int . Parse ( Mathhh ) . ToString ( ThisTableFormat ) ;
}
catch
{
values [ i ] = Mathhh ;
}
}
else
{
//Display Values in double/int
if ( ThisTableFormat ! = "" ) values [ i ] = DoMath ( ( double ) numArray2 [ rowIndex , i ] , ThisMathTable , false , "Table" ) . ToString ( ThisTableFormat ) ;
if ( ThisTableFormat = = "" ) values [ i ] = DoMath ( ( double ) numArray2 [ rowIndex , i ] , ThisMathTable , false , "Table" ) . ToString ( ) ;
}
2022-04-24 16:05:27 -07:00
}
2022-05-03 09:25:40 -07:00
}
else
{
2022-05-07 17:39:50 -07:00
values = new string [ TableSize [ 0 ] ] ;
2022-05-03 09:25:40 -07:00
for ( int i = 0 ; i < TableSize [ 0 ] ; i + + )
2022-04-24 16:05:27 -07:00
{
2022-05-07 17:39:50 -07:00
if ( ThisTableFormat . Contains ( "X" ) )
{
//Display Values in Hexadecimals
string Mathhh = DoMath ( ( double ) numArray2 [ i , rowIndex ] , ThisMathTable , false , "Table" ) . ToString ( ) ;
try
{
if ( ThisTableFormat = = "X4" ) values [ i ] = Int16 . Parse ( Mathhh ) . ToString ( ThisTableFormat ) ;
else if ( ThisTableFormat = = "X8" ) values [ i ] = Int32 . Parse ( Mathhh ) . ToString ( ThisTableFormat ) ;
else values [ i ] = int . Parse ( Mathhh ) . ToString ( ThisTableFormat ) ;
}
catch
{
values [ i ] = Mathhh ;
}
}
else
{
//Display Values in double/int
if ( ThisTableFormat ! = "" ) values [ i ] = DoMath ( ( double ) numArray2 [ i , rowIndex ] , ThisMathTable , false , "Table" ) . ToString ( ThisTableFormat ) ;
if ( ThisTableFormat = = "" ) values [ i ] = DoMath ( ( double ) numArray2 [ i , rowIndex ] , ThisMathTable , false , "Table" ) . ToString ( ) ;
}
2022-04-24 16:05:27 -07:00
}
}
2022-05-03 09:25:40 -07:00
Editortable_0 . dataGridView_0 . Rows . Insert ( rowIndex , values ) ;
rowIndex + + ;
2022-04-24 16:05:27 -07:00
}
2022-05-03 09:25:40 -07:00
break ;
2022-04-27 04:52:09 -07:00
}
2022-05-03 09:25:40 -07:00
//Math perfomed just above
if ( IsSingleByteTable ) BufferValuesArray [ index ] = GetSingleByteValue ( SelectedROMLocation + index ) ;
else BufferValuesArray [ index ] = GetIntValue ( SelectedROMLocation + ( index * 2 ) ) ;
2022-04-27 04:52:09 -07:00
2022-05-03 09:25:40 -07:00
index + + ;
}
2022-04-27 04:52:09 -07:00
2022-05-03 09:25:40 -07:00
//##############################################################################################################
//Invert inner tables values X and Y
if ( IsTableInverted )
{
int [ , ] numArray2 = smethod_35 < int > ( BufferValuesArray , TableSize [ 1 ] , TableSize [ 0 ] ) ;
2022-04-27 04:52:09 -07:00
2022-05-03 09:25:40 -07:00
for ( int i = 0 ; i < Editortable_0 . dataGridView_0 . ColumnCount ; i + + )
2022-04-24 16:05:27 -07:00
{
2022-05-03 09:25:40 -07:00
for ( int i2 = 0 ; i2 < Editortable_0 . dataGridView_0 . RowCount ; i2 + + )
2022-04-27 04:52:09 -07:00
{
2022-05-03 09:25:40 -07:00
string valueinner = "" ;
if ( IsXYInverted )
{
2022-05-07 17:39:50 -07:00
if ( ThisTableFormat ! = "" ) valueinner = DoMath ( ( double ) numArray2 [ i , i2 ] , ThisMathTable , false , "Table" ) . ToString ( ThisTableFormat ) ;
if ( ThisTableFormat = = "" ) valueinner = DoMath ( ( double ) numArray2 [ i , i2 ] , ThisMathTable , false , "Table" ) . ToString ( ) ;
2022-05-03 09:25:40 -07:00
}
else
{
2022-05-07 17:39:50 -07:00
if ( ThisTableFormat ! = "" ) valueinner = DoMath ( ( double ) numArray2 [ i2 , i ] , ThisMathTable , false , "Table" ) . ToString ( ThisTableFormat ) ;
if ( ThisTableFormat = = "" ) valueinner = DoMath ( ( double ) numArray2 [ i2 , i ] , ThisMathTable , false , "Table" ) . ToString ( ) ;
2022-05-03 09:25:40 -07:00
}
2022-04-27 04:52:09 -07:00
2022-05-03 09:25:40 -07:00
Editortable_0 . dataGridView_0 . Rows [ i2 ] . Cells [ i ] . Value = valueinner ;
2022-04-27 04:52:09 -07:00
}
2022-04-24 16:05:27 -07:00
}
2022-05-03 09:25:40 -07:00
}
//##############################################################################################################
2022-05-07 17:39:50 -07:00
Editortable_0 . dataGridView_0 . ReadOnly = IsReadOnly ;
2022-04-24 16:05:27 -07:00
foreach ( object obj in Editortable_0 . dataGridView_0 . Columns )
{
DataGridViewColumn dataGridViewColumn = ( DataGridViewColumn ) obj ;
dataGridViewColumn . SortMode = DataGridViewColumnSortMode . NotSortable ;
2022-04-27 04:52:09 -07:00
//dataGridViewColumn.Width = 50;
2022-04-24 16:05:27 -07:00
}
2022-04-27 04:52:09 -07:00
foreach ( object obj2 in ( ( IEnumerable ) Editortable_0 . dataGridView_0 . Rows ) )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
DataGridViewRow dataGridViewRow2 = ( DataGridViewRow ) obj2 ;
dataGridViewRow2 . Height = 20 ;
2022-04-24 16:05:27 -07:00
}
2022-04-27 04:52:09 -07:00
this . SetBackColor ( TableSize [ 0 ] , Editortable . float_1 [ 0 ] , Editortable . float_1 [ 1 ] ) ;
2022-05-07 17:39:50 -07:00
this . IsTableLoadedCorrectly = true ;
2022-04-24 16:05:27 -07:00
}
catch ( Exception ex )
{
2022-05-07 17:39:50 -07:00
this . IsTableLoadedCorrectly = false ;
2022-04-24 16:05:27 -07:00
DarkMessageBox . Show ( "Failed to load table. " + ex . ToString ( ) ) ;
}
}
2022-04-27 04:52:09 -07:00
private int GetNearestMathIndex ( string ThisMath )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
int IndexOfNearest = - 1 ;
int IndexOfMathDiv = ThisMath . IndexOf ( '/' ) ;
int IndexOfMathMul = ThisMath . IndexOf ( '*' ) ;
int IndexOfMathAdd = ThisMath . IndexOf ( '+' ) ;
//int IndexOfMathSub = ThisMath.IndexOf('-'); //don't check for sub, this is causing issue with negative number
if ( IndexOfMathDiv = = 0 ) return 0 ;
if ( IndexOfMathMul = = 0 ) return 0 ;
if ( IndexOfMathAdd = = 0 ) return 0 ;
if ( IndexOfMathDiv = = - 1 ) IndexOfMathDiv = 99 ;
if ( IndexOfMathMul = = - 1 ) IndexOfMathMul = 99 ;
if ( IndexOfMathAdd = = - 1 ) IndexOfMathAdd = 99 ;
if ( IndexOfMathDiv > 0 & & IndexOfMathDiv < IndexOfMathMul & & IndexOfMathDiv < IndexOfMathAdd ) IndexOfNearest = IndexOfMathDiv ;
if ( IndexOfMathMul > 0 & & IndexOfMathMul < IndexOfMathDiv & & IndexOfMathMul < IndexOfMathAdd ) IndexOfNearest = IndexOfMathMul ;
if ( IndexOfMathAdd > 0 & & IndexOfMathAdd < IndexOfMathMul & & IndexOfMathAdd < IndexOfMathDiv ) IndexOfNearest = IndexOfMathAdd ;
if ( IndexOfNearest = = 99 ) IndexOfNearest = - 1 ;
return IndexOfNearest ;
}
private char GetNextMath ( string ThisMath )
{
int Thisindex = GetNearestMathIndex ( ThisMath ) ;
return ThisMath . Substring ( Thisindex , 1 ) [ 0 ] ;
}
private double GetNextValue ( string ThisMath )
{
double Value = 0 ;
int Nearestindex = GetNearestMathIndex ( ThisMath ) ;
2022-04-30 09:08:54 -07:00
if ( Nearestindex = = 0 ) ThisMath = ThisMath . Substring ( 1 ) ;
2022-04-24 16:05:27 -07:00
2022-04-27 04:52:09 -07:00
if ( Nearestindex = = - 1 )
{
2022-04-30 09:08:54 -07:00
Value = double . Parse ( ThisMath . Replace ( ',' , '.' ) , CultureInfo . InvariantCulture ) ;
2022-04-27 04:52:09 -07:00
}
else
{
string ThisVarStr = ThisMath . Substring ( 0 , Nearestindex ) ;
2022-04-30 09:08:54 -07:00
Value = double . Parse ( ThisVarStr . Replace ( ',' , '.' ) , CultureInfo . InvariantCulture ) ;
2022-04-27 04:52:09 -07:00
}
2022-04-24 16:05:27 -07:00
2022-04-27 04:52:09 -07:00
return Value ;
}
2022-04-24 16:05:27 -07:00
2022-04-27 04:52:09 -07:00
public string InvertMathString ( string ThisMath )
{
string ReturnStr = "" ;
List < double > ValuesList = new List < double > ( ) ;
List < char > MathFuncList = new List < char > ( ) ;
bool WeHaveVal1 = false ;
while ( ThisMath ! = "" )
{
if ( ! WeHaveVal1 ) ValuesList . Add ( GetNextValue ( ThisMath ) ) ;
MathFuncList . Add ( GetNextMath ( ThisMath ) ) ;
ThisMath = ThisMath . Substring ( GetNearestMathIndex ( ThisMath ) + 1 ) ;
ValuesList . Add ( GetNextValue ( ThisMath ) ) ;
2022-04-24 16:05:27 -07:00
2022-04-27 04:52:09 -07:00
int NearestIndex = GetNearestMathIndex ( ThisMath ) ;
2022-04-30 09:08:54 -07:00
if ( NearestIndex ! = - 1 ) ThisMath = ThisMath . Substring ( GetNearestMathIndex ( ThisMath ) ) ;
2022-04-27 04:52:09 -07:00
WeHaveVal1 = true ;
if ( ! ThisMath . Contains ( "/" ) & & ! ThisMath . Contains ( "*" ) & & ! ThisMath . Contains ( "+" ) )
{
ThisMath = "" ; //No remaining maths to perform
}
}
//Create inverted math function
for ( int i = ValuesList . Count - 1 ; i > = 0 ; i - - )
{
ReturnStr = ReturnStr + ValuesList [ i ] ;
if ( i > 0 )
{
if ( MathFuncList [ i - 1 ] = = '*' ) ReturnStr = ReturnStr + "/" ;
if ( MathFuncList [ i - 1 ] = = '/' ) ReturnStr = ReturnStr + "*" ;
if ( MathFuncList [ i - 1 ] = = '+' ) ReturnStr = ReturnStr + "+-" ;
}
}
return ReturnStr ;
}
2022-05-07 17:39:50 -07:00
public string SwipeMathFunc ( string ThisMath )
{
string ReturnStr = "" ;
List < char > MathFuncList = new List < char > ( ) ;
List < double > ValuesList = new List < double > ( ) ;
bool WeHaveVal1 = false ;
while ( ThisMath ! = "" )
{
if ( ! WeHaveVal1 ) ValuesList . Add ( GetNextValue ( ThisMath ) ) ;
MathFuncList . Add ( GetNextMath ( ThisMath ) ) ;
ThisMath = ThisMath . Substring ( GetNearestMathIndex ( ThisMath ) + 1 ) ;
ValuesList . Add ( GetNextValue ( ThisMath ) ) ;
int NearestIndex = GetNearestMathIndex ( ThisMath ) ;
if ( NearestIndex ! = - 1 ) ThisMath = ThisMath . Substring ( GetNearestMathIndex ( ThisMath ) ) ;
WeHaveVal1 = true ;
if ( ! ThisMath . Contains ( "/" ) & & ! ThisMath . Contains ( "*" ) & & ! ThisMath . Contains ( "+" ) )
{
ThisMath = "" ; //No remaining maths to perform
}
}
//Create swiped math function
for ( int i = 0 ; i < ValuesList . Count ; i + + )
{
if ( i > 0 )
{
if ( i > 1 ) ReturnStr = ReturnStr + MathFuncList [ i - 2 ] . ToString ( ) ;
else ReturnStr = ReturnStr + MathFuncList [ MathFuncList . Count - 1 ] . ToString ( ) ;
}
ReturnStr = ReturnStr + ValuesList [ i ] ;
}
return ReturnStr ;
}
2022-04-30 09:08:54 -07:00
2022-05-07 17:39:50 -07:00
public double DoMath ( double ThisValueCheck , string ThisMath , bool Reverse , string Direction )
2022-04-30 09:08:54 -07:00
{
2022-05-07 17:39:50 -07:00
//Check if the reversed math function exist, if not we perform the reversed math function manually
bool ReversFinalForMath = Reverse ;
if ( Reverse )
{
if ( Direction = = "X" & & DefinitionsMathXInverted [ SelectedTableIndexInDefinitions ] ! = "" )
{
ThisMath = DefinitionsMathXInverted [ SelectedTableIndexInDefinitions ] ;
ReversFinalForMath = false ;
}
if ( Direction = = "Y" & & DefinitionsMathYInverted [ SelectedTableIndexInDefinitions ] ! = "" )
{
ThisMath = DefinitionsMathYInverted [ SelectedTableIndexInDefinitions ] ;
ReversFinalForMath = false ;
}
if ( Direction = = "Table" & & DefinitionsMathTableInverted [ SelectedTableIndexInDefinitions ] ! = "" )
{
ThisMath = DefinitionsMathTableInverted [ SelectedTableIndexInDefinitions ] ;
ReversFinalForMath = false ;
}
}
//Perform Math
double ReturnVal = DoMathFinal ( ThisValueCheck , ThisMath , ReversFinalForMath ) ;
2022-04-30 09:08:54 -07:00
2022-05-07 17:39:50 -07:00
//################################################
2022-04-30 09:08:54 -07:00
//Confirm Math function in reverse
if ( ! Reverse )
{
2022-05-07 17:39:50 -07:00
bool PerformedNormalReverse = true ;
//Has the reversed math function existing
if ( Direction = = "X" & & DefinitionsMathXInverted [ SelectedTableIndexInDefinitions ] ! = "" )
{
ThisMath = DefinitionsMathXInverted [ SelectedTableIndexInDefinitions ] ;
PerformedNormalReverse = false ;
}
if ( Direction = = "Y" & & DefinitionsMathYInverted [ SelectedTableIndexInDefinitions ] ! = "" )
{
ThisMath = DefinitionsMathYInverted [ SelectedTableIndexInDefinitions ] ;
PerformedNormalReverse = false ;
}
if ( Direction = = "Table" & & DefinitionsMathTableInverted [ SelectedTableIndexInDefinitions ] ! = "" )
{
ThisMath = DefinitionsMathTableInverted [ SelectedTableIndexInDefinitions ] ;
PerformedNormalReverse = false ;
}
//Has NOT the reversed math function existing
double ReversedVal = DoMathFinal ( ReturnVal , ThisMath , PerformedNormalReverse ) ;
2022-04-30 09:08:54 -07:00
if ( ( ( int ) ReversedVal ) . ToString ( ) ! = ( ( int ) ThisValueCheck ) . ToString ( )
2022-05-03 09:25:40 -07:00
& & ( ( int ) ReversedVal + 1 ) . ToString ( ) ! = ( ( int ) ThisValueCheck ) . ToString ( )
& & ( ( int ) ReversedVal - 1 ) . ToString ( ) ! = ( ( int ) ThisValueCheck ) . ToString ( ) )
2022-04-30 09:08:54 -07:00
{
2022-05-07 17:39:50 -07:00
if ( LastMathDoneCheck ! = ThisMath )
{
Editortable_0 . GForm_Main_0 . method_1 ( "Problem with inverted math: " + ThisMath + " | Values: " + ( ( int ) ThisValueCheck ) . ToString ( ) + " != " + ( ( int ) ReversedVal ) . ToString ( ) ) ;
LastMathDoneCheck = ThisMath ;
}
//suggested to set 'ReadOnly' parameters when there is math problem.
//when there is math problem, it mean the inverted function of your math doesn't return the exact bytes values as within the binary.
//The problem come from the math inversion in the function bellow 'DoMathFinal'
//DefinitionsIsReadOnly
2022-04-30 09:08:54 -07:00
}
}
return ReturnVal ;
}
//public double DoMath(double ThisValue, string ThisMath, bool Reverse)
public double DoMathFinal ( double ThisValue , string ThisMath , bool Reverse )
2022-04-27 04:52:09 -07:00
{
double ReturnVal = ThisValue ;
//No Math found, return value with no math calculation
if ( ThisMath = = "X" | | ThisMath = = "" ) return ReturnVal ;
2022-04-30 09:08:54 -07:00
//Put X at the end in reverse
bool IsDivXValFirst = false ;
2022-04-27 04:52:09 -07:00
if ( Reverse )
{
2022-04-30 09:08:54 -07:00
if ( ThisMath . Contains ( "X/" ) ) IsDivXValFirst = true ;
2022-04-27 04:52:09 -07:00
if ( ThisMath [ ThisMath . Length - 1 ] ! = 'X' )
{
string XandMath = ThisMath . Substring ( ThisMath . IndexOf ( 'X' ) , 2 ) ;
ThisMath = ThisMath . Replace ( XandMath , "" ) + XandMath [ 1 ] . ToString ( ) + XandMath [ 0 ] . ToString ( ) ;
}
}
ThisMath = ThisMath . Replace ( "X" , ThisValue . ToString ( ) ) ;
2022-05-07 17:39:50 -07:00
//########################################################
//double ValTest1 = GetNextValue(ThisMath);
char MathTestChar = GetNextMath ( ThisMath ) ;
string ThisMathTest = ThisMath . Substring ( GetNearestMathIndex ( ThisMath ) + 1 ) ;
double ValTest2 = GetNextValue ( ThisMathTest ) ;
if ( Reverse & & MathTestChar = = '*' & & ValTest2 = = 100 )
{
IsDivXValFirst = true ;
ThisMath = SwipeMathFunc ( ThisMath ) ;
}
//########################################################
2022-04-27 04:52:09 -07:00
if ( Reverse ) ThisMath = InvertMathString ( ThisMath ) ;
2022-05-07 17:39:50 -07:00
//Console.WriteLine("Math: " + ThisMath + " | Reversed: " + Reverse);
2022-04-27 04:52:09 -07:00
bool WeHaveVal1 = false ;
double Val1 = 0 ;
while ( ThisMath ! = "" )
{
if ( ! WeHaveVal1 ) Val1 = GetNextValue ( ThisMath ) ;
char MathChar = GetNextMath ( ThisMath ) ;
ThisMath = ThisMath . Substring ( GetNearestMathIndex ( ThisMath ) + 1 ) ;
double Val2 = GetNextValue ( ThisMath ) ;
if ( MathChar = = '*' ) ReturnVal = Val1 * Val2 ;
if ( MathChar = = '/' ) ReturnVal = Val1 / Val2 ;
if ( MathChar = = '+' ) ReturnVal = Val1 + Val2 ;
2022-05-07 17:39:50 -07:00
//Console.WriteLine("Doing: " + Val1 + MathChar.ToString() + Val2 + "=" + ReturnVal);
2022-04-27 04:52:09 -07:00
2022-04-30 09:08:54 -07:00
if ( Reverse & & MathChar = = '*' & & ! IsDivXValFirst ) ReturnVal = Val2 / Val1 ;
2022-04-27 04:52:09 -07:00
int NearestIndex = GetNearestMathIndex ( ThisMath ) ;
2022-04-30 09:08:54 -07:00
if ( NearestIndex ! = - 1 ) ThisMath = ThisMath . Substring ( GetNearestMathIndex ( ThisMath ) ) ;
2022-04-27 04:52:09 -07:00
WeHaveVal1 = true ;
Val1 = ReturnVal ;
//Check for remaining maths
if ( ! ThisMath . Contains ( "/" ) & & ! ThisMath . Contains ( "*" ) & & ! ThisMath . Contains ( "+" ) )
{
ThisMath = "" ; //No remaining maths to perform
}
}
return ReturnVal ;
}
public string [ ] GetAdvancedHeader ( int ValuesCount , int ThisLocation , string ThisMath , string HeaderFormat )
{
string [ ] strArray = new string [ ValuesCount ] ;
for ( int i = 0 ; i < ValuesCount ; i + + )
{
int Valuue = 0 ;
if ( IsSingleByteY ) Valuue = GetSingleByteValue ( ThisLocation + i ) ;
else Valuue = GetIntValue ( ThisLocation + ( i * 2 ) ) ;
2022-05-07 17:39:50 -07:00
if ( HeaderFormat = = "" ) strArray [ i ] = DoMath ( ( double ) Valuue , ThisMath , false , "Y" ) . ToString ( ) ;
if ( HeaderFormat ! = "" ) strArray [ i ] = DoMath ( ( double ) Valuue , ThisMath , false , "Y" ) . ToString ( HeaderFormat ) ;
2022-04-27 04:52:09 -07:00
}
return strArray ;
}
public byte [ ] StringToByteArray ( string hex )
{
return Enumerable . Range ( 0 , hex . Length )
. Where ( x = > x % 2 = = 0 )
. Select ( x = > Convert . ToByte ( hex . Substring ( x , 2 ) , 16 ) )
. ToArray ( ) ;
}
/ * public Int16 ToInt16BE ( byte [ ] TwoBytes )
{
Int16 k0 = BitConverter . ToInt16 ( TwoBytes , 0 ) ;
Int16 k1 = BitConverter . ToInt16 ( BitConverter . GetBytes ( k0 ) . Reverse ( ) . ToArray ( ) , 0 ) ;
return k1 ;
}
public Int32 ToInt32BE ( byte [ ] FourBytes )
{
Int32 k0 = BitConverter . ToInt32 ( FourBytes , 0 ) ;
Int32 k1 = BitConverter . ToInt32 ( BitConverter . GetBytes ( k0 ) . Reverse ( ) . ToArray ( ) , 0 ) ;
return k1 ;
} * /
public int HexStringToInt ( string hex )
{
string ThisStr = hex . Replace ( "0x" , "" ) ;
if ( ThisStr . Length = = 1 | | ThisStr . Length = = 3 | | ThisStr . Length = = 5 | | ThisStr . Length = = 7 )
{
ThisStr = "0" + ThisStr ;
}
byte [ ] ThisBytes = StringToByteArray ( ThisStr ) ;
Array . Reverse ( ThisBytes ) ;
//Add Empty Bytes
if ( ThisBytes . Length = = 3 )
{
byte [ ] buffArray = new byte [ 4 ] ;
buffArray [ 3 ] = 0 ;
for ( int i = 0 ; i < ThisBytes . Length ; i + + ) buffArray [ i ] = ThisBytes [ i ] ;
ThisBytes = buffArray ;
}
if ( ThisBytes . Length = = 2 ) return BitConverter . ToUInt16 ( ThisBytes , 0 ) ;
if ( ThisBytes . Length = = 4 ) return BitConverter . ToInt32 ( ThisBytes , 0 ) ;
//if (ThisBytes.Length == 8) return BitConverter.ToUInt64(ThisBytes, 0);
return 0 ;
}
public bool LoadROMbytes ( string string_4 )
{
if ( File . Exists ( string_4 ) )
{
try
{
2022-05-07 17:39:50 -07:00
this . ROM_Bytes = File . ReadAllBytes ( string_4 ) ;
2022-04-27 04:52:09 -07:00
//Create a fake bootloader section
if ( ! Editortable_0 . IsFullBinary )
{
2022-05-07 17:39:50 -07:00
byte [ ] BufferBytes = new byte [ 0x8000 + this . ROM_Bytes . Length ] ;
2022-04-27 04:52:09 -07:00
for ( int i = 0 ; i < 0x8000 ; i + + ) BufferBytes [ i ] = 0xff ;
2022-05-07 17:39:50 -07:00
for ( int i = 0 ; i < this . ROM_Bytes . Length ; i + + ) BufferBytes [ 0x8000 + i ] = this . ROM_Bytes [ i ] ;
2022-04-27 04:52:09 -07:00
2022-05-07 17:39:50 -07:00
this . ROM_Bytes = BufferBytes ;
2022-04-27 04:52:09 -07:00
}
//Get ECU filename (33 37 38 30 35 2D -> 37805- 'in ASCII chars') (37805-RRB-A140)
this . string_ECU_Name = "" ;
2022-05-07 17:39:50 -07:00
for ( int i = 0 ; i < this . ROM_Bytes . Length ; i + + )
2022-04-27 04:52:09 -07:00
{
2022-05-07 17:39:50 -07:00
if ( this . ROM_Bytes [ i ] = = 0x33 & &
this . ROM_Bytes [ i + 1 ] = = 0x37 & &
this . ROM_Bytes [ i + 2 ] = = 0x38 & &
this . ROM_Bytes [ i + 3 ] = = 0x30 & &
( this . ROM_Bytes [ i + 4 ] = = 0x35 | | this . ROM_Bytes [ i + 4 ] = = 0x36 ) & &
this . ROM_Bytes [ i + 5 ] = = 0x2D )
2022-04-27 04:52:09 -07:00
{
for ( int i2 = 0 ; i2 < 14 ; i2 + + )
{
2022-05-07 17:39:50 -07:00
this . string_ECU_Name + = ( char ) this . ROM_Bytes [ i + i2 ] ;
2022-04-27 04:52:09 -07:00
}
break ;
}
}
2022-05-07 17:39:50 -07:00
//##################################################################################################
//Load all differences made in ROM from logs
string text = string_4 + "-logs.txt" ;
if ( File . Exists ( text ) )
{
AllROMDifferences = File . ReadAllText ( text ) ;
}
2022-04-27 04:52:09 -07:00
return true ;
2022-05-07 17:39:50 -07:00
//##################################################################################################
2022-04-27 04:52:09 -07:00
/ * this . string_0 = array [ 0 ] ; //37805-RRB-A140
this . string_1 = array [ 1 ] ; //Unused
using ( FileStream fileStream = new FileStream ( string_4 , FileMode . Open ) )
{
using ( ZipArchive zipArchive = new ZipArchive ( fileStream , ZipArchiveMode . Read ) )
{
foreach ( ZipArchiveEntry zipArchiveEntry in zipArchive . Entries )
{
if ( zipArchiveEntry . Name = = "CALID" )
{
//string[] array = File.ReadAllLines(Application.StartupPath + @"\CALID\" + string_4);
string [ ] array = this . smethod_0 ( zipArchiveEntry ) . Split ( new string [ ]
{
Environment . NewLine
} , StringSplitOptions . None ) ;
this . string_0 = array [ 0 ] ;
this . string_1 = array [ 1 ] ;
foreach ( ZipArchiveEntry zipArchiveEntry2 in zipArchive . Entries )
{
if ( zipArchiveEntry2 . Name = = "CLOG" )
{
this . string_2 = this . smethod_0 ( zipArchiveEntry2 ) ;
}
if ( zipArchiveEntry2 . Name = = array [ 1 ] )
{
using ( Stream stream = zipArchiveEntry2 . Open ( ) )
{
using ( BinaryReader binaryReader = new BinaryReader ( stream ) )
2022-04-24 16:05:27 -07:00
{
this . byte_0 = binaryReader . ReadBytes ( ( int ) zipArchiveEntry2 . Length ) ;
return true ;
}
}
break ;
}
}
}
}
}
}
Editortable_0 . GForm_Main_0 . method_1 ( "Cannot load Error#1" ) ;
return false ; * /
2022-05-07 17:39:50 -07:00
//##################################################################################################
2022-04-24 16:05:27 -07:00
}
catch
{
return false ;
}
}
return false ;
}
2022-04-27 04:52:09 -07:00
public int GetIntValue ( int int_232 )
2022-04-24 16:05:27 -07:00
{
2022-05-07 17:39:50 -07:00
return ( int ) ( ( short ) ( ( int ) this . ROM_Bytes [ int_232 ] < < 8 | ( int ) this . ROM_Bytes [ int_232 + 1 ] ) ) ;
2022-04-24 16:05:27 -07:00
}
2022-04-27 04:52:09 -07:00
public int GetSingleByteValue ( int int_232 )
2022-04-24 16:05:27 -07:00
{
2022-05-07 17:39:50 -07:00
return ( int ) this . ROM_Bytes [ int_232 ] ;
2022-04-24 16:05:27 -07:00
}
2022-04-27 04:52:09 -07:00
public void SetBackColor ( int int_232 , float float_0 , float float_1 )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
for ( int i = 0 ; i < int_232 ; i + + )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
foreach ( object obj in ( ( IEnumerable ) Editortable_0 . dataGridView_0 . Rows ) )
{
DataGridViewRow dataGridViewRow = ( DataGridViewRow ) obj ;
try
{
float float_2 = float . Parse ( dataGridViewRow . Cells [ i ] . Value . ToString ( ) ) ;
dataGridViewRow . Cells [ i ] . Style . BackColor = this . GetColor ( float_2 , float_1 , float_0 ) ;
}
catch
{
dataGridViewRow . Cells [ i ] . Style . BackColor = System . Drawing . SystemColors . ControlLight ;
//dataGridViewRow.Cells[i].Style.BackColor = Color.White;
}
}
2022-04-24 16:05:27 -07:00
}
2022-04-27 04:52:09 -07:00
}
public Color GetColor ( float float_0 , float float_1 , float float_2 )
{
Color result ;
2022-05-07 17:39:50 -07:00
if ( float_0 > float_1 ) return Color . White ; //More than Maximum
if ( float_0 < float_2 ) return Color . White ; //Less than Minimum
2022-04-27 04:52:09 -07:00
try
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
int num = ( int ) ( 1023f * ( float_0 - float_1 ) / ( float_2 - float_1 ) ) ;
if ( num < 256 )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
result = Color . FromArgb ( 255 , num , 0 ) ;
}
else if ( num < 512 )
{
num - = 256 ;
result = Color . FromArgb ( 255 - num , 255 , 0 ) ;
}
else if ( num < 768 )
{
num - = 512 ;
result = Color . FromArgb ( 0 , 255 , num ) ;
}
else
{
num - = 768 ;
result = Color . FromArgb ( 0 , 255 - num , 255 ) ;
2022-04-24 16:05:27 -07:00
}
}
2022-04-27 04:52:09 -07:00
catch
{
result = Color . White ;
}
return result ;
}
2022-04-30 09:08:54 -07:00
//Buffer 10 x 20
2022-04-27 04:52:09 -07:00
public T [ , ] smethod_35 < T > ( T [ ] gparam_0 , int int_232 , int int_233 )
{
T [ , ] array = new T [ int_232 , int_233 ] ;
for ( int i = 0 ; i < int_232 ; i + + )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
for ( int j = 0 ; j < int_233 ; j + + )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
array [ i , j ] = gparam_0 [ i * int_233 + j ] ;
2022-04-24 16:05:27 -07:00
}
}
2022-04-27 04:52:09 -07:00
return array ;
}
public void LoadSupportedECUDefinitions ( )
{
try
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
Ecus_Definitions_Compatible = new List < string > ( ) ;
Editortable_0 . CheckDefinitionFolderExist ( ) ;
string Folderpath = Application . StartupPath + @"\Definitions" ;
if ( Directory . Exists ( Folderpath ) )
2022-04-24 16:05:27 -07:00
{
2022-05-01 16:07:45 -07:00
string [ ] AllDefinitionFiles = Directory . GetFiles ( Folderpath , "*.txt" , SearchOption . AllDirectories ) ;
2022-04-27 04:52:09 -07:00
Editortable_0 . GForm_Main_0 . method_1 ( "Loading definitions files..." ) ;
foreach ( string ThisFilePath in AllDefinitionFiles )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
string [ ] AllLines = File . ReadAllLines ( ThisFilePath ) ;
bool GettingEcuList = true ;
for ( int i = 0 ; i < AllLines . Length ; i + + )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
string Thisline = AllLines [ i ] ;
if ( Thisline . Contains ( "ROM Parameters" ) ) GettingEcuList = false ; //make sure we are not reading false contents
if ( Thisline [ 0 ] ! = '#' & & Thisline ! = "" )
{
if ( GettingEcuList )
{
Ecus_Definitions_Compatible . Add ( Thisline ) ;
Editortable_0 . GForm_Main_0 . method_1 ( "Definitions found for ecu: " + Thisline ) ;
}
}
if ( ! GettingEcuList ) i = AllLines . Length ;
2022-04-24 16:05:27 -07:00
}
}
}
2022-04-27 04:52:09 -07:00
else
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
DarkMessageBox . Show ( "Failed to find definitions folder." ) ;
2022-04-24 16:05:27 -07:00
}
}
2022-04-27 04:52:09 -07:00
catch ( Exception ex )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
DarkMessageBox . Show ( "Failed to load definitions. " + ex . ToString ( ) ) ;
2022-04-24 16:05:27 -07:00
}
}
2022-04-27 04:52:09 -07:00
public void LoadThisECUDefinitions ( string ThisECU )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
try
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
Editortable_0 . CheckDefinitionFolderExist ( ) ;
string Folderpath = Application . StartupPath + @"\Definitions" ;
if ( Directory . Exists ( Folderpath ) )
2022-04-24 16:05:27 -07:00
{
2022-05-01 16:07:45 -07:00
string [ ] AllDefinitionFiles = Directory . GetFiles ( Folderpath , "*.txt" , SearchOption . AllDirectories ) ;
2022-04-27 04:52:09 -07:00
DefinitionsLocationsX = new List < string > ( ) ;
DefinitionsLocationsY = new List < string > ( ) ;
DefinitionsLocationsTable = new List < string > ( ) ;
DefinitionsName = new List < string > ( ) ;
DefinitionsUnit1 = new List < string > ( ) ;
DefinitionsUnit2 = new List < string > ( ) ;
DefinitionsTableSize = new List < string > ( ) ;
DefinitionsMathX = new List < string > ( ) ;
DefinitionsMathY = new List < string > ( ) ;
2022-05-07 17:39:50 -07:00
DefinitionsMathTable = new List < string > ( ) ;
DefinitionsMathXInverted = new List < string > ( ) ;
DefinitionsMathYInverted = new List < string > ( ) ;
DefinitionsMathTableInverted = new List < string > ( ) ;
2022-04-27 04:52:09 -07:00
DefinitionsValueMin = new List < float > ( ) ;
DefinitionsValueMax = new List < float > ( ) ;
DefinitionsChangeAmount = new List < double > ( ) ;
DefinitionsIsSingleByteX = new List < bool > ( ) ;
DefinitionsIsSingleByteY = new List < bool > ( ) ;
DefinitionsIsSingleByteTable = new List < bool > ( ) ;
DefinitionsHeaders = new List < string > ( ) ;
2022-05-07 17:39:50 -07:00
DefinitionsFormatX = new List < string > ( ) ;
2022-04-27 04:52:09 -07:00
DefinitionsFormatY = new List < string > ( ) ;
2022-05-07 17:39:50 -07:00
DefinitionsFormatTable = new List < string > ( ) ;
2022-05-03 09:25:40 -07:00
DefinitionsIsXYInverted = new List < bool > ( ) ;
DefinitionsIsTableInverted = new List < bool > ( ) ;
2022-05-07 17:39:50 -07:00
DefinitionsIsReadOnly = new List < bool > ( ) ;
DefinitionsIsUntested = new List < bool > ( ) ;
DefinitionsIsNotDefined = new List < bool > ( ) ;
2022-04-27 04:52:09 -07:00
Editortable_0 . GForm_Main_0 . method_1 ( "Loading ECU definitions for: " + ThisECU ) ;
bool ECUFound = false ;
2022-05-07 17:39:50 -07:00
bool IsFileGenerated = false ;
2022-04-27 04:52:09 -07:00
foreach ( string ThisFilePath in AllDefinitionFiles )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
string [ ] AllLines = File . ReadAllLines ( ThisFilePath ) ;
bool GettingEcuList = true ;
string CurrentLocationX = "" ;
string CurrentLocationY = "" ;
string CurrentLocationTable = "" ;
string CurrentName = "" ;
string CurrentUnit1 = "" ;
string CurrentUnit2 = "" ;
string CurrentTableSize = "" ;
string CurrentMathX = "" ;
string CurrentMathY = "" ;
string CurrentMathTable = "" ;
2022-05-07 17:39:50 -07:00
string CurrentMathXInverted = "" ;
string CurrentMathYInverted = "" ;
string CurrentMathTableInverted = "" ;
2022-04-27 04:52:09 -07:00
float CurrentValueMin = 0f ;
float CurrentValueMax = 255f ;
double CurrentChangeAmount = 1 ;
bool CurrentIsSingleByteX = false ;
bool CurrentIsSingleByteY = false ;
bool CurrentIsSingleByteTable = false ;
string CurrentFormatX = "" ;
string CurrentFormatY = "" ;
string CurrentFormatTable = "" ;
string CurrentHeaders = "" ;
2022-05-03 09:25:40 -07:00
bool CurrentIsXYInverted = false ;
bool CurrentIsTableInverted = false ;
2022-05-07 17:39:50 -07:00
bool CurrentIsReadOnly = false ;
bool CurrentIsUntested = false ;
bool CurrentIsNotDefined = false ;
IsFileGenerated = false ;
2022-04-27 04:52:09 -07:00
for ( int i = 0 ; i < AllLines . Length ; i + + )
2022-04-24 16:05:27 -07:00
{
2022-04-27 04:52:09 -07:00
string Thisline = AllLines [ i ] ;
if ( Thisline . Contains ( "ROM Parameters" ) ) GettingEcuList = false ; //make sure we are not reading false contents
2022-05-07 17:39:50 -07:00
if ( Thisline . Contains ( "THIS FILE AS BEEN GENERATED" ) ) IsFileGenerated = true ;
2022-05-03 09:25:40 -07:00
2022-04-27 04:52:09 -07:00
//Get supported ecu list from file and check if it's match
if ( Thisline [ 0 ] ! = '#' & & Thisline ! = "" )
{
if ( GettingEcuList & & Thisline = = ThisECU ) ECUFound = true ;
}
if ( ! GettingEcuList & & ! ECUFound ) i = AllLines . Length ;
if ( ! GettingEcuList & & ECUFound )
{
//Get Definitions parameters
if ( Thisline [ 0 ] ! = '#' & & Thisline ! = "" )
{
//ROMLocation Name Unit1 Unit2 TableSize Math ValueMin ValueMax ChangeAmount IsWord Format Headers
if ( Thisline . Contains ( ":" ) )
{
string [ ] Commands = Thisline . Split ( ':' ) ;
if ( Commands [ 0 ] = = "ROMLocationX" ) CurrentLocationX = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "ROMLocationY" ) CurrentLocationY = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "ROMLocationTable" ) CurrentLocationTable = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "Name" ) CurrentName = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "Unit1" ) CurrentUnit1 = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "Unit2" ) CurrentUnit2 = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "TableSize" ) CurrentTableSize = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "MathX" ) CurrentMathX = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "MathY" ) CurrentMathY = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "MathTable" ) CurrentMathTable = Commands [ 1 ] ;
2022-05-07 17:39:50 -07:00
if ( Commands [ 0 ] = = "MathXInverted" ) CurrentMathXInverted = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "MathYInverted" ) CurrentMathYInverted = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "MathTableInverted" ) CurrentMathTableInverted = Commands [ 1 ] ;
2022-04-30 09:08:54 -07:00
if ( Commands [ 0 ] = = "ValueMin" ) CurrentValueMin = ( float ) double . Parse ( Commands [ 1 ] . Replace ( ',' , '.' ) , CultureInfo . InvariantCulture ) ;
if ( Commands [ 0 ] = = "ValueMax" ) CurrentValueMax = ( float ) double . Parse ( Commands [ 1 ] . Replace ( ',' , '.' ) , CultureInfo . InvariantCulture ) ;
if ( Commands [ 0 ] = = "ChangeAmount" ) CurrentChangeAmount = double . Parse ( Commands [ 1 ] . Replace ( ',' , '.' ) , CultureInfo . InvariantCulture ) ;
2022-04-27 04:52:09 -07:00
if ( Commands [ 0 ] = = "IsSingleByteX" ) CurrentIsSingleByteX = bool . Parse ( Commands [ 1 ] . ToLower ( ) ) ;
if ( Commands [ 0 ] = = "IsSingleByteY" ) CurrentIsSingleByteY = bool . Parse ( Commands [ 1 ] . ToLower ( ) ) ;
if ( Commands [ 0 ] = = "IsSingleByteTable" ) CurrentIsSingleByteTable = bool . Parse ( Commands [ 1 ] . ToLower ( ) ) ;
if ( Commands [ 0 ] = = "FormatX" ) CurrentFormatX = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "FormatY" ) CurrentFormatY = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "FormatTable" ) CurrentFormatTable = Commands [ 1 ] ;
if ( Commands [ 0 ] = = "Headers" ) CurrentHeaders = Commands [ 1 ] ;
2022-05-03 09:25:40 -07:00
if ( Commands [ 0 ] = = "IsXYInverted" ) CurrentIsXYInverted = bool . Parse ( Commands [ 1 ] . ToLower ( ) ) ;
if ( Commands [ 0 ] = = "IsTableInverted" ) CurrentIsTableInverted = bool . Parse ( Commands [ 1 ] . ToLower ( ) ) ;
2022-05-07 17:39:50 -07:00
if ( Commands [ 0 ] = = "IsReadOnly" ) CurrentIsReadOnly = bool . Parse ( Commands [ 1 ] . ToLower ( ) ) ;
if ( Commands [ 0 ] = = "IsUntested" ) CurrentIsUntested = bool . Parse ( Commands [ 1 ] . ToLower ( ) ) ;
if ( Commands [ 0 ] = = "IsNotDefined" ) CurrentIsNotDefined = bool . Parse ( Commands [ 1 ] . ToLower ( ) ) ;
2022-04-27 04:52:09 -07:00
}
}
//Insert Definitions
//if (Thisline.Contains("######") || Thisline == "")
if ( Thisline . Contains ( "######" ) )
{
if ( CurrentName ! = "" )
{
CurrentName = CurrentName . Replace ( "\\x00b0" , "°" ) ;
2022-05-07 17:39:50 -07:00
CurrentUnit1 = CurrentUnit1 . Replace ( "\\x00b0" , "°" ) ;
CurrentUnit2 = CurrentUnit2 . Replace ( "\\x00b0" , "°" ) ;
2022-04-27 04:52:09 -07:00
DefinitionsLocationsX . Add ( CurrentLocationX ) ;
DefinitionsLocationsY . Add ( CurrentLocationY ) ;
DefinitionsLocationsTable . Add ( CurrentLocationTable ) ;
DefinitionsName . Add ( CurrentName ) ;
DefinitionsUnit1 . Add ( CurrentUnit1 ) ;
DefinitionsUnit2 . Add ( CurrentUnit2 ) ;
DefinitionsTableSize . Add ( CurrentTableSize ) ;
DefinitionsMathX . Add ( CurrentMathX ) ;
DefinitionsMathY . Add ( CurrentMathY ) ;
DefinitionsMathTable . Add ( CurrentMathTable ) ;
2022-05-07 17:39:50 -07:00
DefinitionsMathXInverted . Add ( CurrentMathXInverted ) ;
DefinitionsMathYInverted . Add ( CurrentMathYInverted ) ;
DefinitionsMathTableInverted . Add ( CurrentMathTableInverted ) ;
2022-04-27 04:52:09 -07:00
DefinitionsValueMin . Add ( CurrentValueMin ) ;
DefinitionsValueMax . Add ( CurrentValueMax ) ;
DefinitionsChangeAmount . Add ( CurrentChangeAmount ) ;
DefinitionsIsSingleByteX . Add ( CurrentIsSingleByteX ) ;
DefinitionsIsSingleByteY . Add ( CurrentIsSingleByteY ) ;
DefinitionsIsSingleByteTable . Add ( CurrentIsSingleByteTable ) ;
DefinitionsFormatX . Add ( CurrentFormatX ) ;
DefinitionsFormatY . Add ( CurrentFormatY ) ;
DefinitionsFormatTable . Add ( CurrentFormatTable ) ;
DefinitionsHeaders . Add ( CurrentHeaders ) ;
2022-05-03 09:25:40 -07:00
DefinitionsIsXYInverted . Add ( CurrentIsXYInverted ) ;
DefinitionsIsTableInverted . Add ( CurrentIsTableInverted ) ;
2022-05-07 17:39:50 -07:00
DefinitionsIsReadOnly . Add ( CurrentIsReadOnly ) ;
DefinitionsIsUntested . Add ( CurrentIsUntested ) ;
DefinitionsIsNotDefined . Add ( CurrentIsNotDefined ) ;
2022-04-27 04:52:09 -07:00
//Reset values to default
CurrentLocationX = "" ;
CurrentLocationY = "" ;
CurrentLocationTable = "" ;
CurrentName = "" ;
CurrentUnit1 = "" ;
CurrentUnit2 = "" ;
CurrentTableSize = "" ;
CurrentMathX = "" ;
CurrentMathY = "" ;
CurrentMathTable = "" ;
2022-05-07 17:39:50 -07:00
CurrentMathXInverted = "" ;
CurrentMathYInverted = "" ;
CurrentMathTableInverted = "" ;
2022-04-27 04:52:09 -07:00
CurrentValueMin = 0f ;
CurrentValueMax = 255f ;
CurrentChangeAmount = 1f ;
CurrentIsSingleByteX = false ;
CurrentIsSingleByteY = false ;
CurrentIsSingleByteTable = false ;
CurrentFormatX = "" ;
CurrentHeaders = "" ;
CurrentFormatY = "" ;
CurrentFormatTable = "" ;
2022-05-03 09:25:40 -07:00
CurrentIsXYInverted = false ;
CurrentIsTableInverted = false ;
2022-05-07 17:39:50 -07:00
CurrentIsReadOnly = false ;
CurrentIsUntested = false ;
CurrentIsNotDefined = false ;
2022-04-27 04:52:09 -07:00
}
}
}
2022-04-24 16:05:27 -07:00
}
2022-04-27 04:52:09 -07:00
2022-05-07 17:39:50 -07:00
if ( ECUFound )
{
Editortable_0 . GForm_Main_0 . method_1 ( "Definitions loaded!" ) ;
if ( IsFileGenerated ) DarkMessageBox . Show ( "This Definitions file as been generated to get the ROM Locations.\nThe ROM Locations can possibly be wrong and\nthe tables can display corrupted values!" ) ;
return ;
}
2022-04-24 16:05:27 -07:00
}
2022-04-27 04:52:09 -07:00
if ( ! ECUFound ) Editortable_0 . GForm_Main_0 . method_1 ( "Definitions NOT loaded!" ) ;
}
else
{
DarkMessageBox . Show ( "Failed to find definitions folder." ) ;
}
}
catch ( Exception ex )
{
DarkMessageBox . Show ( "Failed to load definitions. " + ex . ToString ( ) ) ;
}
}
[CompilerGenerated]
private sealed class Class40
{
internal Class40 ( )
{
}
internal void method_0 ( object object_0 )
{
this . taskCompletionSource_0 . SetResult ( null ) ;
}
public TaskCompletionSource < object > taskCompletionSource_0 ;
}
//########################################################################################################################################
//########################################################################################################################################
//########################################################################################################################################
//########################################################################################################################################
/ * public string smethod_0 ( ZipArchiveEntry zipArchiveEntry_0 )
{
string text = "" ;
using ( Stream stream = zipArchiveEntry_0 . Open ( ) )
{
using ( StreamReader streamReader = new StreamReader ( stream , Encoding . GetEncoding ( "iso-8859-1" ) ) )
{
text + = streamReader . ReadToEnd ( ) ;
}
}
return text ;
} * /
/ * public bool smethod_22 ( string TableSize )
{
int [ ] arraytableint = new int [ 0 ] ;
if ( TableSize = = "1X64" ) arraytableint = this . int_220 ;
if ( TableSize = = "1X15" ) arraytableint = this . int_221 ;
if ( TableSize = = "1X8" ) arraytableint = this . int_222 ;
if ( TableSize = = "1X7" ) arraytableint = this . int_223 ;
if ( TableSize = = "1X6" ) arraytableint = this . int_224 ;
if ( TableSize = = "1X5" ) arraytableint = this . int_225 ;
if ( TableSize = = "1X4" ) arraytableint = this . int_226 ;
if ( TableSize = = "1X2" ) arraytableint = this . int_230 ;
if ( TableSize = = "1X1" ) arraytableint = this . int_231 ;
int num = 0 ;
int num2 = 0 ;
for ( int i = 0 ; i < Editortable_0 . dataGridView_0 . ColumnCount ; i + + )
{
try
{
if ( TableSize = = "1X64" ) num2 = ( int ) float . Parse ( Editortable_0 . dataGridView_0 . Rows [ 0 ] . Cells [ i ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) ;
if ( TableSize = = "1X15" ) num2 = ( int ) ( 32767f / float . Parse ( Editortable_0 . dataGridView_0 . Rows [ 0 ] . Cells [ i ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) ) ;
if ( TableSize = = "1X8" ) num2 = ( int ) ( float . Parse ( Editortable_0 . dataGridView_0 . Rows [ 0 ] . Cells [ i ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) / 0.002f ) ;
if ( TableSize = = "1X7" ) num2 = ( int ) ( float . Parse ( Editortable_0 . dataGridView_0 . Rows [ 0 ] . Cells [ i ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) / 0.01f ) ;
if ( TableSize = = "1X6" ) num2 = ( int ) ( float . Parse ( Editortable_0 . dataGridView_0 . Rows [ 0 ] . Cells [ i ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) / 0.005f ) ;
if ( TableSize = = "1X5" )
{
if ( Editortable . genum2_0 = = Editortable . GEnum2 . INJ_DEADTIME )
{
num2 = ( int ) ( ( double ) float . Parse ( Editortable_0 . dataGridView_0 . Rows [ 0 ] . Cells [ i ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) / 0.002 ) ;
}
else
{
num2 = ( int ) float . Parse ( Editortable_0 . dataGridView_0 . Rows [ 0 ] . Cells [ i ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) ;
}
}
if ( TableSize = = "1X4" )
{
if ( Editortable . genum2_0 = = Editortable . GEnum2 . VTEC_PARAMS )
{
num2 = ( int ) float . Parse ( Editortable_0 . dataGridView_0 . Rows [ i ] . Cells [ 0 ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) ;
}
else
2022-04-24 16:05:27 -07:00
{
num2 = ( int ) float . Parse ( Editortable_0 . dataGridView_0 . Rows [ 0 ] . Cells [ i ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) ;
}
}
if ( TableSize = = "1X2" )
{
double numBuf = double . Parse ( Editortable_0 . dataGridView_0 . Rows [ 0 ] . Cells [ 0 ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) ;
if ( Editortable_0 . dataGridView_0 . Columns [ 0 ] . HeaderText = = "MPH" ) numBuf = Math . Floor ( numBuf * 1.609344 ) ;
num2 = ( int ) numBuf ;
}
if ( TableSize = = "1X1" )
{
if ( Editortable . genum2_0 = = Editortable . GEnum2 . MIN_IPW )
{
double numBuf = double . Parse ( Editortable_0 . dataGridView_0 . Rows [ 0 ] . Cells [ 0 ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) / 0.002 ;
num2 = ( int ) numBuf ;
}
else
{
double numBuf = double . Parse ( Editortable_0 . dataGridView_0 . Rows [ 0 ] . Cells [ 0 ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) ;
if ( Editortable_0 . dataGridView_0 . Columns [ 0 ] . HeaderText = = "MPH" ) numBuf = Math . Floor ( num * 1.609344 ) ;
num2 = ( int ) num ;
}
}
if ( TableSize = = "1X2" | | TableSize = = "1X1" ) num = 0 ;
arraytableint [ num + 1 ] = ( int ) ( ( byte ) num2 ) ;
arraytableint [ num ] = ( int ) ( ( byte ) ( num2 > > 8 ) ) ;
num + = 2 ;
}
catch
{
return false ;
}
}
int num3 = this . int_0 ;
int [ ] array = new int [ this . int_1 * 2 ] ;
for ( int j = 0 ; j < this . int_1 * 2 ; j + + )
{
array [ j ] = ( int ) this . byte_0 [ num3 ] ;
num3 + + ;
}
int num4 = 0 ;
foreach ( int num5 in arraytableint )
{
if ( num5 . ToString ( ) ! = array [ num4 ] . ToString ( ) ) this . bool_2 = true ;
num4 + + ;
}
return true ;
2022-04-27 04:52:09 -07:00
} * /
2022-04-24 16:05:27 -07:00
2022-04-27 04:52:09 -07:00
/ * public bool smethod_31 ( )
2022-04-24 16:05:27 -07:00
{
if ( this . int_1 ! = 0 & & this . int_0 ! = 0 )
{
if ( this . int_1 = = 200 )
{
return this . smethod_21 ( ) ;
}
if ( this . int_1 = = 64 )
{
return this . smethod_22 ( "1X64" ) ;
}
if ( this . int_1 = = 15 )
{
return this . smethod_22 ( "1X15" ) ;
}
if ( this . int_1 = = 8 )
{
return this . smethod_22 ( "1X8" ) ;
}
if ( this . int_1 = = 7 )
{
return this . smethod_22 ( "1X7" ) ;
}
if ( this . int_1 = = 6 )
{
return this . smethod_22 ( "1X6" ) ;
}
if ( this . int_1 = = 5 )
{
return this . smethod_22 ( "1X5" ) ;
}
if ( this . int_1 = = 4 )
{
return this . smethod_22 ( "1X4" ) ;
}
if ( this . int_1 = = 2 )
{
return this . smethod_22 ( "1X2" ) ;
}
if ( this . int_1 = = 1 )
{
return this . smethod_22 ( "1X1" ) ;
}
}
return false ;
2022-04-27 04:52:09 -07:00
} * /
2022-04-24 16:05:27 -07:00
2022-04-27 04:52:09 -07:00
/ * public void smethod_32 ( )
2022-04-24 16:05:27 -07:00
{
Editortable_0 . dataGridView_0 . ReadOnly = true ;
if ( this . bool_0 )
{
if ( this . string_0 . Contains ( "RRB" ) )
{
if ( ! this . smethod_31 ( ) )
{
this . bool_2 = false ;
DarkMessageBox . Show ( "Table changes fail" ) ;
return ;
}
}
else if ( this . string_0 . Contains ( "S2K" ) & & ! this . smethod_31 ( ) )
{
this . bool_2 = false ;
DarkMessageBox . Show ( "Table changes fail" ) ;
}
}
2022-04-27 04:52:09 -07:00
} * /
2022-04-24 16:05:27 -07:00
}