Skip to content

Instantly share code, notes, and snippets.

@asm256
Last active September 11, 2015 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asm256/ed75d84a9e89802821f8 to your computer and use it in GitHub Desktop.
Save asm256/ed75d84a9e89802821f8 to your computer and use it in GitHub Desktop.
Generic CM3D2 Plugin Network Build&Install Script

前提条件

  • カスタムメイド3D2
  • ReiPatcher
  • .Net Framework 3.5

をインストール済み

改造カスタムメイド3D2のインストールフォルダ直下にReiPatcherをインストールしている

インストール

  1. 改造カスタムメイド3D2 のインストールフォルダをshift+右クリック
  2. コマンドウィンドウをここで開く
  3. @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://gist.github.com/asm256/ed75d84a9e89802821f8/raw/bootstrap.ps1'))"
  4. 必要に応じてReiPatcherからパッチを当てる

ライセンス

build_lib.ps1のみMITライセンスで後は改変再配布自由です
bootstrap.ps1にも改変再配布自由って書きたかったけど文字コード面倒だった

$build_base = 'https://gist.github.com/asm256/ed75d84a9e89802821f8/raw/'
$build_script = 'build.ps1'
$build_lib = 'build_lib.ps1'
$web = new-object net.webclient
[Text.Encoding]::UTF8.GetString($web.DownloadData("$build_base$build_lib")) | iex
(WebDownloadString $web "$build_base$build_script")| iex
#改変再配布自由
#大抵の場合ここから
$prjName = 'ArchiveReplacer'
$base = 'https://gist.githubusercontent.com/asm256/8f5472657c1675bdc77a/raw/'
$srcs = @('CM3D2.ArchiveReplacer.Patcher.cs','CM3D2.ArchiveReplacer.Hook.cs')
#ここまで
Init($prjName)
pushd -LiteralPath $prjDir
$web = new-object net.webclient
$web.BaseAddress = $base
Write-Host "ダウンロード"
foreach($s in $srcs){
WebDownload $web $s
}
Write-Host "レシピ作成"
$recipe = foreach( $s in $srcs){
make_recipe $s
}
Write-Host "コンパイル"
#csc /t:library /r:Assembly-CSharp-firstpass.dll CM3D2.ArchiveReplacer.Hook.cs
# これだけなら楽だったのに…
foreach($r in $recipe){
compile $r
}
Write-Host "インストール"
foreach($r in $recipe){
install $r
}
#パッチ当ては各自で
Pop-Location
# Generic CM3D2 Plugin Network Build&Install Script
# This software is released under the MIT License.
# Copyright (c) 2015 asm__
# version 15.9.9
&{
function global:Init($prjName){
sal csc ((Get-ItemProperty 'HKLM:\SoftWare\Microsoft\NET Framework Setup\NDP\v3.5').InstallPath+'csc.exe') -scope global
$global:cm3d2= (Get-ItemProperty 'HKCU:\Software\KISS\カスタムメイド3D2').InstallPath
$global:cm3d2_kaizou = Get-Location
$global:source_dir = Join-Path $cm3d2_kaizou PluginSource
if(!(Test-Path $source_dir)){
New-Item -path $cm3d2_kaizou -name PluginSource -type directory
}
$global:prjDir = Join-Path $source_dir $prjName
if(!(Test-Path $prjDir)){
New-Item -path $source_dir -name $prjName -type directory
}
if(Test-Path (Join-Path $cm3d2_kaizou ReiPatcher)){
$global:reipatcher = (Join-Path $cm3d2_kaizou ReiPatcher)
}
if(Test-Path (Join-Path $cm3d2_kaizou CM3D2x64_Data)){
$global:CM3D2_Data = Join-Path $cm3d2_kaizou CM3D2x64_Data
}elseif (Test-Path (Join-Path $cm3d2_kaizou CM3D2x86_Data)){
$global:CM3D2_Data = Join-Path $cm3d2_kaizou CM3D2x86_Data
}
}
function global:WebDownload($web,$name){
# よく分からんがローカル側相対パスだとダメっぽい
$web.DownloadFile($name, (Join-Path $prjDir $name))
}
function global:WebDownloadString($web , $name , $enc = [Text.Encoding]::UTF8){
return $enc.GetString($web.DownloadData($name))
}
# うーん、スクリプトブロック内で定義したglobalブロックの関数からスクリプトブロック呼び出せないっぽい?
function global:replace_macro([string]$str){
return $str -replace '%reipatcher%',$reipatcher`
-replace '%managed%',"$CM3D2_Data\Managed"`
-replace '%cm3d2%',$CM3D2_KAIZOU`
-replace '%uinjector%',"$CM3D2_KAIZOU\UnityInjector"
}
function global:make_recipe($src,$enc='utf8',$type='library'){
$src_f = Get-Content $src -Encoding $enc
$argu = new-object 'System.Collections.Generic.List[System.String]'
$argu.add("/t:library")
foreach ($mi in @($src_f | select-string -pattern '^\/\/\s*@AB_addarg\s+([^\s].*)$' -AllMatches)){
$mi.matches | %{
$r = $_.groups[1].value
$r = replace_macro $r
$argu.add($r)
}
}
$install = new-object 'System.Collections.Generic.List[System.String]';
foreach ($mi in @($src_f | select-string -pattern '^\/\/\s*@AB_install\s+([^\s].*)$' -AllMatches)){
$mi.matches | %{
$r = $_.groups[1].value
$r = replace_macro $r
$install.add($r)}
}
return (@{
argu = $argu.toarray();
type = "/t:$type";
output = $src -replace '\.cs$' , '.dll';
install = $install.toarray();
encoding = $enc;
src = $src;
})
}
function global:compile($recipe){
Write-Host "Compile $($recipe['src'])"
csc $recipe['type'] "/out:$($recipe['output'])" $recipe['argu'] $recipe['src']
}
function global:install($recipe){
foreach ($path in $recipe['install']){
copy $recipe['output'] $path
}
}
function global:make_batch($recipe){
$batch = @"
@echo off
$((gal csc).Definition) $($recipe['type']) /out:$($recipe['output']) $($recipe['argu']) $($recipe['src'])
$(foreach ($path in $recipe['install']){
"copy $($recipe['output']) $path`n"
})
@pause
"@
#Write-Host $batch
try{
$batch | Out-File ($recipe['src'] -replace '\.cs$','.bat') -Encoding oem -NoClobber
}catch{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment