Skip to content

Commit

Permalink
Merge branch 'rewrite-in-c'
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementDreptin committed Aug 31, 2022
2 parents e42d803 + 0bbf8dd commit e538eb2
Show file tree
Hide file tree
Showing 14 changed files with 606 additions and 449 deletions.
12 changes: 4 additions & 8 deletions GameShortcut/GameShortcut.vcxproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Release|Xbox 360">
Expand All @@ -25,7 +25,6 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Xbox 360'">
<RemoteRoot>hdd:\Games\$(ProjectName)</RemoteRoot>
<OutDir>$(SolutionDir)build\bin\</OutDir>
<IntDir>$(SolutionDir)build\obj\</IntDir>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
Expand All @@ -46,6 +45,7 @@
<PreprocessorDefinitions>NDEBUG;_XBOX</PreprocessorDefinitions>
<TreatWarningAsError>true</TreatWarningAsError>
<ObjectFileName>$(IntDir)$(ProjectName)\%(RelativeDir)</ObjectFileName>
<CompileAs>CompileAsC</CompileAs>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand All @@ -54,10 +54,6 @@
<ProgramDatabaseFile>$(IntDir)$(ProjectName)\$(ProjectName).pdb</ProgramDatabaseFile>
<SetChecksum>true</SetChecksum>
</Link>
<Deploy>
<DeploymentType>CopyToHardDrive</DeploymentType>
<DeploymentFiles>$(RemoteRoot)=$(ImagePath);$(RemoteRoot)\config=$(OutDir)config</DeploymentFiles>
</Deploy>
<PostBuildEvent>
<Command>del $(OutDir)$(TargetName)$(TargetExt)</Command>
</PostBuildEvent>
Expand All @@ -66,10 +62,10 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\main.c" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="config\gameInfo.txt">
<CustomBuild Include="config\shortcutInfo.txt">
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Xbox 360'">copy "%(FullPath)" "$(OutDir)config\%(Filename)%(Extension)"</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Xbox 360'">Copy config file %(FullPath)</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Xbox 360'">$(OutDir)config\%(Filename)%(Extension)</Outputs>
Expand Down
4 changes: 2 additions & 2 deletions GameShortcut/GameShortcut.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\main.c" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="config\gameInfo.txt" />
<CustomBuild Include="config\shortcutInfo.txt" />
</ItemGroup>
</Project>
File renamed without changes.
127 changes: 127 additions & 0 deletions GameShortcut/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include <stdint.h>
#include <stdio.h>
#include <xtl.h>

#define ERROR_LENGTH 200

// Structs and function prototypes from xboxkrnl.exe
typedef struct _STRING
{
uint16_t wLength;
uint16_t wMaxLength;
char *szBuffer;
} STRING;

void RtlInitAnsiString(STRING *pDestinationString, const char *szSourceString);
HRESULT ObCreateSymbolicLink(STRING *pLinkName, STRING *pDevicePath);

// Allow the game to access the entire hard drive.
// The system only allows executables to access the directory they live in and binds it to
// the "game:" drive. Nothing else is accessible unless you create a symbolic link.
static HRESULT MountHdd()
{
STRING DeviceName = { 0 };
STRING LinkName = { 0 };
const char *szDestinationDrive = "\\??\\hdd:";
const char *szHddDevicePath = "\\Device\\Harddisk0\\Partition1\\";

// Initialize the STRING structs
RtlInitAnsiString(&DeviceName, szHddDevicePath);
RtlInitAnsiString(&LinkName, szDestinationDrive);

// Bind the root of the hard drive to the "hdd:" drive.
return ObCreateSymbolicLink(&LinkName, &DeviceName);
}

