1- using System ;
2- using System . Collections . Generic ;
1+ using System . Collections . Generic ;
32using System . IO ;
3+ using System . IO . Compression ;
44using System . Linq ;
5- using IniParser ;
65using IniParser . Model ;
76using LeagueSandbox . GameServer . Logging ;
87using log4net ;
98using LeagueSandbox . GameServer . Exceptions ;
10- using Newtonsoft . Json . Linq ;
119
1210namespace LeagueSandbox . GameServer . Content
1311{
@@ -20,15 +18,12 @@ public class ContentManager
2018 private Dictionary < string , CharData > _charData = new Dictionary < string , CharData > ( ) ;
2119 private Dictionary < string , NavGrid > _navGrids = new Dictionary < string , NavGrid > ( ) ;
2220
23- public Dictionary < string , ContentFile > Content = new Dictionary < string , ContentFile > ( ) ;
24- public List < string > CSharpScriptFiles = new List < string > ( ) ;
21+ public Dictionary < string , byte [ ] > Content = new Dictionary < string , byte [ ] > ( ) ;
2522
26- private string _contentPath ;
2723 public string GameModeName { get ; }
2824
29- private ContentManager ( Game game , string gameModeName , string contentPath )
25+ private ContentManager ( Game game , string gameModeName )
3026 {
31- _contentPath = contentPath ;
3227 _game = game ;
3328 _logger = LoggerProvider . GetLogger ( ) ;
3429
@@ -37,18 +32,26 @@ private ContentManager(Game game, string gameModeName, string contentPath)
3732
3833 public string GetMapConfigPath ( int mapId )
3934 {
40- var path = Path . Combine ( _contentPath , GameModeName , "LEVELS" , $ "Map{ mapId } ", $ "Map{ mapId } .json") ;
41- if ( ! File . Exists ( path ) )
35+ var possibilities = new [ ]
4236 {
43- throw new ContentNotFoundException ( $ "Map configuration for Map { mapId } was not found in the content.") ;
37+ $ "LEVELS/Map{ mapId } /Map{ mapId } .json",
38+ $ "LEVELS/map{ mapId } /Map{ mapId } .json"
39+ } ;
40+
41+ foreach ( var path in possibilities )
42+ {
43+ if ( Content . ContainsKey ( path ) )
44+ {
45+ return path ;
46+ }
4447 }
4548
46- return path ;
49+ throw new ContentNotFoundException ( $ "Map configuration for Map { mapId } was not found in the content." ) ;
4750 }
4851
4952 public string GetUnitStatPath ( string model )
5053 {
51- var path = Path . Combine ( "DATA" , " Characters" , model , $ " { model } .ini") ;
54+ var path = $ "DATA/ Characters/ { model } / { model } .ini";
5255 if ( ! Content . ContainsKey ( path ) )
5356 {
5457 throw new ContentNotFoundException ( $ "Stat file for { model } was not found.") ;
@@ -61,9 +64,9 @@ public string GetSpellDataPath(string model, string spellName)
6164 {
6265 var possibilities = new [ ]
6366 {
64- Path . Combine ( "DATA" , " Characters" , model , " Spells" , $ " { spellName } .ini") ,
65- Path . Combine ( "DATA" , " Shared" , " Spells" , $ " { spellName } .ini") ,
66- Path . Combine ( "DATA" , " Spells" , $ " { spellName } .ini")
67+ $ "DATA/ Characters/ { model } / Spells/ { spellName } .ini",
68+ $ "DATA/ Shared/ Spells/ { spellName } .ini",
69+ $ "DATA/ Spells/ { spellName } .ini"
6770 } ;
6871
6972 foreach ( var path in possibilities )
@@ -101,27 +104,84 @@ public CharData GetCharData(string charName)
101104 return _charData [ charName ] ;
102105 }
103106
104- public NavGrid GetNavGrid ( string navGridPath )
107+ public NavGrid GetNavGrid ( int mapId )
105108 {
106- if ( _navGrids . ContainsKey ( navGridPath ) )
109+ var possibilities = new [ ]
110+ {
111+ $ "LEVELS/Map{ mapId } /AIPath.aimesh_ngrid",
112+ $ "LEVELS/map{ mapId } /AIPath.aimesh_ngrid"
113+ } ;
114+ foreach ( var path in possibilities )
107115 {
108- return _navGrids [ navGridPath ] ;
116+ if ( _navGrids . ContainsKey ( path ) )
117+ {
118+ return _navGrids [ path ] ;
119+ }
109120 }
110121
111- throw new ContentNotFoundException ( $ "NavGrid with path { navGridPath } was not loaded.") ;
122+ throw new ContentNotFoundException ( $ "NavGrid for map { mapId } was not loaded.") ;
112123 }
113124
114125 public static ContentManager LoadGameMode ( Game game , string gameModeName , string contentPath )
115126 {
116- var contentManager = new ContentManager ( game , gameModeName , contentPath ) ;
117- var iniParser = new FileIniDataParser ( ) ;
127+ var contentManager = new ContentManager ( game , gameModeName ) ;
128+
129+ var zipPath = Path . Combine ( contentPath , gameModeName , gameModeName + ".zip" ) ;
130+
131+ // If zip exists
132+ if ( File . Exists ( zipPath ) )
133+ {
134+ // Read zip file data
135+ using ( var file = File . OpenRead ( zipPath ) )
136+ {
137+ // Read archive data
138+ using ( var zip = new ZipArchive ( file , ZipArchiveMode . Read ) )
139+ {
140+ // For every entry in the zip
141+ foreach ( var entry in zip . Entries )
142+ {
143+ // Uncompress the entry and read it
144+ using ( var entryData = new BinaryReader ( entry . Open ( ) ) )
145+ {
146+ if ( entry . FullName . EndsWith ( ".ini" ) || entry . FullName . EndsWith ( ".json" ) )
147+ {
148+ contentManager . Content [ entry . FullName ] = entryData . ReadBytes ( ( int ) entry . Length ) ;
149+ }
150+ else if ( entry . FullName . EndsWith ( ".aimesh_ngrid" ) )
151+ {
152+ contentManager . _navGrids [ entry . FullName ] =
153+ NavGridReader . ReadBinary ( entryData . ReadBytes ( ( int ) entry . Length ) ) ;
154+
155+ contentManager . Content [ entry . FullName ] = entryData . ReadBytes ( ( int ) entry . Length ) ;
156+ }
157+ else if ( entry . FullName . EndsWith ( ".cs" ) )
158+ {
159+ if ( entry . FullName . StartsWith ( "bin" ) || entry . FullName . StartsWith ( "obj" ) )
160+ {
161+ continue ;
162+ }
163+
164+ contentManager . Content [ entry . FullName ] = entryData . ReadBytes ( ( int ) entry . Length ) ;
165+ }
166+ else
167+ {
168+ continue ;
169+ }
170+
171+ contentManager . _logger . Debug ( $ "Mapped content from zip [{ entry . FullName } ]") ;
172+ }
173+ }
174+ }
175+ }
176+ }
177+
118178 foreach ( var file in Directory . GetFiles ( contentPath , "*.*" , SearchOption . AllDirectories ) )
119179 {
120- var relativePath = file . Replace ( contentPath , "" ) . Replace ( gameModeName , "" ) . Substring ( 2 ) ;
121- if ( file . EndsWith ( ".ini" ) )
180+ var relativePath = file . Replace ( contentPath , "" ) . Replace ( gameModeName , "" ) . Substring ( 2 )
181+ . Replace ( '\\ ' , '/' ) ;
182+ if ( file . EndsWith ( ".ini" ) || file . EndsWith ( ".json" ) )
122183 {
123- var ini = iniParser . ReadFile ( file ) ;
124- contentManager . Content [ relativePath ] = new ContentFile ( ParseIniFile ( ini ) ) ;
184+ contentManager . Content [ relativePath ] = File . ReadAllBytes ( file ) ;
125185 }
126186 else if ( file . EndsWith ( ".cs" ) )
127187 {
@@ -130,10 +190,11 @@ public static ContentManager LoadGameMode(Game game, string gameModeName, string
130190 continue ;
131191 }
132192
133- contentManager . CSharpScriptFiles . Add ( file ) ;
193+ contentManager . Content [ relativePath ] = File . ReadAllBytes ( file ) ;
134194 }
135195 else if ( file . EndsWith ( ".aimesh_ngrid" ) )
136196 {
197+ contentManager . Content [ relativePath ] = File . ReadAllBytes ( file ) ;
137198 contentManager . _navGrids [ relativePath ] = NavGridReader . ReadBinary ( file ) ;
138199 }
139200 else
@@ -156,6 +217,7 @@ public static Dictionary<string, Dictionary<string, string>> ParseIniFile(IniDat
156217 {
157218 ret [ section . SectionName ] = new Dictionary < string , string > ( ) ;
158219 }
220+
159221 foreach ( var field in section . Keys )
160222 {
161223 ret [ section . SectionName ] [ field . KeyName ] = field . Value ;
@@ -189,4 +251,4 @@ private static bool ValidatePackageName(string packageName)
189251 return true ;
190252 }
191253 }
192- }
254+ }
0 commit comments