AutoHotkey Community

It is currently May 27th, 2012, 6:20 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: November 30th, 2010, 7:42 pm 
Update: Im not going to try to shift all of the cheats down but one.

If i delete All of Cheat2 im going to move All of The Last Cheat to Cheat2.

Update2: I have a fully functioning edit command, and improves some stuff on my add command.
It now removes any trailing blank lines, and removes all blank lines in the middle.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 5th, 2010, 2:19 am 
Offline

Joined: March 22nd, 2009, 11:12 pm
Posts: 28
Here's a function that'll delete cheats and an example usage:

Example:
Code:
MsgBox,, Cheat 5 Deleted, % deletecheat("cheats.ini", "AEROGAUGE.Cheats", 5) . " keys were deleted."


Function:
Code:
deletecheat(file, game, cheat)
{
 IniDelete, %file%, %game%, CheatName%cheat%
 IniRead, _count, %file%, %game%, CheatName%cheat%Count
 IniDelete, %file%, %game%, CheatName%cheat%Count
 Loop, %_count%
 {
    Index := A_Index - 1
    IniDelete, %file%, %game%, CheatName%cheat%Code%Index%
 }
 IniRead, num, %file%, %game%, NumCheats
 IniWrite, % num - 1, %file%, %game%, NumCheats
 Loop,% num - cheat - 1
 {
  Src := cheat + A_Index
  Dest := cheat + A_Index - 1
  IniRead, desc, %file%, %game%, CheatName%Src%
  IniDelete, %file%, %game%, CheatName%Src%
  IniWrite, % desc, %file%, %game%, CheatName%Dest%
  IniRead, count, %file%, %game%, CheatName%Src%Count
  IniDelete, %file%, %game%, CheatName%Src%Count
  IniWrite, % count, %file%, %game%, CheatName%Dest%Count
  Loop, %count%
  {
   Index := A_Index - 1
   IniRead, code, %file%, %game%, CheatName%Src%Code%Index%
   IniDelete, %file%, %game%, CheatName%Src%Code%Index%
   IniWrite, % code, %file%, %game%, CheatName%Dest%Code%Index%
  }
 }
 Return _count + 2
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 5th, 2010, 2:26 am 
Thank you
Thank you
Thank you
Thank you
Thank you
Thank you
and
Thank you

That works.
I can delete codes now. Thanks "B R"


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 5th, 2010, 3:19 am 
Offline
User avatar

Joined: August 23rd, 2010, 6:22 pm
Posts: 781
Location: Ontario, Canada
This is the file reader code:

Code:
BinRead(file,data,0x13,0x20) ;Read file
Text := Hex2Bin(Data) ;Convert to ascii
Text = %Text% ;Trim spaces

Hex2Bin(Hex)
{
 Loop, % StrLen(Hex) // 2
  Ascii .= Chr("0x" . SubStr(Hex,(A_Index * 2) - 1,2))
 Return, Ascii
}

BinRead(file, ByRef data, n=0, offset=0)
{
   h := DllCall("CreateFile","Str",file,"Uint",0x80000000,"Uint",3,"UInt",0,"UInt",3,"Uint",0,"UInt",0)
   IfEqual h,-1, SetEnv, ErrorLevel, -1
   IfNotEqual ErrorLevel,0,Return,0 ; couldn't open the file

   m = 0                            ; seek to offset
   IfLess offset,0, SetEnv,m,2
   r := DllCall("SetFilePointerEx","Uint",h,"Int64",offset,"UInt *",p,"Int",m)
   IfEqual r,0, SetEnv, ErrorLevel, -3
   IfNotEqual ErrorLevel,0, {
      t = %ErrorLevel%              ; save ErrorLevel to be returned
      DllCall("CloseHandle", "Uint", h)
      ErrorLevel = %t%              ; return seek error
      Return 0
   }

   TotalRead = 0
   data =
   IfEqual n,0, SetEnv n,0xffffffff ; almost infinite

   format = %A_FormatInteger%       ; save original integer format
   SetFormat Integer, Hex           ; for converting bytes to hex

   Loop %n%
   {
      result := DllCall("ReadFile","UInt",h,"UChar *",c,"UInt",1,"UInt *",Read,"UInt",0)
      if (!result or Read < 1 or ErrorLevel)
         break
      TotalRead += Read             ; count read
      c += 0                        ; convert to hex
      StringTrimLeft c, c, 2        ; remove 0x
      c = 0%c%                      ; pad left with 0
      StringRight c, c, 2           ; always 2 digits
      data = %data%%c%              ; append 2 hex digits
   }

   IfNotEqual ErrorLevel,0, SetEnv,t,%ErrorLevel%

   h := DllCall("CloseHandle", "Uint", h)
   IfEqual h,-1, SetEnv, ErrorLevel, -2
   IfNotEqual t,,SetEnv, ErrorLevel, %t%

   SetFormat Integer, %format%      ; restore original format
   Totalread += 0                   ; convert to original format
   Return TotalRead
}

_________________
AutoHotkey.net | GitHub

My default license.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 5th, 2010, 3:20 am 
Great, it works.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 5th, 2010, 6:26 am 
Edit First Post:
UPDATE: Currently in working Condition: Application


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: hd0202 and 53 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group