Skip to content

Instantly share code, notes, and snippets.

@Ghabry
Created June 1, 2025 13:15
Show Gist options
  • Save Ghabry/b08bd0765aa434c4748b48be90a6a657 to your computer and use it in GitHub Desktop.
Save Ghabry/b08bd0765aa434c4748b48be90a6a657 to your computer and use it in GitHub Desktop.
Defentron: Achievement Fix

Unlocking of various achievements in Defentron is broken.

Download (overwrite Assembly-CSharp.dll in DEFENTRON_Data\Managed).

If you already have completed the game:

  • Finish the final level again with any amount of stars
  • Finish any level with three stars, this will unlock the secret levels

This patch fixes:

  • Completion of World 5 achievement is now granted when the game is completed
  • "Get 3 Star" achievements are checked again when any level is completed with 3 stars. Unlocking a 3 star achivement adds a secret level per world.
  • "Unlock all Turrets" achievement is obtained after level 30 or later is completed
  • "Encounter every enemy" achievement is obtained after level 23 or later is completed
  • "Complete the Codex" achievement is obtained together with "Unlock all Turrets"
  • "Secret Level" achievement after completing a world with 3 stars (when this fails to unlock just continue playing secret levels)
  • "All Stars" achievement after obtainined three stars in all bonus levels
// Patches code with achivement fixes
using System;
using GameGrind;
using UnityEngine;
using UnityEngine.SceneManagement;
// Token: 0x02000018 RID: 24
public class CompleteLevel : MonoBehaviour
{
// Token: 0x0600008E RID: 142
public void DisplayStars()
{
this.stars.ShowStars(Singleton<PlayerStats>.Instance.CalculateStars());
if (!Singleton<GameManager>.Instance.isSecretLvl)
{
AchievementManager.CheckForAchivementsOnLevelComplete();
}
else
{
AchievementManager.CheckForAchivementsOnLevelSecretComplete(Singleton<GameManager>.Instance.secretLvlCode);
}
this.SaveData();
}
// Token: 0x0600008F RID: 143
public void Menu()
{
this.CheckIfLevelReached();
Time.timeScale = 1f;
SimpleSceneLoad.instance.LoadLevel(this.menuSceneName);
}
// Token: 0x06000090 RID: 144
public void Retry()
{
this.CheckIfLevelReached();
if (ES3.Load<int>("45", 0) != 1 && Singleton<PlayerStats>.Instance.CalculateStars() < 3)
{
Journal.Increment(45, 1);
ES3.Save<int>("45", 1);
}
Time.timeScale = 1f;
SimpleSceneLoad.instance.LoadLevel(SceneManager.GetActiveScene().name);
}
// Token: 0x06000091 RID: 145
public void LoadNext()
{
this.CheckIfLevelReached();
Time.timeScale = 1f;
SimpleSceneLoad.instance.LoadLevel(Singleton<GameManager>.Instance.nextLevel);
}
// Token: 0x06000092 RID: 146
public void LoadMainScene()
{
this.CheckIfLevelReached();
Time.timeScale = 1f;
SimpleSceneLoad.instance.LoadLevel("MainScene");
}
// Token: 0x06000093 RID: 147
public void CheckIfLevelReached()
{
if (!Singleton<GameManager>.Instance.isSecretLvl && ES3.Load<int>("levelReached", 0) < this.levelToUnlock)
{
ES3.Save<int>("levelReached", this.levelToUnlock);
}
}
// Token: 0x06000094 RID: 148
private void SaveData()
{
int num = this.levelToUnlock - 1;
string key = num.ToString();
int num2 = Singleton<PlayerStats>.Instance.CalculateStars();
if (!Singleton<GameManager>.Instance.isSecretLvl)
{
key = num + "level";
}
else
{
key = Singleton<GameManager>.Instance.secretLvlCode + "starlevel";
}
if (num >= 23 && !Journal.GetAchievement(46).completed) {
// FIX: Final enemy encountered
Journal.Increment(46, 5);
}
if (num >= 30 && !Journal.GetAchievement(47).completed) {
// FIX: Final turret encountered
Journal.Increment(47, 5);
}
if (Journal.GetAchievement(46).completed && Journal.GetAchievement(47).completed && !Journal.GetAchievement(48).completed) {
// FIX: Codex completed
Journal.Increment(48, 1);
}
if (num == 38)
{
Journal.Increment(10, 1);
// FIX: Grant completion of World 5 when finishing the game
Journal.Increment(4, 1);
}
if (num > 5)
{
if (Singleton<GameManager>.Instance.onlyBasicsConstructed)
{
Journal.Increment(12, 1);
}
if (Singleton<GameManager>.Instance.noTurretUpgraded)
{
Journal.Increment(13, 1);
}
if (Singleton<GameManager>.Instance.onlyClusterContructed)
{
Journal.Increment(14, 1);
}
}
if (ES3.KeyExists(key))
{
if (ES3.Load<int>(key) < num2)
{
ES3.Save<int>(key, num2);
this.CheckForAchievements();
return;
}
// FIX: Unlock 3 star achivements when a level is completed again with 3 stars
int sum = 0;
for (int i = 1; i < 6; i++)
{
sum += ES3.Load<int>(i.ToString(), 0);
}
if (sum == 5 && !Journal.GetAchievement(5).completed)
{
Journal.Increment(5, sum);
}
sum = 0;
for (int j = 6; j < 12; j++)
{
sum += ES3.Load<int>(j.ToString(), 0);
}
if (sum == 6 && !Journal.GetAchievement(6).completed)
{
Journal.Increment(6, sum);
}
sum = 0;
for (int k = 12; k < 18; k++)
{
sum += ES3.Load<int>(k.ToString(), 0);
}
if (sum == 6 && !Journal.GetAchievement(7).completed)
{
Journal.Increment(7, sum);
}
sum = 0;
for (int l = 18; l < 28; l++)
{
sum += ES3.Load<int>(l.ToString(), 0);
}
if (sum == 10 && !Journal.GetAchievement(8).completed)
{
Journal.Increment(8, sum);
}
sum = 0;
for (int m = 28; m < 39; m++)
{
sum += ES3.Load<int>(m.ToString(), 0);
}
if (sum == 11 && !Journal.GetAchievement(9).completed)
{
Journal.Increment(9, sum);
return;
}
}
else
{
ES3.Save<int>(key, num2);
this.CheckForAchievements();
}
}
// Token: 0x06000095 RID: 149
private void CheckForAchievements()
{
int num = this.levelToUnlock - 1;
string text = num.ToString();
int num2;
if (!Singleton<GameManager>.Instance.isSecretLvl)
{
text = num.ToString();
num2 = ES3.Load<int>(text + "level");
}
else
{
text = Singleton<GameManager>.Instance.secretLvlCode + "star";
num2 = ES3.Load<int>(text + "level");
}
if (num2 == 3)
{
if (!Singleton<GameManager>.Instance.isSecretLvl)
{
if (ES3.Load<int>(text, 0) != 1)
{
ES3.Save<int>(text, 1);
if (num > 0 && num < 6)
{
Journal.Increment(5, 1);
}
else if (num > 5 && num < 12)
{
Journal.Increment(6, 1);
}
else if (num > 11 && num < 18)
{
Journal.Increment(7, 1);
}
else if (num > 17 && num < 28)
{
Journal.Increment(8, 1);
}
else if (num > 27 && num < 39)
{
Journal.Increment(9, 1);
}
}
}
else if (ES3.Load<int>(text, 0) != 1)
{
ES3.Save<int>(text, 1);
if (!(text == "s01star"))
{
if (!(text == "s02star"))
{
if (!(text == "s03star"))
{
if (!(text == "s04star"))
{
if (text == "s05star")
{
Journal.Increment(22, 1);
}
}
else
{
Journal.Increment(22, 1);
}
}
else
{
Journal.Increment(22, 1);
}
}
else
{
Journal.Increment(22, 1);
}
}
else
{
Journal.Increment(22, 1);
}
}
}
if (Journal.GetAchievement(5).completed && Journal.GetAchievement(6).completed && Journal.GetAchievement(7).completed && Journal.GetAchievement(8).completed && Journal.GetAchievement(9).completed)
{
Journal.Increment(21, 1);
}
if (Journal.GetAchievement(5).completed || Journal.GetAchievement(6).completed || Journal.GetAchievement(7).completed || Journal.GetAchievement(8).completed || Journal.GetAchievement(9).completed)
{
// FIX: Secret level discovered when any world has 3 stars
Journal.Increment(49, 1);
}
if (!Journal.GetAchievement(22).completed) {
// FIX: Achievement all stars including secrets
if (ES3.Load<int>("s01star", 0) == 1 && ES3.Load<int>("s02star", 0) == 1
&& ES3.Load<int>("s03star", 0) == 1 && ES3.Load<int>("s04star", 0) == 1 &&
ES3.Load<int>("s05star", 0) == 1) {
Journal.Increment(22, 5);
}
}
}
// Token: 0x040000C0 RID: 192
public string menuSceneName = "MainScene";
// Token: 0x040000C1 RID: 193
public string nextLevel = "Level02";
// Token: 0x040000C2 RID: 194
public int levelToUnlock = 2;
// Token: 0x040000C3 RID: 195
public StarsContainer stars;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment