Skip to content

Commit

Permalink
Adding patches to code system, updating Codes.xml.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed Jan 17, 2016
1 parent 0a1a3f4 commit e681460
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
42 changes: 42 additions & 0 deletions SADXModLoader/dllmain.cpp
Expand Up @@ -2422,6 +2422,47 @@ static void __cdecl InitMods(void)

PrintDebug("Finished loading mods\n");

// Check for patches.
ifstream patches_str("mods\\Patches.dat", ifstream::binary);
if (patches_str.is_open())
{
CodeParser patchParser;
static const char codemagic[6] = { 'c', 'o', 'd', 'e', 'v', '4' };
char buf[sizeof(codemagic)];
patches_str.read(buf, sizeof(buf));
if (!memcmp(buf, codemagic, sizeof(codemagic)))
{
int codecount_header;
patches_str.read((char*)&codecount_header, sizeof(codecount_header));
PrintDebug("Loading %d patches...\n", codecount_header);
patches_str.seekg(0);
int codecount = patchParser.readCodes(patches_str);
if (codecount >= 0)
{
PrintDebug("Loaded %d patches.\n", codecount);
patchParser.processCodeList();
}
else
{
PrintDebug("ERROR loading patches: ");
switch (codecount)
{
case -EINVAL:
PrintDebug("Patch file is not in the correct format.\n");
break;
default:
PrintDebug("%s\n", strerror(-codecount));
break;
}
}
}
else
{
PrintDebug("Patch file is not in the correct format.\n");
}
patches_str.close();
}

// Check for codes.
ifstream codes_str("mods\\Codes.dat", ifstream::binary);
if (codes_str.is_open())
Expand All @@ -2439,6 +2480,7 @@ static void __cdecl InitMods(void)
if (codecount >= 0)
{
PrintDebug("Loaded %d codes.\n", codecount);
codeParser.processCodeList();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion SADXModLoader/version.h
@@ -1,7 +1,7 @@
// Current version.
// Make sure this is updated before every release!
#define VERSION_MAJOR 3
#define VERSION_MINOR 6
#define VERSION_MINOR 7
#define VERSION_BUILD 0
#define VERSION_REVISION 0
//#define VERSION_PRERELEASE 1
Expand Down
27 changes: 25 additions & 2 deletions SADXModManager/MainForm.cs
Expand Up @@ -25,6 +25,7 @@ public MainForm()
Dictionary<string, ModInfo> mods;
const string codexmlpath = "mods/Codes.xml";
const string codedatpath = "mods/Codes.dat";
const string patchdatpath = "mods/Patches.dat";
CodeList mainCodes;
List<Code> codes;
bool installed;
Expand Down Expand Up @@ -226,12 +227,32 @@ private void Save()
loaderini.WindowHeight = (int)windowHeight.Value;
loaderini.MaintainWindowAspectRatio = maintainWindowAspectRatioCheckBox.Checked;
IniFile.Serialize(loaderini, loaderinipath);
List<Code> codes = new List<Code>();
List<Code> patches = new List<Code>();
foreach (Code item in codesCheckedListBox.CheckedIndices.OfType<int>().Select(a => codes[a]))
if (item.Patch)
patches.Add(item);
else
codes.Add(item);
using (FileStream fs = File.Create(patchdatpath))
using (BinaryWriter bw = new BinaryWriter(fs, System.Text.Encoding.ASCII))
{
bw.Write(new[] { 'c', 'o', 'd', 'e', 'v', '4' });
bw.Write(patches.Count);
foreach (Code item in patches)
{
if (item.IsReg)
bw.Write((byte)CodeType.newregs);
WriteCodes(item.Lines, bw);
}
bw.Write(byte.MaxValue);
}
using (FileStream fs = File.Create(codedatpath))
using (BinaryWriter bw = new BinaryWriter(fs, System.Text.Encoding.ASCII))
{
bw.Write(new[] { 'c', 'o', 'd', 'e', 'v', '4' });
bw.Write(codesCheckedListBox.CheckedIndices.Count);
foreach (Code item in codesCheckedListBox.CheckedIndices.OfType<int>().Select(a => codes[a]))
bw.Write(codes.Count);
foreach (Code item in codes)
{
if (item.IsReg)
bw.Write((byte)CodeType.newregs);
Expand Down Expand Up @@ -560,6 +581,8 @@ public class Code
public string Name { get; set; }
[XmlAttribute("required")]
public bool Required { get; set; }
[XmlAttribute("patch")]
public bool Patch { get; set; }
[XmlElement("CodeLine")]
public List<CodeLine> Lines { get; set; }

Expand Down
18 changes: 13 additions & 5 deletions data/Codes.xml
Expand Up @@ -192,15 +192,15 @@
<ValueType>hex</ValueType>
</CodeLine>
</Code>
<Code name="Disable Music">
<Code name="Disable Music" patch="true">
<CodeLine>
<Type>write8</Type>
<Address>00425690</Address>
<Value>C3</Value>
<ValueType>hex</ValueType>
</CodeLine>
</Code>
<Code name="Disable Voices">
<Code name="Disable Voices" patch="true">
<CodeLine>
<Type>write8</Type>
<Address>00425710</Address>
Expand Down Expand Up @@ -354,15 +354,15 @@
</TrueLines>
</CodeLine>
</Code>
<Code name="Tails Can Play Emerald Coast">
<Code name="Tails Can Play Emerald Coast" patch="true">
<CodeLine>
<Type>write16</Type>
<Address>004F6B02</Address>
<Value>9090</Value>
<ValueType>hex</ValueType>
</CodeLine>
</Code>
<Code name="Don't Lose Rings When Hit">
<Code name="Don't Lose Rings When Hit" patch="true">
<CodeLine>
<Type>write8</Type>
<Address>00425AB0</Address>
Expand All @@ -371,7 +371,7 @@
<RepeatCount>9</RepeatCount>
</CodeLine>
</Code>
<Code name="Walk on Water">
<Code name="Walk on Water" patch="true">
<CodeLine>
<Type>write16</Type>
<Address>004496E1</Address>
Expand All @@ -380,4 +380,12 @@
<RepeatCount>3</RepeatCount>
</CodeLine>
</Code>
<Code name="Skip Intro" patch="true">
<CodeLine>
<Type>write32</Type>
<Address>0040C10C</Address>
<Value>11</Value>
<ValueType>decimal</ValueType>
</CodeLine>
</Code>
</CodeList>

0 comments on commit e681460

Please sign in to comment.