// Read the path to the executable from the config file and write it to szGamePath.
static HRESULT GetGamePath(char *szGamePath, size_t nMaxLength)
{
HRESULT hr = S_OK;
size_t i = 0;
FILE *pConfigFile = NULL;
size_t nGamePathSize = 0;

// Open the config file in read-only mode
if (fopen_s(&pConfigFile, "game:\\config\\shortcutInfo.txt", "r") != 0)
return E_FAIL;

// Read the second line of the config file into szGamePath
for (i = 0; i < 2; i++)
if (fgets(szGamePath, (int)nMaxLength, pConfigFile) == NULL)
return E_FAIL;

nGamePathSize = strnlen_s(szGamePath, nMaxLength);

// Remove the new line character at the end of the line
szGamePath[nGamePathSize - 1] = '\0';

fclose(pConfigFile);

return hr;
}

// Display an error dialog on the console.
static HRESULT ShowMessageBoxError(const char *szMessage)
{
DWORD dwResult = 0;

wchar_t wszMessage[ERROR_LENGTH] = { 0 };
XOVERLAPPED Overlapped = { 0 };
MESSAGEBOX_RESULT Result = { 0 };
const wchar_t *pwszButtons[] = { L"OK", L"Cancel" };

// Convert szMessage, which is a narrow string, to a wide string
mbstowcs_s(NULL, wszMessage, ERROR_LENGTH, szMessage, _TRUNCATE);

dwResult = XShowMessageBoxUI(
0,
L"Error",
wszMessage,
ARRAYSIZE(pwszButtons),
pwszButtons,
0,
XMB_ERRORICON,
&Result,
&Overlapped
);

if (dwResult != ERROR_IO_PENDING)
return E_FAIL;

// Wait until the user closes the message box
while (!XHasOverlappedIoCompleted(&Overlapped))
Sleep(100);

// Get how the user closed the message box (by clicking "OK", "Cancel" or the Xbox button on the controller)
dwResult = XGetOverlappedResult(&Overlapped, NULL, TRUE);

if (dwResult == ERROR_ACCESS_DENIED)
return E_FAIL;

return S_OK;
}

int main()
{
HRESULT hr = S_OK;
char szGamePath[MAX_PATH] = { 0 };

// Mount the entire hard drive to be able to access any path in it
hr = MountHdd();
if (FAILED(hr))
{
ShowMessageBoxError("Could not mount HDD1.");
return EXIT_FAILURE;
}

// Read the path to the executable
hr = GetGamePath(szGamePath, MAX_PATH);
if (FAILED(hr))
{
ShowMessageBoxError("The game information file (config\\shortcutInfo.txt) could not be loaded or has a wrong format.");
return EXIT_FAILURE;
}

// Launch the executable
XLaunchNewImage(szGamePath, 0);
}
108 changes: 0 additions & 108 deletions GameShortcut/src/main.cpp

This file was deleted.

9 changes: 4 additions & 5 deletions Publisher/Publisher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<TreatWarningAsError>true</TreatWarningAsError>
<ObjectFileName>$(IntDir)$(ProjectName)\%(RelativeDir)</ObjectFileName>
<AdditionalIncludeDirectories>$(XEDK)\include\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CompileAs>CompileAsC</CompileAs>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -51,18 +52,16 @@
<OptimizeReferences>true</OptimizeReferences>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<ProgramDatabaseFile>$(IntDir)$(ProjectName)\$(ProjectName).pdb</ProgramDatabaseFile>
<AdditionalDependencies>xbdm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>xbdm.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(XEDK)\lib\win32\vs2010;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\main.c" />
<ClCompile Include="src\Utils.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\IO.h" />
<ClInclude Include="src\Log.h" />
<ClInclude Include="src\Utils.h" />
<ClInclude Include="src\XLAST.h" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="resources\icon.png">
Expand Down
6 changes: 2 additions & 4 deletions Publisher/Publisher.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\main.c" />
<ClCompile Include="src\Utils.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Log.h" />
<ClInclude Include="src\IO.h" />
<ClInclude Include="src\Utils.h" />
<ClInclude Include="src\XLAST.h" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="resources\icon.png" />
Expand Down
Loading

0 comments on commit e538eb2

Please sign in to comment.