Skip to content

Commit

Permalink
added configuraable options
Browse files Browse the repository at this point in the history
  • Loading branch information
ash47 committed Dec 29, 2017
1 parent d739841 commit e189200
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 9 deletions.
106 changes: 97 additions & 9 deletions MethodInjector/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,107 @@ static void Main(string[] args)
return;
}

bool allowModifiedSaveGames = true;
bool enableDevTools = true;
bool enableInstantBuild = true;
bool allowFreeBuildings = true;

try
{
// Read in all the lines of the config file
string[] cfg = System.IO.File.ReadAllLines("config.txt");

// Loop over each line in the config file
foreach(string line in cfg)
{
// Our config is x = y, split based on an equals
string[] lineConfig = line.Split('=');
if(lineConfig.Length != 2)
{
// There should always be two sides of the equals
Console.WriteLine("Invalid config line: " + line);
continue;
}

// Remove any spaces, convert to lowercase
lineConfig[0] = lineConfig[0].Trim().ToLower();
lineConfig[1] = lineConfig[1].Trim().ToLower();

switch(lineConfig[0])
{
case "allowModifiedSaveGames":
if (lineConfig[1] == "false")
{
allowModifiedSaveGames = false;
}
break;

case "enableDevTools":
if (lineConfig[1] == "false")
{
enableDevTools = false;
}
break;

case "enableInstantBuild":
if (lineConfig[1] == "false")
{
enableInstantBuild = false;
}
break;

case "allowFreeBuildings":
if (lineConfig[1] == "false")
{
allowFreeBuildings = false;
}
break;

default:
Console.WriteLine("Unknown config: " + lineConfig[0]);
break;
}
}
}
catch
{
Console.WriteLine("Failed to parse config.txt");
}

/*
Perform patching
*/

// Buildings dont cost anything to build
ReplaceMethod("ZX.ZXLevelState", "CanPayResources", BindingFlags.Instance | BindingFlags.Public);
ReplaceMethod("ZX.ZXLevelState", "PayResources", BindingFlags.Instance | BindingFlags.Public);

// Allow hacked save games to be loaded
ReplaceMethod("ZX.ZXGame", "CheckSaveGame", BindingFlags.Static | BindingFlags.NonPublic);
if(allowModifiedSaveGames)
{
ReplaceMethod("ZX.ZXGame", "CheckSaveGame", BindingFlags.Static | BindingFlags.NonPublic);
}

// Enable dev tools & private stuff
ReplaceMethod("ZX.ZXGame", "get_IsDevelopmentVersion", BindingFlags.Static | BindingFlags.Public);
ReplaceMethod("ZX.ZXGame", "get_IsBetaPrivateVersion", BindingFlags.Static | BindingFlags.Public);
if (enableDevTools)
{
ReplaceMethod("ZX.ZXGame", "get_IsDevelopmentVersion", BindingFlags.Static | BindingFlags.Public);
ReplaceMethod("ZX.ZXGame", "get_IsBetaPrivateVersion", BindingFlags.Static | BindingFlags.Public);
}
ReplaceMethod("ZX.ZXGame", "get_IsSteam", BindingFlags.Static | BindingFlags.Public);

// Instant Build
ReplaceMethod("ZX.ZXCommandDefaultParams", "get_BuildingTime", BindingFlags.Public | BindingFlags.Instance, false);
ReplaceMethod("ZX.ZXEntityDefaultParams", "get_BuildingTime", BindingFlags.Public | BindingFlags.Instance, false);
if (enableInstantBuild)
{
ReplaceMethod("ZX.ZXCommandDefaultParams", "get_BuildingTime", BindingFlags.Public | BindingFlags.Instance, false);
ReplaceMethod("ZX.ZXEntityDefaultParams", "get_BuildingTime", BindingFlags.Public | BindingFlags.Instance, false);
}

// Buildings dont cost anything to build
if(allowFreeBuildings)
{
ReplaceMethod("ZX.ZXLevelState", "CanPayResources", BindingFlags.Instance | BindingFlags.Public);
ReplaceMethod("ZX.ZXLevelState", "PayResources", BindingFlags.Instance | BindingFlags.Public);
}

// Allow steam version to load


// Get a reference to the Main method
MethodInfo main = ZXProgram.GetMethod("Main", BindingFlags.Static | BindingFlags.NonPublic);
Expand Down Expand Up @@ -221,6 +303,12 @@ public static bool get_IsDevelopmentVersion()
return true;
}

// Returns if this is a steam build
public static bool get_IsSteam()
{
return false;
}

// Returns that this is a private build
public static bool get_IsBetaPrivateVersion()
{
Expand Down
4 changes: 4 additions & 0 deletions MethodInjector/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
allowModifiedSaveGames=true
enableDevTools=true
enableInstantBuild=true
allowFreeBuildings=true

0 comments on commit e189200

Please sign in to comment.