Advertisement
Brandan

Populous Class V0.1

Mar 3rd, 2014
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 33.38 KB | None | 0 0
  1. Imports System.Runtime.InteropServices
  2. Imports System.Threading
  3. Imports System.Text
  4. Imports System.IO
  5.  
  6. ' Ranking system and charts built into program, probably if I feel like it
  7.  
  8. Public Class Populous
  9.  
  10.     Public Structure Info
  11.         Shared InstallPath As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Bullfrog Productions Ltd\Populous: The Beginning", "InstallPath", "")
  12.         Shared InstallDirectory As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Bullfrog Productions Ltd\Populous: The Beginning", "InstallDirectory", "")
  13.         Shared InstallDrive As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Bullfrog Productions Ltd\Populous: The Beginning", "InstallDrive", "")
  14.         Shared Language As Integer = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Bullfrog Productions Ltd\Populous: The Beginning", "Language", "")
  15.         Shared MathmakerURL As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Bullfrog Productions Ltd\Populous: The Beginning", "Matchmaker URL", "")
  16.         Shared Version As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Bullfrog Productions Ltd\Populous: The Beginning", "Version", "")
  17.     End Structure
  18.  
  19.     Shared keys_cmd = New String() {"Pause", _
  20.                             "Toggle View", _
  21.                             "Encyclopaedia", _
  22.                             "Set map marker 1", _
  23.                             "Set map marker 2", _
  24.                             "Set map marker 3", _
  25.                             "Set map marker 4", _
  26.                             "Goto map marker 1", _
  27.                             "Goto map marker 2", _
  28.                             "Goto map marker 3", _
  29.                             "Goto map marker 4", _
  30.                             "Zoom in", _
  31.                             "Zoom out", _
  32.                             "Quick load", _
  33.                             "Quick save", _
  34.                             "Goto shaman", _
  35.                             "Chat/Message", _
  36.                             "Command tracking", _
  37.                             "Release Guarding", _
  38.                             "Toggle level stats", _
  39.                             "Rotate building", _
  40.                             "Assign units to group 1", _
  41.                             "Assign units to group 2", _
  42.                             "Assign units to group 3", _
  43.                             "Assign units to group 4", _
  44.                             "Assign units to group 5", _
  45.                             "Assign units to group 6", _
  46.                             "Select units to group 1", _
  47.                             "Select units to group 2", _
  48.                             "Select units to group 3", _
  49.                             "Select units to group 4", _
  50.                             "Select units to group 5", _
  51.                             "Select units to group 6", _
  52.                             "Goto units to group 1", _
  53.                             "Goto units to group 2", _
  54.                             "Goto units to group 3", _
  55.                             "Goto units to group 4", _
  56.                             "Goto units to group 5", _
  57.                             "Goto units to group 6", _
  58.                             "Goto reincarnation site", _
  59.                             "Toggle local selection", _
  60.                             "Reselect last selection", _
  61.                             "Reorient view", _
  62.                             "Display last dialog", _
  63.                             "Toggle auto deselect", _
  64.                             "Call to arms", _
  65.                             "Scatter people"}
  66.  
  67.     Structure constant
  68.         Shared name
  69.         Shared value
  70.     End Structure
  71.     Structure keybind
  72.         Public cmd As String
  73.         Public modifer
  74.         Public key
  75.     End Structure
  76.     Public Structure player
  77.         Public tribe As tribe
  78.  
  79.         Public time
  80.         Public flightWwon
  81.         Public fightsLost
  82.         Public enemyFolloweredKilled
  83.         Public enemyBuildingsDestroyed
  84.         Public enemyShamanLills
  85.         Public ownFollowersLost
  86.         Public ownBuildingsDestroyed
  87.         Public ownShamanDeaths
  88.  
  89.         ' Units
  90.         Public units_total_population As Integer
  91.         Public units_total_firewarrior As Integer
  92.         Public units_total_preist As Integer
  93.         Public units_total_spy As Integer
  94.         Public units_total_brave As Integer
  95.  
  96.         ' Selected Units
  97.         Public units_selected_total_population As Integer
  98.         Public units_selected_total_firewarrior As Integer
  99.         Public units_selected_total_preist As Integer
  100.         Public units_selected_total_spy As Integer
  101.         Public units_selected_total_brave As Integer
  102.  
  103.         ' Idle Units
  104.         Public units_idle_total_population As Integer
  105.         Public units_idle_total_firewarrior As Integer
  106.         Public units_idle_total_preist As Integer
  107.         Public units_idle_total_spy As Integer
  108.         Public units_idle_total_brave As Integer
  109.  
  110.         ' Units in huts
  111.         Public units_hut_total_population As Integer
  112.         Public units_hut_total_firewarrior As Integer
  113.         Public units_hut_total_preist As Integer
  114.         Public units_hut_total_spy As Integer
  115.         Public units_hut_total_brave As Integer
  116.  
  117.         ' Units working
  118.         Public units_working_total_population As Integer
  119.         Public units_working_total_firewarrior As Integer
  120.         Public units_working_total_preist As Integer
  121.         Public units_working_total_spy As Integer
  122.         Public units_working_total_brave As Integer
  123.  
  124.         ' Units in boat
  125.         Public units_boat_total_population As Integer
  126.         Public units_boat_total_firewarrior As Integer
  127.         Public units_boat_total_preist As Integer
  128.         Public units_boat_total_spy As Integer
  129.         Public units_boat_total_brave As Integer
  130.  
  131.         ' Units in baloon
  132.         Public units_baloon_total_population As Integer
  133.         Public units_baloon_total_firewarrior As Integer
  134.         Public units_baloon_total_preist As Integer
  135.         Public units_baloon_total_spy As Integer
  136.         Public units_baloon_total_brave As Integer
  137.  
  138.  
  139.         Public vehicle_total_boat
  140.         Public vehicle_total_baloon
  141.  
  142.         Public spells As spell
  143.         Public buildings As building
  144.         Public special As special
  145.  
  146.     End Structure
  147.     Public Structure spell
  148.         Public convert
  149.         Public blast
  150.         Public bloodlust
  151.         Public teleport
  152.         Public armagedon
  153.         Public invisible
  154.         Public swarm
  155.         Public ghosts
  156.         Public lightning
  157.         Public landbridge
  158.         Public magicsheild
  159.         Public swamp
  160.         Public tornado
  161.         Public hypno
  162.         Public erode
  163.         Public earthquake
  164.         Public flatten
  165.         Public volcano
  166.         Public AOD
  167.         Public firestorm
  168.     End Structure
  169.     Public Structure building
  170.         Public hut
  171.         Public tower
  172.         Public warrior
  173.         Public preist
  174.         Public spy
  175.         Public firewarrior
  176.         Public boat
  177.         Public baloon
  178.     End Structure
  179.     Structure special
  180.         Public GOD
  181.         Public FOG
  182.     End Structure
  183.     Public Enum mode
  184.         Hardware = 0
  185.         Software = 1
  186.     End Enum
  187.     Public Enum tribe As Byte
  188.         blue = 0
  189.         red = 1
  190.         yellow = 2
  191.         green = 3
  192.     End Enum
  193.  
  194.     Shared constants() As constant
  195.     Shared keybindings() As keybind
  196.     Shared players(4) As player
  197.     Shared keys(47) As keybind
  198.  
  199.     Shared datafilestruct = New String() {"0", "1", "2", "3", "4", "5", _
  200. "6", "7", "8", "9", "a", "b", _
  201. "c", "d", "e", "f", "g", "h", _
  202. "i", "j", "k", "l", "m", "n", _
  203. "o", "p", "q", "r", "s", "t", _
  204. "u", "v", "w", "x", "y", "z"}
  205.  
  206.  
  207.     Public Class memory
  208.         ' They're many different ways to hook the game, You can hook it on launch like PopRe MM does or you can Hot Hook it and hook it at a later time.
  209.  
  210.         ' Windows.h/Windows API WriteProcessMemory/ReadProcessMemory
  211.         <DllImport("kernel32.dll")> _
  212.         Public Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, <[In](), Out()> ByVal buffer As Byte(), ByVal size As UInteger, ByRef lpNumberOfBytesWritten As IntPtr) As Integer
  213.         End Function
  214.         <DllImport("kernel32.dll")> _
  215.         Public Shared Function ReadProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, <[In](), Out()> ByVal buffer As Byte(), ByVal size As UInteger, ByRef lpNumberOfBytesRead As IntPtr) As Integer
  216.         End Function
  217.  
  218.         Public proc As Process
  219.  
  220.         Enum GameStatus As Byte
  221.             Quit = 0
  222.             Won = 2
  223.             Lost = 4
  224.         End Enum
  225.  
  226.         Public gameMode As mode
  227.         Public status As GameStatus = GameStatus.Lost
  228.         Public gameStarted As Boolean = False
  229.  
  230.         Private Delegate Sub ExitedEventHandler(ByVal [When] As DateTime)
  231.         Private Event OnExit As ExitedEventHandler
  232.         Public Delegate Sub GameStartEventHandler([When] As DateTime)
  233.         Public Event OnGameStart As GameStartEventHandler
  234.         Private Const DefaultGameSpeed As Byte = 12
  235.  
  236.  
  237.         Public Sub New(ByVal TheProcess As Process)
  238.             proc = TheProcess
  239.         End Sub
  240.         ' Watch for the game to close
  241.  
  242.         ' Operational Functions/Memory Writers
  243.         Private Sub ExitWatcher()
  244.             While True
  245.                 Try
  246.                     Thread.Sleep(1000)
  247.                     If proc.HasExited Then
  248.                         RaiseEvent OnExit(DateTime.Now)
  249.                         Thread.CurrentThread.Abort()
  250.                     End If
  251.  
  252.                 Catch
  253.                 End Try
  254.             End While
  255.         End Sub
  256.  
  257.         ' Read Memory
  258.         Public Function ReadProcessMemory(ByVal MemoryAddress As IntPtr, ByVal bytesToRead As UInteger) As Byte()
  259.             Dim ptr As IntPtr = CType(&H0, IntPtr)
  260.             Dim buffer As Byte() = New Byte(CInt((bytesToRead - 1))) {}
  261.             ReadProcessMemory(proc.Handle, MemoryAddress, buffer, bytesToRead, ptr)
  262.             Return buffer
  263.         End Function
  264.  
  265.         Public Function ReadInt8(ByVal address As IntPtr) As [Byte]
  266.             Return ReadProcessMemory(address, 1)(0)
  267.         End Function
  268.  
  269.         Public Function ReadInt16(ByVal address As IntPtr) As Short
  270.             Return BitConverter.ToInt16(ReadProcessMemory(address, 2), 0)
  271.         End Function
  272.  
  273.         Public Function ReadInt32(ByVal address As IntPtr) As Integer
  274.             Return BitConverter.ToInt32(ReadProcessMemory(address, 4), 0)
  275.         End Function
  276.  
  277.         Public Function ReadString(ByVal address As IntPtr, ByVal enc As Encoding, ByVal MaxLength As UInteger) As String
  278.             Return enc.GetString(ReadProcessMemory(address, MaxLength))
  279.         End Function
  280.  
  281.         ' Write Memory
  282.         Public Function WriteProcessMemory(ByVal address As IntPtr, ByVal bytes As Byte())
  283.             Try
  284.                 Dim r As New IntPtr(&H0)
  285.                 WriteProcessMemory(proc.Handle, address, bytes, CUInt(bytes.Length), r)
  286.                 Return True
  287.             Catch ex As Exception
  288.                 Return False
  289.             End Try
  290.         End Function
  291.  
  292.         Public Function WriteInt8(ByVal address As IntPtr, ByVal val As Byte)
  293.             Try
  294.                 Dim bytes As Byte() = New Byte() {val}
  295.                 WriteProcessMemory(address, bytes)
  296.                 Return True
  297.             Catch ex As Exception
  298.                 Return False
  299.             End Try
  300.         End Function
  301.  
  302.         Public Function WriteInt16(ByVal address As IntPtr, ByVal val As Short)
  303.             Try
  304.                 Dim bytes As Byte() = BitConverter.GetBytes(val)
  305.                 WriteProcessMemory(address, bytes)
  306.                 Return True
  307.             Catch ex As Exception
  308.                 Return False
  309.             End Try
  310.         End Function
  311.  
  312.         Public Function WriteInt32(ByVal address As IntPtr, ByVal val As Integer)
  313.             Try
  314.                 Dim bytes As Byte() = BitConverter.GetBytes(val)
  315.                 WriteProcessMemory(address, bytes)
  316.                 Return True
  317.             Catch ex As Exception
  318.                 Return False
  319.             End Try
  320.         End Function
  321.  
  322.         Public Function WriteString(ByVal address As IntPtr, ByVal enc As Encoding, ByVal str As String)
  323.             Try
  324.                 Dim bytes As Byte() = enc.GetBytes(str)
  325.                 WriteProcessMemory(address, bytes)
  326.                 Return True
  327.             Catch ex As Exception
  328.                 Return False
  329.             End Try
  330.         End Function
  331.  
  332.         ' Additonal Functions
  333.         Public Sub BlockBYRNE()
  334.             If gameMode = mode.Hardware Then
  335.                 WriteInt8(CType(&H46871F, IntPtr), &HE9)
  336.                 WriteInt8(CType(&H468720, IntPtr), &HF2)
  337.                 WriteInt8(CType(&H468721, IntPtr), 0)
  338.                 WriteInt8(CType(&H468722, IntPtr), 0)
  339.                 WriteInt8(CType(&H468723, IntPtr), 0)
  340.             ElseIf gameMode = mode.Software Then
  341.                 WriteInt8(CType(&H4AEA3F, IntPtr), &HE9)
  342.                 WriteInt8(CType(&H4AEA40, IntPtr), &HF2)
  343.                 WriteInt8(CType(&H4AEA41, IntPtr), 0)
  344.                 WriteInt8(CType(&H4AEA42, IntPtr), 0)
  345.                 WriteInt8(CType(&H4AEA43, IntPtr), 0)
  346.             End If
  347.         End Sub
  348.  
  349.         Public Sub BlockResync()
  350.             If gameMode = mode.Hardware Then
  351.                 WriteInt8(CType(&H4AB017, IntPtr), &H90)
  352.                 WriteInt8(CType(&H4AB018, IntPtr), &H90)
  353.                 WriteInt8(CType(&H4AB019, IntPtr), &H90)
  354.                 WriteInt8(CType(&H4AB01A, IntPtr), &H90)
  355.                 WriteInt8(CType(&H4AB01B, IntPtr), &H90)
  356.                 WriteInt8(CType(&H4AB01C, IntPtr), &H90)
  357.                 WriteInt8(CType(&H4AB01D, IntPtr), &H90)
  358.                 WriteInt8(CType(&H4AB01E, IntPtr), &H90)
  359.                 WriteInt8(CType(&H4AB01F, IntPtr), &H90)
  360.                 WriteInt8(CType(&H4AB020, IntPtr), &H90)
  361.                 WriteInt8(CType(&H4AB021, IntPtr), &H90)
  362.                 WriteInt8(CType(&H4AB022, IntPtr), &H90)
  363.                 WriteInt8(CType(&H4AB023, IntPtr), &H90)
  364.                 WriteInt8(CType(&H4AB024, IntPtr), &H90)
  365.                 WriteInt8(CType(&H4AB025, IntPtr), &H90)
  366.                 WriteInt8(CType(&H4AB026, IntPtr), &H90)
  367.                 WriteInt8(CType(&H4AB027, IntPtr), &H90)
  368.                 WriteInt8(CType(&H4AB028, IntPtr), &H90)
  369.                 WriteInt8(CType(&H4AB029, IntPtr), &H90)
  370.                 WriteInt8(CType(&H4AB02A, IntPtr), &H90)
  371.                 WriteInt8(CType(&H4AB02B, IntPtr), &H90)
  372.                 WriteInt8(CType(&H4AB02C, IntPtr), &H90)
  373.                 WriteInt8(CType(&H4AB02D, IntPtr), &H90)
  374.                 WriteInt8(CType(&H4AB02E, IntPtr), &H90)
  375.                 WriteInt8(CType(&H4AB02F, IntPtr), &H90)
  376.                 WriteInt8(CType(&H4AB030, IntPtr), &H90)
  377.                 WriteInt8(CType(&H4AB031, IntPtr), &H90)
  378.                 WriteInt8(CType(&H4AB032, IntPtr), &H90)
  379.                 WriteInt8(CType(&H4AB033, IntPtr), &H90)
  380.                 WriteInt8(CType(&H4AB060, IntPtr), &H90)
  381.                 WriteInt8(CType(&H4AB061, IntPtr), &H90)
  382.                 WriteInt8(CType(&H4AB062, IntPtr), &H90)
  383.                 WriteInt8(CType(&H4AB063, IntPtr), &H90)
  384.                 WriteInt8(CType(&H4AB064, IntPtr), &H90)
  385.                 WriteInt8(CType(&H4AB065, IntPtr), &H90)
  386.                 WriteInt8(CType(&H4AB066, IntPtr), &H90)
  387.                 WriteInt8(CType(&H4AB067, IntPtr), &H90)
  388.                 WriteInt8(CType(&H4AB068, IntPtr), &H90)
  389.                 WriteInt8(CType(&H4AB069, IntPtr), &H90)
  390.                 WriteInt8(CType(&H4AB06A, IntPtr), &H90)
  391.                 WriteInt8(CType(&H4AB06B, IntPtr), &H90)
  392.                 WriteInt8(CType(&H4AB06C, IntPtr), &H90)
  393.                 WriteInt8(CType(&H4AB06D, IntPtr), &H90)
  394.                 WriteInt8(CType(&H4AB06E, IntPtr), &H90)
  395.                 WriteInt8(CType(&H4AB06F, IntPtr), &H90)
  396.                 WriteInt8(CType(&H4AB070, IntPtr), &H90)
  397.                 WriteInt8(CType(&H4AB071, IntPtr), &H90)
  398.                 WriteInt8(CType(&H4AB072, IntPtr), &H90)
  399.                 WriteInt8(CType(&H4AB073, IntPtr), &H90)
  400.                 WriteInt8(CType(&H4AB074, IntPtr), &H90)
  401.                 WriteInt8(CType(&H4AB075, IntPtr), &H90)
  402.                 WriteInt8(CType(&H4AB076, IntPtr), &H90)
  403.                 WriteInt8(CType(&H4AB077, IntPtr), &H90)
  404.                 WriteInt8(CType(&H4AB078, IntPtr), &H90)
  405.                 WriteInt8(CType(&H4AB079, IntPtr), &H90)
  406.                 WriteInt8(CType(&H4AB07A, IntPtr), &H90)
  407.                 WriteInt8(CType(&H4AB07B, IntPtr), &H90)
  408.                 WriteInt8(CType(&H4AB07C, IntPtr), &H90)
  409.                 WriteInt8(CType(&H4AB0A9, IntPtr), &H90)
  410.                 WriteInt8(CType(&H4AB0AA, IntPtr), &H90)
  411.                 WriteInt8(CType(&H4AB0AB, IntPtr), &H90)
  412.                 WriteInt8(CType(&H4AB0AC, IntPtr), &H90)
  413.                 WriteInt8(CType(&H4AB0AD, IntPtr), &H90)
  414.                 WriteInt8(CType(&H4AB0AE, IntPtr), &H90)
  415.                 WriteInt8(CType(&H4AB0AF, IntPtr), &H90)
  416.                 WriteInt8(CType(&H4AB0B0, IntPtr), &H90)
  417.                 WriteInt8(CType(&H4AB0B1, IntPtr), &H90)
  418.                 WriteInt8(CType(&H4AB0B2, IntPtr), &H90)
  419.                 WriteInt8(CType(&H4AB0B3, IntPtr), &H90)
  420.                 WriteInt8(CType(&H4AB0B4, IntPtr), &H90)
  421.                 WriteInt8(CType(&H4AB0B5, IntPtr), &H90)
  422.                 WriteInt8(CType(&H4AB0B6, IntPtr), &H90)
  423.                 WriteInt8(CType(&H4AB0B7, IntPtr), &H90)
  424.                 WriteInt8(CType(&H4AB0B8, IntPtr), &H90)
  425.                 WriteInt8(CType(&H4AB0B9, IntPtr), &H90)
  426.                 WriteInt8(CType(&H4AB0BA, IntPtr), &H90)
  427.                 WriteInt8(CType(&H4AB0BB, IntPtr), &H90)
  428.                 WriteInt8(CType(&H4AB0BC, IntPtr), &H90)
  429.                 WriteInt8(CType(&H4AB0BD, IntPtr), &H90)
  430.                 WriteInt8(CType(&H4AB0BE, IntPtr), &H90)
  431.                 WriteInt8(CType(&H4AB0BF, IntPtr), &H90)
  432.                 WriteInt8(CType(&H4AB0C0, IntPtr), &H90)
  433.                 WriteInt8(CType(&H4AB0C1, IntPtr), &H90)
  434.                 WriteInt8(CType(&H4AB0C2, IntPtr), &H90)
  435.                 WriteInt8(CType(&H4AB0C3, IntPtr), &H90)
  436.                 WriteInt8(CType(&H4AB0C4, IntPtr), &H90)
  437.                 WriteInt8(CType(&H4AB0C5, IntPtr), &H90)
  438.             ElseIf gameMode = mode.Software Then
  439.                 WriteInt8(CType(&H464BCE, IntPtr), &H90)
  440.                 WriteInt8(CType(&H464CBF, IntPtr), &H90)
  441.                 WriteInt8(CType(&H464CC0, IntPtr), &H90)
  442.                 WriteInt8(CType(&H464CC1, IntPtr), &H90)
  443.                 WriteInt8(CType(&H464CC2, IntPtr), &H90)
  444.                 WriteInt8(CType(&H464CC3, IntPtr), &H90)
  445.                 WriteInt8(CType(&H464CC4, IntPtr), &H90)
  446.                 WriteInt8(CType(&H464CC5, IntPtr), &H90)
  447.                 WriteInt8(CType(&H464CC6, IntPtr), &H90)
  448.                 WriteInt8(CType(&H464CC7, IntPtr), &H90)
  449.                 WriteInt8(CType(&H464CC8, IntPtr), &H90)
  450.                 WriteInt8(CType(&H464CC9, IntPtr), &H90)
  451.                 WriteInt8(CType(&H464CCA, IntPtr), &H90)
  452.                 WriteInt8(CType(&H464CCB, IntPtr), &H90)
  453.                 WriteInt8(CType(&H464CCC, IntPtr), &H90)
  454.                 WriteInt8(CType(&H464CCD, IntPtr), &H90)
  455.                 WriteInt8(CType(&H464CCE, IntPtr), &H90)
  456.                 WriteInt8(CType(&H464CD0, IntPtr), &H90)
  457.                 WriteInt8(CType(&H464CD1, IntPtr), &H90)
  458.                 WriteInt8(CType(&H464CED, IntPtr), &H90)
  459.                 WriteInt8(CType(&H464CEE, IntPtr), &H90)
  460.                 WriteInt8(CType(&H464CEF, IntPtr), &H90)
  461.                 WriteInt8(CType(&H464CF0, IntPtr), &H90)
  462.                 WriteInt8(CType(&H464CF1, IntPtr), &H90)
  463.                 WriteInt8(CType(&H464CF2, IntPtr), &H90)
  464.                 WriteInt8(CType(&H464CF3, IntPtr), &H90)
  465.                 WriteInt8(CType(&H464CF4, IntPtr), &H90)
  466.                 WriteInt8(CType(&H464CF5, IntPtr), &H90)
  467.                 WriteInt8(CType(&H464CF6, IntPtr), &H90)
  468.                 WriteInt8(CType(&H464CF7, IntPtr), &H90)
  469.                 WriteInt8(CType(&H464CF8, IntPtr), &H90)
  470.                 WriteInt8(CType(&H464CF9, IntPtr), &H90)
  471.                 WriteInt8(CType(&H464CFA, IntPtr), &H90)
  472.                 WriteInt8(CType(&H464CFB, IntPtr), &H90)
  473.                 WriteInt8(CType(&H464CFC, IntPtr), &H90)
  474.                 WriteInt8(CType(&H464CFD, IntPtr), &H90)
  475.                 WriteInt8(CType(&H464CFE, IntPtr), &H90)
  476.                 WriteInt8(CType(&H464CFF, IntPtr), &H90)
  477.                 WriteInt8(CType(&H464D00, IntPtr), &H90)
  478.                 WriteInt8(CType(&H464D01, IntPtr), &H90)
  479.                 WriteInt8(CType(&H464D02, IntPtr), &H90)
  480.                 WriteInt8(CType(&H464D03, IntPtr), &H90)
  481.                 WriteInt8(CType(&H464D04, IntPtr), &H90)
  482.                 WriteInt8(CType(&H464D05, IntPtr), &H90)
  483.                 WriteInt8(CType(&H464D06, IntPtr), &H90)
  484.                 WriteInt8(CType(&H464D07, IntPtr), &H90)
  485.                 WriteInt8(CType(&H464D08, IntPtr), &H90)
  486.                 WriteInt8(CType(&H464D09, IntPtr), &H90)
  487.                 WriteInt8(CType(&H464D36, IntPtr), &H90)
  488.                 WriteInt8(CType(&H464D37, IntPtr), &H90)
  489.                 WriteInt8(CType(&H464D38, IntPtr), &H90)
  490.                 WriteInt8(CType(&H464D39, IntPtr), &H90)
  491.                 WriteInt8(CType(&H464D3A, IntPtr), &H90)
  492.                 WriteInt8(CType(&H464D3B, IntPtr), &H90)
  493.                 WriteInt8(CType(&H464D3C, IntPtr), &H90)
  494.                 WriteInt8(CType(&H464D3D, IntPtr), &H90)
  495.                 WriteInt8(CType(&H464D3E, IntPtr), &H90)
  496.                 WriteInt8(CType(&H464D3F, IntPtr), &H90)
  497.                 WriteInt8(CType(&H464D40, IntPtr), &H90)
  498.                 WriteInt8(CType(&H464D41, IntPtr), &H90)
  499.                 WriteInt8(CType(&H464D42, IntPtr), &H90)
  500.                 WriteInt8(CType(&H464D43, IntPtr), &H90)
  501.                 WriteInt8(CType(&H464D44, IntPtr), &H90)
  502.                 WriteInt8(CType(&H464D45, IntPtr), &H90)
  503.                 WriteInt8(CType(&H464D46, IntPtr), &H90)
  504.                 WriteInt8(CType(&H464D47, IntPtr), &H90)
  505.                 WriteInt8(CType(&H464D48, IntPtr), &H90)
  506.                 WriteInt8(CType(&H464D49, IntPtr), &H90)
  507.                 WriteInt8(CType(&H464D4A, IntPtr), &H90)
  508.                 WriteInt8(CType(&H464D4B, IntPtr), &H90)
  509.                 WriteInt8(CType(&H464D4C, IntPtr), &H90)
  510.                 WriteInt8(CType(&H464D4D, IntPtr), &H90)
  511.                 WriteInt8(CType(&H464D4E, IntPtr), &H90)
  512.                 WriteInt8(CType(&H464D4F, IntPtr), &H90)
  513.                 WriteInt8(CType(&H464D50, IntPtr), &H90)
  514.                 WriteInt8(CType(&H464D51, IntPtr), &H90)
  515.                 WriteInt8(CType(&H464D52, IntPtr), &H90)
  516.             End If
  517.         End Sub
  518.  
  519.         Public Sub FixTexture()
  520.             If gameMode = mode.Hardware Then
  521.                 Dim fix As Byte() = New Byte(0) {}
  522.                 fix(0) = &H3F
  523.                 WriteProcessMemory(CType(&H5177BC, IntPtr), fix)
  524.             End If
  525.         End Sub
  526.  
  527.         Public Sub ChangeResolution(w As Integer, h As Integer)
  528.             If gameMode = mode.Hardware Then
  529.                 WriteInt8(CType(&H410F9A, IntPtr), &H6A)
  530.                 WriteInt8(CType(&H410F9B, IntPtr), &H20)
  531.                 WriteInt8(CType(&H410F9A, IntPtr), &H6A)
  532.                 WriteInt8(CType(&H410F9B, IntPtr), &H20)
  533.                 WriteInt8(CType(&H410F9C, IntPtr), &H68)
  534.                 WriteInt8(CType(&H410F9D, IntPtr), CByte((h And &HFF)))
  535.                 WriteInt8(CType(&H410F9E, IntPtr), CByte(Math.Round(CDbl((CDbl((h And &HFF00)) / 256)))))
  536.                 WriteInt8(CType(&H410F9F, IntPtr), 0)
  537.                 WriteInt8(CType(&H410FA0, IntPtr), 0)
  538.                 WriteInt8(CType(&H410FA1, IntPtr), &H68)
  539.                 WriteInt8(CType(&H410FA2, IntPtr), CByte((w And &HFF)))
  540.                 WriteInt8(CType(&H410FA3, IntPtr), CByte(Math.Round(CDbl((CDbl((w And &HFF00)) / 256)))))
  541.                 WriteInt8(CType(&H410FA4, IntPtr), 0)
  542.                 WriteInt8(CType(&H410FA5, IntPtr), 0)
  543.                 WriteInt8(CType(&H457D60, IntPtr), &H6A)
  544.                 WriteInt8(CType(&H457D61, IntPtr), &H20)
  545.                 WriteInt8(CType(&H457D62, IntPtr), &H68)
  546.                 WriteInt8(CType(&H457D63, IntPtr), CByte((h And &HFF)))
  547.                 WriteInt8(CType(&H457D64, IntPtr), CByte(Math.Round(CDbl((CDbl((h And &HFF00)) / 256)))))
  548.                 WriteInt8(CType(&H457D65, IntPtr), 0)
  549.                 WriteInt8(CType(&H457D66, IntPtr), 0)
  550.                 WriteInt8(CType(&H457D67, IntPtr), &H68)
  551.                 WriteInt8(CType(&H457D68, IntPtr), CByte((w And &HFF)))
  552.                 WriteInt8(CType(&H457D69, IntPtr), CByte(Math.Round(CDbl((CDbl((w And &HFF00)) / 256)))))
  553.                 WriteInt8(CType(&H457D6A, IntPtr), 0)
  554.                 WriteInt8(CType(&H457D6B, IntPtr), 0)
  555.                 Dim n As Integer = &H410FA6
  556.                 While n <= &H410FC5
  557.                     WriteInt8(CType(n, IntPtr), &H90)
  558.                     n += 1
  559.                 End While
  560.                 Dim n2 As Integer = &H457D6C
  561.                 While n2 <= &H457D86
  562.                     WriteInt8(CType(n2, IntPtr), &H90)
  563.                     n2 += 1
  564.                 End While
  565.             End If
  566.         End Sub
  567.  
  568.         Public Sub ChangeTribe(ByVal t As tribe) ' illegal online (cheating)
  569.             If gameMode = mode.Hardware Then
  570.                 WriteInt8(CType(&H884C88, IntPtr), t)
  571.             End If
  572.         End Sub
  573.  
  574.         Public ReadOnly Property Joined() As Boolean
  575.             Get
  576.                 If gameMode = mode.Hardware Then
  577.                     Return ReadInt8(CType(&H87D29CL, IntPtr)) <> 0
  578.                 ElseIf gameMode = mode.Software Then
  579.                     Return ReadInt8(CType(&H894D04L, IntPtr)) <> 0
  580.                 End If
  581.                 Return False
  582.             End Get
  583.         End Property
  584.  
  585.         ' Could add more featues like Change Speed, Window Mode but thats for later.
  586.  
  587.         ' Game Watchers (Online)
  588.         Public Function DetectGameStatus() As GameStatus
  589.  
  590.             If gameMode = mode.Hardware Then
  591.                 status = CType(ReadInt8(CType(&H89C664, IntPtr)), GameStatus)
  592.             ElseIf gameMode = mode.Software Then
  593.                 status = CType(ReadInt8(CType(&H884BFC, IntPtr)), GameStatus)
  594.             End If
  595.  
  596.             Return status
  597.  
  598.         End Function
  599.  
  600.         Public Sub WatchGameStart()
  601.             Dim Watcher = New Thread(AddressOf GameStartWatcher)
  602.             Watcher.IsBackground = True
  603.             Watcher.Start()
  604.         End Sub
  605.  
  606.         Public Sub WatchGame()
  607.             Dim Watcher = New Thread(AddressOf GameWatcher)
  608.             Watcher.IsBackground = True
  609.             Watcher.Start()
  610.         End Sub
  611.  
  612.         Private Sub GameStartWatcher()
  613.             ' the speed value changes when the game starts
  614.             Try
  615.                 Speed = 0
  616.  
  617.                 Thread.Sleep(1000)
  618.  
  619.                 While Speed <> DefaultGameSpeed AndAlso Not proc.HasExited
  620.                     Thread.Sleep(1000)
  621.                 End While
  622.  
  623.                 If Not proc.HasExited Then
  624.                     gameStarted = True
  625.                     RaiseEvent OnGameStart(DateTime.Now)
  626.                 End If
  627.  
  628.             Catch
  629.             End Try
  630.         End Sub
  631.  
  632.         Private Sub GameWatcher()
  633.             Try
  634.                 While Not proc.HasExited
  635.                     DetectGameStatus()
  636.                     GetUnitInfo()
  637.  
  638.                     Thread.Sleep(1000)
  639.                 End While
  640.  
  641.             Catch
  642.             End Try
  643.         End Sub
  644.  
  645.         Public Sub GetUnitInfo()
  646.  
  647.  
  648.         End Sub
  649.  
  650.         Public Property Speed() As Byte
  651.             Get
  652.                 If gameMode = mode.Hardware Then
  653.                     Return ReadInt8(CType(&H89D161, IntPtr))
  654.                 ElseIf gameMode = mode.Software Then
  655.                     Return ReadInt8(CType(&H8856F9, IntPtr))
  656.                 End If
  657.  
  658.                 Return 0
  659.             End Get
  660.  
  661.             Set(value As Byte)
  662.                 If gameMode = mode.Hardware Then
  663.                     WriteInt8(CType(&H89D161, IntPtr), value)
  664.                 ElseIf gameMode = mode.Hardware Then
  665.                     WriteInt8(CType(&H8856F9, IntPtr), value)
  666.                 End If
  667.             End Set
  668.         End Property
  669.  
  670.     End Class
  671.     Public Class colors
  672.         Public Structure RGB
  673.             Public R As Integer
  674.             Public G As Integer
  675.             Public B As Integer
  676.         End Structure
  677.  
  678.         Public Function [Set](ByVal blue As RGB, ByVal red As RGB, ByVal yellow As RGB, ByVal green As RGB)
  679.                 Dim writer As New System.IO.BinaryWriter(System.IO.Stream.Null)
  680.                 For Each pal In Populous.datafilestruct
  681.                     Try
  682.                         writer = New System.IO.BinaryWriter(System.IO.File.Open(Populous.Info.InstallPath & "\data\pal0-" & pal & ".dat", System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite))
  683.                     Catch
  684.                         Return False
  685.                     End Try
  686.                     Try
  687.                         writer.Seek(216 * 4, System.IO.SeekOrigin.Current)
  688.                         ' Each color has 4 bytes so we do 216*4
  689.                     For j As Integer = 0 To 31
  690.                         If j < 8 Then
  691.                             writer.Write(CByte(blue.R)) 'R
  692.                             writer.Write(CByte(blue.G)) 'G
  693.                             writer.Write(CByte(blue.B)) 'B
  694.                             ' We don't know what this is
  695.                             writer.Write(CByte(0))
  696.                         ElseIf j < 16 Then
  697.                             writer.Write(CByte(green.R)) 'R
  698.                             writer.Write(CByte(green.G)) 'G
  699.                             writer.Write(CByte(green.B)) 'B
  700.                             ' We don't know what this is
  701.                             writer.Write(CByte(0))
  702.                         ElseIf j < 24 Then
  703.                             writer.Write(CByte(yellow.R)) 'R
  704.                             writer.Write(CByte(yellow.G)) 'G
  705.                             writer.Write(CByte(yellow.B)) 'B
  706.                             ' We don't know what this is
  707.                             writer.Write(CByte(0))
  708.                         ElseIf j < 32 Then
  709.                             writer.Write(CByte(red.R)) 'R
  710.                             writer.Write(CByte(red.G)) 'G
  711.                             writer.Write(CByte(red.B)) 'B
  712.                             ' We don't know what this is
  713.                             writer.Write(CByte(0))
  714.                         End If
  715.                     Next
  716.                 Catch
  717.                     Return False
  718.                 End Try
  719.                     writer.Close()
  720.                 Next
  721.                 Try
  722.                     writer.Close()
  723.                     writer.Dispose()
  724.                 Catch ex As Exception
  725.  
  726.                 End Try
  727.  
  728.             Return True
  729.         End Function
  730.  
  731.         Public Function restore()
  732.  
  733.             Return True
  734.         End Function
  735.  
  736.     End Class
  737.  
  738.     Public Class files
  739.         Private Declare Function GetKeyboardLayout Lib "user32" (ByVal idThread As UInteger) As IntPtr
  740.         <DllImport("User32.dll")> _
  741.         Shared Function GetKeyboardLayout(idThread As Integer) As IntPtr
  742.         End Function
  743.         <DllImport("user32.dll")> _
  744.         Shared Function MapVirtualKeyEx(uCode As Integer, uMapType As Integer, dwhkl As Integer) As Integer
  745.         End Function
  746.         <DllImport("user32.dll")> _
  747.         Shared Function GetKeyboardState(ByVal keyState() As Byte) As Boolean
  748.         End Function
  749.         <DllImport("user32.dll")> _
  750.         Shared Function ToAsciiEx(uVirtKey As Integer, uScanCode As Integer, lpKeyState As Byte, lpChar As Integer, uFlags As Integer, dwhkl As Integer) As Integer
  751.         End Function
  752.  
  753.         Private keys_loc = New Integer() {8, 23, 38, 53, 68, 83, 98, 113, 128, 143, _
  754.                       158, 173, 188, 203, 218, 233, 248, 263, 278, _
  755.                       293, 308, 323, 338, 353, 368, 383, 398, 413, _
  756.                       428, 443, 458, 473, 488, 503, 518, 533, 548, _
  757.                       563, 578, 593, 608, 623, 638, 653, 668, 683, _
  758.                       698}
  759.  
  760.         Enum install
  761.             complete
  762.             recomended
  763.             minimum
  764.         End Enum
  765.  
  766.         Public Function scan(ByVal install As install)
  767.  
  768.             Return 0
  769.         End Function
  770.  
  771.         Public Function repair(ByVal install As install)
  772.  
  773.             Return 0
  774.         End Function
  775.  
  776.         Public Function loadFile(ByVal file)
  777.  
  778.             Return 0
  779.         End Function
  780.  
  781.         Public Function loadConstants()
  782.  
  783.             Return 0
  784.         End Function
  785.  
  786.         Public Function loadKeyBinding()
  787.  
  788.             Return 0
  789.         End Function
  790.  
  791.         Public Function saveKeyBinding()
  792.  
  793.             Return 0
  794.         End Function
  795.  
  796.         Public Function loadLanguageFile(ByVal file As String)
  797.  
  798.         End Function
  799.  
  800.         Public Function LoadLevelHDR(ByVal file As String)
  801.  
  802.         End Function
  803.  
  804.         Public Function saveConstants()
  805.  
  806.             Return 0
  807.         End Function
  808.  
  809.         Public Function CheckGameVersion()
  810.  
  811.             Return 0
  812.         End Function
  813.  
  814.         Public Function FileCheck(ByVal file As String)
  815.  
  816.             Return 0
  817.         End Function
  818.  
  819.     End Class
  820.  
  821. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement