Collaboration on Survive Mars

phorkus

What is cheating?
Mar 16, 2018
2
0
0
#1
Hello,
first post here, so be gentle. :)

I've figured out some of what Survive Mars has done to make their Compiled Lua files (the one's in the HPK archives that start with 0x1b LuaS).

They've compiled a modified version of the Lua 5.3 engine into the game executable and run all the game logic through the modified compiled lua loader. The file format differs form "normal" compiled Lua 5.3 and prevents the typical tools like Luadec from working correctly.

However, by modifying the expected format of the compiled Lua header you can get the decompiler to work. If you follow the instructions at:

https://github.com/viruscamp/luadec

You can get things working with one small tweak.

In the file lua-5.3/src/lundump.c there is a function named checkHeader. It looks roughly like this:
Code:
static void checkHeader (LoadState *S) {
  checkliteral(S, LUA_SIGNATURE + 1, "not a");  /* 1st char already checked */
  if (LoadByte(S) != LUAC_VERSION)
    error(S, "version mismatch in");
  if (LoadByte(S) != LUAC_FORMAT)
    error(S, "format mismatch in");
  checkliteral(S, LUAC_DATA, "corrupted");
  checksize(S, int);
  checksize(S, size_t);
  checksize(S, Instruction);
  checksize(S, lua_Integer);
  checksize(S, lua_Number);
  if (LoadInteger(S) != LUAC_INT)
    error(S, "endianness mismatch in");
  if (LoadNumber(S) != LUAC_NUM)
    error(S, "float format mismatch in");
}
If you comment out the lines:
Code:
  //checksize(S, Instruction);
  //checksize(S, lua_Integer);
You can then decompile the HPK's embedded Lua files.

I'm planning on modifying the Lua compiler tomorrow to produce compatible Lua files and allow for the dropping in of our own files into the HPKs.

I used the HPK extractor from:

https://github.com/atom0s/HpkArchiver

Sorry if this isn't the right place to post this, but I didn't see a collaboration forum so I figured this is the place.

Hope this helps a fellow hacker out,
-Phorkus.
 

efi_ex

What is cheating?
Mar 19, 2018
3
0
0
#3
Hi

So you are going to provide us the luadec.exe which can decompile the surviving mars files ?
awesome
 

phorkus

What is cheating?
Mar 16, 2018
2
0
0
#4
Hi, I'm more of a developer, and I'm trying to figure out all this stuff so we can mod it freely. There are trainers out there in the other threads, though.

More technical information I've figure out is below.

I've got the decompilation working, and recompilation, as well. In order to recompile the decompiled lua files from the Lua.hpk file, you need to alter the compiler functions in the file lua-5.3/src/ldump.c, in the function DumpHeader. (Code below).
Code:
static void DumpHeader (DumpState *D) {
  DumpLiteral(LUA_SIGNATURE, D);
  DumpByte(LUAC_VERSION, D);
  DumpByte(LUAC_FORMAT, D);
  DumpLiteral(LUAC_DATA, D);
  DumpByte(sizeof(int), D);
  DumpByte(sizeof(size_t), D);
//  DumpByte(sizeof(Instruction), D);	// Comment these out!
//  DumpByte(sizeof(lua_Integer), D);	// Comment these out!
  DumpByte(sizeof(lua_Number), D);
  DumpInteger(LUAC_INT, D);
  DumpNumber(LUAC_NUM, D);
}
If you rebuild the lua-5.3 compiler, you can now replace the compiled lua files in the HPK! I had to use Linux to decompile/recompile the Lua files. Also, you want to be sure to reconstruct the source path from the original file (in the example below that is /Mars/Lua/Cheats.lua).

I've enclosed the file here since I can't attach it. I've made modifications to the base Cheats.lua file. Namely, adding key shortcuts to some of the functions, adding a CheaterGiftBasket function and shortcut (shift-G) and most importantly, changed CheatsEnabled() to return true.
Code:
-- Decompiled using luadec 2.2 rev: 895d923 for Lua 5.3 from https://github.com/viruscamp/luadec
-- function check Command line: -fc Cheats.lua 

-- params : ...
-- function num : 0 , upvalues : _ENV
-- function check fail 0 :  sizecode org: 131, decompiled: 131, same: 79;
CheatsEnabled = function()
  -- function num : 0_0
  -- function check pass 0_0
  return true
end

CheatMapExplore = function(status)
  -- function num : 0_1 , upvalues : _ENV
  -- function check pass 0_1
  if #g_MapSectors == 0 then
    return 
  end
  CreateGameTimeThread(function()
    -- function num : 0_1_0 , upvalues : _ENV, status
    -- function check pass 0_1_0
    local old = IsDepositObstructed
    IsDepositObstructed = empty_func
    for x = 1, const.SectorCount do
      for y = 1, const.SectorCount do
        ((g_MapSectors[x])[y]):Scan(status)
      end
    end
    IsDepositObstructed = old
  end
)
end

local GetCameraLookAtPassable = function()
  -- function num : 0_2 , upvalues : _ENV
  -- function check fail 0_2 :  sizecode org: 17, decompiled: 17, same: 13;
  local _, lookat = GetCamera()
  if not (terrain.IsPassable)(lookat) or not lookat then
    return GetRandomPassableAround(lookat, 100 * guim)
  end
end

CheatDustDevil = function(major)
  -- function num : 0_3 , upvalues : GetCameraLookAtPassable, _ENV
  -- function check fail 0_3 :  sizecode org: 29, decompiled: 29, same: 19;
  local pos = GetCameraLookAtPassable()
  if pos then
    local data = DataInstances.MapSettings_DustDevils
    if mapdata.MapSettings_DustDevils == "disabled" or not data[mapdata.MapSettings_DustDevils] then
      local descr = data.DustDevils_VeryLow
    end
    local devil = GenerateDustDevil(pos, descr, nil, major)
    devil:Start()
  else
    do
      print("No passable point around camera look at")
    end
  end
end

CheatMeteors = function(meteors_type)
  -- function num : 0_4 , upvalues : GetCameraLookAtPassable, _ENV
  -- function check fail 0_4 :  different code size; sizecode org: 21, decompiled: 20, same: 15;
  local pos = GetCameraLookAtPassable()
  if pos then
    local data = DataInstances.MapSettings_Meteor
    do
      if mapdata.MapSettings_Meteor == "disabled" or not data[mapdata.MapSettings_Meteor] then
        local descr = data.Meteor_VeryLow
      end
      CreateGameTimeThread(function()
    -- function num : 0_4_0 , upvalues : _ENV, descr, meteors_type, pos
    -- function check pass 0_4_0
    MeteorsDisaster(descr, meteors_type, pos)
  end
)
    end
  end
end

CheatResearchAll = function()
  -- function num : 0_5 , upvalues : _ENV
  -- function check pass 0_5
  if not UICity then
    return 
  end
  for filed_id,list in sorted_pairs(UICity.tech_field) do
    if (TechFields[filed_id]).discoverable then
      for i = 1, #list do
        UICity:SetTechResearched(list[i])
      end
    end
  end
end

CheatResearchCurrent = function()
  -- function num : 0_6 , upvalues : _ENV
  -- function check pass 0_6
  if not UICity then
    return 
  end
  UICity:SetTechResearched()
end

CheatCompleteAllWiresAndPipes = function(list)
  -- function num : 0_7 , upvalues : _ENV
  -- function check pass 0_7
  SuspendTerrainInvalidations("cheat_wires_and_pipes")
  ForEach({class = "ConstructionGroupLeader", exec = function(obj)
    -- function num : 0_7_0
    -- function check pass 0_7_0
    if obj.building_class ~= "LifeSupportGridElement" and obj.building_class ~= "ElectricityGridElement" then
      return 
    end
    obj:Complete("quick_build")
  end
})
  ResumeTerrainInvalidations("cheat_wires_and_pipes")
end

local CompleteBuildConstructionSite = function(site)
  -- function num : 0_8
  -- function check pass 0_8
  if not site.construction_group or (site.construction_group)[1] == site then
    site:Complete("quick_build")
  end
end

CheatCompleteAllConstructions = function()
  -- function num : 0_9 , upvalues : _ENV, CompleteBuildConstructionSite
  -- function check pass 0_9
  SuspendTerrainInvalidations("cheat_all_constructions")
  CheatCompleteAllWiresAndPipes()
  for i = 1, 2 do
    ForEach({class = "ConstructionSite", exec = CompleteBuildConstructionSite})
  end
  ResumeTerrainInvalidations("cheat_all_constructions")
end

CheatChangeMap = function(map)
  -- function num : 0_10 , upvalues : _ENV
  -- function check pass 0_10
  if Platform.developer then
    CreateRealTimeThread(function()
    -- function num : 0_10_0 , upvalues : _ENV, map
    -- function check pass 0_10_0
    CloseAllDialogs()
    Sleep(1)
    CloseMenuWizards()
    ChangeMap(map)
    -- DECOMPILER ERROR at PC12: Confused about usage of register: R0 in 'UnsetPending'

    LocalStorage.last_map = map
    SaveLocalStorage()
  end
)
  end
end

UnlockAllTech = function()
  -- function num : 0_11 , upvalues : _ENV
  -- function check pass 0_11
  if not UICity then
    return 
  end
  for filed_id,list in sorted_pairs(UICity.tech_field) do
    if (TechFields[filed_id]).discoverable then
      for i = 1, #list do
        UICity:SetTechDiscovered(list[i])
      end
    end
  end
end

CheatUnlockAllBuildings = function()
  -- function num : 0_12 , upvalues : _ENV
  -- function check pass 0_12
  local templates = DataInstances.BuildingTemplate
  for i = 1, #templates do
    local category = (templates[i]).build_category
    -- DECOMPILER ERROR at PC13: Confused about usage of register: R6 in 'UnsetPending'

    if not BuildMenuPrerequisiteOverrides[category] then
      BuildMenuPrerequisiteOverrides[category] = true
    end
  end
end

CheatUnlockBreakthroughs = function()
  -- function num : 0_13 , upvalues : _ENV
  -- function check pass 0_13
  local anomalies = 0
  local reveal = function(anomaly)
    -- function num : 0_13_0 , upvalues : _ENV, anomalies
    -- function check pass 0_13_0
    if not IsValid(anomaly) or anomaly.tech_action ~= "breakthrough" then
      return 
    end
    anomaly:SetRevealed(true)
    anomaly:ScanCompleted(false)
    DoneObject(anomaly)
    anomalies = anomalies + 1
  end

  ForEach({class = "SubsurfaceAnomalyMarker", exec = function(marker)
    -- function num : 0_13_1 , upvalues : reveal, _ENV
    -- function check pass 0_13_1
    reveal(marker:PlaceDeposit())
    DoneObject(marker)
  end
})
  ForEach({class = "SubsurfaceAnomaly", exec = reveal})
  print(anomalies, "breakthroughs technologies have been unlocked")
end

local l_add_funding = 500000000
AddCheatsUA = function()
  -- function num : 0_14 , upvalues : _ENV, l_add_funding
  -- function check pass 0_14
  local CheatsUA = {
MapExplorationScan = {mode = "Game", menu = "Cheats/[01]Map Exploration/[01]Scan", description = "Reveal all Deposits (all)", action = function()
    -- function num : 0_14_0 , upvalues : _ENV
    -- function check pass 0_14_0
    if not CheatsEnabled() then
      return 
    end
    CheatMapExplore("scanned")
  end
}
, 
MapExplorationDeepScan = {mode = "Game", menu = "Cheats/[01]Map Exploration/[02]Deep Scan", description = "Reveal all deposits level 1 and above", action = function()
    -- function num : 0_14_1 , upvalues : _ENV
    -- function check pass 0_14_1
    if not CheatsEnabled() then
      return 
    end
    CheatMapExplore("deep scanned")
  end
}
, 
ChangeMapEmpty = {mode = "Game", menu = "Cheats/[02]Change Map/[1]Empty Map", action = function()
    -- function num : 0_14_2 , upvalues : _ENV
    -- function check pass 0_14_2
    CheatChangeMap("POCMap_Alt_00")
  end
}
, 
ChangeMapPocMapAlt1 = {mode = "Game", menu = "Cheats/[02]Change Map/[2]Phase 1", action = function()
    -- function num : 0_14_3 , upvalues : _ENV
    -- function check pass 0_14_3
    CheatChangeMap("POCMap_Alt_01")
  end
}
, 
ChangeMapPocMapAlt2 = {mode = "Game", menu = "Cheats/[02]Change Map/[3]Phase 2 (Early)", action = function()
    -- function num : 0_14_4 , upvalues : _ENV
    -- function check pass 0_14_4
    CheatChangeMap("POCMap_Alt_02")
  end
}
, 
ChangeMapPocMapAlt3 = {mode = "Game", menu = "Cheats/[02]Change Map/[4]Phase 2 (Late)", action = function()
    -- function num : 0_14_5 , upvalues : _ENV
    -- function check pass 0_14_5
    CheatChangeMap("POCMap_Alt_03")
  end
}
, 
ChangeMapPocMapAlt4 = {mode = "Game", menu = "Cheats/[02]Change Map/[5]Phase 3", action = function()
    -- function num : 0_14_6 , upvalues : _ENV
    -- function check pass 0_14_6
    CheatChangeMap("POCMap_Alt_04")
  end
}
, 
TriggerDisasterDustDevil = {mode = "Game", menu = "Cheats/[03]Trigger Disaster/[1]Dust Devil", description = "Dust Devil", action = function()
    -- function num : 0_14_7 , upvalues : _ENV
    -- function check pass 0_14_7
    if not CheatsEnabled() then
      return 
    end
    CheatDustDevil()
  end
}
, 
TriggerDisasterDustDevilMajor = {mode = "Game", menu = "Cheats/[03]Trigger Disaster/[1m]Major Dust Devil", description = "Major Dust Devil", action = function()
    -- function num : 0_14_8 , upvalues : _ENV
    -- function check pass 0_14_8
    if not CheatsEnabled() then
      return 
    end
    CheatDustDevil("major")
  end
}
, 
TriggerDisasterDustStormNormal = {mode = "Game", menu = "Cheats/[03]Trigger Disaster/[2]Dust Storm", description = "Dust Storm", action = function()
    -- function num : 0_14_9 , upvalues : _ENV
    -- function check pass 0_14_9
    if not CheatsEnabled() then
      return 
    end
    CheatDustStorm("normal")
  end
}
, 
TriggerDisasterDustStormGreat = {mode = "Game", menu = "Cheats/[03]Trigger Disaster/[3]Great Dust Storm", description = "Dust Storm", action = function()
    -- function num : 0_14_10 , upvalues : _ENV
    -- function check pass 0_14_10
    if not CheatsEnabled() then
      return 
    end
    CheatDustStorm("great")
  end
}
, 
TriggerDisasterDustStormElectrostatic = {mode = "Game", menu = "Cheats/[03]Trigger Disaster/[4]Electrostatic Dust Storm", description = "Dust Storm", action = function()
    -- function num : 0_14_11 , upvalues : _ENV
    -- function check pass 0_14_11
    if not CheatsEnabled() then
      return 
    end
    CheatDustStorm("electrostatic")
  end
}
, 
TriggerDisasterColdWave = {mode = "Game", menu = "Cheats/[03]Trigger Disaster/[5]Cold Wave", description = "Cold Wave", action = function()
    -- function num : 0_14_12 , upvalues : _ENV
    -- function check pass 0_14_12
    if not CheatsEnabled() then
      return 
    end
    CheatColdWave()
  end
}
, 
TriggerDisasterMeteorsSingle = {mode = "Game", menu = "Cheats/[03]Trigger Disaster/[6]Meteors Single", description = "Meteors", action = function()
    -- function num : 0_14_13 , upvalues : _ENV
    -- function check pass 0_14_13
    if not CheatsEnabled() then
      return 
    end
    CheatMeteors("single")
  end
}
, 
TriggerDisasterMeteorsMultiSpawn = {mode = "Game", menu = "Cheats/[03]Trigger Disaster/[7]Meteors Multi Spawn", description = "Meteors", action = function()
    -- function num : 0_14_14 , upvalues : _ENV
    -- function check pass 0_14_14
    if not CheatsEnabled() then
      return 
    end
    CheatMeteors("multispawn")
  end
}
, 
TriggerDisasterMeteorsStorm = {mode = "Game", menu = "Cheats/[03]Trigger Disaster/[8]Meteors Storm", description = "Meteors", action = function()
    -- function num : 0_14_15 , upvalues : _ENV
    -- function check pass 0_14_15
    if not CheatsEnabled() then
      return 
    end
    CheatMeteors("storm")
  end
}
, 
TriggerDisasterStop = {key = "Alt-S", mode = "Game", menu = "Cheats/[03]Trigger Disaster/[9]Stop Disaster", description = "Stop Disaster", action = function()
    -- function num : 0_14_16 , upvalues : _ENV
    -- function check pass 0_14_16
    if not CheatsEnabled() then
      return 
    end
    if g_DustStorm then
      StopDustStorm()
    else
      if g_ColdWave then
        StopColdWave()
      end
    end
  end
}
, 
G_OpenPregameMenu = {mode = "Game", menu = "Cheats/[06]New Game", description = "Open Pregame Menu", action = function()
    -- function num : 0_14_17 , upvalues : _ENV
    -- function check pass 0_14_17
    CreateRealTimeThread(OpenPreGameMainMenu)
  end
}
, 
["G_UnlockАllТech"] = {mode = "Game", menu = "Cheats/[04]Research/[10]Unlock all Tech", description = "Unlock all techs instantly", action = function()
    -- function num : 0_14_18 , upvalues : _ENV
    -- function check pass 0_14_18
    if not CheatsEnabled() then
      return 
    end
    UnlockAllTech()
  end
}
, 
G_ResearchCurrent = {key = "Alt-R", mode = "Game", menu = "Cheats/[04]Research/[08]Research current tech", description = "Finish current research instantly", action = function()
    -- function num : 0_14_19 , upvalues : _ENV
    -- function check pass 0_14_19
    if not CheatsEnabled() then
      return 
    end
    CheatResearchCurrent()
  end
}
, 
G_ResearchAll = {key = "Alt-P", mode = "Game", menu = "Cheats/[04]Research/[09]Research all", description = "Research all techs instantly", action = function()
    -- function num : 0_14_20 , upvalues : _ENV
    -- function check pass 0_14_20
    if not CheatsEnabled() then
      return 
    end
    CheatResearchAll()
  end
}
, 
G_UnlockAllBuildings = {mode = "Game", menu = "Cheats/[10]Unlock all buildings", description = "Unlock all buildings for construction", action = function()
    -- function num : 0_14_21 , upvalues : _ENV
    -- function check pass 0_14_21
    if not CheatsEnabled() then
      return 
    end
    CheatUnlockAllBuildings()
  end
}
, 
G_UnpinAll = {mode = "Game", menu = "Cheats/[10]Unpin All Pinned Objects", description = "Unpin All Pinned Objects", action = function()
    -- function num : 0_14_22 , upvalues : _ENV
    -- function check pass 0_14_22
    if not CheatsEnabled() then
      return 
    end
    UnpinAll()
  end
}
, 
UnlockAllBreakthroughs = {key = "Shift-R", mode = "Game", menu = "Cheats/[04]Research/[11]Unlock all Breakthroughs", description = "Unlock all breakthroughs on this map", action = function()
    -- function num : 0_14_23 , upvalues : _ENV
    -- function check pass 0_14_23
    if not CheatsEnabled() then
      return 
    end
    CheatUnlockBreakthroughs()
  end
}
, 
SpawnColonist1 = {key = "Shift-T", mode = "Game", menu = "Cheats/[05]Spawn Colonist/[1]Spawn 1 Colonist", description = "Spawn 1 Colonist", action = function()
    -- function num : 0_14_24 , upvalues : _ENV
    -- function check pass 0_14_24
    if not CheatsEnabled() then
      return 
    end
    CheatSpawnNColonists(1)
  end
}
, 
SpawnColonist10 = {key = "Shift-Y", mode = "Game", menu = "Cheats/[05]Spawn Colonist/[2]Spawn 10 Colonist", description = "Spawn 10 Colonist", action = function()
    -- function num : 0_14_25 , upvalues : _ENV
    -- function check pass 0_14_25
    if not CheatsEnabled() then
      return 
    end
    CheatSpawnNColonists(10)
  end
}
, 
SpawnColonist100 = {mode = "Game", menu = "Cheats/[05]Spawn Colonist/[3]Spawn 100 Colonist", description = "Spawn 100 Colonist", action = function()
    -- function num : 0_14_26 , upvalues : _ENV
    -- function check pass 0_14_26
    if not CheatsEnabled() then
      return 
    end
    CheatSpawnNColonists(100)
  end
}
, 
G_CompleteWiresPipes = {mode = "Game", menu = "Cheats/[12]Complete wires\\pipes", description = "Complete all wires and pipes instantly", action = function()
    -- function num : 0_14_27 , upvalues : _ENV
    -- function check pass 0_14_27
    if not CheatsEnabled() then
      return 
    end
    CheatCompleteAllWiresAndPipes()
  end
}
, 
G_CompleteConstructions = {mode = "Game", menu = "Cheats/[13]Complete constructions", key = "Alt-B", description = "Complete all constructions instantly", action = function()
    -- function num : 0_14_28 , upvalues : _ENV
    -- function check pass 0_14_28
    if not CheatsEnabled() then
      return 
    end
    CheatCompleteAllConstructions()
  end
}
, 
G_ModsEditor = {mode = "Game", menu = "Cheats/[14]Mod editor", action = function()
    -- function num : 0_14_29 , upvalues : _ENV
    -- function check pass 0_14_29
    if not CheatsEnabled() then
      return 
    end
    ModEditorOpen()
  end
}
, 
G_AddFunding = {mode = "Game", menu = "Cheats/[15]Add funding $" .. l_add_funding, key = "Shift-F", action = function()
    -- function num : 0_14_30 , upvalues : _ENV, l_add_funding
    -- function check pass 0_14_30
    if not CheatsEnabled() then
      return 
    end
    UICity:ChangeFunding(l_add_funding)
  end
}
, 
G_ToggleOnScreenHints = {mode = "Game", menu = "Cheats/[16]Toggle on-screen hints", action = function()
    -- function num : 0_14_31 , upvalues : _ENV
    -- function check pass 0_14_31
    if not CheatsEnabled() then
      return 
    end
    SetHintNotificationsEnabled(not HintsEnabled)
    UpdateOnScreenHintDlg()
  end
}
, 
G_ResetOnScreenHints = {mode = "Game", menu = "Cheats/[17]Reset on-screen hints", action = function()
    -- function num : 0_14_32 , upvalues : _ENV
    -- function check pass 0_14_32
    if not CheatsEnabled() then
      return 
    end
    g_ShownOnScreenHints = {}
    UpdateOnScreenHintDlg()
  end
}
, 
G_ToggleSigns = {key = "Ctrl-U", mode = "Game", menu = "Cheats/[18]Toggle Signs", action = function()
    -- function num : 0_14_33 , upvalues : _ENV
    -- function check pass 0_14_33
    if not CheatsEnabled() then
      return 
    end
    ToggleSigns()
  end
}
, 
G_ToggleInGameInterface = {key = "Ctrl-I", mode = "Game", menu = "Cheats/[19]Toggle InGame Interface", action = function()
    -- function num : 0_14_34 , upvalues : _ENV
    -- function check pass 0_14_34
    -- DECOMPILER ERROR at PC9: Confused about usage of register: R0 in 'UnsetPending'

    hr.RenderUIL = hr.RenderUIL == 0 and 1 or 0
  end
}
, 
G_ToggleInfopanelCheats = {key = "Shift-I", menu = "Cheats/[07]Toggle Infopanel Cheats", description = function()
    -- function num : 0_14_35 , upvalues : _ENV
    -- function check pass 0_14_35
    local action = config.BuildingInfopanelCheats and "Disable" or "Enable"
    return action .. " the cheats in the infopanels"
  end
, action = function()
    -- function num : 0_14_36 , upvalues : _ENV
    -- function check pass 0_14_36
    -- DECOMPILER ERROR at PC4: Confused about usage of register: R0 in 'UnsetPending'

    config.BuildingInfopanelCheats = not config.BuildingInfopanelCheats
    ReopenSelectionXInfopanel()
  end
},
  G_CheatBasket = {key = "Shift-G", mode = "Game", menu = "Cheats/[21]Cheater Gift Basket", action = function()
    UICity:ChangeFunding(50000000)
    config.BuildingInfopanelCheats = true
    CheatMapExplore("scanned")
    return "gift basket deployed"
  end
}
}
  CheatsUA.FreeCamera = {key = "Shift-C", mode = "Game", menu = "Cheats/[20]Toggle Free Camera", action = function()
    -- function num : 0_14_37 , upvalues : _ENV
    -- function check pass 0_14_37
    if not mapdata.GameLogic then
      return 
    end
    if (cameraFly.IsActive)() then
      SetMouseDeltaMode(false)
      ShowMouseCursor("InGameCursor")
      ;
      (cameraRTS.Activate)(1)
    else
      print("Camera Fly")
      ;
      (cameraFly.Activate)(1)
      HideMouseCursor("InGameCursor")
      SetMouseDeltaMode(true)
    end
  end
}
  if Platform.editor or Platform.pc or Platform.desktop then
    (UserActions.AddActions)(CheatsUA)
  end
end
-- DECOMPILER ERROR at PC31: Confused about usage of register: R3 in 'UnsetPending'

OnMsg.DataLoaded = function()
  -- function num : 0_15 , upvalues : _ENV
  -- function check pass 0_15
  AddCheatsUA()
end

if not FirstLoad then
  AddCheatsUA()
end
GamepadCheatsList = {
{display_name = T({7790, "Research Current Tech"}), func = CheatResearchCurrent}
, 
{display_name = T({7791, "Research all Techs"}), func = CheatResearchAll}
, 
{display_name = T({7792, "Unlock all Techs"}), func = UnlockAllTech}
, 
{display_name = T({7793, "Unlock all Breakthroughs"}), func = CheatUnlockBreakthroughs}
, 
{display_name = T({7794, "Construct all buildings"}), func = CheatCompleteAllConstructions}
, 
{display_name = T({7795, "Add funding ($500,000,000)"}), func = function()
  -- function num : 0_16 , upvalues : _ENV, l_add_funding
  -- function check pass 0_16
  UICity:ChangeFunding(l_add_funding)
end
}
, 
{display_name = T({7796, "Spawn 1 Colonist"}), func = function()
  -- function num : 0_17 , upvalues : _ENV
  -- function check pass 0_17
  CheatSpawnNColonists(1)
end
}
, 
{display_name = T({7797, "Spawn 10 Colonists"}), func = function()
  -- function num : 0_18 , upvalues : _ENV
  -- function check pass 0_18
  CheatSpawnNColonists(10)
end
}
, 
{display_name = T({7798, "Spawn 100 Colonists"}), func = function()
  -- function num : 0_19 , upvalues : _ENV
  -- function check pass 0_19
  CheatSpawnNColonists(100)
end
}
}
There's also (of course) a way to simply enable cheats from Cheat Engine, but you don't get the perks of having things like the InfoPanel cheats enabled, etc. That method is:

1. Search for the binary array "03 00 00 00 26 00 00 01 26 00 80 00 73 02 00 00 D0 B0 76 80 73 02 00 00 18 00 00 00 00 00 00 00". This is the series of instructions that cause "return false" to be returned when the function CheatsEnabled is called.

2. Replace the first four bytes value at that memory location with "03 00 80 00". This will turn the return false into a return true.

This cheat isn't overly effective in my opinion, since it only really lets you use free camera, and Alt-B to complete building quickly. For the real power house, you have to work for it and build the tools to replace the Cheats.lua file in the HPK. The process for that (roughly) is below:

1. Extract the HPK file using the HPK Archiver tool found at: https://github.com/atom0s/HpkArchiver
2. Build the Lua decompiler following the instructions at: https://github.com/viruscamp/luadec Be sure to configure it for version 5-3 of Lua!!!
3. Comment out the lines below in the file : lua-5.3/src/lundump.c
//checksize(S, Instruction);
//checksize(S, lua_Integer);
4. Comment out the lines below in the file: lua-5.3/src/ldump.c
// DumpByte(sizeof(Instruction), D); // Comment these out!
// DumpByte(sizeof(lua_Integer), D); // Comment these out!
5. Rebuild the decompiler/compiler suit per the instructions on the luadec page. This will give you a compiler that can produce compiled lua files compatible with the game.
6. Create a directory tree for the Cheats.lua file (enclosed above) of ./Mars/Lua/ and place the Cheats.lua file from above in that location.
7. Compile it with: <path to your luadec/lua-5.3/src location> luac -o Cheats.lua Mars/Lua/Cheats.lua
8 Copy the resulting Cheats.lua file OVER the old one at <HPK Extraction Path>/Lua/Cheats.lua
9. Rebuild the HPK archive to a new Lua.HPK file.
10. Move the original Lua.HPK file to Lua.HPK.original
11. Move the new Lua.HPK file you just made into the original Lua.HPK location.
12. Start the game!
13. Press the Shift-G key to get the Cheater's Gift Basket.

Use the keys below to get stuff when you need it, etc.

Alt-S -- May stop disaster (had varying luck on this one).
Alt-R -- Research the current technology in the tech tree.
Alt-P -- Research ALL the techs in the tech tree.
Shift-R -- May research all breakthroughs. (should work, but haven't tested yet)
Shift-T -- Add one colonist at the dome selected. NOTE THAT YOU MUST HAVE FOOD, AIR, WATER, AND POWER for this to work.
Alt-B -- Complete all placed but incomplete buildings (does NOT count against current resources)
Shift-F -- Add funding (maybe?)
Shift-I -- Turn on/off info panel cheats (maybe?)
Alt-G -- Gift Basket! (Scan map, give $50,000,000, and turn on info panel cheats).

So this was long winded, but I wanted to share what I had learned. I hope it's helpful to folks out there who want to know more about building cheats and modifying games to play they way we want them to.

I also have give kudos to the developers of this game. It's fun, well balanced, and a great game over all. I bought it and I'm glad I did. Also, clever work on changing the way the compiler builds compiled lua files. It made is tricky to debug the decompilation failures. I can't wait to buy (and learn to cheat) on your next title Paradox!
 

SpacedInvader

What is cheating?
Mar 20, 2018
2
0
0
#5
Hey, I've been looking to poke around the code and make some more indepth mods than currently allowed. I just cannot for the life of me compile this program, I've tried Ubuntu and Visual Basic and I can't seem to get the program to parse anything.

Could you upload a compiled version with your modifications?

Thanks the work so far!

EDIT: So I managed to make the program run. Turns out I compiled correctly but being new to Linux, didn't realise I needed ./luadec to run.
Now I'm landing at syntax errors while passing Surviving Mars .luas through the luadec program. I commented out the sections in the 2 dump.luas but ignored the cheats mod. I only want a decompiler, has skipping this step caused my program to not function correctly?
 

efi_ex

What is cheating?
Mar 19, 2018
3
0
0
#6
Hi

i used cygwin to compile luadec, do you happen to know if this might cause troubles because when i try to decompile a file i also get errors.
for example
luadec: Tech.lua:1: syntax error near '0'

i don't know if i did something wrong or if cygwin is the issue
 

jungletek

Reality Bytes
Staff member
Shogun
Oct 17, 2017
145
1
18
#7
Might be running into text encoding issues, maybe read up on https://www.google.com/search?q=difference+between+linux+and+windows+text+files ?
 

SpacedInvader

What is cheating?
Mar 20, 2018
2
0
0
#8
jungletek post_id=38560 time=1521590400 user_id=9475 said:
Might be running into text encoding issues, maybe read up on https://www.google.com/search?q=difference+between+linux+and+windows+text+files ?
Most definitely a possibility for me, I'm using files pulled from the windows version of the game. I'll reply when I get around to investigating.
 

rakion99

What is cheating?
Mar 22, 2018
2
0
1
#9
since not all have already installed Visual studio or CMake ill give the compiled binary files for hpk unpacker, luadec.exe and luac.exe(compiled in Windows 10 btw) i tested these and work fine :D, thanks phorkus for your collaboration :cool:
efi_ex post_id=38530 time=1521575034 user_id=14271 said:
Hi

i used cygwin to compile luadec, do you happen to know if this might cause troubles because when i try to decompile a file i also get errors.
for example
luadec: Tech.lua:1: syntax error near '0'

i don't know if i did something wrong or if cygwin is the issue
that error is probably because you used other game option in the hpk unpacker, you need to select the game option Victon vran and should work now

Edit:
also i found that you don't need to recompile the lua script so you can just decompile the file you want to edit and pack again the hpk ;)

and later i found that you don't even need to repack the hpk just place a folder called Mars in the game folder and the needed folders so lets say that you want to use edited Cheats.lua so you go to your game location(where the game executable is) and then you need to create the folders needed so you should have something like Surviving Mars\Mars\Lua and inside that folder ur custom Cheats.lua and the game should load it :D

or probably not these 2 last things, for some reason the cheats are now always on for me, need more testing

nvm sadly that didn't work :(
 

Attachments

efi_ex

What is cheating?
Mar 19, 2018
3
0
0
#10
hi

thanks alot, yes i did use an old version of hpk unpacker it seems, i didn't even have the option in mine.
luadec is somehow working, i do get errors but i guess this is because i use win7 still.
but when i pipe the output into a text file i can read all the lua code in there are also a lot of comments from luadec looking like this:

-- DECOMPILER ERROR at PC1634: Confused about usage of register: R9 in 'UnsetPending'

but i can live with that since i do not plan on compiling the files again.

cheers
Hannes