Skip to content

Commit

Permalink
Removed TestSpawn binaries and added an updated version in project form.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-fadely committed Dec 23, 2015
1 parent 9229ffd commit 256c6ca
Show file tree
Hide file tree
Showing 11 changed files with 439 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "TestSpawn/sadx-mod-loader"]
path = TestSpawn/sadx-mod-loader
url = https://github.com/sonicretro/sadx-mod-loader.git
Binary file removed ModGenerator/Config/SADX/TestSpawn/TestSpawn.dll
Binary file not shown.
141 changes: 139 additions & 2 deletions SA Tools.sln

Large diffs are not rendered by default.

26 changes: 9 additions & 17 deletions SADXLVL2/MainForm.cs
Expand Up @@ -2,12 +2,12 @@
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using SA_Tools;
Expand Down Expand Up @@ -2990,7 +2990,7 @@ private void CopyUpdatedModFiles()
}

LogMessageLine("AutoBuild: Updating Mod Profile");
string modIniFilePath = Settings.GamePath + string.Concat("\\mods\\", EditorOptions.ProjectName, "\\") + "mod.ini";
string modIniFilePath = Settings.GamePath + string.Concat("\\mods\\", EditorOptions.ProjectName, "\\") + "mod.ini";
ModManagement.ModProfile modProfile = new ModManagement.ModProfile(modIniFilePath);

if(hasChangedModExeMapping)
Expand All @@ -3008,20 +3008,11 @@ private void CopyUpdatedModFiles()

private void PlayTestLevel()
{
if(changedSinceSave) SaveStage(true);

// save start info data so that it can be forwarded to modloader
string spawnInfoPath = string.Concat(EditorOptions.GamePath, "\\Mods\\", "TestSpawn", "\\StartData.ini");

List<String> spawnInfo = new List<string>();
spawnInfo.Add(string.Format("level={0}", (byte)levelact.Level));
spawnInfo.Add(string.Format("act={0}", levelact.Act));
spawnInfo.Add(string.Format("character={0}", LevelData.Character));

File.WriteAllLines(spawnInfoPath, spawnInfo.ToArray());
if (changedSinceSave)
SaveStage(true);

// Set our mods properly
string loaderIniPath = string.Concat(EditorOptions.GamePath, "\\Mods\\SADXModLoader.ini");
string loaderIniPath = Path.Combine(EditorOptions.GamePath, "mods\\SADXModLoader.ini");
ModManagement.LoaderInfo loaderInfo = IniSerializer.Deserialize<ModManagement.LoaderInfo>(loaderIniPath);
int testSpawnIndex = -1;
int currentProjectIndex = -1;
Expand All @@ -3037,12 +3028,13 @@ private void PlayTestLevel()
IniSerializer.Serialize(loaderInfo, loaderIniPath);

// set sonic.exe to start with the -testspawn flag
string sonicExePath = Path.GetFullPath(Settings.GamePath + "\\sonic.exe");
string sonicExePath = Path.GetFullPath(Path.Combine(Settings.GamePath, "sonic.exe"));
if (File.Exists(sonicExePath))
{
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(sonicExePath, "-testspawn");
string args = string.Format("-testspawn -level {0} -act {1} -character {2}", levelact.Level, levelact.Act, LevelData.Character);
ProcessStartInfo startInfo = new ProcessStartInfo(sonicExePath, args);
startInfo.WorkingDirectory = Path.GetDirectoryName(sonicExePath);
System.Diagnostics.Process sonicProcess = System.Diagnostics.Process.Start(startInfo);
Process sonicProcess = Process.Start(startInfo);
}
else
{
Expand Down
128 changes: 128 additions & 0 deletions TestSpawn/TestSpawn.cpp
@@ -0,0 +1,128 @@
#include "stdafx.h"

#include <iostream>
#include <SADXModLoader.h>
#include <shellapi.h> // for CommandLineToArgvW
#include <string>
#include <vector>

static const void* jumpAddress = (const void*)0x0040C318;

__declspec(naked) void ForceTrialMode()
{
__asm
{
mov GameMode, GameModes_Trial
jmp jumpAddress
}
}

extern "C"
{
__declspec(dllexport) ModInfo SADXModInfo = { ModLoaderVer };

__declspec(dllexport) void __cdecl Init(const char* path, const HelperFunctions& helperFunctions)
{
int argc = 0;
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
bool spawnFlag = false;

// Prevents CurrentCharacter from being overwritten. There could be other side effects,
// but there are none that I've noticed thus far.
std::vector<Uint8> nop(5, 0x90);
WriteData((void*)0x00415007, nop.data(), nop.size());

// TODO: Start position via command line and/or ini.
for (int i = 1; i < argc; i++)
{
if (!wcscmp(argv[i], L"-testspawn"))
{
WriteJump((void*)0x0040C115, ForceTrialMode);
spawnFlag = true;
continue;
}

if (!spawnFlag)
continue;

if (!wcscmp(argv[i], L"-level"))
{
CurrentLevel = _wtoi(argv[++i]);
PrintDebug("Loading level: %d\n", CurrentLevel);
}
else if (!wcscmp(argv[i], L"-act"))
{
CurrentAct = _wtoi(argv[++i]);
PrintDebug("Loading act: %d\n", CurrentAct);
}
else if (!wcscmp(argv[i], L"-character"))
{
CurrentCharacter = _wtoi(argv[++i]);
PrintDebug("Loading character: %d\n", CurrentCharacter);
}
}

LocalFree(argv);
return;

/*
#ifdef _DEBUG
PrintDebug("Loading SpawnData\n");
#endif
// TODO: GetPrivateProfile*
std::string startDataPath = (std::string)path + "\\StartData.ini";
std::ifstream startDataStream(startDataPath);
if (startDataStream.fail())
{
PrintDebug("Loading spawn data failed!\n");
}
else
{
while (!startDataStream.eof())
{
char currentLine[256];
startDataStream.getline(currentLine, 256);
if (strlen(currentLine) == 0) continue;
char nameBuffer[256];
char* name = nameBuffer;
char valueBuffer[256];
char* value = valueBuffer;
name = strtok(currentLine, "=");
value = strtok(NULL, "=");
if (strcmp(name, "level") == 0)
{
CurrentLevel = atoi(value);
#ifdef _DEBUG
PrintDebug("Loading level: %d\n", CurrentLevel);
#endif
}
else if (strcmp(name, "act") == 0)
{
CurrentAct = atoi(value);
#ifdef _DEBUG
PrintDebug("Loading act: %d\n", CurrentAct);
#endif
}
else if (strcmp(name, "character") == 0)
{
CurrentCharacter = atoi(value);
#ifdef _DEBUG
PrintDebug("Loading character: %d\n", CurrentCharacter);
#endif
}
}
startDataStream.close();
#ifdef _DEBUG
PrintDebug("Finished Loading Spawn!\n");
#endif
}
*/
}
}
107 changes: 107 additions & 0 deletions TestSpawn/TestSpawn.vcxproj
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{2DDB084D-4609-425F-B178-F5FCFED260F2}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>TestSpawn</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)ModGenerator\Config\SADX\$(ProjectName)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)ModGenerator\Config\SADX\$(ProjectName)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>sadx-mod-loader\SADXModLoader\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PreBuildEvent>
<Command>xcopy /Y /D "$(ProjectDir)mod.ini" "$(OutDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>sadx-mod-loader\SADXModLoader\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PreBuildEvent>
<Command>xcopy /Y /D "$(ProjectDir)mod.ini" "$(OutDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="TestSpawn.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="mod.ini" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
35 changes: 35 additions & 0 deletions TestSpawn/TestSpawn.vcxproj.filters
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TestSpawn.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="mod.ini">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
</Project>
@@ -1,4 +1,5 @@
Name=TestSpawn
Author=X-Hax
Description=Used by SADXLVL2. Doesn't do anything on its own.
DLLFile=TestSpawn.dll
DLLFile=TestSpawn.dll
Version=1.0
1 change: 1 addition & 0 deletions TestSpawn/sadx-mod-loader
Submodule sadx-mod-loader added at dfe129
8 changes: 8 additions & 0 deletions TestSpawn/stdafx.cpp
@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// TestSpawn.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
7 changes: 7 additions & 0 deletions TestSpawn/stdafx.h
@@ -0,0 +1,7 @@
#pragma once

#include <iostream>
#include <SADXModLoader.h>
#include <shellapi.h> // for CommandLineToArgvW
#include <string>
#include <vector>

0 comments on commit 256c6ca

Please sign in to comment.